From 5b1af4d77617673cb242dc82d8ab8dd1217955cd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 10 Nov 2015 17:42:44 +0000 Subject: [PATCH] Bug 14946: Remove C4::Dates from acqui/* files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch replaces all use of C4::Dates with Koha::DateUtils, which is the best practice to follow. It also fixes a bug on the invoice search, the shipment date (from and to) were not passed correctly from one page to the other. Test plan: 1/ Search for orders using the different filters 2/ Create an invoice, try with setting and leaving empty the date fields. Default should be an undefined value (not today) 3/ Search for invoices and use the 4 different filters. Close and reopen invoices. The filters should be kept from one page to the other (not that it does not work with shipment date before this patch). 4/ Receive an order, on creating the invoice, the default date should be today. Signed-off-by: Marc VĂ©ron --- acqui/histsearch.pl | 32 +++++--------- acqui/invoice.pl | 7 ++-- acqui/invoices.pl | 20 +++++---- acqui/parcel.pl | 7 +--- acqui/parcels.pl | 8 ++-- acqui/transferorder.pl | 2 - .../prog/en/modules/acqui/histsearch.tt | 4 +- .../prog/en/modules/acqui/invoices.tt | 44 +++++++++++++------- .../intranet-tmpl/prog/en/modules/acqui/parcel.tt | 13 +++--- .../intranet-tmpl/prog/en/modules/acqui/parcels.tt | 2 +- 10 files changed, 70 insertions(+), 69 deletions(-) diff --git a/acqui/histsearch.pl b/acqui/histsearch.pl index 5add9e1..efb9468 100755 --- a/acqui/histsearch.pl +++ b/acqui/histsearch.pl @@ -55,10 +55,10 @@ use CGI qw ( -utf8 ); use C4::Auth; # get_template_and_user use C4::Output; use C4::Acquisition; -use C4::Dates; use C4::Debug; use C4::Branch; use C4::Koha; +use Koha::DateUtils; my $input = new CGI; my $title = $input->param( 'title'); @@ -70,18 +70,17 @@ my $basket = $input->param( 'basket' ); my $basketgroupname = $input->param('basketgroupname'); my $booksellerinvoicenumber = $input->param( 'booksellerinvoicenumber' ); my $do_search = $input->param('do_search') || 0; -my $from_placed_on = C4::Dates->new($input->param('from')); -my $to_placed_on = C4::Dates->new($input->param('to')); my $budget = $input->param( 'budget' ); my $orderstatus = $input->param( 'orderstatus' ); my $ordernumber = $input->param( 'ordernumber' ); my $search_children_too = $input->param( 'search_children_too' ); my @created_by = $input->param('created_by'); -if ( not $input->param('from') ) { - # FIXME Dirty but we can't sent a Date::Calc to C4::Dates ? - # We would use a function like Add_Delta_YM(-1, 0, 0); - $$from_placed_on{dmy_arrayref}[5] -= 1; +my $from_placed_on = eval { dt_from_string( $input->param('from') ) } || dt_from_string; +my $to_placed_on = eval { dt_from_string( $input->param('to') ) } || dt_from_string; +unless ( $input->param('from') ) { + # Fill the form with year-1 + $from_placed_on->subtract( years => 1 ); } my $dbh = C4::Context->dbh; @@ -96,14 +95,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my ( $from_iso, $to_iso, $d ); -if ( $d = $input->param('from') ) { - $from_iso = C4::Dates->new($d)->output('iso'); -} -if ( $d = $input->param('iso') ) { - $to_iso = C4::Dates->new($d)->output('iso'); -} - my $order_loop; # If we're supplied any value then we do a search. Otherwise we don't. if ($do_search) { @@ -113,8 +104,8 @@ if ($do_search) { isbn => $isbn, ean => $ean, name => $name, - from_placed_on => $from_iso, - to_placed_on => $to_iso, + from_placed_on => output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ), + to_placed_on => output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ), basket => $basket, booksellerinvoicenumber => $booksellerinvoicenumber, basketgroupname => $basketgroupname, @@ -126,9 +117,6 @@ if ($do_search) { ); } -my $from_date = $from_placed_on ? $from_placed_on->output('syspref') : undef; -my $to_date = $to_placed_on ? $to_placed_on->output('syspref') : undef; - my $budgetperiods = C4::Budgets::GetBudgetPeriods; my $bp_loop = $budgetperiods; for my $bp ( @{$budgetperiods} ) { @@ -152,8 +140,8 @@ $template->param( basketgroupname => $basketgroupname, ordernumber => $ordernumber, search_children_too => $search_children_too, - from_placed_on => $from_date, - to_placed_on => $to_date, + from_placed_on => $from_placed_on, + to_placed_on => $to_placed_on, orderstatus => $orderstatus, budget_id => $budget, bp_loop => $bp_loop, diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 026fd13..f56afcc 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -36,6 +36,7 @@ use C4::Acquisition; use C4::Budgets; use Koha::Acquisition::Bookseller; +use Koha::DateUtils; use Koha::Misc::Files; my $input = new CGI; @@ -76,14 +77,12 @@ elsif ( $op && $op eq 'reopen' ) { } } elsif ( $op && $op eq 'mod' ) { - my $shipmentdate = $input->param('shipmentdate'); - my $billingdate = $input->param('billingdate'); my $shipmentcost = $input->param('shipmentcost'); my $shipment_budget_id = $input->param('shipment_budget_id'); ModInvoice( invoiceid => $invoiceid, - shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), - billingdate => C4::Dates->new($billingdate)->output("iso"), + shipmentdate => output_pref( { str => $input->param('shipmentdate'), dateformat => 'iso', dateonly => 1 } ), + billingdate => output_pref( { str => $input->param('billingdate'), dateformat => 'iso', dateonly => 1 } ), shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipment_budget_id ); diff --git a/acqui/invoices.pl b/acqui/invoices.pl index 4909b78..48adb80 100755 --- a/acqui/invoices.pl +++ b/acqui/invoices.pl @@ -36,6 +36,7 @@ use C4::Output; use C4::Acquisition qw/GetInvoices/; use C4::Branch qw/GetBranches/; use C4::Budgets; +use Koha::DateUtils; my $input = CGI->new; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -63,19 +64,20 @@ my $publicationyear = $input->param('publicationyear'); my $branch = $input->param('branch'); my $op = $input->param('op'); +$shipmentdatefrom and $shipmentdatefrom = eval { dt_from_string( $shipmentdatefrom ) }; +$shipmentdateto and $shipmentdateto = eval { dt_from_string( $shipmentdateto ) }; +$billingdatefrom and $billingdatefrom = eval { dt_from_string( $billingdatefrom ) }; +$billingdateto and $billingdateto = eval { dt_from_string( $billingdateto ) }; + my $invoices = []; if ( $op and $op eq 'do_search' ) { - my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output('iso'); - my $shipmentdateto_iso = C4::Dates->new($shipmentdateto)->output('iso'); - my $billingdatefrom_iso = C4::Dates->new($billingdatefrom)->output('iso'); - my $billingdateto_iso = C4::Dates->new($billingdateto)->output('iso'); @{$invoices} = GetInvoices( invoicenumber => $invoicenumber, supplierid => $supplierid, - shipmentdatefrom => $shipmentdatefrom_iso, - shipmentdateto => $shipmentdateto_iso, - billingdatefrom => $billingdatefrom_iso, - billingdateto => $billingdateto_iso, + shipmentdatefrom => $shipmentdatefrom ? output_pref( { str => $shipmentdatefrom, dateformat => 'iso' } ) : undef, + shipmentdateto => $shipmentdateto ? output_pref( { str => $shipmentdateto, dateformat => 'iso' } ) : undef, + billingdatefrom => $billingdatefrom ? output_pref( { str => $billingdatefrom, dateformat => 'iso' } ) : undef, + billingdateto => $billingdateto ? output_pref( { str => $billingdateto, dateformat => 'iso' } ) : undef, isbneanissn => $isbneanissn, title => $title, author => $author, @@ -135,6 +137,8 @@ $template->param( invoicenumber => $invoicenumber, booksellerid => $supplierid, suppliername => $suppliername, + shipmentdatefrom => $shipmentdatefrom, + shipmentdateto => $shipmentdateto, billingdatefrom => $billingdatefrom, billingdateto => $billingdateto, isbneanissn => $isbneanissn, diff --git a/acqui/parcel.pl b/acqui/parcel.pl index b66f609..6dee09a 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -64,11 +64,11 @@ use C4::Biblio; use C4::Items; use CGI qw ( -utf8 ); use C4::Output; -use C4::Dates qw/format_date format_date_in_iso/; use C4::Suggestions; use C4::Reserves qw/GetReservesFromBiblionumber/; use Koha::Acquisition::Bookseller; +use Koha::DateUtils; use JSON; @@ -112,7 +112,6 @@ unless( $invoiceid and $invoice->{invoiceid} ) { my $booksellerid = $invoice->{booksellerid}; my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; -my $datereceived = C4::Dates->new(); my @orders = @{ $invoice->{orders} }; my $countlines = scalar @orders; @@ -282,9 +281,7 @@ $template->param( invoiceid => $invoice->{invoiceid}, invoice => $invoice->{invoicenumber}, invoiceclosedate => $invoice->{closedate}, - datereceived => $datereceived->output('iso'), - invoicedatereceived => $datereceived->output('iso'), - formatteddatereceived => $datereceived->output(), + datereceived => dt_from_string, name => $bookseller->{'name'}, booksellerid => $bookseller->{id}, loop_received => \@loop_received, diff --git a/acqui/parcels.pl b/acqui/parcels.pl index 0126fc0..ffcbb66 100755 --- a/acqui/parcels.pl +++ b/acqui/parcels.pl @@ -100,12 +100,10 @@ our ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( ); my $invoicenumber = $input->param('invoice'); -my $shipmentdate = $input->param('shipmentdate'); my $shipmentcost = $input->param('shipmentcost'); my $shipmentcost_budgetid = $input->param('shipmentcost_budgetid'); -if($shipmentdate) { - $shipmentdate = C4::Dates->new($shipmentdate)->output('iso'); -} +my $shipmentdate = $input->param('shipmentdate'); +$shipmentdate and $shipmentdate = output_pref({ str => $shipmentdate, dateformat => 'iso', dateonly => 1 }); if ( $op and $op eq 'new' ) { if ( C4::Context->preference('AcqWarnOnDuplicateInvoice') ) { @@ -206,7 +204,7 @@ $template->param( dateto => $dateto, resultsperpage => $resultsperpage, name => $bookseller->{'name'}, - shipmentdate_today => C4::Dates->new()->output(), + shipmentdate_today => dt_from_string, booksellerid => $booksellerid, GST => C4::Context->preference('gist'), budgets => $budget_loop, diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl index 0f58887..5ce3890 100755 --- a/acqui/transferorder.pl +++ b/acqui/transferorder.pl @@ -27,8 +27,6 @@ use C4::Output; use C4::Context; use C4::Acquisition; use C4::Members; -use C4::Dates qw/format_date_in_iso/; -use Date::Calc qw/Today/; my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt index 8cf89cc..988fd27 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt @@ -137,11 +137,11 @@ var MSG_REMOVE_PATRON = _("Remove");
  • - +
    [% INCLUDE 'date-format.inc' %]
  • - +
    [% INCLUDE 'date-format.inc' %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt index 167591b..e458af1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt @@ -153,12 +153,12 @@ $(document).ready(function() { @@ -214,19 +214,35 @@ $(document).ready(function() { [% IF booksellerid %]
  • Vendor: [% suppliername %]
  • [% END %] - [% IF ( billingdatefrom ) %] + [% IF shipmentdatefrom %] +
  • Shipment date: + [% IF shipmentdateto %] + From [% shipmentdatefrom | $KohaDates %] + To [% shipmentdateto | $KohaDates %] + [% ELSE %] + All since [% shipmentdatefrom | $KohaDates %] + [% END %] +
  • + [% ELSE %] + [% IF shipmentdateto %] +
  • Shipment date: + All until [% shipmentdateto | $KohaDates %] +
  • + [% END %] + [% END %] + [% IF billingdatefrom %]
  • Billing date: - [% IF ( billingdateto ) %] - From [% billingdatefrom %] - To [% billingdateto %] + [% IF billingdateto %] + From [% billingdatefrom | $KohaDates %] + To [% billingdateto | $KohaDates %] [% ELSE %] - All since [% billingdatefrom %] + All since [% billingdatefrom | $KohaDates %] [% END %]
  • [% ELSE %] - [% IF ( billingdateto ) %] + [% IF billingdateto %]
  • Billing date: - All until [% billingdateto %] + All until [% billingdateto | $KohaDates %]
  • [% END %] [% END %] @@ -284,11 +300,11 @@ $(document).ready(function() {
    1. - +
    2. - +
    @@ -299,11 +315,11 @@ $(document).ready(function() {
    1. - +
    2. - +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt index a244f5f..05de288 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -1,9 +1,10 @@ [% USE Koha %] +[% USE KohaDates %] [% USE Price %] [% USE currency = format('%.2f') -%] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › [% IF ( date ) %] - Receipt summary for [% name %] [% IF ( invoice ) %]invoice [% invoice %][% END %] on [% formatteddatereceived %][% ELSE %]Receive orders from [% name %][% END %] + Receipt summary for [% name %] [% IF ( invoice ) %]invoice [% invoice %][% END %] on [% datereceived | $KohaDates %][% ELSE %]Receive orders from [% name %][% END %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'datatables.inc' %] @@ -133,12 +134,12 @@ [% INCLUDE 'acquisitions-search.inc' %] [% END %]

    - [% IF ( datereceived ) %] - Receipt summary for [% name %] [% IF ( invoice ) %] [ [% invoice %] ] [% END %] on [% formatteddatereceived %] + [% IF datereceived %] + Receipt summary for [% name %] [% IF ( invoice ) %] [ [% invoice %] ] [% END %] on [% datereceived | $KohaDates %] [% ELSE %] Receive orders from [% name %] [% END %] @@ -204,7 +205,7 @@ [% UNLESS no_orders_to_display %]
    -

    Invoice number: [% invoice %] Received by: [% loggedinusername %] On: [% formatteddatereceived %]

    +

    Invoice number: [% invoice %] Received by: [% loggedinusername %] On: [% datereceived | $KohaDates %]

    [% UNLESS (invoiceclosedate) %]