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