X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=reporting%2Frep102.php;h=76cbe1a5805d4538872fa32329f5bfb89619e09e;hb=48589f9ce6c51bb25e2fa8ed83c57d9dfa485e44;hp=07847070452e10dfb4a78cf56434e6627d8676a8;hpb=ab5bb181d749dae6f681ee44cba86c9ef2d26c06;p=fa-stable.git diff --git a/reporting/rep102.php b/reporting/rep102.php index 07847070..76cbe1a5 100644 --- a/reporting/rep102.php +++ b/reporting/rep102.php @@ -33,61 +33,56 @@ function get_invoices($customer_id, $to, $all=true) $PastDueDays1 = get_company_pref('past_due_days'); $PastDueDays2 = 2 * $PastDueDays1; - // 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)"; - $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, + $sign = "IF(`type` IN(".implode(',', array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT))."), -1, 1)"; + + $value = "$sign*(IF(trans.prep_amount, trans.prep_amount, + ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount)) ".($all ? '' : "- trans.alloc").")"; + + $due = "IF (type=".ST_SALESINVOICE.", due_date, tran_date)"; + + $sql = "SELECT type, reference, tran_date, $value as Balance, IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$value,0) AS Due, IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $PastDueDays1,$value,0) AS Overdue1, IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $PastDueDays2,$value,0) AS Overdue2 - FROM ".TB_PREF."debtors_master, - ".TB_PREF."debtor_trans + FROM ".TB_PREF."debtor_trans trans - 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) > 0.004 "; - 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) > 0.004 "; - $sql .= "ORDER BY ".TB_PREF."debtor_trans.tran_date"; + WHERE type <> ".ST_CUSTDELIVERY." + AND debtor_no = $customer_id + AND tran_date <= '$todate' + AND ABS($value) > " . FLOAT_COMP_DELTA; - return db_query($sql, "The customer details could not be retrieved"); + $sql .= "ORDER BY tran_date"; + + return db_query($sql, "The customer transactions could not be retrieved"); } //---------------------------------------------------------------------------------------------------- function print_aged_customer_analysis() { - global $path_to_root, $systypes_array; + 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']; - $destination = $_POST['PARAM_8']; + $no_zeros = $_POST['PARAM_5']; + $graphics = $_POST['PARAM_6']; + $comments = $_POST['PARAM_7']; + $orientation = $_POST['PARAM_8']; + $destination = $_POST['PARAM_9']; if ($destination) include_once($path_to_root . "/reporting/includes/excel_report.inc"); else include_once($path_to_root . "/reporting/includes/pdf_report.inc"); + $orientation = ($orientation ? 'L' : 'P'); if ($graphics) { include_once($path_to_root . "/reporting/includes/class.graphic.inc"); - $pg = new graph(); + $pg = new chart($graphics); } if ($fromcust == ALL_TEXT) @@ -135,7 +130,9 @@ function print_aged_customer_analysis() if ($convert) $headers[2] = _('Currency'); - $rep = new FrontReport(_('Aged Customer Analysis'), "AgedCustomerAnalysis", user_pagesize()); + $rep = new FrontReport(_('Aged Customer Analysis'), "AgedCustomerAnalysis", user_pagesize(), 9, $orientation); + if ($orientation == 'L') + recalculate_cols($cols); $rep->Font(); $rep->Info($params, $cols, $headers, $aligns); @@ -171,7 +168,7 @@ function print_aged_customer_analysis() if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue; $rep->fontSize += 2; - $rep->TextCol(0, 2, $myrow['name']); + $rep->TextCol(0, 2, $myrow["name"]); if ($convert) $rep->TextCol(2, 3, $myrow['curr_code']); $rep->fontSize -= 2; $total[0] += ($custrec["Balance"] - $custrec["Due"]); @@ -194,15 +191,9 @@ function print_aged_customer_analysis() $rep->TextCol(0, 1, $systypes_array[$trans['type']], -2); $rep->TextCol(1, 2, $trans['reference'], -2); $rep->DateCol(2, 3, $trans['tran_date'], true, -2); - if ($trans['type'] == ST_CUSTCREDIT || $trans['type'] == ST_CUSTPAYMENT || $trans['type'] == ST_BANKDEPOSIT) - { - $trans['Balance'] *= -1; - $trans['Due'] *= -1; - $trans['Overdue1'] *= -1; - $trans['Overdue2'] *= -1; - } + 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"], @@ -223,29 +214,30 @@ function print_aged_customer_analysis() $rep->fontSize += 2; $rep->TextCol(0, 3, _('Grand Total')); $rep->fontSize -= 2; + $serie = array(); for ($i = 0; $i < count($total); $i++) { $rep->AmountCol($i + 3, $i + 4, $total[$i], $dec); if ($graphics && $i < count($total) - 1) { - $pg->y[$i] = abs($total[$i]); + $serie[] = abs($total[$i]); } } $rep->Line($rep->row - 8); if ($graphics) { - global $decseps, $graph_skin; - $pg->x = array(_('Current'), $nowdue, $pastdue1, $pastdue2); - $pg->title = $rep->title; - $pg->axis_x = _("Days"); - $pg->axis_y = _("Amount"); - $pg->graphic_1 = $to; - $pg->type = $graphics; - $pg->skin = $graph_skin; - $pg->built_in = false; - $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != "."); - $filename = company_path(). "/pdf_files/". uniqid("").".png"; - $pg->display($filename, true); + $pg->setStream('png'); + $pg->addSerie(_('Balances'), $serie); + $pg->setLabels(array(_('Current'), $nowdue, $pastdue1, $pastdue2)); + $pg->setTitle($rep->title); + $pg->setXTitle(_("Days")); + $pg->setYTitle(_("Amount")); + $pg->setDTitle(number_format2($total[4])); + $pg->setValues(true); + $pg->latin_notation = ($SysPrefs->decseps[user_dec_sep()] != "."); + $filename = company_path(). "/pdf_files/". random_id().".png"; + $pg->display($filename); + //sleep(5); $w = $pg->width / 1.5; $h = $pg->height / 1.5; $x = ($rep->pageWidth - $w) / 2; @@ -257,5 +249,3 @@ function print_aged_customer_analysis() $rep->NewLine(); $rep->End(); } - -?>