5 include($path_to_root . "/includes/db_pager.inc");
6 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/sales/includes/sales_ui.inc");
9 include_once($path_to_root . "/sales/includes/sales_db.inc");
12 if ($use_popup_windows)
13 $js .= get_js_open_window(900, 500);
15 $js .= get_js_date_picker();
16 page(_("Customer Allocation Inquiry"), false, false, "", $js);
18 if (isset($_GET['customer_id']))
20 $_POST['customer_id'] = $_GET['customer_id'];
23 //------------------------------------------------------------------------------------------------
25 if (!isset($_POST['customer_id']))
26 $_POST['customer_id'] = get_global_customer();
28 start_form(false, true);
30 start_table("class='tablestyle_noborder'");
33 customer_list_cells(_("Select a customer: "), 'customer_id', $_POST['customer_id'], true);
35 date_cells(_("from:"), 'TransAfterDate', '', null, -30);
36 date_cells(_("to:"), 'TransToDate', '', null, 1);
38 cust_allocations_list_cells(_("Type:"), 'filterType', null);
40 check_cells(" " . _("show settled:"), 'showSettled', null);
42 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true);
44 set_global_customer($_POST['customer_id']);
49 //------------------------------------------------------------------------------------------------
50 function check_overdue($row)
52 return ($row['OverDue'] == 1
53 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0));
56 function order_link($row)
58 return $row['order_']>0 ?
59 get_customer_trans_view_str(systypes::sales_order(), $row['order_'])
63 function systype_name($dummy, $type)
65 return systypes::name($type);
68 function view_link($trans)
70 return get_trans_view_str($trans["type"], $trans["trans_no"]);
73 function due_date($row)
75 return $row["type"] == 10 ? $row["due_date"] : '';
78 function fmt_balance($row)
80 return $row["TotalAmount"] - $row["Allocated"];
83 function alloc_link($row)
86 pager_link(_("Allocation"),
87 "/sales/allocations/customer_allocate.php?trans_no=" . $row["trans_no"]
88 ."&trans_type=" . $row["type"]);
90 if ($row["type"] == 11 && $row['TotalAmount'] > 0)
92 /*its a credit note which could have an allocation */
95 elseif (($row["type"] == systypes::cust_payment() || $row["type"] == systypes::bank_deposit()) &&
96 ($row['TotalAmount'] - $row['Allocated']) > 0)
98 /*its a receipt which could have an allocation*/
101 elseif ($row["type"] == systypes::cust_payment() && $row['TotalAmount'] < 0)
103 /*its a negative receipt */
108 function fmt_debit($row)
111 $row['type']==11 || $row['type']==12 || $row['type']==2 ?
112 -$row["TotalAmount"] : $row["TotalAmount"];
113 return $value>=0 ? price_format($value) : '';
117 function fmt_credit($row)
120 !($row['type']==11 || $row['type']==12 || $row['type']==2) ?
121 -$row["TotalAmount"] : $row["TotalAmount"];
122 return $value>0 ? price_format($value) : '';
124 //------------------------------------------------------------------------------------------------
126 $data_after = date2sql($_POST['TransAfterDate']);
127 $date_to = date2sql($_POST['TransToDate']);
138 (trans.ov_amount + trans.ov_gst + trans.ov_freight
139 + trans.ov_freight_tax + trans.ov_discount) AS TotalAmount,
140 trans.alloc AS Allocated,
142 AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue
144 .TB_PREF."debtor_trans as trans, "
145 .TB_PREF."debtors_master as debtor
146 WHERE debtor.debtor_no = trans.debtor_no
147 AND (trans.ov_amount + trans.ov_gst + trans.ov_freight
148 + trans.ov_freight_tax + trans.ov_discount != 0)
149 AND trans.tran_date >= '$data_after'
150 AND trans.tran_date <= '$date_to'";
152 if ($_POST['customer_id'] != reserved_words::get_all())
153 $sql .= " AND trans.debtor_no = '" . $_POST['customer_id'] . "'";
155 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
157 if ($_POST['filterType'] == '1' || $_POST['filterType'] == '2')
159 $sql .= " AND trans.type = 10 ";
161 elseif ($_POST['filterType'] == '3')
163 $sql .= " AND trans.type = " . systypes::cust_payment();
165 elseif ($_POST['filterType'] == '4')
167 $sql .= " AND trans.type = 11 ";
170 if ($_POST['filterType'] == '2')
172 $today = date2sql(Today());
173 $sql .= " AND trans.due_date < '$today'
174 AND (round(abs(trans.ov_amount + "
175 ."trans.ov_gst + trans.ov_freight + "
176 ."trans.ov_freight_tax + trans.ov_discount) - trans.alloc,6) > 0) ";
180 $sql .= " AND trans.type != 13 ";
184 if (!check_value('showSettled'))
186 $sql .= " AND (round(abs(trans.ov_amount + trans.ov_gst + "
187 ."trans.ov_freight + trans.ov_freight_tax + "
188 ."trans.ov_discount) - trans.alloc,6) != 0) ";
190 //------------------------------------------------------------------------------------------------
193 _("Type") => array('fun'=>'systype_name'),
194 _("Number") => array('fun'=>'view_link'),
196 _("Order") => array('fun'=>'order_link'),
197 _("Date") => array('type'=>'date', 'ord'=>'asc'),
198 _("Due Date") => array('type'=>'date', 'fun'=>'due_date'),
200 _("Currency") => array('align'=>'center'),
201 _("Debit") => array('align'=>'right','fun'=>'fmt_debit'),
202 _("Credit") => array('align'=>'right','insert'=>true, 'fun'=>'fmt_credit'),
203 _("Allocated") => 'amount',
204 _("Balance") => array('type'=>'amount', 'insert'=>true, 'fun'=>'fmt_balance'),
205 array('insert'=>true, 'fun'=>'alloc_link')
208 if ($_POST['customer_id'] != reserved_words::get_all()) {
209 $cols[_("Customer")] = 'skip';
210 $cols[_("Currency")] = 'skip';
213 $table =& new_db_pager('doc_tbl', $sql, $cols);
214 $table->set_marker('check_overdue', _("Marked items are overdue."));
216 if (get_post('RefreshInquiry')) {
217 $table->set_sql($sql);
218 $table->set_columns($cols);
222 display_db_pager($table);