X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=reporting%2Frep102.php;h=22c2d8a96edf7859ca6283e4a92e3d7469ee56fe;hb=630e99edecc3eabe708a9e7bda94eaa60bf16db7;hp=d108f1c1551222b318064060bdf84a85eadb3888;hpb=d1babda7c01b314d35fb89f2d195553b55936532;p=fa-stable.git diff --git a/reporting/rep102.php b/reporting/rep102.php index d108f1c1..22c2d8a9 100644 --- a/reporting/rep102.php +++ b/reporting/rep102.php @@ -35,39 +35,30 @@ function get_invoices($customer_id, $to, $all=true) // Revomed allocated from sql if ($all) - $value = "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + " - .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + " - .TB_PREF."debtor_trans.ov_discount)"; - else - $value = "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + " - .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + " - .TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc)"; + $value = "(ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount)"; + else + $value = "(ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount - alloc)"; $sign = "IF(`type` IN(".implode(',', array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT,ST_JOURNAL))."), -1, 1)"; - $due = "IF (".TB_PREF."debtor_trans.type=".ST_SALESINVOICE.",".TB_PREF."debtor_trans.due_date,".TB_PREF."debtor_trans.tran_date)"; - $sql = "SELECT ".TB_PREF."debtor_trans.type, ".TB_PREF."debtor_trans.reference, - ".TB_PREF."debtor_trans.tran_date, + $due = "IF (type=".ST_SALESINVOICE.", due_date, tran_date)"; + + $sql = "SELECT type, reference, tran_date, $sign*$value as Balance, IF ((TO_DAYS('$todate') - TO_DAYS($due)) > 0,$sign*$value,0) AS Due, IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $PastDueDays1,$sign*$value,0) AS Overdue1, IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $PastDueDays2,$sign*$value,0) AS Overdue2 - FROM ".TB_PREF."debtors_master, - ".TB_PREF."debtor_trans + FROM ".TB_PREF."debtor_trans trans + + WHERE type <> ".ST_CUSTDELIVERY." + AND debtor_no = $customer_id + AND tran_date <= '$todate' + AND ABS(ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount) > " . FLOAT_COMP_DELTA; - WHERE ".TB_PREF."debtor_trans.type <> ".ST_CUSTDELIVERY." - AND ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."debtor_trans.debtor_no - AND ".TB_PREF."debtor_trans.debtor_no = $customer_id - AND ".TB_PREF."debtor_trans.tran_date <= '$todate' - AND ABS(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + " - .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + " - .TB_PREF."debtor_trans.ov_discount) > " . FLOAT_COMP_DELTA; if (!$all) - $sql .= "AND ABS(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + " - .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + " - .TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc) > " . FLOAT_COMP_DELTA; - $sql .= "ORDER BY ".TB_PREF."debtor_trans.tran_date"; + $sql .= "AND ABS(ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount - alloc) > " . FLOAT_COMP_DELTA; + $sql .= "ORDER BY tran_date"; - return db_query($sql, "The customer details could not be retrieved"); + return db_query($sql, "The customer transactions could not be retrieved"); } //---------------------------------------------------------------------------------------------------- @@ -76,14 +67,14 @@ function print_aged_customer_analysis() { global $path_to_root, $systypes_array, $SysPrefs; - $to = $_POST['PARAM_0']; - $fromcust = $_POST['PARAM_1']; - $currency = $_POST['PARAM_2']; - $show_all = $_POST['PARAM_3']; + $to = $_POST['PARAM_0']; + $fromcust = $_POST['PARAM_1']; + $currency = $_POST['PARAM_2']; + $show_all = $_POST['PARAM_3']; $summaryOnly = $_POST['PARAM_4']; - $no_zeros = $_POST['PARAM_5']; - $graphics = $_POST['PARAM_6']; - $comments = $_POST['PARAM_7']; + $no_zeros = $_POST['PARAM_5']; + $graphics = $_POST['PARAM_6']; + $comments = $_POST['PARAM_7']; $orientation = $_POST['PARAM_8']; $destination = $_POST['PARAM_9']; if ($destination) @@ -213,7 +204,7 @@ function print_aged_customer_analysis() } foreach ($trans as $i => $value) - $trans[$i] *= $rate; + $trans[$i] = (float)$trans[$i] * $rate; $str = array($trans["Balance"] - $trans["Due"], $trans["Due"]-$trans["Overdue1"], $trans["Overdue1"]-$trans["Overdue2"], @@ -254,7 +245,7 @@ function print_aged_customer_analysis() $pg->skin = $SysPrefs->graph_skin; $pg->built_in = false; $pg->latin_notation = ($SysPrefs->decseps[user_dec_sep()] != "."); - $filename = company_path(). "/pdf_files/". uniqid("").".png"; + $filename = company_path(). "/pdf_files/". random_id().".png"; $pg->display($filename, true); $w = $pg->width / 1.5; $h = $pg->height / 1.5;