function get_work_order($woid, $allow_null=false)
{
- $sql = "SELECT ".TB_PREF."workorders.*, ".TB_PREF."stock_master.description As StockItemName,
- ".TB_PREF."locations.location_name, ".TB_PREF."locations.delivery_address
- FROM ".TB_PREF."workorders, ".TB_PREF."stock_master, ".TB_PREF."locations
- WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id
- AND ".TB_PREF."locations.loc_code=".TB_PREF."workorders.loc_code
- AND ".TB_PREF."workorders.id=".db_escape($woid)."
- GROUP BY ".TB_PREF."workorders.id";
+ $sql = "SELECT wo.*,st.description As StockItemName,l.location_name,
+ l.delivery_address,l.email, l.contact
+ FROM ".TB_PREF."workorders wo, ".TB_PREF."stock_master st, ".TB_PREF."locations l
+ WHERE st.stock_id=wo.stock_id
+ AND l.loc_code=wo.loc_code
+ AND wo.id=".db_escape($woid)."
+ GROUP BY wo.id";
$result = db_query($sql, "The work order issues could not be retrieved");
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-function add_supplier($supp_name, $supp_ref, $address, $supp_address, $phone, $phone2, $fax, $gst_no, $email,
- $website, $contact, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id,
+function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
+ $website, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id,
$curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
- $notes, $tax_group_id, $rep_lang)
+ $notes, $tax_group_id)
{
- $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, phone, phone2, fax, gst_no, email, website,
- contact, supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
- payment_terms, payable_account, purchase_account, payment_discount_account, notes, tax_group_id, rep_lang)
+ $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, gst_no, website,
+ supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
+ payment_terms, payable_account, purchase_account, payment_discount_account, notes, tax_group_id)
VALUES (".db_escape($_POST['supp_name']). ", "
.db_escape($supp_ref). ", "
.db_escape($address) . ", "
.db_escape($supp_address) . ", "
- .db_escape($phone). ", "
- .db_escape($phone2). ", "
- .db_escape($fax). ", "
.db_escape($gst_no). ", "
- .db_escape($email). ", "
.db_escape($website). ", "
- .db_escape($contact). ", "
.db_escape($supp_account_no). ", "
.db_escape($bank_account). ", "
.$credit_limit. ", "
.db_escape($purchase_account). ", "
.db_escape($payment_discount_account). ", "
.db_escape($notes). ", "
- .db_escape($tax_group_id). ", "
- .db_escape($rep_lang ? $rep_lang : null, true). ")";
+ .db_escape($tax_group_id). ")";
db_query($sql,"The supplier could not be added");
}
-function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_address, $phone, $phone2, $fax, $gst_no,
- $email, $website, $contact, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id,
+function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_address, $gst_no,
+ $website, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id,
$curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
- $notes, $tax_group_id, $rep_lang)
+ $notes, $tax_group_id)
{
$sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($supp_name) . ",
supp_ref=".db_escape($supp_ref) . ",
address=".db_escape($address) . ",
supp_address=".db_escape($supp_address) . ",
- phone=".db_escape($phone) . ",
- phone2=".db_escape($phone2) . ",
- fax=".db_escape($fax) . ",
gst_no=".db_escape($gst_no) . ",
- email=".db_escape($email) . ",
website=".db_escape($website) . ",
- contact=".db_escape($contact) . ",
supp_account_no=".db_escape($supp_account_no) . ",
bank_account=".db_escape($bank_account) . ",
credit_limit=".$credit_limit . ",
purchase_account=".db_escape($purchase_account) . ",
payment_discount_account=".db_escape($payment_discount_account) . ",
notes=".db_escape($notes) . ",
- tax_group_id=".db_escape($tax_group_id) . ",
- rep_lang=".db_escape($rep_lang ? $rep_lang : null, true) . " WHERE supplier_id = ".db_escape($supplier_id);
+ tax_group_id=".db_escape($tax_group_id)
+ ." WHERE supplier_id = ".db_escape($supplier_id);
db_query($sql,"The supplier could not be updated");
}
return db_fetch($result);
}
+function get_supplier_contacts($supplier_id, $action=null)
+{
+ $results = array();
+ $res = get_crm_persons('supplier', $action, $supplier_id);
+ while($contact = db_fetch($res))
+ $results[] = $contact;
+
+ return $results;
+}
?>
\ No newline at end of file
page(_($help_context = "Suppliers"), @$_REQUEST['popup']);
-//include($path_to_root . "/includes/date_functions.inc");
-
-include($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/includes/ui/contacts_view.inc");
check_db_has_tax_groups(_("There are no tax groups defined in the system. At least one tax group is required before proceeding."));
{
$_POST['supplier_id'] = $_GET['supplier_id'];
}
-$new_supplier = get_post('supplier_id') == '';
+
+$supplier_id = get_post('supplier_id');
+//--------------------------------------------------------------------------------------------
+function supplier_settings(&$supplier_id)
+{
+
+ start_outer_table(TABLESTYLE2);
+
+ table_section(1);
+
+ if ($supplier_id)
+ {
+ //SupplierID exists - either passed when calling the form or from the form itself
+ $myrow = get_supplier($_POST['supplier_id']);
+
+ $_POST['supp_name'] = $myrow["supp_name"];
+ $_POST['supp_ref'] = $myrow["supp_ref"];
+ $_POST['address'] = $myrow["address"];
+ $_POST['supp_address'] = $myrow["supp_address"];
+
+ $_POST['gst_no'] = $myrow["gst_no"];
+ $_POST['website'] = $myrow["website"];
+ $_POST['supp_account_no'] = $myrow["supp_account_no"];
+ $_POST['bank_account'] = $myrow["bank_account"];
+ $_POST['dimension_id'] = $myrow["dimension_id"];
+ $_POST['dimension2_id'] = $myrow["dimension2_id"];
+ $_POST['curr_code'] = $myrow["curr_code"];
+ $_POST['payment_terms'] = $myrow["payment_terms"];
+ $_POST['credit_limit'] = price_format($myrow["credit_limit"]);
+ $_POST['tax_group_id'] = $myrow["tax_group_id"];
+ $_POST['payable_account'] = $myrow["payable_account"];
+ $_POST['purchase_account'] = $myrow["purchase_account"];
+ $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
+ $_POST['notes'] = $myrow["notes"];
+ $_POST['inactive'] = $myrow["inactive"];
+ }
+ else
+ {
+ $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] =
+ $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
+ $_POST['dimension_id'] = 0;
+ $_POST['dimension2_id'] = 0;
+ $_POST['sales_type'] = -1;
+ $_POST['gst_no'] = $_POST['bank_account'] = '';
+ $_POST['payment_terms'] = '';
+ $_POST['credit_limit'] = price_format(0);
+
+ $company_record = get_company_prefs();
+ $_POST['curr_code'] = $company_record["curr_default"];
+ $_POST['payable_account'] = $company_record["creditors_act"];
+ $_POST['purchase_account'] = $company_record["default_cogs_act"];
+ $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
+ }
+
+ table_section_title(_("Basic Data"));
+
+ text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
+ text_row(_("Supplier Short Name:"), 'supp_ref', null, 30, 30);
+
+ text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
+ link_row(_("Website:"), 'website', null, 35, 55);
+ if ($supplier_id)
+ {
+ label_row(_("Supplier's Currency:"), $_POST['curr_code']);
+ hidden('curr_code', $_POST['curr_code']);
+ }
+ else
+ {
+ currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
+ }
+ tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
+ text_row(_("Our Customer No:"), 'supp_account_no', null, 42, 40);
+
+ if (!$supplier_id) {
+ table_section_title(_("Contact Data"));
+ text_row(_("Contact Person:"), 'contact', null, 42, 40);
+ text_row(_("Phone Number:"), 'phone', null, 32, 30);
+ text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
+ text_row(_("Fax Number:"), 'fax', null, 32, 30);
+ email_row(_("E-mail:"), 'email', null, 35, 55);
+ languages_list_row(_("Document Language:"), 'rep_lang', null, _('System default'));
+ }
+ table_section_title(_("Purchasing"));
+ text_row(_("Bank Name/Account:"), 'bank_account', null, 42, 40);
+ amount_row(_("Credit Limit:"), 'credit_limit', null);
+ payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
+
+ table_section_title(_("Accounts"));
+ gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
+ gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
+ gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
+
+ table_section(2);
+ $dim = get_company_pref('use_dimension');
+ if ($dim >= 1)
+ {
+ table_section_title(_("Dimension"));
+ dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
+ if ($dim > 1)
+ dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
+ }
+ if ($dim < 1)
+ hidden('dimension_id', 0);
+ if ($dim < 2)
+ hidden('dimension2_id', 0);
+
+
+ table_section_title(_("Addresses"));
+ textarea_row(_("Mailing Address:"), 'address', null, 35, 5);
+ textarea_row(_("Physical Address:"), 'supp_address', null, 35, 5);
+
+ table_section_title(_("General"));
+ textarea_row(_("General Notes:"), 'notes', null, 35, 5);
+ if ($supplier_id)
+ record_status_list_row(_("Supplier status:"), 'inactive');
+
+ end_outer_table(1);
+
+ div_start('controls');
+ if ($supplier_id)
+ {
+ submit_center_first('submit', _("Update Supplier"),
+ _('Update supplier data'), @$_REQUEST['popup'] ? true : 'default');
+ submit_return('select', get_post('supplier_id'), _("Select this supplier and return to document entry."));
+ submit_center_last('delete', _("Delete Supplier"),
+ _('Delete supplier data if have been never used'), true);
+ }
+ else
+ {
+ submit_center('submit', _("Add New Supplier Details"), true, '', 'default');
+ }
+ div_end();
+}
if (isset($_POST['submit']))
{
if ($input_error !=1 )
{
- if (!$new_supplier)
+ begin_transaction();
+ if ($supplier_id)
{
update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'],
- $_POST['supp_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['gst_no'],
- $_POST['email'], $_POST['website'], $_POST['contact'], $_POST['supp_account_no'], $_POST['bank_account'],
+ $_POST['supp_address'], $_POST['gst_no'],
+ $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'],
input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'],
$_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'],
- $_POST['notes'], $_POST['tax_group_id'], $_POST['rep_lang']);
+ $_POST['notes'], $_POST['tax_group_id']);
update_record_status($_POST['supplier_id'], $_POST['inactive'],
'suppliers', 'supplier_id');
else
{
add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'],
- $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['gst_no'], $_POST['email'],
- $_POST['website'], $_POST['contact'], $_POST['supp_account_no'], $_POST['bank_account'],
+ $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'],
input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'],
$_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'],
- $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], $_POST['rep_lang']);
+ $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id']);
+
+ $supplier_id = $_POST['supplier_id'] = db_insert_id();
+
+ add_crm_person($_POST['supp_ref'], $_POST['contact'], '', $_POST['address'],
+ $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'],
+ $_POST['rep_lang'], '');
+
+ add_crm_contact('supplier', 'general', $supplier_id, db_insert_id());
- $_POST['supplier_id'] = db_insert_id();
- $new_supplier = false;
display_notification(_("A new supplier has been added."));
$Ajax->activate('_page_body');
}
+ commit_transaction();
}
}
delete_supplier($_POST['supplier_id']);
unset($_SESSION['supplier_id']);
- $new_supplier = true;
+ $supplier_id = '';
$Ajax->activate('_page_body');
} //end if Delete supplier
}
hidden('supplier_id', get_post('supplier_id'));
}
-start_outer_table(TABLESTYLE2);
-
-table_section(1);
-
-if (!$new_supplier)
-{
- //SupplierID exists - either passed when calling the form or from the form itself
- $myrow = get_supplier($_POST['supplier_id']);
-
- $_POST['supp_name'] = $myrow["supp_name"];
- $_POST['supp_ref'] = $myrow["supp_ref"];
- $_POST['address'] = $myrow["address"];
- $_POST['supp_address'] = $myrow["supp_address"];
- $_POST['phone'] = $myrow["phone"];
- $_POST['phone2'] = $myrow["phone2"];
- $_POST['fax'] = $myrow["fax"];
- $_POST['gst_no'] = $myrow["gst_no"];
- $_POST['email'] = $myrow["email"];
- $_POST['website'] = $myrow["website"];
- $_POST['contact'] = $myrow["contact"];
- $_POST['supp_account_no'] = $myrow["supp_account_no"];
- $_POST['bank_account'] = $myrow["bank_account"];
- $_POST['dimension_id'] = $myrow["dimension_id"];
- $_POST['dimension2_id'] = $myrow["dimension2_id"];
- $_POST['curr_code'] = $myrow["curr_code"];
- $_POST['rep_lang'] = $myrow["rep_lang"];
- $_POST['payment_terms'] = $myrow["payment_terms"];
- $_POST['credit_limit'] = price_format($myrow["credit_limit"]);
- $_POST['tax_group_id'] = $myrow["tax_group_id"];
- $_POST['payable_account'] = $myrow["payable_account"];
- $_POST['purchase_account'] = $myrow["purchase_account"];
- $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
- $_POST['notes'] = $myrow["notes"];
- $_POST['inactive'] = $myrow["inactive"];
-}
-else
-{
- $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] =
- $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
- $_POST['dimension_id'] = 0;
- $_POST['dimension2_id'] = 0;
- $_POST['sales_type'] = -1;
- $_POST['email'] = $_POST['phone'] = $_POST['phone2'] = $_POST['fax'] =
- $_POST['gst_no'] = $_POST['contact'] = $_POST['bank_account'] = '';
- $_POST['payment_terms'] = '';
- $_POST['credit_limit'] = price_format(0);
-
- $company_record = get_company_prefs();
- $_POST['curr_code'] = $company_record["curr_default"];
- $_POST['rep_lang'] = '';
- $_POST['payable_account'] = $company_record["creditors_act"];
- $_POST['purchase_account'] = $company_record["default_cogs_act"];
- $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
- $_POST['inactive'] = 0;
-}
-
-table_section_title(_("Name and Contact"));
-
-text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
-text_row(_("Supplier Short Name:"), 'supp_ref', null, 30, 30);
-text_row(_("Contact Person:"), 'contact', null, 42, 40);
-
-text_row(_("Phone Number:"), 'phone', null, 32, 30);
-text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
-text_row(_("Fax Number:"), 'fax', null, 32, 30);
-
-email_row(_("E-mail:"), 'email', null, 35, 55);
-link_row(_("Website:"), 'website', null, 35, 55);
-text_row(_("Our Customer No:"), 'supp_account_no', null, 42, 40);
-
-table_section_title(_("Addresses"));
-textarea_row(_("Mailing Address:"), 'address', null, 35, 5);
-textarea_row(_("Physical Address:"), 'supp_address', null, 35, 5);
-
-table_section(2);
-
-table_section_title(_("Purchasing"));
-text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
-text_row(_("Bank Name/Account:"), 'bank_account', null, 42, 40);
-amount_row(_("Credit Limit:"), 'credit_limit', null);
-if (!$new_supplier)
-{
- label_row(_("Supplier's Currency:"), $_POST['curr_code']);
- hidden('curr_code', $_POST['curr_code']);
-}
-else
-{
- currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
-}
-
-languages_list_row(_("Document Language:"), 'rep_lang', null, _('System default'));
-
-tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
-
-payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
-
-table_section_title(_("Accounts"));
-
-gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
-
-gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account']);
-
-gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
-
-$dim = get_company_pref('use_dimension');
-if ($dim >= 1)
-{
- table_section_title(_("Dimension"));
-
- dimensions_list_row(_("Dimension")." 1:", 'dimension_id', null, true, " ", false, 1);
- if ($dim > 1)
- dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
-}
-if ($dim < 1)
- hidden('dimension_id', 0);
-if ($dim < 2)
- hidden('dimension2_id', 0);
-table_section_title(_("General"));
-textarea_row(_("General Notes:"), 'notes', null, 35, 5);
-record_status_list_row(_("Supplier status:"), 'inactive');
-
-end_outer_table(1);
-
-div_start('controls');
-if (!$new_supplier)
-{
- submit_center_first('submit', _("Update Supplier"),
- _('Update supplier data'), @$_REQUEST['popup'] ? true : 'default');
- submit_return('select', get_post('supplier_id'), _("Select this supplier and return to document entry."));
- submit_center_last('delete', _("Delete Supplier"),
- _('Delete supplier data if have been never used'), true);
-}
-else
-{
- submit_center('submit', _("Add New Supplier Details"), true, '', 'default');
-}
-div_end();
+if (!$supplier_id)
+ unset($_POST['_tabs_sel']); // force settings tab for new customer
+
+tabbed_content_start('tabs', array(
+ 'settings' => array('&General settings', $supplier_id),
+ 'contacts' => array('&Contacts', $supplier_id),
+ ));
+
+ switch (get_post('_tabs_sel')) {
+ default:
+ case 'settings':
+ supplier_settings($supplier_id);
+ break;
+ case 'contacts':
+ $contacts = new contacts('contacts', $supplier_id, 'supplier');
+ $contacts->show();
+ break;
+ case 'orders':
+ };
+br();
+tabbed_content_end();
hidden('popup', @$_REQUEST['popup']);
end_form();
}
else
$rep->title = ($j == ST_SALESINVOICE) ? _('INVOICE') : _('CREDIT NOTE');
- $rep->SetCommonData($myrow, $branch, $sales_order, $baccount, $j);
+ $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no']);
+ $rep->SetCommonData($myrow, $branch, $sales_order, $baccount, $j, $contacts);
$rep->NewPage();
$result = get_customer_trans_details($j, $i);
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
+include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
//----------------------------------------------------------------------------------------------------
$rep->Info($params, $cols, null, $aligns);
}
- $sql = "SELECT debtor_no, name AS DebtorName, address, tax_id, email, curr_code, curdate() AS tran_date, rep_lang FROM ".TB_PREF."debtors_master";
+ $sql = "SELECT debtor_no, name AS DebtorName, address, tax_id, email, curr_code, curdate() AS tran_date FROM ".TB_PREF."debtors_master";
if ($customer != ALL_NUMERIC)
$sql .= " WHERE debtor_no = ".db_escape($customer);
else
$rep->filename = "Statement" . $myrow['debtor_no'] . ".pdf";
$rep->Info($params, $cols, null, $aligns);
}
- $rep->SetCommonData($myrow, null, null, $baccount, ST_STATEMENT);
+ $contacts = get_customer_contacts($myrow['debtor_no'], 'invoice');
+ //= get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no']);
+ $rep->SetCommonData($myrow, null, null, $baccount, ST_STATEMENT, $contacts);
$rep->NewPage();
$rep->NewLine();
$linetype = true;
}
else
$rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
- $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESORDER);
+
+ $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no']);
+ $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESORDER, $contacts);
$rep->NewPage();
$result = get_sales_order_details($i, ST_SALESORDER);
$rep->Font();
if ($email == 1)
{
+ $res = get_branch_contacts(branch_code, 'order', customer_id);
if ($myrow['contact_email'] == '')
{
$myrow['contact_email'] = $branch['email'];
}
else
$rep->title = _('DELIVERY NOTE');
- $rep->SetCommonData($myrow, $branch, $sales_order, '', ST_CUSTDELIVERY);
+ $contacts = get_branch_contacts($branch['branch_code'], 'delivery', $branch['debtor_no']);
+ $rep->SetCommonData($myrow, $branch, $sales_order, '', ST_CUSTDELIVERY, $contacts);
$rep->NewPage();
$result = get_customer_trans_details(ST_CUSTDELIVERY, $i);
$rep->Info($params, $cols, null, $aligns);
}
$rep->title = _("SALES QUOTATION");
- $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESQUOTE);
+ $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no']);
+ $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESQUOTE, $contacts);
$rep->headerFunc = 'Header2';
$rep->NewPage();
// $ Revision: 2.0 $
// Creator: Joe Hunt
// date_: 2005-05-19
-// Title: Purchase Orders
+// Title: Receipts
// ----------------------------------------------------------------
$path_to_root="..";
".TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_discount) AS Total,
".TB_PREF."debtors_master.name AS DebtorName, ".TB_PREF."debtors_master.debtor_ref,
".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.payment_terms, "
- .TB_PREF."debtors_master.tax_id AS tax_id,".TB_PREF."debtors_master.rep_lang,
+ .TB_PREF."debtors_master.tax_id AS tax_id,
".TB_PREF."debtors_master.email, ".TB_PREF."debtors_master.address
FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master
WHERE ".TB_PREF."debtor_trans.debtor_no = ".TB_PREF."debtors_master.debtor_no
$params['bankaccount'] = $baccount['id'];
$rep->title = _('RECEIPT');
- $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_CUSTPAYMENT);
+ $contacts = get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no']);
+ $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_CUSTPAYMENT, $contacts);
$rep->NewPage();
$result = get_allocations_for_receipt($myrow['debtor_no'], $myrow['type'], $myrow['trans_no']);
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
+include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
//----------------------------------------------------------------------------------------------------
function get_po($order_no)
{
$sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, "
- .TB_PREF."suppliers.rep_lang, ".TB_PREF."suppliers.supp_account_no,
+ .TB_PREF."suppliers.supp_account_no,
".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.payment_terms, ".TB_PREF."locations.location_name,
- ".TB_PREF."suppliers.email, ".TB_PREF."suppliers.address, ".TB_PREF."suppliers.contact
+ ".TB_PREF."suppliers.address, ".TB_PREF."suppliers.contact
FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
AND ".TB_PREF."locations.loc_code = into_stock_location
}
else
$rep->title = _('PURCHASE ORDER');
- $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_PURCHORDER);
+ $contacts = get_supplier_contacts($myrow['supplier_id'], 'order');
+ $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_PURCHORDER, $contacts);
$rep->NewPage();
$result = get_po_details($i);
$rep->Font();
if ($email == 1)
{
- $myrow['contact_email'] = $myrow['email'];
+// $myrow['contact_email'] = $myrow['email'];
$myrow['DebtorName'] = $myrow['supp_name'];
- if ($myrow['contact'] != '') $myrow['DebtorName'] = $myrow['contact'];
+// if ($myrow['contact'] != '') $myrow['DebtorName'] = $myrow['contact'];
$myrow['reference'] = $myrow['order_no'];
$rep->End($email, $doc_Order_no . " " . $myrow['reference'], $myrow);
}
// $ Revision: 2.0 $
// Creator: Joe Hunt
// date_: 2005-05-19
-// Title: Purchase Orders
+// Title: Purchase Remittance
// ----------------------------------------------------------------
$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
+include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
//----------------------------------------------------------------------------------------------------
{
$sql = "SELECT ".TB_PREF."supp_trans.*,
(".TB_PREF."supp_trans.ov_amount+".TB_PREF."supp_trans.ov_gst+".TB_PREF."supp_trans.ov_discount) AS Total,
- ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.supp_account_no, ".TB_PREF."suppliers.rep_lang,
+ ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.supp_account_no,
".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.payment_terms, ".TB_PREF."suppliers.gst_no AS tax_id,
- ".TB_PREF."suppliers.email, ".TB_PREF."suppliers.address, ".TB_PREF."suppliers.contact
+ ".TB_PREF."suppliers.address
FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
WHERE ".TB_PREF."supp_trans.supplier_id = ".TB_PREF."suppliers.supplier_id
AND ".TB_PREF."supp_trans.type = ".db_escape($type)."
}
else
$rep->title = _('REMITTANCE');
- $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_SUPPAYMENT);
+ $contacts = get_supplier_contacts($myrow['supplier_id'], 'invoice');
+ $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_SUPPAYMENT, $contacts);
$rep->NewPage();
$result = get_allocations_for_remittance($myrow['supplier_id'], $myrow['type'], $myrow['trans_no']);
$rep->Font();
if ($email == 1)
{
- $myrow['contact_email'] = $myrow['email'];
+// $myrow['contact_email'] = $myrow['email'];
$myrow['DebtorName'] = $myrow['supp_name'];
- if ($myrow['contact'] != '') $myrow['DebtorName'] = $myrow['contact'];
+// if ($myrow['contact'] != '') $myrow['DebtorName'] = $myrow['contact'];
$rep->End($email, $doc_Order_no . " " . $myrow['reference'], $myrow);
}
}
$page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
'SA_MANUFTRANSVIEW' : 'SA_MANUFBULKREP';
// ----------------------------------------------------------------
-// $ Revision: 2.0 $
-// Creator: Janusz Dobrowolski
-// date_: 2008-01-14
-// Title: Print Workorders
-// draft version!
-// ----------------------------------------------------------------
+// Title: Work Orders
$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
function print_workorders()
{
- global $path_to_root, $SysPrefs;
+ global $path_to_root, $SysPrefs, $dflt_lang;
include_once($path_to_root . "/reporting/includes/pdf_report.inc");
$myrow = get_work_order($i);
if ($myrow === false)
continue;
- $date_ = sql2date($myrow["date_"]);
+ $date_ = sql2date($myrow["date_"]);
if ($email == 1)
{
$rep = new FrontReport("", "", user_pagesize());
$rep->currency = $cur;
$rep->Font();
$rep->title = _('WORK ORDER');
- $rep->filename = "WorkOrder" . $myrow['reference'] . ".pdf";
+ $rep->filename = "WorkOrder" . $myrow['wo_ref'] . ".pdf";
$rep->Info($params, $cols, null, $aligns);
}
else
$rep->title = _('WORK ORDER');
- $rep->SetCommonData($myrow, null, null, '', 26);
+
+ $contact[] = array('email' =>$myrow['email'],'lang' => $dflt_lang,
+ 'name' => $myrow['contact'], 'name2' => '', 'contact');
+
+ $rep->SetCommonData($myrow, null, null, '', 26, $contact);
$rep->NewPage();
$result = get_wo_requirements($i);
while ($comment=db_fetch($comments))
$rep->TextColLines(0, 6, $comment['memo_'], -2);
}
+ if ($email == 1)
+ {
+// $myrow['contact_email'] = $myrow['email'];
+ $myrow['DebtorName'] = $myrow['contact'];
+ $myrow['reference'] = $myrow['wo_ref'];
+ $rep->End($email, _("Work Order No.") . " " . $myrow['wo_ref'], $myrow);
+ }
}
if ($email == 0)
$rep->End();
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-function add_branch($customer_id, $br_name, $br_ref, $br_address, $phone, $phone2, $fax, $contact_name,
- $salesman, $area, $email, $tax_group_id, $sales_account, $sales_discount_account, $receivables_account,
+function add_branch($customer_id, $br_name, $br_ref, $br_address, $salesman, $area,
+ $tax_group_id, $sales_account, $sales_discount_account, $receivables_account,
$payment_discount_account, $default_location, $br_post_address, $disable_trans, $group_no,
- $default_ship_via, $notes, $rep_lang)
+ $default_ship_via, $notes)
{
$sql = "INSERT INTO ".TB_PREF."cust_branch (debtor_no, br_name, branch_ref, br_address,
- salesman, phone, phone2, fax,
- contact_name, area, email, tax_group_id, sales_account, receivables_account, payment_discount_account, sales_discount_account, default_location,
- br_post_address, disable_trans, group_no, default_ship_via, notes, rep_lang)
+ salesman, area, tax_group_id, sales_account, receivables_account, payment_discount_account,
+ sales_discount_account, default_location,
+ br_post_address, disable_trans, group_no, default_ship_via, notes)
VALUES (".db_escape($customer_id). ",".db_escape($br_name) . ", "
.db_escape($br_ref) . ", "
.db_escape($br_address) . ", ".db_escape($salesman) . ", "
- .db_escape($phone) . ", ".db_escape($phone2) . ", "
- .db_escape($fax) . ","
- .db_escape($contact_name) . ", ".db_escape($area) . ","
- .db_escape($email) . ", ".db_escape($tax_group_id) . ", "
+ .db_escape($area) . ","
+ .db_escape($tax_group_id) . ", "
.db_escape($sales_account) . ", "
.db_escape($receivables_account) . ", "
.db_escape($payment_discount_account) . ", "
.db_escape($disable_trans) . ", "
.db_escape($group_no) . ", "
.db_escape($default_ship_via). ", "
- .db_escape($notes). ", "
- .db_escape($rep_lang ? $rep_lang : null, true) . ")";
+ .db_escape($notes).")";
db_query($sql,"The branch record could not be added");
}
-function update_branch($customer_id, $branch_code, $br_name, $br_ref, $br_address, $phone, $phone2, $fax, $contact_name,
- $salesman, $area, $email, $tax_group_id, $sales_account, $sales_discount_account, $receivables_account,
+function update_branch($customer_id, $branch_code, $br_name, $br_ref, $br_address,
+ $salesman, $area, $tax_group_id, $sales_account, $sales_discount_account, $receivables_account,
$payment_discount_account, $default_location, $br_post_address, $disable_trans, $group_no,
- $default_ship_via, $notes, $rep_lang)
+ $default_ship_via, $notes)
{
$sql = "UPDATE ".TB_PREF."cust_branch SET br_name = " . db_escape($br_name) . ",
branch_ref = " . db_escape($br_ref) . ",
br_address = ".db_escape($br_address). ",
- phone=".db_escape($phone). ",
- phone2=".db_escape($phone2). ",
- fax=".db_escape($fax).",
- contact_name=".db_escape($contact_name) . ",
salesman= ".db_escape($salesman) . ",
area=".db_escape($area) . ",
- email=".db_escape($email) . ",
tax_group_id=".db_escape($tax_group_id). ",
sales_account=".db_escape($sales_account) . ",
sales_discount_account=".db_escape($sales_discount_account) . ",
disable_trans=".db_escape($disable_trans) . ",
group_no=".db_escape($group_no) . ",
default_ship_via=".db_escape($default_ship_via) . ",
- notes=".db_escape($notes) . ",
- rep_lang=".db_escape($rep_lang ? $rep_lang : null, true) . "
+ notes=".db_escape($notes) . "
WHERE branch_code =".db_escape($branch_code) . "
AND debtor_no=".db_escape($customer_id);
db_query($sql,"The branch record could not be updated");
function delete_branch($customer_id, $branch_code)
{
+ delete_entity_contacts('cust_branch', $branch_code);
+
$sql="DELETE FROM ".TB_PREF."cust_branch WHERE branch_code=".db_escape($branch_code)." AND debtor_no=".db_escape($customer_id);
db_query($sql,"could not delete branch");
}
$result = db_query($sql, "Cannot retreive a customer branch");
- return db_fetch($result);
+ return db_fetch($result);
}
function get_cust_branch($customer_id, $branch_code)
$result = db_query($sql, "Cannot retreive a customer branch");
- return db_fetch($result);
+ return db_fetch($result);
}
function get_branch_name($branch_id)
$result = db_query($sql,"could not retreive name for branch" . $branch_id);
- $myrow = db_fetch_row($result);
+ $myrow = db_fetch_row($result);
return $myrow[0];
}
function get_default_info_for_branch($customer_id)
{
- $sql = "SELECT name, address, email, debtor_ref, rep_lang
+ $sql = "SELECT name, address, debtor_ref
FROM ".TB_PREF."debtors_master WHERE debtor_no = ".db_escape($customer_id);
$result = db_query($sql,"check failed");
return db_fetch($result);
."b.branch_code, "
."b.branch_ref, "
."b.br_name, "
- ."b.contact_name, "
+ ."p.name as contact_name, "
."s.salesman_name, "
."a.description, "
- ."b.phone, "
- ."b.fax, "
- ."b.email, "
+ ."p.phone, "
+ ."p.fax, "
+ ."p.email, "
."t.name AS tax_group_name, "
."b.inactive
- FROM ".TB_PREF."cust_branch b, "
- .TB_PREF."debtors_master c, "
+ FROM ".TB_PREF."cust_branch b "
+ . "LEFT JOIN ".TB_PREF."crm_contacts c
+ ON c.entity_id=b.branch_code AND c.type='cust_branch' AND c.action='general'
+ LEFT JOIN ".TB_PREF."crm_persons p on c.person_id=p.id,"
.TB_PREF."areas a, "
.TB_PREF."salesman s, "
.TB_PREF."tax_groups t
- WHERE b.debtor_no=c.debtor_no
- AND b.tax_group_id=t.id
+ WHERE b.tax_group_id=t.id
AND b.area=a.area_code
AND b.salesman=s.salesman_code
AND b.debtor_no = ".db_escape($_POST['customer_id']);
return $sql;
}
+
+function get_branch_contacts($branch_code, $action=null, $customer_id=null)
+{
+/*
+ $ret = get_crm_persons('cust_branch', $action, $branch_code);
+ if ($customer_id && !db_num_rows($ret)) {
+ $ret = get_crm_persons('customer', $action, $customer_id);
+ }
+ return $ret;
+*/
+ $sql = "SELECT p.*, r.action, r.type FROM ".TB_PREF."crm_persons p,"
+ .TB_PREF."crm_contacts r WHERE r.person_id=p.id AND r.type='cust_branch'
+ AND r.entity_id=".db_escape($branch_code);
+
+ if ($action)
+ $sql .= ' AND r.action='.db_escape($action);
+
+ $sql .= " GROUP BY person_id";
+
+ if($customer_id) {
+ $sql = "($sql) UNION (SELECT p.*, r.action, r.type FROM ".TB_PREF."crm_persons p,"
+ .TB_PREF."crm_contacts r WHERE r.person_id=p.id AND r.type='customer'
+ AND r.entity_id=".db_escape($customer_id);
+ if ($action)
+ $sql .= ' AND r.action='.db_escape($action);
+ $sql .= " GROUP BY person_id)";
+ }
+
+ $res = db_query($sql, "can't retrieve branch contacts");
+ $results = array();
+ $type = '';
+ while($contact = db_fetch($res)) {
+ if ($type && $type != $contact['type']) break;
+ $results[] = $contact;
+ $type = $contact['type'];
+ }
+ return $results;
+}
+
?>
\ No newline at end of file
$sql = "SELECT trans.*,"
."ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,"
."cust.name AS DebtorName, cust.address, "
- ."cust.email AS email2, cust.curr_code, "
+ ."cust.curr_code, "
."cust.tax_id ";
if ($trans_type == ST_CUSTPAYMENT) {
.TB_PREF."tax_groups.id AS tax_group_id ";
}
- $sql .= ", IF(ISNULL(branch.rep_lang),cust.rep_lang,branch.rep_lang) AS rep_lang";
-
$sql .= " FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master cust";
if ($trans_type == ST_CUSTPAYMENT) {
}
$row = db_fetch($result);
- $row['email'] = $row['email2'];
return $row;
}
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-function add_customer($CustName, $cust_ref, $address, $tax_id, $curr_code, $email,
+function add_customer($CustName, $cust_ref, $address, $tax_id, $curr_code,
$dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount,
- $credit_limit, $sales_type, $notes, $rep_lang)
+ $credit_limit, $sales_type, $notes)
{
- $sql = "INSERT INTO ".TB_PREF."debtors_master (name, debtor_ref, address, tax_id, email, dimension_id, dimension2_id,
- curr_code, credit_status, payment_terms, discount, pymt_discount,credit_limit,
- sales_type, notes, rep_lang) VALUES (".db_escape($CustName) .", " .db_escape($cust_ref) .", "
+ $sql = "INSERT INTO ".TB_PREF."debtors_master (name, debtor_ref, address, tax_id,
+ dimension_id, dimension2_id, curr_code, credit_status, payment_terms, discount,
+ pymt_discount,credit_limit, sales_type, notes) VALUES ("
+ .db_escape($CustName) .", " .db_escape($cust_ref) .", "
.db_escape($address) . ", " . db_escape($tax_id) . ","
- .db_escape($email) . ", ".db_escape($dimension_id) . ", "
+ .db_escape($dimension_id) . ", "
.db_escape($dimension2_id) . ", ".db_escape($curr_code) . ",
" . db_escape($credit_status) . ", ".db_escape($payment_terms) . ", " . $discount . ",
" . $pymt_discount . ", " . $credit_limit
- .", ".db_escape($sales_type).", ".db_escape($notes).", ".db_escape($rep_lang ? $rep_lang : null, true) . ")";
+ .", ".db_escape($sales_type).", ".db_escape($notes) . ")";
db_query($sql,"The customer could not be added");
}
-function update_customer($customer_id, $CustName, $cust_ref, $address, $tax_id, $curr_code, $email,
- $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount,
- $credit_limit, $sales_type, $notes, $rep_lang)
+function update_customer($customer_id, $CustName, $cust_ref, $address, $tax_id, $curr_code,
+ $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount,
+ $credit_limit, $sales_type, $notes)
{
$sql = "UPDATE ".TB_PREF."debtors_master SET name=" . db_escape($CustName) . ",
debtor_ref=" . db_escape($cust_ref) . ",
address=".db_escape($address) . ",
tax_id=".db_escape($tax_id) . ",
curr_code=".db_escape($curr_code) . ",
- email=".db_escape($email) . ",
dimension_id=".db_escape($dimension_id) . ",
dimension2_id=".db_escape($dimension2_id) . ",
credit_status=".db_escape($credit_status) . ",
pymt_discount=" . $pymt_discount . ",
credit_limit=" . $credit_limit . ",
sales_type = ".db_escape($sales_type) . ",
- notes=".db_escape($notes) . ",
- rep_lang=".db_escape($rep_lang ? $rep_lang : null, true) . "
+ notes=".db_escape($notes) ."
WHERE debtor_no = ".db_escape($customer_id);
db_query($sql,"The customer could not be updated");
}
-function delete_customer($customer_id, $escaped=false)
+function delete_customer($customer_id)
{
- if (!$escaped)
- $customer_id = db_escape($customer_id);
- $sql = "DELETE FROM ".TB_PREF."debtors_master WHERE debtor_no=$customer_id";
+ begin_transaction();
+ delete_entity_contacts('customer', $customer_id);
+
+ $sql = "DELETE FROM ".TB_PREF."debtors_master WHERE debtor_no=".db_escape($customer_id);;
db_query($sql,"cannot delete customer");
+ commit_transaction();
}
function get_customer_details($customer_id, $to=null)
return db_fetch($result);
}
+function get_customer_contacts($customer_id, $action=null)
+{
+ $results = array();
+ $res = get_crm_persons('customer', $action, $customer_id);
+ while($contact = db_fetch($res))
+ $results[] = $contact;
+
+ return $results;
+}
?>
\ No newline at end of file
."stype.tax_included, "
."ship.shipper_name, "
."tax_group.name AS tax_group_name , "
- ."tax_group.id AS tax_group_id,"
- ."IF(ISNULL(branch.rep_lang),cust.rep_lang,branch.rep_lang) AS rep_lang "
+ ."tax_group.id AS tax_group_id "
."FROM ".TB_PREF."sales_orders sorder, "
- .TB_PREF."debtors_master cust, "
+ .TB_PREF."debtors_master cust,"
.TB_PREF."sales_types stype, "
.TB_PREF."tax_groups tax_group, "
- .TB_PREF."cust_branch branch, "
+ .TB_PREF."cust_branch branch,"
.TB_PREF."locations loc, "
.TB_PREF."shippers ship
WHERE sorder.order_type=stype.id
$sql = "SELECT ".TB_PREF."cust_branch.br_name, "
.TB_PREF."cust_branch.br_address, "
.TB_PREF."cust_branch.br_post_address, "
- .TB_PREF."cust_branch.phone, "
- .TB_PREF."cust_branch.email,
- default_location, location_name, default_ship_via, "
+ ." default_location, location_name, default_ship_via, "
.TB_PREF."tax_groups.name AS tax_group_name, "
.TB_PREF."tax_groups.id AS tax_group_id
FROM ".TB_PREF."cust_branch, "
$myrow = db_fetch($result);
+ // FIX - implement editable contact selector in sales order
+ $contact = get_branch_contacts($branch_id, 'order', $customer_id);
+
$order->set_branch($branch_id, $myrow["tax_group_id"],
- $myrow["tax_group_name"], $myrow["phone"], $myrow["email"]);
+ $myrow["tax_group_name"], @$contact[0]["phone"], @$contact[0]["email"]);
$address = trim($myrow["br_post_address"]) != '' ? $myrow["br_post_address"]
: (trim($myrow["br_address"]) != '' ? $myrow["br_address"]:$deliver);
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_CUSTOMER';
-//$page_security = 3;
$path_to_root="../..";
+
include($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
page(_($help_context = "Customer Branches"), @$_REQUEST['popup']);
include($path_to_root . "/includes/ui.inc");
+include($path_to_root . "/includes/ui/contacts_view.inc");
//-----------------------------------------------------------------------------------------------
{
$_POST['customer_id'] = strtoupper($_GET['debtor_no']);
}
+
$_POST['branch_code'] = $selected_id;
if (isset($_GET['SelectedBranch']))
//initialise no input errors assumed initially before we test
$input_error = 0;
- //first off validate inputs sensible
-
if (strlen($_POST['br_name']) == 0)
{
$input_error = 1;
if ($input_error != 1)
{
+ begin_transaction();
if ($selected_id != -1)
{
- /*SelectedBranch 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*/
update_branch($_POST['customer_id'], $_POST['branch_code'], $_POST['br_name'], $_POST['br_ref'],
- $_POST['br_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['contact_name'],
- $_POST['salesman'], $_POST['area'], $_POST['email'], $_POST['tax_group_id'], $_POST['sales_account'],
+ $_POST['br_address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], $_POST['sales_account'],
$_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'],
$_POST['default_location'], $_POST['br_post_address'], $_POST['disable_trans'], $_POST['group_no'],
- $_POST['default_ship_via'], $_POST['notes'], $_POST['rep_lang']);
+ $_POST['default_ship_via'], $_POST['notes']);
+// update_record_status($_POST['supplier_id'], $_POST['inactive'],
+// 'cust_branch', 'branch_code');
$note =_('Selected customer branch has been updated');
- }
+ }
else
{
- /*Selected branch is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Customer Branches form */
add_branch($_POST['customer_id'], $_POST['br_name'], $_POST['br_ref'],
- $_POST['br_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['contact_name'],
- $_POST['salesman'], $_POST['area'], $_POST['email'], $_POST['tax_group_id'], $_POST['sales_account'],
+ $_POST['br_address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], $_POST['sales_account'],
$_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'],
- $_POST['default_location'], $_POST['br_post_address'], $_POST['disable_trans'], $_POST['group_no'],
- $_POST['default_ship_via'], $_POST['notes'], $_POST['rep_lang']);
-
+ $_POST['default_location'], $_POST['br_post_address'], 0, $_POST['group_no'],
+ $_POST['default_ship_via'], $_POST['notes']);
+ $selected_id = db_insert_id();
+
+ add_crm_person($_POST['contact_name'], $_POST['contact_name'], '', $_POST['br_post_address'],
+ $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'],
+ $_POST['rep_lang'], '');
+
+ add_crm_contact('cust_branch', 'general', $selected_id, db_insert_id());
+
+
$note = _('New customer branch has been added');
}
+ commit_transaction();
display_notification($note);
- $Mode = 'RESET';
+// $Mode = 'RESET';
if (@$_REQUEST['popup']) {
- set_focus("Select".($_POST['branch_code'] == -1
- ? db_insert_id(): $_POST['branch_code']));
+ set_focus("Select".($_POST['branch_code'] == -1 ? $selected_id: $_POST['branch_code']));
}
}
return button("Select".$row["branch_code"], $row["branch_code"], '', ICON_ADD, 'selector');
}
+function branch_settings($selected_id) {
+ global $Mode, $num_branches;
+
+ start_outer_table(TABLESTYLE2);
+
+ table_section(1);
+
+ $_POST['email'] = "";
+ if ($selected_id != -1)
+ {
+ if ($Mode == 'Edit') {
+
+ //editing an existing branch
+ $myrow = get_cust_branch($_POST['customer_id'], $_POST['branch_code']);
+ set_focus('br_name');
+ $_POST['branch_code'] = $myrow["branch_code"];
+ $_POST['br_name'] = $myrow["br_name"];
+ $_POST['br_ref'] = $myrow["branch_ref"];
+ $_POST['br_address'] = $myrow["br_address"];
+ $_POST['br_post_address'] = $myrow["br_post_address"];
+// $_POST['contact_name'] = $myrow["contact_name"];
+ $_POST['salesman'] =$myrow["salesman"];
+ $_POST['area'] =$myrow["area"];
+// $_POST['rep_lang'] =$myrow["rep_lang"];
+// $_POST['phone'] =$myrow["phone"];
+// $_POST['phone2'] =$myrow["phone2"];
+// $_POST['fax'] =$myrow["fax"];
+// $_POST['email'] =$myrow["email"];
+ $_POST['tax_group_id'] = $myrow["tax_group_id"];
+ $_POST['disable_trans'] = $myrow['disable_trans'];
+ $_POST['default_location'] = $myrow["default_location"];
+ $_POST['default_ship_via'] = $myrow['default_ship_via'];
+ $_POST['sales_account'] = $myrow["sales_account"];
+ $_POST['sales_discount_account'] = $myrow['sales_discount_account'];
+ $_POST['receivables_account'] = $myrow['receivables_account'];
+ $_POST['payment_discount_account'] = $myrow['payment_discount_account'];
+ $_POST['group_no'] = $myrow["group_no"];
+ $_POST['notes'] = $myrow["notes"];
+
+ }
+ }
+ elseif ($Mode != 'ADD_ITEM')
+ { //end of if $SelectedBranch only do the else when a new record is being entered
+ $myrow = get_default_info_for_branch($_POST['customer_id']);
+// $_POST['rep_lang'] = $myrow['rep_lang'];
+ if(!$num_branches) {
+ $_POST['br_name'] = $myrow["name"];
+ $_POST['br_ref'] = $myrow["debtor_ref"];
+ $_POST['contact_name'] = _('Main Branch');
+ $_POST['br_address'] = $_POST['br_post_address'] = $myrow["address"];
+ $_POST['email'] = $myrow['email'];
+ }
+ $_POST['branch_code'] = "";
+ if (!isset($_POST['sales_account']) || !isset($_POST['sales_discount_account']))
+ {
+ $company_record = get_company_prefs();
+
+ // We use the Item Sales Account as default!
+ // $_POST['sales_account'] = $company_record["default_sales_act"];
+ $_POST['sales_account'] = $_POST['notes'] = '';
+ $_POST['sales_discount_account'] = $company_record['default_sales_discount_act'];
+ $_POST['receivables_account'] = $company_record['debtors_act'];
+ $_POST['payment_discount_account'] = $company_record['default_prompt_payment_act'];
+ }
+
+ }
+ hidden('popup', @$_REQUEST['popup']);
+
+ table_section_title(_("Name and Contact"));
+ text_row(_("Branch Name:"), 'br_name', null, 35, 40);
+ text_row(_("Branch Short Name:"), 'br_ref', null, 30, 30);
+
+ table_section_title(_("Sales"));
+ sales_persons_list_row( _("Sales Person:"), 'salesman', null);
+ sales_areas_list_row( _("Sales Area:"), 'area', null);
+ sales_groups_list_row(_("Sales Group:"), 'group_no', null, true);
+ locations_list_row(_("Default Inventory Location:"), 'default_location', null);
+ shippers_list_row(_("Default Shipping Company:"), 'default_ship_via', null);
+ tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
+
+ table_section_title(_("GL Accounts"));
+ // 2006-06-14. Changed gl_al_accounts_list to have an optional all_option 'Use Item Sales Accounts'
+ gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', null, false, false, true);
+ gl_all_accounts_list_row(_("Sales Discount Account:"), 'sales_discount_account');
+ gl_all_accounts_list_row(_("Accounts Receivable Account:"), 'receivables_account');
+ gl_all_accounts_list_row(_("Prompt Payment Discount Account:"), 'payment_discount_account');
+
+ table_section(2);
+
+if($selected_id==-1) {
+ table_section_title(_("General contact data"));
+ text_row(_("Contact Person:"), 'contact_name', null, 35, 40);
+ text_row(_("Phone Number:"), 'phone', null, 32, 30);
+ text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
+ text_row(_("Fax Number:"), 'fax', null, 32, 30);
+ email_row(_("E-mail:"), 'email', null, 35, 55);
+ languages_list_row( _("Document Language:"), 'rep_lang', null, _("Customer default"));
+}
+ table_section_title(_("Addresses"));
+ textarea_row(_("Mailing Address:"), 'br_post_address', null, 35, 4);
+ textarea_row(_("Billing Address:"), 'br_address', null, 35, 4);
+ textarea_row(_("General Notes:"), 'notes', null, 35, 4);
+
+if($selected_id!=-1)
+ yesno_list_row(_("Disable this Branch:"), 'disable_trans', null);
+
+ end_outer_table(1);
+ submit_add_or_update_center($selected_id == -1, '', 'both');
+}
+
start_form();
echo "<center>" . _("Select a customer: ") . " ";
if (!@$_REQUEST['popup']) {
$cols[' '] = 'skip';
}
-
$table =& new_db_pager('branch_tbl', $sql, $cols, 'cust_branch');
$table->set_inactive_ctrl('cust_branch', 'branch_code');
//$table->width = "85%";
display_db_pager($table);
+
+tabbed_content_start('tabs', array(
+ 'settings' => array('&General settings', $selected_id!=-1),
+ 'contacts' => array('&Contacts', $selected_id!=-1),
+// 'orders' => array('S&ales orders', $selected_id!=-1) // not implemented
+ ));
+
+ switch (get_post('_tabs_sel')) {
+ default:
+ case 'settings':
+ branch_settings($selected_id);
+ break;
+ case 'contacts':
+ $contacts = new contacts('contacts', $selected_id, 'cust_branch');
+ $contacts->show();
+ break;
+ case 'orders':
+ };
+ hidden('branch_code');
+ hidden('selected_id', $selected_id);
+br();
+tabbed_content_end();
}
else
display_note(_("The selected customer does not have any branches. Please create at least one branch."));
-start_outer_table(TABLESTYLE2);
-
-table_section(1);
-
-$_POST['email'] = "";
-if ($selected_id != -1)
-{
- if ($Mode == 'Edit') {
-
- //editing an existing branch
- $myrow = get_cust_branch($_POST['customer_id'], $_POST['branch_code']);
- set_focus('br_name');
- $_POST['branch_code'] = $myrow["branch_code"];
- $_POST['br_name'] = $myrow["br_name"];
- $_POST['br_ref'] = $myrow["branch_ref"];
- $_POST['br_address'] = $myrow["br_address"];
- $_POST['br_post_address'] = $myrow["br_post_address"];
- $_POST['contact_name'] = $myrow["contact_name"];
- $_POST['salesman'] =$myrow["salesman"];
- $_POST['area'] =$myrow["area"];
- $_POST['rep_lang'] =$myrow["rep_lang"];
- $_POST['phone'] =$myrow["phone"];
- $_POST['phone2'] =$myrow["phone2"];
- $_POST['fax'] =$myrow["fax"];
- $_POST['email'] =$myrow["email"];
- $_POST['tax_group_id'] = $myrow["tax_group_id"];
- $_POST['disable_trans'] = $myrow['disable_trans'];
- $_POST['default_location'] = $myrow["default_location"];
- $_POST['default_ship_via'] = $myrow['default_ship_via'];
- $_POST['sales_account'] = $myrow["sales_account"];
- $_POST['sales_discount_account'] = $myrow['sales_discount_account'];
- $_POST['receivables_account'] = $myrow['receivables_account'];
- $_POST['payment_discount_account'] = $myrow['payment_discount_account'];
- $_POST['group_no'] = $myrow["group_no"];
- $_POST['notes'] = $myrow["notes"];
-
- }
-}
-elseif ($Mode != 'ADD_ITEM')
-{ //end of if $SelectedBranch only do the else when a new record is being entered
- $myrow = get_default_info_for_branch($_POST['customer_id']);
- $_POST['rep_lang'] = $myrow['rep_lang'];
- if(!$num_branches) {
- $_POST['br_name'] = $myrow["name"];
- $_POST['br_ref'] = $myrow["debtor_ref"];
- $_POST['contact_name'] = _('Main Branch');
- $_POST['br_address'] = $_POST['br_post_address'] = $myrow["address"];
- $_POST['email'] = $myrow['email'];
- }
- $_POST['branch_code'] = "";
- if (!isset($_POST['sales_account']) || !isset($_POST['sales_discount_account']))
- {
- $company_record = get_company_prefs();
-
- // We use the Item Sales Account as default!
- // $_POST['sales_account'] = $company_record["default_sales_act"];
- $_POST['sales_account'] = $_POST['notes'] = '';
- $_POST['sales_discount_account'] = $company_record['default_sales_discount_act'];
- $_POST['receivables_account'] = $company_record['debtors_act'];
- $_POST['payment_discount_account'] = $company_record['default_prompt_payment_act'];
-
- }
-
-}
-hidden('selected_id', $selected_id);
-hidden('branch_code');
-hidden('popup', @$_REQUEST['popup']);
-
-table_section_title(_("Name and Contact"));
-
-text_row(_("Branch Name:"), 'br_name', null, 35, 40);
-text_row(_("Branch Short Name:"), 'br_ref', null, 30, 30);
-text_row(_("Contact Person:"), 'contact_name', null, 35, 40);
-
-text_row(_("Phone Number:"), 'phone', null, 32, 30);
-text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
-text_row(_("Fax Number:"), 'fax', null, 32, 30);
-
-email_row(_("E-mail:"), 'email', null, 35, 55);
-
-table_section_title(_("Sales"));
-
-sales_persons_list_row( _("Sales Person:"), 'salesman', null);
-
-languages_list_row( _("Document Language:"), 'rep_lang', null, _("Customer default"));
-
-sales_areas_list_row( _("Sales Area:"), 'area', null);
-
-sales_groups_list_row(_("Sales Group:"), 'group_no', null, true);
-
-locations_list_row(_("Default Inventory Location:"), 'default_location', null);
-
-shippers_list_row(_("Default Shipping Company:"), 'default_ship_via', null);
-
-tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
-
-yesno_list_row(_("Disable this Branch:"), 'disable_trans', null);
-
-table_section(2);
-
-table_section_title(_("GL Accounts"));
-
-// 2006-06-14. Changed gl_al_accounts_list to have an optional all_option 'Use Item Sales Accounts'
-gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', null, false, false, true);
-
-gl_all_accounts_list_row(_("Sales Discount Account:"), 'sales_discount_account');
-
-gl_all_accounts_list_row(_("Accounts Receivable Account:"), 'receivables_account');
-
-gl_all_accounts_list_row(_("Prompt Payment Discount Account:"), 'payment_discount_account');
-
-table_section_title(_("Addresses"));
-
-textarea_row(_("Mailing Address:"), 'br_post_address', null, 35, 4);
-
-textarea_row(_("Billing Address:"), 'br_address', null, 35, 4);
-
-textarea_row(_("General Notes:"), 'notes', null, 35, 4);
-
-end_outer_table(1);
-
-submit_add_or_update_center($selected_id == -1, '', 'both');
end_form();
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/banking.inc");
include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/includes/ui/contacts_view.inc");
if (isset($_GET['debtor_no']))
{
$_POST['customer_id'] = $_GET['debtor_no'];
}
-$new_customer = (!isset($_POST['customer_id']) || $_POST['customer_id'] == "");
+
+$selected_id = get_post('customer_id','');
//--------------------------------------------------------------------------------------------
function can_process()
//--------------------------------------------------------------------------------------------
-function handle_submit()
+function handle_submit(&$selected_id)
{
- global $path_to_root, $new_customer, $Ajax;
+ global $path_to_root, $Ajax;
if (!can_process())
return;
- if ($new_customer == false)
+ if ($selected_id)
{
update_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'],
- $_POST['tax_id'], $_POST['curr_code'], $_POST['email'], $_POST['dimension_id'], $_POST['dimension2_id'],
+ $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'],
$_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100,
- input_num('credit_limit'), $_POST['sales_type'], $_POST['notes'], $_POST['rep_lang']);
+ input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
update_record_status($_POST['customer_id'], $_POST['inactive'],
'debtors_master', 'debtor_no');
begin_transaction();
add_customer($_POST['CustName'], $_POST['cust_ref'], $_POST['address'],
- $_POST['tax_id'], $_POST['curr_code'], $_POST['email'], $_POST['dimension_id'], $_POST['dimension2_id'],
+ $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'],
$_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100,
- input_num('credit_limit'), $_POST['sales_type'], $_POST['notes'], $_POST['rep_lang']);
+ input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
- $_POST['customer_id'] = db_insert_id();
- $new_customer = false;
- commit_transaction();
+ $selected_id = $_POST['customer_id'] = db_insert_id();
+ commit_transaction();
display_notification(_("A new customer has been added."));
-
$Ajax->activate('_page_body');
}
}
if (isset($_POST['submit']))
{
- handle_submit();
+ handle_submit($selected_id);
}
//--------------------------------------------------------------------------------------------
if (isset($_POST['delete']))
{
- //the link to delete a selected record was clicked instead of the submit button
-
$cancel_delete = 0;
// PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
- $sel_id = db_escape($_POST['customer_id']);
- if (key_in_foreign_table($sel_id, 'debtor_trans', 'debtor_no', true))
+ if (key_in_foreign_table($selected_id, 'debtor_trans', 'debtor_no', true))
{
$cancel_delete = 1;
display_error(_("This customer cannot be deleted because there are transactions that refer to it."));
}
else
{
- if (key_in_foreign_table($sel_id, 'sales_orders', 'debtor_no', true))
+ if (key_in_foreign_table($selected_id, 'sales_orders', 'debtor_no', true))
{
$cancel_delete = 1;
display_error(_("Cannot delete the customer record because orders have been created against it."));
}
else
{
- if (key_in_foreign_table($sel_id, 'cust_branch', 'debtor_no', true))
+ if (key_in_foreign_table($selected_id, 'cust_branch', 'debtor_no', true))
{
$cancel_delete = 1;
display_error(_("Cannot delete this customer because there are branch records set up against it."));
if ($cancel_delete == 0)
{ //ie not cancelled the delete as a result of above tests
- delete_customer($sel_id, true);
+ delete_customer($selected_id);
display_notification(_("Selected customer has been deleted."));
unset($_POST['customer_id']);
- $new_customer = true;
+ $selected_id = '';
$Ajax->activate('_page_body');
} //end if Delete Customer
}
+function customer_settings($selected_id)
+{
+ global $SysPrefs, $path_to_root;
+
+ if (!$selected_id)
+ {
+ $_POST['CustName'] = $_POST['cust_ref'] = $_POST['address'] = $_POST['tax_id'] = '';
+ $_POST['dimension_id'] = 0;
+ $_POST['dimension2_id'] = 0;
+ $_POST['sales_type'] = -1;
+ $_POST['curr_code'] = get_company_currency();
+ $_POST['credit_status'] = -1;
+ $_POST['payment_terms'] = $_POST['notes'] = '';
+
+ $_POST['discount'] = $_POST['pymt_discount'] = percent_format(0);
+ $_POST['credit_limit'] = price_format($SysPrefs->default_credit_limit());
+ }
+ else
+ {
+ $myrow = get_customer($selected_id);
+
+ $_POST['CustName'] = $myrow["name"];
+ $_POST['cust_ref'] = $myrow["debtor_ref"];
+ $_POST['address'] = $myrow["address"];
+ $_POST['tax_id'] = $myrow["tax_id"];
+ $_POST['dimension_id'] = $myrow["dimension_id"];
+ $_POST['dimension2_id'] = $myrow["dimension2_id"];
+ $_POST['sales_type'] = $myrow["sales_type"];
+ $_POST['curr_code'] = $myrow["curr_code"];
+ $_POST['credit_status'] = $myrow["credit_status"];
+ $_POST['payment_terms'] = $myrow["payment_terms"];
+ $_POST['discount'] = percent_format($myrow["discount"] * 100);
+ $_POST['pymt_discount'] = percent_format($myrow["pymt_discount"] * 100);
+ $_POST['credit_limit'] = price_format($myrow["credit_limit"]);
+ $_POST['notes'] = $myrow["notes"];
+ $_POST['inactive'] = $myrow["inactive"];
+ }
+
+ start_outer_table(TABLESTYLE2);
+ table_section(1);
+ table_section_title(_("Name and Address"));
+
+ text_row(_("Customer Name:"), 'CustName', $_POST['CustName'], 40, 80);
+ text_row(_("Customer Short Name:"), 'cust_ref', null, 30, 30);
+ textarea_row(_("Address:"), 'address', $_POST['address'], 35, 5);
+
+ text_row(_("GSTNo:"), 'tax_id', null, 40, 40);
+
+
+ if (!$selected_id)
+ {
+ currencies_list_row(_("Customer's Currency:"), 'curr_code', $_POST['curr_code']);
+ }
+ else
+ {
+ label_row(_("Customer's Currency:"), $_POST['curr_code']);
+ hidden('curr_code', $_POST['curr_code']);
+ }
+ sales_types_list_row(_("Sales Type/Price List:"), 'sales_type', $_POST['sales_type']);
+
+ if($selected_id)
+ record_status_list_row(_("Customer status:"), 'inactive');
+
+ table_section(2);
+
+ table_section_title(_("Sales"));
+
+ percent_row(_("Discount Percent:"), 'discount', $_POST['discount']);
+ percent_row(_("Prompt Payment Discount Percent:"), 'pymt_discount', $_POST['pymt_discount']);
+ amount_row(_("Credit Limit:"), 'credit_limit', $_POST['credit_limit']);
+
+ payment_terms_list_row(_("Payment Terms:"), 'payment_terms', $_POST['payment_terms']);
+ credit_status_list_row(_("Credit Status:"), 'credit_status', $_POST['credit_status']);
+ $dim = get_company_pref('use_dimension');
+ if ($dim >= 1)
+ dimensions_list_row(_("Dimension")." 1:", 'dimension_id', $_POST['dimension_id'], true, " ", false, 1);
+ if ($dim > 1)
+ dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', $_POST['dimension2_id'], true, " ", false, 2);
+ if ($dim < 1)
+ hidden('dimension_id', 0);
+ if ($dim < 2)
+ hidden('dimension2_id', 0);
+
+ if ($selected_id) {
+ start_row();
+ echo '<td>'._('Customer branches').':</td>';
+ hyperlink_params_td($path_to_root . "/sales/manage/customer_branches.php",
+ '<b>'. (@$_REQUEST['popup'] ? _("Select or &Add") : _("&Add or Edit ")).'</b>',
+ "debtor_no=".$selected_id.(@$_REQUEST['popup'] ? '&popup=1':''));
+ end_row();
+ }
+
+ textarea_row(_("General Notes:"), 'notes', null, 35, 5);
+ end_outer_table(1);
+
+ div_start('controls');
+ if (!$selected_id)
+ {
+ submit_center('submit', _("Add New Customer"), true, '', 'default');
+ }
+ else
+ {
+ submit_center_first('submit', _("Update Customer"),
+ _('Update customer data'), @$_REQUEST['popup'] ? true : 'default');
+ submit_return('select', $selected_id, _("Select this customer and return to document entry."));
+ submit_center_last('delete', _("Delete Customer"),
+ _('Delete customer data if have been never used'), true);
+ }
+ div_end();
+}
+
+//--------------------------------------------------------------------------------------------
+
check_db_has_sales_types(_("There are no sales types defined. Please define at least one sales type before adding a customer."));
start_form();
check_cells(_("Show inactive:"), 'show_inactive', null, true);
end_row();
end_table();
+
if (get_post('_show_inactive_update')) {
$Ajax->activate('customer_id');
set_focus('customer_id');
hidden('customer_id');
}
-if ($new_customer)
-{
- $_POST['CustName'] = $_POST['cust_ref'] = $_POST['address'] = $_POST['tax_id'] = '';
- $_POST['dimension_id'] = 0;
- $_POST['dimension2_id'] = 0;
- $_POST['sales_type'] = -1;
- $_POST['rep_lang'] = '';
- $_POST['email'] = '';
- $_POST['curr_code'] = get_company_currency();
- $_POST['credit_status'] = -1;
- $_POST['payment_terms'] = $_POST['notes'] = '';
-
- $_POST['discount'] = $_POST['pymt_discount'] = percent_format(0);
- $_POST['credit_limit'] = price_format($SysPrefs->default_credit_limit());
- $_POST['inactive'] = 0;
-}
-else
-{
- $myrow = get_customer($_POST['customer_id']);
-
- $_POST['CustName'] = $myrow["name"];
- $_POST['cust_ref'] = $myrow["debtor_ref"];
- $_POST['address'] = $myrow["address"];
- $_POST['tax_id'] = $myrow["tax_id"];
- $_POST['email'] = $myrow["email"];
- $_POST['dimension_id'] = $myrow["dimension_id"];
- $_POST['dimension2_id'] = $myrow["dimension2_id"];
- $_POST['sales_type'] = $myrow["sales_type"];
- $_POST['rep_lang'] = $myrow["rep_lang"];
- $_POST['curr_code'] = $myrow["curr_code"];
- $_POST['credit_status'] = $myrow["credit_status"];
- $_POST['payment_terms'] = $myrow["payment_terms"];
- $_POST['discount'] = percent_format($myrow["discount"] * 100);
- $_POST['pymt_discount'] = percent_format($myrow["pymt_discount"] * 100);
- $_POST['credit_limit'] = price_format($myrow["credit_limit"]);
- $_POST['notes'] = $myrow["notes"];
- $_POST['inactive'] = $myrow["inactive"];
-}
-
-start_outer_table(TABLESTYLE2);
-table_section(1);
-table_section_title(_("Name and Address"));
-
-text_row(_("Customer Name:"), 'CustName', $_POST['CustName'], 40, 80);
-text_row(_("Customer Short Name:"), 'cust_ref', null, 30, 30);
-textarea_row(_("Address:"), 'address', $_POST['address'], 35, 5);
-
-email_row(_("E-mail:"), 'email', null, 40, 40);
-text_row(_("GSTNo:"), 'tax_id', null, 40, 40);
-
-
-if ($new_customer)
-{
- currencies_list_row(_("Customer's Currency:"), 'curr_code', $_POST['curr_code']);
-}
-else
-{
- label_row(_("Customer's Currency:"), $_POST['curr_code']);
- hidden('curr_code', $_POST['curr_code']);
-}
-sales_types_list_row(_("Sales Type/Price List:"), 'sales_type', $_POST['sales_type']);
-languages_list_row( _("Document Language:"), 'rep_lang', $_POST['rep_lang'], _('System default'));
-
-table_section(2);
-
-table_section_title(_("Sales"));
-
-percent_row(_("Discount Percent:"), 'discount', $_POST['discount']);
-percent_row(_("Prompt Payment Discount Percent:"), 'pymt_discount', $_POST['pymt_discount']);
-amount_row(_("Credit Limit:"), 'credit_limit', $_POST['credit_limit']);
-
-payment_terms_list_row(_("Payment Terms:"), 'payment_terms', $_POST['payment_terms']);
-credit_status_list_row(_("Credit Status:"), 'credit_status', $_POST['credit_status']);
-$dim = get_company_pref('use_dimension');
-if ($dim >= 1)
- dimensions_list_row(_("Dimension")." 1:", 'dimension_id', $_POST['dimension_id'], true, " ", false, 1);
-if ($dim > 1)
- dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', $_POST['dimension2_id'], true, " ", false, 2);
-if ($dim < 1)
- hidden('dimension_id', 0);
-if ($dim < 2)
- hidden('dimension2_id', 0);
-
-if (!$new_customer) {
- start_row();
- echo '<td>'._('Customer branches').':</td>';
- hyperlink_params_td($path_to_root . "/sales/manage/customer_branches.php",
- '<b>'. (@$_REQUEST['popup'] ? _("Select or &Add") : _("&Add or Edit ")).'</b>',
- "debtor_no=".$_POST['customer_id'].(@$_REQUEST['popup'] ? '&popup=1':''));
- end_row();
-
-}
+if (!$selected_id)
+ unset($_POST['_tabs_sel']); // force settings tab for new customer
-textarea_row(_("General Notes:"), 'notes', null, 35, 5);
-record_status_list_row(_("Customer status:"), 'inactive');
-end_outer_table(1);
+tabbed_content_start('tabs', array(
+ 'settings' => array('&General settings', $selected_id),
+ 'contacts' => array('&Contacts', $selected_id),
+ ));
+
+ switch (get_post('_tabs_sel')) {
+ default:
+ case 'settings':
+ customer_settings($selected_id);
+ break;
+ case 'contacts':
+ $contacts = new contacts('contacts', $selected_id, 'customer');
+ $contacts->show();
+ break;
+ case 'orders':
+ };
+br();
+tabbed_content_end();
-div_start('controls');
-if ($new_customer)
-{
- submit_center('submit', _("Add New Customer"), true, '', 'default');
-}
-else
-{
- submit_center_first('submit', _("Update Customer"),
- _('Update customer data'), @$_REQUEST['popup'] ? true : 'default');
- submit_return('select', get_post('customer_id'), _("Select this customer and return to document entry."));
- submit_center_last('delete', _("Delete Customer"),
- _('Delete customer data if have been never used'), true);
-}
-div_end();
hidden('popup', @$_REQUEST['popup']);
end_form();
end_page();
return false;
}
}
+ //remove obsolete and temporary columns.
+ // this have to be done here as db_import rearranges alter query order
+ $dropcol = array(
+ 'crm_persons' => array('tmp_id','tmp_class'),
+ 'debtors_master' => array('email'),
+ 'cust_branch' => array('phone', 'phone2', 'fax', 'email'),
+ 'suppliers' => array('phone', 'phone2', 'fax', 'email')
+ );
+ foreach($dropcol as $table => $columns)
+ foreach($columns as $col) {
+ if (db_query("ALTER TABLE `{$pref}{$table}` DROP `$col`")==false) {
+ display_error("Cannot drop {$table}.{$col} column:<br>".db_error_msg($db));
+ return false;
+ }
+ }
+
// remove old preferences table after upgrade script has been executed
- $sql = "DROP TABLE IF EXISTS `".$pref."company`";
+ $sql = "DROP TABLE IF EXISTS `{$pref}company`";
return db_query($sql) && update_company_prefs(array('version_id'=>'2.3'));
}
.
UPDATE `0_chart_types` SET parent='' WHERE parent='0' OR parent='-1';
-ALTER TABLE `0_debtors_master` ADD COLUMN `rep_lang` char(5) default NULL;
-UPDATE `0_debtors_master` set `rep_lang`= 'en_GB' WHERE `curr_code`<>(SELECT value FROM `0_sys_prefs` WHERE name='curr_default');
-
-ALTER TABLE `0_cust_branch` ADD COLUMN `rep_lang` char(5) default NULL;
-
-ALTER TABLE `0_suppliers` ADD COLUMN `rep_lang` char(5) default NULL;
-UPDATE `0_suppliers` set `rep_lang`= 'en_GB' WHERE `curr_code`<>(SELECT value FROM `0_sys_prefs` WHERE name='curr_default');
-
INSERT INTO `0_sys_prefs` (name, category, type, length, value) VALUES ('auto_curr_reval','setup.company', 'smallint','6', '1');
+
+DROP TABLE IF EXISTS `0_crm_categories`;
+CREATE TABLE `0_crm_categories` (
+ `id` int(11) NOT NULL auto_increment COMMENT 'pure technical key',
+ `type` varchar(20) NOT NULL COMMENT 'contact type e.g. customer' ,
+ `action` varchar(20) NOT NULL COMMENT 'detailed usage e.g. department',
+ `name` varchar(30) NOT NULL COMMENT 'for category selector',
+ `description` tinytext NOT NULL COMMENT 'usage description',
+ `system` tinyint(1) NOT NULL default '0' COMMENT 'nonzero for core system usage',
+ `inactive` tinyint(1) NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`type`, `action`),
+ UNIQUE KEY(`type`, `name`)
+) TYPE=InnoDB ;
+
+
+INSERT INTO `0_crm_categories` VALUES (1, 'cust_branch', 'general', 'General', 'General contact data for customer branch (overrides company setting)', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (2, 'cust_branch', 'invoice', 'Invoices', 'Invoice posting (overrides company setting)', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (3, 'cust_branch', 'order', 'Orders', 'Order confirmation (overrides company setting)', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (4, 'cust_branch', 'delivery', 'Deliveries', 'Delivery coordination (overrides company setting)', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (5, 'customer', 'general', 'General', 'General contact data for customer', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (6, 'customer', 'order', 'Orders', 'Order confirmation', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (7, 'customer', 'delivery', 'Deliveries', 'Delivery coordination', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (8, 'customer', 'invoice', 'Invoices', 'Invoice posting', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (9, 'supplier', 'general', 'General', 'General contact data for supplier', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (10,'supplier', 'order', 'Orders', 'Order confirmation', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (11,'supplier', 'delivery', 'Deliveries', 'Delivery coordination', 1, 0);
+INSERT INTO `0_crm_categories` VALUES (12,'supplier', 'invoice', 'Invoices', 'Invoice posting', 1, 0);
+
+DROP TABLE IF EXISTS `0_crm_persons`;
+
+CREATE TABLE `0_crm_persons` (
+ `id` int(11) NOT NULL auto_increment,
+ `ref` varchar(30) NOT NULL,
+ `name` varchar(60) NOT NULL,
+ `name2` varchar(60) default NULL,
+ `address` tinytext default NULL,
+ `phone` varchar(30) default NULL,
+ `phone2` varchar(30) default NULL,
+ `fax` varchar(30) default NULL,
+ `email` varchar(100) default NULL,
+ `lang` char(5) default NULL,
+ `notes` tinytext NOT NULL,
+ `tmp_id` varchar(11),
+ `tmp_class` varchar(20),
+ `inactive` tinyint(1) NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ KEY (`ref`)
+) TYPE=InnoDB AUTO_INCREMENT=1 ;
+
+DROP TABLE IF EXISTS `0_crm_contacts`;
+
+CREATE TABLE `0_crm_contacts` (
+ `id` int(11) NOT NULL auto_increment,
+ `person_id` int(11) NOT NULL default '0' COMMENT 'foreign key to crm_contacts',
+ `type` varchar(20) NOT NULL COMMENT 'foreign key to crm_categories',
+ `action` varchar(20) NOT NULL COMMENT 'foreign key to crm_categories',
+ `entity_id` varchar(11) NULL COMMENT 'entity id in related class table',
+ PRIMARY KEY (`id`),
+ KEY(`type`, `action`)
+) TYPE=InnoDB ;
+
+
+#
+# tmp_id, tmp_class fields are used temporarily during upgrade to makethe process easier
+#
+INSERT INTO `0_crm_persons` (`ref`, `email`, `lang`, `tmp_id`, `tmp_class`)
+ SELECT `debtor_ref`, `email`, if(`curr_code`=d.`lang`, NULL, 'en_GB'), `debtor_no`, 'customer'
+ FROM `0_debtors_master`,
+ (SELECT `value` as lang FROM `0_sys_prefs` WHERE name='curr_default') d;
+
+INSERT INTO `0_crm_persons` (`ref`, `name`, `address`, `phone`, `phone2`,
+ `fax`,`email`, `tmp_id`,`tmp_class`)
+ SELECT `branch_ref`, `contact_name`, `br_address`, `phone`, `phone2`,
+ `fax`,`email`,`branch_code`, 'cust_branch' FROM `0_cust_branch`;
+
+INSERT INTO `0_crm_persons` (`ref`, `name`, `address`, `phone`, `phone2`,
+ `fax`,`email`,`lang`,`tmp_id`,`tmp_class`)
+ SELECT `supp_ref`, `contact`, `supp_address`, `phone`, `phone2`,
+ `fax`,`email`,if(`curr_code`=d.`lang`, NULL, 'en_GB'),`supplier_id`,'supplier'
+ FROM `0_suppliers`,
+ (SELECT `value` as lang FROM `0_sys_prefs` WHERE name='curr_default') d;
+
+
+INSERT INTO `0_crm_contacts` (`person_id`, `type`, `action`, `entity_id`)
+ SELECT `id`, `tmp_class`, 'general', `tmp_id`
+ FROM `0_crm_persons`;
INSERT INTO `0_payment_terms` VALUES ('1', 'Due 15th Of the Following Month', '0', '17', '0');
INSERT INTO `0_payment_terms` VALUES ('2', 'Due By End Of The Following Month', '0', '30', '0');
INSERT INTO `0_payment_terms` VALUES ('3', 'Payment due within 10 days', '10', '0', '0');
-INSERT INTO `0_payment_terms` VALUES ('4', 'Cash Only', '1', '0', '0');
+INSERT INTO `0_payment_terms` VALUES ('4', 'Cash Only', '0', '0', '0');
### Structure of table `0_prices` ###
INSERT INTO `0_payment_terms` VALUES ('1', 'Due 15th Of the Following Month', '0', '17', '0');
INSERT INTO `0_payment_terms` VALUES ('2', 'Due By End Of The Following Month', '0', '30', '0');
INSERT INTO `0_payment_terms` VALUES ('3', 'Payment due within 10 days', '10', '0', '0');
-INSERT INTO `0_payment_terms` VALUES ('4', 'Cash Only', '1', '0', '0');
+INSERT INTO `0_payment_terms` VALUES ('4', 'Cash Only', '0', '0', '0');
### Structure of table `0_prices` ###