include($path_to_root . "/includes/session.inc");
include($path_to_root . "/sales/includes/sales_ui.inc");
+include_once($path_to_root . "/reporting/includes/reporting.inc");
$js = "";
if ($use_popup_windows)
$js .= get_js_open_window(900, 600);
+if ($use_date_picker)
+ $js .= get_js_date_picker();
-if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
+if (isset($_GET['OutstandingOnly']) && ($_GET['OutstandingOnly'] == true))
{
- $_POST['OutstandingOnly'] = true;
- page(_("Search Outstanding Sales Orders"), false, false, "", $js);
-}
-else
+ $_POST['order_view_mode'] = 'OutstandingOnly';
+ $_SESSION['page_title'] = _("Search Outstanding Sales Orders");
+}
+elseif (isset($_GET['InvoiceTemplates']) && ($_GET['InvoiceTemplates'] == true))
+{
+ $_POST['order_view_mode'] = 'InvoiceTemplates';
+ $_SESSION['page_title'] = _("Search Template for Invoicing");
+}
+elseif (isset($_GET['DeliveryTemplates']) && ($_GET['DeliveryTemplates'] == true))
{
- $_POST['OutstandingOnly'] = false;
- page(_("Search All Sales Orders"), false, false, "", $js);
+ $_POST['order_view_mode'] = 'DeliveryTemplates';
+ $_SESSION['page_title'] = _("Select Template for Delivery");
}
+elseif (!isset($_POST['order_view_mode']))
+{
+ $_POST['order_view_mode'] = false;
+ $_SESSION['page_title'] = _("Search All Sales Orders");
+}
+
+page($_SESSION['page_title'], false, false, "", $js);
if (isset($_GET['selected_customer']))
{
$selected_customer = $_GET['selected_customer'];
-}
+}
elseif (isset($_POST['selected_customer']))
{
$selected_customer = $_POST['selected_customer'];
}
else
$selected_customer = -1;
-
+
//-----------------------------------------------------------------------------------
+/*
+$action = $_SERVER['PHP_SELF'];
-start_form(false, false, $_SERVER['PHP_SELF'] ."?OutstandingOnly=" . $_POST['OutstandingOnly'] .SID);
+if ($_POST['order_view_mode']=='OutstandingOnly')
+{
+ $action .= "?OutstandingOnly=" . $_POST['order_view_mode']$_PO;
+}
+elseif ($_POST['order_view_mode']=='InvoiceTemplates')
+{
+ $action .= "?InvoiceTemplates=" . $_POST['InvoiceTemplates'];
+}
+elseif ($_POST['order_view_mode']=='DeliveryTemplates')
+{
+ $action .= "?DeliveryTemplates=" . $_POST['InvoiceTemplates'];
+}
+*/
+start_form(false, false, $_SERVER['PHP_SELF'] .SID);
start_table("class='tablestyle_noborder'");
start_row();
ref_cells(_("#:"), 'OrderNumber');
-date_cells(_("from:"), 'OrdersAfterDate', null, -30);
-date_cells(_("to:"), 'OrdersToDate', null, 1);
-
+if ($_POST['order_view_mode'] != 'DeliveryTemplates' && $_POST['order_view_mode'] != 'InvoiceTemplates')
+{
+ date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
+ date_cells(_("to:"), 'OrdersToDate', '', null, 1);
+}
locations_list_cells(_("Location:"), 'StockLocation', null, true);
stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
submit_cells('SearchOrders', _("Search"));
-hidden('OutstandingOnly', $_POST['OutstandingOnly']);
+hidden('order_view_mode', $_POST['order_view_mode']);
end_row();
($_POST['SelectStockFromList'] != reserved_words::get_all()))
{
$selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
+}
+else
{
unset($selected_stock_item);
}
+//---------------------------------------------------------------------------------------------
+if (isset($_POST['ChangeTmpl']) && $_POST['ChangeTmpl'] != 0)
+{
+ $sql = "UPDATE ".TB_PREF."sales_orders SET type = !type WHERE order_no=".$_POST['ChangeTmpl'];
+
+ db_query($sql, "Can't change sales order type");
+}
//---------------------------------------------------------------------------------------------
$sql = "SELECT ".TB_PREF."sales_orders.order_no, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.name, ".TB_PREF."cust_branch.br_name,
- ".TB_PREF."sales_orders.customer_ref, ".TB_PREF."sales_orders.ord_date, ".TB_PREF."sales_orders.deliver_to, ".TB_PREF."sales_orders.delivery_date, ";
-$sql .= " Sum(".TB_PREF."sales_order_details.qty_invoiced) AS TotInvoiced, ";
+ ".TB_PREF."sales_orders.ord_date, ".TB_PREF."sales_orders.deliver_to, ".TB_PREF."sales_orders.delivery_date,
+ ".TB_PREF."sales_orders.type, ";
+$sql .= " Sum(".TB_PREF."sales_order_details.qty_sent) AS TotDelivered, ";
$sql .= " Sum(".TB_PREF."sales_order_details.quantity) AS TotQuantity, ";
+$sql .= " Sum(".TB_PREF."sales_order_details.unit_price*".TB_PREF."sales_order_details.quantity*(1-".TB_PREF."sales_order_details.discount_percent)) AS OrderValue, ";
+
+//if ($_POST['order_view_mode']=='InvoiceTemplates' || $_POST['order_view_mode']=='DeliveryTemplates')
+ $sql .= TB_PREF."sales_orders.comments, ";
+//else
+ $sql .= TB_PREF."sales_orders.customer_ref";
-$sql .= " Sum(".TB_PREF."sales_order_details.unit_price*".TB_PREF."sales_order_details.quantity*(1-".TB_PREF."sales_order_details.discount_percent)) AS OrderValue
- FROM ".TB_PREF."sales_orders, ".TB_PREF."sales_order_details, ".TB_PREF."debtors_master, ".TB_PREF."cust_branch
+$sql .= " FROM ".TB_PREF."sales_orders, ".TB_PREF."sales_order_details, ".TB_PREF."debtors_master, ".TB_PREF."cust_branch
WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
AND ".TB_PREF."sales_orders.debtor_no = ".TB_PREF."debtors_master.debtor_no
AND ".TB_PREF."sales_orders.branch_code = ".TB_PREF."cust_branch.branch_code
AND ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."cust_branch.debtor_no ";
//figure out the sql required from the inputs available
-if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
+if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
{
$sql .= " AND ".TB_PREF."sales_orders.order_no LIKE '%". $_POST['OrderNumber'] ."' GROUP BY ".TB_PREF."sales_orders.order_no";
-}
-else
+}
+else
{
-
- $date_after = date2sql($_POST['OrdersAfterDate']);
- $date_before = date2sql($_POST['OrdersToDate']);
-
- $sql .= " AND ".TB_PREF."sales_orders.ord_date >= '$date_after'";
- $sql .= " AND ".TB_PREF."sales_orders.ord_date <= '$date_before'";
-
+ if ($_POST['order_view_mode']!='DeliveryTemplates' && $_POST['order_view_mode']!='InvoiceTemplates')
+ {
+ $date_after = date2sql($_POST['OrdersAfterDate']);
+ $date_before = date2sql($_POST['OrdersToDate']);
+
+ $sql .= " AND ".TB_PREF."sales_orders.ord_date >= '$date_after'";
+ $sql .= " AND ".TB_PREF."sales_orders.ord_date <= '$date_before'";
+ }
if ($selected_customer != -1)
$sql .= " AND ".TB_PREF."sales_orders.debtor_no='" . $selected_customer . "'";
if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all())
$sql .= " AND ".TB_PREF."sales_orders.from_stk_loc = '". $_POST['StockLocation'] . "' ";
- if ($_POST['OutstandingOnly'] == true)
- $sql .= " AND ".TB_PREF."sales_order_details.qty_invoiced < ".TB_PREF."sales_order_details.quantity";
+ if ($_POST['order_view_mode']=='OutstandingOnly')
+ $sql .= " AND ".TB_PREF."sales_order_details.qty_sent < ".TB_PREF."sales_order_details.quantity";
+ elseif ($_POST['order_view_mode']=='InvoiceTemplates' || $_POST['order_view_mode']=='DeliveryTemplates')
+ $sql .= " AND ".TB_PREF."sales_orders.type=1";
$sql .= " GROUP BY ".TB_PREF."sales_orders.order_no, ".TB_PREF."sales_orders.debtor_no, ".TB_PREF."sales_orders.branch_code,
".TB_PREF."sales_orders.customer_ref, ".TB_PREF."sales_orders.ord_date, ".TB_PREF."sales_orders.deliver_to";
//-----------------------------------------------------------------------------------
-if ($result)
+if ($result)
{
+ print_hidden_script(30);
/*show a table of the orders returned by the sql */
start_table("$table_style colspan=6 width=95%");
$th = array(_("Order #"), _("Customer"), _("Branch"), _("Cust Order #"), _("Order Date"),
- _("Required By"), _("Delivery To"), _("Order Total"), _("Currency"), "", "");
+ _("Required By"), _("Delivery To"), _("Order Total"), _("Currency"), "");
+
+ if($_POST['order_view_mode']=='InvoiceTemplates' || $_POST['order_view_mode']=='DeliveryTemplates')
+ {
+ $th[3] = _('Description');
+ } elseif ($_POST['order_view_mode'] != 'OutstandingOnly') {
+ $th[9] = _('Tmpl');
+ $th[] =''; $th[] ='';
+ }
+
table_header($th);
+ start_form();
$j = 1;
$k = 0; //row colour counter
$overdue_items = false;
- while ($myrow = db_fetch($result))
+ while ($myrow = db_fetch($result))
{
$view_page = get_customer_trans_view_str(systypes::sales_order(), $myrow["order_no"]);
$formated_del_date = sql2date($myrow["delivery_date"]);
$formated_order_date = sql2date($myrow["ord_date"]);
+// $not_closed = $myrow['type'] && ($myrow["TotDelivered"] < $myrow["TotQuantity"]);
// if overdue orders, then highlight as so
- if (date1_greater_date2(Today(), $formated_del_date))
+ if ($myrow['type'] == 0 && date1_greater_date2(Today(), $formated_del_date))
{
start_row("class='overduebg'");
$overdue_items = true;
- }
- else
+ }
+ else
{
alt_table_row_color($k);
}
label_cell($view_page);
label_cell($myrow["name"]);
label_cell($myrow["br_name"]);
- label_cell($myrow["customer_ref"]);
+ if($_POST['order_view_mode']=='InvoiceTemplates' || $_POST['order_view_mode']=='DeliveryTemplates')
+ label_cell($myrow["comments"]);
+ else
+ label_cell($myrow["customer_ref"]);
label_cell($formated_order_date);
label_cell($formated_del_date);
label_cell($myrow["deliver_to"]);
amount_cell($myrow["OrderValue"]);
label_cell($myrow["curr_code"]);
-
- if ($_POST['OutstandingOnly'] == true || $myrow["TotInvoiced"] < $myrow["TotQuantity"])
+ if ($_POST['order_view_mode']=='OutstandingOnly'/* || $not_closed*/)
{
- $modify_page = $path_to_root . "/sales/sales_order_entry.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
- $issue_invoice = $path_to_root . "/sales/customer_invoice.php?" . SID . "OrderNumber=" .$myrow["order_no"];
-
- label_cell("<a href='$modify_page'>" . _("Edit") . "</a>");
- label_cell("<a href='$issue_invoice'>" . _("Invoice") . "</a>");
+ $delivery_note = $path_to_root . "/sales/customer_delivery.php?" . SID . "OrderNumber=" .$myrow["order_no"];
+ label_cell("<a href='$delivery_note'>" . _("Dispatch") . "</a>");
+ }
+ elseif ($_POST['order_view_mode']=='InvoiceTemplates')
+ {
+ $select_order= $path_to_root . "/sales/sales_order_entry.php?" . SID . "NewInvoice=" .$myrow["order_no"];
+ label_cell("<a href='$select_order'>" . _("Invoice") . "</a>");
+ }
+ elseif ($_POST['order_view_mode']=='DeliveryTemplates')
+ {
+ $select_order= $path_to_root . "/sales/sales_order_entry.php?" . SID . "NewDelivery=" .$myrow["order_no"];
+ label_cell("<a href='$select_order'>" . _("Delivery") . "</a>");
}
else
{
- label_cell("");
- label_cell("");
+ echo "<td><input ".($myrow["type"]==1 ? 'checked' : '')." type='checkbox' name='chgtpl" .$myrow["order_no"]. "' value='1'
+ onclick='this.form.ChangeTmpl.value= this.name.substr(6);
+ this.form.submit();' ></td>";
+
+ $modify_page = $path_to_root . "/sales/sales_order_entry.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
+ label_cell("<a href='$modify_page'>" . _("Edit") . "</a>");
+ label_cell(print_document_link($myrow['order_no'], _("Print")));
}
end_row();;
//end of page full new headings if
}
//end of while loop
-
+ hidden('ChangeTmpl', 0);
+ end_form();
end_table();
if ($overdue_items)
echo "<br>";
end_page();
-?>
-
+?>
\ No newline at end of file