X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fui%2Fsales_order_ui.inc;h=faa2a3c8e2c2283b7be83a6ad7a0e7efba442fdf;hb=3b06c6c4718610a408cae2e9b76c3134ca30b84c;hp=57be11958de99cba29686777a7cf22882bc2576a;hpb=bd3023c1b5e64429043358a691b3aae20eb54c09;p=fa-stable.git diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 57be1195..faa2a3c8 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -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); @@ -90,6 +92,8 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) $order->set_sales_type($myrow['salestype'], $myrow['sales_type'], $myrow['tax_included'], $myrow['factor']); + $order->credit = $myrow['cur_credit']; + if ($order->trans_type != ST_SALESORDER && $order->trans_type != ST_SALESQUOTE) { $order->dimension_id = $myrow['dimension_id']; @@ -106,9 +110,8 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) // FIX - implement editable contact selector in sales order $contact = get_branch_contacts($branch_id, 'order', $customer_id); - $order->set_branch($branch_id, $myrow["tax_group_id"], - $myrow["tax_group_name"], @$contact[0]["phone"], @$contact[0]["email"]); + $myrow["tax_group_name"], @$contact["phone"], @$contact["email"]); $address = trim($myrow["br_post_address"]) != '' ? $myrow["br_post_address"] : (trim($myrow["br_address"]) != '' ? $myrow["br_address"]:$deliver); @@ -117,17 +120,17 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) $address); if ($order->trans_type == ST_SALESINVOICE) { $order->due_date = get_invoice_duedate($order->payment, $order->document_date); -// if ($order->pos != -1) -// $order->cash = date_diff2($order->due_date, Today(), 'd')<2; } - if($order->cash ) { - if($order->pos != -1) { - $pos = get_sales_point($order->pos); - $order->set_location($pos["pos_location"], $pos["location_name"]); - } + elseif ($order->trans_type == ST_SALESORDER) + $order->due_date = add_days($order->document_date, $SysPrefs->default_delivery_required_by()); + elseif ($order->trans_type == ST_SALESQUOTE) + $order->due_date = add_days($order->document_date, $SysPrefs->default_quote_valid_days()); + + 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"]); - + return $ret_error; } @@ -135,7 +138,6 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) function display_order_summary($title, &$order, $editable_items=false) { - global $path_to_root, $SysPrefs; display_heading($title); @@ -143,7 +145,7 @@ function display_order_summary($title, &$order, $editable_items=false) start_table(TABLESTYLE, "colspan=7 width=90%"); $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Delivered"), - _("Unit"), _("Price"), _("Discount %"), _("Total"), ""); + _("Unit"), $order->tax_included ? _("Price after Tax") : _("Price before Tax"), _("Discount %"), _("Total"), ""); if ($order->trans_no == 0) { unset( $th[3] ); @@ -158,8 +160,9 @@ function display_order_summary($title, &$order, $editable_items=false) $k = 0; //row colour counter $id = find_submit('Edit'); - $has_marked = false; - foreach ($order->line_items as $line_no=>$stock_item) + + $low_stock = $order->check_qoh($_POST['OrderDate'], $_POST['Location']); + foreach ($order->get_items() as $line_no=>$stock_item) { $line_total = round($stock_item->qty_dispatched * $stock_item->price * (1 - $stock_item->discount_percent), @@ -168,22 +171,10 @@ function display_order_summary($title, &$order, $editable_items=false) $qoh_msg = ''; if (!$editable_items || $id != $line_no) { - if (!$SysPrefs->allow_negative_stock() && is_inventory_item($stock_item->stock_id)) { - $qoh = get_qoh_on_date($stock_item->stock_id, - $_POST['Location'], $_POST['OrderDate']); - if ($stock_item->qty_dispatched > $qoh) - { - // oops, we don't have enough of one of the component items - start_row("class='stockmankobg'"); - $qoh_msg .= $stock_item->stock_id . " - " . $stock_item->item_description . ": " . - _("Quantity On Hand") . " = " - . number_format2($qoh, get_qty_dec($stock_item->stock_id)) . '
'; - $has_marked = true; - } else - alt_table_row_color($k); - } else { + if (in_array($stock_item->stock_id, $low_stock)) + start_row("class='stockmankobg'"); // notice low stock status + else alt_table_row_color($k); - } view_stock_status_cell($stock_item->stock_id); @@ -238,22 +229,19 @@ function display_order_summary($title, &$order, $editable_items=false) start_row(); label_cells(_("Amount Total"), $display_total, "colspan=$colspan align=right","align=right"); - submit_cells('update', _("Update"), "colspan=2", _("Refresh"), true); + submit_cells('update', _("Update"), "colspan=2 align='center'", _("Refresh"), true); end_row(); end_table(); - if ($has_marked) { + if ($low_stock) display_note(_("Marked items have insufficient quantities in stock as on day of delivery."), 0, 1, "class='stockmankofg'"); - if ($order->trans_type!=30 && !$SysPrefs->allow_negative_stock()) - display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") - . '
'. $qoh_msg); - } + div_end(); } // ------------------------------------------------------------------------------ -function display_order_header(&$order, $editable, $date_text, $display_tax_group=false) +function display_order_header(&$order, $editable, $date_text) { global $Ajax, $SysPrefs; @@ -314,7 +302,20 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group $_POST['deliver_to'] = $order->deliver_to; $_POST['delivery_address'] = $order->delivery_address; $_POST['phone'] = $order->phone; - if (get_post('payment') !== $order->payment) { + $_POST['delivery_date'] = $order->due_date; + + if (!in_array($order->trans_type, array(ST_SALESQUOTE, ST_SALESORDER)) + && ($order->pos['cash_sale'] != $order->pos['credit_sale']) + && (($order->payment_terms['cash_sale'] && !$order->pos['cash_sale']) || + (!$order->payment_terms['cash_sale'] && !$order->pos['credit_sale']))) { + // force payment terms refresh if terms are editable + // and pos have no permitions for terms selected in customer record. + // Terms are set to first terms in allowed category below. + display_warning( + sprintf(_("Customer's payment terms '%s' cannot be selected on this POS"), + $order->payment_terms['terms'])); + $order->payment = ''; + } elseif (get_post('payment') !== $order->payment) { $_POST['payment'] = $order->payment; $Ajax->activate('delivery'); $Ajax->activate('payment'); @@ -357,44 +358,50 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group $row = get_customer_to_order($_POST['customer_id']); if ($row['dissallow_invoices'] == 1) $customer_error = _("The selected customer account is currently on hold. Please contact the credit control personnel to discuss."); - } } ref_row(_("Reference").':', 'ref', _('Reference number unique for this document type'), null, ''); - if (!is_company_currency($order->customer_currency)) - { - table_section(2); + table_section(2); + if (!is_company_currency($order->customer_currency) && in_array($order->trans_type, array(ST_SALESINVOICE, ST_CUSTDELIVERY))) + { label_row(_("Customer Currency:"), $order->customer_currency); - exchange_rate_display($order->customer_currency, get_company_currency(), + exchange_rate_display(get_company_currency(), $order->customer_currency, ($editable ? $_POST['OrderDate'] : $order->document_date)); } - table_section(3); - if (($order->trans_type != ST_CUSTDELIVERY) && ($order->pos != -1)) { // editable payment type + customer_credit_row($_POST['customer_id'], $order->credit); + + label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); + + table_section(3); + if (($order->pos['cash_sale'] || $order->pos['credit_sale']) + && !$order->is_started()) { + // editable payment type if (get_post('payment') !== $order->payment) { $order->payment = get_post('payment'); $order->payment_terms = get_payment_terms($order->payment); - $order->cash = $order->payment_terms['cash_sale']; - if ($order->cash) { - $paym = get_sales_point(user_pos()); - $order->cash_account = $paym['pos_account']; - $order->account_name = $paym['bank_account_name']; - $_POST['Location'] = $order->Location = $paym['pos_location']; - $order->location_name = $paym['location_name']; + $order->due_date = get_invoice_duedate($order->payment, $order->document_date); + if ($order->payment_terms['cash_sale']) { + $_POST['Location'] = $order->Location = $order->pos['pos_location']; + $order->location_name = $order->pos['location_name']; } $Ajax->activate('items_table'); $Ajax->activate('delivery'); - set_focus($order->pos == -1 ? 'delivery_date' : 'account'); } - sale_payment_list_cells(_('Payment:'), 'payment', null); + $paymcat = !$order->pos['cash_sale'] ? PM_CREDIT : + (!$order->pos['credit_sale'] ? PM_CASH : PM_ANY); + // all terms are available for SO + $is_order = in_array($order->trans_type, array(ST_SALESQUOTE, ST_SALESORDER)); + sale_payment_list_cells(_('Payment:'), 'payment', $is_order ? PM_ANY : $paymcat, null, true, $is_order); } else { - label_cells(_('Payment:'), $order->payment_terms['terms']); + label_cells(_('Payment:'), $order->payment_terms['terms'], "class='label'"); } + if($editable) { - $str = sales_types_list_row(_("Price List"), 'sales_type', null, true); + $str = sales_types_list_row(_("Price List:"), 'sales_type', null, true); } else { label_row(_("Price List:"), $order->sales_type_name); } @@ -406,8 +413,6 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group $change_prices = 1; } - label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%"); - table_section(4); if ($editable) @@ -451,12 +456,6 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group hidden('OrderDate', $order->document_date); } - if ($display_tax_group) - { - label_row(_("Tax Group:"), $order->tax_group_name); - hidden('tax_group_id', $order->tax_group_id); - } - end_outer_table(1); // outer table if ($change_prices != 0) { @@ -506,7 +505,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1) } else // prepare new line { - sales_items_list_cells(null,'stock_id', null, false, true); + sales_items_list_cells(null,'stock_id', null, false, true, true); if (list_updated('stock_id')) { $Ajax->activate('price'); $Ajax->activate('units'); @@ -553,7 +552,7 @@ function sales_order_item_controls(&$order, &$rowcounter, $line_no=-1) } else { - submit_cells('AddItem', _("Add Item"), "colspan=2", + submit_cells('AddItem', _("Add Item"), "colspan=2 align='center'", _('Add new item to document'), true); } @@ -568,16 +567,19 @@ function display_delivery_details(&$order) div_start('delivery'); - if ($order->cash) { // Direct payment sale + + if ($order->payment_terms['cash_sale']) { // Direct payment sale $Ajax->activate('items_table'); display_heading(_('Cash payment')); start_table(TABLESTYLE2, "width=60%"); - label_row(_("Deliver from Location:"), $order->location_name); - hidden('Location', $order->Location); - label_row(_("Cash account:"), $order->account_name); + locations_list_row(_("Deliver from Location:"), 'Location', null, false, true); + if (list_updated('Location')) + $Ajax->activate('items_table'); + label_row(_("Cash account:"), $order->pos['bank_account_name']); textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5); end_table(); + hidden('delivery_date', $order->due_date); } else { if ($order->trans_type==ST_SALESINVOICE) { @@ -603,8 +605,15 @@ function display_delivery_details(&$order) start_outer_table(TABLESTYLE2, "width=90%"); table_section(1); - locations_list_row(_("Deliver from Location:"), 'Location', null, - false, true); + locations_list_row(_("Deliver from Location:"), 'Location', null, false, true); + if ($order->payment_terms['days_before_due'] < 0) + { + $Ajax->addUpdate('items_table', 'prep_amount', price_format($order->get_trans_total())); // bind to items_table update + if (!$order->is_started()) + amount_row(_("Pre-Payment Required:"), 'prep_amount'); + else + label_row(_("Pre-Payment Required:"), price_format($order->prep_amount), "class='label'"); + } if (list_updated('Location')) $Ajax->activate('items_table');