[0000643] Error during delivery note read for edition.
[fa-stable.git] / sales / customer_invoice.php
index 560ea687c582334bba89c7bde5a0acb015346d4c..287c61709328cb1adc7aa2f570326a5174229358 100644 (file)
@@ -110,6 +110,7 @@ if ( (isset($_GET['DeliveryNumber']) && ($_GET['DeliveryNumber'] > 0) )
        } else {
                $src = array($_GET['DeliveryNumber']);
        }
+
        /*read in all the selected deliveries into the Items cart  */
        $dn = new Cart(ST_CUSTDELIVERY, $src, true);
 
@@ -119,12 +120,6 @@ if ( (isset($_GET['DeliveryNumber']) && ($_GET['DeliveryNumber'] > 0) )
                die ("<br><b>" . _("There are no delivered items with a quantity left to invoice. There is nothing left to invoice.") . "</b>");
        }
 
-       $dn->trans_type = ST_SALESINVOICE;
-       $dn->src_docs = $dn->trans_no;
-       $dn->trans_no = 0;
-       $dn->reference = $Refs->get_next(ST_SALESINVOICE);
-       $dn->due_date = get_invoice_duedate($dn->payment, $dn->document_date);
-
        $_SESSION['Items'] = $dn;
        copy_from_cart();
 
@@ -328,6 +323,16 @@ if (isset($_POST['process_invoice']) && check_data()) {
        }
 }
 
+if(list_updated('payment')) {
+       $order = &$_SESSION['Items'];
+       $order->payment = get_post('payment');
+       $order->payment_terms = get_payment_terms($order->payment);
+       $order->due_date = get_invoice_duedate($order->payment, $order->document_date);
+       if ($order->payment_terms['cash_sale']) {
+               $_POST['Location'] = $order->Location = $order->pos['pos_location'];
+               $order->location_name = $order->pos['location_name'];
+       }
+}
 // find delivery spans for batch invoice display
 $dspans = array();
 $lastdn = ''; $spanlen=1;
@@ -367,7 +372,6 @@ if ($dim > 0)
 label_cells(_("Customer"), $_SESSION['Items']->customer_name, "class='tableheader2'");
 label_cells(_("Branch"), get_branch_name($_SESSION['Items']->Branch), "class='tableheader2'");
 if ($_SESSION['Items']->pos['credit_sale'] || $_SESSION['Items']->pos['cash_sale']) {
- // editable payment type
        $paymcat = !$_SESSION['Items']->pos['cash_sale'] ? PM_CREDIT :
                (!$_SESSION['Items']->pos['credit_sale'] ? PM_CASH : PM_ANY);
        label_cells(_("Payment terms:"), sale_payment_list('payment', $paymcat),