From 519b163aef42dc16ca5ef29efc0af4181c09d178 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Wed, 17 Aug 2016 13:43:01 +0000
Subject: [PATCH] Bug 15164 - Allow editing of the invoice number after initial
 saving
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When you notice a typo in your invoice number after finishing with the
receiving process, the only way to correct it right now is in the
database - or by undoing all the steps and starting over.

It would be nice if the invoice number could be edited.

Test Plan:
1) Apply this patch
2) Browse to acqui/invoice.pl for an invoice
3) Note the new "Invoice number" field contains the existing invoice
4) Alter the invoice number
5) Save the invoice
6) Note the invoice number has been updated
7) Edit the invoice again
8) Attempt to save the invoice with an empty invoice number field
9) Note that you cannot save the invoice without having an invoice number

Followed test plan, works as expected.
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 acqui/invoice.pl                                         | 2 ++
 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/acqui/invoice.pl b/acqui/invoice.pl
index 08e3ee8..eaf3769 100755
--- a/acqui/invoice.pl
+++ b/acqui/invoice.pl
@@ -80,8 +80,10 @@ elsif ( $op && $op eq 'reopen' ) {
 elsif ( $op && $op eq 'mod' ) {
     my $shipmentcost       = $input->param('shipmentcost');
     my $shipment_budget_id = $input->param('shipment_budget_id');
+    my $invoicenumber      = $input->param('invoicenumber');
     ModInvoice(
         invoiceid             => $invoiceid,
+        invoicenumber         => $invoicenumber,
         shipmentdate          => output_pref( { str => scalar $input->param('shipmentdate'), dateformat => 'iso', dateonly => 1 } ),
         billingdate           => output_pref( { str => scalar $input->param('billingdate'),  dateformat => 'iso', dateonly => 1 } ),
         shipmentcost          => $shipmentcost,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt
index 8f8a317..39068b4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt
@@ -73,9 +73,15 @@
       <h1>Invoice: [% invoicenumber %]</h1>
 
       <p>Vendor: <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]">[% suppliername %]</a></p>
-        <form action="/cgi-bin/koha/acqui/invoice.pl" method="post">
+        <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
         <fieldset class="rows">
             <ol>
+            <li>
+                <label for="shipmentdate">Invoice number:</label>
+                <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber %]" class="required" required="required"/>
+                <span class="required">Required</span>
+            </li>
+
             <li><label for="shipmentdate">Shipment date:</label>
                     <input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | $KohaDates %]" readonly="readonly" class="datepicker" /></li>
 
-- 
2.8.1