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 ***********************************************************************/
12 $page_security = 'SA_SALESALLOC';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/sales/includes/sales_ui.inc");
18 include_once($path_to_root . "/sales/includes/sales_db.inc");
20 if ($use_popup_windows)
21 $js .= get_js_open_window(900, 500);
22 page(_("Customer Allocations"), false, false, "", $js);
24 //--------------------------------------------------------------------------------
27 /* show all outstanding receipts and credits to be allocated */
28 /*Clear any previous allocation records */
29 if (isset($_SESSION['alloc']))
31 unset($_SESSION['alloc']->allocs);
32 unset($_SESSION['alloc']);
34 if (!isset($_POST['customer_id']))
35 $_POST['customer_id'] = get_global_customer();
37 echo "<center>" . _("Select a customer: ") . " ";
38 customer_list('customer_id', $_POST['customer_id'], true, true);
40 check(_("Show Settled Items:"), 'ShowSettled', null, true);
41 echo "</center><br><br>";
43 set_global_customer($_POST['customer_id']);
45 if (isset($_POST['customer_id']) && ($_POST['customer_id'] == ALL_TEXT))
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 global $systypes_array;
69 return $systypes_array[$type];
72 function trans_view($trans)
74 return get_trans_view_str($trans["type"], $trans["trans_no"]);
77 function alloc_link($row)
79 return pager_link(_("Allocate"),
80 "/sales/allocations/customer_allocate.php?trans_no="
81 .$row["trans_no"] . "&trans_type=" . $row["type"], ICON_MONEY);
84 function amount_left($row)
86 return price_format($row["Total"]-$row["alloc"]);
89 function check_settled($row)
91 return $row['settled'] == 1;
95 $sql = get_allocatable_from_cust_sql($customer_id, $settled);
98 _("Transaction Type") => array('fun'=>'systype_name'),
99 _("#") => array('fun'=>'trans_view'),
101 _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'asc'),
102 _("Customer") => array('ord'=>''),
103 _("Currency") => array('align'=>'center'),
104 _("Total") => 'amount',
105 _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'),
106 array('insert'=>true, 'fun'=>'alloc_link')
109 if (isset($_POST['customer_id'])) {
110 $cols[_("Customer")] = 'skip';
111 $cols[_("Currency")] = 'skip';
114 $table =& new_db_pager('alloc_tbl', $sql, $cols);
115 $table->set_marker('check_settled', _("Marked items are settled."), 'settledbg', 'settledfg');
117 if (get_post('_ShowSettled_update') || get_post('_customer_id_update')) {
118 $table->set_sql($sql);
119 $table->set_columns($cols);
121 $table->width = "75%";
123 display_db_pager($table);