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