'shipper' => _("Shipper"),
'company' => _("Company internal")
);
+//----------------------------------------------------------------------------------
+
+$pterm_types = array(
+ PTT_PRE => _("Prepayment"),
+ PTT_CASH => _("Cash"),
+ PTT_DAYS => _("After No. of Days"),
+ PTT_FOLLOWING => _("Day In Following Month")
+);
+
?>
\ No newline at end of file
$Ajax->activate('_page_body');
}
}
+
+function customer_credit_row($customer, $credit, $parms='')
+{
+ global $path_to_root;
+
+ label_row( _("Current Credit:"),
+ "<a target='_blank' " . ($credit<0 ? 'class="redfg"' : '')
+ ."href='$path_to_root/sales/inquiry/customer_inquiry.php?customer_id=".$customer."'"
+ ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >"
+ . price_format($credit)
+ ."</a>", $parms);
+}
+
+function supplier_credit_row($supplier, $credit, $parms='')
+{
+ global $path_to_root;
+
+ label_row( _("Current Credit:"),
+ "<a target='_blank' " . ($credit<0 ? 'class="redfg"' : '')
+ ."href='$path_to_root/purchasing/inquiry/supplier_inquiry.php?supplier_id=".$supplier."'"
+ ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >"
+ . price_format($credit)
+ ."</a>", $parms);
+}
+
?>
\ No newline at end of file
begin_transaction();
/*Insert to purchase order header record */
- $sql = "INSERT INTO ".TB_PREF."purch_orders (supplier_id, Comments, ord_date, reference, requisition_no, into_stock_location, delivery_address) VALUES(";
+ $sql = "INSERT INTO ".TB_PREF."purch_orders (supplier_id, Comments, ord_date, reference, requisition_no, into_stock_location, delivery_address, total) VALUES(";
$sql .= db_escape($po_obj->supplier_id) . "," .
db_escape($po_obj->Comments) . ",'" .
date2sql($po_obj->orig_order_date) . "', " .
db_escape($po_obj->reference) . ", " .
db_escape($po_obj->supp_ref) . ", " .
db_escape($po_obj->Location) . ", " .
- db_escape($po_obj->delivery_address) . ")";
+ db_escape($po_obj->delivery_address) . ", " .
+ db_escape($po_obj->get_trans_total()) . ")";
db_query($sql, "The purchase order header record could not be inserted");
requisition_no= ". db_escape( $po_obj->supp_ref). ",
into_stock_location=" . db_escape($po_obj->Location). ",
ord_date='" . date2sql($po_obj->orig_order_date) . "',
- delivery_address=" . db_escape($po_obj->delivery_address);
+ delivery_address=" . db_escape($po_obj->delivery_address).",
+ total=". db_escape($po_obj->get_trans_total());
$sql .= " WHERE order_no = " . $po_obj->order_no;
db_query($sql, "The purchase order could not be updated");
function read_po_header($order_no, &$order)
{
- $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name,
+ $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.tax_group_id,
".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name
FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
AND ".TB_PREF."purch_orders.order_no = ".db_escape($order_no);
$result = db_query($sql, "The order cannot be retrieved");
-
+_vd($sql);
if (db_num_rows($result) == 1)
{
$order->supplier_id = $myrow["supplier_id"];
$order->supplier_name = $myrow["supp_name"];
$order->curr_code = $myrow["curr_code"];
+ $order->tax_group_id = $myrow['tax_group_id'];
+ $order->credit = get_current_supp_credit($order->supplier_id);
$order->orig_order_date = sql2date($myrow["ord_date"]);
$order->Comments = $myrow["comments"];
$past2 = 2 * $past1;
// removed - supp_trans.alloc from all summations
- $value = "(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
- $due = "IF (".TB_PREF."supp_trans.type=".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type=".ST_SUPPCREDIT.",".TB_PREF."supp_trans.due_date,".TB_PREF."supp_trans.tran_date)";
- $sql = "SELECT ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.curr_code, ".TB_PREF."payment_terms.terms,
+ $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
+ $due = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_SUPPCREDIT.",trans.due_date,trans.tran_date)";
+ $sql = "SELECT supp.supp_name, supp.curr_code, ".TB_PREF."payment_terms.terms,
- Sum($value) AS Balance,
+ Sum(IFNULL($value,0)) AS Balance,
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$value,0)) AS Due,
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past1,$value,0)) AS Overdue1,
- Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past2,$value,0)) AS Overdue2
+ Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past2,$value,0)) AS Overdue2,
+ supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
+ * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
+ supp.tax_group_id
- FROM ".TB_PREF."suppliers,
- ".TB_PREF."payment_terms,
- ".TB_PREF."supp_trans
+ FROM ".TB_PREF."suppliers supp
+ LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id AND trans.tran_date <= '$todate',
+ ".TB_PREF."payment_terms
WHERE
- ".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.terms_indicator
- AND ".TB_PREF."suppliers.supplier_id = $supplier_id
- AND ".TB_PREF."supp_trans.tran_date <= '$todate'
- AND ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
+ supp.payment_terms = ".TB_PREF."payment_terms.terms_indicator
+ AND supp.supplier_id = $supplier_id
GROUP BY
- ".TB_PREF."suppliers.supp_name,
+ supp.supp_name,
".TB_PREF."payment_terms.terms,
".TB_PREF."payment_terms.days_before_due,
".TB_PREF."payment_terms.day_in_following_month";
$result = db_query($sql,"The customer details could not be retrieved");
-
- if (db_num_rows($result) == 0)
- {
-
- /*Because there is no balance - so just retrieve the header information about the customer - the choice is do one query to get the balance and transactions for those customers who have a balance and two queries for those who don't have a balance OR always do two queries - I opted for the former */
-
- $nil_balance = true;
-
- $sql = "SELECT ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supplier_id, ".TB_PREF."payment_terms.terms
- FROM ".TB_PREF."suppliers,
- ".TB_PREF."payment_terms
- WHERE
- ".TB_PREF."suppliers.payment_terms = ".TB_PREF."payment_terms.terms_indicator
- AND ".TB_PREF."suppliers.supplier_id = ".db_escape($supplier_id);
-
- $result = db_query($sql,"The customer details could not be retrieved");
-
- }
- else
- {
- $nil_balance = false;
- }
-
$supp = db_fetch($result);
- if ($nil_balance == true)
- {
- $supp["Balance"] = 0;
- $supp["Due"] = 0;
- $supp["Overdue1"] = 0;
- $supp["Overdue2"] = 0;
- }
-
return $supp;
-
}
function get_supplier($supplier_id)
return $results;
}
+function get_current_supp_credit($supplier_id)
+{
+ $suppdet = get_supplier_details($supplier_id);
+ return $suppdet['cur_credit'];
+
+}
+
?>
\ No newline at end of file
function get_supplier_details_to_order(&$order, $supplier_id)
{
- $sql = "SELECT curr_code,supp_name FROM ".TB_PREF."suppliers
- WHERE supplier_id = '$supplier_id'";
+ $sql = "SELECT curr_code, supp_name, tax_group_id,
+ supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
+ * (ov_amount + ov_gst + ov_discount),0)) as cur_credit
+ FROM ".TB_PREF."suppliers supp
+ LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
+ WHERE supp.supplier_id = '$supplier_id'
+ GROUP BY
+ supp.supp_name";
+
$result = db_query($sql, "The supplier details could not be retreived");
$myrow = db_fetch($result);
-
+ $order->credit = $myrow["cur_credit"];
+ $order->tax_group_id = $myrow["tax_group_id"];
$order->curr_code = $_POST['curr_code'] = $myrow["curr_code"];
$order->supplier_name = $_POST['supplier_name'] = $myrow["supp_name"];
$order->supplier_id = $_POST['supplier_id'] = $supplier_id;
$_POST['OrderDate']);
}
+ supplier_credit_row($order->supplier_id, $order->credit);
+
+ table_section(2);
+
if ($editable)
{
ref_row(_("Reference:"), 'ref');
label_row(_("Reference:"), $order->reference);
}
- table_section(2);
-
// check this out?????????
//if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "")
// $_POST['OrderDate'] = $order->orig_order_date;
include_once($path_to_root . "/purchasing/includes/po_class.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
+include_once($path_to_root . "/purchasing/includes/db/suppliers_db.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
set_page_security( @$_SESSION['PO']->trans_type,
if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) {
$_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->payment, $_POST['DispatchDate']);
}
+customer_credit_row($_SESSION['Items']->customer_id, $_SESSION['Items']->credit, "class='tableheader2'");
start_row();
date_cells(_("Invoice Dead-line"), 'due_date', '', null, 0, 0, 0, "class='tableheader2'");
end_row();
var $dimension2_id;
var $payment;
var $payment_terms; // cached payment terms
+ var $credit;
+
//-------------------------------------------------------------------------
//
// $trans_no==0 => open new/direct document
$this->due_date =
add_days($this->document_date, $SysPrefs->default_delivery_required_by());
}
+ $this->credit = get_current_cust_credit($this->customer_id);
$this->pos = user_pos();
$pos = get_sales_point($this->pos);
if (!$pos['cash_sale'] && !$pos['credit_sale'])
$this->payment_terms = get_payment_terms($payment);
$this->cash = $this->payment_terms['cash_sale'];
$this->cash_discount = $cdiscount;
+ $this->credit = get_current_cust_credit($customer_id);
}
function set_branch($branch_id, $tax_group_id, $tax_group_name, $phone='', $email='')
// Adjustment for swiss franken, we always have 5 rappen = 1/20 franken
if ($this->customer_currency == 'CHF') {
$val = $taxes['1']['Value'];
- $val1 = (floatval((intval(round(($val*20),0)))/20));
+ $val1 = (floatval((intval(round(($val*20),0)))/20));
$taxes['1']['Value'] = $val1;
}
return $taxes;
else
return round($this->freight_cost*$tax_rate/100, user_price_dec());
}
+ /*
+ Returns transaction value including all taxes
+ */
+ function get_trans_total() {
+
+ $total = $this->get_items_total() + $this->freight_cost;
+ $dec = user_price_dec();
+ if (!$this->tax_included ) {
+ $total += $this->get_shipping_tax();
+ $taxes = $this->get_taxes();
+ foreach($taxes as $tax)
+ $total += round($tax['Value'], $dec);
+ }
+ return $total;
+ }
} /* end of class defintion */
class line_details
$past2 = 2 * $past1;
// removed - debtor_trans.alloc from all summations
- $value = "IF(".TB_PREF."debtor_trans.type=11 OR ".TB_PREF."debtor_trans.type=12 OR ".TB_PREF."debtor_trans.type=2,
- -1, 1) *".
- "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
- .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + "
- .TB_PREF."debtor_trans.ov_discount)";
- $due = "IF (".TB_PREF."debtor_trans.type=10,".TB_PREF."debtor_trans.due_date,".TB_PREF."debtor_trans.tran_date)";
+ $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1)
+ * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
+
+ $due = "IF (trans.type=10, trans.due_date, trans.tran_date)";
$sql = "SELECT ".TB_PREF."debtors_master.name, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."payment_terms.terms,
".TB_PREF."debtors_master.credit_limit, ".TB_PREF."credit_status.dissallow_invoices, ".TB_PREF."credit_status.reason_description,
- Sum(".$value.") AS Balance,
-
+ Sum(IFNULL($value,0)) AS Balance,
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$value,0)) AS Due,
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past1,$value,0)) AS Overdue1,
Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past2,$value,0)) AS Overdue2
- FROM ".TB_PREF."debtors_master,
+ FROM ".TB_PREF."debtors_master
+ LEFT JOIN ".TB_PREF."debtor_trans trans ON
+ trans.tran_date <= '$todate' AND ".TB_PREF."debtors_master.debtor_no = trans.debtor_no AND trans.type <> 13
+,
".TB_PREF."payment_terms,
- ".TB_PREF."credit_status,
- ".TB_PREF."debtor_trans
+ ".TB_PREF."credit_status
WHERE
".TB_PREF."debtors_master.payment_terms = ".TB_PREF."payment_terms.terms_indicator
- AND ".TB_PREF."debtors_master.credit_status = ".TB_PREF."credit_status.id
+ AND ".TB_PREF."debtors_master.credit_status = ".TB_PREF."credit_status.id
AND ".TB_PREF."debtors_master.debtor_no = ".db_escape($customer_id)."
- AND ".TB_PREF."debtor_trans.tran_date <= '$todate'
- AND ".TB_PREF."debtor_trans.type <> 13
- AND ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."debtor_trans.debtor_no
GROUP BY
".TB_PREF."debtors_master.name,
".TB_PREF."credit_status.reason_description";
$result = db_query($sql,"The customer details could not be retrieved");
- if (db_num_rows($result) == 0)
- {
-
- /*Because there is no balance - so just retrieve the header information about the customer - the choice is do one query to get the balance and transactions for those customers who have a balance and two queries for those who don't have a balance OR always do two queries - I opted for the former */
-
- $nil_balance = true;
-
- $sql = "SELECT ".TB_PREF."debtors_master.name, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.debtor_no, ".TB_PREF."payment_terms.terms,
- ".TB_PREF."debtors_master.credit_limit, ".TB_PREF."credit_status.dissallow_invoices, ".TB_PREF."credit_status.reason_description
- FROM ".TB_PREF."debtors_master,
- ".TB_PREF."payment_terms,
- ".TB_PREF."credit_status
-
- WHERE
- ".TB_PREF."debtors_master.payment_terms = ".TB_PREF."payment_terms.terms_indicator
- AND ".TB_PREF."debtors_master.credit_status = ".TB_PREF."credit_status.id
- AND ".TB_PREF."debtors_master.debtor_no = ".db_escape($customer_id);
-
- $result = db_query($sql,"The customer details could not be retrieved");
-
- }
- else
- {
- $nil_balance = false;
- }
-
$customer_record = db_fetch($result);
- if ($nil_balance == true)
- {
- $customer_record["Balance"] = 0;
- $customer_record["Due"] = 0;
- $customer_record["Overdue1"] = 0;
- $customer_record["Overdue2"] = 0;
- }
-
return $customer_record;
}
+
function get_customer($customer_id)
{
$sql = "SELECT * FROM ".TB_PREF."debtors_master WHERE debtor_no=".db_escape($customer_id);
return $results;
}
+function get_current_cust_credit($customer_id)
+{
+ $custdet = get_customer_details($customer_id);
+
+ return $custdet['credit_limit']-$custdet['Balance'];
+
+}
?>
\ No newline at end of file
$order_no = get_next_trans_no($order->trans_type);
$del_date = date2sql($order->due_date);
$order_type = 0; // this is default on new order
+ $total = $order->get_trans_total();
$sql = "INSERT INTO ".TB_PREF."sales_orders (order_no, type, debtor_no, trans_type, branch_code, customer_ref, reference, comments, ord_date,
order_type, ship_via, deliver_to, delivery_address, contact_phone,
- freight_cost, from_stk_loc, delivery_date, payment_terms)
+ freight_cost, from_stk_loc, delivery_date, payment_terms, total)
VALUES (" .db_escape($order_no) . "," .db_escape($order_type) . "," . db_escape($order->customer_id) .
", " .db_escape($order->trans_type) . "," .db_escape($order->Branch) . ", ".
db_escape($order->cust_ref) .",".
db_escape($order->freight_cost) .", " .
db_escape($order->Location) .", " .
db_escape($del_date) . "," .
- db_escape($order->payment) . ")";
+ db_escape($order->payment) . "," .
+ db_escape($total). ")";
db_query($sql, "order Cannot be Added");
$ord_date = date2sql($order->document_date);
$order_no = key($order->trans_no);
$version= current($order->trans_no);
+ $total = $order->get_trans_total();
begin_transaction();
from_stk_loc = " .db_escape($order->Location) .",
delivery_date = " .db_escape($del_date). ",
version = ".($version+1).",
- payment_terms = " .db_escape($order->payment). "
+ payment_terms = " .db_escape($order->payment). ",
+ total = ". db_escape($total) ."
WHERE order_no=" . $order_no ."
AND trans_type=".$order->trans_type." AND version=".$version;
db_query($sql, "order Cannot be Updated, this can be concurrent edition conflict");
function get_customer_to_order($customer_id) {
// Now check to ensure this account is not on hold */
- $sql = "SELECT ".TB_PREF."debtors_master.name, "
- .TB_PREF."debtors_master.address, "
- .TB_PREF."credit_status.dissallow_invoices, "
- .TB_PREF."debtors_master.sales_type AS salestype, "
- .TB_PREF."debtors_master.dimension_id, "
- .TB_PREF."debtors_master.dimension2_id, "
- .TB_PREF."sales_types.sales_type, "
- .TB_PREF."sales_types.tax_included, "
- .TB_PREF."sales_types.factor, "
- .TB_PREF."debtors_master.curr_code, "
- .TB_PREF."debtors_master.discount,"
- .TB_PREF."debtors_master.payment_terms,"
- .TB_PREF."debtors_master.pymt_discount
- FROM ".TB_PREF."debtors_master, "
+ $sql = "SELECT cust.name,
+ cust.address, "
+ .TB_PREF."credit_status.dissallow_invoices,
+ cust.sales_type AS salestype,
+ cust.dimension_id,
+ cust.dimension2_id,
+ stype.sales_type,
+ stype.tax_included,
+ stype.factor,
+ cust.curr_code,
+ cust.discount,
+ cust.payment_terms,
+ cust.pymt_discount,
+ cust.credit_limit - Sum(IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2,
+ -1, 1) * (ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount),0)) as cur_credit
+ FROM ".TB_PREF."debtors_master cust
+ LEFT JOIN ".TB_PREF."debtor_trans trans ON trans.type!=".ST_CUSTDELIVERY." AND trans.debtor_no = cust.debtor_no,"
.TB_PREF."credit_status, "
- .TB_PREF."sales_types
- WHERE ".TB_PREF."debtors_master.sales_type="
- .TB_PREF."sales_types.id
- AND ".TB_PREF."debtors_master.credit_status=".TB_PREF."credit_status.id
- AND ".TB_PREF."debtors_master.debtor_no = ".db_escape($customer_id);
+ .TB_PREF."sales_types stype
+ WHERE cust.sales_type=stype.id
+ AND cust.credit_status=".TB_PREF."credit_status.id
+ AND cust.debtor_no = ".db_escape($customer_id)
+ ." GROUP by cust.debtor_no";
$result =db_query($sql,"Customer Record Retreive");
return db_fetch($result);
$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'];
function display_order_summary($title, &$order, $editable_items=false)
{
- global $path_to_root, $SysPrefs;
+ global $SysPrefs;
display_heading($title);
ref_row(_("Reference").':', 'ref', _('Reference number unique for this document type'), null, '');
+ table_section(2);
+
if (!is_company_currency($order->customer_currency))
{
- table_section(2);
-
label_row(_("Customer Currency:"), $order->customer_currency);
exchange_rate_display($order->customer_currency, get_company_currency(),
($editable ? $_POST['OrderDate'] : $order->document_date));
}
+
+ customer_credit_row($_POST['customer_id'], $order->credit);
+
+ label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
+
table_section(3);
if (($order->trans_type != ST_CUSTDELIVERY) && ($order->pos != -1)) { // editable payment type
$change_prices = 1;
}
- label_row(_("Customer Discount:"), ($order->default_discount * 100) . "%");
-
table_section(4);
if ($editable)