A couple of additional smaller fixes.
[fa-stable.git] / sales / sales_order_entry.php
index 9e5a04adadd6e100a5f5084fb9a6ffc2fc3008ec..4a47369598f7e7659418d1b91d96931416657f51 100644 (file)
@@ -109,6 +109,8 @@ if (isset($_GET['AddedID'])) {
        submenu_option(_("Make &Delivery Against This Order"),
                "/sales/customer_delivery.php?OrderNumber=$order_no");
 
+       submenu_option(_("Work &Order Entry"),  "/manufacturing/work_order_entry.php?");
+
        submenu_option(_("Enter a &New Order"), "/sales/sales_order_entry.php?NewOrder=0");
 
        display_footer_exit();
@@ -239,9 +241,8 @@ function copy_to_cart()
        if (isset($_POST['payment']) && ($cart->payment != $_POST['payment'])) {
                $cart->payment = $_POST['payment'];
                $cart->payment_terms = get_payment_terms($_POST['payment']);
-               $cart->cash = $cart->payment_terms['cash_sale'];
        }
-       if ($cart->cash) {
+       if ($cart->payment_terms['cash_sale']) {
                $cart->due_date = $cart->document_date;
                $cart->phone = $cart->cust_ref = $cart->delivery_address = '';
                $cart->freight_cost = input_num('freight_cost');
@@ -295,8 +296,7 @@ function copy_from_cart()
        $_POST['branch_id'] = $cart->Branch;
        $_POST['sales_type'] = $cart->sales_type;
        // POS 
-       if ($cart->pos != -1)
-               $_POST['payment'] = $cart->payment;
+       $_POST['payment'] = $cart->payment;
        if ($cart->trans_type!=ST_SALESORDER && $cart->trans_type!=ST_SALESQUOTE) { // 2008-11-12 Joe Hunt
                $_POST['dimension_id'] = $cart->dimension_id;
                $_POST['dimension2_id'] = $cart->dimension2_id;
@@ -317,6 +317,20 @@ function line_start_focus() {
 function can_process() {
        global $Refs;
 
+       if (!get_post('customer_id')) 
+       {
+               display_error(_("There is no customer selected."));
+               set_focus('customer_id');
+               return false;
+       } 
+       
+       if (!get_post('branch_id')) 
+       {
+               display_error(_("This customer has no branch defined."));
+               set_focus('branch_id');
+               return false;
+       } 
+       
        if (!is_date($_POST['OrderDate'])) {
                display_error(_("The entered date is invalid."));
                set_focus('OrderDate');
@@ -332,7 +346,7 @@ function can_process() {
                set_focus('AddItem');
                return false;
        }
-       if ($_SESSION['Items']->cash == 0) {
+       if ($_SESSION['Items']->payment_terms['cash_sale'] == 0) {
        if (strlen($_POST['deliver_to']) <= 1) {
                display_error(_("You must enter the person or company to whom delivery should be made to."));
                set_focus('deliver_to');
@@ -385,6 +399,12 @@ function can_process() {
                set_focus('ref');
                return false;
        }
+       if ($_SESSION['Items']->trans_no==0 && !is_new_reference($_POST['ref'], 
+               $_SESSION['Items']->trans_type)) {
+               display_error(_("The entered reference is already in use."));
+               set_focus('ref');
+               return false;
+       }
        return true;
 }
 
@@ -476,6 +496,7 @@ function handle_update_item()
                 input_num('qty'), input_num('price'),
                 input_num('Disc') / 100, $_POST['item_description'] );
        }
+       page_modified();
   line_start_focus();
 }
 
@@ -503,6 +524,7 @@ function handle_new_item()
                input_num('price'), input_num('Disc') / 100, get_post('stock_id_text'));
 
        unset($_POST['_stock_id_edit'], $_POST['stock_id']);
+       page_modified();
        line_start_focus();
 }
 
@@ -554,6 +576,9 @@ function create_cart($type, $trans_no)
 { 
        global $Refs;
 
+       if (!$_SESSION['SysPrefs']->db_ok) // create_cart is called before page() where the check is done
+               return;
+
        processing_start();
 
        if (isset($_GET['NewQuoteToSalesOrder']))
@@ -575,13 +600,7 @@ function create_cart($type, $trans_no)
                $doc->document_date = new_doc_date();
                if ($type == ST_SALESINVOICE) {
                        $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
-                       $doc->pos = user_pos();
-                       $pos = get_sales_point($doc->pos);
-//                     $doc->cash = $pos['cash_sale'];
-                       if (!$pos['cash_sale'] && !$pos['credit_sale'])
-                               $doc->pos = -1; // mark not editable payment type
-//                     else
-//                             $doc->cash = date_diff2($doc->due_date, Today(), 'd')<2;
+                       $doc->pos = get_sales_point(user_pos());
                } else
                        $doc->due_date = $doc->document_date;
                $doc->reference = $Refs->get_next($doc->trans_type);
@@ -653,7 +672,7 @@ $customer_error = display_order_header($_SESSION['Items'],
        ($_SESSION['Items']->any_already_delivered() == 0), $idate);
 
 if ($customer_error == "") {
-       start_table("$table_style width=80%", 10);
+       start_table(TABLESTYLE, "width=80%", 10);
        echo "<tr><td>";
        display_order_summary($orderitems, $_SESSION['Items'], true);
        echo "</td></tr>";