Not fully credited invoice still can be credited (with invoice reallocation).
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 21 Jun 2010 17:15:12 +0000 (17:15 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 21 Jun 2010 17:15:12 +0000 (17:15 +0000)
sales/includes/db/cust_trans_db.inc
sales/includes/db/sales_credit_db.inc

index 6d4a64126fcdaa598ea4d5573af53a3c3889e5a9..4b10acc6e9f0bfa2f751924b25ae3d10ff29683f 100644 (file)
@@ -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;
 }
 
index 40e67191f4fab17faa6a904595e923a79672fea7..1d44fcb641380765a6047f2bb53e9fcf63a737f0 100644 (file)
@@ -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;