Implemented Selectable Print Orientation (Portrait, Landscape) for all reports in...
[fa-stable.git] / reporting / rep112.php
1 <?php
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 ***********************************************************************/
12
13 $page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
14         'SA_SALESTRANSVIEW' : 'SA_SALESBULKREP';
15 // ----------------------------------------------------------------
16 // $ Revision:  2.0 $
17 // Creator:     Joe Hunt
18 // date_:       2005-05-19
19 // Title:       Receipts
20 // ----------------------------------------------------------------
21 $path_to_root="..";
22
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
27 //----------------------------------------------------------------------------------------------------
28
29 print_receipts();
30
31 //----------------------------------------------------------------------------------------------------
32 function get_receipt($type, $trans_no)
33 {
34     $sql = "SELECT ".TB_PREF."debtor_trans.*,
35                                 (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + 
36                                 ".TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_discount) AS Total, 
37                                 ".TB_PREF."debtors_master.name AS DebtorName,  ".TB_PREF."debtors_master.debtor_ref,
38                                 ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.payment_terms, "
39                                 .TB_PREF."debtors_master.tax_id AS tax_id,
40                                 ".TB_PREF."debtors_master.address
41                         FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master
42                                 WHERE ".TB_PREF."debtor_trans.debtor_no = ".TB_PREF."debtors_master.debtor_no
43                                 AND ".TB_PREF."debtor_trans.type = ".db_escape($type)."
44                                 AND ".TB_PREF."debtor_trans.trans_no = ".db_escape($trans_no);
45         $result = db_query($sql, "The remittance cannot be retrieved");
46         if (db_num_rows($result) == 0)
47                 return false;
48     return db_fetch($result);
49 }
50
51 function print_receipts()
52 {
53         global $path_to_root, $systypes_array;
54
55         include_once($path_to_root . "/reporting/includes/pdf_report.inc");
56
57         $from = $_POST['PARAM_0'];
58         $to = $_POST['PARAM_1'];
59         $currency = $_POST['PARAM_2'];
60         $comments = $_POST['PARAM_3'];
61         $orientation = $_POST['PARAM_4'];
62
63         $orientation = ($orientation ? 'L' : 'P');
64         if (!$from || !$to) return;
65
66         $dec = user_price_dec();
67
68         $fno = explode("-", $from);
69         $tno = explode("-", $to);
70         $from = min($fno[0], $tno[0]);
71         $to = max($fno[0], $tno[0]);
72
73         $cols = array(4, 85, 150, 225, 275, 360, 450, 515);
74
75         // $headers in doctext.inc
76         $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
77
78         $params = array('comments' => $comments);
79
80         $cur = get_company_Pref('curr_default');
81
82         $rep = new FrontReport(_('RECEIPT'), "ReceiptBulk", user_pagesize(), 9, $orientation);
83     if ($orientation == 'L')
84         $rep->recalculate_cols($cols);
85         $rep->SetHeaderType('Header2');
86         $rep->currency = $cur;
87         $rep->Font();
88         $rep->Info($params, $cols, null, $aligns);
89
90         for ($i = $from; $i <= $to; $i++)
91         {
92                 if ($fno[0] == $tno[0])
93                         $types = array($fno[1]);
94                 else
95                         $types = array(ST_BANKDEPOSIT, ST_CUSTPAYMENT);
96                 foreach ($types as $j)
97                 {
98                         $myrow = get_receipt($j, $i);
99                         if (!$myrow)
100                                 continue;
101                         $res = get_bank_trans($j, $i);
102                         $baccount = db_fetch($res);
103                         $params['bankaccount'] = $baccount['bank_act'];
104
105                         $rep->title = _('RECEIPT');
106                         $contacts = get_branch_contacts($myrow['branch_code'], 'invoice', $myrow['debtor_no']);
107                         $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_CUSTPAYMENT, $contacts);
108                         $rep->NewPage();
109                         $result = get_allocatable_to_cust_transactions($myrow['debtor_no'], $myrow['trans_no'], $myrow['type']);
110
111                         $doctype = ST_CUSTPAYMENT;
112
113                         $total_allocated = 0;
114                         $rep->TextCol(0, 4,     _("As advance / full / part / payment towards:"), -2);
115                         $rep->NewLine(2);
116
117                         while ($myrow2=db_fetch($result))
118                         {
119                                 $rep->TextCol(0, 1,     $systypes_array[$myrow2['type']], -2);
120                                 $rep->TextCol(1, 2,     $myrow2['reference'], -2);
121                                 $rep->TextCol(2, 3,     sql2date($myrow2['tran_date']), -2);
122                                 $rep->TextCol(3, 4,     sql2date($myrow2['due_date']), -2);
123                                 $rep->AmountCol(4, 5, $myrow2['Total'], $dec, -2);
124                                 $rep->AmountCol(5, 6, $myrow2['Total'] - $myrow2['alloc'], $dec, -2);
125                                 $rep->AmountCol(6, 7, $myrow2['amt'], $dec, -2);
126
127                                 $total_allocated += $myrow2['amt'];
128                                 $rep->NewLine(1);
129                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
130                                         $rep->NewPage();
131                         }
132
133                         $memo = get_comments_string($j, $i);
134                         if ($memo != "")
135                         {
136                                 $rep->NewLine();
137                                 $rep->TextColLines(1, 5, $memo, -2);
138                         }
139
140                         $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
141
142                         $rep->TextCol(3, 6, _("Total Allocated"), -2);
143                         $rep->AmountCol(6, 7, $total_allocated, $dec, -2);
144                         $rep->NewLine();
145                         $rep->TextCol(3, 6, _("Left to Allocate"), -2);
146                         $rep->AmountCol(6, 7, $myrow['Total'] - $total_allocated, $dec, -2);
147                         $rep->NewLine();
148                         $rep->Font('bold');
149                         $rep->TextCol(3, 6, _("TOTAL RECEIPT"), - 2);
150                         $rep->AmountCol(6, 7, $myrow['Total'], $dec, -2);
151                         $words = price_in_words($myrow['Total'], ST_CUSTPAYMENT);
152                         if ($words != "")
153                         {
154                                 $rep->NewLine(1);
155                                 $rep->TextCol(0, 7, $myrow['curr_code'] . ": " . $words, - 2);
156                         }
157                         $rep->Font();
158                         $rep->NewLine();
159                         $rep->TextCol(6, 7, _("Received / Sign"), - 2);
160                         $rep->NewLine();
161                         $rep->TextCol(0, 2, _("By Cash / Cheque* / Draft No."), - 2);
162                         $rep->TextCol(2, 4, "______________________________", - 2);
163                         $rep->TextCol(4, 5, _("Dated"), - 2);
164                         $rep->TextCol(5, 6, "__________________", - 2);
165                         $rep->NewLine(1);
166                         $rep->TextCol(0, 2, _("Drawn on Bank"), - 2);
167                         $rep->TextCol(2, 4, "______________________________", - 2);
168                         $rep->TextCol(4, 5, _("Branch"), - 2);
169                         $rep->TextCol(5, 6, "__________________", - 2);
170                         $rep->TextCol(6, 7, "__________________");
171                 }
172         }
173         $rep->End();
174 }
175
176 ?>