Merged bugfixes upto [0000072] (version 2.0.3).
[fa-stable.git] / sales / allocations / customer_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 . "/sales/includes/sales_ui.inc");
8 include_once($path_to_root . "/sales/includes/sales_db.inc");
9 $js = "";
10 if ($use_popup_windows)
11         $js .= get_js_open_window(900, 500);
12 page(_("Customer Allocations"), false, false, "", $js);
13
14 //--------------------------------------------------------------------------------
15 if ($ret = context_restore()) {
16         if(isset($ret['customer_id']))
17                 $_POST['customer_id'] = $ret['customer_id'];
18 }
19 if (isset($_POST['_customer_id_editor'])) {
20         context_call($path_to_root.'/sales/manage/customers.php?debtor_no='.$_POST['customer_id'] );
21 }
22
23 function display_allocatable_transactions()
24 {
25         global $table_style, $path_to_root;
26         start_form();
27
28         /* show all outstanding receipts and credits to be allocated */
29         /*Clear any previous allocation records */
30         if (isset($_SESSION['alloc']))
31         {
32                 unset($_SESSION['alloc']->allocs);
33                 unset($_SESSION['alloc']);
34         }
35     if (!isset($_POST['customer_id']))
36         $_POST['customer_id'] = get_global_customer();
37
38     echo "<center>" . _("Select a customer: ") . "&nbsp;&nbsp;";
39         customer_list('customer_id', $_POST['customer_id'], true, true);
40     echo "<br>";
41     check(_("Show Settled Items:"), 'ShowSettled', null, true);
42         echo "</center><br><br>";
43
44         set_global_customer($_POST['customer_id']);
45
46         if (isset($_POST['customer_id']) && ($_POST['customer_id'] == reserved_words::get_all()))
47         {
48                 unset($_POST['customer_id']);
49         }
50
51         /*if (isset($_POST['customer_id'])) {
52                 $custCurr = get_customer_currency($_POST['customer_id']);
53                 if (!is_company_currency($custCurr))
54                         echo _("Customer Currency:") . $custCurr;
55         }*/
56
57         $settled = false;
58         if (check_value('ShowSettled'))
59                 $settled = true;
60
61         $customer_id = null;
62         if (isset($_POST['customer_id']))
63                 $customer_id = $_POST['customer_id'];
64
65         $trans_items = get_allocatable_from_cust_transactions($customer_id, $settled);
66  div_start('alloc_tbl');
67         start_table($table_style);
68         if (!isset($_POST['customer_id']))
69                 $th = array(_("Transaction Type"), _("#"), _("Reference"), _("Date"), _("Customer"),
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         $k = 0; //row colour counter
76         $has_settled_items = false;
77
78         while ($myrow = db_fetch($trans_items))
79         {
80         if ($myrow["settled"] == 1)
81         {
82                 start_row("class='settledbg'");
83                 $has_settled_items = true;
84         }
85         else
86         {
87                 alt_table_row_color($k);
88         }
89
90         label_cell(systypes::name($myrow["type"]));
91         label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"]));
92                 label_cell($myrow["reference"]);
93         label_cell(sql2date($myrow["tran_date"]));
94
95                 if (!isset($_POST['customer_id']))
96                 {
97                 label_cell($myrow["DebtorName"]);
98                 label_cell($myrow["curr_code"]);
99                 }
100                 amount_cell($myrow["Total"]);
101         amount_cell($myrow["Total"] - $myrow["alloc"]);
102                 label_cell("<a href='$path_to_root/sales/allocations/customer_allocate.php?trans_no="
103                                         .$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 if (get_post('_ShowSettled_update')) {
120         $Ajax->activate('alloc_tbl');
121 }
122 display_allocatable_transactions();
123
124 //--------------------------------------------------------------------------------
125
126 end_page();
127
128 ?>