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 // ----------------------------------------------------------------
17 // Title: price Listing
18 // ----------------------------------------------------------------
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");
29 //----------------------------------------------------------------------------------------------------
31 print_price_listing();
33 function fetch_items($category=0)
35 $sql = "SELECT item.stock_id, item.description AS name,
36 item.material_cost AS Standardcost,
37 item.category_id,item.units,
39 FROM ".TB_PREF."stock_master item,
40 ".TB_PREF."stock_category category
41 WHERE item.category_id=category.category_id AND NOT item.inactive";
43 $sql .= " AND category.category_id = ".db_escape($category);
44 $sql .= " AND item.mb_flag<> 'F' ORDER BY item.category_id,
47 return db_query($sql,"No transactions were returned");
50 function get_kits($category=0)
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
54 ".TB_PREF."item_codes i
55 LEFT JOIN ".TB_PREF."stock_category c ON i.category_id=c.category_id
56 WHERE !i.is_foreign AND i.item_code!=i.stock_id";
58 $sql .= " AND c.category_id = ".db_escape($category);
59 $sql .= " GROUP BY i.item_code";
60 return db_query($sql,"No kits were returned");
63 //----------------------------------------------------------------------------------------------------
65 function print_price_listing()
67 global $path_to_root, $SysPrefs;
69 $currency = $_POST['PARAM_0'];
70 $category = $_POST['PARAM_1'];
71 $salestype = $_POST['PARAM_2'];
72 $pictures = $_POST['PARAM_3'];
73 $showGP = $_POST['PARAM_4'];
74 $comments = $_POST['PARAM_5'];
75 $orientation = $_POST['PARAM_6'];
76 $destination = $_POST['PARAM_7'];
78 include_once($path_to_root . "/reporting/includes/excel_report.inc");
80 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
82 $orientation = ($orientation ? 'L' : 'P');
83 $dec = user_price_dec();
85 $home_curr = get_company_pref('curr_default');
86 if ($currency == ALL_TEXT)
87 $currency = $home_curr;
88 $curr = get_currency($currency);
89 $curr_sel = $currency . " - " . $curr['currency'];
90 if ($category == ALL_NUMERIC)
92 if ($salestype == ALL_NUMERIC)
97 $cat = get_category_name($category);
101 $stype = get_sales_type_name($salestype);
107 $cols = array(0, 100, 360, 385, 450, 515);
109 $headers = array(_('Category/Items'), _('Description'), _('UOM'), _('Price'), _('GP %'));
111 $aligns = array('left', 'left', 'left', 'right', 'right');
113 $params = array( 0 => $comments,
114 1 => array('text' => _('Currency'), 'from' => $curr_sel, 'to' => ''),
115 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
116 3 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''),
117 4 => array( 'text' => _('Show GP %'),'from' => $GP,'to' => ''));
120 $user_comp = user_company();
124 $rep = new FrontReport(_('Price Listing'), "PriceListing", user_pagesize(), 9, $orientation);
125 if ($orientation == 'L')
126 recalculate_cols($cols);
129 $rep->Info($params, $cols, $headers, $aligns);
132 $result = fetch_items($category);
135 $_POST['sales_type_id'] = $salestype;
136 while ($myrow=db_fetch($result))
138 if ($catgor != $myrow['description'])
140 $rep->Line($rep->row - $rep->lineHeight);
143 $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
144 $catgor = $myrow['description'];
149 $rep->TextCol(0, 1, $myrow['stock_id']);
150 $rep->TextCol(1, 2, $myrow['name']);
151 $rep->TextCol(2, 3, $myrow['units']);
152 $price = get_price($myrow['stock_id'], $currency, $salestype);
153 $rep->AmountCol(3, 4, $price, $dec);
156 $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
158 $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
161 $rep->TextCol(4, 5, number_format2($disp, user_percent_dec()) . " %");
165 $image = company_path(). "/images/"
166 . item_img_name($myrow['stock_id']) . ".jpg";
167 if (file_exists($image))
170 if ($rep->row - $SysPrefs->pic_height < $rep->bottomMargin)
172 $rep->AddImage($image, $rep->cols[1], $rep->row - $SysPrefs->pic_height, 0, $SysPrefs->pic_height);
173 $rep->row -= $SysPrefs->pic_height;
180 $rep->Line($rep->row - 4);
182 $result = get_kits($category);
185 while ($myrow=db_fetch($result))
187 if ($catgor != $myrow['cat_name'])
193 $rep->TextCol(0, 3, _("Sales Kits"));
196 $rep->Line($rep->row - $rep->lineHeight);
199 $rep->TextCol(0, 3, $myrow['cat_id'] . " - " . $myrow['cat_name']);
200 $catgor = $myrow['cat_name'];
205 $rep->TextCol(0, 1, $myrow['kit_code']);
206 $rep->TextCol(1, 3, $myrow['kit_name']);
207 $price = get_kit_price($myrow['kit_code'], $currency, $salestype);
208 $rep->AmountCol(3, 4, $price, $dec);
211 $rep->Line($rep->row - 4);