4 // ----------------------------------------------------------------
8 // Title: Order Status List
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 . "sales/includes/sales_db.inc");
16 include_once($path_to_root . "inventory/includes/db/items_category_db.inc");
18 //----------------------------------------------------------------------------------------------------
20 // trial_inquiry_controls();
21 print_salesman_list();
23 //----------------------------------------------------------------------------------------------------
25 function GetSalesmanTrans($from, $to)
27 $fromdate = date2sql($from);
28 $todate = date2sql($to);
30 $sql = "SELECT DISTINCT ".TB_PREF."debtor_trans.*,
31 ov_amount+ov_discount AS InvoiceTotal,
32 ".TB_PREF."debtors_master.name AS DebtorName, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."cust_branch.br_name,
33 ".TB_PREF."cust_branch.contact_name, ".TB_PREF."salesman.*
34 FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master, ".TB_PREF."sales_orders, ".TB_PREF."cust_branch,
36 WHERE ".TB_PREF."sales_orders.order_no=".TB_PREF."debtor_trans.order_
37 AND ".TB_PREF."sales_orders.branch_code=".TB_PREF."cust_branch.branch_code
38 AND ".TB_PREF."cust_branch.salesman=".TB_PREF."salesman.salesman_code
39 AND ".TB_PREF."debtor_trans.debtor_no=".TB_PREF."debtors_master.debtor_no
40 AND (".TB_PREF."debtor_trans.type=10 OR ".TB_PREF."debtor_trans.type=11)
41 AND ".TB_PREF."debtor_trans.tran_date>='$fromdate'
42 AND ".TB_PREF."debtor_trans.tran_date<='$todate'
43 ORDER BY ".TB_PREF."salesman.salesman_code, ".TB_PREF."debtor_trans.tran_date";
45 return db_query($sql, "Error getting order details");
48 //----------------------------------------------------------------------------------------------------
50 function print_salesman_list()
54 include_once($path_to_root . "reporting/includes/pdf_report.inc");
56 $from = $_POST['PARAM_0'];
57 $to = $_POST['PARAM_1'];
58 $summary = $_POST['PARAM_2'];
59 $comments = $_POST['PARAM_3'];
66 $dec = user_qty_dec();
68 $cols = array(0, 60, 150, 220, 325, 385, 450, 515);
70 $headers = array(_('Invoice'), _('Customer'), _('Branch'), _('Customer Ref'),
71 _('Inv Date'), _('Total'), _('Provision'));
73 $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right');
75 $headers2 = array(_('Salesman'), " ", _('Phone'), _('Email'), _('Provision'),
76 _('Break Pt.'), _('Provision')." 2");
78 $params = array( 0 => $comments,
79 1 => array( 'text' => _('Period'), 'from' => $from, 'to' => $to),
80 2 => array( 'text' => _('Summary Only'),'from' => $sum,'to' => ''));
85 $rep = new FrontReport(_('Salesman Listing'), "SalesmanListing.pdf", user_pagesize());
87 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
91 $subtotal = $total = $subprov = $provtotal = 0;
93 $result = GetSalesmanTrans($from, $to);
95 while ($myrow=db_fetch($result))
97 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
102 $rep->NewLine(0, 2, false, $salesman);
103 if ($salesman != $myrow['salesman_code'])
107 $rep->Line($rep->row - 8);
109 $rep->TextCol(0, 3, _('Total'));
110 $rep->TextCol(5, 6, number_format2($subtotal, $dec));
111 $rep->TextCol(6, 7, number_format2($subprov, $dec));
112 $rep->Line($rep->row - 4);
114 //$rep->Line($rep->row);
116 $rep->TextCol(0, 2, $myrow['salesman_code']." ".$myrow['salesman_name']);
117 $rep->TextCol(2, 3, $myrow['salesman_phone']);
118 $rep->TextCol(3, 4, $myrow['salesman_email']);
119 $rep->TextCol(4, 5, number_format2($myrow['provision'], user_percent_dec()) ." %");
120 $rep->TextCol(5, 6, number_format2($myrow['break_pt'], $dec));
121 $rep->TextCol(6, 7, number_format2($myrow['provision2'], user_percent_dec()) ." %");
123 $salesman = $myrow['salesman_code'];
125 $provtotal += $subprov;
129 $date = sql2date($myrow['tran_date']);
130 $rate = $myrow['rate'];
131 $amt = $myrow['InvoiceTotal'] * $rate;
132 if ($subprov > $myrow['break_pt'] && $myrow['provision2'] != 0)
133 $prov = $myrow['provision2'] * $amt / 100;
135 $prov = $myrow['provision'] * $amt / 100;
138 $rep->TextCol(0, 1, $myrow['trans_no']);
139 $rep->TextCol(1, 2, $myrow['DebtorName']);
140 $rep->TextCol(2, 3, $myrow['br_name']);
141 $rep->TextCol(3, 4, $myrow['contact_name']);
142 $rep->TextCol(4, 5, $date);
143 $rep->TextCol(5, 6, number_format2($amt, $dec));
144 $rep->TextCol(6, 7, number_format2($prov, $dec));
146 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
157 $rep->Line($rep->row - 4);
159 $rep->TextCol(0, 3, _('Total'));
160 $rep->TextCol(5, 6, number_format2($subtotal, $dec));
161 $rep->TextCol(6, 7, number_format2($subprov, $dec));
162 $rep->Line($rep->row - 4);
164 //$rep->Line($rep->row);
166 $provtotal += $subprov;
169 $rep->TextCol(0, 3, _('Grand Total'));
171 $rep->TextCol(5, 6, number_format2($total, $dec));
172 $rep->TextCol(6, 7, number_format2($provtotal, $dec));
173 $rep->Line($rep->row - 4);