From: Janusz Dobrowolski Date: Mon, 21 Jun 2010 17:15:12 +0000 (+0000) Subject: Not fully credited invoice still can be credited (with invoice reallocation). X-Git-Tag: v2.4.2~19^2~837 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=7a9337f5114653a80da01fe3600790b93157b233;p=fa-stable.git Not fully credited invoice still can be credited (with invoice reallocation). --- diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index 6d4a6412..4b10acc6 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -405,12 +405,15 @@ function get_sql_for_customer_inquiry() // (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount))) , "; $sql .= "trans.alloc AS Allocated, ((trans.type = ".ST_SALESINVOICE.") - AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue + AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue, + Sum(line.quantity-line.qty_done) AS Outstanding FROM " .TB_PREF."debtor_trans as trans, " .TB_PREF."debtors_master as debtor, " - .TB_PREF."cust_branch as branch + .TB_PREF."cust_branch as branch, " + .TB_PREF."debtor_trans_details as line WHERE debtor.debtor_no = trans.debtor_no + AND trans.trans_no=line.debtor_trans_no AND trans.type=line.debtor_trans_type AND trans.tran_date >= '$date_after' AND trans.tran_date <= '$date_to' AND trans.branch_code = branch.branch_code"; @@ -450,6 +453,7 @@ function get_sql_for_customer_inquiry() trans.ov_freight + trans.ov_discount - trans.alloc > 0) "; } } + $sql .= " GROUP BY trans.trans_no, trans.type"; return $sql; } diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 40e67191..1d44fcb6 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -88,27 +88,13 @@ function write_credit_note(&$credit_note, $write_off_acc) void_trans_tax_details(ST_CUSTCREDIT, $credit_no); } if ($credit_invoice) { - $invoice_alloc_balance = get_debtor_trans_allocation_balance(ST_SALESINVOICE, $credit_invoice); update_customer_trans_version(get_parent_type(ST_CUSTCREDIT), $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(ST_SALESINVOICE, $credit_invoice, $allocate_amount); - update_debtor_trans_allocation(ST_CUSTCREDIT, $credit_no, $allocate_amount); // *** - add_cust_allocation($allocate_amount, ST_CUSTCREDIT, $credit_no, ST_SALESINVOICE, $credit_invoice); - // Exchange Variations Joe Hunt 2008-09-20 //////////////////////////////////////// + $total = $credit_note_total + $credit_note->freight_cost + $items_added_tax + + $freight_added_tax; - exchange_variation(ST_CUSTCREDIT, $credit_no, ST_SALESINVOICE, $credit_invoice, $credit_date, - $allocate_amount, PT_CUSTOMER); - - /////////////////////////////////////////////////////////////////////////// - - } - } + if (!credit_sales_invoice_allocate($credit_invoice, $credit_no, $total, $credit_date)) + return false; } $total = 0;