From 487d4f1f6ccd3e22c05469f679bf5d0685914611 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Stephan=20K=C3=B6hler?= <s.koehler@linet-services.de>
Date: Thu, 26 Jan 2006 16:34:11 +0000
Subject: [PATCH] Merge von 833,836-838 aus unstable: Lieferdatum in Rechnungen
 -833 Lieferdatum in Rechnungen. Lieferdatum wird nicht auf automatisch
 gesetzt und ist zur Zeit auch nicht vom Programm erfordert. Es wird bei der
 Konvertierung von und in Auftraege beibehalten. -836 Aenderung von
 write_trigger zusammen mit einem Aufruf im alten Format hat einen
 Javascript-Fehler beim Waren erfassen erzeugt. Fixed. -837 Export des
 Lieferdatums fuer gedruckte Rechnungen. Die Variable ist <%deliverydate%>.
 Anbei Rechnungen mit Lieferdatum in tex und html. (Sollte sich jemand
 anschauen der weiss wie die auszusehen haben) -838 Doku Update zu r837

---
 SL/Form.pm                        | 36 ++++++++++---------------------
 SL/IS.pm                          |  8 ++++---
 SL/OE.pm                          |  4 ++++
 bin/mozilla/ic.pl                 |  3 +--
 bin/mozilla/io.pl                 |  4 ++--
 bin/mozilla/is.pl                 | 14 ++++++++++--
 bin/mozilla/oe.pl                 |  2 ++
 doc/latex-template-variablen.html |  2 +-
 sql/Pg-upgrade-2.1.1-2.1.2.sql    |  3 +++
 sql/lx-office.sql                 |  1 +
 templates/German-invoice.html     |  3 +++
 templates/German-invoice.tex      |  1 +
 12 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/SL/Form.pm b/SL/Form.pm
index c70e35ab1..f82a70f66 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -412,14 +412,14 @@ function fokus(){document.$self->{fokus}.focus();}
   $main::lxdebug->leave_sub();
 }
 
-# write Trigger JavaScript-Code ($qty = 1 - only one Trigger)
+# write Trigger JavaScript-Code ($qty = quantity of Triggers)
+# changed it to accept an arbitrary number of triggers - sschoeling
 sub write_trigger {
   $main::lxdebug->enter_sub();
 
-  my ($self,         $myconfig, $qty,
-      $inputField_1, $align_1,  $button_1,
-      $inputField_2, $align_2,  $button_2)
-    = @_;
+  my $self     = shift;
+  my $myconfig = shift;
+  my $qty      = shift;
 
   # set dateform for jsscript
   # default
@@ -448,35 +448,21 @@ sub write_trigger {
     }
   }
 
-  $trigger_1 = qq|
+  while ($#_ >= 2) {
+    push @triggers, qq|
        Calendar.setup(
       {
-      inputField : "$inputField_1",
+      inputField : "|.(shift).qq|",
       ifFormat :"$ifFormat",
-      align : "$align_1", 
-      button : "$button_1"
+      align : "|.(shift).qq|", 
+      button : "|.(shift).qq|"
       }
       );
        |;
-
-  if ($qty == 2) {
-    $trigger_2 = qq|
-       Calendar.setup(
-       {
-      inputField : "$inputField_2",
-      ifFormat :"$ifFormat",
-      align : "$align_2", 
-      button : "$button_2"
-      }
-      );
-        |;
   }
   $jsscript = qq|
        <script type="text/javascript">
-       <!--
-       $trigger_1
-       $trigger_2
-        //-->
+       <!--|.join("", @triggers).qq|//-->
         </script>
         |;
 
diff --git a/SL/IS.pm b/SL/IS.pm
index 9c4f50b1a..a5b00f0d2 100644
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -805,8 +805,9 @@ sub post_invoice {
   # set values which could be empty to 0
   $form->{terms}       *= 1;
   $form->{taxincluded} *= 1;
-  my $datepaid = ($form->{paid})    ? qq|'$form->{datepaid}'| : "NULL";
-  my $duedate  = ($form->{duedate}) ? qq|'$form->{duedate}'|  : "NULL";
+  my $datepaid     = ($form->{paid})         ? qq|'$form->{datepaid}'| : "NULL";
+  my $duedate      = ($form->{duedate})      ? qq|'$form->{duedate}'|  : "NULL";
+  my $deliverydate = ($form->{deliverydate}) ? qq|'$form->{deliverydate}'| : "NULL";
 
   # fill in subject if there is none
   $form->{subject} = qq|$form->{label} $form->{invnumber}|
@@ -839,6 +840,7 @@ Message: $form->{message}\r| if $form->{message};
               paid = $form->{paid},
 	      datepaid = $datepaid,
 	      duedate = $duedate,
+              deliverydate = $deliverydate,
 	      invoice = '1',
 	      shippingpoint = '$form->{shippingpoint}',
 	      shipvia = '$form->{shipvia}',
@@ -1164,7 +1166,7 @@ sub retrieve_invoice {
 
     # retrieve invoice
     $query = qq|SELECT a.invnumber, a.ordnumber, a.quonumber, a.cusordnumber,
-                a.transdate AS invdate, a.paid,
+                a.transdate AS invdate, a.deliverydate, a.paid,
                 a.shippingpoint, a.shipvia, a.terms, a.notes, a.intnotes,
 		a.duedate, a.taxincluded, a.curr AS currency,
 		a.employee_id, e.name AS employee
diff --git a/SL/OE.pm b/SL/OE.pm
index 535006598..4662f5046 100644
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -628,6 +628,10 @@ sub retrieve {
 
   ($form->{currency}) = split /:/, $form->{currencies};
 
+  # set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure 
+  # we come from invoices, feel free.
+  $form->{reqdate} = $form->{deliverydate} if ($form->{deliverydate} and $form->{callback} =~ /action=ar_transactions/);
+
   if ($form->{id} or @ids) {
 
     # retrieve order for single id
diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl
index df6e2cab6..f6134db52 100644
--- a/bin/mozilla/ic.pl
+++ b/bin/mozilla/ic.pl
@@ -2228,8 +2228,7 @@ sub form_header {
 
     #write Trigger
     $jsscript =
-      Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1", "",
-                          "", "");
+      Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1");
   } else {
 
     # without JavaScript Calendar
diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl
index 31322f088..690162348 100644
--- a/bin/mozilla/io.pl
+++ b/bin/mozilla/io.pl
@@ -1586,7 +1586,7 @@ sub print_form {
   }
 
   map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, 1) }
-    ("${inv}date", "${due}date", "shippingdate");
+    ("${inv}date", "${due}date", "shippingdate", "deliverydate");
 
   @a = qw(name street zipcode city country);
 
@@ -1616,7 +1616,7 @@ sub print_form {
   push @a,
     qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptoemail shippingpoint shipvia company address signature employee contact department_1 department_2);
 
-  push @a, ("${inv}date", "${due}date", email, cc, bcc);
+  push @a, ("${inv}date", "${due}date", "deliverydate", email, cc, bcc);
 
   $form->format_string(@a);
 
diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl
index 314f68bc1..3e7704972 100644
--- a/bin/mozilla/is.pl
+++ b/bin/mozilla/is.pl
@@ -334,11 +334,17 @@ sub form_header {
        <td width="4"><input type=button name=duedate id="trigger2" value=|
       . $locale->text('button') . qq|></td></td>
      |;
+    $button3 = qq|
+       <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
+       <td width="4"><input type=button name=deliverydate id="trigger3" value=|
+      . $locale->text('button') . qq|></td></td>
+     |;
 
     #write Trigger
     $jsscript =
-      Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
-                          "duedate", "BL", "trigger2");
+      Form->write_trigger(\%myconfig, "3", "invdate",      "BL", "trigger1",
+                                           "duedate",      "BL", "trigger2",
+                                           "deliverydate", "BL", "trigger3");
   } else {
 
     # without JavaScript Calendar
@@ -470,6 +476,10 @@ sub form_header {
 		<th align=right>| . $locale->text('Due Date') . qq|</th>
                 $button2
 	      </tr>
+	      <tr>
+		<th align=right>| . $locale->text('Delivery Date') . qq|</th>
+                $button3
+	      </tr>
 	      <tr>
 		<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
 		<td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl
index f9907cbf2..d05745b8e 100644
--- a/bin/mozilla/oe.pl
+++ b/bin/mozilla/oe.pl
@@ -1809,6 +1809,8 @@ sub invoice {
     $form->isblank("ordnumber", $locale->text('Order Number missing!')) if ( +{ map { $form->{"ordnumber_$_"}, 1 } ( 1 .. $form->{rowcount}-1 ) }->{''} );
     $form->isblank("transdate", $locale->text('Order Date missing!'))   if ( +{ map { $form->{"transdate_$_"}, 1 } ( 1 .. $form->{rowcount}-1 ) }->{''} );
 
+    # also copy deliverydate from the order
+    $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
   } else {
     $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
     $form->isblank("transdate", $locale->text('Quotation Date missing!'));
diff --git a/doc/latex-template-variablen.html b/doc/latex-template-variablen.html
index e19eb6dad..516cbc0e6 100644
--- a/doc/latex-template-variablen.html
+++ b/doc/latex-template-variablen.html
@@ -474,7 +474,7 @@ td {
     <td>Angebotsnummer</td>
    </tr>
    <tr>
-    <td><code>shippingdate</code></td>
+    <td><code>deliverydate</code></td>
     <td>Lieferdatum</td>
    </tr>
    <tr>
diff --git a/sql/Pg-upgrade-2.1.1-2.1.2.sql b/sql/Pg-upgrade-2.1.1-2.1.2.sql
index 5887b357c..068ee2319 100644
--- a/sql/Pg-upgrade-2.1.1-2.1.2.sql
+++ b/sql/Pg-upgrade-2.1.1-2.1.2.sql
@@ -256,5 +256,8 @@ alter table invoice add column cusordnumber text;
 --
 -- add unqiue constraint to project
 ALTER TABLE project ADD constraint project_projectnumber_key UNIQUE(projectnumber);
+--
+-- add column deliverydate to ar
+ALTER TABLE ar ADD COLUMN deliverydate date;
 
 update defaults set version = '2.1.2';
diff --git a/sql/lx-office.sql b/sql/lx-office.sql
index 76267264b..9caa7bd04 100644
--- a/sql/lx-office.sql
+++ b/sql/lx-office.sql
@@ -285,6 +285,7 @@ CREATE TABLE "ar" (
 	"paid" numeric (15,5),
 	"datepaid" date,
 	"duedate" date,
+	"deliverydate" date,
 	"invoice" boolean DEFAULT 'f',
 	"shippingpoint" text,
 	"terms" smallint DEFAULT 0,
diff --git a/templates/German-invoice.html b/templates/German-invoice.html
index 249a0ac25..2858f4f08 100644
--- a/templates/German-invoice.html
+++ b/templates/German-invoice.html
@@ -49,6 +49,9 @@
       <th align=right>Nummer</th><td>&nbsp;</td><td><%invnumber%></td></tr>
     </tr>
   
+    <tr>
+      <th align=right>Lieferdatum</th><td>&nbsp;</td><td><%deliverydate%></td></tr>
+    </tr>
 <!--
     <tr>
       <th align=right>Clerk:</th><td>&nbsp;</td><td><%username%></td>
diff --git a/templates/German-invoice.tex b/templates/German-invoice.tex
index bd27f77ac..9f93e032b 100644
--- a/templates/German-invoice.tex
+++ b/templates/German-invoice.tex
@@ -88,6 +88,7 @@
 \begin{tabular}[t]{l@{\hspace{0.3cm}}l}
   \textbf{Datum} & <%invdate%> \\
   \textbf{Nummer} & <%invnumber%> \\
+  \textbf{Lieferdatum} & <%deliverydate%> \\
 \end{tabular}
 
 \vspace{1cm}
-- 
2.20.1