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 ***********************************************************************/
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/db/inventory_db.inc");
29 //----------------------------------------------------------------------------------------------------
31 print_price_listing();
33 function fetch_items($category=0)
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,
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";
43 $sql .= " AND ".TB_PREF."stock_category.category_id = '$category'";
44 $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
45 ".TB_PREF."stock_master.stock_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
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";
60 $sql .= " AND c.category_id = '$category'";
61 $sql .= " GROUP BY i.item_code";
62 return db_query($sql,"No kits were returned");
65 //----------------------------------------------------------------------------------------------------
67 function print_price_listing()
69 global $comp_path, $path_to_root, $pic_height, $pic_width;
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 $destination = $_POST['PARAM_6'];
79 include_once($path_to_root . "/reporting/includes/excel_report.inc");
81 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
83 $dec = user_price_dec();
85 $home_curr = get_company_pref('curr_default');
86 if ($currency == reserved_words::get_all())
87 $currency = $home_curr;
88 $curr = get_currency($currency);
89 $curr_sel = $currency . " - " . $curr['currency'];
90 if ($category == reserved_words::get_all_numeric())
92 if ($salestype == reserved_words::get_all_numeric())
97 $cat = get_category_name($category);
101 $stype = get_sales_type_name($salestype);
107 $cols = array(0, 100, 385, 450, 515);
109 $headers = array(_('Category/Items'), _('Description'), _('Price'), _('GP %'));
111 $aligns = array('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());
127 $rep->Info($params, $cols, $headers, $aligns);
130 $result = fetch_items($category);
133 $_POST['sales_type_id'] = $salestype;
134 while ($myrow=db_fetch($result))
136 if ($catgor != $myrow['description'])
138 $rep->Line($rep->row - $rep->lineHeight);
141 $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
142 $catgor = $myrow['description'];
147 $rep->TextCol(0, 1, $myrow['stock_id']);
148 $rep->TextCol(1, 2, $myrow['name']);
149 $price = get_price($myrow['stock_id'], $currency, $salestype);
150 $rep->AmountCol(2, 3, $price, $dec);
153 $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
155 $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
158 $rep->TextCol(3, 4, number_format2($disp, user_percent_dec()) . " %");
162 $image = $comp_path . '/'. $user_comp . "/images/"
163 . item_img_name($myrow['stock_id']) . ".jpg";
164 if (file_exists($image))
167 if ($rep->row - $pic_height < $rep->bottomMargin)
169 $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, 0, $pic_height);
170 $rep->row -= $pic_height;
177 $rep->Line($rep->row - 4);
179 $result = get_kits($category);
182 while ($myrow=db_fetch($result))
184 if ($catgor != $myrow['cat_name'])
190 $rep->TextCol(0, 3, _("Sales Kits"));
193 $rep->Line($rep->row - $rep->lineHeight);
196 $rep->TextCol(0, 3, $myrow['cat_id'] . " - " . $myrow['cat_name']);
197 $catgor = $myrow['cat_name'];
202 $rep->TextCol(0, 1, $myrow['kit_code']);
203 $rep->TextCol(1, 2, $myrow['kit_name']);
204 $price = get_kit_price($myrow['kit_code'], $currency, $salestype);
205 $rep->AmountCol(2, 3, $price, $dec);
208 $rep->Line($rep->row - 4);