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>";
43 set_global_customer($_POST['customer_id']);
45 if (isset($_POST['customer_id']) && ($_POST['customer_id'] == reserved_words::get_all()))
47 unset($_POST['customer_id']);
50 /*if (isset($_POST['customer_id'])) {
51 $custCurr = get_customer_currency($_POST['customer_id']);
52 if (!is_company_currency($custCurr))
53 echo _("Customer Currency:") . $custCurr;
57 if (check_value('ShowSettled'))
61 if (isset($_POST['customer_id']))
62 $customer_id = $_POST['customer_id'];
64 //--------------------------------------------------------------------------------
65 function systype_name($dummy, $type)
67 return systypes::name($type);
70 function trans_view($trans)
72 return get_trans_view_str($trans["type"], $trans["trans_no"]);
75 function alloc_link($row)
77 return pager_link(_("Allocate"),
78 "/sales/allocations/customer_allocate.php?trans_no="
79 .$row["trans_no"] . "&trans_type=" . $row["type"]
83 function amount_left($row)
85 return $row["Total"]-$row["alloc"];
88 function check_settled($row)
90 return $row['settled'] == 1;
94 $sql = get_allocatable_from_cust_sql($customer_id, $settled);
97 _("Transaction Type") => array('fun'=>'systype_name'),
98 _("#") => array('fun'=>'trans_view'),
100 _("Date") => array('type'=>'date', 'ord'=>'asc'),
101 _("Customer") => array('ord'=>''),
102 _("Currency") => array('align'=>'center'),
103 _("Total") => 'amount',
104 _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'),
105 array('insert'=>true, 'fun'=>'alloc_link')
108 if (isset($_POST['customer_id'])) {
109 $cols[_("Customer")] = 'skip';
110 $cols[_("Currency")] = 'skip';
113 $table =& new_db_pager('alloc_tbl', $sql, $cols);
114 $table->set_marker('check_settled', _("Marked items are settled."), 'settledbg', 'settledfg');
116 if (get_post('_ShowSettled_update') || get_post('_customer_id_update')) {
117 $table->set_sql($sql);
118 $table->set_columns($cols);
119 $Ajax->activate('alloc_tbl');
123 display_db_pager($table);