+ /*Now insert the Credit Note into the debtor_trans table with the allocations as calculated above*/
+ // all amounts in debtor's currency
+ $credit_no = write_customer_trans(11, $trans_no, $credit_note->customer_id,
+ $credit_note->Branch, $credit_date, $credit_note->reference,
+ $credit_note_total, 0, $items_added_tax,
+ $credit_note->freight_cost, $freight_added_tax,
+ $credit_note->sales_type,
+ $credit_note->order_no, $credit_invoice, $credit_note->ship_via,
+ null, $alloc); // 2008-06-14 extra $alloc
+
+ if ($trans_no==0) {
+ $credit_note->trans_no = array($credit_no=>0);
+ set_document_parent($credit_note);
+ } else {
+ delete_comments(11, $credit_no);
+ void_cust_allocations(11, $credit_no, $credit_date);
+ void_gl_trans(11, $credit_no, true);
+ void_stock_move(11, $credit_no);
+ void_customer_trans_tax_details(11, $credit_no);
+ }
+ if ($credit_invoice) {
+ $invoice_alloc_balance = get_DebtorTrans_allocation_balance(10, $credit_invoice);
+ update_customer_trans_version(get_parent_type(11), $credit_note->src_docs );
+ if ($invoice_alloc_balance > 0) { //the invoice is not already fully allocated
+ $total = $credit_note_total + $credit_note->freight_cost +
+ $items_added_tax + $freight_added_tax;
+
+ $allocate_amount = ($invoice_alloc_balance > $total) ? $total : $invoice_alloc_balance;
+ /*Now insert the allocation record if > 0 */
+ if ($allocate_amount != 0) {
+ update_debtor_trans_allocation(10, $credit_invoice, $allocate_amount);
+ update_debtor_trans_allocation(11, $credit_no, $allocate_amount); // ***
+ add_cust_allocation($allocate_amount, 11, $credit_no, 10, $credit_invoice);
+ // Exchange Variations Joe Hunt 2008-09-20 ////////////////////////////////////////
+
+ exchange_variation(11, $credit_no, 10, $credit_invoice, $credit_date,
+ $allocate_amount, payment_person_types::customer());
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ }
+ }
+ }