4 // ----------------------------------------------------------------
8 // Title: Inventory Planning
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();
21 print_inventory_sales();
23 function getTransactions($category, $location, $from, $to)
25 $from = date2sql($from);
27 $sql = "SELECT ".TB_PREF."stock_master.category_id,
28 ".TB_PREF."stock_category.description AS cat_description,
29 ".TB_PREF."stock_master.stock_id,
30 ".TB_PREF."stock_master.description,
31 ".TB_PREF."stock_moves.loc_code,
32 SUM(-".TB_PREF."stock_moves.qty*".TB_PREF."stock_moves.price*(1-".TB_PREF."stock_moves.discount_percent)) AS amt,
33 SUM(-".TB_PREF."stock_moves.qty) *(".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost) AS cost
34 FROM ".TB_PREF."stock_master,
35 ".TB_PREF."stock_category,
36 ".TB_PREF."debtor_trans,
37 ".TB_PREF."stock_moves
38 WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id
39 AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
41 AND ".TB_PREF."stock_moves.type=".TB_PREF."debtor_trans.type
42 AND ".TB_PREF."stock_moves.trans_no=".TB_PREF."debtor_trans.trans_no
43 AND ".TB_PREF."stock_moves.tran_date>='$from'
44 AND ".TB_PREF."stock_moves.tran_date<='$to'
45 AND ((".TB_PREF."debtor_trans.type=13 AND ".TB_PREF."debtor_trans.version=1) OR ".TB_PREF."stock_moves.type=11)
46 AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
48 $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
49 if ($location != 'all')
50 $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
51 //$sql .= " AND SUM(".TB_PREF."stock_moves.qty) != 0
52 $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
53 ".TB_PREF."stock_category.description,
54 ".TB_PREF."stock_master.stock_id,
55 ".TB_PREF."stock_master.description
56 ORDER BY ".TB_PREF."stock_master.category_id,
57 ".TB_PREF."stock_master.stock_id";
59 return db_query($sql,"No transactions were returned");
63 //----------------------------------------------------------------------------------------------------
65 function print_inventory_sales()
69 include_once($path_to_root . "reporting/includes/pdf_report.inc");
71 $from = $_POST['PARAM_0'];
72 $to = $_POST['PARAM_1'];
73 $category = $_POST['PARAM_2'];
74 $location = $_POST['PARAM_3'];
75 $detail = $_POST['PARAM_4'];
76 $comments = $_POST['PARAM_5'];
78 $dec = user_price_dec();
80 if ($category == reserved_words::get_all_numeric())
85 $cat = get_category_name($category);
87 if ($location == reserved_words::get_all())
89 if ($location == 'all')
92 $loc = get_location_name($location);
94 $cols = array(0, 100, 250, 350, 450, 515);
96 $headers = array(_('Category'), '', _('Sales'), _('Cost'), _('Contribution'));
98 $aligns = array('left', 'left', 'right', 'right', 'right');
100 $params = array( 0 => $comments,
101 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
102 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
103 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
105 $rep = new FrontReport(_('Inventory Sales Report'), "InventorySalesReport.pdf", user_pagesize());
108 $rep->Info($params, $cols, $headers, $aligns);
111 $res = getTransactions($category, $location, $from, $to);
112 $total = $grandtotal = 0.0;
113 $total1 = $grandtotal1 = 0.0;
114 $total2 = $grandtotal2 = 0.0;
116 while ($trans=db_fetch($res))
118 if ($catt != $trans['cat_description'])
125 $rep->TextCol(0, 2, _('Total'));
127 $rep->TextCol(2, 3, number_format2($total, $dec));
128 $rep->TextCol(3, 4, number_format2($total1, $dec));
129 $rep->Textcol(4, 5, number_format2($total2, $dec));
132 $rep->Line($rep->row - 2);
136 $total = $total1 = $total2 = 0.0;
138 $rep->TextCol(0, 1, $trans['category_id']);
139 $rep->TextCol(1, 2, $trans['cat_description']);
140 $catt = $trans['cat_description'];
144 $cb = $trans['amt'] - $trans['cost'];
149 $rep->TextCol(0, 1, $trans['stock_id']);
150 $rep->TextCol(1, 2, $trans['description']);
151 $rep->TextCol(2, 3, number_format2($trans['amt'], user_qty_dec()));
152 $rep->TextCol(3, 4, number_format2($trans['cost'], $dec));
153 $rep->TextCol(4, 5, number_format2($cb, $dec));
156 $total += $trans['amt'];
157 $total1 += $trans['cost'];
159 $grandtotal += $trans['amt'];
160 $grandtotal1 += $trans['cost'];
166 $rep->TextCol(0, 2, _('Total'));
168 $rep->TextCol(2, 3, number_format2($total, $dec));
169 $rep->TextCol(3, 4, number_format2($total1, $dec));
170 $rep->Textcol(4, 5, number_format2($total2, $dec));
173 $rep->Line($rep->row - 2);
177 $rep->TextCol(0, 2, _('Grand Total'));
178 $rep->TextCol(2, 3, number_format2($grandtotal, $dec));
179 $rep->TextCol(3, 4, number_format2($grandtotal1, $dec));
180 $rep->Textcol(4, 5, number_format2($grandtotal2, $dec));
182 $rep->Line($rep->row - 4);