5 include($path_to_root . "/includes/db_pager.inc");
6 include($path_to_root . "/includes/session.inc");
8 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
10 if ($use_popup_windows)
11 $js .= get_js_open_window(900, 500);
13 $js .= get_js_date_picker();
14 page(_("Supplier Allocation Inquiry"), false, false, "", $js);
16 if (isset($_GET['supplier_id']))
18 $_POST['supplier_id'] = $_GET['supplier_id'];
20 if (isset($_GET['FromDate']))
22 $_POST['TransAfterDate'] = $_GET['FromDate'];
24 if (isset($_GET['ToDate']))
26 $_POST['TransToDate'] = $_GET['ToDate'];
29 //------------------------------------------------------------------------------------------------
31 start_form(false, true);
33 if (!isset($_POST['supplier_id']))
34 $_POST['supplier_id'] = get_global_supplier();
36 start_table("class='tablestyle_noborder'");
39 supplier_list_cells(_("Select a supplier: "), 'supplier_id', $_POST['supplier_id'], true);
41 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
42 date_cells(_("To:"), 'TransToDate', '', null, 1);
44 supp_allocations_list_cell("filterType", null);
46 check_cells(_("show settled:"), 'showSettled', null);
48 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true);
50 set_global_supplier($_POST['supplier_id']);
55 //------------------------------------------------------------------------------------------------
56 function check_overdue($row)
58 return ($row['TotalAmount']>$row['Allocated']) &&
62 function systype_name($dummy, $type)
64 return systypes::name($type);
67 function view_link($trans)
69 return get_trans_view_str($trans["type"], $trans["trans_no"]);
72 function due_date($row)
74 return (($row["type"] == 20) || ($row["type"]== 21))
75 ? $row["due_date"] : "";
78 function fmt_balance($row)
80 $value = ($row["type"] == 1 || $row["type"] == 21 || $row["type"] == 22)
81 ? -$row["TotalAmount"] - $row["Allocated"]
82 : $row["TotalAmount"] - $row["Allocated"];
86 function alloc_link($row)
89 pager_link(_("Allocations"),
90 "/purchasing/allocations/supplier_allocate.php?trans_no=" .
91 $row["trans_no"]. "&trans_type=" . $row["type"] );
93 return (($row["type"] == 1 || $row["type"] == 21 || $row["type"] == 22)
94 && (-$row["TotalAmount"] - $row["Allocated"]) > 0)
98 function fmt_debit($row)
100 $value = -$row["TotalAmount"];
101 return $value>=0 ? price_format($value) : '';
105 function fmt_credit($row)
107 $value = $row["TotalAmount"];
108 return $value>0 ? price_format($value) : '';
110 //------------------------------------------------------------------------------------------------
112 $date_after = date2sql($_POST['TransAfterDate']);
113 $date_to = date2sql($_POST['TransToDate']);
115 // Sherifoz 22.06.03 Also get the description
121 trans.supp_reference,
125 (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount,
126 trans.alloc AS Allocated,
127 ((trans.type = 20 OR trans.type = 21) AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue
129 .TB_PREF."supp_trans as trans, "
130 .TB_PREF."suppliers as supplier
131 WHERE supplier.supplier_id = trans.supplier_id
132 AND trans.tran_date >= '$date_after'
133 AND trans.tran_date <= '$date_to'";
134 if ($_POST['supplier_id'] != reserved_words::get_all())
135 $sql .= " AND trans.supplier_id = '" . $_POST['supplier_id'] . "'";
136 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
138 if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2'))
140 $sql .= " AND trans.type = 20 ";
142 elseif ($_POST['filterType'] == '3')
144 $sql .= " AND trans.type = 22 ";
146 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
148 $sql .= " AND trans.type = 21 ";
151 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
153 $today = date2sql(Today());
154 $sql .= " AND trans.due_date < '$today' ";
158 if (!check_value('showSettled'))
160 $sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) ";
164 _("Type") => array('fun'=>'systype_name'),
165 _("Number") => array('fun'=>'view_link', 'ord'=>''),
167 _("Supplier") => array('ord'=>''),
169 _("Date") => array('type'=>'date', 'ord'=>'asc'),
170 _("Due Date") => array('fun'=>'due_date'),
171 _("Currency") => array('align'=>'center'),
172 _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
173 _("Credit") => array('align'=>'right', 'insert'=>true, 'fun'=>'fmt_credit'),
174 _("Allocated") => 'amount',
175 _("Balance") => array('type'=>'amount', 'insert'=>true, 'fun'=>'fmt_balance'),
176 array('insert'=>true, 'fun'=>'alloc_link')
179 if ($_POST['supplier_id'] != reserved_words::get_all()) {
180 $cols[_("Supplier")] = 'skip';
181 $cols[_("Currency")] = 'skip';
183 //------------------------------------------------------------------------------------------------
185 $table =& new_db_pager('doc_tbl', $sql, $cols);
186 $table->set_marker('check_overdue', _("Marked items are overdue."));
188 if(get_post('RefreshInquiry'))
190 $table->set_sql($sql);
191 $table->set_columns($cols);
192 $Ajax->activate('doc_tbl');
196 display_db_pager($table);