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 // ----------------------------------------------------------------
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)
34 $sql = "SELECT ".TB_PREF."stock_master.category_id,
35 ".TB_PREF."stock_category.description AS cat_description,
36 ".TB_PREF."stock_master.stock_id,
37 ".TB_PREF."stock_master.description,
38 IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
39 SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS QtyOnHand
40 FROM (".TB_PREF."stock_master,
41 ".TB_PREF."stock_category)
42 LEFT JOIN ".TB_PREF."stock_moves ON
43 (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id OR ".TB_PREF."stock_master.stock_id IS NULL)
44 WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
45 AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
47 $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
48 if ($location != 'all')
49 $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
50 $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
51 ".TB_PREF."stock_category.description,
52 ".TB_PREF."stock_master.stock_id,
53 ".TB_PREF."stock_master.description
54 ORDER BY ".TB_PREF."stock_master.category_id,
55 ".TB_PREF."stock_master.stock_id";
57 return db_query($sql,"No transactions were returned");
60 //----------------------------------------------------------------------------------------------------
62 function print_stock_check()
64 global $comp_path, $path_to_root, $pic_height, $pic_width;
66 $category = $_POST['PARAM_0'];
67 $location = $_POST['PARAM_1'];
68 $pictures = $_POST['PARAM_2'];
69 $check = $_POST['PARAM_3'];
70 $comments = $_POST['PARAM_4'];
71 $destination = $_POST['PARAM_5'];
73 include_once($path_to_root . "/reporting/includes/excel_report.inc");
75 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
77 if ($category == reserved_words::get_all_numeric())
82 $cat = get_category_name($category);
84 if ($location == reserved_words::get_all())
86 if ($location == 'all')
93 $cols = array(0, 100, 250, 305, 375, 445, 515);
94 $headers = array(_('Category'), _('Description'), _('Quantity'), _('Check'), _('Demand'), _('Difference'));
95 $aligns = array('left', 'left', 'right', 'right', 'right', 'right');
99 $cols = array(0, 100, 305, 375, 445, 515);
100 $headers = array(_('Category'), _('Description'), _('Quantity'), _('Demand'), _('Difference'));
101 $aligns = array('left', 'left', 'right', 'right', 'right');
105 $params = array( 0 => $comments,
106 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
107 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
110 $user_comp = user_company();
114 $rep = new FrontReport(_('Stock Check Sheets'), "StockCheckSheet", user_pagesize());
117 $rep->Info($params, $cols, $headers, $aligns);
120 $res = getTransactions($category, $location);
122 while ($trans=db_fetch($res))
124 if ($catt != $trans['cat_description'])
128 $rep->Line($rep->row - 2);
131 $rep->TextCol(0, 1, $trans['category_id']);
132 $rep->TextCol(1, 2, $trans['cat_description']);
133 $catt = $trans['cat_description'];
136 if ($location == 'all')
139 $loc_code = $trans['loc_code'];
140 $demandqty = get_demand_qty($trans['stock_id'], $loc_code);
141 $demandqty += get_demand_asm_qty($trans['stock_id'], $loc_code);
143 $dec = get_qty_dec($trans['stock_id']);
144 $rep->TextCol(0, 1, $trans['stock_id']);
145 $rep->TextCol(1, 2, $trans['description']);
146 $rep->AmountCol(2, 3, $trans['QtyOnHand'], $dec);
149 $rep->TextCol(3, 4, "_________");
150 $rep->AmountCol(4, 5, $demandqty, $dec);
151 $rep->AmountCol(5, 6, $trans['QtyOnHand'] - $demandqty, $dec);
155 $rep->AmountCol(3, 4, $demandqty, $dec);
156 $rep->AmountCol(4, 5, $trans['QtyOnHand'] - $demandqty, $dec);
160 $image = $comp_path .'/'. $user_comp . '/images/'
161 . item_img_name($trans['stock_id']) . '.jpg';
162 if (file_exists($image))
165 if ($rep->row - $pic_height < $rep->bottomMargin)
167 $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, 0, $pic_height);
168 $rep->row -= $pic_height;
173 $rep->Line($rep->row - 4);