$_SESSION['Items']->document_date = $_POST['OrderDate'];
$_SESSION['Items']->freight_cost = $_POST['ChargeFreightCost'];
$_SESSION['Items']->Location = $_POST["Location"];
- $_SESSION['Items']->default_sales_type = $_POST['sales_type_id'];
+ $_SESSION['Items']->sales_type = $_POST['sales_type_id'];
$_SESSION['Items']->reference = $_POST['ref'];
$_SESSION['Items']->ship_via = $_POST['ShipperID'];
}
$_POST['OrderDate'] = $_SESSION['Items']->document_date;
$_POST['ChargeFreightCost'] = $_SESSION['Items']->freight_cost;
$_POST['Location'] = $_SESSION['Items']->Location;
- $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type;
+ $_POST['sales_type_id'] = $_SESSION['Items']->sales_type;
$_POST['ref'] = $_SESSION['Items']->reference;
$_POST['ShipperID'] = $_SESSION['Items']->ship_via;
}
label_cell(_("Shipping Company"), "class='tableheader2'");
shippers_list_cells(null, 'ShipperID', $_POST['ShipperID']);
// if (!isset($_POST['sales_type_id']))
-// $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type;
+// $_POST['sales_type_id'] = $_SESSION['Items']->sales_type;
// label_cell(_("Sales Type"), "class='tableheader2'");
// sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']);
$cart->due_date = $_POST['due_date'];
$cart->Location = $_POST['Location'];
$cart->Comments = $_POST['Comments'];
- $cart->default_sales_type = $_POST['sales_type_id'];
+ $cart->sales_type = $_POST['sales_type_id'];
}
//------------------------------------------------------------------------------
$_POST['due_date'] = $cart->due_date;
$_POST['Location']= $cart->Location;
$_POST['Comments']= $cart->Comments;
- $_POST['sales_type_id'] = $cart->default_sales_type;
+ $_POST['sales_type_id'] = $cart->sales_type;
}
//------------------------------------------------------------------------------
label_cells(_("For Sales Order"), get_customer_trans_view_str(systypes::sales_order(), $_SESSION['Items']->order_no), "class='tableheader2'");
-if (!isset($_POST['sales_type_id'])) {
- $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type;
-}
-label_cell(_("Sales Type"), "class='tableheader2'");
-sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']);
-
+label_cells(_("Sales Type"), $_SESSION['Items']->sales_type_name, "class='tableheader2'");
end_row();
start_row();
label_cells(_("Delivery Notes:"),
get_customer_trans_view_str(systypes::cust_dispatch(), array_keys($_SESSION['Items']->src_docs)), "class='tableheader2'");
-if (!isset($_POST['sales_type_id'])) {
- $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type;
-}
-
-label_cell(_("Sales Type"), "class='tableheader2'");
-sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']);
+label_cells(_("Sales Type"), $_SESSION['Items']->sales_type_name, "class='tableheader2'");
end_row();
start_row();
var $document_date;
var $due_date;
- var $default_sales_type; // set to the customer's sales type
+ var $sales_type; // set to the customer's sales type
var $sales_type_name; // set to customer's sales type name
var $tax_included;
function Cart($type, $trans_no=0, $view=false ) {
/*Constructor function initialises a new shopping cart */
$this->line_items = array();
- $this->default_sales_type = "";
+ $this->sales_type = "";
$this->trans_type = 30;
$this->read($type, $trans_no, $view );
}
+ //-------------------------------------------------------------------------
+ // Reading document into cart
+ //
+ function read($type, $trans_no = 0, $view=false ) {
- function read($type, $trans_no=0, $view=false ) {
-
- if (!is_array($trans_no)) $trans_no = array($trans_no);
+ if (!is_array($trans_no)) $trans_no = array($trans_no);
- if ($trans_no[0]) {
- if ($type==30) { // sales order
- read_sales_order($trans_no[0], $this);
- if ($view) { // prepare for DN/IV entry
- for($line_no=0; $line_no<count($this->line_items); $line_no++) {
- $line= &$this->line_items[$line_no];
- $line->qty_dispatched = $line->quantity-$line->qty_done;
- }
- }
- } else { // derivative transaction
- read_sales_trans($type, $trans_no, $this);
- if ($this->order_no) { // free hand credit notes have no order_no
- $sodata = get_sales_order_header($this->order_no);
- $this->cust_ref = $sodata["customer_ref"];
-//set_customer($customer_name, $customer_id, $currency, $discount)
-//* $this->customer_name = $sodata["name"];
-//* $this->customer_currency = $sodata["curr_code"];
-//* $this->Comments = $sodata["comments"];
- $this->delivery_address = $sodata["delivery_address"];
-// $this->location_name = $sodata["location_name"];
-// $this->document_date = sql2date($myrow["ord_date"]);
- }
- if (!$view && ($type!=11 || $this->trans_link!=0)) {
- $src_type = get_parent_type($type);
- $src_details = 0;
- if ($src_type==30) { // get src data from sales_orders
- $this->src_docs = array( $sodata['order_no']=>$sodata['version']);
- $srcdetails = get_sales_order_details($this->order_no);
- } else { // get src_data from debtor_trans
- $this->src_docs = get_customer_trans_version($src_type, get_parent_trans($type,$trans_no[0]));
- $srcdetails = get_customer_trans_details($src_type,array_keys($this->src_docs));
- }
- // calculate & save: qtys on other docs and free qtys on src doc
- $line_no = 0;
- for($line_no=0; $srcline = db_fetch($srcdetails); $line_no++) {
- $sign = 1; // $type==13 ? 1 : -1; // this is strange debtor_trans atavism
+ if ($trans_no[0]) {
+ if ($type == 30) { // sales order
+ read_sales_order($trans_no[0], $this);
+ if ($view) { // prepare for DN/IV entry
+ for($line_no = 0; $line_no < count($this->line_items); $line_no++) {
$line = &$this->line_items[$line_no];
-
- $line->qty_old = $line->qty_dispatched = $line->quantity;
- $line->quantity += $sign*($srcline['quantity']-$srcline['qty_done']); // add free qty on src doc
+ $line->qty_dispatched = $line->quantity - $line->qty_done;
+ }
+ }
+ } else { // derivative transaction
+ read_sales_trans($type, $trans_no, $this);
+ if ($this->order_no) { // free hand credit notes have no order_no
+ $sodata = get_sales_order_header($this->order_no);
+ $this->cust_ref = $sodata["customer_ref"];
+ // currently currency is hard linked to debtor account
+ // $this->customer_currency = $sodata["curr_code"];
+ $this->delivery_to = $sodata["deliver_to"];
+ $this->delivery_address = $sodata["delivery_address"];
}
- } else {
- for($line_no=0; $line_no<count($this->line_items); $line_no++) {
- $line= &$this->line_items[$line_no];
- $line->qty_dispatched = $line->quantity;
+ if (!$view && ($type!=11 || $this->trans_link!=0)) {
+ $src_type = get_parent_type($type);
+ $src_details = 0;
+ if ($src_type == 30) { // get src data from sales_orders
+ $this->src_docs = array( $sodata['order_no']=>$sodata['version']);
+ $srcdetails = get_sales_order_details($this->order_no);
+ } else { // get src_data from debtor_trans
+ $this->src_docs = get_customer_trans_version($src_type, get_parent_trans($type,$trans_no[0]));
+ $srcdetails = get_customer_trans_details($src_type,array_keys($this->src_docs));
+ }
+ // calculate & save: qtys on other docs and free qtys on src doc
+ $line_no = 0;
+ for($line_no = 0; $srcline = db_fetch($srcdetails); $line_no++) {
+ $sign = 1; // $type==13 ? 1 : -1; // this is strange debtor_trans atavism
+ $line = &$this->line_items[$line_no];
+
+ $line->qty_old = $line->qty_dispatched = $line->quantity;
+ $line->quantity += $sign * ($srcline['quantity'] - $srcline['qty_done']); // add free qty on src doc
+ }
+ } else {
+ for($line_no = 0; $line_no < count($this->line_items); $line_no++) {
+ $line = &$this->line_items[$line_no];
+ $line->qty_dispatched = $line->quantity;
+ }
}
}
+ } else {
+ $this->trans_type = $type;
+ $this->trans_no = 0;
+ // set new sales document defaults here
+ $this->customer_id = '';
+ $this->document_date = Today();
+ if (!is_date_in_fiscalyear($this->document_date))
+ $this->document_date = end_fiscalyear();
+ $this->reference = references::get_next($this->trans_type);
}
- } else {
- $this->trans_type = $type;
- $this->trans_no = 0;
- // set new sales document defaults here
- $this->customer_id='';
- $this->document_date = Today();
- if (!is_date_in_fiscalyear($this->document_date))
- $this->document_date = end_fiscalyear();
- $this->reference = references::get_next($this->trans_type);
- }
}
//-------------------------------------------------------------------------
// Writing new/modified sales document to database.
// Makes parent documents for direct delivery/invoice by recurent call.
-
+ // $policy - 0 or 1: writeoff/return for IV, back order/cancel for DN
function write($policy=0) {
if (count($this->src_docs) == 0 && ($this->trans_type == 10 || $this->trans_type == 13)) {
- // direct document -> first add parent
- $src = do_clone($this);
+ // this is direct document - first add parent
+ $src = (PHP_VERSION<5) ? $this : clone( $this ); // make local copy of this cart
$src->trans_type = get_parent_type($src->trans_type);
$src->reference = 'auto';
$src->write(1);
+
$type = $this->trans_type;
$ref = $this->reference;
// re-read document
$this->read($src->trans_type, key($src->trans_no), true);
-
$this->reference = $ref;
$this->trans_type = $type;
$this->src_docs= $this->trans_no;
function set_sales_type($sales_type, $sales_name, $tax_included=0)
{
- $this->default_sales_type = $sales_type;
- $this->sales_type_name = $sales_name;
- $this->tax_included = $tax_included;
+ $old_tax_inc = $this->tax_included;
+ $this->sales_type = $sales_type;
+ $this->sales_type_name = $sales_name;
+ $this->tax_included = $tax_included;
}
function set_location($id, $name)
{
unset($this->line_items);
$this->line_items = array();
- $this->default_sales_type = "";
+ $this->sales_type = "";
$this->trans_no = 0;
$this->customer_id = $this->order_no = 0;
}
}
- function get_tax_free_shipping() {
+ function get_tax_free_shipping()
+ {
if ($this->tax_included==0)
return $this->freight_cost;
return ($this->freight_cost - $this->get_shipping_tax());
}
- function get_shipping_tax() {
+ function get_shipping_tax()
+ {
$tax_items = get_shipping_tax_as_array();
$tax_rate = 0;
$credit_note->Branch, $credit_date, $credit_note->reference,
$credit_note_total, 0, $items_added_tax,
$credit_note->freight_cost, $freight_added_tax,
- $credit_note->default_sales_type,
+ $credit_note->sales_type,
$credit_note->order_no, $credit_invoice, $credit_note->ship_via
//, $credit_note->due_date
);
$credit_line->line_price(), $line_tax, $credit_line->discount_percent,
$credit_line->standard_cost, $trans_no==0 ? 0: $credit_line->id);
- add_credit_movements_item(&$credit_note, &$credit_line, $credit_date,
+ add_credit_movements_item(&$credit_note, &$credit_line,
$credit_type, $line_taxfree_price+$line_tax, $credit_invoice);
add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'],
$taxitem['rate'], $credit_note->tax_included, $taxitem['Value']);
- add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+ add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
$taxitem['Value'], $credit_note->customer_id,
"A tax GL posting for this credit note could not be inserted");
}
// Insert a stock movement coming back in to show the credit note and
// a reversing stock movement to show the write off
//
-function add_credit_movements_item(&$credit_note, &$credit_line, $date_,
+function add_credit_movements_item(&$credit_note, &$credit_line,
$credit_type, $price, $credited_invoice=0)
{
$delivery->tax_included ? 0 : $tax_total-$freight_tax,
$delivery->freight_cost,
$delivery->tax_included ? 0 : $freight_tax,
- $delivery->default_sales_type, $delivery->order_no, 0,
+ $delivery->sales_type, $delivery->order_no, 0,
$delivery->ship_via, $delivery->due_date);
if ($trans_no == 0) {
$invoice_no = write_customer_trans(10, $trans_no, $invoice->customer_id,
$invoice->Branch, $date_, $invoice->reference, $items_total, 0,
$items_added_tax, $invoice->freight_cost, $freight_added_tax,
- $invoice->default_sales_type, $sales_order, $delivery_no,
+ $invoice->sales_type, $sales_order, $delivery_no,
$invoice->ship_via, $invoice->due_date);
if ($trans_no == 0) {
VALUES ('" . $order_type . "', '" . $order->customer_id . "', '" . $order->Branch . "', '".
$order->cust_ref ."','". db_escape($order->Comments) ."','" .
date2sql($order->document_date) . "', '" .
- $order->default_sales_type . "', " .
+ $order->sales_type . "', " .
$_POST['ship_via'] .",'" . $order->deliver_to . "', '" .
$order->delivery_address . "', '" .
$order->phone . "', '" . $order->email . "', " .
customer_ref = '". $order->cust_ref ."',
comments = '". db_escape($order->Comments) ."',
ord_date = '" . $ord_date . "',
- order_type = '" . $order->default_sales_type . "',
+ order_type = '" . $order->sales_type . "',
ship_via = " . $order->ship_via .",
deliver_to = '" . $order->deliver_to . "',
delivery_address = '" . $order->delivery_address . "',
$myrow["delivery_address"], $myrow["freight_cost"]);
$order->cust_ref = $myrow["customer_ref"];
- $order->default_sales_type =$myrow["order_type"];
+ $order->sales_type =$myrow["order_type"];
$order->Comments = $myrow["comments"];
$order->due_date = sql2date($myrow["delivery_date"]);
$order->document_date = sql2date($myrow["ord_date"]);
//----------------------------------------------------------------------------------------
-function get_price ($stock_id, $debtor_no)
+function get_price ($stock_id, $currency, $sales_type_id)
{
$sql = "SELECT ".TB_PREF."prices.price
- FROM ".TB_PREF."prices, ".TB_PREF."debtors_master
- WHERE ".TB_PREF."debtors_master.sales_type=".TB_PREF."prices.sales_type_id
- AND ".TB_PREF."debtors_master.debtor_no='" . $debtor_no . "'
- AND ".TB_PREF."prices.stock_id = '" . $stock_id . "'
- AND ".TB_PREF."prices.curr_abrev = ".TB_PREF."debtors_master.curr_code";
+ FROM ".TB_PREF."prices
+ WHERE ".TB_PREF."prices.stock_id = '" . $stock_id . "'
+ AND ".TB_PREF."prices.sales_type_id = " . $sales_type_id . "
+ AND ".TB_PREF."prices.curr_abrev = '$currency'";
$result = db_query($sql, "There was a problem retrieving the pricing information for the part $stock_id for customer");
customer_list_row(_("Customer:"), 'customer_id', null, false, true);
- if ($order->customer_id != $_POST['customer_id'])
+ if ($order->customer_id != $_POST['customer_id'] || $order->sales_type != $_POST['sales_type_id'])
{
// customer has changed
echo "<table height='5'>";
if (!isset($_POST['sales_type_id']))
- $_POST['sales_type_id'] = $order->default_sales_type;
- sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id']);
+ $_POST['sales_type_id'] = $order->sales_type;
+ sales_types_list_row(_("Sales Type"), 'sales_type_id', $_POST['sales_type_id'], true);
label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
echo "</table>";
$_POST['units'] = $item_info["units"];
$_POST['qty'] = 0;
- $_POST['price'] = get_price($_POST['stock_id'], $order->customer_id);
+ $_POST['price'] = get_price($_POST['stock_id'],
+ $order->customer_currency, $order->sales_type);
// default to the customer's discount %
$_POST['Disc'] = $order->default_discount * 100;
}
echo "<table>";
$customer_error = "";
+ $change_prices = 0;
if (isset($order) && !$editable)
{
$customer_error = _("The selected customer does not have any branches. Please create at least one branch.");
unset($_POST['branch_id']);
$order->Branch = 0;
- } else
-
+ } else
{
-
//set_global_customer($_POST['customer_id']);
if (($order->customer_id != $_POST['customer_id']) ||
($order->Branch != $_POST['branch_id'])) {
- $old_order = $order;
+
+ $old_order = (PHP_VERSION<5) ? $order : clone( $order );
$customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
$_POST['Location'] = $order->Location;
$_POST['deliver_to'] = $order->deliver_to;
$_POST['delivery_address'] = $order->delivery_address;
$_POST['phone'] = $order->phone;
+ $_POST['sales_type'] = $order->sales_type;
// change prices if necessary
// what about discount in template case?
if ( $old_order->customer_currency!=$order->customer_currency
- || $old_order->default_sales_type!=$order->default_sales_type
+ || $old_order->sales_type!=$order->sales_type
// || $old_order->default_discount!=$order->default_discount
) {
-
- foreach ($order->line_items as $line_no=>$item) {
- $line = &$order->line_items[$line_no];
- $line->price = get_price($line->stock_id, $order->customer_id);
- // $line->discount_percent = $order->default_discount;
+ $change_prices = 1;
}
- }
}
- }
+ } // changed branch
set_global_customer($_POST['customer_id']);
}
echo "</td><td>"; // outer table
}
+ if( $order->sales_type != $_POST['sales_type']) {
+ $myrow = get_sales_type($_POST['sales_type']);
+ $order->set_sales_type($myrow['id'], $myrow['sales_type'],
+ $myrow['tax_included']);
+ $change_prices = 1;
+ }
+
+ if($change_prices!=0)
+ {
+ foreach ($order->line_items as $line_no=>$item) {
+ $line = &$order->line_items[$line_no];
+ $line->price = get_price($line->stock_id, $order->customer_currency,
+ $order->sales_type);
+ // $line->discount_percent = $order->default_discount;
+ }
+ }
+
echo "<table height='5'>";
- label_row(_("Sales Type:"), $order->sales_type_name);
+ if($editable)
+ sales_types_list_row(_("Price List"), 'sales_type', $_POST['sales_type'], true);
+ else
+ label_row(_("Price List:"), $order->sales_type_name);
label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
echo "</table>";
$_POST['units'] = $item_info["units"];
$_POST['qty'] = 1;
- $_POST['price'] = get_price ($_POST['stock_id'], $order->customer_id);
+ $_POST['price'] = get_price ($_POST['stock_id'],
+ $order->customer_currency, $order->sales_type);
// default to the customer's discount %
$_POST['Disc'] = $order->default_discount * 100;
}