Eliminated non-static method calls and other bulk fixes to fix php5 warnings
[fa-stable.git] / purchasing / allocations / supplier_allocation_main.php
1 <?php
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");
16
17 include_once($path_to_root . "/includes/date_functions.inc");
18
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/includes/banking.inc");
21
22 include_once($path_to_root . "/sales/includes/sales_db.inc");
23 $js = "";
24 if ($use_popup_windows)
25         $js .= get_js_open_window(900, 500);
26 page(_("Supplier Allocations"), false, false, "", $js);
27
28 //--------------------------------------------------------------------------------
29
30 start_form();
31
32         /* show all outstanding receipts and credits to be allocated */
33         /*Clear any previous allocation records */
34         if (isset($_SESSION['alloc']))
35         {
36                 unset($_SESSION['alloc']->allocs);
37                 unset($_SESSION['alloc']);
38         }
39     if (!isset($_POST['supplier_id']))
40         $_POST['supplier_id'] = get_global_supplier();
41
42     echo "<center>" . _("Select a Supplier: ") . "&nbsp;&nbsp;";
43         supplier_list('supplier_id', $_POST['supplier_id'], true, true);
44     echo "<br>";
45     check(_("Show Settled Items:"), 'ShowSettled', null, true);
46         echo "</center><br><br>";
47         end_form();
48         set_global_supplier($_POST['supplier_id']);
49
50         if (isset($_POST['supplier_id']) && ($_POST['supplier_id'] == ALL_TEXT)) 
51         {
52                 unset($_POST['supplier_id']);
53         }
54
55         $settled = false;
56         if (check_value('ShowSettled'))
57                 $settled = true;
58         $supplier_id = null;
59         if (isset($_POST['supplier_id']))
60                 $supplier_id = $_POST['supplier_id'];
61
62 //--------------------------------------------------------------------------------
63 function systype_name($dummy, $type)
64 {
65         global $systypes_array;
66
67         return $systypes_array[$type;
68 }
69
70 function trans_view($trans)
71 {
72         return get_trans_view_str($trans["type"], $trans["trans_no"]);
73 }
74
75 function alloc_link($row)
76 {
77         return pager_link(_("Allocate"),
78                 "/purchasing/allocations/supplier_allocate.php?trans_no="
79                         .$row["trans_no"] . "&trans_type=" . $row["type"], ICON_MONEY );
80 }
81
82 function amount_left($row)
83 {
84         return price_format(-$row["Total"]-$row["alloc"]);
85 }
86
87 function amount_total($row)
88 {
89         return price_format(-$row["Total"]);
90 }
91
92 function check_settled($row)
93 {
94         return $row['settled'] == 1;
95 }
96
97
98 $sql = get_allocatable_from_supp_sql($supplier_id, $settled);
99
100 $cols = array(
101         _("Transaction Type") => array('fun'=>'systype_name'),
102         _("#") => array('fun'=>'trans_view'),
103         _("Reference"), 
104         _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'asc'),
105         _("Supplier") => array('ord'=>''),
106         _("Currency") => array('align'=>'center'),
107         _("Total") => array('align'=>'right', 'fun'=>'amount_total'), 
108         _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'), 
109         array('insert'=>true, 'fun'=>'alloc_link')
110         );
111
112 if (isset($_POST['customer_id'])) {
113         $cols[_("Supplier")] = 'skip';
114         $cols[_("Currency")] = 'skip';
115 }
116
117 $table =& new_db_pager('alloc_tbl', $sql, $cols);
118 $table->set_marker('check_settled', _("Marked items are settled."), 'settledbg', 'settledfg');
119
120 if (get_post('_ShowSettled_update') || get_post('_supplier_id_update') ) {
121         $table->set_sql($sql);
122         $table->set_columns($cols);
123 }
124 $table->width = "80%";
125 start_form();
126
127 display_db_pager($table);
128
129 end_form();
130 end_page();
131 ?>