From ab6179fbb1f355ec702a33cc32eefd7a34e64961 Mon Sep 17 00:00:00 2001 From: Tim Schofield Date: Sat, 28 Apr 2012 13:34:17 +0100 Subject: [PATCH] Add scripts to help link the weberp and care2x insurance companies --- KCMCInsuranceCompanyDetails.php | 24 ++- Z_ChangeInsuranceCompanyCode.php | 266 +++++++++++++++++++++++++++++++ includes/IndexArray.php | 2 + sql/mysql/updates/121.php | 10 ++ 4 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 Z_ChangeInsuranceCompanyCode.php create mode 100644 sql/mysql/updates/121.php diff --git a/KCMCInsuranceCompanyDetails.php b/KCMCInsuranceCompanyDetails.php index bd2919a30..7f0ea109f 100644 --- a/KCMCInsuranceCompanyDetails.php +++ b/KCMCInsuranceCompanyDetails.php @@ -459,7 +459,29 @@ echo '
'; if (!isset($DebtorNo)) { - echo ''; + if ($_SESSION['Care2xDatabase']=='None') { + echo ' + + + '; + } else { + $sql = "SELECT id, + name + FROM ".$_SESSION['Care2xDatabase'].".care_tz_company"; + $result = DB_query($sql, $db); + echo ' + + '; + } } else { echo ''; $sql = "SELECT debtorsmaster.debtorno, diff --git a/Z_ChangeInsuranceCompanyCode.php b/Z_ChangeInsuranceCompanyCode.php new file mode 100644 index 000000000..49630bb3c --- /dev/null +++ b/Z_ChangeInsuranceCompanyCode.php @@ -0,0 +1,266 @@ +
' . _('The customer code') . ': ' . $_POST['OldDebtorNo'] . ' ' . _('does not currently exist as a customer code in the system'),'error'); + include('includes/footer.inc'); + exit; + } + + + if ($_POST['NewDebtorNo']==''){ + prnMsg(_('The new customer code to change the old code to must be entered as well'),'error'); + include('includes/footer.inc'); + exit; + } +/*Now check that the new code doesn't already exist */ + $result=DB_query("SELECT debtorno FROM debtorsmaster WHERE debtorno='" . $_POST['NewDebtorNo'] . "'",$db); + if (DB_num_rows($result)!=0){ + prnMsg(_('The replacement customer code') .': ' . $_POST['NewDebtorNo'] . ' ' . _('already exists as a customer code in the system') . ' - ' . _('a unique customer code must be entered for the new code'),'error'); + include('includes/footer.inc'); + exit; + } + + $result = DB_Txn_Begin($db); + + prnMsg(_('Inserting the new debtors master record'),'info'); + $sql = "INSERT INTO debtorsmaster (`debtorno`, + `name`, + `address1`, + `address2`, + `address3`, + `address4`, + `currcode`, + `salestype`, + `clientsince`, + `holdreason`, + `paymentterms`, + `discount`, + `discountcode`, + `pymtdiscount`, + `lastpaid`, + `lastpaiddate`, + `creditlimit`, + `invaddrbranch`, + `ediinvoices`, + `ediorders`, + `edireference`, + `editransport`, + `ediaddress`, + `ediserveruser`, + `ediserverpwd`, + `typeid`) + SELECT '" . $_POST['NewDebtorNo'] . "', + `name`, + `address1`, + `address2`, + `address3`, + `address4`, + `currcode`, + `salestype`, + `clientsince`, + `holdreason`, + `paymentterms`, + `discount`, + `discountcode`, + `pymtdiscount`, + `lastpaid`, + `lastpaiddate`, + `creditlimit`, + `invaddrbranch`, + `ediinvoices`, + `ediorders`, + `edireference`, + `editransport`, + `ediaddress`, + `ediserveruser`, + `ediserverpwd`, + `typeid` + FROM debtorsmaster + WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $DbgMsg =_('The SQL that failed was'); + $ErrMsg = _('The SQL to insert the new debtors master record failed') . ', ' . _('the SQL statement was'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg(_('Inserting new customer branch records'),'info'); + $sql = "INSERT INTO custbranch ( `branchcode`, + `debtorno`, + `brname`, + `braddress1`, + `braddress2`, + `braddress3`, + `braddress4`, + `braddress5`, + `braddress6`, + `estdeliverydays`, + `area`, + `salesman`, + `fwddate`, + `phoneno`, + `faxno`, + `contactname`, + `email`, + `defaultlocation`, + `taxgroupid`, + `disabletrans`, + `brpostaddr1`, + `brpostaddr2`, + `brpostaddr3`, + `brpostaddr4`, + `brpostaddr5`, + `brpostaddr6`, + `defaultshipvia`, + `custbranchcode`) + SELECT branchcode, + '" . $_POST['NewDebtorNo'] . "', + `brname`, + `braddress1`, + `braddress2`, + `braddress3`, + `braddress4`, + `braddress5`, + `braddress6`, + `estdeliverydays`, + `area`, + `salesman`, + `fwddate`, + `phoneno`, + `faxno`, + `contactname`, + `email`, + `defaultlocation`, + `taxgroupid`, + `disabletrans`, + `brpostaddr1`, + `brpostaddr2`, + `brpostaddr3`, + `brpostaddr4`, + `brpostaddr5`, + `brpostaddr6`, + `defaultshipvia`, + `custbranchcode` + FROM custbranch + WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to insert new customer branch records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + prnMsg(_('Changing debtor transaction records'),'info'); + + $sql = "UPDATE debtortrans SET debtorNo='" . $_POST['NewDebtorNo'] . "' WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to update debtor transaction records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg(_('Changing sales analysis records'),'info'); + + $sql = "UPDATE salesanalysis SET cust='" . $_POST['NewDebtorNo'] . "' WHERE cust='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to update Sales Analysis records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg (_('Changing order delivery differences records'),'info'); + $sql = "UPDATE orderdeliverydifferenceslog SET debtorno='" . $_POST['NewDebtorNo'] . "' WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + $ErrMsg = _('The SQL to update order delivery differences records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + + prnMsg(_('Changing pricing records'),'info'); + $sql = "UPDATE prices SET debtorno='" . $_POST['NewDebtorNo'] . "' WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to update the pricing records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg(_('Changing sales orders records'),'info'); + $sql = "UPDATE salesorders SET debtorno='" . $_POST['NewDebtorNo'] . "' WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to update the sales order header records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg( _('Changing stock movement records'),'info'); + $sql = "UPDATE stockmoves SET debtorno='" . $_POST['NewDebtorNo'] . "' WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + $ErrMsg = _('The SQL to update the sales order header records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg(_('Changing user default customer records'),'info'); + $sql = "UPDATE www_users SET customerid='" . $_POST['NewDebtorNo'] . "' WHERE customerid='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to update the user records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + prnMsg(_('Changing the customer code in contract header records'),'info'); + $sql = "UPDATE contracts SET debtorno='" . $_POST['NewDebtorNo'] . "' WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to update contract header records failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + $result = DB_IgnoreForeignKeys($db); + + prnMsg(_('Deleting the old customer branch records from the CustBranch table'),'info'); + $sql = "DELETE FROM custbranch WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + $ErrMsg = _('The SQL to delete the old CustBranch records for the old debtor record failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + + prnMsg(_('Deleting the customer code from the DebtorsMaster table'),'info'); + $sql = "DELETE FROM debtorsmaster WHERE debtorno='" . $_POST['OldDebtorNo'] . "'"; + + $ErrMsg = _('The SQL to delete the old debtor record failed'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + + $result = DB_Txn_Commit($db); + $result = DB_ReinstateForeignKeys($db); + +} + +echo ''; +echo ''; +echo '

' . ' ' . $title . '

'; + +$sql="SELECT debtorno, name FROM debtorsmaster WHERE debtorno not like '10%'"; +$result = DB_query($sql, $db); +echo '
' . _('Company Code') . ':
' . _('Company Code') . ':
' . _('Insurance Company From Care2x') . ':
' . _('Company Code') . ':' . $DebtorNo . '
'; +echo ''; +echo ''; + +$sql = "SELECT id, + name + FROM ".$_SESSION['Care2xDatabase'].".care_tz_company"; +$result = DB_query($sql, $db); +echo ' + +
' . _('Existing Debtor Code') . ':
' . _('Insurance Company From Care2x') . ':
'; + +echo '
'; + +echo ''; + +include('includes/footer.inc'); + +?> \ No newline at end of file diff --git a/includes/IndexArray.php b/includes/IndexArray.php index f49debf93..3e764f241 100644 --- a/includes/IndexArray.php +++ b/includes/IndexArray.php @@ -555,6 +555,7 @@ ); $MenuItems['Utilities']['Transactions']['Caption'] = array (_('Change A Customer Code'), + _('Change An Insurance Company Code'), _('Change A Customer Branch Code'), _('Change An Inventory Item Code'), _('Change A Supplier Code'), @@ -564,6 +565,7 @@ _('Reverse all supplier payments on a specified date')); $MenuItems['Utilities']['Transactions']['URL'] = array ('/Z_ChangeCustomerCode.php', + '/Z_ChangeInsuranceCompanyCode.php', '/Z_ChangeBranchCode.php', '/Z_ChangeStockCode.php', '/Z_ChangeSupplierCode.php', diff --git a/sql/mysql/updates/121.php b/sql/mysql/updates/121.php new file mode 100644 index 000000000..4fa7a2640 --- /dev/null +++ b/sql/mysql/updates/121.php @@ -0,0 +1,10 @@ + \ No newline at end of file