var $price_factor; // ditto for price calculations
var $pos; // user assigned POS
- var $cash; // cash transaction - helper variable not stored in db
var $cash_account;
var $account_name;
var $cash_discount; // not used as of FA 2.1
$this->trans_type = ST_SALESORDER;
$this->dimension_id = 0;
$this->dimension2_id = 0;
+ $this->pos = get_sales_point(user_pos());
$this->read($type, $trans_no, $no_edit);
$this->cart_id = uniqid('');
}
} else
$this->due_date =
add_days($this->document_date, $SysPrefs->default_delivery_required_by());
- $this->pos = user_pos();
- }
+ }
$this->credit = get_current_cust_credit($this->customer_id);
}
$this->customer_currency = $currency;
$this->payment = $payment;
$this->payment_terms = get_payment_terms($payment);
- $this->cash = $this->payment_terms['cash_sale'];
$this->cash_discount = $cdiscount;
- $pos = get_sales_point($this->pos);
- if (!$pos['cash_sale'] || !$pos['credit_sale'])
- $this->pos = -1; // mark not editable payment type
- if ($this->cash) {
- $this->Location = $pos['pos_location'];
- $this->location_name = $pos['location_name'];
- $this->cash_account = $pos['pos_account'];
- $this->account_name = $pos['bank_account_name'];
+ if ($this->payment_terms['cash_sale']) {
+ $this->Location = $this->pos['pos_location'];
+ $this->location_name = $this->pos['location_name'];
+ $this->cash_account = $this->pos['pos_account'];
+ $this->account_name = $this->pos['bank_account_name'];
}
$this->credit = get_current_cust_credit($customer_id);
}
$order->set_delivery($myrow["default_ship_via"], $myrow["br_name"],
$address);
- if ($order->trans_type == ST_SALESINVOICE) {
+ if ($order->trans_type == ST_SALESINVOICE || $order->trans_type == ST_SALESORDER) {
$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"]);
- }
+ 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"]);
$_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');
label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
table_section(3);
-
- if (($order->trans_type != ST_CUSTDELIVERY) && ($order->pos != -1)) { // editable payment type
+ if ($order->pos['cash_sale'] || $order->pos['credit_sale']) {
+ // 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']) {
+ $order->cash_account = $order->pos['pos_account'];
+ $order->account_name = $order->pos['bank_account_name'];
+ $_POST['Location'] = $order->Location = $order->pos['pos_location'];
+ $order->location_name = $order->pos['location_name'];
}
$Ajax->activate('items_table');
$Ajax->activate('delivery');
}
- 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
+ sale_payment_list_cells(_('Payment:'), 'payment',
+ (in_array($order->trans_type, array(ST_SALESQUOTE, ST_SALESORDER))
+ ? PM_ANY : $paymcat), null);
} else {
label_cells(_('Payment:'), $order->payment_terms['terms']);
}
+
if($editable) {
$str = sales_types_list_row(_("Price List"), 'sales_type', null, true);
} else {
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);
+ locations_list_row(_("Deliver from Location:"), 'Location', null, false, true);
label_row(_("Cash account:"), $order->account_name);
textarea_row(_("Comments:"), "Comments", $order->Comments, 31, 5);
end_table();
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 (list_updated('Location'))
$Ajax->activate('items_table');
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');
$_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;
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');
$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);