2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 $page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
14 'SA_SUPPTRANSVIEW' : 'SA_SUPPBULKREP';
15 // ----------------------------------------------------------------
19 // Title: Purchase Remittance
20 // ----------------------------------------------------------------
23 include_once($path_to_root . "/includes/session.inc");
24 include_once($path_to_root . "/includes/date_functions.inc");
25 include_once($path_to_root . "/includes/data_checks.inc");
26 include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
28 //----------------------------------------------------------------------------------------------------
32 //----------------------------------------------------------------------------------------------------
33 function get_remittance($type, $trans_no)
35 $sql = "SELECT trans.*,
36 (trans.ov_amount+trans.ov_gst) AS Total,
38 supplier.supp_name, supplier.supp_account_no,
39 supplier.curr_code, supplier.payment_terms, supplier.gst_no AS tax_id,
42 .TB_PREF."supp_trans trans,"
43 .TB_PREF."suppliers supplier
44 WHERE trans.supplier_id = supplier.supplier_id
45 AND trans.type = ".db_escape($type)."
46 AND trans.trans_no = ".db_escape($trans_no);
47 $result = db_query($sql, "The remittance cannot be retrieved");
48 if (db_num_rows($result) == 0)
50 return db_fetch($result);
53 function print_remittances()
55 global $path_to_root, $systypes_array;
57 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
59 $from = $_POST['PARAM_0'];
60 $to = $_POST['PARAM_1'];
61 $currency = $_POST['PARAM_2'];
62 $email = $_POST['PARAM_3'];
63 $comments = $_POST['PARAM_4'];
64 $orientation = $_POST['PARAM_5'];
66 if (!$from || !$to) return;
68 $orientation = ($orientation ? 'L' : 'P');
69 $dec = user_price_dec();
71 $fno = explode("-", $from);
72 $tno = explode("-", $to);
73 $from = min($fno[0], $tno[0]);
74 $to = max($fno[0], $tno[0]);
76 $cols = array(4, 85, 150, 225, 275, 360, 450, 515);
78 // $headers in doctext.inc
79 $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
81 $params = array('comments' => $comments);
83 $cur = get_company_Pref('curr_default');
86 $rep = new FrontReport(_('REMITTANCE'), "RemittanceBulk", user_pagesize(), 9, $orientation);
87 if ($orientation == 'L')
88 recalculate_cols($cols);
90 for ($i = $from; $i <= $to; $i++)
92 if ($fno[0] == $tno[0])
93 $types = array($fno[1]);
95 $types = array(ST_BANKPAYMENT, ST_SUPPAYMENT, ST_SUPPCREDIT);
96 foreach ($types as $j)
98 $myrow = get_remittance($j, $i);
101 if ($currency != ALL_TEXT && $myrow['curr_code'] != $currency) {
104 $res = get_bank_trans($j, $i);
105 $baccount = db_fetch($res);
106 $params['bankaccount'] = $baccount['bank_act'];
110 $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
111 $rep->title = _('REMITTANCE');
112 $rep->filename = "Remittance" . $i . ".pdf";
114 $rep->currency = $cur;
116 $rep->Info($params, $cols, null, $aligns);
118 $contacts = get_supplier_contacts($myrow['supplier_id'], 'invoice');
119 $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_SUPPAYMENT, $contacts);
120 $rep->SetHeaderType('Header2');
122 $result = get_allocatable_to_supp_transactions($myrow['supplier_id'], $myrow['trans_no'], $myrow['type']);
124 $doctype = ST_SUPPAYMENT;
126 $total_allocated = 0;
127 $rep->TextCol(0, 4, _("As advance / full / part / payment towards:"), -2);
130 while ($myrow2=db_fetch($result))
132 $rep->TextCol(0, 1, $systypes_array[$myrow2['type']], -2);
133 $rep->TextCol(1, 2, $myrow2['supp_reference'], -2);
134 $rep->TextCol(2, 3, sql2date($myrow2['tran_date']), -2);
135 $rep->TextCol(3, 4, sql2date($myrow2['due_date']), -2);
136 $rep->AmountCol(4, 5, $myrow2['Total'], $dec, -2);
137 $rep->AmountCol(5, 6, $myrow2['Total'] - $myrow2['alloc'], $dec, -2);
138 $rep->AmountCol(6, 7, $myrow2['amt'], $dec, -2);
140 $total_allocated += $myrow2['amt'];
142 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
146 $memo = get_comments_string($j, $i);
150 $rep->TextColLines(1, 5, $memo, -2);
152 $rep->row = $rep->bottomMargin + (16 * $rep->lineHeight);
154 $rep->TextCol(3, 6, _("Total Allocated"), -2);
155 $rep->AmountCol(6, 7, $total_allocated, $dec, -2);
157 $rep->TextCol(3, 6, _("Left to Allocate"), -2);
158 $myrow['Total'] *= -1;
159 $myrow['ov_discount'] *= -1;
160 $rep->AmountCol(6, 7, $myrow['Total'] + $myrow['ov_discount'] - $total_allocated, $dec, -2);
161 if (floatcmp($myrow['ov_discount'], 0))
164 $rep->TextCol(3, 6, _("Discount"), - 2);
165 $rep->AmountCol(6, 7, -$myrow['ov_discount'], $dec, -2);
170 $rep->TextCol(3, 6, _("TOTAL REMITTANCE"), - 2);
171 $rep->AmountCol(6, 7, $myrow['Total'], $dec, -2);
173 $words = price_in_words($myrow['Total'], ST_SUPPAYMENT);
177 $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
182 $myrow['DebtorName'] = $myrow['supp_name'];