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.tran_date,
29 ".TB_PREF."supp_trans.due_date,
30 ".TB_PREF."supp_trans.trans_no,
31 ".TB_PREF."supp_trans.type,
32 ".TB_PREF."supp_trans.rate,
33 (ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) - ".TB_PREF."supp_trans.alloc) AS Balance,
34 (ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) ) AS TranTotal
35 FROM ".TB_PREF."supp_trans,
37 WHERE ".TB_PREF."sys_types.type_id = ".TB_PREF."supp_trans.type
38 AND ".TB_PREF."supp_trans.supplier_id = '" . $supplier . "'
39 AND ABS(".TB_PREF."supp_trans.ov_amount) + ABS(".TB_PREF."supp_trans.ov_gst) - ".TB_PREF."supp_trans.alloc != 0
40 AND ".TB_PREF."supp_trans.tran_date <='" . $date . "'
41 ORDER BY ".TB_PREF."supp_trans.type,
42 ".TB_PREF."supp_trans.trans_no";
44 return db_query($sql, "No transactions were returned");
47 //----------------------------------------------------------------------------------------------------
49 function print_payment_report()
53 include_once($path_to_root . "reporting/includes/pdf_report.inc");
55 $to = $_POST['PARAM_0'];
56 $fromsupp = $_POST['PARAM_1'];
57 $currency = $_POST['PARAM_2'];
58 $comments = $_POST['PARAM_3'];
60 if ($fromsupp == reserved_words::get_all_numeric())
63 $from = get_supplier_name($fromsupp);
65 $dec = user_price_dec();
67 if ($currency == reserved_words::get_all())
70 $currency = _('Balances in Home Currency');
75 $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
77 $headers = array(_('Trans Type'), _('#'), _('Due Date'), '', '',
78 '', _('Total'), _('Balance'));
80 $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
82 $params = array( 0 => $comments,
83 1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''),
84 2 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''),
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(0,0);
96 $sql = "SELECT supplier_id, supp_name AS name, curr_code, ".TB_PREF."payment_terms.terms FROM ".TB_PREF."suppliers, ".TB_PREF."payment_terms
98 if ($fromsupp != reserved_words::get_all_numeric())
99 $sql .= "supplier_id=$fromsupp AND ";
100 $sql .= "".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.terms_indicator
102 $result = db_query($sql, "The customers could not be retrieved");
104 while ($myrow=db_fetch($result))
106 if (!$convert && $currency != $myrow['curr_code'])
109 $rep->TextCol(0, 6, $myrow['name'] . " - " . $myrow['terms']);
111 $rep->TextCol(6, 7, $myrow['curr_code']);
114 $res = getTransactions($myrow['supplier_id'], $to);
115 if (db_num_rows($res)==0)
117 $rep->Line($rep->row + 4);
118 $total[0] = $total[1] = 0.0;
119 while ($trans=db_fetch($res))
122 $rate = $trans['rate'];
126 $rep->TextCol(0, 1, $trans['type_name']);
127 $rep->TextCol(1, 2, $trans['supp_reference']);
128 if ($trans['type'] == 20)
129 $rep->TextCol(2, 3, sql2date($trans['due_date']));
131 $rep->TextCol(2, 3, sql2date($trans['tran_date']));
132 if ($trans['type'] != 20)
134 $trans['TranTotal'] = -$trans['TranTotal'];
135 $trans['Balance'] = -$trans['Balance'];
137 $item[0] = $trans['TranTotal'] * $rate;
138 $rep->TextCol(6, 7, number_format2($item[0], $dec));
139 $item[1] = $trans['Balance'] * $rate;
140 $rep->TextCol(7, 8, number_format2($item[1], $dec));
141 for ($i = 0; $i < 2; $i++)
143 $total[$i] += $item[$i];
144 $grandtotal[$i] += $item[$i];
147 $rep->Line($rep->row - 8);
149 $rep->TextCol(0, 3, _('Total'));
150 for ($i = 0; $i < 2; $i++)
152 $rep->TextCol($i + 6, $i + 7, number_format2($total[$i], $dec));
155 $rep->Line($rep->row - 4);
159 $rep->TextCol(0, 3, _('Grand Total'));
161 for ($i = 0; $i < 2; $i++)
162 $rep->TextCol($i + 6, $i + 7,number_format2($grandtotal[$i], $dec));
163 $rep->Line($rep->row - 4);