X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fdb%2Fsales_invoice_db.inc;h=a80232ecd5c78b16ce33623b45f8bbf8aec5c8d1;hb=6c40a3be4a79826087d7abbdd11b483f19decc2a;hp=c17e9214e361e936664bbdf93a68c736765d4edc;hpb=b2a9c105e368f6e4fdb35477665edeff13fb574b;p=fa-stable.git diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index c17e9214..a80232ec 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -84,7 +84,6 @@ function write_sales_invoice(&$invoice) } else { $prepaid_factor = 1; } - // write_customer_trans have to be called after optional void_cust_allocations above $invoice_no = write_customer_trans(ST_SALESINVOICE, $trans_no, $invoice->customer_id, $invoice->Branch, $date_, $invoice->reference, $items_total, 0, @@ -249,8 +248,9 @@ function void_sales_invoice($type, $type_no) if ($deliveries !== 0) { if ($type == ST_SALESINVOICE && count($deliveries) == 1 && get_reference(ST_CUSTDELIVERY, $deliveries[0]) == "auto") { + $trans = get_customer_trans($deliveries[0], ST_CUSTDELIVERY); void_sales_delivery(ST_CUSTDELIVERY, $deliveries[0], false); - $date_ = Today(); + $date_ = sql2date($trans['tran_date']); add_audit_trail(ST_CUSTDELIVERY, $deliveries[0], $date_, _("Voided.")); add_voided_entry(ST_CUSTDELIVERY, $deliveries[0], $date_, ""); } @@ -258,7 +258,7 @@ function void_sales_invoice($type, $type_no) { $srcdetails = get_sales_parent_lines($type, $type_no); while ($row = db_fetch($srcdetails)) { - update_parent_line($type, $row['id'], -$row['quantity']); + update_parent_line($type, $row['id'], -$row['qty_done']); } } } @@ -291,7 +291,7 @@ function get_cust_prepayment_invoice_factor($trans_no) LEFT JOIN ".TB_PREF."sales_orders so ON so.trans_type=".ST_SALESORDER." AND so.order_no=dt.order_ WHERE dt.type=".ST_SALESINVOICE." AND trans_no=".db_escape($trans_no); $row = db_fetch(db_query($sql, 'cannot retrieve prepaid invoice factor')); - return $row[0]; + return is_array($row) ? $row[0] : false; } /* @@ -299,18 +299,14 @@ function get_cust_prepayment_invoice_factor($trans_no) */ function prepaid_invoice_remainder($order) { - $sql = "SELECT so.total - IFNULL(SUM(inv.prep_amount),0) FROM " - .TB_PREF."sales_orders so, - ".TB_PREF."debtor_trans inv, - ".TB_PREF."payment_terms pt + $sql = "SELECT so.total - SUM(IFNULL(inv.prep_amount,0)) FROM " + .TB_PREF."sales_orders so + LEFT JOIN ".TB_PREF."payment_terms pt ON so.payment_terms=pt.terms_indicator AND pt.days_before_due = -1 + LEFT JOIN ".TB_PREF."debtor_trans inv ON inv.type=".ST_SALESINVOICE ." AND inv.order_=so.order_no WHERE so.order_no=".db_escape($order) ." AND so.trans_type=".ST_SALESORDER - ." AND inv.type=".ST_SALESINVOICE - ." AND inv.order_=so.order_no" - ." AND so.payment_terms=pt.terms_indicator" - ." AND inv.payment_terms=pt.terms_indicator" - ." AND pt.days_before_due = -1"; - + ." AND so.payment_terms=pt.terms_indicator"; + $result = db_fetch(db_query($sql, "cannot find final invoice value")); return $result[0] ? $result[0] : 0; }