Merged bugfixes upto [0000072] (version 2.0.3).
[fa-stable.git] / purchasing / allocations / supplier_allocation_main.php
1 <?php
2
3 $path_to_root="../..";
4 $page_security = 3;
5 include_once($path_to_root . "/includes/session.inc");
6
7 include_once($path_to_root . "/includes/date_functions.inc");
8
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/banking.inc");
11
12 include_once($path_to_root . "/sales/includes/sales_db.inc");
13 $js = "";
14 if ($use_popup_windows)
15         $js .= get_js_open_window(900, 500);
16 page(_("Supplier Allocations"), false, false, "", $js);
17
18 //--------------------------------------------------------------------------------
19 if ($ret = context_restore()) {
20         if(isset($ret['supplier_id']))
21                 $_POST['supplier_id'] = $ret['supplier_id'];
22 }
23 if (isset($_POST['_supplier_id_editor'])) {
24         context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'] );
25 }
26
27 //--------------------------------------------------------------------------------
28
29 function display_allocatable_transactions()
30 {
31         global $table_style, $path_to_root;
32         start_form();
33
34         /* show all outstanding receipts and credits to be allocated */
35         /*Clear any previous allocation records */
36         if (isset($_SESSION['alloc']))
37         {
38                 unset($_SESSION['alloc']->allocs);
39                 unset($_SESSION['alloc']);
40         }
41     if (!isset($_POST['supplier_id']))
42         $_POST['supplier_id'] = get_global_supplier();
43
44     echo "<center>" . _("Select a Supplier: ") . "&nbsp;&nbsp;";
45         supplier_list('supplier_id', $_POST['supplier_id'], true, true);
46     echo "<br>";
47     check(_("Show Settled Items:"), 'ShowSettled', null, true);
48         echo "</center><br><br>";
49
50         set_global_supplier($_POST['supplier_id']);
51
52         if (isset($_POST['supplier_id']) && ($_POST['supplier_id'] == reserved_words::get_all())) 
53         {
54                 unset($_POST['supplier_id']);
55         }
56
57         $settled = false;
58         if (check_value('ShowSettled'))
59                 $settled = true;
60
61         $supplier_id = null;
62         if (isset($_POST['supplier_id']))
63                 $supplier_id = $_POST['supplier_id'];
64
65         $trans_items = get_allocatable_from_supp_transactions($supplier_id, $settled);
66         div_start('alloc_tbl');
67         start_table($table_style);
68         if (!isset($_POST['supplier_id']))
69                 $th = array(_("Transaction Type"), _("#"), _("Reference"), _("Date"), _("Supplier"), 
70                         _("Currency"), _("Total"), _("Left To Allocate"));
71         else
72                 $th = array(_("Transaction Type"), _("#"), _("Reference"), _("Date"), 
73                         _("Total"), _("Left To Allocate"));
74         table_header($th);      
75
76         $k = 0; //row colour counter
77         $has_settled_items = false;
78
79         while ($myrow = db_fetch($trans_items))
80         {
81         if ($myrow["settled"] == 1) 
82         {
83                 start_row("class='settledbg'");
84                 $has_settled_items = true;
85         } 
86         else 
87         {
88                 alt_table_row_color($k);
89         }
90
91         label_cell(systypes::name($myrow["type"]));
92                 label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"]));
93                 label_cell($myrow["reference"]);
94         label_cell(sql2date($myrow["tran_date"]));
95
96                 if (!isset($_POST['supplier_id']))
97                 {
98                 label_cell($myrow["supp_name"]);
99                 label_cell($myrow["curr_code"]);
100                 }
101                 amount_cell(-$myrow["Total"]);
102         amount_cell(-$myrow["Total"]-$myrow["alloc"]);
103         label_cell("<a href='$path_to_root/purchasing/allocations/supplier_allocate.php?trans_no=" . $myrow["trans_no"] . "&trans_type=" . $myrow["type"]  . "'>" . _("Allocate") . "</a>");
104         end_row();
105         }
106
107         end_table();
108
109         if ($has_settled_items)
110                 display_note(_("Marked items are settled."), 0, 1, "class='settledfg'");
111
112         if (db_num_rows($trans_items) == 0)
113                 display_note(_("There are no allocations to be done."), 1, 2);
114         div_end();
115         end_form();
116 }
117
118 //--------------------------------------------------------------------------------
119
120 if (get_post('_ShowSettled_update')) {
121         $Ajax->activate('alloc_tbl');
122 }
123 display_allocatable_transactions();
124
125 //--------------------------------------------------------------------------------
126
127 end_page();
128
129 ?>