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 // ----------------------------------------------------------------
17 // Title: Order Status List
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 . "/sales/includes/sales_db.inc");
25 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
27 //----------------------------------------------------------------------------------------------------
29 // trial_inquiry_controls();
30 print_salesman_list();
32 //----------------------------------------------------------------------------------------------------
34 function GetSalesmanTrans($from, $to)
36 $fromdate = date2sql($from);
37 $todate = date2sql($to);
39 $sql = "SELECT DISTINCT ".TB_PREF."debtor_trans.*,
40 ov_amount+ov_discount AS InvoiceTotal,
41 ".TB_PREF."debtors_master.name AS DebtorName, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."cust_branch.br_name,
42 ".TB_PREF."cust_branch.contact_name, ".TB_PREF."salesman.*
43 FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master, ".TB_PREF."sales_orders, ".TB_PREF."cust_branch,
45 WHERE ".TB_PREF."sales_orders.order_no=".TB_PREF."debtor_trans.order_
46 AND ".TB_PREF."sales_orders.branch_code=".TB_PREF."cust_branch.branch_code
47 AND ".TB_PREF."cust_branch.salesman=".TB_PREF."salesman.salesman_code
48 AND ".TB_PREF."debtor_trans.debtor_no=".TB_PREF."debtors_master.debtor_no
49 AND (".TB_PREF."debtor_trans.type=10 OR ".TB_PREF."debtor_trans.type=11)
50 AND ".TB_PREF."debtor_trans.tran_date>='$fromdate'
51 AND ".TB_PREF."debtor_trans.tran_date<='$todate'
52 ORDER BY ".TB_PREF."salesman.salesman_code, ".TB_PREF."debtor_trans.tran_date";
54 return db_query($sql, "Error getting order details");
57 //----------------------------------------------------------------------------------------------------
59 function print_salesman_list()
63 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
65 $from = $_POST['PARAM_0'];
66 $to = $_POST['PARAM_1'];
67 $summary = $_POST['PARAM_2'];
68 $comments = $_POST['PARAM_3'];
75 $dec = user_qty_dec();
77 $cols = array(0, 60, 150, 220, 325, 385, 450, 515);
79 $headers = array(_('Invoice'), _('Customer'), _('Branch'), _('Customer Ref'),
80 _('Inv Date'), _('Total'), _('Provision'));
82 $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right');
84 $headers2 = array(_('Salesman'), " ", _('Phone'), _('Email'), _('Provision'),
85 _('Break Pt.'), _('Provision')." 2");
87 $params = array( 0 => $comments,
88 1 => array( 'text' => _('Period'), 'from' => $from, 'to' => $to),
89 2 => array( 'text' => _('Summary Only'),'from' => $sum,'to' => ''));
94 $rep = new FrontReport(_('Salesman Listing'), "SalesmanListing.pdf", user_pagesize());
96 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
100 $subtotal = $total = $subprov = $provtotal = 0;
102 $result = GetSalesmanTrans($from, $to);
104 while ($myrow=db_fetch($result))
106 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
111 $rep->NewLine(0, 2, false, $salesman);
112 if ($salesman != $myrow['salesman_code'])
116 $rep->Line($rep->row - 8);
118 $rep->TextCol(0, 3, _('Total'));
119 $rep->TextCol(5, 6, number_format2($subtotal, $dec));
120 $rep->TextCol(6, 7, number_format2($subprov, $dec));
121 $rep->Line($rep->row - 4);
123 //$rep->Line($rep->row);
125 $rep->TextCol(0, 2, $myrow['salesman_code']." ".$myrow['salesman_name']);
126 $rep->TextCol(2, 3, $myrow['salesman_phone']);
127 $rep->TextCol(3, 4, $myrow['salesman_email']);
128 $rep->TextCol(4, 5, number_format2($myrow['provision'], user_percent_dec()) ." %");
129 $rep->TextCol(5, 6, number_format2($myrow['break_pt'], $dec));
130 $rep->TextCol(6, 7, number_format2($myrow['provision2'], user_percent_dec()) ." %");
132 $salesman = $myrow['salesman_code'];
134 $provtotal += $subprov;
138 $date = sql2date($myrow['tran_date']);
139 $rate = $myrow['rate'];
140 $amt = $myrow['InvoiceTotal'] * $rate;
141 if ($subprov > $myrow['break_pt'] && $myrow['provision2'] != 0)
142 $prov = $myrow['provision2'] * $amt / 100;
144 $prov = $myrow['provision'] * $amt / 100;
147 $rep->TextCol(0, 1, $myrow['trans_no']);
148 $rep->TextCol(1, 2, $myrow['DebtorName']);
149 $rep->TextCol(2, 3, $myrow['br_name']);
150 $rep->TextCol(3, 4, $myrow['contact_name']);
151 $rep->TextCol(4, 5, $date);
152 $rep->TextCol(5, 6, number_format2($amt, $dec));
153 $rep->TextCol(6, 7, number_format2($prov, $dec));
155 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
166 $rep->Line($rep->row - 4);
168 $rep->TextCol(0, 3, _('Total'));
169 $rep->TextCol(5, 6, number_format2($subtotal, $dec));
170 $rep->TextCol(6, 7, number_format2($subprov, $dec));
171 $rep->Line($rep->row - 4);
173 //$rep->Line($rep->row);
175 $provtotal += $subprov;
178 $rep->TextCol(0, 3, _('Grand Total'));
180 $rep->TextCol(5, 6, number_format2($total, $dec));
181 $rep->TextCol(6, 7, number_format2($provtotal, $dec));
182 $rep->Line($rep->row - 4);