@@ -, +, @@
* Create a new table 'aqorders_claims' (id, ordernumber, claimed_on)
* Remove the two columns from the aqorders table: claims_count and
claimed_date
* delay
* Estimated delivery date from/to
* Vendor
---
C4/Acquisition.pm | 2 -
Koha/Acquisition/Basket.pm | 51 +++++++++++
Koha/Acquisition/Order.pm | 57 +++++++++++++
Koha/Acquisition/Order/Claim.pm | 2 +
Koha/Acquisition/Order/Claims.pm | 6 +-
Koha/Acquisition/Orders.pm | 99 ++++++++++++++++++++++
acqui/basket.pl | 1 +
acqui/lateorders-export.pl | 6 +-
acqui/lateorders.pl | 38 ++++-----
.../intranet-tmpl/prog/en/modules/acqui/basket.tt | 6 ++
.../prog/en/modules/acqui/csv/lateorders.tt | 4 +-
.../prog/en/modules/acqui/lateorders.tt | 70 +++++++--------
.../prog/en/modules/acqui/showorder.tt | 4 +-
t/db_dependent/Acquisition.t | 23 +++--
14 files changed, 293 insertions(+), 76 deletions(-)
--- a/C4/Acquisition.pm
+++ a/C4/Acquisition.pm
@@ -1222,8 +1222,6 @@ sub GetOrder {
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,
--- a/Koha/Acquisition/Basket.pm
+++ a/Koha/Acquisition/Basket.pm
@@ -20,6 +20,7 @@ package Koha::Acquisition::Basket;
use Modern::Perl;
use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Acquisition::BasketGroups;
use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
@@ -71,6 +72,56 @@ sub effective_create_items {
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;
--- a/Koha/Acquisition/Order.pm
+++ a/Koha/Acquisition/Order.pm
@@ -22,6 +22,7 @@ use Carp qw( croak );
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;
@@ -200,6 +201,62 @@ sub biblio {
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]);
--- a/Koha/Acquisition/Order/Claim.pm
+++ a/Koha/Acquisition/Order/Claim.pm
@@ -31,6 +31,8 @@ Koha::Acquisition::Order::Claim - Koha Claim Object class
=head2 Class methods
+=cut
+
=head2 Internal methods
=head3 _type
--- a/Koha/Acquisition/Order/Claims.pm
+++ a/Koha/Acquisition/Order/Claims.pm
@@ -35,7 +35,7 @@ Koha::Cities - Koha Claim Object set class
=cut
-=head3 type
+=head3 _type
=cut
@@ -43,6 +43,10 @@ sub _type {
return 'AqordersClaim';
}
+=head3 object_class
+
+=cut
+
sub object_class {
return 'Koha::Acquisition::Order::Claim';
}
--- a/Koha/Acquisition/Orders.pm
+++ a/Koha/Acquisition/Orders.pm
@@ -21,6 +21,7 @@ use Carp;
use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
use Koha::Acquisition::Order;
use base qw(Koha::Objects);
@@ -31,6 +32,104 @@ Koha::Acquisition::Orders object set class
=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
+ This order has been claimed [% claims.count | html %] times. On [% FOR c IN claims %][% c.claimed_on | $KohaDates %][% UNLESS loop.last %], [% END %][% END %] +
+ [% END %] [% 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 %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/csv/lateorders.tt @@ -6,14 +6,14 @@ [%- 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 %]" --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt @@ -3,6 +3,7 @@ [% USE KohaDates %] [% USE Branches %] [% USE ColumnsSettings %] +[% USE Price %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %]