4 // ----------------------------------------------------------------
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
16 include_once($path_to_root . "inventory/includes/db/items_category_db.inc");
18 //----------------------------------------------------------------------------------------------------
20 // trial_inquiry_controls();
23 function getTransactions($category, $location)
25 $sql = "SELECT ".TB_PREF."stock_master.category_id,
26 ".TB_PREF."stock_category.description AS cat_description,
27 ".TB_PREF."stock_master.stock_id,
28 ".TB_PREF."stock_master.description,
29 IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
30 SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS QtyOnHand
31 FROM (".TB_PREF."stock_master,
32 ".TB_PREF."stock_category)
33 LEFT JOIN ".TB_PREF."stock_moves ON
34 (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id OR ".TB_PREF."stock_master.stock_id IS NULL)
35 WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
36 AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
38 $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
39 if ($location != 'all')
40 $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
41 $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
42 ".TB_PREF."stock_category.description,
43 ".TB_PREF."stock_master.stock_id,
44 ".TB_PREF."stock_master.description
45 ORDER BY ".TB_PREF."stock_master.category_id,
46 ".TB_PREF."stock_master.stock_id";
48 return db_query($sql,"No transactions were returned");
51 function getDemandQty($stockid, $location)
53 $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand
54 FROM ".TB_PREF."sales_order_details,
55 ".TB_PREF."sales_orders
56 WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND ";
58 $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
59 $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'";
61 $TransResult = db_query($sql,"No transactions were returned");
62 $DemandRow = db_fetch($TransResult);
63 return $DemandRow['QtyDemand'];
66 function getDemandAsmQty($stockid, $location)
68 $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity)
70 FROM ".TB_PREF."sales_order_details,
71 ".TB_PREF."sales_orders,
73 ".TB_PREF."stock_master
74 WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND
75 ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ";
77 $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
78 $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
79 ".TB_PREF."bom.component='$stockid' AND
80 ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND
81 ".TB_PREF."stock_master.mb_flag='A'";
83 $TransResult = db_query($sql,"No transactions were returned");
84 if (db_num_rows($TransResult)==1)
86 $DemandRow = db_fetch_row($TransResult);
87 $DemandQty = $DemandRow[0];
95 //----------------------------------------------------------------------------------------------------
97 function print_stock_check()
99 global $comp_path, $path_to_root, $pic_height, $pic_width;
101 include_once($path_to_root . "reporting/includes/pdf_report.inc");
103 $category = $_POST['PARAM_0'];
104 $location = $_POST['PARAM_1'];
105 $pictures = $_POST['PARAM_2'];
106 $check = $_POST['PARAM_3'];
107 $comments = $_POST['PARAM_4'];
109 if ($category == reserved_words::get_all_numeric())
114 $cat = get_category_name($category);
116 if ($location == reserved_words::get_all())
118 if ($location == 'all')
125 $cols = array(0, 100, 250, 305, 375, 445, 515);
126 $headers = array(_('Category'), _('Description'), _('Quantity'), _('Check'), _('Demand'), _('Difference'));
127 $aligns = array('left', 'left', 'right', 'right', 'right', 'right');
131 $cols = array(0, 100, 305, 375, 445, 515);
132 $headers = array(_('Category'), _('Description'), _('Quantity'), _('Demand'), _('Difference'));
133 $aligns = array('left', 'left', 'right', 'right', 'right');
137 $params = array( 0 => $comments,
138 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
139 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
142 $user_comp = user_company();
146 $rep = new FrontReport(_('Stock Check Sheets'), "StockCheckSheet.pdf", user_pagesize());
149 $rep->Info($params, $cols, $headers, $aligns);
152 $res = getTransactions($category, $location);
154 while ($trans=db_fetch($res))
156 if ($catt != $trans['cat_description'])
160 $rep->Line($rep->row - 2);
163 $rep->TextCol(0, 1, $trans['category_id']);
164 $rep->TextCol(1, 2, $trans['cat_description']);
165 $catt = $trans['cat_description'];
168 if ($location == 'all')
171 $loc_code = $trans['loc_code'];
172 $demandqty = getDemandQty($trans['stock_id'], $loc_code);
173 $demandqty += getDemandAsmQty($trans['stock_id'], $loc_code);
175 $dec = get_qty_dec($trans['stock_id']);
176 $rep->TextCol(0, 1, $trans['stock_id']);
177 $rep->TextCol(1, 2, $trans['description']);
178 $rep->TextCol(2, 3, number_format2($trans['QtyOnHand'], $dec));
181 $rep->TextCol(3, 4, "_________");
182 $rep->TextCol(4, 5, number_format2($demandqty, $dec));
183 $rep->TextCol(5, 6, number_format2($trans['QtyOnHand'] - $demandqty, $dec));
187 $rep->TextCol(3, 4, number_format2($demandqty, $dec));
188 $rep->TextCol(4, 5, number_format2($trans['QtyOnHand'] - $demandqty, $dec));
192 $image = $comp_path .'/'. $user_comp . '/images/' . $trans['stock_id'] . '.jpg';
193 if (file_exists($image))
196 if ($rep->row - $pic_height < $rep->bottomMargin)
198 $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, $pic_width, $pic_height);
199 $rep->row -= $pic_height;
204 $rep->Line($rep->row - 4);