Removed obsolete submit_on_change option from sales_credit_note dimension lists.
[fa-stable.git] / purchasing / allocations / supplier_allocation_main.php
1 <?php
2
3 $path_to_root="../..";
4 $page_security = 3;
5 include($path_to_root . "/includes/db_pager.inc");
6 include_once($path_to_root . "/includes/session.inc");
7
8 include_once($path_to_root . "/includes/date_functions.inc");
9
10 include_once($path_to_root . "/includes/ui.inc");
11 include_once($path_to_root . "/includes/banking.inc");
12
13 include_once($path_to_root . "/sales/includes/sales_db.inc");
14 $js = "";
15 if ($use_popup_windows)
16         $js .= get_js_open_window(900, 500);
17 page(_("Supplier Allocations"), false, false, "", $js);
18
19 //--------------------------------------------------------------------------------
20 if ($ret = context_restore()) {
21         if(isset($ret['supplier_id']))
22                 $_POST['supplier_id'] = $ret['supplier_id'];
23 }
24 if (isset($_POST['_supplier_id_editor'])) {
25         context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'] );
26 }
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
48 end_form();
49         set_global_supplier($_POST['supplier_id']);
50
51         if (isset($_POST['supplier_id']) && ($_POST['supplier_id'] == reserved_words::get_all())) 
52         {
53                 unset($_POST['supplier_id']);
54         }
55
56         $settled = false;
57         if (check_value('ShowSettled'))
58                 $settled = true;
59         $supplier_id = null;
60         if (isset($_POST['supplier_id']))
61                 $supplier_id = $_POST['supplier_id'];
62
63 //--------------------------------------------------------------------------------
64 function systype_name($dummy, $type)
65 {
66         return systypes::name($type);
67 }
68
69 function trans_view($trans)
70 {
71         return get_trans_view_str($trans["type"], $trans["trans_no"]);
72 }
73
74 function alloc_link($row)
75 {
76         return pager_link(_("Allocate"),
77                 "/purchasing/allocations/supplier_allocate.php?trans_no="
78                         .$row["trans_no"] . "&trans_type=" . $row["type"] );
79 }
80
81 function amount_left($row)
82 {
83         return -$row["Total"]-$row["alloc"];
84 }
85
86 function amount_total($row)
87 {
88         return -$row["Total"];
89 }
90
91 function check_settled($row)
92 {
93         return $row['settled'] == 1;
94 }
95
96
97 $sql = get_allocatable_from_supp_sql($supplier_id, $settled);
98
99 $cols = array(
100         _("Transaction Type") => array('fun'=>'systype_name'),
101         _("#") => array('fun'=>'trans_view'),
102         _("Reference"), 
103         _("Date") => array('type'=>'date', 'ord'=>'asc'),
104         _("Supplier") => array('ord'=>''),
105         _("Currency") => array('align'=>'center'),
106         _("Total") => 'amount', 
107         _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'), 
108         array('insert'=>true, 'fun'=>'alloc_link')
109         );
110
111 if (isset($_POST['customer_id'])) {
112         $cols[_("Supplier")] = 'skip';
113         $cols[_("Currency")] = 'skip';
114 }
115
116 $table =& new_db_pager('alloc_tbl', $sql, $cols);
117 $table->set_marker('check_settled', _("Marked items are settled."), 'settledbg', 'settledfg');
118
119 if (get_post('_ShowSettled_update') || get_post('_supplier_id_update') ) {
120         $table->set_sql($sql);
121         $table->set_columns($cols);
122         $Ajax->activate('alloc_tbl');
123 }
124
125         start_form();
126         display_db_pager($table);
127         end_form();
128 end_page();
129
130
131 ?>