//-------------------------------------------------------------------------------------------------
-if (isset($_POST['submit']) && $_POST['submit'] != "")
+if (isset($_POST['submit']) && $_POST['submit'] != "")
{
$input_error = 0;
- if (strlen($_POST['coy_name'])==0)
+ if (strlen($_POST['coy_name'])==0)
{
$input_error = 1;
display_error(_("The company name must be entered."));
$_POST['postal_address'], $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['coy_logo'], $_POST['domicile'],
$_POST['use_dimension'], $_POST['custom1_name'], $_POST['custom2_name'], $_POST['custom3_name'],
$_POST['custom1_value'], $_POST['custom2_value'], $_POST['custom3_value'],
- $_POST['curr_default'], $_POST['f_year']);
+ $_POST['curr_default'], $_POST['f_year'], check_value('no_item_list'), check_value('no_customer_list'),
+ check_value('no_supplier_list'));
display_notification_centered(_("Company setup has been updated."));
}
$_POST['coy_logo'] = $myrow["coy_logo"];
$_POST['domicile'] = $myrow["domicile"];
$_POST['use_dimension'] = $myrow["use_dimension"];
+$_POST['no_item_list'] = $myrow["no_item_list"];
+$_POST['no_customer_list'] = $myrow["no_customer_list"];
+$_POST['no_supplier_list'] = $myrow["no_supplier_list"];
$_POST['custom1_name'] = $myrow["custom1_name"];
$_POST['custom2_name'] = $myrow["custom2_name"];
$_POST['custom3_name'] = $myrow["custom3_name"];
number_list_row(_("Use Dimensions:"), 'use_dimension', null, 0, 2);
+check_row(_("No Item List"), 'no_item_list', $_POST['no_item_list']);
+check_row(_("No Customer List"), 'no_customer_list', $_POST['no_customer_list']);
+check_row(_("No Supplier List"), 'no_supplier_list', $_POST['no_supplier_list']);
+
start_row();
end_row();
label_row(_("Custom Field Name"), _("Custom Field Value"));
$db_connections[$id]['dbname'] = $_POST['dbname'];
if (isset($_GET['ul']) && $_GET['ul'] == 1)
{
- if ($_POST['tbpref'] == 1)
+ if (is_numeric($_POST['tbpref']) && $_POST['tbpref'] == 1)
{
$db_connections[$id]['tbpref'] = $tb_pref_counter."_";
$new = true;
function update_company_setup($coy_name, $coy_no, $gst_no, $tax_prd, $tax_last, $postal_address, $phone, $fax, $email,
$coy_logo, $domicile, $Dimension, $custom1_name, $custom2_name, $custom3_name,
- $custom1_value, $custom2_value, $custom3_value, $curr_default, $f_year)
+ $custom1_value, $custom2_value, $custom3_value, $curr_default, $f_year, $no_item_list, $no_customer_list,
+ $no_supplier_list)
{
if ($f_year == null)
$f_year = 0;
coy_logo='$coy_logo',
domicile='$domicile',
use_dimension=$Dimension,
+ no_item_list=$no_item_list,
+ no_customer_list=$no_customer_list,
+ no_supplier_list=$no_supplier_list,
custom1_name='$custom1_name',
custom2_name='$custom2_name',
custom3_name='$custom3_name',
$debug = 1;
$show_sql = 0;
- $go_debug = 0;
- if ($go_debug == 1)
+ $go_debug = 1;
+ if ($go_debug == 0)
{
error_reporting(E_ALL);
ini_set("display_errors", "On");
// Main Title
$app_title = "FrontAccounting";
// application version
- $version = "1.16";
+ $version = "2.0 Pre Alpha";
// Build for development purposes
- $build_version = "15";
+ $build_version = "2";
// Powered by
$power_by = "FrontAccounting";
/* print_invoice_no. 0 = print reference number, 1 = print invoice number */
$print_invoice_no = 0;
- /* Flags for no item, customer and supplier lists. The list can only hold about 1000 items in the lists */
- $no_item_list = 0; // change value to 1 if you do not want all items in list
- $no_customer_list = 0; // change value to 1 if you do not want all customers in list
- $no_supplier_list = 0; // change value to 1 if you do not want all suppliers in list
-
$dateformats = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD");
$dateseps = array("/", ".", "-", " ");
$thoseps = array(",", ".", " ");
echo "<td> </td>\n";
submit_cells($name, $value, $extra);
echo "</tr>\n";
-}
+}
//-----------------------------------------------------------------------------------
-function check_value($name)
+function check_value($name)
{
if (!isset($_POST[$name]))
return 0;
- return 1;
+ return 1;
}
function check($label, $name, $value, $submit_on_change=false)
//-----------------------------------------------------------------------------------
-function labelheader_cell($label, $params="")
+function labelheader_cell($label, $params="")
{
echo "<td class='tableheader' $params>$label</td>\n";
}
-function label_cell($label, $params="")
+function label_cell($label, $params="")
{
echo "<td $params>$label</td>\n";
}
{
if ($bold)
label_cell("<b>".number_format2($label,user_price_dec())."</b>", "nowrap align=right");
- else
+ else
label_cell(number_format2($label,user_price_dec()), "nowrap align=right");
}
+function percent_cell($label, $bold=false)
+{
+ if ($bold)
+ label_cell("<b>".number_format2($label,user_percent_dec())." %</b>", "nowrap align=right");
+ else
+ label_cell(number_format2($label,user_percent_dec())." %", "nowrap align=right");
+}
+
function qty_cell($label, $bold=false)
{
if ($bold)
label_cell("<b>".number_format2($label,user_qty_dec())."</b>", "nowrap align=right");
- else
+ else
label_cell(number_format2($label,user_qty_dec()), "nowrap align=right");
}
function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
{
- if (!isset($_POST[$name]) || $_POST[$name] == "")
+ if (!isset($_POST[$name]) || $_POST[$name] == "")
{
if ($init)
$_POST[$name] = $init;
function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
{
global $use_date_picker, $path_to_root;
- if (!isset($_POST[$name]) || $_POST[$name] == "")
+ if (!isset($_POST[$name]) || $_POST[$name] == "")
{
if (!$init)
{
if ($inc_years != 0)
$dd = add_years($dd, $inc_years);
$_POST[$name] = $dd;
- }
- }
+ }
+ }
else
$_POST[$name] = $init;
}
function percent_row($label, $name, $init=null)
{
- if (!isset($_POST[$name]) || $_POST[$name]=="")
+ if (!isset($_POST[$name]) || $_POST[$name]=="")
{
if ($init)
$_POST[$name] = $init;
function supplier_list($name, $selected_id, $all_option=false, $submit_on_change=false)
{
- global $no_supplier_list, $all_items;
+ global $all_items;
if ($selected_id == null)
$selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
-
+ $no_supplier_list = get_company_pref('no_supplier_list');
if ($no_supplier_list)
{
global $search_button;
function customer_list($name, $selected_id, $all_option=false, $submit_on_change=false)
{
- global $no_customer_list, $all_items;
+ global $all_items;
if ($selected_id == null)
$selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
-
+ $no_customer_list = get_company_pref('no_customer_list');
if ($no_customer_list)
{
global $search_button;
function stock_items_list($name, $selected_id, $all_option=false, $submit_on_change=false, $extra="")
{
- global $all_items, $no_item_list;
+ global $all_items;
if ($selected_id == null)
$selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
-
+ $no_item_list = get_company_pref('no_item_list');
if ($no_item_list)
{
global $search_button;
function stock_purchasable_items_list($name, &$selected_id, $all_option=false, $submit_on_change=false, $extra="")
{
- global $no_item_list, $all_items;
+ global $all_items;
if ($selected_id == null)
$selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
-
+ $no_item_list = get_company_pref('no_item_list');
if ($no_item_list)
{
- global $search_button;
$edit_name = $name."_edit";
$edit_button = $name."_button";
$result = false;
}
- echo "<input type='text' name='$edit_name' size='8' maxlength='50' value='$val' onblur='this.form.$edit_button.click();'> ";
+ echo "<input type='text' name='$edit_name' size='8' maxlength='50' value='$val' > ";
- echo sprintf($search_button, $edit_button);
+ echo "<input type='submit' class='inputsubmit' name='$edit_button' value='?'> ";
}
else
{
//-------------------------------------------------------------------------------------------------------------
-function add_supp_invoice_item($supp_trans_type, $supp_trans_no, $stock_id, $description,
- $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_,
- $err_msg="")
+function add_supp_invoice_item($supp_trans_type, $supp_trans_no, $stock_id, $description,
+ $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_,
+ $err_msg="")
{
$sql = "INSERT INTO ".TB_PREF."supp_invoice_items (supp_trans_type, supp_trans_no, stock_id, description, gl_code, unit_price, unit_tax, quantity,
grn_item_id, po_detail_item_id, memo_) ";
- $sql .= "VALUES ($supp_trans_type, $supp_trans_no, '$stock_id', '$description', $gl_code, $unit_price, $unit_tax, $quantity,
+ $sql .= "VALUES ($supp_trans_type, $supp_trans_no, '$stock_id', '$description', '$gl_code', $unit_price, $unit_tax, $quantity,
$grn_item_id, $po_detail_item_id, '$memo_')";
-
+
if ($err_msg == "")
$err_msg = "Cannot insert a supplier transaction detail record";
-
- db_query($sql, $err_msg);
- return db_insert_id();
+ db_query($sql, $err_msg);
+
+ return db_insert_id();
}
//-------------------------------------------------------------------------------------------------------------
-function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $err_msg="")
+function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $err_msg="")
{
- return add_supp_invoice_item($supp_trans_type, $supp_trans_no, "", "", $gl_code, $amount,
- 0, 0, /*$grn_item_id*/0, /*$po_detail_item_id*/0, $memo_, $err_msg);
-}
+ return add_supp_invoice_item($supp_trans_type, $supp_trans_no, "", "", $gl_code, $amount,
+ 0, 0, /*$grn_item_id*/0, /*$po_detail_item_id*/0, $memo_, $err_msg);
+}
//----------------------------------------------------------------------------------------
function get_supp_invoice_items($supp_trans_type, $supp_trans_no)
{
- $sql = "SELECT *,unit_price+unit_tax AS FullUnitPrice FROM ".TB_PREF."supp_invoice_items
- WHERE supp_trans_type = $supp_trans_type
+ $sql = "SELECT *,unit_price+unit_tax AS FullUnitPrice FROM ".TB_PREF."supp_invoice_items
+ WHERE supp_trans_type = $supp_trans_type
AND supp_trans_no = $supp_trans_no ORDER BY id";
- return db_query($sql, "Cannot retreive supplier transaction detail records");
+ return db_query($sql, "Cannot retreive supplier transaction detail records");
}
//----------------------------------------------------------------------------------------
{
$sql = "UPDATE ".TB_PREF."supp_invoice_items SET quantity=0, unit_price=0
WHERE supp_trans_type = $type AND supp_trans_no=$type_no";
- db_query($sql, "could not void supptrans details");
+ db_query($sql, "could not void supptrans details");
}
//----------------------------------------------------------------------------------------
{
$sql = "INSERT INTO ".TB_PREF."supp_invoice_tax_items (supp_trans_type, supp_trans_no, tax_type_id, rate, included_in_price, amount)
VALUES ($supp_trans_type, $supp_trans_no, $tax_type_id, $rate, $included_in_price, $amount)";
-
- db_query($sql, "The supplier transaction tax detail could not be added");
+
+ db_query($sql, "The supplier transaction tax detail could not be added");
}
//----------------------------------------------------------------------------------------
function get_supp_invoice_tax_items($supp_trans_type, $supp_trans_no)
{
$sql = "SELECT ".TB_PREF."supp_invoice_tax_items.*, ".TB_PREF."tax_types.name AS tax_type_name
- FROM ".TB_PREF."supp_invoice_tax_items,".TB_PREF."tax_types
- WHERE supp_trans_type = $supp_trans_type
- AND supp_trans_no = $supp_trans_no
+ FROM ".TB_PREF."supp_invoice_tax_items,".TB_PREF."tax_types
+ WHERE supp_trans_type = $supp_trans_type
+ AND supp_trans_no = $supp_trans_no
AND ".TB_PREF."tax_types.id = ".TB_PREF."supp_invoice_tax_items.tax_type_id";
return db_query($sql, "The supplier transaction tax details could not be queried");
function void_supp_invoice_tax_items($type, $type_no)
{
$sql = "UPDATE ".TB_PREF."supp_invoice_tax_items SET amount=0
- WHERE supp_trans_type = $type
+ WHERE supp_trans_type = $type
AND supp_trans_no=$type_no";
-
+
db_query($sql, "The supplier transaction tax details could not be voided");
}
}
else
{
- global $no_item_list;
-
hidden('line_no', ($_SESSION['PO']->lines_on_order + 1));
+ $no_item_list = get_company_pref('no_item_list');
if ($no_item_list)
{
echo "<td colspan=2>\n";
//------------------------------------------------------------------------------------------------
-function clear_fields()
+function clear_fields()
{
unset($_POST['gl_code']);
unset($_POST['dimension_id']);
unset($_POST['amount']);
unset($_POST['memo_']);
unset($_POST['AcctSelection']);
- unset($_POST['AddGLCodeToTrans']);
+ unset($_POST['AddGLCodeToTrans']);
}
//------------------------------------------------------------------------------------------------
$_POST['gl_code'] = $_POST['AcctSelection'];
}
- $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code=" . $_POST['gl_code'];
+ $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
$result = db_query($sql,"get account information");
if (db_num_rows($result) == 0)
{
display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
$input_error = true;
- }
- else
+ }
+ else
{
$myrow = db_fetch_row($result);
$gl_act_name = $myrow[1];
if ($input_error == false)
{
- $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
+ $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
$_POST['dimension_id'], $_POST['dimension2_id'], $_POST['amount'], $_POST['memo_']);
clear_fields();
}
if (isset($_GET['Delete']))
{
$_SESSION['supp_trans']->remove_gl_codes_from_trans($_GET['Delete']);
- clear_fields();
+ clear_fields();
}
//------------------------------------------------------------------------------------------------
-display_heading($_SESSION['supp_trans']->supplier_name);
+display_heading($_SESSION['supp_trans']->supplier_name);
display_gl_items($_SESSION['supp_trans'], 1);
-
+
echo "<br>";
if ($_SESSION['supp_trans']->is_invoice == true)
{
hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Invoice Entry"));
-}
-else
+}
+else
{
- hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
+ hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
}
echo "<hr>";
//---------------------------------------------------------------------------------------------------------------
-if (isset($_GET['AddedID']))
+if (isset($_GET['AddedID']))
{
$credit_no = $_GET['AddedID'];
$trans_type = 11;
display_notification_centered(_("Credit Note has been processed"));
display_note(get_customer_trans_view_str($trans_type, $credit_no, _("View this credit note")), 0, 1);
-
+
display_note(get_gl_view_str($trans_type, $credit_no, _("View the GL Journal Entries for this Credit Note")));
hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Credit Note"), "NewCredit=yes");
$_POST['OrderDate'] = Today();
if (!is_date_in_fiscalyear($_POST['OrderDate']))
$_POST['OrderDate'] = end_fiscalyear();
- $_SESSION['credit_items']->orig_order_date = $_POST['OrderDate'];
-
+ $_SESSION['credit_items']->orig_order_date = $_POST['OrderDate'];
+
}
//-----------------------------------------------------------------------------------------------
$input_error = 0;
- if (!references::is_valid($_POST['ref']))
+ if (!references::is_valid($_POST['ref']))
{
display_error( _("You must enter a reference."));
$input_error = 1;
- }
- elseif (!is_new_reference($_POST['ref'], 11))
+ }
+ elseif (!is_new_reference($_POST['ref'], 11))
{
display_error( _("The entered reference is already in use."));
$input_error = 1;
- }
- elseif (!is_date($_POST['OrderDate']))
+ }
+ elseif (!is_date($_POST['OrderDate']))
{
display_error(_("The entered date for the credit note is invalid."));
$input_error = 1;
- }
- elseif (!is_date_in_fiscalyear($_POST['OrderDate']))
+ }
+ elseif (!is_date_in_fiscalyear($_POST['OrderDate']))
{
display_error(_("The entered date is not in fiscal year."));
$input_error = 1;
if (isset($_POST['ProcessCredit']))
{
//alert("WriteOffGLCode = ".$_POST['WriteOffGLCode'].", CreditType = ".$_POST['CreditType']);
- if ($_POST['CreditType'] == "WriteOff" && (!isset($_POST['WriteOffGLCode']) ||
+ if ($_POST['CreditType'] == "WriteOff" && (!isset($_POST['WriteOffGLCode']) ||
$_POST['WriteOffGLCode'] == ''))
{
display_note(_("For credit notes created to write off the stock, a general ledger account is required to be selected."), 1, 0);
{
if($_POST['UpdateItem'] != "" && check_item_data())
{
- $_SESSION['credit_items']->update_cart_item($_POST['stock_id'], $_POST['qty'],
+ $_SESSION['credit_items']->update_cart_item($_POST['line_no'], $_POST['qty'],
$_POST['price'], ($_POST['Disc'] / 100));
}
}
if (!check_item_data())
return;
- add_to_order($_SESSION['credit_items'], $_POST['stock_id'], $_POST['qty'],
+ add_to_order($_SESSION['credit_items'], $_POST['line_no'], $_POST['stock_id'], $_POST['qty'],
$_POST['price'], $_POST['Disc'] / 100);
}
if (isset($_GET['NewCredit']) || !isset($_SESSION['credit_items']))
{
handle_new_order();
-}
-else
+}
+else
{
if (!isset($_POST['customer_id']))
$_POST['customer_id'] = $_SESSION['credit_items']->customer_id;
credit_options_controls();
echo "</td></tr>";
end_table();
-}
+}
else
{
display_error($customer_error);
//---------------------------------------------------------------------------------------------------------------
-if (isset($_GET['AddedID']))
+if (isset($_GET['AddedID']))
{
$credit_no = $_GET['AddedID'];
$trans_type = 11;
echo "<center>";
display_notification_centered(_("Credit Note has been processed"));
display_note(get_customer_trans_view_str($trans_type, $credit_no, _("View this credit note")), 0, 0);
-
+
display_note(get_gl_view_str($trans_type, $credit_no, _("View the GL Journal Entries for this Credit Note")));
display_footer_exit();
//--------------------------------------------------------------------------------------
-if (!isset($_GET['InvoiceNumber']) && !$_SESSION['InvoiceToCredit'])
+if (!isset($_GET['InvoiceNumber']) && !$_SESSION['InvoiceToCredit'])
{
/* This page can only be called with an invoice number for crediting*/
die (_("This page can only be opened if an invoice has been selected for crediting."));
function can_process()
{
- if (!is_date($_POST['CreditDate']))
+ if (!is_date($_POST['CreditDate']))
{
display_error(_("The entered date is invalid."));;
return false;
- }
- elseif (!is_date_in_fiscalyear($_POST['CreditDate']))
+ }
+ elseif (!is_date_in_fiscalyear($_POST['CreditDate']))
{
display_error(_("The entered date is not in fiscal year."));
return false;
}
- if (!references::is_valid($_POST['ref']))
+ if (!references::is_valid($_POST['ref']))
{
display_error(_("You must enter a reference."));;
return false;
}
- if (!is_new_reference($_POST['ref'], 11))
+ if (!is_new_reference($_POST['ref'], 11))
{
display_error(_("The entered reference is already in use."));;
return false;
}
- if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0)
+ if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0)
{
display_error(_("The entered shipping cost is invalid or less than zero."));;
return false;
function clear_globals()
{
- if (isset($_SESSION['Items']))
+ if (isset($_SESSION['Items']))
{
unset($_SESSION['Items']->line_items);
unset($_SESSION['Items']);
if (can_process())
{
$credit_no = credit_invoice($_SESSION['Items'], $_SESSION['InvoiceToCredit'],
- $_SESSION['Order'], $_POST['CreditDate'], $_POST['CreditType'],
- $_POST['tax_group_id'], $_POST['ChargeFreightCost'], $_POST['ref'],
+ $_SESSION['Order'], $_POST['CreditDate'], $_POST['CreditType'],
+ $_POST['tax_group_id'], $_POST['ChargeFreightCost'], $_POST['ref'],
$_POST['CreditText'], $_POST['WriteOffGLCode']);
clear_globals();
//--------------------------------------------------------------------------------------
-if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
+if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
{
clear_globals();
$result = db_query($sql,"The invoice details cannot be retrieved");
- if (db_num_rows($result) == 1)
+ if (db_num_rows($result) == 1)
{
$myrow = db_fetch($result);
$result = get_customer_trans_details(10, $_GET['InvoiceNumber']);
- if (db_num_rows($result) > 0)
+ if (db_num_rows($result) > 0)
{
- while ($myrow = db_fetch($result))
+ while ($myrow = db_fetch($result))
{
- $_SESSION['Items']->add_to_cart($myrow["stock_id"],-$myrow["quantity"],
+ $_SESSION['Items']->add_to_cart($_SESSION['Items']->lines_on_order+1, $myrow["id"], $myrow["stock_id"],-$myrow["quantity"],
$myrow["FullUnitPrice"],$myrow["discount_percent"]);
- $_SESSION['Items']->line_items[$myrow["stock_id"]]->standard_cost = $myrow["standard_cost"];
+ $_SESSION['Items']->line_items[$_SESSION['Items']->lines_on_order]->standard_cost = $myrow["standard_cost"];
}
}*/ //end of checks on returned data set
db_free_result($result);
- }
- else
+ }
+ else
{
display_error(_("This invoice can not be credited using the automatic facility."));
display_error("Please report that a duplicate debtor_trans header record was found for invoice " . $SESSION['InvoiceToCredit']);
exit;
} //valid invoice record returned from the entered invoice number
-}
-else
+}
+else
{
/* if processing, the page has been called and ${$StkItm->stock_id} would have been set from the post */
- foreach ($_SESSION['Items']->line_items as $itm)
+ foreach ($_SESSION['Items']->line_items as $itm)
{
- $_SESSION['Items']->line_items[$itm->stock_id]->qty_dispatched = $_POST[$itm->stock_id];
+ $_SESSION['Items']->line_items[$itm->line_no]->qty_dispatched = $_POST[$itm->stock_id];
- if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
+ if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
{
- $_SESSION['Items']->line_items[$itm->stock_id]->item_description = $_POST[$itm->stock_id . "Desc"];
+ $_SESSION['Items']->line_items[$itm->line_no]->item_description = $_POST[$itm->stock_id . "Desc"];
}
}
}
label_cells(_("Currency"), $_SESSION['Items']->customer_currency, "class='tableheader2'");
end_row();
start_row();
-
+
if (!isset($_POST['ref']))
$_POST['ref'] = references::get_next(11);
if (!isset($_POST['tax_group_id']))
$_POST['tax_group_id'] = $_SESSION['Items']->tax_group_id;
- label_cell(_("Tax Group"), "class='tableheader2'");
+ label_cell(_("Tax Group"), "class='tableheader2'");
tax_groups_list_cells(null, 'tax_group_id', $_POST['tax_group_id'], false, null, true);
end_row();
end_table();
end_table();
echo "</td></tr>";
-
+
end_table(1); // outer table
start_table("$table_style width=80%");
$th = array(_("Item Code"), _("Item Description"), _("Invoiced Quantity"), _("Units"),
_("Credit Quantity"), _("Price"), _("Discount %"), _("Total"));
- table_header($th);
+ table_header($th);
$k = 0; //row colour counter
- foreach ($_SESSION['Items']->line_items as $ln_itm)
+ foreach ($_SESSION['Items']->line_items as $ln_itm)
{
alt_table_row_color($k);
function display_credit_options()
{
global $table_style2;
-
+
echo "<br>";
start_table($table_style2);
{
echo "<option value='WriteOff'>" . _("Items Written Off") . "</option>";
echo "<option selected value='Return'>" . _("Items Returned to Inventory Location") . "</option>";
- }
- else
+ }
+ else
{
echo "<option selected value='WriteOff'>" . _("Items Written Off") . "</option>";
echo "<option value='Return'>" . _("Items Returned to Inventory Location") . "</option>";
locations_list_row(_("Items Returned to Inventory Location"), 'Location', $_POST['Location']);
- }
- else
+ }
+ else
{ /* the goods are to be written off to somewhere */
gl_all_accounts_list_row(_("Write Off the Cost of the Items to"), 'WriteOffGLCode', $_POST['WriteOffGLCode']);
$js .= get_js_open_window(900, 500);
if ($use_date_picker)
$js .= get_js_date_picker();
-page(_("Issue an Invoice and Deliver Items for a Sales Order"), false, false, "", $js);
+if ($_SESSION['Items']->direct_invoice)
+ page(_("Issue an Invoice"), false, false, "", $js);
+else
+ page(_("Issue an Invoice and Deliver Items for a Sales Order"), false, false, "", $js);
//---------------------------------------------------------------------------------------------------------------
-if (isset($_GET['AddedID']))
+if (isset($_GET['AddedID']))
{
$invoice_no = $_GET['AddedID'];
$trans_type = 10;
//---------------------------------------------------------------------------------------------------------------
-if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) &&
- !isset($_GET['process_invoice']))
+if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) &&
+ !isset($_GET['process_invoice']))
{
/* This page can only be called with an order number for invoicing*/
display_error(_("This page can only be opened if an order has been selected. Please select an order first."));
end_page();
exit;
-}
-elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0)
+}
+elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0)
{
if (isset($_SESSION['Items']))
/*read in all the selected order into the Items cart */
- if (read_sales_order($_SESSION['ProcessingOrder'], $_SESSION['Items'], true))
+ if (read_sales_order($_SESSION['ProcessingOrder'], $_SESSION['Items'], true))
{
- if ($_SESSION['Items']->count_items() == 0)
+ if ($_SESSION['Items']->count_items() == 0)
{
hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", _("Select a different sales order to invoice"), "OutstandingOnly=1");
die ("<br><b>" . _("There are no ordered items with a quantity left to deliver. There is nothing left to invoice.") . "</b>");
}
- }
- else
+ }
+ else
{
hyperlink_no_params("/sales_orders_view.php", _("Select a sales order to invoice"));
die ("<br><b>" . _("This order item could not be retrieved. Please select another order.") . "</b>");
}
-}
-else
+}
+else
{
/* if processing, a dispatch page has been called and ${$StkItm->stock_id} would have been set from the post */
- foreach ($_SESSION['Items']->line_items as $itm)
+ foreach ($_SESSION['Items']->line_items as $itm)
{
- if (isset($_SESSION['Items']->line_items[$itm->stock_id]) &&
- isset($_POST[$itm->stock_id]) && is_numeric($_POST[$itm->stock_id]) &&
- $_POST[$itm->stock_id] <= ($_SESSION['Items']->line_items[$itm->stock_id]->quantity -
- $_SESSION['Items']->line_items[$itm->stock_id]->qty_inv))
+ if (isset($_POST[$itm->stock_id]) && is_numeric($_POST[$itm->stock_id]) &&
+ $_POST[$itm->stock_id] <= ($_SESSION['Items']->line_items[$itm->line_no]->quantity -
+ $_SESSION['Items']->line_items[$itm->line_no]->qty_inv))
{
- $_SESSION['Items']->line_items[$itm->stock_id]->qty_dispatched = $_POST[$itm->stock_id];
+ $_SESSION['Items']->line_items[$itm->line_no]->qty_dispatched = $_POST[$itm->stock_id];
}
- if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
+ if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
{
- $_SESSION['Items']->line_items[$itm->stock_id]->item_description = $_POST[$itm->stock_id . "Desc"];
+ $_SESSION['Items']->line_items[$itm->line_no]->item_description = $_POST[$itm->stock_id . "Desc"];
}
}
}
return false;
}
- while ($myrow = db_fetch($result))
+ while ($myrow = db_fetch($result))
{
- $stk_itm = $myrow["stk_code"];
- if ($_SESSION['Items']->line_items[$stk_itm]->quantity != $myrow["quantity"] ||
- $_SESSION['Items']->line_items[$stk_itm]->qty_inv != $myrow["qty_invoiced"])
+ foreach($_SESSION['Items']->line_items as $line)
{
- display_note(_("Original order for") . " " . $myrow["stk_code"] . " " .
- _("has a quantity of") . " " . $myrow["quantity"] . " " .
- _("and an invoiced quantity of") . " " . $myrow["qty_invoiced"] . " " .
- _("the session shows quantity of") . " " .
- $_SESSION['Items']->line_items[$stk_itm]->quantity . " " .
- _("and quantity invoice of") . " " .
- $_SESSION['Items']->line_items[$stk_itm]->qty_inv, 1, 0);
-
- return false;
+ if ($line->stock_id == $myrow["stk_code"])
+ {
+ if ($line->quantity != $myrow["quantity"] ||
+ $line->qty_inv != $myrow["qty_invoiced"])
+ {
+ display_note(_("Original order for") . " " . $myrow["stk_code"] . " " .
+ _("has a quantity of") . " " . $myrow["quantity"] . " " .
+ _("and an invoiced quantity of") . " " . $myrow["qty_invoiced"] . " " .
+ _("the session shows quantity of") . " " .
+ $line->quantity . " " .
+ _("and quantity invoice of") . " " .
+ $line->qty_inv, 1, 0);
+
+ return false;
+ }
+ }
}
} /*loop through all line items of the order to ensure none have been invoiced */
function check_data()
{
- if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate']))
+ if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate']))
{
display_error(_("The entered invoice date is invalid."));
return false;
}
- if (!is_date_in_fiscalyear($_POST['DispatchDate']))
+ if (!is_date_in_fiscalyear($_POST['DispatchDate']))
{
display_error(_("The entered invoice date is not in fiscal year."));
return false;
}
- if (!isset($_POST['due_date']) || !is_date($_POST['due_date']))
+ if (!isset($_POST['due_date']) || !is_date($_POST['due_date']))
{
display_error(_("The entered invoice due date is invalid."));
return false;
}
- if (!references::is_valid($_POST['ref']))
+ if (!references::is_valid($_POST['ref']))
{
display_error(_("You must enter a reference."));
return false;
}
- if (!is_new_reference($_POST['ref'], 10))
+ if (!is_new_reference($_POST['ref'], 10))
{
display_error(_("The entered reference is already in use."));
return false;
}
if ($_POST['ChargeFreightCost'] == "")
$_POST['ChargeFreightCost'] = 0;
- if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0)
+ if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0)
{
display_error(_("The entered shipping value is not numeric."));
return false;
}
- if ($_SESSION['Items']->has_items_dispatch() == 0 && $_POST['ChargeFreightCost'] == 0)
+ if ($_SESSION['Items']->has_items_dispatch() == 0 && $_POST['ChargeFreightCost'] == 0)
{
display_error(_("There are no item quantities on this invoice."));
return false;
{
if (!sys_prefs::allow_negative_stock())
{
- foreach ($_SESSION['Items']->line_items as $itm)
+ foreach ($_SESSION['Items']->line_items as $itm)
{
if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag))
{
$qoh = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
- if ($itm->qty_dispatched > $qoh)
+ if ($itm->qty_dispatched > $qoh)
{
display_error(_("The invoice cannot be processed because there is an insufficient quantity for component:") .
" " . $itm->stock_id . " - " . $itm->item_description);
function process_invoice($invoicing=false)
{
- if ($invoicing)
+ if ($invoicing)
{
+
read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items'], true);
$duedate = get_invoice_duedate($_SESSION['Items']->customer_id, $_SESSION['Items']->delivery_date);
$invoice_no = add_sales_invoice($_SESSION['Items'],
$_SESSION['Items']->Location, $_SESSION['Items']->ship_via,
$_SESSION['Items']->default_sales_type, references::get_next(10),
$_SESSION['Items']->memo_, 0);
- }
- else
+ }
+ else
{
-
+
if (!check_data())
return;
if (!isset($_POST['tax_group_id']))
$_POST['tax_group_id'] = $_SESSION['Items']->tax_group_id;
-label_cell(_("Tax Group"), "class='tableheader2'");
+label_cell(_("Tax Group"), "class='tableheader2'");
tax_groups_list_cells(null, 'tax_group_id', $_POST['tax_group_id'], false, null, true);
label_cells(_("For Sales Order"), get_customer_trans_view_str(systypes::sales_order(), $_SESSION['ProcessingOrder']), "class='tableheader2'");
if (!isset($_POST['sales_type_id']))
$_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type;
-label_cell(_("Sales Type"), "class='tableheader2'");
+label_cell(_("Sales Type"), "class='tableheader2'");
sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']);
if (!isset($_POST['Location']))
$_POST['Location'] = $_SESSION['Items']->Location;
-label_cell(_("Delivery From"), "class='tableheader2'");
+label_cell(_("Delivery From"), "class='tableheader2'");
locations_list_cells(null, 'Location', $_POST['Location'], false, true);
if (!isset($_POST['ship_via']))
$_POST['ship_via'] = $_SESSION['Items']->ship_via;
-label_cell(_("Shipping Company"), "class='tableheader2'");
+label_cell(_("Shipping Company"), "class='tableheader2'");
shippers_list_cells(null, 'ship_via', $_POST['ship_via']);
end_row();
$has_marked = false;
$show_qoh = true;
-foreach ($_SESSION['Items']->line_items as $ln_itm)
+foreach ($_SESSION['Items']->line_items as $ln_itm)
{
// if it's a non-stock item (eg. service) don't show qoh
if ($show_qoh)
$qoh = get_qoh_on_date($ln_itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
- if ($show_qoh && ($ln_itm->qty_dispatched > $qoh))
+ if ($show_qoh && ($ln_itm->qty_dispatched > $qoh))
{
// oops, we don't have enough of one of the component items
start_row("class='stockmankobg'");
$has_marked = true;
- }
+ }
else
alt_table_row_color($k);
It seems unfair to charge the customer twice for freight if the order
was not fully delivered the first time ?? */
-if (!isset($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] == "")
+if (!isset($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] == "")
{
- if ($_SESSION['Items']->any_already_delivered() == 1)
+ if ($_SESSION['Items']->any_already_delivered() == 1)
{
$_POST['ChargeFreightCost'] = 0;
- }
- else
+ }
+ else
{
$_POST['ChargeFreightCost'] = $_SESSION['Items']->freight_cost;
}
include_once($path_to_root . "/inventory/includes/inventory_db.inc");
include_once($path_to_root . "/taxes/tax_calc.inc");
-class cart
+class cart
{
var $line_items; /*array of objects of class line_details using the product id as the pointer */
var $default_discount; // set to the customer's discount %
var $direct_invoice; // direct invoicing
var $memo_; // memo_ on direct invoicing
-
+
var $deliver_to;
var $delivery_address;
var $phone;
-
+
var $email;
var $cust_ref;
var $Comments;
var $Location;
var $location_name;
-
- var $order_no; // the order number
+
+ var $order_no; // the order number
var $customer_name;
var $customer_id;
var $Branch;
-
+
var $orig_order_date;
-
+
var $ship_via;
var $freight_cost;
-
+
var $tax_group_id;
var $tax_group_name;
+ var $lines_on_order;
+
function Cart()
{
/*Constructor function initialises a new shopping cart */
$this->line_items = array();
$this->default_sales_type = "";
$this->direct_invoice=false;
+ $this->lines_on_order = 0;
}
- function add_to_cart($stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null)
+ function add_to_cart($line_no, $id, $stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null)
{
if (isset($stock_id) && $stock_id != "" && isset($qty) && $qty > 0)
{
- $this->line_items[$stock_id] = new line_details($stock_id, $qty, $price, $disc,
+ $this->line_items[$line_no] = new line_details($line_no, $id, $stock_id, $qty, $price, $disc,
$qty_invoiced, $standard_cost, $description);
+ $this->lines_on_order++;
return 1;
- }
- else
+ }
+ else
{
// shouldn't come here under normal circumstances
display_db_error("unexpected - adding an invalid item or null quantity", "", true);
return 0;
}
- function find_cart_item($stock_id)
- {
- if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null)
- return $this->line_items[$stock_id];
- return null;
- }
-
- function update_cart_item($update_item, $qty, $price, $disc)
+ function update_cart_item($line_no, $qty, $price, $disc)
{
if ($qty > 0)
{
- $this->line_items[$update_item]->quantity = $qty;
+ $this->line_items[$line_no]->quantity = $qty;
}
- $this->line_items[$update_item]->price = $price;
- $this->line_items[$update_item]->discount_percent = $disc;
+ $this->line_items[$line_no]->price = $price;
+ $this->line_items[$line_no]->discount_percent = $disc;
}
-
- function update_add_cart_item_qty($update_item, $qty)
+
+ function update_add_cart_item_qty($line_no, $qty)
{
- $this->line_items[$update_item]->quantity += $qty;
- }
+ $this->line_items[$line_no]->quantity += $qty;
+ }
- function remove_from_cart(&$stock_id)
+ function remove_from_cart($line_no)
{
- if (isset($stock_id))
- {
- unset($this->line_items[$stock_id]);
- }
+ $this->line_items[$line_no]->Deleted = true;
}
-
- function clear_items()
+
+ function clear_items()
{
unset($this->line_items);
$this->line_items = array();
$this->default_sales_type = "";
$this->customer_id = $this->order_no = 0;
+ $this->lines_on_order = 0;
}
-
- function count_items()
+
+ function count_items()
{
return count($this->line_items);
}
-
+
function get_items_total_dispatch($tax_group_id=null)
{
$total = 0;
-
+
// preload the taxgroup !
if ($tax_group_id != null)
$tax_group_array = get_tax_group_items_as_array($tax_group_id);
- else
+ else
$tax_group_array = null;
-
- foreach ($this->line_items as $ln_itm)
+
+ foreach ($this->line_items as $ln_itm)
{
- $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
- }
+ $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
+ }
return $total;
}
-
+
function has_items_dispatch()
{
- foreach ($this->line_items as $ln_itm)
+ foreach ($this->line_items as $ln_itm)
{
if ($ln_itm->qty_dispatched > 0)
- return true;
- }
+ return true;
+ }
return false;
}
-
+
function get_items_total($tax_group_id=null)
{
$total = 0;
-
+
// preload the taxgroup !
if ($tax_group_id != null)
$tax_group_array = get_tax_group_items_as_array($tax_group_id);
- else
- $tax_group_array = null;
-
+ else
+ $tax_group_array = null;
+
foreach ($this->line_items as $ln_itm) {
- $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
- }
+ $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
+ }
return $total;
- }
+ }
function any_already_delivered()
{
/* Checks if there have been deliveries of line items */
- foreach ($this->line_items as $stock_item)
+ foreach ($this->line_items as $stock_item)
{
if ($stock_item->qty_inv !=0)
{
}
- function some_already_delivered($stock_id)
+ function some_already_delivered($line_no)
{
/* Checks if there have been deliveries of a specific line item */
- if (isset($stock_id) && isset($this->line_items[$stock_id]) &&
- $this->line_items[$stock_id]->qty_inv != 0)
+ if (isset($this->line_items[$line_no]) &&
+ $this->line_items[$line_no]->qty_inv != 0)
{
return 1;
}
return 0;
}
-
+
function get_taxes($tax_group_id=null, $shipping_cost=0)
{
$items = array();
$prices = array();
-
+
if ($tax_group_id == null)
$tax_group_id = $this->tax_group_id;
-
+
// preload the taxgroup !
$tax_group_array = get_tax_group_items_as_array($tax_group_id);
-
- foreach ($this->line_items as $ln_itm)
+
+ foreach ($this->line_items as $ln_itm)
{
- $items[] = $ln_itm->stock_id;
- $prices[] = ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
+ if (!$ln_itm->Deleted)
+ {
+ $items[] = $ln_itm->stock_id;
+ $prices[] = ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
+ }
}
-
+
$taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id, $tax_group_array);
-
+
return $taxes;
- }
-
+ }
+
} /* end of class defintion */
-class line_details
+class line_details
{
+ var $line_no;
+ var $id;
var $stock_id;
var $item_description;
var $units;
var $mb_flag;
var $tax_type;
var $tax_type_name;
-
+
var $quantity;
var $price;
var $discount_percent;
var $qty_inv;
var $qty_dispatched;
var $standard_cost;
+ var $Deleted;
- function line_details ($stock_id, $qty, $prc, $disc_percent,
+ function line_details ($line_no, $id, $stock_id, $qty, $prc, $disc_percent,
$qty_invoiced, $standard_cost, $description)
{
/* Constructor function to add a new LineDetail object with passed params */
+
+ $this->line_no = $line_no;
+ $this->id = $id;
$item_row = get_item($stock_id);
-
+
if ($item_row == null)
display_db_error("invalid item added to order : $stock_id", "");
-
+
$this->mb_flag = $item_row["mb_flag"];
$this->units = $item_row["units"];
if ($description == null)
$this->item_description = $item_row["description"];
else
$this->item_description = $description;
- //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"];
+ //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"];
$this->tax_type = $item_row["tax_type_id"];
$this->tax_type_name = $item_row["tax_type_name"];
$this->qty_inv = $qty_invoiced;
$this->qty_dispatched = $qty - $qty_invoiced;
$this->standard_cost = $standard_cost;
+ $this->Deleted = false;
}
-
+
function full_price()
{
return $this->price;
}
-
+
function taxfree_price($tax_group_id, $tax_group_array=null)
{
if ($tax_group_id==null)
//----------------------------------------------------------------------------------------
-function add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity,
+function add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity,
$unit_price, $unit_tax, $discount_percent, $standard_cost)
{
$sql = "INSERT INTO ".TB_PREF."debtor_trans_details (debtor_trans_no, debtor_trans_type, stock_id, description, quantity, unit_price, unit_tax, discount_percent, standard_cost)
VALUES ($debtor_trans_no, $debtor_trans_type, '$stock_id', '$description', $quantity, $unit_price, $unit_tax, $discount_percent, $standard_cost)";
-
- db_query($sql, "The debtor transaction detail could not be added");
+
+ db_query($sql, "The debtor transaction detail could not be added");
}
//----------------------------------------------------------------------------------------
function get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
{
- $sql = "SELECT ".TB_PREF."debtor_trans_details.*, ".TB_PREF."debtor_trans_details.unit_price+".TB_PREF."debtor_trans_details.unit_tax AS FullUnitPrice,
+ $sql = "SELECT ".TB_PREF."debtor_trans_details.*, ".TB_PREF."debtor_trans_details.unit_price+".TB_PREF."debtor_trans_details.unit_tax AS FullUnitPrice,
".TB_PREF."debtor_trans_details.description As StockDescription,
- ".TB_PREF."stock_master.units
- FROM ".TB_PREF."debtor_trans_details,".TB_PREF."stock_master
+ ".TB_PREF."stock_master.units
+ FROM ".TB_PREF."debtor_trans_details,".TB_PREF."stock_master
WHERE debtor_trans_no=$debtor_trans_no
- AND debtor_trans_type=$debtor_trans_type
- AND ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id";
+ AND debtor_trans_type=$debtor_trans_type
+ AND ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id
+ ORDER BY id";
return db_query($sql, "The debtor transaction detail could not be queried");
}
function void_customer_trans_details($type, $type_no)
{
- $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0,
+ $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0,
unit_tax=0, discount_percent=0, standard_cost=0
WHERE debtor_trans_no=$type_no
AND debtor_trans_type=$type";
-
+
db_query($sql, "The debtor transaction details could not be voided");
-
+
// clear the stock move items
- void_stock_move($type, $type_no);
+ void_stock_move($type, $type_no);
}
//----------------------------------------------------------------------------------------
function add_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
- $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
+ $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
$reference, $std_cost)
{
- add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
+ add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
$quantity, $unit_price, $unit_tax, $discount_percent, $std_cost);
-
+
add_stock_move_customer($debtor_trans_type, $stock_id, $debtor_trans_no, $Location,
$date_, $reference, $quantity, $std_cost, 1, $unit_price+$unit_tax, $discount_percent);
-
+
return $std_cost;
}
//----------------------------------------------------------------------------------------
function add_customer_trans_detail_item_writeoff($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
- $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
+ $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
$reference, $std_cost)
{
$retCost = add_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
- $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
+ $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
$reference, $std_cost);
-
+
$reference = _("Write off") . " " . $reference;
add_stock_move_customer($debtor_trans_type, $stock_id, $debtor_trans_no, $Location,
$date_, $reference, -$quantity, $std_cost, 0, $unit_price+$unit_tax, $discount_percent);
-
- return $retCost;
-}
+
+ return $retCost;
+}
//----------------------------------------------------------------------------------------
-function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no,
+function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no,
$tax_type_id, $rate, $included_in_price, $amount)
{
$sql = "INSERT INTO ".TB_PREF."debtor_trans_tax_details (debtor_trans_no, debtor_trans_type, tax_type_id, rate, included_in_price, amount)
VALUES ($debtor_trans_no, $debtor_trans_type, $tax_type_id, $rate, $included_in_price, $amount)";
-
- db_query($sql, "The debtor transaction tax detail could not be added");
+
+ db_query($sql, "The debtor transaction tax detail could not be added");
}
//----------------------------------------------------------------------------------------
function get_customer_trans_tax_details($debtor_trans_type, $debtor_trans_no)
{
$sql = "SELECT ".TB_PREF."debtor_trans_tax_details.*, ".TB_PREF."tax_types.name AS tax_type_name
- FROM ".TB_PREF."debtor_trans_tax_details,".TB_PREF."tax_types
+ FROM ".TB_PREF."debtor_trans_tax_details,".TB_PREF."tax_types
WHERE debtor_trans_no=$debtor_trans_no
- AND debtor_trans_type=$debtor_trans_type
+ AND debtor_trans_type=$debtor_trans_type
AND ".TB_PREF."tax_types.id = ".TB_PREF."debtor_trans_tax_details.tax_type_id";
return db_query($sql, "The debtor transaction tax details could not be queried");
$sql = "UPDATE ".TB_PREF."debtor_trans_tax_details SET amount=0
WHERE debtor_trans_no=$type_no
AND debtor_trans_type=$type";
-
+
db_query($sql, "The debtor transaction tax details could not be voided");
}
//----------------------------------------------------------------------------------------
-function add_credit_note($credit_items, $credit_date, $credit_type, $tax_group_id,
+function add_credit_note($credit_items, $credit_date, $credit_type, $tax_group_id,
$charge_freight, $sales_type, $shipper, $reference, $memo_, $write_off_gl_code)
{
begin_transaction();
-
+
$branch_data = get_branch_accounts($credit_items->Branch);
$credit_items_total = $credit_items->get_items_total($tax_group_id);
-
+
$tax_total = 0;
$taxes = $credit_items->get_taxes($tax_group_id, $charge_freight);
foreach ($taxes as $taxitem)
- $tax_total += $taxitem['Value'];
-
- $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch,
- $credit_date, $reference, -($credit_items_total), 0, -$tax_total, -$charge_freight,
- $sales_type, 0, $credit_items->ship_via);
+ $tax_total += $taxitem['Value'];
+
+ $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch,
+ $credit_date, $reference, -($credit_items_total), 0, -$tax_total, -$charge_freight,
+ $sales_type, 0, $credit_items->ship_via);
- foreach ($credit_items->line_items as $credit_line)
+ foreach ($credit_items->line_items as $credit_line)
{
if ($credit_line->quantity > 0)
// the functions use qty_dispatched - so until that's fixed make sure it's set
// or KABOOOOM
$credit_line->qty_dispatched = $credit_line->quantity;
-
- add_gl_trans_credit_order_item($credit_items, $credit_line, $credit_no, $credit_date,
+
+ add_gl_trans_credit_order_item($credit_items, $credit_line, $credit_no, $credit_date,
$tax_group_id, $credit_type);
- add_gl_trans_credit_costs($credit_items, $credit_line, $credit_no, $credit_date,
+ add_gl_trans_credit_costs($credit_items, $credit_line, $credit_no, $credit_date,
$tax_group_id, $credit_type, $write_off_gl_code, $branch_data);
} /*quantity credited is more than 0 */
} /*end of credit_line loop */
-
- /*Post credit note transaction to GL credit debtors,
+
+ /*Post credit note transaction to GL credit debtors,
debit freight re-charged and debit sales */
-
+
add_g_trans_credit_common($credit_items, $credit_no, $credit_date,
- $credit_items_total, $charge_freight, $taxes, $tax_total, $branch_data);
-
- add_comments(11, $credit_no, $credit_date, $memo_);
-
- add_forms_for_sys_type(11, $credit_no, $credit_items->Location);
-
- references::save_last($reference, 11);
-
- commit_transaction();
-
+ $credit_items_total, $charge_freight, $taxes, $tax_total, $branch_data);
+
+ add_comments(11, $credit_no, $credit_date, $memo_);
+
+ add_forms_for_sys_type(11, $credit_no, $credit_items->Location);
+
+ references::save_last($reference, 11);
+
+ commit_transaction();
+
return $credit_no;
}
//----------------------------------------------------------------------------------------
-function credit_invoice($credit_items, $invoice_no, $order_no,
- $default_dispatch_date, $credit_type, $tax_group_id,
+function credit_invoice($credit_items, $invoice_no, $order_no,
+ $default_dispatch_date, $credit_type, $tax_group_id,
$charge_freight, $reference, $memo_, $write_off_gl_code)
{
begin_transaction();
-
- $branch_data = get_branch_accounts($credit_items->Branch);
-
+
+ $branch_data = get_branch_accounts($credit_items->Branch);
+
$invoice_alloc_balance = get_DebtorTrans_allocation_balance(10, $invoice_no);
$invoice_items_total = $credit_items->get_items_total_dispatch($tax_group_id);
-
+
$tax_total = 0;
$taxes = $credit_items->get_taxes($tax_group_id, $charge_freight);
foreach ($taxes as $taxitem)
$tax_total += $taxitem['Value'];
-
- $allocate_amount = 0;
-
+
+ $allocate_amount = 0;
+
if ($invoice_alloc_balance > 0)
{ /*the invoice is not already fully allocated */
{
$allocate_amount = $invoice_items_total + $charge_freight + $tax_total;
- }
- else
+ }
+ else
{ /*the balance left to allocate is less than the credit note value */
$allocate_amount = $invoice_alloc_balance;
}
/*Now insert the Credit Note into the debtor_trans table with the allocations as calculated above*/
// all amounts in debtor's currency
-
- $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch,
- $default_dispatch_date, $reference, -($invoice_items_total), 0, -$tax_total,
- -$charge_freight, $credit_items->default_sales_type, $order_no,
+
+ $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch,
+ $default_dispatch_date, $reference, -($invoice_items_total), 0, -$tax_total,
+ -$charge_freight, $credit_items->default_sales_type, $order_no,
$credit_items->ship_via, "", $allocate_amount);
-
+
/*Now insert the allocation record if > 0 */
if ($allocate_amount != 0)
{
add_cust_allocation($allocate_amount, 11, $credit_no, 10, $invoice_no);
}
-
+
/* Update sales order details quantity invoiced less this credit quantity. */
- foreach ($credit_items->line_items as $order_line)
+ foreach ($credit_items->line_items as $order_line)
{
if ($order_line->qty_dispatched >0)
{
-
+
// always deduct the credited/returned quantities from the sales order
- dispatch_sales_order_item($order_no, $order_line->stock_id, -$order_line->qty_dispatched);
-
+ dispatch_sales_order_item($order_no, $order_line->id, -$order_line->qty_dispatched);
+
//if (($_POST['credit_type']=="Return") OR ($_POST['ItemsAction']==1))
/*{
- $sql = "UPDATE ".TB_PREF."sales_order_details
+ $sql = "UPDATE ".TB_PREF."sales_order_details
SET qty_invoiced = qty_invoiced - " . $order_line->qty_dispatched . "
- WHERE order_no = " . $order_no . "
- AND stk_code = '" . $order_line->stock_id . "'";
+ WHERE order_no = " . $order_no . "
+ AND id = '" . $order_line->id . "'";
$result = db_query($sql,"The sales order detail record could not be updated for the reduced quantity invoiced");
- }*/
-
+ }*/
+
/*Now update sales_order_details for the quantity invoiced and the actual dispatch dates. */
-
- add_gl_trans_credit_order_item($credit_items, $order_line, $credit_no,
+
+ add_gl_trans_credit_order_item($credit_items, $order_line, $credit_no,
$default_dispatch_date, $tax_group_id, $credit_type, $invoice_no);
-
- add_gl_trans_credit_costs($credit_items, $order_line, $credit_no, $default_dispatch_date,
+
+ add_gl_trans_credit_costs($credit_items, $order_line, $credit_no, $default_dispatch_date,
$tax_group_id, $credit_type, $write_off_gl_code, $branch_data);
} /*quantity dispatched is more than 0 */
} /*end of order_line loop */
-
+
add_g_trans_credit_common($credit_items, $credit_no, $default_dispatch_date,
$invoice_items_total, $charge_freight, $taxes, $tax_total, $branch_data);
-
- add_comments(11, $credit_no, $default_dispatch_date, $memo_);
-
+
+ add_comments(11, $credit_no, $default_dispatch_date, $memo_);
+
add_forms_for_sys_type(11, $credit_no);
-
- references::save_last($reference, 11);
+
+ references::save_last($reference, 11);
commit_transaction();
-
+
return $credit_no;
}
//----------------------------------------------------------------------------------------
-function add_gl_trans_credit_order_item(&$order, &$order_line, $credit_no, $date_, $tax_group_id,
+function add_gl_trans_credit_order_item(&$order, &$order_line, $credit_no, $date_, $tax_group_id,
$credit_type, $credited_invoice=0)
{
$line_taxfree_price = $order_line->taxfree_price($tax_group_id);
$line_tax = $order_line->full_price() - $line_taxfree_price;
-
+
if ($credit_type == "Return")
{
/* Insert stock movements for the stock coming back in - with unit cost */
-
+
$reference = "";
if ($credited_invoice)
$reference .= "Ex Inv: " . $credited_invoice;
-
- add_customer_trans_detail_item(11, $credit_no, $order_line->stock_id,
- $order_line->item_description, $order->Location, $date_,
+
+ add_customer_trans_detail_item(11, $credit_no, $order_line->stock_id,
+ $order_line->item_description, $order->Location, $date_,
$order_line->qty_dispatched, $line_taxfree_price, $line_tax,
- $order_line->discount_percent, $reference, $order_line->standard_cost);
+ $order_line->discount_percent, $reference, $order_line->standard_cost);
- }
- elseif ($credit_type == "WriteOff")
+ }
+ elseif ($credit_type == "WriteOff")
{
/*Insert a stock movement coming back in to show the credit note and
a reversing stock movement to show the write off
no mods to location stock records*/
-
+
$reference = "";
if ($credited_invoice)
$reference .= "Ex Inv: " . $credited_invoice;
-
+
add_customer_trans_detail_item_writeoff(11, $credit_no, $order_line->stock_id,
- $order_line->item_description, $order->Location, $date_,
+ $order_line->item_description, $order->Location, $date_,
$order_line->qty_dispatched, $line_taxfree_price, $line_tax,
- $order_line->discount_percent, $reference, $order_line->standard_cost);
- }
+ $order_line->discount_percent, $reference, $order_line->standard_cost);
+ }
}
//----------------------------------------------------------------------------------------
-function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, $tax_group_id,
+function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, $tax_group_id,
$credit_type, $write_off_gl_code, &$branch_data)
{
- $stock_gl_codes = get_stock_gl_code($order_line->stock_id);
-
+ $stock_gl_codes = get_stock_gl_code($order_line->stock_id);
+
/* insert gl_trans to credit stock and debit cost of sales at standard cost*/
if ($order_line->standard_cost != 0)
{
/*first the cost of sales entry*/
- add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
- $stock_gl_codes["dimension_id"], $stock_gl_codes["dimension2_id"], "",
- -($order_line->standard_cost * $order_line->qty_dispatched),
- payment_person_types::customer(), $order->customer_id,
- "The cost of sales GL posting could not be inserted");
-
+ add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
+ $stock_gl_codes["dimension_id"], $stock_gl_codes["dimension2_id"], "",
+ -($order_line->standard_cost * $order_line->qty_dispatched),
+ payment_person_types::customer(), $order->customer_id,
+ "The cost of sales GL posting could not be inserted");
+
/*now the stock entry*/
if ($credit_type == "WriteOff")
{
$stock_entry_account = $write_off_gl_code;
- }
- else
+ }
+ else
{
- $stock_gl_code = get_stock_gl_code($order_line->stock_id);
+ $stock_gl_code = get_stock_gl_code($order_line->stock_id);
$stock_entry_account = $stock_gl_code["inventory_account"];
}
-
+
add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
- "", ($order_line->standard_cost * $order_line->qty_dispatched),
- payment_person_types::customer(), $order->customer_id,
+ "", ($order_line->standard_cost * $order_line->qty_dispatched),
+ payment_person_types::customer(), $order->customer_id,
"The stock side (or write off) of the cost of sales GL posting could not be inserted");
-
- } /* end of if GL and stock integrated and standard cost !=0 */
-
+
+ } /* end of if GL and stock integrated and standard cost !=0 */
+
if ($order_line->price != 0)
{
-
+
$line_taxfree_price = $order_line->taxfree_price($tax_group_id);
- $line_tax = $order_line->full_price() - $line_taxfree_price;
+ $line_tax = $order_line->full_price() - $line_taxfree_price;
//Post sales transaction to GL credit sales
-
+
add_gl_trans_customer(11, $credit_no, $date_, $stock_gl_codes["sales_account"], 0, 0,
- ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id,
+ ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id,
"The credit note GL posting could not be inserted");
if ($order_line->discount_percent != 0)
{
-
+
add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"], 0, 0,
- -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
- $order->customer_id,
- "The credit note discount GL posting could not be inserted");
+ -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
+ $order->customer_id,
+ "The credit note discount GL posting could not be inserted");
} /*end of if discount !=0 */
- } /*end of if sales integrated with debtors */
+ } /*end of if sales integrated with debtors */
}
//----------------------------------------------------------------------------------------
-function add_g_trans_credit_common($order, $credit_no, $date_,
+function add_g_trans_credit_common($order, $credit_no, $date_,
$credit_items_total, $freight, $taxes, $tax_total, &$branch_data)
{
$company_data = get_company_prefs();
-
- /*Post credit note transaction to GL credit debtors,
+
+ /*Post credit note transaction to GL credit debtors,
debit freight re-charged and debit sales */
-
- if (($credit_items_total + $freight + $tax_total) != 0)
+
+ if (($credit_items_total + $freight + $tax_total) != 0)
{
-
+
add_gl_trans_customer(11, $credit_no, $date_, $branch_data["receivables_account"], 0, 0,
- -($credit_items_total + $freight + $tax_total), $order->customer_id,
- "The total debtor GL posting for the credit note could not be inserted");
+ -($credit_items_total + $freight + $tax_total), $order->customer_id,
+ "The total debtor GL posting for the credit note could not be inserted");
}
-
- if ($freight !=0)
+
+ if ($freight !=0)
{
add_gl_trans_customer(11, $credit_no, $date_, $company_data["freight_act"], 0, 0,
- $freight, $order->customer_id,
- "The freight GL posting for this credit note could not be inserted");
+ $freight, $order->customer_id,
+ "The freight GL posting for this credit note could not be inserted");
}
-
- foreach ($taxes as $taxitem)
+
+ foreach ($taxes as $taxitem)
{
- if ($taxitem['Value'] != 0)
+ if ($taxitem['Value'] != 0)
{
-
+
add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'],
- $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']);
-
- add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0,
- $taxitem['Value'], $order->customer_id,
- "A tax GL posting for this credit note could not be inserted");
- }
- }
+ $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']);
+
+ add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+ $taxitem['Value'], $order->customer_id,
+ "A tax GL posting for this credit note could not be inserted");
+ }
+ }
}
//----------------------------------------------------------------------------------------
<?php
// $bo_policy = 0, cancel remaining quantities on order
-// = 1, backorder remaining quantities
+// = 1, backorder remaining quantities
-function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_group_id,
+function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_group_id,
$charge_shipping, $location, $ship_via, $sales_type, $reference, $memo_, $bo_policy)
{
begin_transaction();
-
+
$company_data = get_company_prefs();
-
- $branch_data = get_branch_accounts($invoice->Branch);
-
+
+ $branch_data = get_branch_accounts($invoice->Branch);
+
$invoice_items_total = $invoice->get_items_total_dispatch($tax_group_id);
-
+
$tax_total = 0;
$taxes = $invoice->get_taxes($tax_group_id, $charge_shipping);
foreach ($taxes as $taxitem)
$tax_total += $taxitem['Value'];
/*Now insert the debtor_trans */
-
- $invoice_no = add_customer_trans(10, $invoice->customer_id, $invoice->Branch, $date_,
- $reference, $invoice_items_total, 0, $tax_total, $charge_shipping,
+
+ $invoice_no = add_customer_trans(10, $invoice->customer_id, $invoice->Branch, $date_,
+ $reference, $invoice_items_total, 0, $tax_total, $charge_shipping,
$sales_type, $sales_order, $ship_via, $due_date);
-
- // If balance of the order cancelled update sales order details quantity.
- foreach ($invoice->line_items as $order_line)
+
+ // If balance of the order cancelled update sales order details quantity.
+ foreach ($invoice->line_items as $order_line)
{
- if ($order_line->qty_dispatched != 0)
+ if ($order_line->qty_dispatched != 0)
{
-
+
$line_taxfree_price = $order_line->taxfree_price($tax_group_id);
$line_tax = $order_line->full_price() - $line_taxfree_price;
-
- // Now update sales_order_details for the quantity invoiced
- dispatch_sales_order_item($sales_order, $order_line->stock_id,
+
+ // Now update sales_order_details for the quantity invoiced
+ dispatch_sales_order_item($sales_order, $order_line->id,
$order_line->qty_dispatched);
-
+
/* add invoice details and stock movements */
$memo_ = "";
add_customer_trans_detail_item(10, $invoice_no, $order_line->stock_id,
- $order_line->item_description, $location, $date_,
+ $order_line->item_description, $location, $date_,
-$order_line->qty_dispatched, $line_taxfree_price, $line_tax,
$order_line->discount_percent, $memo_, $order_line->standard_cost);
-
- $stock_gl_code = get_stock_gl_code($order_line->stock_id);
-
+
+ $stock_gl_code = get_stock_gl_code($order_line->stock_id);
+
/* insert gl_trans to credit stock and debit cost of sales at standard cost*/
if ($order_line->standard_cost != 0)
{
/*first the cost of sales entry*/
- add_gl_trans_std_cost(10, $invoice_no, $date_, $stock_gl_code["cogs_account"],
- $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], "",
- $order_line->standard_cost * $order_line->qty_dispatched,
- payment_person_types::customer(), $invoice->customer_id,
+ add_gl_trans_std_cost(10, $invoice_no, $date_, $stock_gl_code["cogs_account"],
+ $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], "",
+ $order_line->standard_cost * $order_line->qty_dispatched,
+ payment_person_types::customer(), $invoice->customer_id,
"The cost of sales GL posting could not be inserted");
-
+
/*now the stock entry*/
//$stock_gl_code = get_stock_gl_code($order_line->stock_id);
-
- add_gl_trans_std_cost(10, $invoice_no, $date_, $stock_gl_code["inventory_account"], 0, 0, "",
- (-$order_line->standard_cost * $order_line->qty_dispatched),
- payment_person_types::customer(), $invoice->customer_id,
- "The stock side of the cost of sales GL posting could not be inserted");
+
+ add_gl_trans_std_cost(10, $invoice_no, $date_, $stock_gl_code["inventory_account"], 0, 0, "",
+ (-$order_line->standard_cost * $order_line->qty_dispatched),
+ payment_person_types::customer(), $invoice->customer_id,
+ "The stock side of the cost of sales GL posting could not be inserted");
} /* end of if GL and stock integrated and standard cost !=0 */
{
//Post sales transaction to GL credit sales
-
- add_gl_trans_customer(10, $invoice_no, $date_, $stock_gl_code["sales_account"],
- $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"],
- (-$line_taxfree_price * $order_line->qty_dispatched),
+
+ add_gl_trans_customer(10, $invoice_no, $date_, $stock_gl_code["sales_account"],
+ $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"],
+ (-$line_taxfree_price * $order_line->qty_dispatched),
$invoice->customer_id, "The sales price GL posting could not be inserted");
-
+
if ($order_line->discount_percent != 0)
{
-
- add_gl_trans_customer(10, $invoice_no, $date_,
- $branch_data["sales_discount_account"], $stock_gl_code["dimension_id"],
+
+ add_gl_trans_customer(10, $invoice_no, $date_,
+ $branch_data["sales_discount_account"], $stock_gl_code["dimension_id"],
$stock_gl_code["dimension2_id"],
- ($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
- $invoice->customer_id, "The sales discount GL posting could not be inserted");
+ ($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
+ $invoice->customer_id, "The sales discount GL posting could not be inserted");
} /*end of if discount !=0 */
} /*end of if sales integrated with debtors */
}
/*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
- if (($invoice_items_total + $charge_shipping + $tax_total) != 0)
+ if (($invoice_items_total + $charge_shipping + $tax_total) != 0)
{
-
+
add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
- ($invoice_items_total + $charge_shipping + $tax_total),
- $invoice->customer_id, "The total debtor GL posting could not be inserted");
+ ($invoice_items_total + $charge_shipping + $tax_total),
+ $invoice->customer_id, "The total debtor GL posting could not be inserted");
}
- if ($charge_shipping != 0)
+ if ($charge_shipping != 0)
{
-
+
add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
- (-$charge_shipping), $invoice->customer_id,
- "The freight GL posting could not be inserted");
+ (-$charge_shipping), $invoice->customer_id,
+ "The freight GL posting could not be inserted");
}
-
- foreach ($taxes as $taxitem)
+
+ foreach ($taxes as $taxitem)
{
- if ($taxitem['Value'] != 0)
+ if ($taxitem['Value'] != 0)
{
add_customer_trans_tax_detail_item(10, $invoice_no, $taxitem['tax_type_id'],
- $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']);
-
+ $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']);
+
add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
- (-$taxitem['Value']), $invoice->customer_id,
+ (-$taxitem['Value']), $invoice->customer_id,
"A tax GL posting could not be inserted");
- }
- }
-
- add_comments(10, $invoice_no, $date_, $memo_);
-
+ }
+ }
+
+ add_comments(10, $invoice_no, $date_, $memo_);
+
add_forms_for_sys_type(10, $invoice_no, $location);
-
- references::save_last($reference, 10);
-
- commit_transaction();
-
+
+ references::save_last($reference, 10);
+
+ commit_transaction();
+
return $invoice_no;
}
function void_sales_invoice($type, $type_no)
{
begin_transaction();
-
+
void_bank_trans($type, $type_no, true);
void_gl_trans($type, $type_no, true);
-
- // for invoices and credits related to invoices,
+
+ // for invoices and credits related to invoices,
// reverse all the changes in the sales order
$items_result = get_customer_trans_details($type, $type_no);
-
+
$order = get_customer_trans_order($type, $type_no);
-
- if ($order)
+
+ if ($order)
{
while ($row = db_fetch($items_result))
{
- dispatch_sales_order_item($order, $row["stock_id"], $row["quantity"]);
+ dispatch_sales_order_item($order, $row["id"], $row["quantity"]);
}
}
-
+
// clear details after they've been reversed in the sales order
void_customer_trans_details($type, $type_no);
-
- void_customer_trans_tax_details($type, $type_no);
-
+
+ void_customer_trans_tax_details($type, $type_no);
+
void_cust_allocations($type, $type_no);
-
+
// do this last because other voidings can depend on it - especially voiding
// DO NOT MOVE THIS ABOVE VOIDING or we can end up with trans with alloc < 0
- void_customer_trans($type, $type_no);
-
- commit_transaction();
+ void_customer_trans($type, $type_no);
+
+ commit_transaction();
}
//--------------------------------------------------------------------------------------------------
$st_num = array();
$st_reorder = array();
}
- foreach ($order->line_items as $stock_item)
+ foreach ($order->line_items as $line)
{
- if ($loc_notification == 1 && is_inventory_item($stock_item->stock_id))
+ if ($line->Deleted == false)
{
- $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
- FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
- WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
- AND ".TB_PREF."loc_stock.stock_id = '" . $stock_item->stock_id . "'
- AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
- $res = db_query($sql,"a location could not be retreived");
- $loc = db_fetch($res);
- if ($loc['email'] != "")
+ if ($loc_notification == 1 && is_inventory_item($line->stock_id))
{
- $qoh = get_qoh_on_date($stock_item->stock_id, $order->Location);
- $qoh -= get_demand_qty($stock_item->stock_id, $order->Location);
- $qoh -= get_demand_asm_qty($stock_item->stock_id, $order->Location);
- $qoh -= $stock_item->quantity;
- if ($qoh < $loc['reorder_level'])
+ $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
+ FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
+ WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
+ AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "'
+ AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
+ $res = db_query($sql,"a location could not be retreived");
+ $loc = db_fetch($res);
+ if ($loc['email'] != "")
{
- $st_ids[] = $stock_item->stock_id;
- $st_names[] = $stock_item->item_description;
- $st_num[] = $qoh - $loc['reorder_level'];
- $st_reorder[] = $loc['reorder_level'];
+ $qoh = get_qoh_on_date($line->stock_id, $order->Location);
+ $qoh -= get_demand_qty($line->stock_id, $order->Location);
+ $qoh -= get_demand_asm_qty($line->stock_id, $order->Location);
+ $qoh -= $line->quantity;
+ if ($qoh < $loc['reorder_level'])
+ {
+ $st_ids[] = $line->stock_id;
+ $st_names[] = $line->item_description;
+ $st_num[] = $qoh - $loc['reorder_level'];
+ $st_reorder[] = $loc['reorder_level'];
+ }
}
}
- }
- $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent) VALUES (";
- $sql .= $order_no .
- ",'$stock_item->stock_id', '$stock_item->item_description', $stock_item->price,
- $stock_item->quantity,
- $stock_item->discount_percent)";
- db_query($sql, "order Details Cannot be Added");
-
- } /* inserted line items into sales order details */
-
+ $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent) VALUES (";
+ $sql .= $order_no .
+ ",'$line->stock_id', '$line->item_description', $line->price,
+ $line->quantity,
+ $line->discount_percent)";
+ db_query($sql, "order Details Cannot be Added");
+
+ } /* inserted line items into sales order details */
+ }
add_forms_for_sys_type(systypes::sales_order(), $order_no);
commit_transaction();
$st_num = array();
$st_reorder = array();
}
- foreach ($order->line_items as $stock_item)
+ foreach ($order->line_items as $line)
{
- if ($loc_notification == 1 && is_inventory_item($stock_item->stock_id))
+ if ($line->Deleted == false)
{
- $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
- FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
- WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
- AND ".TB_PREF."loc_stock.stock_id = '" . $stock_item->stock_id . "'
- AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
- $res = db_query($sql,"a location could not be retreived");
- $loc = db_fetch($res);
- if ($loc['email'] != "")
+ if ($loc_notification == 1 && is_inventory_item($line->stock_id))
{
- $qoh = get_qoh_on_date($stock_item->stock_id, $order->Location);
- $qoh -= get_demand_qty($stock_item->stock_id, $order->Location);
- $qoh -= get_demand_asm_qty($stock_item->stock_id, $order->Location);
- $qoh -= $stock_item->quantity;
- if ($qoh < $loc['reorder_level'])
+ $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
+ FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
+ WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
+ AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "'
+ AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
+ $res = db_query($sql,"a location could not be retreived");
+ $loc = db_fetch($res);
+ if ($loc['email'] != "")
{
- $st_ids[] = $stock_item->stock_id;
- $st_names[] = $stock_item->item_description;
- $st_num[] = $qoh - $loc['reorder_level'];
- $st_reorder[] = $loc['reorder_level'];
+ $qoh = get_qoh_on_date($line->stock_id, $order->Location);
+ $qoh -= get_demand_qty($line->stock_id, $order->Location);
+ $qoh -= get_demand_asm_qty($line->stock_id, $order->Location);
+ $qoh -= $line->quantity;
+ if ($qoh < $loc['reorder_level'])
+ {
+ $st_ids[] = $line->stock_id;
+ $st_names[] = $line->item_description;
+ $st_num[] = $qoh - $loc['reorder_level'];
+ $st_reorder[] = $loc['reorder_level'];
+ }
}
}
- }
-
- $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent, qty_invoiced) VALUES (";
- $sql .= $order_no . ",'" . $stock_item->stock_id . "','" . $stock_item->item_description . "', " . $stock_item->price . ", " . $stock_item->quantity . ", " . $stock_item->discount_percent . ", " . $stock_item->qty_inv . " )";
+ $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent, qty_invoiced) VALUES (";
- db_query($sql, "Old order Cannot be Inserted");
+ $sql .= $order_no . ",'" . $line->stock_id . "','" . $line->item_description . "', " . $line->price . ", " . $line->quantity . ", " . $line->discount_percent . ", " . $line->qty_inv . " )";
- } /* inserted line items into sales order details */
+ db_query($sql, "Old order Cannot be Inserted");
+ } /* inserted line items into sales order details */
+ }
commit_transaction();
if ($loc_notification == 1 && count($st_ids) > 0)
{
$order->tax_group_id = $myrow["tax_group_id"];
$sql = "SELECT stk_code, unit_price, ".TB_PREF."sales_order_details.description,
- ".TB_PREF."sales_order_details.quantity, discount_percent,
+ ".TB_PREF."sales_order_details.quantity, ".TB_PREF."sales_order_details.id, discount_percent,
qty_invoiced, ".TB_PREF."stock_master.units,
".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS standard_cost
FROM ".TB_PREF."sales_order_details, ".TB_PREF."stock_master
if ($skip_completed_items)
$sql .= "
AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced > 0 ";
+ $sql .= " ORDER BY ".TB_PREF."sales_order_details.id";
$result = db_query($sql, "Retreive order Line Items");
while ($myrow = db_fetch($result))
{
- $order->add_to_cart($myrow["stk_code"],$myrow["quantity"],
+ $order->add_to_cart($order->lines_on_order+1, $myrow["id"], $myrow["stk_code"],$myrow["quantity"],
$myrow["unit_price"], $myrow["discount_percent"],
$myrow["qty_invoiced"], $myrow["standard_cost"], $myrow["description"]);
}
//----------------------------------------------------------------------------------------
-function dispatch_sales_order_item($order_no, $stock_id, $qty_dispatched)
+function dispatch_sales_order_item($order_no, $id, $qty_dispatched)
{
$sql = "UPDATE ".TB_PREF."sales_order_details
SET qty_invoiced = qty_invoiced + $qty_dispatched ";
$sql .= " WHERE order_no = $order_no
- AND stk_code = '$stock_id'";
+ AND id = $id";
db_query($sql, "The sales order detail record could not be updated");
}
customer_list_row(_("Customer:"), 'customer_id', null, false, true);
- if ($order->customer_id != $_POST['customer_id'])
+ if ($order->customer_id != $_POST['customer_id'])
{
// customer has changed
customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'branch_id', null, false, true, true);
- //if (($_SESSION['Items']->order_no == 0) ||
- // ($order->customer_id != $_POST['customer_id']) ||
+ //if (($_SESSION['credit_items']->order_no == 0) ||
+ // ($order->customer_id != $_POST['customer_id']) ||
// ($order->Branch != $_POST['branch_id']))
// $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
- if (($order->customer_id != $_POST['customer_id']) ||
+ if (($order->customer_id != $_POST['customer_id']) ||
($order->Branch != $_POST['branch_id']))
$customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
start_table("$table_style width=90%");
$th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
_("Price"), _("Discount %"), _("Total"));
- table_header($th);
+ table_header($th);
$subtotal = 0;
$k = 0; //row colour counter
- foreach ($order->line_items as $stock_item)
+ foreach ($order->line_items as $line)
{
- $line_total = $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent);
+ $line_total = $line->quantity * $line->price * (1 - $line->discount_percent);
- if (!isset($_GET['Edit']) || $_GET['Edit'] != $stock_item->stock_id)
+ if (!isset($_GET['Edit']) || $_GET['Edit'] != $line->line_no)
{
alt_table_row_color($k);
- label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $stock_item->stock_id . "'>$stock_item->stock_id</a>");
- label_cell($stock_item->item_description);
- qty_cell($stock_item->quantity);
- label_cell($stock_item->units);
- amount_cell($stock_item->price);
+ label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $line->stock_id . "'>$line->stock_id</a>");
+ label_cell($line->item_description);
+ qty_cell($line->quantity);
+ label_cell($line->units);
+ amount_cell($line->price);
- amount_cell($stock_item->discount_percent * 100);
+ amount_cell($line->discount_percent * 100);
amount_cell($line_total);
- edit_link_cell(SID . "Edit=$stock_item->stock_id");
- delete_link_cell(SID . "Delete=$stock_item->stock_id");
+ edit_link_cell(SID . "Edit=$line->line_no");
+ delete_link_cell(SID . "Delete=$line->line_no");
- //labelt_cell(get_tax_free_price_for_item($stock_item->stock_id, $line_total, $_POST['tax_group_id']));
+ //labelt_cell(get_tax_free_price_for_item($line->stock_id, $line_total, $_POST['tax_group_id']));
end_row();
- }
- else
+ }
+ else
{
- credit_edit_item_controls($order, $stock_item->stock_id);
+ credit_edit_item_controls($order, $line->stock_id);
}
$subtotal += $line_total;
if (isset($_GET['Edit']) and $stock_id!=null)
{
+ $line_no = $_GET['Edit'];
+ hidden('line_no', $line_no);
+
if (!isset($_POST['stock_id']))
- $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
+ $_POST['stock_id'] = $order->line_items[$line_no]->stock_id;
if (!isset($_POST['qty']) OR ($_POST['qty']==""))
- $_POST['qty'] = $order->line_items[$stock_id]->quantity;
+ $_POST['qty'] = $order->line_items[$line_no]->quantity;
if (!isset($_POST['price']) OR ($_POST['price']==""))
- $_POST['price'] = $order->line_items[$stock_id]->price;
+ $_POST['price'] = $order->line_items[$line_no]->price;
if (!isset($_POST['Disc']) OR ($_POST['Disc']==""))
- $_POST['Disc'] = ($order->line_items[$stock_id]->discount_percent)*100;
+ $_POST['Disc'] = ($order->line_items[$line_no]->discount_percent)*100;
- $_POST['units'] = $order->line_items[$stock_id]->units;
+ $_POST['units'] = $order->line_items[$line_no]->units;
hidden('stock_id', $_POST['stock_id']);
label_cell($_POST['stock_id']);
- label_cell($order->line_items[$stock_id]->item_description);
+ label_cell($order->line_items[$line_no]->item_description);
}
else
{
+ hidden('line_no', ($_SESSION['credit_items']->lines_on_order + 1));
echo "<td colspan=2>";
stock_items_list('stock_id', null, false, true);
echo "</td>";
text_cells(null, 'Disc', $_POST['Disc'], 7, 5);
amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
- if (isset($_GET['Edit']))
+ if (isset($_GET['Edit']))
{
submit_cells('UpdateItem', _("Update"));
submit_cells('CancelItemChanges', _("Cancel"));
- }
- else
+ }
+ else
{
submit_cells('AddItem', _("Add Item"), "colspan=2");
}
$_POST['Location'] = $_SESSION['credit_items']->Location;
locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
- }
- else
+ }
+ else
{
/* the goods are to be written off to somewhere */
gl_all_accounts_list_row(_("Write off the cost of the items to"), 'WriteOffGLCode', null);
//--------------------------------------------------------------------------------
-function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount)
+function add_to_order(&$order, $line_no, $new_item, $new_item_qty, $price, $discount)
{
+/*
$already_on_order = 0;
foreach ($order->line_items AS $order_item)
if ($already_on_order != 1)
{
- $order->add_to_cart ($new_item, $new_item_qty, $price, $discount);
- } /* end of if not already on the order */
+*/
+ $order->add_to_cart ($line_no, 0, $new_item, $new_item_qty, $price, $discount);
}
//---------------------------------------------------------------------------------
$total = 0;
$k = 0; //row colour counter
- foreach ($order->line_items as $stock_item)
+ foreach ($order->line_items as $line)
{
-
- $line_total = $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent);
-
- if (!isset($_GET['Edit']))
- $id = "";
- else
- $id = $_GET['Edit'];
- if (!$editable_items || $id != $stock_item->stock_id)
+ if ($line->Deleted == false)
{
- alt_table_row_color($k);
+ $line_total = $line->quantity * $line->price * (1 - $line->discount_percent);
- view_stock_status_cell($stock_item->stock_id);
-
- label_cell($stock_item->item_description);
- qty_cell($stock_item->quantity);
- label_cell($stock_item->units);
- amount_cell($stock_item->price);
-
- amount_cell($stock_item->discount_percent * 100);
- amount_cell($line_total);
+ if (!isset($_GET['Edit']))
+ $id = "";
+ else
+ $id = $_GET['Edit'];
+ if (!$editable_items || $id != $line->line_no)
+ {
+ alt_table_row_color($k);
+
+ view_stock_status_cell($line->stock_id);
+
+ label_cell($line->item_description);
+ qty_cell($line->quantity);
+ label_cell($line->units);
+ amount_cell($line->price);
+
+ amount_cell($line->discount_percent * 100);
+ amount_cell($line_total);
+
+ if ($editable_items)
+ {
+ edit_link_cell(SID . "Edit=$line->line_no");
+ delete_link_cell(SID . "Delete=$line->line_no");
+ }
+ end_row();
+ }
+ else
+ {
+ sales_order_item_controls($order, $line->stock_id);
+ }
- if ($editable_items)
- {
- edit_link_cell(SID . "Edit=$stock_item->stock_id");
- delete_link_cell(SID . "Delete=$stock_item->stock_id");
- }
- end_row();
- }
- else
- {
- sales_order_item_controls($order, $stock_item->stock_id);
+ $total += $line_total;
}
-
- $total += $line_total;
}
if (!isset($_GET['Edit']) && $editable_items)
if (isset($_GET['Edit']) && $stock_id != null)
{
+ $line_no = $_GET['Edit'];
+ hidden('line_no', $line_no);
+
if (!isset($_POST['stock_id']))
- $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id;
+ $_POST['stock_id'] = $order->line_items[$line_no]->stock_id;
if (!isset($_POST['qty']) || ($_POST['qty'] == ""))
- $_POST['qty'] = $order->line_items[$_GET['Edit']]->quantity;
+ $_POST['qty'] = $order->line_items[$line_no]->quantity;
if (!isset($_POST['price']) || ($_POST['price'] == ""))
- $_POST['price'] = $order->line_items[$_GET['Edit']]->price;
+ $_POST['price'] = $order->line_items[$line_no]->price;
if (!isset($_POST['Disc']) || ($_POST['Disc'] == ""))
- $_POST['Disc'] = ($order->line_items[$_GET['Edit']]->discount_percent)*100;
+ $_POST['Disc'] = ($order->line_items[$line_no]->discount_percent)*100;
- $_POST['units'] = $order->line_items[$_GET['Edit']]->units;
+ $_POST['units'] = $order->line_items[$line_no]->units;
hidden('stock_id', $_POST['stock_id']);
label_cell($_POST['stock_id']);
- label_cell($order->line_items[$stock_id]->item_description);
+ label_cell($order->line_items[$line_no]->item_description);
}
else
{
- global $no_item_list;
+ hidden('line_no', ($_SESSION['Items']->lines_on_order + 1));
+ $no_item_list = get_company_pref('no_item_list');
if ($no_item_list)
{
echo "<td colspan=2>\n";
if (isset($_GET['selected_id']))
{
$selected_id = strtoupper($_GET['selected_id']);
-}
+}
elseif (isset($_POST['selected_id']))
{
$selected_id = strtoupper($_POST['selected_id']);
//------------------------------------------------------------------------------------------------
-if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
+if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
{
//initialise no input errors assumed initially before we test
$input_error = 0;
- if (strlen($_POST['salesman_name']) == 0)
+ if (strlen($_POST['salesman_name']) == 0)
{
$input_error = 1;
display_error(_("The sales person name cannot be empty."));
- }
+ }
if ($input_error != 1)
{
- if (isset($selected_id))
+ if (isset($selected_id))
{
/*selected_id could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
-
- $sql = "UPDATE ".TB_PREF."salesman SET salesman_name='" . $_POST['salesman_name'] . "',
- salesman_phone='" . $_POST['salesman_phone'] . "',
+
+ $sql = "UPDATE ".TB_PREF."salesman SET salesman_name='" . $_POST['salesman_name'] . "',
+ salesman_phone='" . $_POST['salesman_phone'] . "',
salesman_fax='" . $_POST['salesman_fax'] . "',
- salesman_email='" . $_POST['salesman_email'] . "'
+ salesman_email='" . $_POST['salesman_email'] . "',
+ provision=".$_POST['provision'].",
+ break_pt=".$_POST['break_pt'].",
+ provision2=".$_POST['provision2']."
WHERE salesman_code = '$selected_id'";
- }
- else
+ }
+ else
{
/*Selected group is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Sales-person form */
- $sql = "INSERT INTO ".TB_PREF."salesman (salesman_name, salesman_phone, salesman_fax, salesman_email)
- VALUES ('" . $_POST['salesman_name'] . "', '" . $_POST['salesman_phone'] . "', '" . $_POST['salesman_fax'] . "', '" . $_POST['salesman_email'] . "')";
+ $sql = "INSERT INTO ".TB_PREF."salesman (salesman_name, salesman_phone, salesman_fax, salesman_email,
+ provision, break_pt, provision2)
+ VALUES ('" . $_POST['salesman_name'] . "', '" . $_POST['salesman_phone'] . "', '" . $_POST['salesman_fax'] . "', '" . $_POST['salesman_email'] . "', ".
+ $_POST['provision'].", ".$_POST['break_pt'].", ".$_POST['provision2'].")";
}
//run the sql from either of the above possibilites
db_query($sql,"The insert or update of the salesperson failed");
-
- meta_forward($_SERVER['PHP_SELF']);
+
+ meta_forward($_SERVER['PHP_SELF']);
}
-}
-if (isset($_GET['delete']))
+}
+if (isset($_GET['delete']))
{
//the link to delete a selected record was clicked instead of the submit button
$sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE salesman='$selected_id'";
$result = db_query($sql,"check failed");
$myrow = db_fetch_row($result);
- if ($myrow[0] > 0)
+ if ($myrow[0] > 0)
{
display_error("Cannot delete this sales-person because branches are set up referring to this sales-person - first alter the branches concerned.");
- }
- else
+ }
+ else
{
$sql="DELETE FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
db_query($sql,"The sales-person could not be deleted");
- meta_forward($_SERVER['PHP_SELF']);
+ meta_forward($_SERVER['PHP_SELF']);
}
}
-//------------------------------------------------------------------------------------------------
+//------------------------------------------------------------------------------------------------
$sql = "SELECT * FROM ".TB_PREF."salesman";
$result = db_query($sql,"could not get sales persons");
-start_table("$table_style width=40%");
-$th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), "", "");
+start_table("$table_style width=60%");
+$th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), _("Provision"), _("Break Pt."), _("Provision")." 2", "", "");
table_header($th);
$k = 0;
-while ($myrow = db_fetch($result))
+while ($myrow = db_fetch($result))
{
-
- alt_table_row_color($k);
-
+
+ alt_table_row_color($k);
+
label_cell($myrow["salesman_name"]);
label_cell($myrow["salesman_phone"]);
label_cell($myrow["salesman_fax"]);
label_cell($myrow["salesman_email"]);
+ percent_cell($myrow["provision"]);
+ amount_cell($myrow["break_pt"]);
+ percent_cell($myrow["provision2"]);
edit_link_cell(SID . "selected_id=" . $myrow["salesman_code"]);
delete_link_cell(SID . "selected_id=" . $myrow["salesman_code"]. "&delete=1");
end_row();
-
+
} //END WHILE LIST LOOP
-
+
end_table();
//------------------------------------------------------------------------------------------------
start_form();
-if (isset($selected_id))
+if (isset($selected_id))
{
//editing an existing Sales-person
$sql = "SELECT * FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
$_POST['salesman_phone'] = $myrow["salesman_phone"];
$_POST['salesman_fax'] = $myrow["salesman_fax"];
$_POST['salesman_email'] = $myrow["salesman_email"];
+ $_POST['provision'] = $myrow["provision"];
+ $_POST['break_pt'] = $myrow["break_pt"];
+ $_POST['provision2'] = $myrow["provision2"];
hidden('selected_id', $selected_id);
}
-start_table("$table_style2 width=40%");
+start_table("$table_style2 width=60%");
text_row_ex(_("Sales person name:"), 'salesman_name', 30);
text_row_ex(_("Telephone number:"), 'salesman_phone', 20);
text_row_ex(_("Fax number:"), 'salesman_fax', 20);
text_row_ex(_("Email:"), 'salesman_email', 40);
-
+percent_row(_("Provision"), 'provision');
+amount_row(_("Break Pt.:"), 'break_pt');
+percent_row(_("Provision")." 2", 'provision2');
end_table(1);
submit_add_or_update_center(!isset($selected_id));
if ($use_date_picker)
$js .= get_js_date_picker();
-if (isset($_GET['ModifyOrderNumber']))
+if (isset($_GET['ModifyOrderNumber']))
{
- page(_("Modifying Sales Order") . " #".$_GET['ModifyOrderNumber'], false, false, "", $js);
-}
-elseif (isset($_GET['NewInvoice']) || (isset($_SESSION['Items']) && $_SESSION['Items']->direct_invoice))
+ page(_("Modifying Sales Order") . " #".$_GET['ModifyOrderNumber'], false, false, "", $js);
+}
+elseif (isset($_GET['NewInvoice']) || (isset($_SESSION['Items']) && $_SESSION['Items']->direct_invoice))
{
- page(_("Sales Invoices"), false, false, "", $js);
-}
-else
+ page(_("Sales Invoices"), false, false, "", $js);
+}
+else
{
- page(_("Sales Order Entry"), false, false, "", $js);
+ page(_("Sales Order Entry"), false, false, "", $js);
}
//--------------------------------------------------------------------------------
-if (isset($_GET['AddedID']))
+if (isset($_GET['AddedID']))
{
$order_no = $_GET['AddedID'];
$trans_type = systypes::sales_order();
}
//--------------------------------------------------------------------------------
-if (isset($_GET['UpdatedID']))
+if (isset($_GET['UpdatedID']))
{
$order_no = $_GET['UpdatedID'];
$trans_type = systypes::sales_order();
function can_process()
{
- if ($_SESSION['Items']->direct_invoice)
+ if ($_SESSION['Items']->direct_invoice)
{
$edate = _("The entered invoice date is invalid.");
- }
- else
- {
+ }
+ else
+ {
$edate = _("The entered order date is invalid.");
- }
- if (!is_date($_POST['OrderDate']))
+ }
+ if (!is_date($_POST['OrderDate']))
{
display_error($edate);
return false;
}
- if ($_SESSION['Items']->direct_invoice && !is_date_in_fiscalyear($_POST['OrderDate']))
+ if ($_SESSION['Items']->direct_invoice && !is_date_in_fiscalyear($_POST['OrderDate']))
{
display_error(_("The entered date is not in fiscal year"));
return false;
return false;
}
- if (!is_date($_POST['delivery_date']))
+ if (!is_date($_POST['delivery_date']))
{
display_error(_("The delivery date is invalid."));
return false;
}
- if (date1_greater_date2($_SESSION['Items']->orig_order_date, $_POST['delivery_date']))
+ if (date1_greater_date2($_SESSION['Items']->orig_order_date, $_POST['delivery_date']))
{
display_error(_("The requested delivery date is before the date of the order."));
return false;
$_SESSION['Items']->phone =$_POST['phone'];
if (isset($_POST['email']))
$_SESSION['Items']->email =$_POST['email'];
- else
+ else
$_SESSION['Items']->email = "";
$_SESSION['Items']->Location = $_POST['Location'];
$_SESSION['Items']->cust_ref = $_POST['cust_ref'];
{
$order_no = add_sales_order($_SESSION['Items']);
-
- if ($_SESSION['Items']->direct_invoice)
+
+ if ($_SESSION['Items']->direct_invoice)
{
+ $_SESSION['Items']->clear_items();
$_SESSION['Items']->memo_ = $_POST['InvoiceText'];
$_SESSION['Items']->memo_ = str_replace("'", "\\'", $_SESSION['Items']->memo_);
$_SESSION['Items']->order_no = $order_no;
meta_forward("$path_to_root/sales/customer_invoice.php", "process_invoice=Yes");
-
- }
- else
+
+ }
+ else
{
-
+
unset($_SESSION['Items']->line_items);
unset($_SESSION['Items']);
meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no");
- }
+ }
}
//-------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
-function check_item_data()
+function check_item_data()
{
- if (!is_numeric($_POST['qty']) || $_POST['qty'] < 0 || $_POST['Disc'] > 100 ||
+ if (!is_numeric($_POST['qty']) || $_POST['qty'] < 0 || $_POST['Disc'] > 100 ||
$_POST['Disc'] < 0)
{
display_error( _("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100."));
return false;
- }
- elseif($_SESSION['Items']->some_already_delivered($_POST['stock_id']) != 0 &&
- $_SESSION['Items']->line_items[$_POST['stock_id']]->price != $_POST['price'])
+ }
+ elseif($_SESSION['Items']->some_already_delivered($_POST['line_no']) != 0 &&
+ $_SESSION['Items']->line_items[$_POST['line_no']]->price != $_POST['price'])
{
display_error(_("The item you attempting to modify the price for has already had some quantity invoiced at the old price. The item unit price cannot be modified retrospectively."));
return false;
- }
- elseif($_SESSION['Items']->some_already_delivered($_POST['stock_id']) != 0 &&
- $_SESSION['Items']->line_items[$_POST['stock_id']]->discount_percent != ($_POST['Disc']/100))
+ }
+ elseif($_SESSION['Items']->some_already_delivered($_POST['line_no']) != 0 &&
+ $_SESSION['Items']->line_items[$_POST['line_no']]->discount_percent != ($_POST['Disc']/100))
{
display_error(_("The item you attempting to modify has had some quantity invoiced at the old discount percent. The items discount cannot be modified retrospectively."));
return false;
- }
- elseif (isset($_SESSION['Items']->line_items[$_POST['stock_id']]) && $_SESSION['Items']->line_items[$_POST['stock_id']]->qty_inv > $_POST['qty'])
+ }
+ elseif (isset($_SESSION['Items']->line_items[$_POST['line_no']]) && $_SESSION['Items']->line_items[$_POST['line_no']]->qty_inv > $_POST['qty'])
{
display_error(_("You attempting to make the quantity ordered a quantity less than has already been invoiced. The quantity delivered and invoiced cannot be modified retrospectively."));
return false;
- }
+ }
return true;
}
-function handle_update_item()
+function handle_update_item()
{
if($_POST['UpdateItem'] != "" && check_item_data())
{
- $_SESSION['Items']->update_cart_item($_POST['stock_id'], $_POST['qty'],
+ $_SESSION['Items']->update_cart_item($_POST['line_no'], $_POST['qty'],
$_POST['price'], ($_POST['Disc'] / 100));
}
}
//--------------------------------------------------------------------------------
-function handle_delete_item()
-{
+function handle_delete_item()
+{
if($_GET['Delete'] != "")
{
- $stock_id = $_GET['Delete'];
- if($_SESSION['Items']->some_already_delivered($stock_id) == 0)
+ $line_no = $_GET['Delete'];
+ if($_SESSION['Items']->some_already_delivered($line_no) == 0)
{
- $_SESSION['Items']->remove_from_cart($stock_id);
- }
- else
+ $_SESSION['Items']->remove_from_cart($line_no);
+ }
+ else
{
display_error(_("This item cannot be deleted because some of it has already been invoiced."));
}
{
if (!check_item_data())
return;
-
- add_to_order($_SESSION['Items'], $_POST['stock_id'], $_POST['qty'],
+
+ add_to_order($_SESSION['Items'], $_POST['line_no'], $_POST['stock_id'], $_POST['qty'],
$_POST['price'], $_POST['Disc']/100);
$_POST['StockID2'] = $_POST['stock_id'] = "";
}
-//--------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------
function handle_cancel_order()
{
global $path_to_root;
-
- if ($_POST['CancelOrder'] != "")
+
+ if ($_POST['CancelOrder'] != "")
{
$ok_to_delete = 1; //assume this in the first instance
-
- if (($_SESSION['Items']->order_no != 0) &&
- sales_order_has_invoices($_SESSION['Items']->order_no))
+
+ if (($_SESSION['Items']->order_no != 0) &&
+ sales_order_has_invoices($_SESSION['Items']->order_no))
{
$ok_to_delete = 0;
display_error(_("This order cannot be cancelled because some of it has already been invoiced. However, the line item quantities may be modified."));
}
-
+
if ($ok_to_delete == 1)
{
if($_SESSION['Items']->order_no != 0)
$_SESSION['Items']->clear_items();
$_SESSION['Items'] = new cart;
$_SESSION['Items']->direct_invoice = $diriv;
- if ($diriv)
+ if ($diriv)
{
display_note(_("This sales invoice has been cancelled as requested."), 1);
hyperlink_params($path_to_root . "/sales/sales_order_entry.php", _("Enter a New Sales Invoice"), SID . "&NewInvoice=Yes");
- }
- else
+ }
+ else
{
display_note(_("This sales order has been cancelled as requested."), 1);
hyperlink_params($path_to_root . "/sales/sales_order_entry.php", _("Enter a New Sales Order"), SID . "&NewOrder=Yes");
}
br(1);
- end_page();
+ end_page();
exit;
}
}
}
-
+
//--------------------------------------------------------------------------------
-function handle_new_order()
+function handle_new_order()
{
/*New order entry - clear any existing order details from the Items object and initiate a newy*/
if (isset($_SESSION['Items']))
unset ($_SESSION['Items']->line_items);
unset ($_SESSION['Items']);
}
-
+
session_register("Items");
$_SESSION['Items'] = new cart;
if (isset($_GET['NewInvoice']))
$_SESSION['Items']->direct_invoice = true;
$_SESSION['Items']->customer_id = "";
- $_POST['OrderDate'] = Today();
+ $_POST['OrderDate'] = Today();
if (!is_date_in_fiscalyear($_POST['OrderDate']))
$_POST['OrderDate'] = end_fiscalyear();
$_SESSION['Items']->orig_order_date = $_POST['OrderDate'];
}
-//--------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------
if (isset($_GET['ModifyOrderNumber']) && $_GET['ModifyOrderNumber'] != "")
{
session_register("Items");
$_SESSION['Items'] = new cart;
- $_SESSION['Items']->order_no = $_GET['ModifyOrderNumber'];
+ $_SESSION['Items']->order_no = $_GET['ModifyOrderNumber'];
/*read in all the selected order into the Items cart */
-
+
read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items']);
}
if (isset($_GET['Delete']) || isset($_GET['Edit']))
copy_from_so();
-
+
if (isset($_GET['Delete']))
handle_delete_item();
if (isset($_POST['UpdateItem']) || isset($_POST['AddItem']))
copy_to_so();
-
+
if (isset($_POST['UpdateItem']))
handle_update_item();
if (isset($_POST['AddItem']))
handle_new_item();
-
+
//--------------------------------------------------------------------------------
if (isset($_GET['NewOrder']) || isset($_GET['NewInvoice']))
{
handle_new_order();
-}
-else
+}
+else
{
if (!isset($_POST['customer_id']))
$_POST['customer_id'] = $_SESSION['Items']->customer_id;
- if (!isset($_POST['branch_id']))
+ if (!isset($_POST['branch_id']))
$_POST['branch_id'] = $_SESSION['Items']->Branch;
- if (!isset($_POST['OrderDate']))
+ if (!isset($_POST['OrderDate']))
$_POST['OrderDate'] = $_SESSION['Items']->orig_order_date;
}
-//--------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------
check_db_has_stock_items(_("There are no inventory items defined in the system."));
-check_db_has_customer_branches(_("There are no customers, or there are no customers with branches. Please define customers and customer branches."));
+check_db_has_customer_branches(_("There are no customers, or there are no customers with branches. Please define customers and customer branches."));
-if ($_SESSION['Items']->direct_invoice)
+if ($_SESSION['Items']->direct_invoice)
{
$idate = _("Invoice Date:");
$orderitems = _("Sales Invoice Items");
$deliverydetails = _("Enter Delivery Details and Confirm Invoice");
$cancelorder = _("Cancel Invoice");
-}
-else
+}
+else
{
$idate = _("Order Date:");
$orderitems = _("Sales Order Items");
}
start_form(false, true);
-$customer_error = display_order_header($_SESSION['Items'],
+$customer_error = display_order_header($_SESSION['Items'],
($_SESSION['Items']->any_already_delivered() == 0), $idate);
if ($customer_error == "")
{
start_table("$table_style width=80%", 10);
- echo "<tr><td>";
+ echo "<tr><td>";
display_order_summary($orderitems, $_SESSION['Items'], true);
echo "</td></tr>";
- echo "<tr><td>";
+ echo "<tr><td>";
display_delivery_details($_SESSION['Items']);
echo "</td></tr>";
- end_table(1);
-}
+ end_table(1);
+}
else
{
display_error($customer_error);
}
-if ($_SESSION['Items']->direct_invoice)
+if ($_SESSION['Items']->direct_invoice)
{
$porder = _("Place Invoice");
$corder = _("Commit Invoice Changes");
$eorder = _("Edit Invoice Items");
-}
-else
+}
+else
{
$porder = _("Place Order");
$corder = _("Commit Order Changes");
if ($_SESSION['Items']->order_no == 0)
{
submit_center_first('ProcessOrder', $porder);
-}
-else
+}
+else
{
submit_center_first('ProcessOrder', $corder);
}
-/*
+/*
echo " ";
submit('EditOrder', $eorder);
if ($_SESSION['Items']->count_items() >= 1)
submit('DeliveryDetails', $deliverydetails);
echo " ";
}
-*/
+*/
submit_center_last('CancelOrder', $cancelorder);
-
+
end_form();
//--------------------------------------------------------------------------------
$_SESSION['Items'] = new cart;
if (isset($_GET['NewInvoice']))
$_SESSION['Items']->direct_invoice = true;
- $_SESSION['Items']->order_no = 0;
+ $_SESSION['Items']->order_no = 0;
}
//--------------------------------------------------------------------------------