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 $currency = $_POST['PARAM_2'];
56 $comments = $_POST['PARAM_3'];
58 if ($fromsupp == reserved_words::get_all_numeric())
61 $from = get_supplier_name($fromsupp);
63 $dec = user_price_dec();
65 if ($currency == reserved_words::get_all())
68 $currency = _('Balances in Home Currency');
73 $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
75 $headers = array(_('Trans Type'), _('#'), _('Due Date'), '', '',
76 '', _('Total'), _('Balance'));
78 $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
80 $params = array( 0 => $comments,
81 1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''),
82 2 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''),
83 3 => array( 'text' => _('Currency'),'from' => $currency, 'to' => ''));
85 $rep = new FrontReport(_('Payment Report'), "PaymentReport.pdf", user_pagesize());
88 $rep->Info($params, $cols, $headers, $aligns);
92 $grandtotal = array(0,0);
94 $sql = "SELECT supplier_id, supp_name AS name, curr_code, ".TB_PREF."payment_terms.terms FROM ".TB_PREF."suppliers, ".TB_PREF."payment_terms
96 if ($fromsupp != reserved_words::get_all_numeric())
97 $sql .= "supplier_id=$fromsupp AND ";
98 $sql .= "".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.terms_indicator
100 $result = db_query($sql, "The customers could not be retrieved");
102 while ($myrow=db_fetch($result))
104 if (!$convert && $currency != $myrow['curr_code'])
107 $rep->TextCol(0, 6, $myrow['name'] . " - " . $myrow['terms']);
110 $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
111 $rep->TextCol(6, 7, $myrow['curr_code']);
117 $res = getTransactions($myrow['supplier_id'], $to);
118 if (db_num_rows($res)==0)
120 $rep->Line($rep->row + 4);
121 $total[0] = $total[1] = 0.0;
122 while ($trans=db_fetch($res))
125 $rep->TextCol(0, 1, $trans['type_name']);
126 $rep->TextCol(1, 2, $trans['supp_reference']);
127 $rep->TextCol(2, 3, sql2date($trans['due_date']));
128 $item[0] = Abs($trans['TranTotal']) * $rate;
129 $rep->TextCol(6, 7, number_format2($item[0], $dec));
130 $item[1] = $trans['Balance'] * $rate;
131 $rep->TextCol(7, 8, number_format2($item[1], $dec));
132 for ($i = 0; $i < 2; $i++)
134 $total[$i] += $item[$i];
135 $grandtotal[$i] += $item[$i];
138 $rep->Line($rep->row - 8);
140 $rep->TextCol(0, 3, _('Total'));
141 for ($i = 0; $i < 2; $i++)
143 $rep->TextCol($i + 6, $i + 7, number_format2($total[$i], $dec));
146 $rep->Line($rep->row - 4);
150 $rep->TextCol(0, 3, _('Grand Total'));
152 for ($i = 0; $i < 2; $i++)
153 $rep->TextCol($i + 6, $i + 7,number_format2($grandtotal[$i], $dec));
154 $rep->Line($rep->row - 4);