biblioitems.publishercode,
aqorders.rrp AS unitpricesupplier,
aqorders.ecost AS unitpricelib,
- aqorders.claims_count AS claims_count,
- aqorders.claimed_date AS claimed_date,
aqbudgets.budget_name AS budget,
aqbooksellers.name AS supplier,
aqbooksellers.id AS supplierid,
use Modern::Perl;
use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Acquisition::BasketGroups;
use Koha::Patrons;
return $self->create_items || C4::Context->preference('AcqCreateItem');
}
+=head3 estimated_delivery_date
+
+my $estimated_delivery_date = $basket->estimated_delivery_date;
+
+Return the estimated delivery date for this basket.
+
+It is calculated adding the delivery time of the vendor to the close date of this basket.
+
+Return implicit undef if the basket is not closed, or the vendor does not have a delivery time.
+
+=cut
+
+sub estimated_delivery_date {
+ my ( $self ) = @_;
+ return unless $self->closedate and $self->bookseller->deliverytime;
+ return dt_from_string($self->closedate)->add( days => $self->bookseller->deliverytime);
+}
+
+=head3 late_since_days
+
+my $number_of_days_late = $basket->late_since_days;
+
+Return the number of days the basket is late.
+
+Return implicit undef if the basket is not closed.
+
+=cut
+
+sub late_since_days {
+ my ( $self ) = @_;
+ return unless $self->closedate;
+ return dt_from_string->delta_days(dt_from_string($self->closedate))->delta_days();
+}
+
+=head3 authorizer
+
+my $authorizer = $basket->authorizer;
+
+Returns the patron who authorized/created this basket.
+
+=cut
+
+sub authorizer {
+ my ($self) = @_;
+ # FIXME We should use a DBIC rs, but the FK is missing
+ return unless $self->authorisedby;
+ return scalar Koha::Patrons->find($self->authorisedby);
+}
+
+
=head3 to_api
my $json = $basket->to_api;
use Koha::Acquisition::Baskets;
use Koha::Acquisition::Funds;
use Koha::Acquisition::Invoices;
+use Koha::Acquisition::Order::Claims;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Biblios;
return Koha::Biblio->_new_from_dbic( $biblio_rs );
}
+=head3 claims
+
+ my $claims = $order->claims
+
+Return the claims history for this order
+
+=cut
+
+sub claims {
+ my ( $self ) = @_;
+ my $claims_rs = $self->_result->aqorders_claims;
+ return Koha::Acquisition::Order::Claims->_new_from_dbic( $claims_rs );
+}
+
+=head3 claim
+
+ my $claim = $order->claim
+
+Do claim for this order
+
+=cut
+
+sub claim {
+ my ( $self ) = @_;
+ my $claim_rs = $self->_result->create_related('aqorders_claims', {});
+ return Koha::Acquisition::Order::Claim->_new_from_dbic($claim_rs);
+}
+
+=head3 claims_count
+
+my $nb_of_claims = $order->claims_count;
+
+This is the equivalent of $order->claims->count. Keeping it for retrocompatibilty.
+
+=cut
+
+sub claims_count {
+ my ( $self ) = @_;
+ return $self->claims->count;
+}
+
+=head3 claimed_date
+
+my $last_claim_date = $order->claimed_date;
+
+This is the equivalent of $order->claims->last->claimed_on. Keeping it for retrocompatibilty.
+
+=cut
+
+sub claimed_date {
+ my ( $self ) = @_;
+ my $last_claim = $self->claims->last;
+ return unless $last_claim;
+ return $last_claim->claimed_on;
+}
+
=head3 duplicate_to
my $duplicated_order = $order->duplicate_to($basket, [$default_values]);
=head2 Class methods
+=cut
+
=head2 Internal methods
=head3 _type
=cut
-=head3 type
+=head3 _type
=cut
return 'AqordersClaim';
}
+=head3 object_class
+
+=cut
+
sub object_class {
return 'Koha::Acquisition::Order::Claim';
}
use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Acquisition::Order;
use base qw(Koha::Objects);
=head1 API
+=head2 Class Methods
+
+=head3 filter_by_lates
+
+my $late_orders = $orders->filter_by_lates($params);
+
+Filter an order set given different parameters.
+
+This is the équivalent method of the former GetLateOrders C4 subroutine
+
+$params can be:
+
+=over
+
+=item C<delay> the number of days the basket has been closed
+
+=item C<bookseller_id> the bookseller id
+
+=item C<estimated_from> Beginning of the estimated delivery date
+
+=item C<estimated_to> End of the estimated delivery date
+
+=back
+
+=cut
+
+sub filter_by_lates {
+ my ( $self, $params ) = @_;
+ my $delay = $params->{delay};
+ my $bookseller_id = $params->{bookseller_id};
+ # my $branchcode = $params->{branchcode}; # FIXME do we really need this
+ my $estimated_from = $params->{estimated_from};
+ my $estimated_to = $params->{estimated_to};
+ my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+
+ my @delivery_time_conditions;
+ my $date_add = "DATE_ADD(basketno.closedate, INTERVAL COALESCE(booksellerid.deliverytime, booksellerid.deliverytime, 0) day)";
+ if ( defined $estimated_from or defined $estimated_to ) {
+ push @delivery_time_conditions, \[ "$date_add IS NOT NULL" ];
+ }
+ if ( defined $estimated_from ) {
+ push @delivery_time_conditions, \[ "$date_add >= ?", $dtf->format_date($estimated_from) ];
+ }
+ if ( defined $estimated_to ) {
+ push @delivery_time_conditions, \[ "$date_add <= ?", $dtf->format_date($estimated_to) ];
+ }
+ if ( defined $estimated_from and not defined $estimated_to ) {
+ push @delivery_time_conditions, \[ "$date_add <= ?", $dtf->format_date(dt_from_string) ];
+ }
+
+ $self->search(
+ {
+ -or => [
+ { datereceived => undef },
+ quantityreceived => { '<' => \'quantity' }
+ ],
+ 'basketno.closedate' => [
+ -and =>
+ { '!=' => undef },
+ {
+ defined $delay
+ ? (
+ '<=' => $dtf->format_date(
+ dt_from_string->subtract( days => $delay )
+ )
+ )
+ : ()
+ }
+ ],
+ 'datecancellationprinted' => undef,
+ (
+ $bookseller_id
+ ? ( 'basketno.booksellerid' => $bookseller_id )
+ : ()
+ ),
+
+ # ( $branchcode ? ('borrower.branchcode')) # FIXME branch is not a filter we may not need to implement this
+
+ ( @delivery_time_conditions ? ( -and => \@delivery_time_conditions ) : ()),
+ (
+ C4::Context->preference('IndependentBranches')
+ && !C4::Context->IsSuperLibrarian
+ ? ( 'borrower.branchcode' => C4::Context->userenv->{branch} )
+ : ()
+ ),
+
+ ( orderstatus => { '!=' => 'cancelled' } ),
+
+ },
+ {
+ '+select' => [\"DATE_ADD(basketno.closedate, INTERVAL COALESCE(booksellerid.deliverytime, booksellerid.deliverytime, 0) day)"],
+ '+as' => ['estimated_delivery_date'],
+ join => { 'basketno' => 'booksellerid' },
+ prefetch => {'basketno' => 'booksellerid'},
+ }
+ );
+}
+
=head2 Internal methods
=head3 _type (internal)
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds );
$line{holds} = $holds_count;
$line{holds_on_order} = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order};
+ $line{order_object} = $order;
}
my @orders;
for my $ordernumber ( @ordernumbers ) {
my $order = GetOrder $ordernumber;
+ my $order_object = Koha::Acquisition::Orders->find($ordernumber);
+ my $claims = $order_object->claims;
push @orders, {
orderdate => $order->{orderdate},
latesince => $order->{latesince},
budget => $order->{budget},
basketname => $order->{basketname},
basketno => $order->{basketno},
- claims_count => $order->{claims_count},
- claimed_date => $order->{claimed_date},
+ claims_count => $claims->count,
+ claimed_date => $claims->count ? $claims->last->claimed_on : undef,
internalnote => $order->{order_internalnote},
vendornote => $order->{order_vendornote},
isbn => $order->{isbn},
eval {
$err = SendAlerts( 'claimacquisition', \@ordernums, $input->param("letter_code") );
if ( not ref $err or not exists $err->{error} ) {
- AddClaim ( $_ ) for @ordernums;
+ Koha::Acquisition::Orders->find($_)->claim() for @ordernums;
}
};
$template->param(Supplier=>$supplierlist{$booksellerid}) if ($booksellerid);
$template->param(booksellerid=>$booksellerid) if ($booksellerid);
-@parameters =
- ( $delay, $booksellerid, $branch );
-if ($estimateddeliverydatefrom_dt) {
- push @parameters, $estimateddeliverydatefrom_dt->ymd();
-}
-else {
- push @parameters, undef;
-}
-if ($estimateddeliverydateto_dt) {
- push @parameters, $estimateddeliverydateto_dt->ymd();
-}
-my @lateorders = GetLateOrders( @parameters );
-
-my $total;
-foreach (@lateorders){
- $total += $_->{subtotal};
-}
+my $lateorders = Koha::Acquisition::Orders->filter_by_lates(
+ {
+ delay => $delay,
+ booksellerid => $booksellerid,
+ (
+ $estimateddeliverydatefrom_dt
+ ? ( estimated_from => $estimateddeliverydatefrom_dt )
+ : ()
+ ),
+ (
+ $estimateddeliverydateto_dt
+ ? ( estimated_to => $estimateddeliverydateto_dt )
+ : ()
+ )
+ }
+);
my $letters = GetLetters({ module => "claimacquisition" });
$template->param(ERROR_LOOP => \@errors) if (@errors);
$template->param(
- lateorders => \@lateorders,
+ lateorders => $lateorders,
delay => $delay,
letters => $letters,
estimateddeliverydatefrom => $estimateddeliverydatefrom,
estimateddeliverydateto => $estimateddeliverydateto,
- total => $total,
intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
);
output_html_with_http_headers $input, $cookie, $template->output;
</span>
</p>
[% END %]
+ [% SET claims = books_loo.order_object.claims %]
+ [% IF claims.count %]
+ <p>
+ This order has been claimed [% claims.count | html %] times. On [% FOR c IN claims %][% c.claimed_on | $KohaDates %][% UNLESS loop.last %], [% END %][% END %]
+ </p>
+ [% END %]
</td>
[% SET zero_regex = "^0{1,}\.?0{1,}[^1-9]" %] [%# 0 or 0.0 or 0.00 or 00 or 00.0 or 00.00 or 0.000 ... %]
[%# FIXME: use of a regexp is not ideal; bugs 9410 and 10929 suggest better way of handling this %]
[%- INCLUDE empty_line.inc -%]
[%- FOREACH o IN orders -%]
-"[% o.orderdate | html %] ([% o.latesince | html %] days)"[%- delimiter | html -%]
+"[% o.orderdate | $KohaDates %] ([% o.latesince | html %] days)"[%- delimiter | html -%]
"[% o.estimateddeliverydate | $KohaDates %]"[%- delimiter | html -%]
"[% o.supplier (o.supplierid) | html %]"[%- delimiter | html -%]
"[% o.title | html %] [% IF o.author %]Author: [% o.author | html %].[% END %][% IF o.publisher %]Published by: [% o.publisher | html %].[% END %]"[%- delimiter | html -%]
"[% o.unitpricesupplier | html %] x [% o.quantity_to_receive | html %] = [% o.subtotal | html %] ([% o.budget | html %])"[%- delimiter | html -%]
"[% o.basketname | html %] ([% o.basketno | html %])"[%- delimiter | html -%]
"[% o.claims_count | html %]"[%- delimiter | html -%]
-"[% o.claimed_date | html %]"[%- delimiter | html -%]
+"[% o.claimed_date | $KohaDates %]"[%- delimiter | html -%]
"[% o.internalnote | html %]"[%- delimiter | html -%]
"[% o.vendornote | html %]"[%- delimiter | html -%]
"[% o.isbn | html %]"
[% USE KohaDates %]
[% USE Branches %]
[% USE ColumnsSettings %]
+[% USE Price %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha › Acquisitions › Late orders</title>
[% IF info_claim %]
<div class="dialog message">Email has been sent.</div>
[% END %]
-[% IF ( lateorders ) %]
+[% IF lateorders.count %]
<form action="lateorders.pl" name="claim" method="post">
<input type="hidden" name="op" value="send_alert" />
<input type="hidden" name="delay" value="[% delay | html %]" />
</select>
</p>
[% END %]
+ [% SET total = 0 %]
<table id="late_orders">
<thead>
<tr>
[% FOREACH lateorder IN lateorders %]
<tr>
<td>
- <input type="checkbox" value="[% lateorder.ordernumber | html %]" data-booksellerid="[% lateorder.supplierid | html %]" name="ordernumber">
+ <input type="checkbox" value="[% lateorder.ordernumber | html %]" data-booksellerid="[% lateorder.basket.booksellerid | html %]" name="ordernumber">
</td>
<td>
[% lateorder.ordernumber | $raw %]
</td>
<td>
- <span title="[% lateorder.orderdate | html %]">[% lateorder.orderdate | $KohaDates %] ([% lateorder.latesince | html %] days)</span>
+ <span title="[% lateorder.basket.closedate | html %]">[% lateorder.basket.closedate | $KohaDates %] ([% lateorder.basket.late_since_days | html %] days)</span>
</td>
<td>
- [% IF ( lateorder.estimateddeliverydate ) %]
- <span title="[% lateorder.estimateddeliverydate | html %]">[% lateorder.estimateddeliverydate | $KohaDates %]</span>
- [% ELSE %]
- <span title="0000-00-00"></span>
+ [% SET estimated_delivery_date = lateorder.get_column('estimated_delivery_date') %]
+ [% IF estimated_delivery_date %]
+ <span title="[% estimated_delivery_date | html %]">[% estimated_delivery_date | $KohaDates %]</span>
[% END %]
</td>
<td>
- [% lateorder.supplier | html %]
- ([% lateorder.supplierid | html %])
+ [% lateorder.basket.bookseller.name | html %]
+ ([% lateorder.basket.bookseller.id | html %])
</td>
<td>
- <b>[% lateorder.title | html %]</b>
- [% IF ( lateorder.author ) %]<br/><i>Author:</i> [% lateorder.author | html %][% END %]
- [% IF ( lateorder.publisher ) %]
- <br/><i>Published by:</i> [% lateorder.publisher | html %]
- [% IF ( lateorder.publicationyear ) %]
- <i> in </i>[% lateorder.publicationyear | html %]
+ <b>[% lateorder.biblio.title | html %]</b>
+ [% IF ( lateorder.biblio.author ) %]<br/><i>Author:</i> [% lateorder.biblio.author | html %][% END %]
+ [% IF ( lateorder.biblio.biblioitem.publishercode ) %]
+ <br/><i>Published by:</i> [% lateorder.biblio.biblioitem.publishercode | html %]
+ [% IF ( lateorder.biblio.biblioitem.publicationyear ) %]
+ <i> in </i>[% lateorder.biblio.biblioitem.publicationyear | html %]
[% END %]
[% END %]
</td>
<td>
- [% lateorder.unitpricesupplier | html %]x[% lateorder.quantity | html %] =
- [% lateorder.subtotal | html %]
+ [% SET subtotal = (lateorder.quantity - lateorder.quantityreceived) * lateorder.rrp %]
+ [% SET total = total + subtotal %]
+ [% lateorder.rrp | html %]x[% lateorder.quantity - lateorder.quantityreceived | html %] = [% subtotal | $Price %]
</td>
<td>
[% IF ( CAN_user_acquisition_order_manage ) %]
- <a href="basket.pl?basketno=[% lateorder.basketno | uri %]" title="basket">[% lateorder.basketname | html %] ([% lateorder.basketno | html %])</a>
+ <a href="basket.pl?basketno=[% lateorder.basketno | uri %]" title="basket">[% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])</a>
[% ELSE %]
- [% lateorder.basketname | html %] ([% lateorder.basketno | html %])
+ [% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])
[% END %]
</td>
<td>
- [% IF ( lateorder.basketgroupid ) %]
+ [% IF ( lateorder.basket.basketgroupid ) %]
[% IF ( CAN_user_acquisition_group_manage ) %]
- <a href="basketgroup.pl?op=add&booksellerid=[% lateorder.supplierid | uri %]&basketgroupid=[% lateorder.basketgroupid | uri %]" title="basketgroup">[% lateorder.basketgroupname | html %] ([% lateorder.basketgroupid | html %])</a>
+ <a href="basketgroup.pl?op=add&booksellerid=[% lateorder.basket.booksellerid | uri %]&basketgroupid=[% lateorder.basket.basketgroupid | uri %]" title="basketgroup">[% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a>
[% ELSE %]
- [% lateorder.basketgroupname | html %] ([% lateorder.basketgroupid | html %])</a>
+ [% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a>
[% END %]
[% END %]
</td>
- <td>[% Branches.GetName( lateorder.branch ) | html %]
+ <td>[% Branches.GetName( lateorder.basket.authorizer.branchcode ) | html %]
</td>
- <td>[% lateorder.budget | html %]
+ <td>[% lateorder.fund.budget_name | html %]
</td>
- <td>[% lateorder.claims_count | html %]</td>
+ <td>[% lateorder.claims.count | html %]</td>
<td>
- [% IF ( lateorder.claimed_date ) %]
- <span title="[% lateorder.claimed_date | html %]">[% lateorder.claimed_date | $KohaDates %]</span>
- [% ELSE %]
- <span title="0000-00-00"></span>
+ [% FOR claim IN lateorder.claims %]
+ <span title="[% lateorder.claims.last.claimed_on | html %]">[% claim.claimed_on | $KohaDates %]</span>
[% END %]
</td>
<td>
- [% IF ( lateorder.internalnote ) %]
+ [% IF lateorder.order_internalnote %]
<p class="ordernote">
- <span id="internal-note-[% lateorder.ordernumber | html %]">[% lateorder.internalnote | html %]</span>
+ <span id="internal-note-[% lateorder.ordernumber | html %]">[% lateorder.order_internalnote | html %]</span>
<a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="internal" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=internal" title="Edit internal note">
<i class="fa fa-pencil"></i> Edit internal note
</a>
[% END %]
</td>
<td>
- [% IF ( lateorder.vendornote ) %]
+ [% IF lateorder.order_vendornote %]
<p class="ordernote">
- <span id="vendor-note-[% lateorder.ordernumber | html %]">[% lateorder.vendornote | html %]</span>
+ <span id="vendor-note-[% lateorder.ordernumber | html %]">[% lateorder.order_vendornote | html %]</span>
<a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="vendor" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=vendor" title="Edit vendor note">
<i class="fa fa-pencil"></i> Edit vendor note
</a>
</a>
[% END %]
</td>
- <td>[% lateorder.isbn | $raw %]</td>
+ <td>[% lateorder.biblio.biblioitem.isbn | $raw %]</td>
</tr>
[% END %]
</tbody>
<tfoot>
<tr>
<th colspan="6">Total</th>
- <th>[% total | html %]</th>
+ <th>[% total | $Price %]</th>
<th colspan="9"> </th>
</tr>
</tfoot>
</li>
<li>
<span class="label">Claims count: </span>
- [% order.claims_count | html %]
+ [% order.claims.count | html %]
</li>
<li>
<span class="label">Last claim date: </span>
- [% order.claimed_date | html %]
+ [% order.claims.last.claimed_on | html %]
</li>
</ol>
</fieldset>
ok( GetBudgetByOrderNumber( $ordernumbers[0] )->{'budget_id'} eq $budgetid,
"GetBudgetByOrderNumber returns expected budget" );
-my @lateorders = GetLateOrders(0);
-is( scalar grep ( $_->{basketno} eq $basketno, @lateorders ),
+my $lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
+is( $lateorders->search({ 'me.basketno' => $basketno })->count,
0, "GetLateOrders does not get orders from opened baskets" );
C4::Acquisition::CloseBasket($basketno);
-@lateorders = GetLateOrders(0);
-isnt( scalar grep ( $_->{basketno} eq $basketno, @lateorders ),
+$lateorders = Koha::Acquisition::Orders->filter_by_lates({ delay => 0 });
+isnt( $lateorders->search({ 'me.basketno' => $basketno })->count,
0, "GetLateOrders gets orders from closed baskets" );
-ok( !grep ( $_->{ordernumber} eq $ordernumbers[3], @lateorders ),
+is( $lateorders->search({ ordernumber => $ordernumbers[3] })->count, 0,
"GetLateOrders does not get cancelled orders" );
-ok( !grep ( $_->{ordernumber} eq $ordernumbers[4], @lateorders ),
+is( $lateorders->search({ ordernumber => $ordernumbers[4] })->count, 0,
"GetLateOrders does not get received orders" );
$search_orders = SearchOrders({
# Test AddClaim
#
-my $order = $lateorders[0];
-AddClaim( $order->{ordernumber} );
-my $neworder = GetOrder( $order->{ordernumber} );
+my $order = $lateorders->next;
+$order->claim();
is(
- $neworder->{claimed_date},
+ output_pref({ str => $order->claimed_date, dateformat => 'iso', dateonly => 1 }),
strftime( "%Y-%m-%d", localtime(time) ),
- "AddClaim : Check claimed_date"
+ "Koha::Acquisition::Order->claim: Check claimed_date"
);
my $order2 = Koha::Acquisition::Orders->find( $ordernumbers[1] )->unblessed;
"ModReceiveOrder only changes the supplied orders internal notes"
);
-$neworder = GetOrder($new_ordernumber);
+my $neworder = GetOrder($new_ordernumber);
is( $neworder->{'quantity'}, 2, '2 items on new order' );
is( $neworder->{'quantityreceived'},
2, 'Splitting up order received items on new order' );