Merged last changes from stable.
[fa-stable.git] / sales / inquiry / sales_orders_view.php
index 522cfd80c993fedcccbcf3a24db17bc600d4c8c8..b96b99dd1e7f3692ec00babeb090e65ab3bd7cc8 100644 (file)
@@ -20,9 +20,13 @@ $page_security = 'SA_SALESTRANSVIEW';
 
 set_page_security( @$_POST['order_view_mode'],
        array(  'OutstandingOnly' => 'SA_SALESDELIVERY',
-                       'InvoiceTemplates' => 'SA_SALESINVOICE'),
+                       'InvoiceTemplates' => 'SA_SALESINVOICE',
+                       'DeliveryTemplates' => 'SA_SALESDELIVERY',
+                       'PrepaidOrders' => 'SA_SALESINVOICE'),
        array(  'OutstandingOnly' => 'SA_SALESDELIVERY',
-                       'InvoiceTemplates' => 'SA_SALESINVOICE')
+                       'InvoiceTemplates' => 'SA_SALESINVOICE',
+                       'DeliveryTemplates' => 'SA_SALESDELIVERY',
+                       'PrepaidOrders' => 'SA_SALESINVOICE')
 );
 
 if (get_post('type'))
@@ -49,6 +53,11 @@ if ($trans_type == ST_SALESORDER)
                $_POST['order_view_mode'] = 'DeliveryTemplates';
                $_SESSION['page_title'] = _($help_context = "Select Template for Delivery");
        }
+       elseif (isset($_GET['PrepaidOrders']) && ($_GET['PrepaidOrders'] == true))
+       {
+               $_POST['order_view_mode'] = 'PrepaidOrders';
+               $_SESSION['page_title'] = _($help_context = "Invoicing Prepayment Orders");
+       }
        elseif (!isset($_POST['order_view_mode']))
        {
                $_POST['order_view_mode'] = false;
@@ -61,15 +70,12 @@ else
        $_SESSION['page_title'] = _($help_context = "Search All Sales Quotations");
 }
 
-if (!@$_GET['popup'])
-{
-       $js = "";
-       if ($use_popup_windows)
-               $js .= get_js_open_window(900, 600);
-       if ($use_date_picker)
-               $js .= get_js_date_picker();
-       page($_SESSION['page_title'], false, false, "", $js);
-}
+$js = "";
+if ($use_popup_windows)
+       $js .= get_js_open_window(900, 600);
+if ($use_date_picker)
+       $js .= get_js_date_picker();
+page($_SESSION['page_title'], false, false, "", $js);
 
 if (isset($_GET['selected_customer']))
 {
@@ -121,7 +127,9 @@ function prt_link($row)
 
 function edit_link($row) 
 {
-       if (@$_GET['popup'])
+       global $page_nested;
+
+       if ($page_nested)
                return '';
        global $trans_type;
        $modify = ($trans_type == ST_SALESORDER ? "ModifyOrderNumber" : "ModifyQuotationNumber");
@@ -132,10 +140,14 @@ function edit_link($row)
 function dispatch_link($row)
 {
        global $trans_type;
+
+       if ($row['ord_payments'] + $row['inv_payments'] < $row['prep_amount'])
+               return '';
+
        if ($trans_type == ST_SALESORDER)
                return pager_link( _("Dispatch"),
                        "/sales/customer_delivery.php?OrderNumber=" .$row['order_no'], ICON_DOC);
-       else            
+       else
                return pager_link( _("Sales Order"),
                        "/sales/sales_order_entry.php?OrderNumber=" .$row['order_no'], ICON_DOC);
 }
@@ -164,10 +176,11 @@ function order_link($row)
 
 function tmpl_checkbox($row)
 {
-       global $trans_type;
+       global $trans_type, $page_nested;
        if ($trans_type == ST_SALESQUOTE)
                return '';
-       if (@$_GET['popup'])
+
+       if ($page_nested)
                return '';
        $name = "chgtpl" .$row['order_no'];
        $value = $row['type'] ? 1:0;
@@ -178,6 +191,16 @@ function tmpl_checkbox($row)
        _('Set this order as a template for direct deliveries/invoices'))
        . hidden('last['.$row['order_no'].']', $value, false);
 }
+
+function invoice_prep_link($row)
+{
+       // invoicing should be available only for partially allocated orders
+       return 
+               $row['inv_payments'] < $row['total'] ?
+               pager_link($row['ord_payments']  ? _("Prepayment Invoice") : _("Final Invoice"),
+               "/sales/customer_invoice.php?InvoicePrepayments=" .$row['order_no'], ICON_DOC) : '';
+}
+
 //---------------------------------------------------------------------------------------------
 // Update db record if respective checkbox value has changed.
 //
@@ -217,8 +240,7 @@ if (get_post('_OrderNumber_changed') || get_post('_OrderReference_changed')) //
        $Ajax->activate('orders_tbl');
 }
 
-if (!@$_GET['popup'])
-       start_form();
+start_form();
 
 start_table(TABLESTYLE_NOBORDER);
 start_row();
@@ -226,7 +248,7 @@ ref_cells(_("#:"), 'OrderNumber', '',null, '', true);
 ref_cells(_("Ref"), 'OrderReference', '',null, '', true);
 if ($show_dates)
 {
-       date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
+       date_cells(_("from:"), 'OrdersAfterDate', '', null, -$_SESSION["wa_current_user"]->prefs->transaction_days());
        date_cells(_("to:"), 'OrdersToDate', '', null, 1);
 }
 locations_list_cells(_("Location:"), 'StockLocation', null, true, true);
@@ -239,6 +261,7 @@ if($show_dates) {
        start_row();
 }
 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true, true);
+
 if (!@$_GET['popup'])
        customer_list_cells(_("Select a customer: "), 'customer_id', null, true, true);
 if ($trans_type == ST_SALESQUOTE)
@@ -286,7 +309,7 @@ else
                _("Currency") => array('align'=>'center')
        );
 if ($_POST['order_view_mode'] == 'OutstandingOnly') {
-       //array_substitute($cols, 4, 1, _("Cust Order Ref"));
+       //array_substitute($cols, 3, 1, _("Cust Order Ref"));
        array_append($cols, array(
                array('insert'=>true, 'fun'=>'dispatch_link'),
                array('insert'=>true, 'fun'=>'edit_link')));
@@ -300,6 +323,10 @@ if ($_POST['order_view_mode'] == 'OutstandingOnly') {
        array_append($cols, array(
                        array('insert'=>true, 'fun'=>'delivery_link'))
        );
+} else if ($_POST['order_view_mode'] == 'PrepaidOrders') {
+       array_append($cols, array(
+                       array('insert'=>true, 'fun'=>'invoice_prep_link'))
+       );
 
 } elseif ($trans_type == ST_SALESQUOTE) {
         array_append($cols,array(
@@ -322,9 +349,5 @@ $table->width = "80%";
 display_db_pager($table);
 submit_center('Update', _("Update"), true, '', null);
 
-if (!@$_GET['popup'])
-{
-       end_form();
-       end_page();
-}
-?>
+end_form();
+end_page();