e3b0ab1fcddf684a6e85cc4cc3da6d96ff4b1e15
[fa-stable.git] / reporting / rep111.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:     Joe Hunt
17 // date_:       2005-05-19
18 // Title:       Print Sales Quotations
19 // ----------------------------------------------------------------
20 $path_to_root="..";
21
22 include_once($path_to_root . "/includes/session.inc");
23 include_once($path_to_root . "/includes/date_functions.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25 include_once($path_to_root . "/sales/includes/sales_db.inc");
26
27 //----------------------------------------------------------------------------------------------------
28
29 print_sales_quotations();
30
31 function print_sales_quotations()
32 {
33         global $path_to_root, $print_as_quote;
34
35         include_once($path_to_root . "/reporting/includes/pdf_report.inc");
36
37         $from = $_POST['PARAM_0'];
38         $to = $_POST['PARAM_1'];
39         $currency = $_POST['PARAM_2'];
40         $email = $_POST['PARAM_3'];
41         $comments = $_POST['PARAM_4'];
42
43         if ($from == null)
44                 $from = 0;
45         if ($to == null)
46                 $to = 0;
47         $dec = user_price_dec();
48
49         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
50
51         // $headers in doctext.inc
52         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
53
54         $params = array('comments' => $comments);
55
56         $cur = get_company_Pref('curr_default');
57
58         if ($email == 0)
59         {
60                 $rep = new FrontReport(_("SALES QUOTATION"), "SalesQuotationBulk", user_pagesize());
61                 $rep->SetHeaderType('Header2');
62                 $rep->currency = $cur;
63                 $rep->Font();
64                 $rep->Info($params, $cols, null, $aligns);
65         }
66
67         for ($i = $from; $i <= $to; $i++)
68         {
69                 $myrow = get_sales_order_header($i, ST_SALESQUOTE);
70                 $baccount = get_default_bank_account($myrow['curr_code']);
71                 $params['bankaccount'] = $baccount['id'];
72                 $branch = get_branch($myrow["branch_code"]);
73                 if ($email == 1)
74                 {
75                         $rep = new FrontReport("", "", user_pagesize());
76                         $rep->SetHeaderType('Header2');
77                         $rep->currency = $cur;
78                         $rep->Font();
79                         $rep->filename = "SalesQuotation" . $i . ".pdf";
80                         $rep->Info($params, $cols, null, $aligns);
81                 }
82                 $rep->title = _("SALES QUOTATION");
83                 $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESQUOTE);
84                 $rep->headerFunc = 'Header2';
85                 $rep->NewPage();
86
87                 $result = get_sales_order_details($i, ST_SALESQUOTE);
88                 $SubTotal = 0;
89                 while ($myrow2=db_fetch($result))
90                 {
91                         $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
92                            user_price_dec());
93                         $SubTotal += $Net;
94                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
95                         $DisplayQty = number_format2($myrow2["quantity"],get_qty_dec($myrow2['stk_code']));
96                         $DisplayNet = number_format2($Net,$dec);
97                         if ($myrow2["discount_percent"]==0)
98                                 $DisplayDiscount ="";
99                         else
100                                 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
101                         $rep->TextCol(0, 1,     $myrow2['stk_code'], -2);
102                         $oldrow = $rep->row;
103                         $rep->TextColLines(1, 2, $myrow2['description'], -2);
104                         $newrow = $rep->row;
105                         $rep->row = $oldrow;
106                         $rep->TextCol(2, 3,     $DisplayQty, -2);
107                         $rep->TextCol(3, 4,     $myrow2['units'], -2);
108                         $rep->TextCol(4, 5,     $DisplayPrice, -2);
109                         $rep->TextCol(5, 6,     $DisplayDiscount, -2);
110                         $rep->TextCol(6, 7,     $DisplayNet, -2);
111                         $rep->row = $newrow;
112                         //$rep->NewLine(1);
113                         if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
114                                 $rep->NewPage();
115                 }
116                 if ($myrow['comments'] != "")
117                 {
118                         $rep->NewLine();
119                         $rep->TextColLines(1, 5, $myrow['comments'], -2);
120                 }
121                 $DisplaySubTot = number_format2($SubTotal,$dec);
122                 $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
123
124                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
125                 $linetype = true;
126                 $doctype = ST_SALESQUOTE;
127                 if ($rep->currency != $myrow['curr_code'])
128                 {
129                         include($path_to_root . "/reporting/includes/doctext2.inc");
130                 }
131                 else
132                 {
133                         include($path_to_root . "/reporting/includes/doctext.inc");
134                 }
135
136                 $rep->TextCol(3, 6, $doc_Sub_total, -2);
137                 $rep->TextCol(6, 7,     $DisplaySubTot, -2);
138                 $rep->NewLine();
139                 $rep->TextCol(3, 6, $doc_Shipping, -2);
140                 $rep->TextCol(6, 7,     $DisplayFreight, -2);
141                 $rep->NewLine();
142                 $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
143                 $rep->Font('bold');
144                 if ($myrow['tax_included'] == 0)
145                         $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
146                 else    
147                         $rep->TextCol(3, 6, $doc_TOTAL_ORDER2, - 2);
148                 $rep->TextCol(6, 7,     $DisplayTotal, -2);
149                 $words = price_in_words($myrow["freight_cost"] + $SubTotal, ST_SALESQUOTE);
150                 if ($words != "")
151                 {
152                         $rep->NewLine(1);
153                         $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
154                 }       
155                 $rep->Font();
156                 if ($email == 1)
157                 {
158                         if ($myrow['contact_email'] == '')
159                         {
160                                 $myrow['contact_email'] = $branch['email'];
161                                 if ($myrow['contact_email'] == '')
162                                         $myrow['contact_email'] = $myrow['master_email'];
163                                 $myrow['DebtorName'] = $branch['br_name'];
164                         }
165                         //$myrow['reference'] = $i;
166                         $rep->End($email, $doc_Invoice_no . " " . $i, $myrow);
167                 }
168         }
169         if ($email == 0)
170                 $rep->End();
171 }
172
173 ?>