Moving 2.0 development version to main trunk.
[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
20 function display_allocatable_transactions()
21 {
22         global $table_style, $path_to_root;
23         start_form();
24
25         /* show all outstanding receipts and credits to be allocated */
26         /*Clear any previous allocation records */
27         if (isset($_SESSION['alloc']))
28         {
29                 unset($_SESSION['alloc']->allocs);
30                 unset($_SESSION['alloc']);
31         }
32     if (!isset($_POST['supplier_id']))
33         $_POST['supplier_id'] = get_global_supplier();
34
35     echo "<center>" . _("Select a Supplier: ") . "&nbsp;&nbsp;";
36         supplier_list('supplier_id', $_POST['supplier_id'], true, true);
37     echo "<br>";
38     check(_("Show Settled Items:"), 'ShowSettled', null, true);
39         echo "</center><br><br>";
40
41         set_global_supplier($_POST['supplier_id']);
42
43         if (isset($_POST['supplier_id']) && ($_POST['supplier_id'] == reserved_words::get_all())) 
44         {
45                 unset($_POST['supplier_id']);
46         }
47
48         $settled = false;
49         if (check_value('ShowSettled'))
50                 $settled = true;
51
52         $supplier_id = null;
53         if (isset($_POST['supplier_id']))
54                 $supplier_id = $_POST['supplier_id'];
55
56         $trans_items = get_allocatable_from_supp_transactions($supplier_id, $settled);
57         div_start('alloc_tbl');
58         start_table($table_style);
59         if (!isset($_POST['supplier_id']))
60                 $th = array(_("Transaction Type"), _("#"), _("Reference"), _("Date"), _("Supplier"), 
61                         _("Currency"), _("Total"), _("Left To Allocate"));
62         else
63                 $th = array(_("Transaction Type"), _("#"), _("Reference"), _("Date"), 
64                         _("Total"), _("Left To Allocate"));
65         table_header($th);      
66
67         $k = 0; //row colour counter
68         $has_settled_items = false;
69
70         while ($myrow = db_fetch($trans_items))
71         {
72         if ($myrow["settled"] == 1) 
73         {
74                 start_row("class='settledbg'");
75                 $has_settled_items = true;
76         } 
77         else 
78         {
79                 alt_table_row_color($k);
80         }
81
82         label_cell(systypes::name($myrow["type"]));
83                 label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"]));
84                 label_cell($myrow["reference"]);
85         label_cell(sql2date($myrow["tran_date"]));
86
87                 if (!isset($_POST['supplier_id']))
88                 {
89                 label_cell($myrow["supp_name"]);
90                 label_cell($myrow["curr_code"]);
91                 }
92                 amount_cell(-$myrow["Total"]);
93         amount_cell(-$myrow["Total"]-$myrow["alloc"]);
94         label_cell("<a href='$path_to_root/purchasing/allocations/supplier_allocate.php?trans_no=" . $myrow["trans_no"] . "&trans_type=" . $myrow["type"]  . "'>" . _("Allocate") . "</a>");
95         end_row();
96         }
97
98         end_table();
99
100         if ($has_settled_items)
101                 display_note(_("Marked items are settled."), 0, 1, "class='settledfg'");
102
103         if (db_num_rows($trans_items) == 0)
104                 display_note(_("There are no allocations to be done."), 1, 2);
105         div_end();
106         end_form();
107 }
108
109 //--------------------------------------------------------------------------------
110
111 if (get_post('_ShowSettled_update')) {
112         $Ajax->activate('alloc_tbl');
113 }
114 display_allocatable_transactions();
115
116 //--------------------------------------------------------------------------------
117
118 end_page();
119
120 ?>