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");
11 if ($use_popup_windows)
12 $js .= get_js_open_window(900, 500);
13 page(_("Customer Allocations"), false, false, "", $js);
15 //--------------------------------------------------------------------------------
16 if ($ret = context_restore()) {
17 if(isset($ret['customer_id']))
18 $_POST['customer_id'] = $ret['customer_id'];
20 if (isset($_POST['_customer_id_editor'])) {
21 context_call($path_to_root.'/sales/manage/customers.php?debtor_no='.$_POST['customer_id'] );
25 /* show all outstanding receipts and credits to be allocated */
26 /*Clear any previous allocation records */
27 if (isset($_SESSION['alloc']))
29 unset($_SESSION['alloc']->allocs);
30 unset($_SESSION['alloc']);
32 if (!isset($_POST['customer_id']))
33 $_POST['customer_id'] = get_global_customer();
35 echo "<center>" . _("Select a customer: ") . " ";
36 customer_list('customer_id', $_POST['customer_id'], true, true);
38 check(_("Show Settled Items:"), 'ShowSettled', null, true);
39 echo "</center><br><br>";
41 set_global_customer($_POST['customer_id']);
43 if (isset($_POST['customer_id']) && ($_POST['customer_id'] == reserved_words::get_all()))
45 unset($_POST['customer_id']);
48 /*if (isset($_POST['customer_id'])) {
49 $custCurr = get_customer_currency($_POST['customer_id']);
50 if (!is_company_currency($custCurr))
51 echo _("Customer Currency:") . $custCurr;
55 if (check_value('ShowSettled'))
59 if (isset($_POST['customer_id']))
60 $customer_id = $_POST['customer_id'];
62 //--------------------------------------------------------------------------------
63 function systype_name($dummy, $type)
65 return systypes::name($type);
68 function trans_view($trans)
70 return get_trans_view_str($trans["type"], $trans["trans_no"]);
73 function alloc_link($row)
75 return pager_link(_("Allocate"),
76 "/sales/allocations/customer_allocate.php?trans_no="
77 .$row["trans_no"] . "&trans_type=" . $row["type"]
81 function amount_left($row)
83 return $row["Total"]-$row["alloc"];
86 function check_settled($row)
88 return $row['settled'] == 1;
92 $sql = get_allocatable_from_cust_sql($customer_id, $settled);
95 _("Transaction Type") => array('fun'=>'systype_name'),
96 _("#") => array('fun'=>'trans_view'),
98 _("Date") => array('type'=>'date', 'ord'=>'asc'),
99 _("Customer") => array('ord'=>''),
100 _("Currency") => array('align'=>'center'),
101 _("Total") => 'amount',
102 _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'),
103 array('insert'=>true, 'fun'=>'alloc_link')
106 if (isset($_POST['customer_id'])) {
107 $cols[_("Customer")] = 'skip';
108 $cols[_("Currency")] = 'skip';
111 $table =& new_db_pager('alloc_tbl', $sql, $cols);
112 $table->set_marker('check_settled', _("Marked items are settled."), 'settledbg', 'settledfg');
114 if (get_post('_ShowSettled_update') || get_post('_customer_id_update')) {
115 $table->set_sql($sql);
116 $table->set_columns($cols);
119 display_db_pager($table);