No display of shipping if there are no shipping costs on sales documents or views.
[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 = 'SA_PRICEREP';
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/inventory_db.inc");
28
29 //----------------------------------------------------------------------------------------------------
30
31 print_price_listing();
32
33 function fetch_items($category=0)
34 {
35                 $sql = "SELECT ".TB_PREF."stock_master.stock_id, ".TB_PREF."stock_master.description AS name,
36                                 ".TB_PREF."stock_master.material_cost+".TB_PREF."stock_master.labour_cost+".TB_PREF."stock_master.overhead_cost AS Standardcost,
37                                 ".TB_PREF."stock_master.category_id,".TB_PREF."stock_master.units,
38                                 ".TB_PREF."stock_category.description
39                         FROM ".TB_PREF."stock_master,
40                                 ".TB_PREF."stock_category
41                         WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id AND NOT ".TB_PREF."stock_master.inactive";
42                 if ($category != 0)
43                         $sql .= " AND ".TB_PREF."stock_category.category_id = ".db_escape($category);
44                 $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
45                                 ".TB_PREF."stock_master.stock_id";
46
47     return db_query($sql,"No transactions were returned");
48 }
49
50 function get_kits($category=0)
51 {
52         $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
53                         FROM
54                         ".TB_PREF."item_codes i
55                         LEFT JOIN
56                         ".TB_PREF."stock_category c
57                         ON i.category_id=c.category_id";
58         $sql .= " WHERE !i.is_foreign AND i.item_code!=i.stock_id";
59         if ($category != 0)
60                 $sql .= " AND c.category_id = ".db_escape($category);
61         $sql .= " GROUP BY i.item_code";
62     return db_query($sql,"No kits were returned");
63 }
64
65 //----------------------------------------------------------------------------------------------------
66
67 function print_price_listing()
68 {
69     global $path_to_root, $pic_height, $pic_width;
70
71     $currency = $_POST['PARAM_0'];
72     $category = $_POST['PARAM_1'];
73     $salestype = $_POST['PARAM_2'];
74     $pictures = $_POST['PARAM_3'];
75     $showGP = $_POST['PARAM_4'];
76     $comments = $_POST['PARAM_5'];
77         $orientation = $_POST['PARAM_6'];
78         $destination = $_POST['PARAM_7'];
79         if ($destination)
80                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
81         else
82                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
83
84         $orientation = ($orientation ? 'L' : 'P');
85     $dec = user_price_dec();
86
87         $home_curr = get_company_pref('curr_default');
88         if ($currency == ALL_TEXT)
89                 $currency = $home_curr;
90         $curr = get_currency($currency);
91         $curr_sel = $currency . " - " . $curr['currency'];
92         if ($category == ALL_NUMERIC)
93                 $category = 0;
94         if ($salestype == ALL_NUMERIC)
95                 $salestype = 0;
96         if ($category == 0)
97                 $cat = _('All');
98         else
99                 $cat = get_category_name($category);
100         if ($salestype == 0)
101                 $stype = _('All');
102         else
103                 $stype = get_sales_type_name($salestype);
104         if ($showGP == 0)
105                 $GP = _('No');
106         else
107                 $GP = _('Yes');
108
109         $cols = array(0, 100, 360, 385, 450, 515);
110
111         $headers = array(_('Category/Items'), _('Description'), _('UOM'), _('Price'),   _('GP %'));
112
113         $aligns = array('left', 'left', 'left', 'right', 'right');
114
115     $params =   array(  0 => $comments,
116                                     1 => array('text' => _('Currency'), 'from' => $curr_sel, 'to' => ''),
117                                     2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
118                                     3 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''),
119                                     4 => array(  'text' => _('Show GP %'),'from' => $GP,'to' => ''));
120
121         if ($pictures)
122                 $user_comp = user_company();
123         else
124                 $user_comp = "";
125
126     $rep = new FrontReport(_('Price Listing'), "PriceListing", user_pagesize(), 9, $orientation);
127     if ($orientation == 'L')
128         recalculate_cols($cols);
129
130     $rep->Font();
131     $rep->Info($params, $cols, $headers, $aligns);
132     $rep->NewPage();
133
134         $result = fetch_items($category);
135
136         $catgor = '';
137         $_POST['sales_type_id'] = $salestype;
138         while ($myrow=db_fetch($result))
139         {
140                 if ($catgor != $myrow['description'])
141                 {
142                         $rep->Line($rep->row  - $rep->lineHeight);
143                         $rep->NewLine(2);
144                         $rep->fontSize += 2;
145                         $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
146                         $catgor = $myrow['description'];
147                         $rep->fontSize -= 2;
148                         $rep->NewLine();
149                 }
150                 $rep->NewLine();
151                 $rep->TextCol(0, 1,     $myrow['stock_id']);
152                 $rep->TextCol(1, 2, $myrow['name']);
153                 $rep->TextCol(2, 3, $myrow['units']);
154                 $price = get_price($myrow['stock_id'], $currency, $salestype);
155                 $rep->AmountCol(3, 4, $price, $dec);
156                 if ($showGP)
157                 {
158                         $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
159                         if ($price2 != 0.0)
160                                 $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
161                         else
162                                 $disp = 0.0;
163                         $rep->TextCol(4, 5,     number_format2($disp, user_percent_dec()) . " %");
164                 }
165                 if ($pictures)
166                 {
167                         $image = company_path(). "/images/"
168                                 . item_img_name($myrow['stock_id']) . ".jpg";
169                         if (file_exists($image))
170                         {
171                                 $rep->NewLine();
172                                 if ($rep->row - $pic_height < $rep->bottomMargin)
173                                         $rep->NewPage();
174                                 $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, 0, $pic_height);
175                                 $rep->row -= $pic_height;
176                                 $rep->NewLine();
177                         }
178                 }
179                 else
180                         $rep->NewLine(0, 1);
181         }
182         $rep->Line($rep->row  - 4);
183
184         $result = get_kits($category);
185
186         $catgor = '';
187         while ($myrow=db_fetch($result))
188         {
189                 if ($catgor != $myrow['cat_name'])
190                 {
191                         if ($catgor == '')
192                         {
193                                 $rep->NewLine(2);
194                                 $rep->fontSize += 2;
195                                 $rep->TextCol(0, 3, _("Sales Kits"));
196                                 $rep->fontSize -= 2;
197                         }
198                         $rep->Line($rep->row  - $rep->lineHeight);
199                         $rep->NewLine(2);
200                         $rep->fontSize += 2;
201                         $rep->TextCol(0, 3, $myrow['cat_id'] . " - " . $myrow['cat_name']);
202                         $catgor = $myrow['cat_name'];
203                         $rep->fontSize -= 2;
204                         $rep->NewLine();
205                 }
206                 $rep->NewLine();
207                 $rep->TextCol(0, 1,     $myrow['kit_code']);
208                 $rep->TextCol(1, 3, $myrow['kit_name']);
209                 $price = get_kit_price($myrow['kit_code'], $currency, $salestype);
210                 $rep->AmountCol(3, 4, $price, $dec);
211                 $rep->NewLine(0, 1);
212         }
213         $rep->Line($rep->row  - 4);
214         $rep->NewLine();
215     $rep->End();
216 }
217
218 ?>