From 920d00f0776da5a044141f1f24445ae37dac3e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Fri, 2 Oct 2015 22:36:25 +0200 Subject: [PATCH] Bug 14946 - Remove C4::Dates from files acqui/*.pl This patch removes C4::Dates from: - acqui/histsearch.pl - acqui/invoice.pl - acqui/invoices.pl - acqui/orderreceive.pl - acqui/parcel.pl - acqui/parcels.pl - acqui/transferorder.pl To test: - Apply patch - Go to Home > Acquisitions > Invoices - Verify that Search filters work OK - Edit an invoice - Verify that Shipment date and Billing date display OK and edit / save is OK - Receive shipment for a vendor - Verify that Shipment date behaves OK and that you can filter list of shipents for this vendor - Transfer an item from a basket to another vendor Amended to make patch apply 25.10.2015/mv Amended following comment #6 Signed-off-by: Mirko Tietgen --- acqui/finishreceive.pl | 5 ++++ acqui/histsearch.pl | 28 ++++++++++---------- acqui/invoice.pl | 21 ++++++++++++--- acqui/invoices.pl | 67 +++++++++++++++++++++++++++++++++--------------- acqui/orderreceive.pl | 9 ++++--- acqui/parcel.pl | 11 ++++---- acqui/parcels.pl | 40 +++++++++++++++++++++++------ acqui/transferorder.pl | 1 - 8 files changed, 126 insertions(+), 56 deletions(-) diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index cc022b3..165fc3a 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -33,6 +33,7 @@ use C4::Items; use C4::Search; use Koha::Acquisition::Bookseller; +use Koha::DateUtils; use List::MoreUtils qw/any/; @@ -61,6 +62,10 @@ my $bookfund = $input->param("bookfund"); my $order = GetOrder($ordernumber); my $new_ordernumber = $ordernumber; +my $datereceived_dt = eval { dt_from_string( $datereceived) }; +$datereceived_dt = dt_from_string unless ( $datereceived_dt ); +$datereceived = output_pref( { dt => $datereceived_dt , dateonly => 1, dateformat => 'iso' } ) ; + #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME if ($quantityrec > $origquantityrec ) { my @received_items = (); diff --git a/acqui/histsearch.pl b/acqui/histsearch.pl index 5add9e1..2dd38db 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'); @@ -67,11 +67,11 @@ my $isbn = $input->param('isbn'); my $name = $input->param( 'name' ); my $ean = $input->param('ean'); my $basket = $input->param( 'basket' ); -my $basketgroupname = $input->param('basketgroupname'); +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 $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; my $budget = $input->param( 'budget' ); my $orderstatus = $input->param( 'orderstatus' ); my $ordernumber = $input->param( 'ordernumber' ); @@ -79,9 +79,8 @@ 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; + # Subtract one year if param was not defined + $from_placed_on->subtract(years => 1); } my $dbh = C4::Context->dbh; @@ -96,12 +95,13 @@ 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'); +my ( $from_iso, $to_iso ); + +if ( $input->param('from') ) { + $from_iso = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ); } -if ( $d = $input->param('iso') ) { - $to_iso = C4::Dates->new($d)->output('iso'); +if ( $input->param('to') ) { + $to_iso = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ); } my $order_loop; @@ -126,8 +126,8 @@ 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 $from_date = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ); +my $to_date = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ); my $budgetperiods = C4::Budgets::GetBudgetPeriods; my $bp_loop = $budgetperiods; diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 026fd13..fdd78c3 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -37,6 +37,7 @@ use C4::Budgets; use Koha::Acquisition::Bookseller; use Koha::Misc::Files; +use Koha::DateUtils; my $input = new CGI; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -76,14 +77,26 @@ 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'); + my $shipmentdate = ''; + my $billingdate = ''; + + if ( $input->param('shipmentdate') ) { + $shipmentdate = eval { dt_from_string( $input->param('shipmentdate') ) }; + $shipmentdate = output_pref( { dt => $shipmentdate, dateformat => 'iso', dateonly => 1 } ) if ( $shipmentdate ); + } + + if ( $input->param('billingdate') ) { + $billingdate = eval { dt_from_string( $input->param('billingdate') ) }; + $billingdate = output_pref( { dt => $billingdate, dateformat => 'iso', dateonly => 1 } ) if ( $billingdate ); + } + ModInvoice( invoiceid => $invoiceid, - shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), - billingdate => C4::Dates->new($billingdate)->output("iso"), + shipmentdate => $shipmentdate, + billingdate => $billingdate, shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipment_budget_id ); diff --git a/acqui/invoices.pl b/acqui/invoices.pl index 4909b78..3ee725a 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( @@ -64,11 +65,35 @@ my $branch = $input->param('branch'); my $op = $input->param('op'); my $invoices = []; + +my $shipmentdatefrom_iso = ''; +my $shipmentdateto_iso = ''; +my $billingdatefrom_iso = ''; +my $billingdateto_iso = ''; + + 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'); + + if ( $shipmentdatefrom ) { + $shipmentdatefrom_iso = eval { dt_from_string( $shipmentdatefrom ) }; + $shipmentdatefrom_iso = output_pref( { dt => $shipmentdatefrom_iso, dateformat => 'iso', dateonly => 1 } ) if ( $shipmentdatefrom_iso ); + } + + if ( $shipmentdateto ) { + $shipmentdateto_iso = eval { dt_from_string( $shipmentdateto) }; + $shipmentdateto_iso = output_pref( { dt => $shipmentdateto_iso, dateformat => 'iso', dateonly => 1 } ) if ( $shipmentdateto_iso ); + } + + if ( $billingdatefrom ) { + $billingdatefrom_iso = eval { dt_from_string( $billingdatefrom) }; + $billingdatefrom_iso = output_pref( { dt => $billingdatefrom_iso, dateformat => 'iso', dateonly => 1 } ) if ( $billingdatefrom_iso ); + } + + if ( $billingdateto ) { + $billingdateto_iso = eval { dt_from_string( $billingdateto) }; + $billingdateto_iso = output_pref( { dt => $billingdateto_iso, dateformat => 'iso', dateonly => 1 } ) if ( $billingdateto_iso ); + } + @{$invoices} = GetInvoices( invoicenumber => $invoicenumber, supplierid => $supplierid, @@ -130,22 +155,24 @@ foreach my $budget (@$budgets) { $template->{'VARS'}->{'budgets_loop'} = \@budgets_loop; $template->param( - do_search => ( $op and $op eq 'do_search' ) ? 1 : 0, - invoices => $invoices, - invoicenumber => $invoicenumber, - booksellerid => $supplierid, - suppliername => $suppliername, - billingdatefrom => $billingdatefrom, - billingdateto => $billingdateto, - isbneanissn => $isbneanissn, - title => $title, - author => $author, - publisher => $publisher, - publicationyear => $publicationyear, - branch => $branch, - branchname => $branchname, - suppliers_loop => $suppliers_loop, - branches_loop => $branches_loop, + do_search => ( $op and $op eq 'do_search' ) ? 1 : 0, + invoices => $invoices, + invoicenumber => $invoicenumber, + booksellerid => $supplierid, + suppliername => $suppliername, + shipmentdatefrom => $shipmentdatefrom_iso, + shipmentdateto => $shipmentdateto_iso, + billingdatefrom => $billingdatefrom_iso, + billingdateto => $billingdateto_iso, + isbneanissn => $isbneanissn, + title => $title, + author => $author, + publisher => $publisher, + publicationyear => $publicationyear, + branch => $branch, + branchname => $branchname, + suppliers_loop => $suppliers_loop, + branches_loop => $branches_loop, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index a75a624..b9cd516 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -74,8 +74,7 @@ use C4::Items; use C4::Biblio; use C4::Suggestions; -use Koha::Acquisition::Bookseller; -use Koha::DateUtils qw( dt_from_string ); +use Koha::DateUtils; my $input = new CGI; @@ -194,6 +193,9 @@ my $budget = GetBudget( $order->{budget_id} ); my $datereceived = $order->{datereceived} ? dt_from_string( $order->{datereceived} ) : dt_from_string; +my $orderentrydate = eval{ dt_from_string( $order->{entrydate} ); }; +$orderentrydate = output_pref( { dt => $orderentrydate, dateonly => 1 } ) if ( $orderentrydate ); + $template->param( AcqCreateItem => $AcqCreateItem, count => 1, @@ -203,6 +205,7 @@ $template->param( booksellerid => $order->{'booksellerid'}, freight => $freight, name => $bookseller->{'name'}, + date => $orderentrydate, title => $order->{'title'}, author => $order->{'author'}, copyrightdate => $order->{'copyrightdate'}, @@ -218,7 +221,7 @@ $template->param( membersurname => $member->{surname} || "", invoiceid => $invoice->{invoiceid}, invoice => $invoice->{invoicenumber}, - datereceived => $datereceived, + datereceived => output_pref( { dt => $datereceived, dateonly => 1, dateformat => 'iso' } ), order_internalnote => $order->{order_internalnote}, order_vendornote => $order->{order_vendornote}, suggestionid => $suggestion->{suggestionid}, diff --git a/acqui/parcel.pl b/acqui/parcel.pl index b66f609..f0223f8 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -64,10 +64,9 @@ 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::DateUtils; use Koha::Acquisition::Bookseller; use JSON; @@ -112,7 +111,7 @@ 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 $datereceived = dt_from_string; my @orders = @{ $invoice->{orders} }; my $countlines = scalar @orders; @@ -282,9 +281,9 @@ $template->param( invoiceid => $invoice->{invoiceid}, invoice => $invoice->{invoicenumber}, invoiceclosedate => $invoice->{closedate}, - datereceived => $datereceived->output('iso'), - invoicedatereceived => $datereceived->output('iso'), - formatteddatereceived => $datereceived->output(), + datereceived => eval { output_pref( { dt => $datereceived, dateonly => 1, dateformat =>'iso' } ) }, + invoicedatereceived => eval { output_pref( { dt => $datereceived, dateonly => 1, dateformat =>'iso' } ) }, + formatteddatereceived => eval { output_pref( { dt => $datereceived, dateonly => 1 } ) }, name => $bookseller->{'name'}, booksellerid => $bookseller->{id}, loop_received => \@loop_received, diff --git a/acqui/parcels.pl b/acqui/parcels.pl index 0126fc0..39e686f 100755 --- a/acqui/parcels.pl +++ b/acqui/parcels.pl @@ -89,6 +89,29 @@ my $resultsperpage = $input->param('resultsperpage'); my $op = $input->param('op'); $resultsperpage ||= 20; +my $datefrom_iso = ''; +my $dateto_iso = ''; + +if ( $datefrom ) { + $datefrom_iso = eval { dt_from_string( $datefrom ) }; + if ($datefrom_iso ) { + $datefrom_iso = output_pref( { dt => $datefrom_iso, dateformat => 'iso', dateonly => 1 } ); + } + else { + $datefrom = ''; + } +} + +if ( $dateto ) { + $dateto_iso = eval { dt_from_string( $dateto ) }; + if ($dateto_iso ) { + $dateto_iso = output_pref( { dt => $dateto_iso, dateformat => 'iso', dateonly => 1 } ); + } + else { + $dateto = ''; + } +} + our ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( { template_name => 'acqui/parcels.tt', query => $input, @@ -103,8 +126,9 @@ 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'); +if ( $shipmentdate ) { + $shipmentdate = eval { dt_from_string ( $shipmentdate ) }; + $shipmentdate = output_pref( { dt => $shipmentdate, dateonly => 1, dateformat => 'iso' } ) if ( $shipmentdate ); } if ( $op and $op eq 'new' ) { @@ -143,11 +167,11 @@ if ($op and $op eq 'confirm') { my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); my @parcels = GetInvoices( - supplierid => $booksellerid, - invoicenumber => $code, - ( $datefrom ? ( shipmentdatefrom => output_pref({ dt => dt_from_string($datefrom), dateformat => 'iso' }) ) : () ), - ( $dateto ? ( shipmentdateto => output_pref({ dt => dt_from_string($dateto), dateformat => 'iso' }) ) : () ), - order_by => $order + supplierid => $booksellerid, + invoicenumber => $code, + shipmentdatefrom => $datefrom_iso, + shipmentdateto => $dateto_iso, + order_by => $order ); my $count_parcels = @parcels; @@ -206,7 +230,7 @@ $template->param( dateto => $dateto, resultsperpage => $resultsperpage, name => $bookseller->{'name'}, - shipmentdate_today => C4::Dates->new()->output(), + shipmentdate_today => output_pref( { dt => dt_from_string, dateonly =>1 } ), booksellerid => $booksellerid, GST => C4::Context->preference('gist'), budgets => $budget_loop, diff --git a/acqui/transferorder.pl b/acqui/transferorder.pl index 0f58887..7b8412f 100755 --- a/acqui/transferorder.pl +++ b/acqui/transferorder.pl @@ -27,7 +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; -- 1.7.10.4