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_ITEMSVALREP';
13 // ----------------------------------------------------------------
17 // Title: Stock Check Sheet
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/data_checks.inc");
24 include_once($path_to_root . "/gl/includes/gl_db.inc");
25 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
26 include_once($path_to_root . "/includes/db/manufacturing_db.inc");
28 //----------------------------------------------------------------------------------------------------
32 function getTransactions($category, $location, $item_like)
34 $sql = "SELECT item.category_id,
35 category.description AS cat_description,
36 item.stock_id, item.units,
37 item.description, item.inactive,
38 IF(move.stock_id IS NULL, '', move.loc_code) AS loc_code,
39 SUM(IF(move.stock_id IS NULL,0,move.qty)) AS QtyOnHand
41 .TB_PREF."stock_master item,"
42 .TB_PREF."stock_category category)
43 LEFT JOIN ".TB_PREF."stock_moves move ON item.stock_id=move.stock_id
44 WHERE item.category_id=category.category_id
45 AND (item.mb_flag='B' OR item.mb_flag='M')";
47 $sql .= " AND item.category_id = ".db_escape($category);
48 if ($location != 'all')
49 $sql .= " AND IF(move.stock_id IS NULL, '1=1',move.loc_code = ".db_escape($location).")";
54 if(sscanf($item_like, "/%s", $regexp)==1)
55 $sql .= " AND item.stock_id RLIKE ".db_escape($regexp);
57 $sql .= " AND item.stock_id LIKE ".db_escape($item_like);
59 $sql .= " GROUP BY item.category_id,
63 ORDER BY item.category_id,
66 return db_query($sql,"No transactions were returned");
69 //----------------------------------------------------------------------------------------------------
71 function print_stock_check()
73 global $path_to_root, $SysPrefs;
75 $category = $_POST['PARAM_0'];
76 $location = $_POST['PARAM_1'];
77 $pictures = $_POST['PARAM_2'];
78 $check = $_POST['PARAM_3'];
79 $shortage = $_POST['PARAM_4'];
80 $no_zeros = $_POST['PARAM_5'];
81 $like = $_POST['PARAM_6'];
82 $comments = $_POST['PARAM_7'];
83 $orientation = $_POST['PARAM_8'];
84 $destination = $_POST['PARAM_9'];
87 include_once($path_to_root . "/reporting/includes/excel_report.inc");
89 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
91 $orientation = ($orientation ? 'L' : 'P');
92 if ($category == ALL_NUMERIC)
97 $cat = get_category_name($category);
99 if ($location == ALL_TEXT)
101 if ($location == 'all')
104 $loc = get_location_name($location);
108 $available = _('Shortage');
113 $available = _('Available');
115 $barcodes = !empty($SysPrefs->prefs['barcodes_on_stock']);
116 if ($no_zeros) $nozeros = _('Yes');
117 else $nozeros = _('No');
120 $cols = array(0, 75, 225, 250, 295, 345, 390, 445, 515);
121 $headers = array(_('Stock ID'), _('Description'), _('UOM'), _('Quantity'), _('Check'), _('Demand'), $available, _('On Order'));
122 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
126 $cols = array(0, 75, 225, 250, 315, 380, 445, 515);
127 $headers = array(_('Stock ID'), _('Description'), _('UOM'), _('Quantity'), _('Demand'), $available, _('On Order'));
128 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
133 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
134 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''),
135 3 => array('text' => _('Only Shortage'), 'from' => $short, 'to' => ''),
136 4 => array('text' => _('Suppress Zeros'), 'from' => $nozeros, 'to' => '')
141 // define barcode style
143 'position' => 'L', // If blank string, barcode starts on left edge of page
146 'cellfitalign' => '',
149 'fgcolor' => array(0,0,0),
150 'bgcolor' => false, //array(255,255,255),
152 'font' => 'helvetica',
156 // write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres=0.4, $style='', $align='')
159 $rep = new FrontReport(_('Stock Check Sheets'), "StockCheckSheet", user_pagesize(), 9, $orientation);
160 if ($orientation == 'L')
161 recalculate_cols($cols);
164 $rep->Info($params, $cols, $headers, $aligns);
167 $res = getTransactions($category, $location, $like);
169 while ($trans=db_fetch($res))
171 if ($location == 'all')
174 $loc_code = $location;
175 $demandqty = get_demand_qty($trans['stock_id'], $loc_code);
176 $demandqty += get_demand_asm_qty($trans['stock_id'], $loc_code);
177 $onorder = get_on_porder_qty($trans['stock_id'], $loc_code);
178 $onorder += get_on_worder_qty($trans['stock_id'], $loc_code);
179 if ($no_zeros && $trans['QtyOnHand'] == 0 && $demandqty == 0 && $onorder == 0)
181 if ($shortage && $trans['QtyOnHand'] - $demandqty >= 0)
183 if ($catt != $trans['cat_description'])
187 $rep->Line($rep->row - 2);
190 $rep->TextCol(0, 1, $trans['category_id']);
191 $rep->TextCol(1, 2, $trans['cat_description']);
192 $catt = $trans['cat_description'];
196 $dec = get_qty_dec($trans['stock_id']);
197 $rep->TextCol(0, 1, $trans['stock_id']);
198 $rep->TextCol(1, 2, $trans['description'].($trans['inactive']==1 ? " ("._("Inactive").")" : ""), -1);
199 $rep->TextCol(2, 3, $trans['units']);
200 $rep->AmountCol(3, 4, $trans['QtyOnHand'], $dec);
203 $rep->TextCol(4, 5, "_________");
204 $rep->AmountCol(5, 6, $demandqty, $dec);
205 $rep->AmountCol(6, 7, $trans['QtyOnHand'] - $demandqty, $dec);
206 $rep->AmountCol(7, 8, $onorder, $dec);
210 $rep->AmountCol(4, 5, $demandqty, $dec);
211 $rep->AmountCol(5, 6, $trans['QtyOnHand'] - $demandqty, $dec);
212 $rep->AmountCol(6, 7, $onorder, $dec);
214 if ($pictures || $barcodes)
217 if ($rep->row - $SysPrefs->pic_height < $rep->bottomMargin)
222 $bar_y = $rep->GetY();
223 $barcode = str_pad($trans['stock_id'], 7, '0', STR_PAD_LEFT);
224 $barcode = substr($barcode, 0, 8); // EAN 8 Check digit is auto computed and barcode printed
225 $rep->write1DBarcode($barcode, 'EAN8', $rep->cols[$firstcol++], $bar_y + 22, 22, $SysPrefs->pic_height, 1.2, $style, 'N');
229 $image = company_path() . '/images/' . item_img_name($trans['stock_id']) . '.jpg';
230 if (file_exists($image))
232 $rep->AddImage($image, $rep->cols[$firstcol], $rep->row - $SysPrefs->pic_height, 0, $SysPrefs->pic_height);
235 $rep->row -= $SysPrefs->pic_height;
239 $rep->Line($rep->row - 4);