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_SALESANALYTIC';
13 // ----------------------------------------------------------------
17 // Title: Sales Summary Report
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 . "/includes/banking.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
28 //----------------------------------------------------------------------------------------------------
30 print_inventory_sales();
32 function getTransactions($category, $from, $to)
34 $from = date2sql($from);
36 $sql = "SELECT item.category_id,
37 category.description AS cat_description,
40 line.unit_price * trans.rate AS unit_price,
41 SUM(line.quantity) as quantity
42 FROM ".TB_PREF."stock_master item,
43 ".TB_PREF."stock_category category,
44 ".TB_PREF."debtor_trans trans,
45 ".TB_PREF."debtor_trans_details line
46 WHERE line.stock_id = item.stock_id
47 AND item.category_id=category.category_id
48 AND line.debtor_trans_type=trans.type
49 AND line.debtor_trans_no=trans.trans_no
50 AND trans.tran_date>='$from'
51 AND trans.tran_date<='$to'
53 AND line.debtor_trans_type = ".ST_SALESINVOICE;
55 $sql .= " AND item.category_id = ".db_escape($category);
56 $sql .= " GROUP BY item.category_id,
61 ORDER BY item.category_id, item.stock_id, line.unit_price";
63 //display_notification($sql);
65 return db_query($sql,"No transactions were returned");
69 //----------------------------------------------------------------------------------------------------
71 function print_inventory_sales()
75 $from = $_POST['PARAM_0'];
76 $to = $_POST['PARAM_1'];
77 $category = $_POST['PARAM_2'];
78 $comments = $_POST['PARAM_3'];
79 $orientation = $_POST['PARAM_4'];
80 $destination = $_POST['PARAM_5'];
82 include_once($path_to_root . "/reporting/includes/excel_report.inc");
84 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
86 $orientation = ($orientation ? 'L' : 'P');
87 $dec = user_price_dec();
89 if ($category == ALL_NUMERIC)
94 $cat = get_category_name($category);
96 $cols = array(0, 100, 260, 300, 350, 425, 430, 515);
98 $headers = array(_('Item/Category'), _('Description'), _('Qty'), _('Unit Price'), _('Sales'), '', _('Remark'));
100 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'left');
102 $params = array( 0 => $comments,
103 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
104 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''));
106 $rep = new FrontReport(_('Item Sales Summary Report'), "ItemSalesSummaryReport", user_pagesize(), 9, $orientation);
107 if ($orientation == 'L')
108 recalculate_cols($cols);
111 $rep->Info($params, $cols, $headers, $aligns);
114 $res = getTransactions($category, $from, $to);
115 $total = $grandtotal = 0.0;
117 while ($trans=db_fetch($res))
119 if ($catt != $trans['cat_description'])
124 $rep->TextCol(0, 4, _('Total'));
125 $rep->AmountCol(4, 5, $total, $dec);
126 $rep->Line($rep->row - 2);
131 $rep->TextCol(0, 1, $trans['category_id']);
132 $rep->TextCol(1, 7, $trans['cat_description']);
133 $catt = $trans['cat_description'];
139 $rep->TextCol(0, 1, $trans['stock_id']);
140 $rep->TextCol(1, 2, $trans['description']);
141 $rep->AmountCol(2, 3, $trans['quantity'], get_qty_dec($trans['stock_id']));
142 $rep->AmountCol(3, 4, $trans['unit_price'], $dec);
143 $rep->AmountCol(4, 5, $trans['quantity']*$trans['unit_price'], $dec);
144 if ($trans['unit_price'] == 0)
145 $rep->TextCol(6, 7, _('Gift'));
147 $total += $trans['quantity']*$trans['unit_price'];
148 $grandtotal += $trans['quantity']*$trans['unit_price'];
151 $rep->TextCol(0, 4, _('Total'));
152 $rep->AmountCol(4, 5, $total, $dec);
153 $rep->Line($rep->row - 2);
156 $rep->TextCol(0, 4, _('Grand Total'));
157 $rep->AmountCol(4, 5, $grandtotal, $dec);
159 $rep->Line($rep->row - 4);