From a3d855b06cd856f9a6e42190f5c4da4b3ea493d2 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Tue, 31 Mar 2015 14:13:03 +0200
Subject: [PATCH] Bug 8417: Make the order receive date editable

Currently the date of the order reception is the date of shipping date,
which is wrong.
This patch makes this date editable (with default is today).

Test plan:
1/ Create an order and receive it
2/ Confirm that you can edit the reception date and it's take into
account as the datereceived.

Signed-off-by: Aleisha <aleishaamohia@hotmail.com>
---
 C4/Acquisition.pm                                          |    8 +++++++-
 acqui/finishreceive.pl                                     |    2 +-
 acqui/orderreceive.pl                                      |   12 ++++--------
 .../intranet-tmpl/prog/en/modules/acqui/orderreceive.tt    |   10 +++++++---
 4 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm
index 83ec911..57f10f5 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -1387,7 +1387,13 @@ sub ModReceiveOrder {
     my $order_vendornote = $params->{order_vendornote};
 
     my $dbh = C4::Context->dbh;
-    $datereceived = C4::Dates->output('iso') unless $datereceived;
+    $datereceived = output_pref(
+        {
+            dt => ( $datereceived ? dt_from_string( $datereceived ) : dt_from_string ),
+            dateformat => 'iso',
+            dateonly => 1,
+        }
+    );
     my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber );
     if ($suggestionid) {
         ModSuggestion( {suggestionid=>$suggestionid,
diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl
index 5f0cf81..f035b33 100755
--- a/acqui/finishreceive.pl
+++ b/acqui/finishreceive.pl
@@ -48,10 +48,10 @@ my $origquantityrec  = $input->param('origquantityrec');
 my $quantityrec      = $input->param('quantityrec');
 my $quantity         = $input->param('quantity');
 my $unitprice        = $input->param('cost');
+my $datereceived     = $input->param('datereceived'),
 my $invoiceid        = $input->param('invoiceid');
 my $invoice          = GetInvoice($invoiceid);
 my $invoiceno        = $invoice->{invoicenumber};
-my $datereceived     = $invoice->{shipmentdate};
 my $booksellerid     = $input->param('booksellerid');
 my $cnt              = 0;
 my $ecost            = $input->param('ecost');
diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl
index 117f56c..c6750f2 100755
--- a/acqui/orderreceive.pl
+++ b/acqui/orderreceive.pl
@@ -67,7 +67,6 @@ use C4::Koha;   # GetKohaAuthorisedValues GetItemTypes
 use C4::Acquisition;
 use C4::Auth;
 use C4::Output;
-use C4::Dates qw/format_date/;
 use C4::Budgets qw/ GetBudget GetBudgetHierarchy CanUserUseBudget GetBudgetPeriods /;
 use C4::Members;
 use C4::Branch;    # GetBranches
@@ -76,7 +75,7 @@ use C4::Biblio;
 use C4::Suggestions;
 
 use Koha::Acquisition::Bookseller;
-
+use Koha::DateUtils qw( dt_from_string );
 
 my $input      = new CGI;
 
@@ -85,11 +84,8 @@ my $invoiceid    = $input->param('invoiceid');
 my $invoice      = GetInvoice($invoiceid);
 my $booksellerid   = $invoice->{booksellerid};
 my $freight      = $invoice->{shipmentcost};
-my $datereceived = $invoice->{shipmentdate};
 my $ordernumber  = $input->param('ordernumber');
 
-$datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
-
 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
 my $results;
 $results = SearchOrders({
@@ -196,6 +192,8 @@ my $member = GetMember( borrowernumber => $authorisedby );
 
 my $budget = GetBudget( $order->{budget_id} );
 
+my $datereceived = $order->{datereceived} ? dt_from_string( $order->{datereceived} ) : dt_from_string;
+
 $template->param(
     AcqCreateItem         => $AcqCreateItem,
     count                 => 1,
@@ -205,7 +203,6 @@ $template->param(
     booksellerid          => $order->{'booksellerid'},
     freight               => $freight,
     name                  => $bookseller->{'name'},
-    date                  => format_date($order->{entrydate}),
     title                 => $order->{'title'},
     author                => $order->{'author'},
     copyrightdate         => $order->{'copyrightdate'},
@@ -221,8 +218,7 @@ $template->param(
     membersurname         => $member->{surname} || "",
     invoiceid             => $invoice->{invoiceid},
     invoice               => $invoice->{invoicenumber},
-    datereceived          => $datereceived->output(),
-    datereceived_iso      => $datereceived->output('iso'),
+    datereceived          => $datereceived,
     order_internalnote    => $order->{order_internalnote},
     order_vendornote      => $order->{order_vendornote},
     suggestionid          => $suggestion->{suggestionid},
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
index 014f39b..dccaa9d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt
@@ -1,6 +1,8 @@
+[% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Receipt summary for : [% name %] [% IF ( invoice ) %]invoice, [% invoice %][% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
+[% INCLUDE 'calendar.inc' %]
 [% INCLUDE 'additem.js.inc' %]
 <script type="text/javascript" src="[% themelang %]/js/additem.js"></script>
 <script type="text/javascript" src="[% themelang %]/js/cataloging.js"></script>
@@ -257,14 +259,16 @@
     <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
     <input type="hidden" name="ordernumber" value="[% ordernumber %]" />
     <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
-    <input type="hidden" name="datereceived" value="[% datereceived_iso %]" />
     <input type="hidden" name="gstrate" value="[% gstrate %]" />
 	</div>
 	<div class="yui-u">
     <fieldset class="rows">
     <legend>Accounting details</legend>
-       <ol>
-       <li><label for="datereceived">Date received: </label><span> [% datereceived %] </span></li>
+        <ol>
+            <li>
+                <label for="datereceived">Date received: </label>
+                <input type="text" size="10" id="datereceived" name="datereceived" value="[% datereceived | $KohaDates %]" class="datepicker" />
+            </li>
        <li><label for="bookfund">Fund: </label><select id="bookfund" name="bookfund">
             <option value="">Keep current ([% budget_period_description %] - [% bookfund %])</option>
             [% FOREACH period IN budget_loop %]
-- 
1.7.10.4