X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fdb%2Fsales_credit_db.inc;h=bb284f04d8326ff965e668ae0ff998a946147802;hb=cf015790b7363cfcf29b98c82d20787c8d703fc1;hp=f5d66505b42ee6c403c2cd468da2725bb8b08fd9;hpb=0c1bcd8ce3c089d7ddb3722a097f8fc8417f41e6;p=fa-stable.git diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index f5d66505..bb284f04 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -41,9 +41,17 @@ function write_credit_note($credit_note, $write_off_acc) $items_added_tax = 0; $freight_added_tax = 0; } + // 2006-06-14. If the Customer Branch AR Account is set to a Bank Account, + // the transaction will be settled at once. + if (is_bank_account($branch_data['receivables_account'])) + $alloc = $credit_note_total + $items_added_tax + $credit_note->freight_cost + $freight_added_tax; + else + $alloc = 0; // $sales_order=$invoice->order_no; //? // if (is_array($sales_order)) $sales_order = $sales_order[0]; //? + if (!isset($credit_note->order_no)) + $credit_note->order_no = 0; /*Now insert the Credit Note into the debtor_trans table with the allocations as calculated above*/ // all amounts in debtor's currency @@ -51,10 +59,9 @@ function write_credit_note($credit_note, $write_off_acc) $credit_note->Branch, $credit_date, $credit_note->reference, $credit_note_total, 0, $items_added_tax, $credit_note->freight_cost, $freight_added_tax, - $credit_note->default_sales_type, - $credit_note->order_no, $credit_invoice, $credit_note->ship_via - //, $credit_note->due_date - ); + $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); @@ -102,7 +109,7 @@ function write_credit_note($credit_note, $write_off_acc) $credit_line->line_price(), $line_tax, $credit_line->discount_percent, $credit_line->standard_cost, $trans_no==0 ? 0: $credit_line->id); - add_credit_movements_item(&$credit_note, &$credit_line, $credit_date, + add_credit_movements_item($credit_note, $credit_line, $credit_type, $line_taxfree_price+$line_tax, $credit_invoice); add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no, @@ -132,7 +139,7 @@ function write_credit_note($credit_note, $write_off_acc) add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'], $taxitem['rate'], $credit_note->tax_included, $taxitem['Value']); - add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0, + add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0, $taxitem['Value'], $credit_note->customer_id, "A tax GL posting for this credit note could not be inserted"); } @@ -153,7 +160,7 @@ function write_credit_note($credit_note, $write_off_acc) // Insert a stock movement coming back in to show the credit note and // a reversing stock movement to show the write off // -function add_credit_movements_item(&$credit_note, &$credit_line, $date_, +function add_credit_movements_item(&$credit_note, &$credit_line, $credit_type, $price, $credited_invoice=0) { @@ -229,13 +236,21 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, //Post sales transaction to GL credit sales - add_gl_trans_customer(11, $credit_no, $date_, $stock_gl_codes["sales_account"], 0, 0, + // 2008-06-14. If there is a Branch Sales Account, then override with this, + // else take the Item Sales Account + if ($branch_data['sales_account'] != "") + $sales_account = $branch_data['sales_account']; + else + $sales_account = $stock_gl_codes['sales_account']; + add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $stock_gl_codes["dimension_id"], + $stock_gl_codes["dimension2_id"], ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id, "The credit note GL posting could not be inserted"); if ($order_line->discount_percent != 0) { - add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"], 0, 0, + add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"], + $stock_gl_codes["dimension_id"], $stock_gl_codes["dimension2_id"], -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent), $order->customer_id, "The credit note discount GL posting could not be inserted");