Merged changes from stable branch up to 2.3.12
[fa-stable.git] / sales / includes / ui / sales_order_ui.inc
index 2170595a986968b819ff621cb729f4906cc8c4d4..af675e7769c6a53b0574021b4b732e03f4b553a9 100644 (file)
@@ -72,6 +72,8 @@ function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount, $des
 
 function get_customer_details_to_order(&$order, $customer_id, $branch_id)
 {
+       global $SysPrefs;
+       
        $ret_error = "";
 
        $myrow = get_customer_to_order($customer_id);
@@ -116,10 +118,13 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id)
 
        $order->set_delivery($myrow["default_ship_via"], $myrow["br_name"],
                $address);
-       if ($order->trans_type == ST_SALESINVOICE || $order->trans_type == ST_SALESORDER) {
+       if ($order->trans_type == ST_SALESINVOICE) {
                $order->due_date = get_invoice_duedate($order->payment, $order->document_date);
        }
-       if ($order->payment_terms['cash_sale']) {
+       elseif ($order->trans_type == ST_SALESORDER)
+               $order->due_date = add_days($order->document_date, $SysPrefs->default_delivery_required_by());
+
+       if($order->payment_terms['cash_sale']) {
                $order->set_location($order->pos["pos_location"], $order->pos["location_name"]);
        } else
                $order->set_location($myrow["default_location"], $myrow["location_name"]);