Changed to let the $doctypes in documents follow the types in types.inc
[fa-stable.git] / reporting / rep110.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 $page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
13         'SA_SALESTRANSVIEW' : 'SA_SALESBULKREP';
14 // ----------------------------------------------------------------
15 // $ Revision:  2.0 $
16 // Creator:     Janusz Dobrwolski
17 // date_:       2008-01-14
18 // Title:       Print Delivery Notes
19 // draft version!
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 include_once($path_to_root . "/sales/includes/sales_db.inc");
27
28 $packing_slip = 0;
29 //----------------------------------------------------------------------------------------------------
30
31 print_deliveries();
32
33 //----------------------------------------------------------------------------------------------------
34
35 function print_deliveries()
36 {
37         global $path_to_root, $packing_slip;
38
39         include_once($path_to_root . "/reporting/includes/pdf_report.inc");
40
41         $from = $_POST['PARAM_0'];
42         $to = $_POST['PARAM_1'];
43         $email = $_POST['PARAM_2'];
44         $packing_slip = $_POST['PARAM_3'];
45         $comments = $_POST['PARAM_4'];
46
47         if ($from == null)
48                 $from = 0;
49         if ($to == null)
50                 $to = 0;
51         $dec = user_price_dec();
52
53         $fno = explode("-", $from);
54         $tno = explode("-", $to);
55
56         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
57
58         // $headers in doctext.inc
59         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
60
61         $params = array('comments' => $comments);
62
63         $cur = get_company_Pref('curr_default');
64
65         if ($email == 0)
66         {
67                 if ($packing_slip == 0)
68                         $rep = new FrontReport(_('DELIVERY'), "DeliveryNoteBulk", user_pagesize());
69                 else
70                         $rep = new FrontReport(_('PACKING SLIP'), "PackingSlipBulk", user_pagesize());
71                 $rep->currency = $cur;
72                 $rep->Font();
73                 $rep->Info($params, $cols, null, $aligns);
74         }
75
76         for ($i = $fno[0]; $i <= $tno[0]; $i++)
77         {
78                         if (!exists_customer_trans(ST_CUSTDELIVERY, $i))
79                                 continue;
80                         $myrow = get_customer_trans($i, ST_CUSTDELIVERY);
81                         $branch = get_branch($myrow["branch_code"]);
82                         $sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER); // ?
83                         if ($email == 1)
84                         {
85                                 $rep = new FrontReport("", "", user_pagesize());
86                                 $rep->currency = $cur;
87                                 $rep->Font();
88                                 if ($packing_slip == 0)
89                                 {
90                                         $rep->title = _('DELIVERY NOTE');
91                                         $rep->filename = "Delivery" . $myrow['reference'] . ".pdf";
92                                 }
93                                 else
94                                 {
95                                         $rep->title = _('PACKING SLIP');
96                                         $rep->filename = "Packing_slip" . $myrow['reference'] . ".pdf";
97                                 }
98                                 $rep->Info($params, $cols, null, $aligns);
99                         }
100                         else
101                                 $rep->title = _('DELIVERY NOTE');
102                         $rep->Header2($myrow, $branch, $sales_order, '', ST_CUSTDELIVERY);
103
104                         $result = get_customer_trans_details(ST_CUSTDELIVERY, $i);
105                         $SubTotal = 0;
106                         while ($myrow2=db_fetch($result))
107                         {
108                                 $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
109                                    user_price_dec());
110                                 $SubTotal += $Net;
111                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
112                         $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stock_id']));
113                         $DisplayNet = number_format2($Net,$dec);
114                         if ($myrow2["discount_percent"]==0)
115                                         $DisplayDiscount ="";
116                         else
117                                         $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
118                                 $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
119                                 $oldrow = $rep->row;
120                                 $rep->TextColLines(1, 2, $myrow2['StockDescription'], -2);
121                                 $newrow = $rep->row;
122                                 $rep->row = $oldrow;
123                                 $rep->TextCol(2, 3,     $DisplayQty, -2);
124                                 $rep->TextCol(3, 4,     $myrow2['units'], -2);
125                                 if ($packing_slip == 0)
126                                 {
127                                         $rep->TextCol(4, 5,     $DisplayPrice, -2);
128                                         $rep->TextCol(5, 6,     $DisplayDiscount, -2);
129                                         $rep->TextCol(6, 7,     $DisplayNet, -2);
130                                 }       
131                                 $rep->row = $newrow;
132                                 //$rep->NewLine(1);
133                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
134                                         $rep->Header2($myrow, $branch, $sales_order,'',ST_CUSTDELIVERY);
135                         }
136
137                         $comments = get_comments(ST_CUSTDELIVERY, $i);
138                         if ($comments && db_num_rows($comments))
139                         {
140                                 $rep->NewLine();
141                         while ($comment=db_fetch($comments))
142                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
143                         }
144
145                         $DisplaySubTot = number_format2($SubTotal,$dec);
146                         $DisplayFreight = number_format2($myrow["ov_freight"],$dec);
147
148                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
149                         $linetype = true;
150                         $doctype=ST_CUSTDELIVERY;
151                         if ($rep->currency != $myrow['curr_code'])
152                         {
153                                 include($path_to_root . "/reporting/includes/doctext2.inc");
154                         }
155                         else
156                         {
157                                 include($path_to_root . "/reporting/includes/doctext.inc");
158                         }
159                         if ($packing_slip == 0)
160                         {
161                                 $rep->TextCol(3, 6, $doc_Sub_total, -2);
162                                 $rep->TextCol(6, 7,     $DisplaySubTot, -2);
163                                 $rep->NewLine();
164                                 $rep->TextCol(3, 6, $doc_Shipping, -2);
165                                 $rep->TextCol(6, 7,     $DisplayFreight, -2);
166                                 $rep->NewLine();
167                                 $tax_items = get_trans_tax_details(ST_CUSTDELIVERY, $i);
168                         while ($tax_item = db_fetch($tax_items))
169                         {
170                                 $DisplayTax = number_format2($tax_item['amount'], $dec);
171                                 if ($tax_item['included_in_price'])
172                                 {
173                                                 $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] .
174                                                         " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2);
175                                         }
176                                 else
177                                 {
178                                                 $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" .
179                                                         $tax_item['rate'] . "%)", -2);
180                                                 $rep->TextCol(6, 7,     $DisplayTax, -2);
181                                         }
182                                         $rep->NewLine();
183                         }
184                         $rep->NewLine();
185                                 $DisplayTotal = number_format2($myrow["ov_freight"] +$myrow["ov_freight_tax"] + $myrow["ov_gst"] +
186                                         $myrow["ov_amount"],$dec);
187                                 $rep->Font('bold');
188                                 $rep->TextCol(3, 6, $doc_TOTAL_DELIVERY, - 2);
189                                 $rep->TextCol(6, 7,     $DisplayTotal, -2);
190                                 $rep->Font();
191                         }       
192                         if ($email == 1)
193                         {
194                                 if ($myrow['email'] == '')
195                                 {
196                                         $myrow['email'] = $branch['email'];
197                                         $myrow['DebtorName'] = $branch['br_name'];
198                                 }
199                                 $rep->End($email, $doc_Delivery_no . " " . $myrow['reference'], $myrow, ST_CUSTDELIVERY);
200                         }
201         }
202         if ($email == 0)
203                 $rep->End();
204 }
205
206 ?>