4 // ----------------------------------------------------------------
8 // Title: Payment Report
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_payment_report();
22 function getTransactions($supplier, $date)
24 $date = date2sql($date);
26 $sql = "SELECT ".TB_PREF."sys_types.type_name,
27 ".TB_PREF."supp_trans.supp_reference,
28 ".TB_PREF."supp_trans.due_date,
29 ".TB_PREF."supp_trans.trans_no,
30 ".TB_PREF."supp_trans.type,
31 (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst - ".TB_PREF."supp_trans.alloc) AS Balance,
32 (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst ) AS TranTotal
33 FROM ".TB_PREF."supp_trans,
35 WHERE ".TB_PREF."sys_types.type_id = ".TB_PREF."supp_trans.type
36 AND ".TB_PREF."supp_trans.supplier_id = '" . $supplier . "'
37 AND ".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst - ".TB_PREF."supp_trans.alloc != 0
38 AND ".TB_PREF."supp_trans.due_date <='" . $date . "'
39 ORDER BY ".TB_PREF."supp_trans.type,
40 ".TB_PREF."supp_trans.trans_no";
42 return db_query($sql, "No transactions were returned");
45 //----------------------------------------------------------------------------------------------------
47 function print_payment_report()
51 include_once($path_to_root . "reporting/includes/pdf_report.inc");
53 $to = $_POST['PARAM_0'];
54 $fromsupp = $_POST['PARAM_1'];
55 $tosupp = $_POST['PARAM_2'];
56 $currency = $_POST['PARAM_3'];
57 $comments = $_POST['PARAM_4'];
59 if ($fromsupp == null)
64 $dec = user_price_dec();
66 if ($currency == reserved_words::get_all())
69 $currency = _('Balances in Home Currency');
74 $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
76 $headers = array(_('Trans Type'), _('#'), _('Due Date'), '', '',
77 '', _('Total'), _('Balance'));
79 $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
81 $params = array( 0 => $comments,
82 1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''),
83 2 => array('text' => _('Supplier'), 'from' => get_supplier_name($fromsupp),
84 'to' => get_supplier_name($tosupp)),
85 3 => array( 'text' => _('Currency'),'from' => $currency, 'to' => ''));
87 $rep = new FrontReport(_('Payment Report'), "PaymentReport.pdf", user_pagesize());
90 $rep->Info($params, $cols, $headers, $aligns);
94 $grandtotal = array();
96 $sql = "SELECT supplier_id, supp_name AS name, curr_code, ".TB_PREF."payment_terms.terms FROM ".TB_PREF."suppliers, ".TB_PREF."payment_terms
97 WHERE supplier_id>=$fromsupp AND supplier_id<=$tosupp AND ".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.terms_indicator
99 $result = db_query($sql, "The customers could not be retrieved");
101 while ($myrow=db_fetch($result))
103 if (!$convert && $currency != $myrow['curr_code'])
106 $rep->TextCol(0, 6, $myrow['name'] . " - " . $myrow['terms']);
109 $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
110 $rep->TextCol(6, 7, $myrow['curr_code']);
116 $res = getTransactions($myrow['supplier_id'], $to);
117 if (db_num_rows($res)==0)
119 $rep->Line($rep->row + 4);
120 $total[0] = $total[1] = $total[2] = $total[3] = 0.0;
121 while ($trans=db_fetch($res))
124 $rep->TextCol(0, 1, $trans['type_name']);
125 $rep->TextCol(1, 2, $trans['supp_reference']);
126 $rep->TextCol(2, 3, sql2date($trans['due_date']));
127 $item[0] = Abs($trans['TranTotal']) * $rate;
128 $rep->TextCol(6, 7, number_format2($item[0], $dec));
129 $item[1] = $trans['Balance'] * $rate;
130 $rep->TextCol(7, 8, number_format2($item[1], $dec));
131 for ($i = 0; $i < 2; $i++)
133 $total[$i] += $item[$i];
134 $grandtotal[$i] += $item[$i];
137 $rep->Line($rep->row - 8);
139 $rep->TextCol(0, 3, _('Total'));
140 for ($i = 0; $i < 2; $i++)
142 $rep->TextCol($i + 6, $i + 7, number_format2($total[$i], $dec));
145 $rep->Line($rep->row - 4);
149 $rep->TextCol(0, 3, _('Grand Total'));
151 for ($i = 0; $i < 2; $i++)
152 $rep->TextCol($i + 6, $i + 7,number_format2($grandtotal[$i], $dec));
153 $rep->Line($rep->row - 4);