New files from unstable branch
[fa-stable.git] / sales / sales_order_entry.php
index 625ce897872f9ef170535174ae3a152758106d98..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();
@@ -235,9 +237,12 @@ function copy_to_cart()
        $cart->Comments =  $_POST['Comments'];
 
        $cart->document_date = $_POST['OrderDate'];
-       if ($cart->trans_type == ST_SALESINVOICE)
-               $cart->cash = $_POST['cash']; 
-       if ($cart->cash) {
+//     if ($cart->trans_type == ST_SALESINVOICE) {
+       if (isset($_POST['payment']) && ($cart->payment != $_POST['payment'])) {
+               $cart->payment = $_POST['payment'];
+               $cart->payment_terms = get_payment_terms($_POST['payment']);
+       }
+       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');
@@ -291,8 +296,7 @@ function copy_from_cart()
        $_POST['branch_id'] = $cart->Branch;
        $_POST['sales_type'] = $cart->sales_type;
        // POS 
-       if ($cart->trans_type == ST_SALESINVOICE)
-               $_POST['cash'] = $cart->cash;
+       $_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;
@@ -342,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');
@@ -445,8 +449,13 @@ if (isset($_POST['update'])) {
 function check_item_data()
 {
        global $SysPrefs;
-
-       if (!check_num('qty', 0) || !check_num('Disc', 0, 100)) {
+       
+       if(!get_post('stock_id_text', true)) {
+               display_error( _("Item description cannot be empty."));
+               set_focus('stock_id_edit');
+               return false;
+       }
+       elseif (!check_num('qty', 0) || !check_num('Disc', 0, 100)) {
                display_error( _("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100."));
                set_focus('qty');
                return false;
@@ -487,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();
 }
 
@@ -510,9 +520,11 @@ function handle_new_item()
        if (!check_item_data()) {
                        return;
        }
-       add_to_order($_SESSION['Items'], $_POST['stock_id'], input_num('qty'),
-               input_num('price'), input_num('Disc') / 100);
-       $_POST['_stock_id_edit'] = $_POST['stock_id']   = "";
+       add_to_order($_SESSION['Items'], get_post('stock_id'), input_num('qty'),
+               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();
 }
 
@@ -564,8 +576,10 @@ 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();
-       $doc_type = $type;
 
        if (isset($_GET['NewQuoteToSalesOrder']))
        {
@@ -579,21 +593,14 @@ function create_cart($type, $trans_no)
                $_SESSION['Items'] = $doc;
        }       
        elseif($type != ST_SALESORDER && $type != ST_SALESQUOTE && $trans_no != 0) { // this is template
-               $doc_type = ST_SALESORDER;
 
                $doc = new Cart(ST_SALESORDER, array($trans_no));
                $doc->trans_type = $type;
                $doc->trans_no = 0;
                $doc->document_date = new_doc_date();
                if ($type == ST_SALESINVOICE) {
-                       $doc->due_date = get_invoice_duedate($doc->customer_id, $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->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
+                       $doc->pos = get_sales_point(user_pos());
                } else
                        $doc->due_date = $doc->document_date;
                $doc->reference = $Refs->get_next($doc->trans_type);
@@ -603,7 +610,7 @@ function create_cart($type, $trans_no)
                }
                $_SESSION['Items'] = $doc;
        } else
-               $_SESSION['Items'] = new Cart($type,array($trans_no));
+               $_SESSION['Items'] = new Cart($type, array($trans_no));
        copy_from_cart();
 }
 
@@ -665,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>";
@@ -691,5 +698,4 @@ if ($customer_error == "") {
 }
 end_form();
 end_page();
-
 ?>
\ No newline at end of file