Changed license type to GPLv3 in top of files
[fa-stable.git] / reporting / rep104.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 = 2;
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       price Listing
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/ui/ui_input.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
27 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
28
29 //----------------------------------------------------------------------------------------------------
30
31 // trial_inquiry_controls();
32 print_price_listing();
33
34 function fetch_items($category=0)
35 {
36                 $sql = "SELECT ".TB_PREF."stock_master.stock_id, ".TB_PREF."stock_master.description AS name,
37                                 ".TB_PREF."stock_master.material_cost+".TB_PREF."stock_master.labour_cost+".TB_PREF."stock_master.overhead_cost AS Standardcost,
38                                 ".TB_PREF."stock_master.category_id,
39                                 ".TB_PREF."stock_category.description
40                         FROM ".TB_PREF."stock_master,
41                                 ".TB_PREF."stock_category
42                         WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id";
43                 if ($category != 0)
44                         $sql .= " AND ".TB_PREF."stock_category.category_id = '$category'";
45                 $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
46                                 ".TB_PREF."stock_master.stock_id";
47
48     return db_query($sql,"No transactions were returned");
49 }
50
51 function get_kits($category=0)
52 {
53         $sql = "SELECT i.item_code AS kit_code, i.description AS kit_name, c.category_id AS cat_id, c.description AS cat_name, count(*)>1 AS kit
54                         FROM
55                         ".TB_PREF."item_codes i
56                         LEFT JOIN
57                         ".TB_PREF."stock_category c
58                         ON i.category_id=c.category_id";
59         $sql .= " WHERE !i.is_foreign AND i.item_code!=i.stock_id";
60         if ($category != 0)
61                 $sql .= " AND c.category_id = '$category'";
62         $sql .= " GROUP BY i.item_code";
63     return db_query($sql,"No kits were returned");
64 }
65
66 //----------------------------------------------------------------------------------------------------
67
68 function print_price_listing()
69 {
70     global $comp_path, $path_to_root, $pic_height, $pic_width;
71
72     include_once($path_to_root . "/reporting/includes/pdf_report.inc");
73
74     $currency = $_POST['PARAM_0'];
75     $category = $_POST['PARAM_1'];
76     $salestype = $_POST['PARAM_2'];
77     $pictures = $_POST['PARAM_3'];
78     $showGP = $_POST['PARAM_4'];
79     $comments = $_POST['PARAM_5'];
80
81     $dec = user_price_dec();
82
83         $home_curr = get_company_pref('curr_default');
84         if ($currency == reserved_words::get_all())
85                 $currency = $home_curr;
86         $curr = get_currency($currency);
87         $curr_sel = $currency . " - " . $curr['currency'];
88         if ($category == reserved_words::get_all_numeric())
89                 $category = 0;
90         if ($salestype == reserved_words::get_all_numeric())
91                 $salestype = 0;
92         if ($category == 0)
93                 $cat = _('All');
94         else
95                 $cat = get_category_name($category);
96         if ($salestype == 0)
97                 $stype = _('All');
98         else
99                 $stype = get_sales_type_name($salestype);
100         if ($showGP == 0)
101                 $GP = _('No');
102         else
103                 $GP = _('Yes');
104
105         $cols = array(0, 100, 385, 450, 515);
106
107         $headers = array(_('Category/Items'), _('Description'), _('Price'),     _('GP %'));
108
109         $aligns = array('left', 'left', 'right', 'right');
110
111     $params =   array(  0 => $comments,
112                                     1 => array('text' => _('Currency'), 'from' => $curr_sel, 'to' => ''),
113                                     2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
114                                     3 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''),
115                                     4 => array(  'text' => _('Show GP %'),'from' => $GP,'to' => ''));
116
117         if ($pictures)
118                 $user_comp = user_company();
119         else
120                 $user_comp = "";
121
122     $rep = new FrontReport(_('Price Listing'), "PriceListing.pdf", user_pagesize());
123
124     $rep->Font();
125     $rep->Info($params, $cols, $headers, $aligns);
126     $rep->Header();
127
128         $result = fetch_items($category);
129
130         $catgor = '';
131         $_POST['sales_type_id'] = $salestype;
132         while ($myrow=db_fetch($result))
133         {
134                 if ($catgor != $myrow['description'])
135                 {
136                         $rep->Line($rep->row  - $rep->lineHeight);
137                         $rep->NewLine(2);
138                         $rep->fontSize += 2;
139                         $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
140                         $catgor = $myrow['description'];
141                         $rep->fontSize -= 2;
142                         $rep->NewLine();
143                 }
144                 $rep->NewLine();
145                 $rep->TextCol(0, 1,     $myrow['stock_id']);
146                 $rep->TextCol(1, 2, $myrow['name']);
147                 $price = get_price($myrow['stock_id'], $currency, $salestype);
148                 $rep->TextCol(2, 3,     number_format2($price, $dec));
149                 if ($showGP)
150                 {
151                         $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
152                         if ($price2 != 0.0)
153                                 $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
154                         else
155                                 $disp = 0.0;
156                         $rep->TextCol(3, 4,     number_format2($disp, user_percent_dec()) . " %");
157                 }
158                 if ($pictures)
159                 {
160                         $image = $comp_path . '/'. $user_comp . "/images/" . $myrow['stock_id'] . ".jpg";
161                         if (file_exists($image))
162                         {
163                                 $rep->NewLine();
164                                 if ($rep->row - $pic_height < $rep->bottomMargin)
165                                         $rep->Header();
166                                 $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, $pic_width, $pic_height);
167                                 $rep->row -= $pic_height;
168                                 $rep->NewLine();
169                         }
170                 }
171                 else
172                         $rep->NewLine(0, 1);
173         }
174         $rep->Line($rep->row  - 4);
175
176         $result = get_kits($category);
177
178         $catgor = '';
179         while ($myrow=db_fetch($result))
180         {
181                 if ($catgor != $myrow['cat_name'])
182                 {
183                         if ($catgor == '')
184                         {
185                                 $rep->NewLine(2);
186                                 $rep->fontSize += 2;
187                                 $rep->TextCol(0, 3, _("Sales Kits"));
188                                 $rep->fontSize -= 2;
189                         }       
190                         $rep->Line($rep->row  - $rep->lineHeight);
191                         $rep->NewLine(2);
192                         $rep->fontSize += 2;
193                         $rep->TextCol(0, 3, $myrow['cat_id'] . " - " . $myrow['cat_name']);
194                         $catgor = $myrow['cat_name'];
195                         $rep->fontSize -= 2;
196                         $rep->NewLine();
197                 }
198                 $rep->NewLine();
199                 $rep->TextCol(0, 1,     $myrow['kit_code']);
200                 $rep->TextCol(1, 2, $myrow['kit_name']);
201                 $price = get_kit_price($myrow['kit_code'], $currency, $salestype);
202                 $rep->TextCol(2, 3,     number_format2($price, $dec));
203                 $rep->NewLine(0, 1);
204         }
205         $rep->Line($rep->row  - 4);
206         
207     $rep->End();
208 }
209
210 ?>