Additional access control related ui helpers added: check_edit_access, access_post...
[fa-stable.git] / sales / includes / db / sales_invoice_db.inc
index 2032bcf058d0a55e1f0ab9d97aa81b4e3ba923d5..c38d69542bedb45202737421c31a1f5ef1edc989 100644 (file)
@@ -32,6 +32,8 @@ function write_sales_invoice(&$invoice)
 
        $customer = get_customer($invoice->customer_id);
 
+       add_new_exchange_rate($customer['curr_code'], $date_, $invoice->ex_rate);
+
        // offer price values without freight costs
        $items_total = $invoice->get_items_total_dispatch();
        $freight_tax = $invoice->get_shipping_tax();
@@ -88,7 +90,8 @@ function write_sales_invoice(&$invoice)
 
        if ($trans_no == 0) {
                $invoice->trans_no = array($invoice_no=>0);
-       }
+       } else
+               move_trans_attachments(ST_SALESINVOICE, $trans_no, $invoice_no);
 
        $total = 0;
        // for prepayments use deferred income account if set
@@ -196,8 +199,8 @@ function write_sales_invoice(&$invoice)
                                _('Cash invoice').' '.$invoice_no);
                        add_cust_allocation($amount, ST_CUSTPAYMENT, $pmtno, ST_SALESINVOICE, $invoice_no);
 
-                       update_debtor_trans_allocation(ST_SALESINVOICE, $invoice_no, $amount);
-                       update_debtor_trans_allocation(ST_CUSTPAYMENT, $pmtno, $amount);
+                       update_debtor_trans_allocation(ST_SALESINVOICE, $invoice_no);
+                       update_debtor_trans_allocation(ST_CUSTPAYMENT, $pmtno);
                }
        }
 //_vd($allocs);
@@ -242,7 +245,7 @@ function void_sales_invoice($type, $type_no)
                $deliveries = get_sales_parent_numbers($type, $type_no);
 
                if ($deliveries !== 0) {
-                       if (count($deliveries) == 1 && get_reference(ST_CUSTDELIVERY, $deliveries[0]) == "auto")
+                       if ($type == ST_SALESINVOICE && count($deliveries) == 1 && get_reference(ST_CUSTDELIVERY, $deliveries[0]) == "auto")
                        {
                                void_sales_delivery(ST_CUSTDELIVERY, $deliveries[0], false);
                                $date_ = Today();
@@ -252,7 +255,7 @@ function void_sales_invoice($type, $type_no)
                        else
                        {
                                $srcdetails = get_sales_parent_lines($type, $type_no);
-                                       while ($row = db_fetch($srcdetails)) {
+                               while ($row = db_fetch($srcdetails)) {
                                        update_parent_line($type, $row['id'], -$row['quantity']);
                                }
                        }
@@ -261,6 +264,8 @@ function void_sales_invoice($type, $type_no)
        // clear details after they've been reversed in the sales order
        void_customer_trans_details($type, $type_no);
 
+       void_stock_move($type, $type_no); // in case of credit note with return
+
        void_trans_tax_details($type, $type_no);
 
        void_cust_allocations($type, $type_no);