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);
12 $js .= get_js_date_picker();
13 page(_("Supplier Allocation Inquiry"), false, false, "", $js);
15 if (isset($_GET['supplier_id']))
17 $_POST['supplier_id'] = $_GET['supplier_id'];
19 if (isset($_GET['FromDate']))
21 $_POST['TransAfterDate'] = $_GET['FromDate'];
23 if (isset($_GET['ToDate']))
25 $_POST['TransToDate'] = $_GET['ToDate'];
28 //------------------------------------------------------------------------------------------------
30 start_form(false, true);
32 if (!isset($_POST['supplier_id']))
33 $_POST['supplier_id'] = get_global_supplier();
35 start_table("class='tablestyle_noborder'");
38 supplier_list_cells(_("Select a supplier: "), 'supplier_id', $_POST['supplier_id'], true);
40 date_cells(_("From:"), 'TransAfterDate', null, -30);
41 date_cells(_("To:"), 'TransToDate', null, 1);
43 supp_allocations_list_cells("filterType", null);
45 check_cells(_("show settled:"), 'showSettled', null);
47 submit_cells('Refresh Inquiry', _("Search"));
49 set_global_supplier($_POST['supplier_id']);
56 //------------------------------------------------------------------------------------------------
58 function get_transactions()
62 $date_after = date2sql($_POST['TransAfterDate']);
63 $date_to = date2sql($_POST['TransToDate']);
65 // Sherifoz 22.06.03 Also get the description
66 $sql = "SELECT ".TB_PREF."supp_trans.type, ".TB_PREF."supp_trans.trans_no,
67 ".TB_PREF."supp_trans.tran_date, ".TB_PREF."supp_trans.reference, ".TB_PREF."supp_trans.supp_reference,
68 (".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,
69 ((".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 21) AND ".TB_PREF."supp_trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
70 ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supp_name, ".TB_PREF."supp_trans.due_date
71 FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
72 WHERE ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
73 AND ".TB_PREF."supp_trans.tran_date >= '$date_after'
74 AND ".TB_PREF."supp_trans.tran_date <= '$date_to'";
75 if ($_POST['supplier_id'] != reserved_words::get_all())
76 $sql .= " AND ".TB_PREF."supp_trans.supplier_id = '" . $_POST['supplier_id'] . "'";
77 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
79 if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2'))
81 $sql .= " AND ".TB_PREF."supp_trans.type = 20 ";
83 elseif ($_POST['filterType'] == '3')
85 $sql .= " AND ".TB_PREF."supp_trans.type = 22 ";
87 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
89 $sql .= " AND ".TB_PREF."supp_trans.type = 21 ";
92 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
94 $today = date2sql(Today());
95 $sql .= " AND ".TB_PREF."supp_trans.due_date < '$today' ";
99 if (!check_value('showSettled'))
101 $sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) ";
104 $sql .= " ORDER BY ".TB_PREF."supp_trans.tran_date";
106 return db_query($sql,"No supplier transactions were returned");
109 //------------------------------------------------------------------------------------------------
111 $result = get_transactions();
113 if (db_num_rows($result) == 0)
115 display_note(_("There are no transactions to display for the given dates."), 1, 1);
120 //------------------------------------------------------------------------------------------------
122 /*show a table of the transactions returned by the sql */
124 start_table("$table_style width=80%");
125 if ($_POST['supplier_id'] == reserved_words::get_all())
126 $th = array(_("Type"), _("Number"), _("Reference"), _("Supplier"),
127 _("Supp Reference"), _("Date"), _("Due Date"), _("Currency"),
128 _("Debit"), _("Credit"), _("Allocated"), _("Balance"));
130 $th = array(_("Type"), _("Number"), _("Reference"), _("Supp Reference"), _("Date"), _("Due Date"),
131 _("Debit"), _("Credit"), _("Allocated"), _("Balance"));
135 $k = 0; //row colour counter
137 while ($myrow = db_fetch($result))
140 if ($myrow['OverDue'] == 1)
142 start_row("class='overduebg'");
147 alt_table_row_color($k);
150 $date = sql2date($myrow["tran_date"]);
152 $duedate = ((($myrow["type"] == 20) || ($myrow["type"]== 21))?sql2date($myrow["due_date"]):"");
155 label_cell(systypes::name($myrow["type"]));
156 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
157 label_cell($myrow["reference"]);
158 if ($_POST['supplier_id'] == reserved_words::get_all())
159 label_cell($myrow["supp_name"]);
160 label_cell($myrow["supp_reference"]);
162 label_cell($duedate);
163 if ($_POST['supplier_id'] == reserved_words::get_all())
164 label_cell($myrow["curr_code"]);
165 if ($myrow["TotalAmount"] >= 0)
167 amount_cell(abs($myrow["TotalAmount"]));
168 if ($myrow["TotalAmount"] < 0)
170 amount_cell($myrow["Allocated"]);
171 if ($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22)
172 $balance = -$myrow["TotalAmount"] - $myrow["Allocated"];
174 $balance = $myrow["TotalAmount"] - $myrow["Allocated"];
175 amount_cell($balance);
177 //if (($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22) &&
178 // $myrow["Void"] == 0)
179 if (($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22) &&
182 label_cell("<a href='$path_to_root/purchasing/allocations/supplier_allocate.php?trans_no=" .
183 $myrow["trans_no"]. "&trans_type=" . $myrow["type"] . "'>" . _("Allocations") . "</a>");
194 //end of page full new headings if
200 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");