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_SUPPLIERALLOC';
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 . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/includes/banking.inc");
22 include_once($path_to_root . "/sales/includes/sales_db.inc");
24 if ($SysPrefs->use_popup_windows)
25 $js .= get_js_open_window(900, 500);
26 page(_($help_context = "Supplier Allocations"), false, false, "", $js);
28 //--------------------------------------------------------------------------------
32 /* show all outstanding receipts and credits to be allocated */
33 if (!isset($_POST['supplier_id']))
34 $_POST['supplier_id'] = get_global_supplier();
36 echo "<center>" . _("Select a Supplier: ") . " ";
37 echo supplier_list('supplier_id', $_POST['supplier_id'], true, true);
39 check(_("Show Settled Items:"), 'ShowSettled', null, true);
40 echo "</center><br><br>";
41 set_global_supplier($_POST['supplier_id']);
43 if (isset($_POST['supplier_id']) && ($_POST['supplier_id'] == ALL_TEXT))
45 unset($_POST['supplier_id']);
49 if (check_value('ShowSettled'))
52 if (isset($_POST['supplier_id']))
53 $supplier_id = $_POST['supplier_id'];
55 //--------------------------------------------------------------------------------
56 function systype_name($dummy, $type)
58 global $systypes_array;
60 return $systypes_array[$type];
63 function trans_view($trans)
65 return get_trans_view_str($trans["type"], $trans["trans_no"]);
68 function alloc_link($row)
70 return pager_link(_("Allocate"),
71 "/purchasing/allocations/supplier_allocate.php?trans_no="
72 .$row["trans_no"] . "&trans_type=" . $row["type"]. "&supplier_id=" . $row["supplier_id"], ICON_ALLOC);
75 function amount_left($row)
77 return price_format($row['type'] == ST_JOURNAL ? abs($row["Total"])-$row["alloc"] : -$row["Total"]-$row["alloc"]);
80 function amount_total($row)
82 return price_format(-$row["Total"]);
85 function check_settled($row)
87 return $row['settled'] == 1;
91 $sql = get_allocatable_from_supp_sql($supplier_id, $settled);
94 _("Transaction Type") => array('fun'=>'systype_name'),
95 _("#") => array('fun'=>'trans_view', 'align'=>'right'),
97 _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'asc'),
98 _("Supplier") => array('ord'=>''),
99 _("Currency") => array('align'=>'center'),
100 _("Total") => array('align'=>'right', 'fun'=>'amount_total'),
101 _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'),
102 array('insert'=>true, 'fun'=>'alloc_link')
105 if (isset($_POST['customer_id'])) {
106 $cols[_("Supplier")] = 'skip';
107 $cols[_("Currency")] = 'skip';
110 $table =& new_db_pager('alloc_tbl', $sql, $cols);
111 $table->set_marker('check_settled', _("Marked items are settled."), 'settledbg', 'settledfg');
113 $table->width = "80%";
115 display_db_pager($table);