Bug 14946: Remove C4::Dates from acqui/* files

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 <veron@veron.ch>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2015-11-10 17:42:44 +00:00 committed by Tomas Cohen Arazi
parent bbc4eb4663
commit 94029916cc
10 changed files with 71 additions and 70 deletions

View File

@ -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,

View File

@ -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
);

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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(

View File

@ -137,11 +137,11 @@ var MSG_REMOVE_PATRON = _("Remove");
</li>
<li><label for="from">From: </label>
<input type="text" size="10" id="from" name="from" value="[% from_placed_on %]" class="datepickerfrom" />
<input type="text" size="10" id="from" name="from" value="[% from_placed_on | $KohaDates %]" class="datepickerfrom" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
<li><label for="to">To: </label>
<input type="text" size="10" id="to" name="to" value="[% to_placed_on %]" class="datepickerto" />
<input type="text" size="10" id="to" name="to" value="[% to_placed_on | $KohaDates %]" class="datepickerto" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
</ol>

View File

@ -153,12 +153,12 @@ $(document).ready(function() {
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="invoiceactions[% invoice.invoiceid %]">
<li><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid %]"><i class="fa fa-search"></i> Details</a></li>
[% IF invoice.closedate %]
<li><a href="invoice.pl?op=reopen&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]"><i class="fa fa-refresh"></i> Reopen</a></li>
<li><a href="invoice.pl?op=reopen&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]"><i class="fa fa-refresh"></i> Reopen</a></li>
[% ELSE %]
<li><a href="invoice.pl?op=close&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]"><i class="fa fa-times-circle"></i> Close</a></li>
<li><a href="invoice.pl?op=close&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]"><i class="fa fa-times-circle"></i> Close</a></li>
[% END %]
[% UNLESS invoice.receivedbiblios || invoice.receiveditems %]
<li><a href="invoice.pl?op=delete&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]"><i class="fa fa-remove"></i> Delete</a></li>
<li><a href="invoice.pl?op=delete&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]"><i class="fa fa-remove"></i> Delete</a></li>
[% END %]
</ul>
</div>
@ -214,19 +214,35 @@ $(document).ready(function() {
[% IF booksellerid %]
<li>Vendor: [% suppliername %]</li>
[% END %]
[% IF ( billingdatefrom ) %]
<li>Billing date:
[% IF ( billingdateto ) %]
From [% billingdatefrom %]
To [% billingdateto %]
[% IF shipmentdatefrom %]
<li>Shipment date:
[% IF shipmentdateto %]
From [% shipmentdatefrom | $KohaDates %]
To [% shipmentdateto | $KohaDates %]
[% ELSE %]
All since [% billingdatefrom %]
All since [% shipmentdatefrom | $KohaDates %]
[% END %]
</li>
[% ELSE %]
[% IF ( billingdateto ) %]
[% IF shipmentdateto %]
<li>Shipment date:
All until [% shipmentdateto | $KohaDates %]
</li>
[% END %]
[% END %]
[% IF billingdatefrom %]
<li>Billing date:
[% IF billingdateto %]
From [% billingdatefrom | $KohaDates %]
To [% billingdateto | $KohaDates %]
[% ELSE %]
All since [% billingdatefrom | $KohaDates %]
[% END %]
</li>
[% ELSE %]
[% IF billingdateto %]
<li>Billing date:
All until [% billingdateto %]
All until [% billingdateto | $KohaDates %]
</li>
[% END %]
[% END %]
@ -284,11 +300,11 @@ $(document).ready(function() {
<ol>
<li>
<label for="shipmentdatefrom">From:</label>
<input type="text" id="shipmentdatefrom" name="shipmentdatefrom" size="10" value="[% shipmentdatefrom %]" class="datepicker" />
<input type="text" id="shipmentdatefrom" name="shipmentdatefrom" size="10" value="[% shipmentdatefrom | $KohaDates %]" class="datepicker" />
</li>
<li>
<label for="shipmentdateto">To:</label>
<input type="text" id="shipmentdateto" name="shipmentdateto" size="10" value="[% shipmentdateto %]" class="datepicker" />
<input type="text" id="shipmentdateto" name="shipmentdateto" size="10" value="[% shipmentdateto | $KohaDates %]" class="datepicker" />
</li>
</ol>
</fieldset>
@ -299,11 +315,11 @@ $(document).ready(function() {
<ol>
<li>
<label for="billingdatefrom">From:</label>
<input type="text" id="billingdatefrom" name="billingdatefrom" size="10" value="[% billingdatefrom %]" class="datepicker" />
<input type="text" id="billingdatefrom" name="billingdatefrom" size="10" value="[% billingdatefrom | $KohaDates %]" class="datepicker" />
</li>
<li>
<label for="billingdateto">To:</label>
<input type="text" id="billingdateto" name="billingdateto" size="10" value="[% billingdateto %]" class="datepicker" />
<input type="text" id="billingdateto" name="billingdateto" size="10" value="[% billingdateto | $KohaDates %]" class="datepicker" />
</li>
</ol>
</fieldset>

View File

@ -1,9 +1,10 @@
[% USE Koha %]
[% USE KohaDates %]
[% USE Price %]
[% USE currency = format('%.2f') -%]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Acquisitions &rsaquo; [% IF ( date ) %]
Receipt summary for [% name %] [% IF ( invoice ) %]invoice [% invoice %][% END %] on [% formatteddatereceived %][% ELSE %]Receive orders from [% name %][% END %]</title>
Receipt summary for [% name %] [% IF ( invoice ) %]invoice [% invoice %][% END %] on [% datereceived | $KohaDates %][% ELSE %]Receive orders from [% name %][% END %]</title>
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'datatables.inc' %]
@ -133,12 +134,12 @@
[% INCLUDE 'acquisitions-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo;
[% IF ( datereceived ) %]
[% IF datereceived %]
Receipt summary for <i>[% name %]</i>
[% IF ( invoice ) %]
<i>[ [% invoice %] ]</i>
[% END %]
on <i>[% formatteddatereceived %]</i>
on <i>[% datereceived | $KohaDates %]</i>
[% ELSE %]
Receive orders from [% name %]
[% END %]
@ -160,8 +161,8 @@
</div>
[% END %]
<h1>
[% IF ( datereceived ) %]
Receipt summary for <i>[% name %]</i> [% IF ( invoice ) %] <i> [ [% invoice %] ] </i>[% END %] on <i>[% formatteddatereceived %]</i>
[% IF datereceived %]
Receipt summary for <i>[% name %]</i> [% IF ( invoice ) %] <i> [ [% invoice %] ] </i>[% END %] on <i>[% datereceived | $KohaDates %]</i>
[% ELSE %]
Receive orders from [% name %]
[% END %]
@ -204,7 +205,7 @@
[% UNLESS no_orders_to_display %]
<div id="acqui_receive_summary">
<p><strong>Invoice number:</strong> [% invoice %] <strong>Received by:</strong> [% loggedinusername %] <strong>On:</strong> [% formatteddatereceived %]</p>
<p><strong>Invoice number:</strong> [% invoice %] <strong>Received by:</strong> [% loggedinusername %] <strong>On:</strong> [% datereceived | $KohaDates %]</p>
</div>
[% UNLESS (invoiceclosedate) %]
<div id="acqui_receive_search">

View File

@ -172,7 +172,7 @@
</li> -->
<li>
<label for="shipmentdate">Shipment date: </label>
<input type="text" id="shipmentdate" name="shipmentdate" maxlength="10" size="10" value="[% shipmentdate_today %]" class="datepicker" />
<input type="text" id="shipmentdate" name="shipmentdate" maxlength="10" size="10" value="[% shipmentdate_today | $KohaDates %]" class="datepicker" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
<li>