5 include($path_to_root . "/includes/session.inc");
7 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
9 if ($use_popup_windows)
10 $js .= get_js_open_window(900, 500);
11 page(_("Supplier Allocation Inquiry"), false, false, "", $js);
13 if (isset($_GET['supplier_id']))
15 $_POST['supplier_id'] = $_GET['supplier_id'];
17 if (isset($_GET['FromDate']))
19 $_POST['TransAfterDate'] = $_GET['FromDate'];
21 if (isset($_GET['ToDate']))
23 $_POST['TransToDate'] = $_GET['ToDate'];
26 //------------------------------------------------------------------------------------------------
28 start_form(false, true);
30 if (!isset($_POST['supplier_id']))
31 $_POST['supplier_id'] = get_global_supplier();
33 start_table("class='tablestyle_noborder'");
36 supplier_list_cells(_("Select a supplier: "), 'supplier_id', $_POST['supplier_id'], true);
38 date_cells(_("From:"), 'TransAfterDate', null, -30);
39 date_cells(_("To:"), 'TransToDate', null, 1);
41 supp_allocations_list_cells("filterType", null);
43 check_cells(_("show settled:"), 'showSettled', null);
45 submit_cells('Refresh Inquiry', _("Search"));
47 set_global_supplier($_POST['supplier_id']);
54 //------------------------------------------------------------------------------------------------
56 function get_transactions()
60 $date_after = date2sql($_POST['TransAfterDate']);
61 $date_to = date2sql($_POST['TransToDate']);
63 // Sherifoz 22.06.03 Also get the description
64 $sql = "SELECT ".TB_PREF."supp_trans.type, ".TB_PREF."supp_trans.trans_no,
65 ".TB_PREF."supp_trans.tran_date, ".TB_PREF."supp_trans.reference, ".TB_PREF."supp_trans.supp_reference,
66 (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount) AS TotalAmount, ".TB_PREF."supp_trans.alloc AS Allocated,
67 ((".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 21) AND ".TB_PREF."supp_trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
68 ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supp_name, ".TB_PREF."supp_trans.due_date
69 FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
70 WHERE ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
71 AND ".TB_PREF."supp_trans.tran_date >= '$date_after'
72 AND ".TB_PREF."supp_trans.tran_date <= '$date_to'";
73 if ($_POST['supplier_id'] != reserved_words::get_all())
74 $sql .= " AND ".TB_PREF."supp_trans.supplier_id = '" . $_POST['supplier_id'] . "'";
75 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
77 if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2'))
79 $sql .= " AND ".TB_PREF."supp_trans.type = 20 ";
81 elseif ($_POST['filterType'] == '3')
83 $sql .= " AND ".TB_PREF."supp_trans.type = 22 ";
85 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
87 $sql .= " AND ".TB_PREF."supp_trans.type = 21 ";
90 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
92 $today = date2sql(Today());
93 $sql .= " AND ".TB_PREF."supp_trans.due_date < '$today' ";
97 if (!check_value('showSettled'))
99 $sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) ";
102 $sql .= " ORDER BY ".TB_PREF."supp_trans.tran_date";
104 return db_query($sql,"No supplier transactions were returned");
107 //------------------------------------------------------------------------------------------------
109 $result = get_transactions();
111 if (db_num_rows($result) == 0)
113 display_note(_("There are no transactions to display for the given dates."), 1, 1);
118 //------------------------------------------------------------------------------------------------
120 /*show a table of the transactions returned by the sql */
122 start_table("$table_style width=80%");
123 if ($_POST['supplier_id'] == reserved_words::get_all())
124 $th = array(_("Type"), _("Number"), _("Reference"), _("Supplier"),
125 _("Supp Reference"), _("Date"), _("Due Date"), _("Currency"),
126 _("Debit"), _("Credit"), _("Allocated"), _("Balance"));
128 $th = array(_("Type"), _("Number"), _("Reference"), _("Supp Reference"), _("Date"), _("Due Date"),
129 _("Debit"), _("Credit"), _("Allocated"), _("Balance"));
133 $k = 0; //row colour counter
135 while ($myrow = db_fetch($result))
138 if ($myrow['OverDue'] == 1)
140 start_row("class='overduebg'");
145 alt_table_row_color($k);
148 $date = sql2date($myrow["tran_date"]);
150 $duedate = ((($myrow["type"] == 20) || ($myrow["type"]== 21))?sql2date($myrow["due_date"]):"");
153 label_cell(systypes::name($myrow["type"]));
154 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
155 label_cell($myrow["reference"]);
156 if ($_POST['supplier_id'] == reserved_words::get_all())
157 label_cell($myrow["supp_name"]);
158 label_cell($myrow["supp_reference"]);
160 label_cell($duedate);
161 if ($_POST['supplier_id'] == reserved_words::get_all())
162 label_cell($myrow["curr_code"]);
163 if ($myrow["TotalAmount"] >= 0)
165 amount_cell(abs($myrow["TotalAmount"]));
166 if ($myrow["TotalAmount"] < 0)
168 amount_cell($myrow["Allocated"]);
169 if ($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22)
170 $balance = -$myrow["TotalAmount"] - $myrow["Allocated"];
172 $balance = $myrow["TotalAmount"] - $myrow["Allocated"];
173 amount_cell($balance);
175 //if (($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22) &&
176 // $myrow["Void"] == 0)
177 if (($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22) &&
180 label_cell("<a href='$path_to_root/purchasing/allocations/supplier_allocate.php?trans_no=" .
181 $myrow["trans_no"]. "&trans_type=" . $myrow["type"] . "'>" . _("Allocations") . "</a>");
192 //end of page full new headings if
198 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");