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_cell("filterType", null);
45 check_cells(_("show settled:"), 'showSettled', null);
47 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true);
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();
112 //------------------------------------------------------------------------------------------------
113 if(get_post('RefreshInquiry'))
115 $Ajax->activate('doc_tbl');
118 //------------------------------------------------------------------------------------------------
120 /*show a table of the transactions returned by the sql */
122 div_start('doc_tbl');
123 if (db_num_rows($result) == 0)
125 display_note(_("There are no transactions to display for the given dates."), 1, 1);
128 start_table("$table_style width=90%");
129 if ($_POST['supplier_id'] == reserved_words::get_all())
130 $th = array(_("Type"), _("Number"), _("Reference"), _("Supplier"),
131 _("Supp Reference"), _("Date"), _("Due Date"), _("Currency"),
132 _("Debit"), _("Credit"), _("Allocated"), _("Balance"), "");
134 $th = array(_("Type"), _("Number"), _("Reference"), _("Supp Reference"), _("Date"), _("Due Date"),
135 _("Debit"), _("Credit"), _("Allocated"), _("Balance"), "");
139 $k = 0; //row colour counter
141 while ($myrow = db_fetch($result))
144 if (($myrow['TotalAmount']>$myrow['Allocated']) && $myrow['OverDue'] == 1)
146 start_row("class='overduebg'");
151 alt_table_row_color($k);
154 $date = sql2date($myrow["tran_date"]);
156 $duedate = ((($myrow["type"] == 20) || ($myrow["type"]== 21))?sql2date($myrow["due_date"]):"");
159 label_cell(systypes::name($myrow["type"]));
160 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
161 label_cell($myrow["reference"]);
162 if ($_POST['supplier_id'] == reserved_words::get_all())
163 label_cell($myrow["supp_name"]);
164 label_cell($myrow["supp_reference"]);
166 label_cell($duedate);
167 if ($_POST['supplier_id'] == reserved_words::get_all())
168 label_cell($myrow["curr_code"]);
169 $myrow["TotalAmount"] = round2($myrow["TotalAmount"], user_price_dec());
170 $myrow["Allocated"] = round2($myrow["Allocated"], user_price_dec());
171 if ($myrow["TotalAmount"] >= 0)
173 amount_cell(abs($myrow["TotalAmount"]));
174 if ($myrow["TotalAmount"] < 0)
176 amount_cell($myrow["Allocated"]);
177 if ($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22)
178 $balance = -$myrow["TotalAmount"] - $myrow["Allocated"];
180 $balance = $myrow["TotalAmount"] - $myrow["Allocated"];
181 amount_cell($balance);
183 if (($myrow["type"] == 1 || $myrow["type"] == 21 || $myrow["type"] == 22) &&
186 label_cell("<a href='$path_to_root/purchasing/allocations/supplier_allocate.php?trans_no=" .
187 $myrow["trans_no"]. "&trans_type=" . $myrow["type"] . "'>" . _("Allocations") . "</a>");
200 //end of page full new headings if
206 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");