Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using LumenWorks.Framework.IO.Csv;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.OleDb;
- using System.Data.SqlClient;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HonanImportScript {
- class Program {
- //================================================================================
- public const string WINDOWS_AUTHENTICATION_USERNAME = "WINDOWS";
- //--------------------------------------------------------------------------------
- public enum Team {
- None,
- All,
- RisksmartGCC,
- RisksmartProperty,
- PropertyClaims,
- GCCClaims
- }
- public enum WinbeatLedger {
- None,
- Melbourne,
- RealEstate,
- Underwriting
- }
- public enum Operation {
- None,
- Insert,
- Update
- }
- //================================================================================
- private static StreamWriter sLogWriter = null;
- private static StreamWriter sSummaryLogWriter = null;
- private static string sInforConnectionString;
- private static string sWBRisksmartPropertyConnectionString;
- private static string sWBRealEstateConnectionString;
- private static string sWBMelbourneConnectionString;
- private static Dictionary<string, string> sClaimNumberSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sPolicyNumberSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sRGCPolicyNumberSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sRSPPolicyNumberSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sPRCPolicyNumberSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sGCCPolicyNumberSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sAccountNameSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sCustomerCodeSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sUnderwriterCodeSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sAssociateCodeSubstitutions = new Dictionary<string, string>();
- private static Dictionary<string, string> sUserNameSubstitutions = new Dictionary<string, string>();
- private static Team sTeam = Team.None;
- private static string sTime = null;
- private static int sLine = -1;
- private static Dictionary<string, Tuple<int, int>> sMissingAccounts = new Dictionary<string, Tuple<int, int>>();
- private static Dictionary<string, Tuple<int, int>> sMissingAssociates = new Dictionary<string, Tuple<int, int>>();
- private static Dictionary<string, Tuple<int, int>> sMissingUnderwriters = new Dictionary<string, Tuple<int, int>>();
- private static Dictionary<string, Tuple<int, int>> sMissingCustomers = new Dictionary<string, Tuple<int, int>>();
- private static Dictionary<string, Tuple<int, int>> sMissingPolicies = new Dictionary<string, Tuple<int, int>>();
- private static Dictionary<string, Tuple<int, int>> sMissingClaims = new Dictionary<string, Tuple<int, int>>();
- private static Dictionary<string, Tuple<int, int>> sMissingUsers = new Dictionary<string, Tuple<int, int>>();
- //================================================================================
- //--------------------------------------------------------------------------------
- [STAThread]
- static void Main(string[] args) {
- // Console
- Console.WindowWidth = 160;
- //Console.SetBufferSize(Console.BufferWidth, 15000);
- // Open logs
- OpenLog("log.txt");
- OpenSummaryLog("summarylog.txt");
- // Log session
- Log("\n################################################################################\n");
- // Arguments
- if (args.Length == 0) {
- // Launcher
- Launcher launcher = new Launcher();
- launcher.ShowDialog();
- }
- else if (args.Length == 5) {
- // Team
- switch (args[0].ToLower()) {
- case "risksmart gcc": case "risksmart_gcc": case "risksmartgcc": sTeam = Team.RisksmartGCC; break;
- case "risksmart property": case "risksmart_property": case "risksmartproperty": sTeam = Team.RisksmartProperty; break;
- case "property claims": case "property_claims": case "propertyclaims": sTeam = Team.PropertyClaims; break;
- case "gcc claims": case "gcc_claims": case "gccclaims": sTeam = Team.GCCClaims; break;
- default: sTeam = Team.All; break;
- }
- // TODO: Add winbeat connection details here
- // Infor connection
- SetInforConnectionDetails(args[1], args[2], args[3], args[4]);
- // Import
- Import(new ImportConfig(sTeam));
- }
- else {
- Log("Usage: [team], [source], [database], [username], [password]");
- return;
- }
- // Close logs
- CloseLog();
- CloseSummaryLog();
- }
- // INFOR CONNECTION ================================================================================
- //--------------------------------------------------------------------------------
- public static void SetInforConnectionDetails(string source, string database, string username, string password) {
- sInforConnectionString = "Provider=SLXOLEDB.1;Data Source=" + source + ";Initial Catalog=" + database + ";" +
- "User ID=" + username + ";Password=" + password + ";Persist Security Info=True";
- }
- // WINBEAT CONNECTION ================================================================================
- //--------------------------------------------------------------------------------
- public static void SetWinBEATConnectionDetails(string instance, string username, string password, string risksmartPropertyDatabase, string realEstateDatabase, string melbourneDatabase) {
- // Risksmart property
- sWBRisksmartPropertyConnectionString = "Data Source=" + instance + ";Initial Catalog=" + risksmartPropertyDatabase + ";";
- if (!username.Equals(WINDOWS_AUTHENTICATION_USERNAME))
- sWBRisksmartPropertyConnectionString += "User ID=" + username + ";Password=" + password + ";Persist Security Info=True";
- else
- sWBRisksmartPropertyConnectionString += "Integrated Security=SSPI";
- // Real estate
- sWBRealEstateConnectionString = "Data Source=" + instance + ";Initial Catalog=" + realEstateDatabase + ";";
- if (!username.Equals(WINDOWS_AUTHENTICATION_USERNAME))
- sWBRealEstateConnectionString += "User ID=" + username + ";Password=" + password + ";Persist Security Info=True";
- else
- sWBRealEstateConnectionString += "Integrated Security=SSPI";
- // Melbourne
- sWBMelbourneConnectionString = "Data Source=" + instance + ";Initial Catalog=" + melbourneDatabase + ";";
- if (!username.Equals(WINDOWS_AUTHENTICATION_USERNAME))
- sWBMelbourneConnectionString += "User ID=" + username + ";Password=" + password + ";Persist Security Info=True";
- else
- sWBMelbourneConnectionString += "Integrated Security=SSPI";
- }
- // TEAMS ================================================================================
- //--------------------------------------------------------------------------------
- public static string TeamName() {
- switch (sTeam) {
- case Team.RisksmartGCC: return "Risksmart GCC";
- case Team.RisksmartProperty: return "Risksmart Property";
- case Team.PropertyClaims: return "Property Claims";
- case Team.GCCClaims: return "GCC Claims";
- default: return "";
- }
- }
- // DELETION ================================================================================
- //--------------------------------------------------------------------------------
- public static void DeleteImportedData(bool claimsOnly = false) {
- try {
- Log("Deleting imported data...");
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- OleDbCommand command;
- if (!claimsOnly) {
- command = new OleDbCommand("delete from Address where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- command = new OleDbCommand("delete from Contact where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- command = new OleDbCommand("delete from Account where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- command = new OleDbCommand("delete from H_Policy where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- }
- command = new OleDbCommand("delete from H_Claims where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- command = new OleDbCommand("delete from H_Billings where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- command = new OleDbCommand("delete from H_Payments where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- command = new OleDbCommand("delete from H_KeyContacts where Imported = 'T'", connection);
- command.ExecuteNonQuery();
- connection.Close();
- Log("Done.");
- }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // IMPORT ================================================================================
- //--------------------------------------------------------------------------------
- public static void Import(ImportConfig config) {
- // Log
- Log("********************************************************************************");
- // Team / time
- sTeam = Team.None;
- sTime = DateTime.Now.ToString();
- // Accounts
- if (!string.IsNullOrEmpty(config.accountsContactsCSVPath)) {
- try { ImportCSVAccountContacts(Team.RisksmartGCC, config.accountsContactsCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Policies
- if (!string.IsNullOrEmpty(config.policiesCSVPath)) {
- try { ImportCSVPolicies(Team.RisksmartGCC, config.policiesCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Import
- sTeam = config.team;
- switch (config.team) {
- case Team.RisksmartGCC: RisksmartGCC_Import(config); break;
- case Team.RisksmartProperty: RisksmartProperty_Import(config); break;
- case Team.PropertyClaims: PropertyClaims_Import(config); break;
- case Team.GCCClaims: GCCClaims_Import(config); break;
- }
- sTeam = Team.None;
- // Post import
- // Timeslips
- if (!string.IsNullOrEmpty(config.timeslipsCSVPath)) {
- try { ImportCSVTimeslips(Team.RisksmartGCC, config.timeslipsCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Key contacts
- if (!string.IsNullOrEmpty(config.keyContactsCSVPath)) {
- try { ImportCSVKeyContacts(config.keyContactsCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Payments
- if (!string.IsNullOrEmpty(config.paymentsCSVPath)) {
- try { ImportCSVPayments(config.paymentsCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Reserves
- if (!string.IsNullOrEmpty(config.reservesCSVPath)) {
- try { ImportCSVReserves(config.reservesCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Done
- Log("\nDone.");
- }
- // RISKSMART GCC ================================================================================
- //--------------------------------------------------------------------------------
- private static void RisksmartGCC_Import(ImportConfig config) {
- Log("IMPORTING: Risksmart GCC\n");
- // Claim amendments
- if (!string.IsNullOrEmpty(config.accessClaimAmendmentsCSVPath)) {
- try { ImportCSVClaimAmendments(config.accessClaimAmendmentsCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Claims
- if (config.importClaims) {
- try { ImportAccessClaims(); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- }
- // RISKSMART PROPERTY ================================================================================
- //--------------------------------------------------------------------------------
- private static void RisksmartProperty_Import(ImportConfig config) {
- Log("IMPORTING: Risksmart Property\n");
- // Claim amendments
- if (!string.IsNullOrEmpty(config.accessClaimAmendmentsCSVPath)) {
- try { ImportCSVClaimAmendments(config.accessClaimAmendmentsCSVPath); }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- // Claims
- if (config.importClaims) {
- try {
- ImportAccessClaims();
- ImportWinBEATClaims(WinbeatLedger.Underwriting, !config.updateWinBEATClaims);
- }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- }
- // PROPERTY CLAIMS ================================================================================
- //--------------------------------------------------------------------------------
- private static void PropertyClaims_Import(ImportConfig config) {
- Log("IMPORTING: Property Claims\n");
- // Claims
- if (config.importClaims) {
- try {
- ImportWinBEATClaims(WinbeatLedger.RealEstate, !config.updateWinBEATClaims);
- ImportWinBEATClaims(WinbeatLedger.Melbourne, !config.updateWinBEATClaims);
- }
- catch (Exception e) {
- LogError(e.Message);
- return;
- }
- }
- }
- // GCC CLAIMS ================================================================================
- //--------------------------------------------------------------------------------
- private static void GCCClaims_Import(ImportConfig config) {
- Log("IMPORTING: GCC Claims\n");
- // Claims
- if (config.importClaims) {
- /*try {*/ ImportWinBEATClaims(WinbeatLedger.Melbourne, !config.updateWinBEATClaims); /*}
- catch (Exception e) {
- LogError(e.Message);
- return;
- }*/
- }
- }
- // CSV ================================================================================
- //--------------------------------------------------------------------------------
- private static void ImportCSVAccountContacts(Team team, string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing accounts and contacts (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory columns
- string missingColumn = csv.FindMissingColumn(new string[] { "account name", "client code", "underwriter code", "account type" });
- if (missingColumn != null) {
- LogError("Missing account/contacts column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "account name", "account type" });
- if (missingField != null) {
- LogError("Missing account/contacts field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- if (!csv.HeaderIndices.ContainsKey("client code") && !csv.HeaderIndices.ContainsKey("underwriter code")) {
- LogError("Missing account/contacts field: 'client code' OR 'underwriter code'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), "'client code' OR 'underwriter code'");
- continue;
- }
- // Account
- string accountName = csv.FieldOrNull("account name", 128);
- string clientCode = csv.FieldOrNull("client code", 20);
- string underwriterCode = csv.FieldOrNull("underwriter code", 32);
- string accountType = ConvertAccountType(csv.FieldOrNull("account type", 64));
- // Duplicate check
- OleDbCommand command;
- if (clientCode != null) {
- command = new OleDbCommand("select top 1 AccountID from Account where Client_Code=? and Account=? and Type=?", connection);
- command.Parameters.AddWithValue("@Client_Code", clientCode);
- }
- else {
- command = new OleDbCommand("select top 1 AccountID from Account where ExternalAccountNo=? and Account=? and Type=?", connection);
- command.Parameters.AddWithValue("@ExternalAccountNo", underwriterCode);
- }
- command.Parameters.AddWithValue("@Account", accountName);
- command.Parameters.AddWithValue("@Type", accountType);
- object accountID = command.ExecuteScalar();
- command.Dispose();
- // Add account if missing
- if ((accountID == null) || (accountID == DBNull.Value)) {
- // Account ID
- accountID = Infor.IDFor("Account", connection);
- // Address
- object addressID = ImportCSVAddress(accountID, csv, connection);
- // Insert
- command = new OleDbCommand("insert into Account (AccountID, Account, Client_Code, ExternalAccountNo, Type, AddressID, Mainphone, Email, Billing_Method," +
- " Billable_Rate, Service_Rage, Status, Imported, Userfield10, AccountManagerID, SeccodeID) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@AccountID", accountID);
- command.Parameters.AddWithValue("@Account", accountName);
- command.Parameters.AddWithValue("@Client_Code", (object)clientCode ?? DBNull.Value);
- command.Parameters.AddWithValue("@ExternalAccountNo", (object)underwriterCode ?? DBNull.Value);
- command.Parameters.AddWithValue("@Type", accountType);
- command.Parameters.AddWithValue("@AddressID", addressID);
- command.Parameters.AddWithValue("@Mainphone", csv.FieldOrNull("main phone", 32));
- bool hasContact = (csv.FieldOrNull("first name", 32) != null) && !csv.FieldOrNull("first name", 32).ToLower().Equals("n/a");
- command.Parameters.AddWithValue("@Email", !hasContact ? (object)csv.FieldOrNull("email address", 128) : DBNull.Value);
- command.Parameters.AddWithValue("@Billing_Method", csv.FieldOrNull("billing method", 32));
- command.Parameters.AddWithValue("@Billable_Rate", csv.DBFieldFloatFlexible("fee per billing method"));
- command.Parameters.AddWithValue("@Service_Rage", csv.DBFieldFloatFlexible("fee for service"));
- command.Parameters.AddWithValue("@Status", "Active");
- command.Parameters.AddWithValue("@Imported", "T");
- command.Parameters.AddWithValue("@Userfield10", "Imported CSV");
- command.Parameters.AddWithValue("@AccountManagerID", Infor.GetField("UserID", "UserInfo", "Username = 'Ms Dalia Ismaiel'", connection));
- command.Parameters.AddWithValue("@SeccodeID", Infor.GetField("SeccodeID", "Seccode", "SeccodeDesc = 'Everyone' and SeccodeType = 'S'", connection));
- command.ExecuteNonQuery();
- command.Dispose();
- Log("Account (" + accountID + "): " + accountName + ", " + clientCode + ", " + accountType);
- }
- // Contact
- //create address a second time - one for account, one for contact
- string firstName = csv.FieldOrNull("first name", 32);
- string lastName = csv.FieldOrNull("last name", 32) ?? "";
- if ((firstName != null) && !firstName.ToLower().Equals("n/a")) {
- // Duplicate check
- command = new OleDbCommand("select top 1 ContactID from Contact where AccountID=? and FirstName=? and LastName=?", connection);
- command.Parameters.AddWithValue("@AccountID", accountID);
- command.Parameters.AddWithValue("@FirstName", firstName);
- command.Parameters.AddWithValue("@LastName", lastName);
- object contactID = command.ExecuteScalar();
- command.Dispose();
- // Add contact if missing
- if ((contactID == null) || (contactID == DBNull.Value)) {
- // Contact ID
- contactID = Infor.IDFor("Contact", connection);
- // Address
- object addressID = ImportCSVAddress(contactID, csv, connection);
- // Insert
- command = new OleDbCommand("insert into Contact (ContactID, AccountID, Account, AddressID, FirstName, LastName, Title, WorkPhone, Mobile, Email, Imported) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@ContactID", contactID);
- command.Parameters.AddWithValue("@AccountID", accountID);
- string account = (string)Infor.GetField("Account", "Account", "AccountID = '" + accountID + "'", connection);
- command.Parameters.AddWithValue("@Account", account);
- command.Parameters.AddWithValue("@AddressID", addressID);
- command.Parameters.AddWithValue("@FirstName", firstName);
- command.Parameters.AddWithValue("@LastName", lastName);
- command.Parameters.AddWithValue("@Title", csv.FieldOrNull("title", 64));
- command.Parameters.AddWithValue("@WorkPhone", csv.FieldOrNull("main phone", 32));
- command.Parameters.AddWithValue("@Mobile", csv.FieldOrNull("mobile phone", 32));
- command.Parameters.AddWithValue("@Email", csv.FieldOrNull("email address", 128));
- command.Parameters.AddWithValue("@Imported", "T");
- command.ExecuteNonQuery();
- command.Dispose();
- Log("Contact (" + contactID + ", " + accountID + "): " + firstName + ", " + lastName + ", " + account);
- }
- }
- }
- // Line
- sLine = -1;
- // Close
- csv.Dispose();
- connection.Close();
- // Summary
- IssueTracker.LogSummary("Importing accounts and contacts (" + sTime + ")");
- // Missing
- LogMissingSummary("Importing accounts and contacts (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static object ImportCSVAddress(object entityID, CSV csv, OleDbConnection connection) {
- // Fields
- string address1 = csv.FieldOrNull("address 1", 64);
- string address2 = csv.FieldOrNull("address 2", 64);
- string city = csv.FieldOrNull("suburb", 32);
- string state = csv.FieldOrNull("state", 32);
- string postalcode = csv.FieldOrNull("postalcode", 24);
- // Add if available
- if ((address1 != null) || (address2 != null) || (city != null) || (state != null) || (postalcode != null)) {
- // ID
- object addressID = Infor.IDFor("Address", connection);
- // Insert
- OleDbCommand command = new OleDbCommand("insert into Address (AddressID, EntityID, Address1, Address2, City, State, Postalcode, IsPrimary, IsMailing) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@AddressID", addressID);
- command.Parameters.AddWithValue("@EntityID", entityID);
- command.Parameters.AddWithValue("@Address1", (object)address1 ?? DBNull.Value);
- command.Parameters.AddWithValue("@Address2", (object)address2 ?? DBNull.Value);
- command.Parameters.AddWithValue("@City", (object)city ?? DBNull.Value);
- command.Parameters.AddWithValue("@State", (object)state ?? DBNull.Value);
- command.Parameters.AddWithValue("@Postalcode", (object)postalcode ?? DBNull.Value);
- command.Parameters.AddWithValue("@IsPrimary", "T");
- command.Parameters.AddWithValue("@IsMailing", "T");
- command.ExecuteNonQuery();
- Log("Address (" + addressID + ", " + entityID + "): " + (address1 ?? "") + ", " + (address2 ?? "") + ", " + (city ?? "") + ", " + (state ?? "") + ", " + (postalcode ?? ""));
- return addressID;
- }
- else
- return DBNull.Value;
- }
- //--------------------------------------------------------------------------------
- private static void ImportCSVPolicies(Team team, string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing policies... (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory columns
- string missingColumn = csv.FindMissingColumn(new string[] { "policy number", "policy status", "client code", "insured name", "policy class",
- "underwriter code", "inception date policy", "inception date invoiced",
- "expiry date policy", "expiry date invoice", "basic excess" });
- if (missingColumn != null) {
- LogError("Missing policy column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "policy number", "policy status", "client code", "insured name", "policy class",
- "underwriter code", "inception date policy", "inception date invoiced",
- "expiry date policy", "expiry date invoice" });
- if (missingField != null) {
- LogError("Missing policy field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- // Policy
- string policyNumber = csv.FieldOrNull("policy number", 32);
- string policyStatus = csv.FieldOrNull("policy status", 32);
- string clientCode = csv.FieldOrNull("client code", 20);
- string insuredName = csv.FieldOrNull("insured name", 256);
- string policyClass = csv.FieldOrNull("policy class", 64);
- string underwriterCode = csv.FieldOrNull("underwriter code", 128);
- DateTime inceptionDatePolicy = (DateTime)csv.DBFieldDateTime("inception date policy");
- DateTime inceptionDateInvoice = (DateTime)csv.DBFieldDateTime("inception date invoiced");
- DateTime expiryDatePolicy = (DateTime)csv.DBFieldDateTime("expiry date policy");
- DateTime expiryDateInvoice = (DateTime)csv.DBFieldDateTime("expiry date invoice");
- // Duplicate check
- /*OleDbCommand command = new OleDbCommand("select top 1 _P.H_PolicyID from H_Policy _P " +
- "left join Account _O on _P.Owner_AccountID = _O.AccountID left join Account _U on _P.Underwriter_AccountID = _U.AccountID " +
- "where Policy_Number = ? and Policy_Status = ? and _O.Client_Code = ? and InsuredName = ? and Policy_Class = ? and _U.Account = ? and " +
- "Inception_Date = ? and Inception_Date_Invoice = ? and Expiry_Date = ? and Expiry_Date_Invoice = ?", connection);*/
- OleDbCommand command = new OleDbCommand("select top 1 _P.H_PolicyID from H_Policy _P " +
- "where Policy_Number = ? and Policy_Status = ? and InsuredName = ? and Policy_Class = ? and " +
- "Inception_Date = ? and Inception_Date_Invoice = ? and Expiry_Date = ? and Expiry_Date_Invoice = ?", connection);
- command.Parameters.AddWithValue("@PolicyNumber", policyNumber);
- command.Parameters.AddWithValue("@PolicyStatus", policyStatus);
- //command.Parameters.AddWithValue("@ClientCode", clientCode);
- command.Parameters.AddWithValue("@InsuredName", insuredName);
- command.Parameters.AddWithValue("@PolicyClass", policyClass);
- //command.Parameters.AddWithValue("@UnderwriterName", underwriterName);
- command.Parameters.AddWithValue("@InceptionDatePolicy", inceptionDatePolicy);
- command.Parameters.AddWithValue("@InceptionDateInvoice", inceptionDateInvoice);
- command.Parameters.AddWithValue("@ExpiryDatePolicy", expiryDatePolicy);
- command.Parameters.AddWithValue("@ExpiryDateInvoice", expiryDateInvoice);
- object policyID = command.ExecuteScalar();
- command.Dispose();
- // Add policy if missing
- if ((policyID == null) || (policyID == DBNull.Value)) {
- // Policy ID
- policyID = Infor.IDFor("Policy", connection);
- // Insert
- command = new OleDbCommand("insert into H_Policy (H_PolicyID, Policy_Number, Policy_Status, InsuredName, Policy_Class, Inception_Date, Inception_Date_Invoice, Expiry_Date," +
- " Expiry_Date_Invoice, Basic_Excess, Imported, Year_Built, SeccodeID, Owner_AccountID, Underwriter_AccountID) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@PolicyID", policyID);
- command.Parameters.AddWithValue("@PolicyNumber", policyNumber);
- command.Parameters.AddWithValue("@PolicyStatus", policyStatus);
- command.Parameters.AddWithValue("@InsuredName", insuredName);
- command.Parameters.AddWithValue("@PolicyClass", policyClass);
- command.Parameters.AddWithValue("@InceptionDate", inceptionDatePolicy);
- command.Parameters.AddWithValue("@InceptionDateInvoice", inceptionDateInvoice);
- command.Parameters.AddWithValue("@ExpiryDate", expiryDatePolicy);
- command.Parameters.AddWithValue("@ExpiryDateInvoice", expiryDateInvoice);
- command.Parameters.AddWithValue("@BasicExcess", csv.DBFieldDecimalFlexible("basic excess"));
- command.Parameters.AddWithValue("@Imported", "T");
- command.Parameters.AddWithValue("@YearBuilt", 2000);
- // Seccode ID
- object seccodeID = DBNull.Value;
- switch (team) {
- case Team.RisksmartGCC: seccodeID = Infor.GetField("SeccodeID", "Seccode", "SeccodeDesc = 'Risksmart GCC Policies' and SeccodeType = 'G'", connection); break;
- }
- command.Parameters.AddWithValue("@SeccodeID", seccodeID);
- // Owner account
- object ownerAccountID = Infor.GetField("AccountID", "Account", "Type = 'Customer' and Client_Code = '" + clientCode + "'", connection) ?? DBNull.Value;
- if (ownerAccountID == DBNull.Value) {
- LogError("Owner account not found: '" + clientCode + "'");
- IssueTracker.AddError(IssueTracker.Issue.CUSTOMER_NOT_FOUND, sLine.ToString(), clientCode);
- AddMissingCustomer("ClientCode : " + clientCode);
- continue;
- }
- command.Parameters.AddWithValue("@OwnerAccountID", ownerAccountID);
- // Underwriter account
- object underwriterAccountID = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and ExternalAccountNo = '" + underwriterCode + "'", connection) ?? DBNull.Value;
- if (underwriterAccountID == DBNull.Value) {
- LogError("Underwriter account not found: '" + underwriterCode + "'");
- IssueTracker.AddError(IssueTracker.Issue.UNDERWRITER_NOT_FOUND, sLine.ToString(), underwriterCode);
- AddMissingUnderwriter(underwriterCode);
- continue;
- }
- command.Parameters.AddWithValue("@UnderwriterAccountID", underwriterAccountID);
- // Execute
- command.ExecuteNonQuery();
- Log("Policy (" + policyID + "): " + policyNumber + ", " + policyClass + ", " + clientCode + ", " + insuredName + ", " + underwriterCode);
- }
- //else
- // LogWarning("Policy already exists: " + policyID);
- }
- // Line
- sLine = -1;
- // Close
- csv.Dispose();
- connection.Close();
- // Summary
- IssueTracker.LogSummary("Importing policies... (" + sTime + ")");
- // Missing
- LogMissingSummary("Importing policies... (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static void ImportCSVClaimAmendments(string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing claim amendments (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory clumns
- string missingColumn = csv.FindMissingColumn(new string[] { "claim no", "claim type", "policy number", "insured", "assigned user" });
- if (missingColumn != null) {
- LogError("Missing claim amendments column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "claim no" });
- if (missingField != null) {
- LogError("Missing claim amendments field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- // Staged claim
- string claimNo = csv.FieldOrNull("claim no", 255);
- OleDbDataAdapter adapter = new OleDbDataAdapter("select top 1 * from S_Acc_Claim where Claim_No = '" + claimNo + "'", sInforConnectionString);
- DataSet dataSet = new DataSet();
- adapter.Fill(dataSet, "S_Acc_Claim");
- DataTable claimTable = dataSet.Tables["S_Acc_Claim"];
- if (claimTable.Rows.Count == 0) {
- LogError("Claim not found: '" + claimNo + "'");
- IssueTracker.AddError(IssueTracker.Issue.CLAIM_NOT_FOUND, sLine.ToString(), claimNo);
- continue;
- }
- DataRow claimRow = claimTable.Rows[0];
- // Policy number
- object policyNumber = claimRow["Policy_Number"];
- string csvPolicyNumber = csv.FieldOrNull("policy number");
- if (csvPolicyNumber != null) {
- csvPolicyNumber = csvPolicyNumber.Trim();
- if ((policyNumber == DBNull.Value) || ((string)policyNumber).ToLower().Contains("xx") || ((string)policyNumber).ToLower().Contains("tba")) {
- policyNumber = csvPolicyNumber; // Update
- Log("Policy number updated (" + claimNo + "): " + policyNumber);
- }
- else if (!csvPolicyNumber.Equals(((string)policyNumber).Trim())) {
- LogError("Policy number differs (" + claimNo + "): " + csvPolicyNumber + ", " + policyNumber);
- IssueTracker.AddError(IssueTracker.Issue.POLICY_NUMBER_DIFFERS, sLine.ToString(), csvPolicyNumber + ", " + policyNumber);
- }
- }
- // Claim type
- object claimType = ConvertDDField(claimRow, "DD_Claim_Type", "Claim_Type", new string[] { "Claim", "Notification" });
- string csvClaimType = csv.FieldOrNull("claim type");
- if (csvClaimType != null) {
- csvClaimType = csvClaimType.First().ToString().ToUpper() + csvClaimType.Substring(1);
- if ((claimType == DBNull.Value) || (!new string[] { "claim", "notification" }.Contains(((string)claimType).ToLower()))) {
- claimType = csvClaimType; // Update
- Log("Claim type updated (" + claimNo + "): " + claimType);
- }
- else if (!csvClaimType.Equals(claimType)) {
- LogError("Claim type differs (" + claimNo + "): " + csvClaimType + ", " + claimType);
- IssueTracker.AddError(IssueTracker.Issue.CLAIM_TYPE_DIFFERS, sLine.ToString(), csvClaimType + ", " + claimType);
- }
- }
- // Insured
- object insured = ConvertDDField(claimRow, "DD_Insured", "Insured");
- string csvInsured = csv.FieldOrNull("insured");
- if (csvInsured != null) {
- if (insured == DBNull.Value) {
- insured = csvInsured; // Update
- Log("Insured updated (" + claimNo + "): " + insured);
- }
- else if (!csvInsured.Equals(insured)) {
- LogError("Insured differs (" + claimNo + "): " + csvInsured + ", " + insured);
- IssueTracker.AddError(IssueTracker.Issue.INSURED_DIFFERS, sLine.ToString(), csvInsured + ", " + insured);
- }
- }
- // Assigned user
- object assignedUser = claimRow["Claim_Operator"];
- string csvAssignedUser = csv.FieldOrNull("assigned user");
- if (csvAssignedUser != null) {
- assignedUser = csvAssignedUser;
- Log("Assigned user updated (" + claimNo + "): " + assignedUser);
- }
- // Update
- OleDbCommand command = new OleDbCommand("update S_Acc_Claim set Policy_Number = ?, DD_Claim_Type = ?, DD_Insured = ?, Claim_Operator = ? where Claim_No = ?", connection);
- command.Parameters.AddWithValue("@PolicyNumber", policyNumber);
- command.Parameters.AddWithValue("@ClaimType", claimType);
- command.Parameters.AddWithValue("@Insured", insured);
- command.Parameters.AddWithValue("@AssignedUser", assignedUser);
- command.Parameters.AddWithValue("@ClaimNo", claimNo);
- command.ExecuteNonQuery();
- }
- // Line
- sLine = -1;
- // Close
- csv.Dispose();
- connection.Close();
- // Summary
- IssueTracker.LogSummary("Importing claim amendments (" + sTime + ")");
- // Missing
- LogMissingSummary("Importing claim amendments (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static void ImportCSVTimeslips(Team team, string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing timeslips (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory columns
- string missingColumn = csv.FindMissingColumn(new string[] { "claim ref", "service by", "service date", /*"start time", "end time",*/ "units",
- "billable", "invoiced", "work done" });
- if (missingColumn != null) {
- LogError("Missing timeslip column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "claim ref", "service by", "service date", "units", "billable", "invoiced", "work done" });
- if (missingField != null) {
- LogError("Missing timeslip field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- // Timeslip
- string claimNo = (string)ClaimNumber(csv.FieldOrNull("claim ref", 12));
- string serviceByName = csv.FieldOrNull("service by", 64) ?? "Ms Dalia Ismaiel";
- DateTime serviceDate = (DateTime)csv.DBFieldDateTime("service date");
- int units = (int)csv.DBFieldInt("units");
- decimal billable = (decimal)csv.DBFieldDecimalFlexible("billable");
- string invoiced = (bool)csv.DBFieldBool("invoiced") ? "T" : "F";
- string workDoneShort = csv.FieldOrNull("work done", 400);
- // Duplicate check
- OleDbCommand command = new OleDbCommand("select top 1 H_BillingsID from H_Billings where Claim_No = ? and Service_By_Name = ? and Service_Date = ? and " +
- "Units = ? and Billable = ? and Invoice_Processed = ? and Work_Done_Short = ?", connection);
- command.Parameters.AddWithValue("@ClaimNo", claimNo);
- command.Parameters.AddWithValue("@ServiceByName", serviceByName);
- command.Parameters.AddWithValue("@ServiceDate", serviceDate);
- command.Parameters.AddWithValue("@Units", units);
- command.Parameters.AddWithValue("@Billable", billable);
- command.Parameters.AddWithValue("@Invoiced", invoiced);
- command.Parameters.AddWithValue("@WorkDoneShort", workDoneShort);
- object billingID = command.ExecuteScalar();
- command.Dispose();
- // Add billing if missing
- if ((billingID == null) || (billingID == DBNull.Value)) {
- // Billing ID
- billingID = Infor.IDFor("H_Billings", connection);
- // Insert
- command = new OleDbCommand("insert into H_Billings (H_BillingsID, H_ClaimsID, Claim_No, Service_By, Service_By_Name, Service_Date, Start_Time, End_Time," +
- " Units, Is_Billable, Billable, Invoice_Processed, Work_Done, Work_Done_Short, Imported, PolicyID, Client_Code, Quarter," +
- " Rate, Rate_Per_Unit, Timeslip_Checked, Checked_By, Checked_Date, Invoice_Processed_By, Invoice_Processed_Date," +
- " Invoice_No, Invoice_Date) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@BillingID", billingID);
- // Claim
- object claimID = Infor.GetField("H_ClaimsID", "H_Claims", "Claim_Reference_Num = '" + claimNo + "'", connection) ?? DBNull.Value;
- if (claimID == DBNull.Value) {
- LogError("Claim not found: '" + claimNo + "'");
- IssueTracker.AddError(IssueTracker.Issue.CLAIM_NOT_FOUND, sLine.ToString(), claimNo);
- AddMissingClaim(claimNo);
- continue;
- }
- command.Parameters.AddWithValue("@ClaimID", claimID);
- command.Parameters.AddWithValue("@ClaimNo", claimNo);
- // Service
- object serviceByID = Infor.GetField("UserID", "UserInfo", "Username = '" + serviceByName + "'", connection) ?? DBNull.Value;
- if (serviceByID == DBNull.Value) {
- LogError("Service by user not found: '" + serviceByName + "'");
- IssueTracker.AddError(IssueTracker.Issue.SERVICE_BY_USER_NOT_FOUND, sLine.ToString(), serviceByName);
- AddMissingUser(serviceByName);
- continue;
- }
- command.Parameters.AddWithValue("@ServiceBy", serviceByID);
- command.Parameters.AddWithValue("@ServiceByName", serviceByName);
- command.Parameters.AddWithValue("@ServiceDate", serviceDate);
- // Start time
- object startTime = csv.DBFieldDateTime("start time");
- if (startTime == DBNull.Value)
- startTime = new DateTime(1899, 12, 31, 9, 0, 0);
- command.Parameters.AddWithValue("@StartTime", startTime);
- // End time
- object endTime = csv.DBFieldDateTime("end time");
- if (endTime == DBNull.Value)
- endTime = ((DateTime)startTime).AddMinutes(units * 6);
- command.Parameters.AddWithValue("@StartTime", endTime);
- // Fields
- command.Parameters.AddWithValue("@Units", units);
- command.Parameters.AddWithValue("@IsBillable", billable > 0.0m ? "T" : "F");
- command.Parameters.AddWithValue("@Billable", billable);
- command.Parameters.AddWithValue("@InvoiceProcessed", invoiced);
- command.Parameters.AddWithValue("@WorkDone", csv.FieldOrNull("work done"));
- command.Parameters.AddWithValue("@WorkDoneShort", workDoneShort);
- command.Parameters.AddWithValue("@Imported", "T");
- // Policy
- command.Parameters.AddWithValue("@PolicyID", Infor.GetField("Policy_No", "H_Claims", "H_ClaimsID = '" + claimID + "'", connection) ?? DBNull.Value);
- // Account
- object accountID = Infor.GetField("AccountID", "H_Claims", "H_ClaimsID = '" + claimID + "'", connection) ?? DBNull.Value;
- command.Parameters.AddWithValue("@AccountID", accountID);
- // Quarter
- command.Parameters.AddWithValue("@Quarter", "Quarter " + (serviceDate.Month <= 3 ? 1 : (serviceDate.Month <= 6 ? 2 : (serviceDate.Month <= 9 ? 3 : 4))) + " " + serviceDate.Year);
- // Rates
- object rate = csv.DBFieldDecimalFlexible("rate p hr");
- object ratePerUnit = csv.DBFieldDecimalFlexible("rate p unit");
- if ((accountID != DBNull.Value) && (rate == DBNull.Value)) {
- string billingMethod = ((string)(Infor.GetField("Billing_Method", "Account", "AccountID = '" + accountID + "'", connection) ?? "")).ToLower();
- if (billingMethod.Equals("per hour"))
- rate = Infor.GetField("Service_Rage", "Account", "AccountID = '" + accountID + "'", connection) ?? DBNull.Value;
- else
- rate = Infor.GetField("Billable_Rate", "Account", "AccountID = '" + accountID + "'", connection) ?? DBNull.Value;
- if (rate != DBNull.Value) {
- ratePerUnit = (decimal)((double)rate / 10.0f);
- rate = (decimal)(double)rate;
- }
- }
- command.Parameters.AddWithValue("@Rate", rate);
- command.Parameters.AddWithValue("@RatePerUnit", ratePerUnit);
- // Status
- command.Parameters.AddWithValue("@TimeslipChecked", invoiced);
- //command.Parameters.AddWithValue("@CheckedBy", invoiced.Equals("T") ? (object)"ADMIN" : DBNull.Value);
- command.Parameters.AddWithValue("@CheckedBy", DBNull.Value);
- //command.Parameters.AddWithValue("@CheckedDate", invoiced.Equals("T") ? (object)DateTime.Now : DBNull.Value);
- command.Parameters.AddWithValue("@CheckedDate", DBNull.Value);
- command.Parameters.AddWithValue("@InvoiceProcessedBy", invoiced.Equals("T") ? (object)"ADMIN" : DBNull.Value);
- object invoiceDate = csv.DBFieldDateTime("service date");
- command.Parameters.AddWithValue("@InvoiceProcessedDate", invoiced.Equals("T") ? (invoiceDate != DBNull.Value ? invoiceDate : (object)DateTime.Now) : DBNull.Value);
- object invoiceNumber = csv.DBFieldOrNull("invoice number");
- command.Parameters.AddWithValue("@InvoiceNo", invoiceNumber != DBNull.Value ? invoiceNumber : (invoiced.Equals("T") ? (object)"IMPORTED" : DBNull.Value));
- command.Parameters.AddWithValue("@InvoiceDate", invoiced.Equals("T") ? (object)DateTime.Now : DBNull.Value);
- // Execute
- command.ExecuteNonQuery();
- Log("Billing (" + billingID + "): " + claimNo + ", " + serviceByName + ", " + serviceDate + ", " + units + ", " + billable);
- }
- //else
- // LogWarning("Timeslip already exists: " + billingID);
- }
- // Line
- sLine = -1;
- // Close
- csv.Dispose();
- connection.Close();
- // Summary
- IssueTracker.LogSummary("Importing timeslips (" + sTime + ")");
- // Missing
- LogMissingSummary("Importing timeslips (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static void ImportCSVKeyContacts(string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing key contacts (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory columns
- string missingColumn = csv.FindMissingColumn(new string[] { "account name", "name", "description", "address", "phone", "email", "notes" });
- if (missingColumn != null) {
- LogError("Missing key contacts column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "account name", "name" });
- if (missingField != null) {
- LogError("Missing key contacts field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- // Key contact
- string accountName = csv.FieldOrNull("account name", 128);
- string contactName = csv.FieldOrNull("name", 200);
- // Claims
- OleDbCommand command = new OleDbCommand("select H_ClaimsID, Claim_Reference_Num from H_Claims where Account_Name = ?", connection);
- command.Parameters.AddWithValue("@AccountName", accountName);
- OleDbDataReader reader = command.ExecuteReader();
- while (reader.Read()) {
- // Claim
- string claimID = (string)reader[0];
- string claimNumber = reader[1] != null ? (string)reader[1] : "";
- // Duplicate check
- command = new OleDbCommand("select top 1 H_KeyContactsID from H_KeyContacts where H_ClaimsID = ? and Account_Name = ? and Contact_Name = ?", connection);
- command.Parameters.AddWithValue("@ClaimID", claimID);
- command.Parameters.AddWithValue("@AccountName", accountName);
- command.Parameters.AddWithValue("@ContactName", contactName);
- object keyContactID = command.ExecuteScalar();
- command.Dispose();
- // Add key contact if missing
- if ((keyContactID == null) || (keyContactID == DBNull.Value)) {
- // Key contact ID
- keyContactID = Infor.IDFor("H_KeyContactsID", connection);
- // Insert
- command = new OleDbCommand("insert into H_KeyContacts (H_KeyContactsID, H_ClaimsID, Account_Name, AccountID, Contact_Name," +
- " Description, Address, Phone, Email_Address, Notes, Imported) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@KeyContactID", keyContactID);
- command.Parameters.AddWithValue("@ClaimID", claimID);
- // Account
- object accountID = Infor.GetField("AccountID", "Account", "Account = '" + accountName.Replace("'", "''") + "'", connection) ?? DBNull.Value;
- if (accountID == DBNull.Value) {
- LogWarning("Key contact account not found: '" + accountName + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ACCOUNT_NOT_FOUND, sLine.ToString(), accountName);
- AddMissingAccount(accountName);
- }
- command.Parameters.AddWithValue("@AccountName", accountName);
- command.Parameters.AddWithValue("@AccountID", accountID);
- // Contact
- command.Parameters.AddWithValue("@ContactName", contactName);
- // Fields
- command.Parameters.AddWithValue("@Description", csv.FieldOrNull("description", 400));
- command.Parameters.AddWithValue("@Address", csv.FieldOrNull("address"));
- command.Parameters.AddWithValue("@Phone", csv.FieldOrNull("phone", 200));
- command.Parameters.AddWithValue("@Email_Address", csv.FieldOrNull("email", 200));
- command.Parameters.AddWithValue("@Notes", csv.FieldOrNull("notes"));
- command.Parameters.AddWithValue("@Imported", "T");
- // Execute
- command.ExecuteNonQuery();
- command.Dispose();
- Log("Key Contact (" + keyContactID + "): " + claimNumber + ", " + contactName + ", " + accountName);
- }
- }
- reader.Close();
- }
- // Line
- sLine = -1;
- // Close
- csv.Dispose();
- connection.Close();
- // Summary
- IssueTracker.LogSummary("Importing key contacts (" + sTime + ")");
- // Missing
- LogMissingSummary("Importing key contacts (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static void ImportCSVPayments(string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing payments (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory columns
- string missingColumn = csv.FindMissingColumn(new string[] { "id", "claim no", "payment type", "gross paid to date", "gst", "net paid to date", "payor", "payee",
- "payment method", "cheque no", "pay date" });
- if (missingColumn != null) {
- LogError("Missing payment column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Counts
- int newPaymentCount = 0;
- int updatedPaymentCount = 0;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "id", "claim no", "gross paid to date", "net paid to date" });
- if (missingField != null) {
- LogError("Missing payment field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- // Amounts
- decimal grossPaid = (decimal)csv.DBFieldDecimalFlexible("gross paid to date");
- decimal netPaid = (decimal)csv.DBFieldDecimalFlexible("net paid to date");
- if ((grossPaid <= 0.0m) && (netPaid <= 0.0m)) {
- LogError("Gross paid and net paid both zero: " + grossPaid + ", " + netPaid);
- IssueTracker.AddError(IssueTracker.Issue.ZERO_GROSS_PAID_NET_PAID, sLine.ToString(), grossPaid + ", " + netPaid);
- continue;
- }
- if (grossPaid < netPaid) {
- LogWarning("Gross paid less than net paid");
- IssueTracker.AddWarning(IssueTracker.Issue.GROSS_PAID_LESS_THAN_NET_PAID, sLine.ToString(), grossPaid + ", " + netPaid);
- //LogWarning("Gross paid less than net paid, swapping: " + grossPaid + " < " + netPaid);
- //decimal temporary = grossPaid;
- //grossPaid = netPaid;
- //netPaid = temporary;
- }
- // Payment
- int accessID = (int)csv.DBFieldInt("id");
- string claimNo = (string)ClaimNumber(csv.FieldOrNull("claim no", 20));
- // Duplicate check
- OleDbCommand command = new OleDbCommand("select top 1 H_PaymentsID from H_Payments _P left join H_Claims _C on _P.H_ClaimsID = _C.H_ClaimsID " +
- "where _P.AccessID = ? and _C.Claim_Reference_Num = ?", connection);
- command.Parameters.AddWithValue("@AccessID", accessID);
- command.Parameters.AddWithValue("@ClaimNo", (object)claimNo ?? DBNull.Value);
- object paymentID = command.ExecuteScalar();
- command.Dispose();
- // Insert / update
- Operation operation = ((paymentID == null) || (paymentID == DBNull.Value)) ? Operation.Insert : Operation.Update;
- if (operation == Operation.Insert) {
- command = new OleDbCommand("insert into H_Payments (H_PaymentsID, AccessID, H_ClaimsID, Reserve_Type, Invoice_Reference, Total_Gross, Total_Net, GST_Included, GST," +
- " Date_Invoice_Paid, Payment_Status, Payment_Type, Payment_Method, Payment_To, Payment_To_Name," +
- " Payee_Account, Payee_Account_Name, Is_Settlement, Imported) " +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'T')", connection);
- paymentID = Infor.IDFor("H_Payments", connection);
- command.Parameters.AddWithValue("@PaymentID", paymentID);
- command.Parameters.AddWithValue("@AccessID", accessID);
- }
- else {
- command = new OleDbCommand("update H_Payments set H_ClaimsID = ?, Reserve_Type = ?, Invoice_Reference = ?, Total_Gross = ?, Total_Net = ?, GST_Included = ?, GST = ?," +
- " Date_Invoice_Paid = ?, Payment_Status = ?, Payment_Type = ?, Payment_Method = ?, Payment_To = ?, Payment_To_Name = ?," +
- " Payee_Account = ?, Payee_Account_Name = ?, Is_Settlement = ? " +
- "where H_PaymentsID = ? and AccessID = ? and Imported = 'T'", connection);
- }
- // Claim
- object claimID = Infor.GetField("H_ClaimsID", "H_Claims", "Claim_Reference_Num = '" + claimNo + "'", connection) ?? DBNull.Value;
- if (claimID == DBNull.Value) {
- LogError("Claim not found: '" + claimNo + "'");
- IssueTracker.AddError(IssueTracker.Issue.CLAIM_NOT_FOUND, sLine.ToString(), claimNo);
- AddMissingClaim(claimNo);
- continue;
- }
- command.Parameters.AddWithValue("@ClaimID", claimID);
- // Claim status (FINANCIALS CHANGE)
- /*string claimStatus = (string)Infor.GetField("Claim_Status", "H_Claims", "H_ClaimsID = '" + claimID +"'", connection);
- if ((claimStatus != null) && claimStatus.ToLower().Contains("open")) {
- LogWarning("Claim is open: '" + claimNo + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.CLAIM_IS_OPEN, sLine.ToString(), claimNo);
- continue;
- }*/
- // Reserve type
- string claimTeam = Infor.GetFieldString("Claim_Team_Name", "H_Claims", "Claim_Reference_Num = '" + claimNo + "'", connection) ?? "";
- string reserveType = null;
- //if (claimTeam.ToLower().Equals("risksmart gcc"))
- // reserveType = "Liability Reserve";
- string paymentType = csv.FieldOrNull("payment type", 200); // FINANCIALS CHANGE
- if ((paymentType != null) && (paymentType.ToLower().Contains("legal") || paymentType.ToLower().Contains("assessor")))
- reserveType = "Defence Reserve";
- else
- reserveType = "Liability Reserve";
- command.Parameters.AddWithValue("@ReserveType", reserveType);
- // Fields
- command.Parameters.AddWithValue("@InvoiceReference", csv.FieldOrNull("cheque no", 100));
- command.Parameters.AddWithValue("@TotalGross", grossPaid);
- command.Parameters.AddWithValue("@TotalNet", netPaid);
- // GST
- bool gstIncluded = false;
- /*if ((grossPaid > 0.0m) && (netPaid > 0.0m) && (grossPaid > netPaid)) {
- double differenceRatio = (double)((grossPaid - netPaid) / netPaid);
- gstIncluded = (differenceRatio > 0.0999) && (differenceRatio < 0.1001);
- }*/
- command.Parameters.AddWithValue("@GSTIncluded", gstIncluded ? "T" : "F");
- command.Parameters.AddWithValue("@GST", 0.1);
- // Fields
- command.Parameters.AddWithValue("@DateInvoicePaid", csv.DBFieldDateTime("pay date"));
- command.Parameters.AddWithValue("@PaymentStatus", csv.DBFieldDateTime("pay date") != DBNull.Value ? (object)"Paid" : DBNull.Value);
- command.Parameters.AddWithValue("@PaymentType", csv.FieldOrNull("payment type", 200));
- command.Parameters.AddWithValue("@PaymentMethod", csv.FieldOrNull("payment method", 200));
- // Payment to
- object paymentToID = DBNull.Value;
- object paymentTo = AccountName(csv.FieldOrNull("payor", 200));
- if (paymentTo != null) {
- paymentToID = Infor.GetField("AccountID", "Account", "Account = '" + ((string)paymentTo).Replace("'", "''") + "'", connection) ?? DBNull.Value;
- if (paymentToID == DBNull.Value) {
- LogWarning("Payment to account not found: '" + paymentTo + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ACCOUNT_NOT_FOUND, sLine.ToString(), paymentTo.ToString());
- AddMissingAccount((string)paymentTo);
- }
- }
- command.Parameters.AddWithValue("@PaymentTo", paymentToID);
- command.Parameters.AddWithValue("@PaymentToName", paymentTo);
- // Payee
- object payeeAccountID = DBNull.Value;
- object payeeAccount = AccountName(csv.FieldOrNull("payee", 200));
- if (payeeAccount != null) {
- payeeAccountID = Infor.GetField("AccountID", "Account", "Account = '" + ((string)payeeAccount).Replace("'", "''") + "'", connection) ?? DBNull.Value;
- if (payeeAccountID == DBNull.Value) {
- LogWarning("Payee account not found: '" + payeeAccount + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ACCOUNT_NOT_FOUND, sLine.ToString(), payeeAccount.ToString());
- AddMissingAccount((string)payeeAccount);
- }
- }
- command.Parameters.AddWithValue("@PayeeAccount", payeeAccountID);
- command.Parameters.AddWithValue("@PayeeAccountName", payeeAccount);
- // Settlement
- bool isSettlement = (csv.FieldOrNull("payment type", 200) ?? "").ToLower().Equals("settlement");
- command.Parameters.AddWithValue("@IsSettlement", isSettlement ? "T" : "F");
- // Claim settlement
- if (isSettlement) {
- OleDbCommand claimCommand = new OleDbCommand("update H_Claims set Outcome_Settlement = 'T' where Claim_Reference_Num = ?", connection);
- claimCommand.Parameters.AddWithValue("@ClaimReferenceNum", claimNo);
- claimCommand.ExecuteNonQuery();
- claimCommand.Dispose();
- Log("Claim Settlement (" + claimNo + ")");
- }
- // Where
- if (operation == Operation.Update) {
- command.Parameters.AddWithValue("@PaymentID", paymentID);
- command.Parameters.AddWithValue("@AccessID", accessID);
- }
- // Execute
- command.ExecuteNonQuery();
- command.Dispose();
- Log((operation == Operation.Update ? "Updated " : "") + "Payment (" + paymentID + "): " + claimNo + ", " + accessID + ", " + grossPaid + ", " + netPaid);
- if (operation == Operation.Insert)
- ++newPaymentCount;
- else
- ++updatedPaymentCount;
- }
- // Line
- sLine = -1;
- // Close
- csv.Dispose();
- connection.Close();
- // Summary
- Log("\n--------------------------------------------------------------------------------");
- Log("RESULTS (Importing payments (" + sTime + ")):");
- Log(" " + newPaymentCount + " payments added.");
- Log(" " + updatedPaymentCount + " payments updated.\n");
- // Summary
- IssueTracker.LogSummary("Importing payments (" + sTime + ")");
- // Missing
- LogMissingSummary("Importing payments (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static void ImportCSVReserves(string csvPath) {
- // Log
- Log("================================================================================");
- Log("Importing reserves (" + sTime + ")");
- Log("================================================================================");
- // Reserves
- Dictionary<string, List<Tuple<int, decimal>>> reserves = new Dictionary<string, List<Tuple<int, decimal>>>();
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // CSV
- CSV csv = new CSV(csvPath);
- // Delegates
- csv.missingField += new CSV.MissingFieldDelegate(MissingField);
- csv.parseError += new CSV.ParseErrorDelegate(ParseError);
- csv.truncated += new CSV.TruncatedDelegate(Truncated);
- // Mandatory columns
- string missingColumn = csv.FindMissingColumn(new string[] { "id", "claim no", "reserve" });
- if (missingColumn != null) {
- LogError("Missing reserve column: '" + missingColumn + "'");
- return;
- }
- // Line
- sLine = 1;
- // Records
- while (csv.ReadNext()) {
- // Line
- ++sLine;
- // Mandatory fields
- string missingField = csv.FindMissingField(new string[] { "id", "claim no", "reserve" });
- if (missingField != null) {
- LogError("Missing reserve field: '" + missingField + "'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CSV_FIELD_VALUE, sLine.ToString(), missingField);
- continue;
- }
- // Reserve
- decimal reserve = (decimal)csv.DBFieldDecimalFlexible("reserve");
- if (reserve <= 0.0m) {
- LogError("Reserve is zero: " + reserve);
- IssueTracker.AddError(IssueTracker.Issue.ZERO_RESERVE, sLine.ToString(), reserve.ToString());
- continue;
- }
- // Details
- int accessID = (int)csv.DBFieldInt("id");
- string claimNo = (string)ClaimNumber(csv.FieldOrNull("claim no", 20));
- // Add
- if (!reserves.ContainsKey(claimNo))
- reserves.Add(claimNo, new List<Tuple<int, decimal>>());
- reserves[claimNo].Add(new Tuple<int, decimal>(accessID, reserve));
- }
- // Line
- sLine = -1;
- // Close csv
- csv.Dispose();
- // Process reserves
- int ambiguousCount = 0;
- foreach (KeyValuePair<string, List<Tuple<int, decimal>>> c in reserves) {
- // Already imported
- //OleDbCommand command = new OleDbCommand("select H_ClaimsID from H_Claims where Claim_Reference_Num = ? and Imported = 'T' and Imported_Reserve is null or Imported_Reserve <> 'T'", connection);
- //OleDbCommand command = new OleDbCommand("select H_ClaimsID from H_Claims where Claim_Reference_Num = ? and Imported = 'T'", connection);
- OleDbCommand command = new OleDbCommand("select H_ClaimsID from H_Claims where Claim_Reference_Num = ? and Imported = 'T' and (Claim_Status is null or Claim_Status not like '%open%')", connection); // FINANCIALS CHANGE
- command.Parameters.AddWithValue("@ClaimReferenceNum", c.Key);
- object claimID = command.ExecuteScalar();
- command.Dispose();
- if ((claimID == null) || (claimID == DBNull.Value)) {
- //Log("Skipped reserve (" + c.Key + ")"); // Shows missing claims, not just skipped ones
- continue;
- }
- // First reserve
- int firstID = int.MaxValue;
- decimal firstReserve = 0;
- foreach (Tuple<int, decimal> r in c.Value) {
- if (r.Item1 < firstID) {
- firstID = r.Item1;
- firstReserve = r.Item2;
- }
- }
- // Update
- command = new OleDbCommand("update H_Claims set Liability_Res_Source = ?, Imported_Reserve = 'T' where Claim_Reference_Num = ?", connection);
- command.Parameters.AddWithValue("@LiabilityResSource", firstReserve);
- command.Parameters.AddWithValue("@ClaimReferenceNum", c.Key);
- command.ExecuteNonQuery();
- command.Dispose();
- Log("Reserve (" + c.Key + "): " + firstReserve);
- // Ambiguous
- if (c.Value.Count > 1) {
- ++ambiguousCount;
- // String
- string ambiguousReservesString = "RESERVE (" + DateTime.Now + "):";
- string reserveList = "";
- foreach (Tuple<int, decimal> r in c.Value) {
- ambiguousReservesString += "\n $" + r.Item2;
- reserveList += (reserveList.Length > 0 ? ", " : "") + "$" + r.Item2;
- }
- // Note
- object claimNoteObject = Infor.GetField("Claim_Note", "H_Claims", "Claim_Reference_Num = '" + c.Key.Replace("'", "''") + "'", connection) ?? DBNull.Value;
- string claimNote = (claimNoteObject != DBNull.Value ? (string)claimNoteObject : "");
- // Apply indication
- command = new OleDbCommand("update H_Claims set Ambiguous_Reserve = 'T', Claim_Note = ? " +
- "where Claim_Reference_Num = ?", connection);
- command.Parameters.AddWithValue("@ClaimNote", ambiguousReservesString + "\n\n" + claimNote);
- command.Parameters.AddWithValue("@ClaimReferenceNum", c.Key);
- command.ExecuteNonQuery();
- command.Dispose();
- // Log
- Log("Ambiguous Reserve (" + c.Key + "): " + reserveList);
- IssueTracker.AddWarning(IssueTracker.Issue.AMBIGUOUS_RESERVE, c.Key, reserveList);
- }
- }
- // Close connection
- connection.Close();
- // Summary
- Log("\n--------------------------------------------------------------------------------");
- Log("RESULTS (Importing reserves (" + sTime + ")):\n");
- Log(" " + ambiguousCount + " ambiguous reserves.\n");
- // Summary
- IssueTracker.LogSummary("Importing reserves (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- // ACCESS ================================================================================
- //--------------------------------------------------------------------------------
- private static void ImportAccessClaims() {
- // Log
- Log("================================================================================");
- Log(TeamName() + ": Importing Access claims (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // Adapters
- Log("Retrieving claim data...");
- OleDbDataAdapter stagingAdapter = new OleDbDataAdapter("select * from S_Acc_Claim", sInforConnectionString);
- OleDbDataAdapter claimAdapter = new OleDbDataAdapter("select * from H_Claims where Claim_Reference_Num in (select Claim_No from S_Acc_Claim) and Imported = 'T'", sInforConnectionString);
- OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(claimAdapter);
- claimAdapter.InsertCommand = commandBuilder.GetInsertCommand(true);
- claimAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
- // Dataset
- DataSet dataSet = new DataSet();
- stagingAdapter.SelectCommand.CommandTimeout = 1200;
- stagingAdapter.Fill(dataSet, "S_Acc_Claim");
- claimAdapter.SelectCommand.CommandTimeout = 1200;
- claimAdapter.Fill(dataSet, "H_Claims");
- // Tables
- DataTable accessClaim = dataSet.Tables["S_Acc_Claim"];
- DataTable claim = dataSet.Tables["H_Claims"];
- int i = 1;
- // Log
- Log("Importing...");
- // Counts
- int newClaimCount = 0;
- int updatedClaimCount = 0;
- foreach (DataRow s in accessClaim.Rows) {
- // Claim number
- object claimNumber = ClaimNumber(s["Claim_No"]);
- // Incident type
- string incidentType = null;
- // Claim type
- object claimTypeObject = Truncate(200, ConvertDDField(s, "DD_Claim_Type", "Claim_Type", new string[] { "Claim", "Notification" }));
- string claimType = "";
- if (claimTypeObject != DBNull.Value)
- claimType = ((string)claimTypeObject).ToLower();
- if (!new string[] { "claim", "notification" }.Contains(claimType)) {
- if ((sTeam == Team.RisksmartGCC) && claimType.Contains("motor vehicle")) {
- claimType = "claim";
- incidentType = "Recovery - Motor Vehicle Impact/ Accident";
- }
- else
- claimType = "unknown";
- }
- claimType = claimType.First().ToString().ToUpper() + claimType.Substring(1);
- // Status
- object statusObject = Truncate(200, ConvertDDField(s, "DD_Claim_Status", "Claim_Status"));
- string status = "";
- if (statusObject != DBNull.Value)
- status = ((string)statusObject).ToLower();
- // Open or notification
- bool isOpen = status.Contains("open");
- bool isOpenOrNotification = isOpen || (new string[] { "Claim", "Notification" }.Contains(claimType));
- // Team check
- string clientGroup = (s["DD_Client_Group"] != DBNull.Value ? ((string)s["DD_Client_Group"]).ToLower() : "");
- if (sTeam == Team.RisksmartGCC) {
- if (!(new string[] { "aldi", "ezko property services (aust) retail pty ltd", "ezko property services (aust) pty ltd", "whirlpool", "millers liability",
- "folkestone limited", " hydro flow pty ltd", "hydro flow pty ltd" }).Contains(clientGroup))
- {
- continue; // Skip
- }
- }
- else if (sTeam == Team.RisksmartProperty) {
- if (!(new string[] { "chu strata", /*"honan lloyds facility",*/ "honan residential landlords property" }).Contains(clientGroup))
- continue; // Skip
- }
- // Validation
- if (claimNumber == DBNull.Value) {
- LogError("Missing claim field: 'claim_no'");
- continue;
- }
- if ((s["DD_Claim_Type"] == DBNull.Value) && (s["Claim_Type"] == DBNull.Value)) {
- //LogError("Missing claim field (" + claimNumber + "): 'claim_type'");
- //continue;
- LogError("Missing claim field (" + claimNumber + "): 'claim_type'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CLAIM_TYPE, (string)claimNumber);
- continue;
- }
- else if (((s["DD_Claim_Type"] == DBNull.Value) || (!new string[] { "claim", "notification" }.Contains(((string)s["DD_Claim_Type"]).ToLower()))) &&
- ((s["Claim_Type"] == DBNull.Value) || (!new string[] { "claim", "notification" }.Contains(((string)s["Claim_Type"]).ToLower()))))
- {
- //LogError("Invalid claim type (" + claimNumber + "): '" + s["DD_Claim_Type"] + "' / '" + s["Claim_Type"] + "'");
- //continue;
- LogWarning("Invalid claim type (" + claimNumber + "): '" + s["DD_Claim_Type"] + "' / '" + s["Claim_Type"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.INVALID_CLAIM_TYPE, (string)claimNumber, s["DD_Claim_Type"] + "', '" + s["Claim_Type"] + "'");
- }
- /*if ((s["Policy_Number"] == DBNull.Value) || ((string)s["Policy_Number"]).ToLower().Contains("xx") || ((string)s["Policy_Number"]).ToLower().Contains("tba")) {
- LogError("Missing claim field (" + claimNumber + "): 'policy_number'");
- continue;
- }*/
- //if ((s["DD_Insured"] == DBNull.Value) && (s["Insured"] == DBNull.Value)) {
- // LogError("Missing claim field (" + claimNumber + "): 'dd_unsured/insured'");
- // continue;
- //}
- //if (s["Date_Reported"] == DBNull.Value) {
- // LogError("Missing claim field (" + claimNumber + "): 'date_reported'");
- // continue;
- //}
- //if ((sTeam == Team.RisksmartGCC) && (s["Incident_Name"] == DBNull.Value)) {
- // LogError("Missing claim field (" + claimNumber + "): 'incident_name'");
- // continue;
- //}
- //if (s["Incident_Date"] == DBNull.Value) {
- // LogError("Missing claim field (" + claimNumber + "): 'incident_date'");
- // continue;
- //}
- // Existing claim
- DataRow c = null;
- DataRow[] claims = claim.Select("Claim_Reference_Num = '" + claimNumber + "'");
- if (claims.Length > 0) {
- if (claims.Length > 1) {
- LogWarning("Claim found more than once: '" + s["Claim_No"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.MULTIPLE_CLAIMS_FOUND, (string)claimNumber);
- }
- c = claims[0];
- }
- // Claim row
- Operation operation = (c == null ? Operation.Insert : Operation.Update);
- if (c == null)
- c = claim.NewRow();
- // ID
- object claimID = ((operation == Operation.Insert) ? Infor.IDFor("H_Claims", connection) : c["H_ClaimsID"]);
- // SLX
- c["H_ClaimsID"] = claimID;
- c["CreateUser"] = "ADMIN";
- //c["CreateDate"] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
- c["CreateDate"] = ConvertDateTime(s["Date_Registered"], claimNumber);
- c["ModifyUser"] = "ADMIN";
- //c["ModifyDate"] = c["CreateDate"];
- c["ModifyDate"] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
- // Claim
- c["Imported"] = "T";
- c["Claim_Reference_Num"] = Truncate(20, claimNumber);
- //c["Claim_Type"] = Truncate(200, ConvertDDField(s, "DD_Claim_Type", "Claim_Type", new string[] { "Claim", "Notification" }));
- c["Claim_Type"] = claimType;
- c["Claim_Status"] = statusObject;
- c["Reported_Date"] = ConvertDateTime(s["Date_Reported"], claimNumber);
- c["Reported_Time"] = ConvertDateTime(s["Date_Reported"], claimNumber);
- c["Client_Group"] = Truncate(400, s["DD_Client_Group"]);
- // Team
- c["Claim_Team_Name"] = TeamName();
- switch (sTeam) {
- case Team.RisksmartGCC: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Risksmart GCC Team'", connection); break;
- case Team.RisksmartProperty: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Risksmart Property Team'", connection); break;
- }
- c["SeccodeID"] = c["Claim_Team"];
- // Policy
- c["Policy_No_Name"] = PolicyNumber(Truncate(200, s["Policy_Number"]));
- c["Imported_Policy_Number"] = c["Policy_No_Name"];
- if (/*isOpenOrNotification && */(c["Policy_No_Name"] != DBNull.Value)) {
- c["Policy_No"] = Infor.GetField("H_PolicyID", "H_Policy", "Policy_Number = '" + ((string)c["Policy_No_Name"]).Replace("'", "''") + "'", connection) ?? DBNull.Value;
- if (c["Policy_No"] == DBNull.Value) {
- LogWarning("Policy not found (" + claimNumber + "): '" + c["Policy_No_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.POLICY_NOT_FOUND, (string)claimNumber, c["Policy_No_Name"].ToString());
- AddMissingPolicy((string)c["Policy_No_Name"], isOpen);
- }
- }
- c["Binder"] = Truncate(200, s["Binder_Number"]);
- c["Policy_Section"] = Truncate(400, ConvertDDField(s, "DD_Policy_Section", "Segment"));
- // Account
- c["Account_Name"] = AccountName(Truncate(200, ConvertDDField(s, "DD_Insured", "Insured"))) ?? DBNull.Value;
- c["Imported_Account_Name"] = c["Account_Name"];
- if (/*isOpenOrNotification && */(c["Account_Name"] != DBNull.Value)) {
- c["AccountID"] = Infor.GetField("AccountID", "Account", "Type = 'Customer' and (Account = '" + ((string)c["Account_Name"]).Replace("'", "''") + "' or Client_Code = '" + c["Account_Name"] +
- "' or ExternalAccountNo = '" + c["Account_Name"] + "')", connection) ?? DBNull.Value;
- if (c["AccountID"] != DBNull.Value)
- c["Account_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["AccountID"] + "'", connection);
- else {
- LogWarning("Account not found (" + claimNumber + "): '" + c["Account_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.CUSTOMER_NOT_FOUND, (string)claimNumber, c["Account_Name"].ToString());
- AddMissingCustomer((string)c["Account_Name"], isOpen);
- }
- }
- // Insurance
- c["Insurer_Name"] = AccountName(Truncate(200, ConvertDDField(s, "DD_Insurer", "Insurer"))) ?? DBNull.Value;
- c["Imported_Insurer_Name"] = c["Insurer_Name"];
- if (/*isOpenOrNotification && */(c["Insurer_Name"] != DBNull.Value)) {
- c["Insurer"] = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and (Account = '" + ((string)c["Insurer_Name"]).Replace("'", "''") + "' or Client_Code = '" + c["Insurer_Name"] +
- "' or ExternalAccountNo = '" + c["Insurer_Name"] + "')", connection) ?? DBNull.Value;
- if (c["Insurer"] != DBNull.Value)
- c["Insurer_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Insurer"] + "'", connection);
- else {
- LogWarning("Insurer not found (" + claimNumber + "): '" + c["Insurer_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.UNDERWRITER_NOT_FOUND, (string)claimNumber, c["Insurer_Name"].ToString());
- AddMissingUnderwriter((string)c["Insurer_Name"], isOpen);
- }
- }
- c["Insured_Name"] = Truncate(200, ConvertDDField(s, "DD_Insured", "Insured"));
- c["Insurer_Ref"] = Truncate(200, s["Insurer_Reference"]);
- // Broker
- c["Broker_Company_Name"] = AccountName(Truncate(200, ConvertDDField(s, "DD_Broker", "Broker"))) ?? DBNull.Value;
- c["Imported_Broker_Name"] = c["Broker_Company_Name"];
- if (/*isOpenOrNotification && */(c["Broker_Company_Name"] != DBNull.Value)) {
- c["Broker_Company"] = Infor.GetField("AccountID", "Account", "Type = 'Associate' and (Account = '" + ((string)c["Broker_Company_Name"]).Replace("'", "''") + "' or Client_Code = '" + c["Broker_Company_Name"] +
- "' or ExternalAccountNo = '" + c["Broker_Company_Name"] + "')", connection) ?? DBNull.Value;
- if (c["Broker_Company"] != DBNull.Value)
- c["Broker_Company_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Broker_Company"] + "'", connection);
- else {
- LogWarning("Broker company not found (" + claimNumber + "): '" + c["Broker_Company_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSOCIATE_NOT_FOUND, (string)claimNumber, c["Broker_Company_Name"].ToString());
- AddMissingAssociate((string)c["Broker_Company_Name"], isOpen);
- }
- }
- // Assigned user
- if (s["Claim_Operator"] != DBNull.Value) {
- string username = (string)UserName(s["Claim_Operator"]);
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = '" + username + "'", connection) ?? DBNull.Value;
- if (c["Assigned_User"] == DBNull.Value) {
- // Log
- LogWarning("Assigned user not found: '" + username + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSIGNED_USER_NOT_FOUND, (string)claimNumber, username);
- AddMissingUser(username, isOpen);
- // Fallback user
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = 'Ms Megan Peacock'", connection) ?? DBNull.Value;
- }
- }
- c["Assigned_Date"] = ConvertDateTime(s["Date_Registered"], claimNumber);
- // Claimant
- c["Claimant_First_Name"] = Truncate(200, ConvertFirstName(s["Claimant_1"]));
- c["Claimant_Last_Name"] = Truncate(200, ConvertLastName(s["Claimant_1"]));
- c["Claimant_Address"] = Truncate(400, JoinStringFields(s["Claimant_Address"], s["Claimant_1_State"], ", "));
- c["Date_Of_Birth"] = Truncate(32, s["Date_Of_Birth"]);
- c["Claimant_Work_Phone"] = Truncate(200, ConvertWorkPhone(s["Contact_No"]));
- c["Claimant_Mobile_Phone"] = Truncate(200, ConvertMobilePhone(s["Contact_No"]));
- c["Email_Address"] = Truncate(200, s["Email_Address"]);
- // Incident
- c["Incident_Name"] = Truncate(400, s["Incident_Name"]);
- object incidentAddress = JoinStringFields(s["DD_Incident_Location_Address"], s["DD_Incident_Location_Suburb"], ", ");
- incidentAddress = JoinStringFields(incidentAddress, s["DD_Incident_Location_State"], ", ");
- incidentAddress = JoinStringFields(incidentAddress, s["DD_Incident_Location_Postcode"], ", ");
- c["Incident_Address"] = Truncate(400, incidentAddress);
- c["Incident_Date"] = ConvertDateTime(s["Incident_Date"], claimNumber);
- c["Incident_Time"] = ConvertDateTime(s["Incident_Date"], claimNumber);
- c["Incident_Category"] = Truncate(400, ConvertDDField(s, "DD_Incident_Category", "Incident_Category"));
- c["Incident_Summary"] = s["Incident_Description"];
- if (incidentType != null)
- c["Incident_Type"] = incidentType;
- c["Juristiction"] = Truncate(32, ConvertDDField(s, "DD_Jurisdiction", "Jurisdiction"));
- c["Bodily_Location"] = Truncate(200, ConvertDDField(s, "DD_Bodily_Location", "Bodily_Location"));
- // Store
- c["StoreID_Name"] = Truncate(200, ConvertDDField(s, "DD_Incident_Location_Code", "Incident_Location"));
- if ((c["StoreID_Name"] != null) && (c["StoreID_Name"] != DBNull.Value))
- c["Region"] = Truncate(200, RegionFromStore((string)c["StoreID_Name"], (string)claimNumber));
- // Trading name
- //c["Trading_Name"] = s["Trading"]
- // Property
- //c["Property_Address_1"] = Truncate(200, s["DD_Incident_Location_Address"]);
- c["Property_Address_1"] = Truncate(200, JoinStringFields(s["Claimant_Address"], s["Claimant_1_State"], ", "));
- c["Property_Suburb"] = Truncate(200, s["DD_Incident_Location_Suburb"]);
- c["Property_State"] = Truncate(32, s["DD_Incident_Location_State"]);
- c["Property_Postalcode"] = Truncate(32, s["DD_Incident_Location_Postcode"]);
- if (sTeam == Team.RisksmartProperty)
- c["Loss_Details"] = s["Incident_Description"];
- // Other
- c["Date_Of_Loss"] = ConvertDateTime(s["Incident_Date"], claimNumber);
- //c["Are_You_GST_Registered"] = ; // Claim doesn't have a gst property - only financial t records do
- // Reserve
- c["Liability_Res_Source"] = s["Reserve"];
- // State
- //c["Review"] = (ConvertDateTime(s["Date_Reviewed"], claimNumber) != DBNull.Value ? "T" : "F");
- //c["Review_Date"] = ConvertDateTime(s["Date_Reviewed"], claimNumber);
- c["Claim_Closed"] = (ConvertDateTime(s["Date_Closed"], claimNumber) != DBNull.Value ? "T" : "F");
- c["Claim_Closed_Date"] = ConvertDateTime(s["Date_Closed"], claimNumber);
- // E-mail on 09/10/2017 - RE: Important Task - Data Check - Risksmart GCC Imported Claims Data
- // Decision was to remove inferring value of these fields.
- //c["Outcome_Settlement"] = (new string[] { "closed paid", "open pending settlement" }.Contains(status)) ? "T" : "F";
- //c["Outcome_Declined"] = (new string[] { "closed declined", "open declined (pending mgt review)" }.Contains(status)) ? "T" : "F";
- //if (new string[] { "closed paid", "open pending settlement" }.Contains(status))
- // c["Outcome"] = "Settled";
- //else if (new string[] { "closed declined", "open declined (pending mgt review)" }.Contains(status))
- // c["Outcome"] = "Denied";
- //else if (new string[] { "closed withdrawn" }.Contains(status))
- // c["Outcome"] = "Withdrawn";
- //else if (new string[] { "closed" }.Contains(status))
- // c["Outcome"] = "No Further Action";
- //if (c["Outcome"] != DBNull.Value)
- // c["Outcome_Date"] = ConvertDateTime(s["Date_Closed"], claimNumber);
- // Add
- if (operation == Operation.Insert)
- claim.Rows.Add(c);
- // Log
- Log((operation == Operation.Update ? "Updated " : "") + "Claim (" + claimID + "): " + claimNumber);
- if (operation == Operation.Insert)
- ++newClaimCount;
- else
- ++updatedClaimCount;
- ++i;
- }
- // Insert
- Log("Applying to database...");
- claimAdapter.InsertCommand.CommandTimeout = 3000;
- claimAdapter.UpdateCommand.CommandTimeout = 3000;
- claimAdapter.Update(claim);
- // Delete duplicates
- Log("Culling duplicates...");
- OleDbCommand command = new OleDbCommand("delete from S_Acc_Claim where Claim_No in (select Claim_Reference_Num from H_Claims where Imported = 'T' and Claim_Team_Name = '" + TeamName() + "')", connection);
- command.ExecuteNonQuery();
- // Close connection
- connection.Close();
- // Summary
- IssueTracker.LogSummary(TeamName() + ": Importing Access claims (" + sTime + ")");
- // Missing
- LogMissingSummary(TeamName() + ": Importing Access claims (" + sTime + ")");
- // Summary
- Log("\n--------------------------------------------------------------------------------");
- Log("RESULTS (" + TeamName() + ": Importing Access claims (" + sTime + ")):");
- Log(" " + newClaimCount + " claims added.");
- Log(" " + updatedClaimCount + " claims updated.\n");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static void ImportAccessClaims_OLD() {
- // DEV
- //Log("DEV: Deleting imported claims to keep S_ACC_CLAIM populated");
- //DeleteImportedData(true);
- // Log
- Log("\n================================================================================");
- Log("Importing Access claims...");
- Log("================================================================================");
- Log("Team: " + TeamName());
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // Delete duplicates
- Log("Culling duplicates...");
- OleDbCommand command = new OleDbCommand("delete from S_Acc_Claim where Claim_No in (select Claim_Reference_Num from H_Claims)", connection);
- command.ExecuteNonQuery();
- // Adapters
- Log("Retrieving imported claim data...");
- OleDbDataAdapter stagingAdapter = new OleDbDataAdapter("select * from S_Acc_Claim", sInforConnectionString);
- OleDbDataAdapter claimAdapter = new OleDbDataAdapter("select * from H_Claims where 1=0", sInforConnectionString);
- OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(claimAdapter);
- claimAdapter.InsertCommand = commandBuilder.GetInsertCommand(true);
- claimAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
- // Dataset
- DataSet dataSet = new DataSet();
- stagingAdapter.Fill(dataSet, "S_Acc_Claim");
- claimAdapter.Fill(dataSet, "H_Claims");
- // Convert
- DataTable accessClaim = dataSet.Tables["S_Acc_Claim"];
- DataTable claim = dataSet.Tables["H_Claims"];
- int i = 1;
- foreach (DataRow s in accessClaim.Rows) {
- // Claim number
- object claimNumber = ClaimNumber(s["Claim_No"]);
- // Incident type
- string incidentType = null;
- // Claim type
- object claimTypeObject = Truncate(200, ConvertDDField(s, "DD_Claim_Type", "Claim_Type", new string[] { "Claim", "Notification" }));
- string claimType = "";
- if (claimTypeObject != DBNull.Value)
- claimType = ((string)claimTypeObject).ToLower();
- if (!new string[] { "claim", "notification" }.Contains(claimType)) {
- if ((sTeam == Team.RisksmartGCC) && claimType.Contains("motor vehicle")) {
- claimType = "claim";
- incidentType = "Recovery - Motor Vehicle Impact/ Accident";
- }
- else
- claimType = "unknown";
- }
- claimType = claimType.First().ToString().ToUpper() + claimType.Substring(1);
- // Status
- object statusObject = Truncate(200, ConvertDDField(s, "DD_Claim_Status", "Claim_Status"));
- string status = "";
- if (statusObject != DBNull.Value)
- status = ((string)statusObject).ToLower();
- // Open or notification
- bool isOpen = status.Contains("open");
- bool isOpenOrNotification = isOpen || (new string[] { "Claim", "Notification" }.Contains(claimType));
- // Team check
- string clientGroup = (s["DD_Client_Group"] != DBNull.Value ? ((string)s["DD_Client_Group"]).ToLower() : "");
- if (sTeam == Team.RisksmartGCC) {
- if (!(new string[] { "aldi", "ezko property services (aust) retail pty ltd", "ezko property services (aust) pty ltd", "whirlpool", "millers liability",
- "folkestone limited", " hydro flow pty ltd", "hydro flow pty ltd" }).Contains(clientGroup))
- {
- continue; // Skip
- }
- }
- else if (sTeam == Team.RisksmartProperty) {
- if (!(new string[] { "chu strata", /*"honan lloyds facility",*/ "honan residential landlords property" }).Contains(clientGroup))
- continue; // Skip
- }
- // Validation
- if (claimNumber == DBNull.Value) {
- LogError("Missing claim field: 'claim_no'");
- continue;
- }
- if ((s["DD_Claim_Type"] == DBNull.Value) && (s["Claim_Type"] == DBNull.Value)) {
- //LogError("Missing claim field (" + claimNumber + "): 'claim_type'");
- //continue;
- LogError("Missing claim field (" + claimNumber + "): 'claim_type'");
- IssueTracker.AddError(IssueTracker.Issue.MISSING_CLAIM_TYPE, (string)claimNumber);
- continue;
- }
- else if (((s["DD_Claim_Type"] == DBNull.Value) || (!new string[] { "claim", "notification" }.Contains(((string)s["DD_Claim_Type"]).ToLower()))) &&
- ((s["Claim_Type"] == DBNull.Value) || (!new string[] { "claim", "notification" }.Contains(((string)s["Claim_Type"]).ToLower()))))
- {
- //LogError("Invalid claim type (" + claimNumber + "): '" + s["DD_Claim_Type"] + "' / '" + s["Claim_Type"] + "'");
- //continue;
- LogWarning("Invalid claim type (" + claimNumber + "): '" + s["DD_Claim_Type"] + "' / '" + s["Claim_Type"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.INVALID_CLAIM_TYPE, (string)claimNumber, s["DD_Claim_Type"] + "', '" + s["Claim_Type"] + "'");
- }
- /*if ((s["Policy_Number"] == DBNull.Value) || ((string)s["Policy_Number"]).ToLower().Contains("xx") || ((string)s["Policy_Number"]).ToLower().Contains("tba")) {
- LogError("Missing claim field (" + claimNumber + "): 'policy_number'");
- continue;
- }*/
- //if ((s["DD_Insured"] == DBNull.Value) && (s["Insured"] == DBNull.Value)) {
- // LogError("Missing claim field (" + claimNumber + "): 'dd_unsured/insured'");
- // continue;
- //}
- //if (s["Date_Reported"] == DBNull.Value) {
- // LogError("Missing claim field (" + claimNumber + "): 'date_reported'");
- // continue;
- //}
- //if ((sTeam == Team.RisksmartGCC) && (s["Incident_Name"] == DBNull.Value)) {
- // LogError("Missing claim field (" + claimNumber + "): 'incident_name'");
- // continue;
- //}
- //if (s["Incident_Date"] == DBNull.Value) {
- // LogError("Missing claim field (" + claimNumber + "): 'incident_date'");
- // continue;
- //}
- // New row
- DataRow c = claim.NewRow();
- // SLX
- object claimID = Infor.IDFor("H_Claims", connection);
- c["H_ClaimsID"] = claimID;
- c["CreateUser"] = "ADMIN";
- //c["CreateDate"] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
- c["CreateDate"] = ConvertDateTime(s["Date_Registered"], claimNumber);
- c["ModifyUser"] = "ADMIN";
- c["ModifyDate"] = c["CreateDate"];
- // Claim
- c["Imported"] = "T";
- c["Claim_Reference_Num"] = Truncate(20, claimNumber);
- //c["Claim_Type"] = Truncate(200, ConvertDDField(s, "DD_Claim_Type", "Claim_Type", new string[] { "Claim", "Notification" }));
- c["Claim_Type"] = claimType;
- c["Claim_Status"] = statusObject;
- c["Reported_Date"] = ConvertDateTime(s["Date_Reported"], claimNumber);
- c["Reported_Time"] = ConvertDateTime(s["Date_Reported"], claimNumber);
- c["Client_Group"] = Truncate(400, s["DD_Client_Group"]);
- // Team
- c["Claim_Team_Name"] = TeamName();
- switch (sTeam) {
- case Team.RisksmartGCC: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Risksmart GCC Team'", connection); break;
- case Team.RisksmartProperty: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Risksmart Property Team'", connection); break;
- }
- c["SeccodeID"] = c["Claim_Team"];
- // Policy
- c["Policy_No_Name"] = PolicyNumber(Truncate(200, s["Policy_Number"]));
- c["Imported_Policy_Number"] = c["Policy_No_Name"];
- if (/*isOpenOrNotification && */(c["Policy_No_Name"] != DBNull.Value)) {
- c["Policy_No"] = Infor.GetField("H_PolicyID", "H_Policy", "Policy_Number = '" + ((string)c["Policy_No_Name"]).Replace("'", "''") + "'", connection) ?? DBNull.Value;
- if (c["Policy_No"] == DBNull.Value) {
- LogWarning("Policy not found (" + claimNumber + "): '" + c["Policy_No_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.POLICY_NOT_FOUND, (string)claimNumber, c["Policy_No_Name"].ToString());
- AddMissingPolicy((string)c["Policy_No_Name"], isOpen);
- }
- }
- c["Binder"] = Truncate(200, s["Binder_Number"]);
- c["Policy_Section"] = Truncate(400, ConvertDDField(s, "DD_Policy_Section", "Segment"));
- // Account
- c["Account_Name"] = AccountName(Truncate(200, ConvertDDField(s, "DD_Insured", "Insured"))) ?? DBNull.Value;
- c["Imported_Account_Name"] = c["Account_Name"];
- if (/*isOpenOrNotification && */(c["Account_Name"] != DBNull.Value)) {
- c["AccountID"] = Infor.GetField("AccountID", "Account", "Type = 'Customer' and (Account = '" + ((string)c["Account_Name"]).Replace("'", "''") + "' or Client_Code = '" + c["Account_Name"] +
- "' or ExternalAccountNo = '" + c["Account_Name"] + "')", connection) ?? DBNull.Value;
- if (c["AccountID"] != DBNull.Value)
- c["Account_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["AccountID"] + "'", connection);
- else {
- LogWarning("Account not found (" + claimNumber + "): '" + c["Account_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.CUSTOMER_NOT_FOUND, (string)claimNumber, c["Account_Name"].ToString());
- AddMissingCustomer((string)c["Account_Name"], isOpen);
- }
- }
- // Insurance
- c["Insurer_Name"] = AccountName(Truncate(200, ConvertDDField(s, "DD_Insurer", "Insurer"))) ?? DBNull.Value;
- c["Imported_Insurer_Name"] = c["Insurer_Name"];
- if (/*isOpenOrNotification && */(c["Insurer_Name"] != DBNull.Value)) {
- c["Insurer"] = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and (Account = '" + ((string)c["Insurer_Name"]).Replace("'", "''") + "' or Client_Code = '" + c["Insurer_Name"] +
- "' or ExternalAccountNo = '" + c["Insurer_Name"] + "')", connection) ?? DBNull.Value;
- if (c["Insurer"] != DBNull.Value)
- c["Insurer_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Insurer"] + "'", connection);
- else {
- LogWarning("Insurer not found (" + claimNumber + "): '" + c["Insurer_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.UNDERWRITER_NOT_FOUND, (string)claimNumber, c["Insurer_Name"].ToString());
- AddMissingUnderwriter((string)c["Insurer_Name"], isOpen);
- }
- }
- c["Insured_Name"] = Truncate(200, ConvertDDField(s, "DD_Insured", "Insured"));
- c["Insurer_Ref"] = Truncate(200, s["Insurer_Reference"]);
- // Broker
- c["Broker_Company_Name"] = AccountName(Truncate(200, ConvertDDField(s, "DD_Broker", "Broker"))) ?? DBNull.Value;
- c["Imported_Broker_Name"] = c["Broker_Company_Name"];
- if (/*isOpenOrNotification && */(c["Broker_Company_Name"] != DBNull.Value)) {
- c["Broker_Company"] = Infor.GetField("AccountID", "Account", "Type = 'Associate' and (Account = '" + ((string)c["Broker_Company_Name"]).Replace("'", "''") + "' or Client_Code = '" + c["Broker_Company_Name"] +
- "' or ExternalAccountNo = '" + c["Broker_Company_Name"] + "')", connection) ?? DBNull.Value;
- if (c["Broker_Company"] != DBNull.Value)
- c["Broker_Company_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Broker_Company"] + "'", connection);
- else {
- LogWarning("Broker company not found (" + claimNumber + "): '" + c["Broker_Company_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSOCIATE_NOT_FOUND, (string)claimNumber, c["Broker_Company_Name"].ToString());
- AddMissingAssociate((string)c["Broker_Company_Name"], isOpen);
- }
- }
- // Assigned user
- if (s["Claim_Operator"] != DBNull.Value) {
- string username = (string)UserName(s["Claim_Operator"]);
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = '" + username + "'", connection) ?? DBNull.Value;
- if (c["Assigned_User"] == DBNull.Value) {
- // Log
- LogWarning("Assigned user not found: '" + username + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSIGNED_USER_NOT_FOUND, (string)claimNumber, username);
- AddMissingUser(username, isOpen);
- // Fallback user
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = 'Ms Megan Peacock'", connection) ?? DBNull.Value;
- }
- }
- c["Assigned_Date"] = ConvertDateTime(s["Date_Registered"], claimNumber);
- // Claimant
- c["Claimant_First_Name"] = Truncate(200, ConvertFirstName(s["Claimant_1"]));
- c["Claimant_Last_Name"] = Truncate(200, ConvertLastName(s["Claimant_1"]));
- c["Claimant_Address"] = Truncate(400, JoinStringFields(s["Claimant_Address"], s["Claimant_1_State"], ", "));
- c["Date_Of_Birth"] = Truncate(32, s["Date_Of_Birth"]);
- c["Claimant_Work_Phone"] = Truncate(200, ConvertWorkPhone(s["Contact_No"]));
- c["Claimant_Mobile_Phone"] = Truncate(200, ConvertMobilePhone(s["Contact_No"]));
- c["Email_Address"] = Truncate(200, s["Email_Address"]);
- // Incident
- c["Incident_Name"] = Truncate(400, s["Incident_Name"]);
- object incidentAddress = JoinStringFields(s["DD_Incident_Location_Address"], s["DD_Incident_Location_Suburb"], ", ");
- incidentAddress = JoinStringFields(incidentAddress, s["DD_Incident_Location_State"], ", ");
- incidentAddress = JoinStringFields(incidentAddress, s["DD_Incident_Location_Postcode"], ", ");
- c["Incident_Address"] = Truncate(400, incidentAddress);
- c["Incident_Date"] = ConvertDateTime(s["Incident_Date"], claimNumber);
- c["Incident_Time"] = ConvertDateTime(s["Incident_Date"], claimNumber);
- c["Incident_Category"] = Truncate(400, ConvertDDField(s, "DD_Incident_Category", "Incident_Category"));
- c["Incident_Summary"] = s["Incident_Description"];
- if (incidentType != null)
- c["Incident_Type"] = incidentType;
- c["Juristiction"] = Truncate(32, ConvertDDField(s, "DD_Jurisdiction", "Jurisdiction"));
- c["Bodily_Location"] = Truncate(200, ConvertDDField(s, "DD_Bodily_Location", "Bodily_Location"));
- // Store
- c["StoreID_Name"] = Truncate(200, ConvertDDField(s, "DD_Incident_Location_Code", "Incident_Location"));
- if ((c["StoreID_Name"] != null) && (c["StoreID_Name"] != DBNull.Value))
- c["Region"] = Truncate(200, RegionFromStore((string)c["StoreID_Name"], (string)claimNumber));
- // Trading name
- //c["Trading_Name"] = s["Trading"]
- // Property
- //c["Property_Address_1"] = Truncate(200, s["DD_Incident_Location_Address"]);
- c["Property_Address_1"] = Truncate(200, JoinStringFields(s["Claimant_Address"], s["Claimant_1_State"], ", "));
- c["Property_Suburb"] = Truncate(200, s["DD_Incident_Location_Suburb"]);
- c["Property_State"] = Truncate(32, s["DD_Incident_Location_State"]);
- c["Property_Postalcode"] = Truncate(32, s["DD_Incident_Location_Postcode"]);
- if (sTeam == Team.RisksmartProperty)
- c["Loss_Details"] = s["Incident_Description"];
- // Other
- c["Date_Of_Loss"] = ConvertDateTime(s["Incident_Date"], claimNumber);
- //c["Are_You_GST_Registered"] = ; // Claim doesn't have a gst property - only financial t records do
- // Reserve
- c["Liability_Res_Source"] = s["Reserve"];
- // State
- //c["Review"] = (ConvertDateTime(s["Date_Reviewed"], claimNumber) != DBNull.Value ? "T" : "F");
- //c["Review_Date"] = ConvertDateTime(s["Date_Reviewed"], claimNumber);
- c["Claim_Closed"] = (ConvertDateTime(s["Date_Closed"], claimNumber) != DBNull.Value ? "T" : "F");
- c["Claim_Closed_Date"] = ConvertDateTime(s["Date_Closed"], claimNumber);
- // E-mail on 09/10/2017 - RE: Important Task - Data Check - Risksmart GCC Imported Claims Data
- // Decision was to remove inferring value of these fields.
- //c["Outcome_Settlement"] = (new string[] { "closed paid", "open pending settlement" }.Contains(status)) ? "T" : "F";
- //c["Outcome_Declined"] = (new string[] { "closed declined", "open declined (pending mgt review)" }.Contains(status)) ? "T" : "F";
- //if (new string[] { "closed paid", "open pending settlement" }.Contains(status))
- // c["Outcome"] = "Settled";
- //else if (new string[] { "closed declined", "open declined (pending mgt review)" }.Contains(status))
- // c["Outcome"] = "Denied";
- //else if (new string[] { "closed withdrawn" }.Contains(status))
- // c["Outcome"] = "Withdrawn";
- //else if (new string[] { "closed" }.Contains(status))
- // c["Outcome"] = "No Further Action";
- //if (c["Outcome"] != DBNull.Value)
- // c["Outcome_Date"] = ConvertDateTime(s["Date_Closed"], claimNumber);
- // Add
- claim.Rows.Add(c);
- Log("Claim (" + claimID + "): " + claimNumber);
- ++i;
- }
- // Insert
- Log("Applying to database...");
- claimAdapter.InsertCommand.CommandTimeout = 1800;
- claimAdapter.Update(claim);
- // Close connection
- connection.Close();
- // Summary
- IssueTracker.LogSummary("");
- // Missing
- LogMissingSummary("");
- }
- // WINBEAT ================================================================================
- //--------------------------------------------------------------------------------
- private static void ImportWinBEATClaims(WinbeatLedger ledger, bool insertOnly = true) {
- // Log
- Log("================================================================================");
- Log(TeamName() + ": Importing " + (insertOnly ? "" : "and updating ") + "WinBEAT claims (" + sTime + ")");
- Log("================================================================================");
- // Connection string
- string connectionString;
- switch (ledger) {
- case WinbeatLedger.Melbourne: connectionString = sWBMelbourneConnectionString; break;
- case WinbeatLedger.RealEstate: connectionString = sWBRealEstateConnectionString; break;
- case WinbeatLedger.Underwriting: connectionString = sWBRisksmartPropertyConnectionString; break;
- default:
- LogError("Invalid team selected");
- return;
- }
- // Connection
- OleDbConnection inforConnection = new OleDbConnection(sInforConnectionString);
- inforConnection.Open();
- // Query
- string query = "select _C.*, _U.CatCode as UDD_CatCode, _U.ClaimStatus as UDD_ClaimStatus, ";
- if (ledger != WinbeatLedger.Underwriting) {
- query += "_U.ClaimantName as UDD_ClaimantName, _U.ClaimNextAction as UDD_ClaimNextAction, _U.ProximateCause as UDD_ProximateCause, " +
- "_U.ClaimDetail as UDD_ClaimDetail, _U.ClaimCategory as UDD_ClaimCategory, ";
- }
- if (ledger == WinbeatLedger.RealEstate)
- query += "_U.GSTStatus as UDD_GSTStatus, _U.ClaimsHandler as UDD_ClaimsHandler, ";
- else if (ledger == WinbeatLedger.Melbourne)
- query += "_U.ClaimOfficer as UDD_ClaimOfficer, ";
- query += "_CC.Code as Client_Code, _CC.Name as Client_Name, _CC.ABN as Client_ABN, " +
- "_AM.Code as AccountManager_Code, " +
- "_CCG.Abbrev as ClientGroup_Abbrev, _CCG.Code as ClientGroup_Code, " +
- "_CU.Code as Underwriter_Code, _CU.Name as Underwriter_Name, " +
- "_P.PolicyNumber as Policy_PolicyNumber, _P.InceptionDate as Policy_InceptionDate, _P.ExpiryDate as Policy_ExpiryDate, " +
- "_PC.Abbrev as PolicyClass_Abbrev, _PC.Description as PolicyClass_Description, " +
- "_PU.Code as PolicyUnderwriter_Code, " +
- "_PS.Code as PolicySubInter_Code, _PS.Name as PolicySubInter_Name " +
- "from Claim _C " +
- "left join UDDataClaim _U on _C.ClaimID = _U.ClaimID " +
- "left join Client _CC on _C.ClaimClientID = _CC.ClientID " +
- "left join AccountManager _AM on _CC.AccountManagerID = _AM.AccountManagerID " +
- "left join ClientGroup _CCG on _CC.ClientGroupID = _CCG.ClientGroupID " +
- "left join Underwriter _CU on _C.ClaimUnderwriterID = _CU.UnderwriterID " +
- "left join Policy _P on _C.PolicyID = _P.PolicyID " +
- "left join Class _PC on _P.ClassID = _PC.ClassID " +
- "left join Underwriter _PU on _P.UnderwriterID = _PU.UnderwriterID " +
- "left join SubInter _PS on _P.SubInterID = _PS.SubInterID";
- // Adapter
- Log("Retrieving claim data...");
- SqlDataAdapter winbeatAdapter = new SqlDataAdapter(query, connectionString);
- OleDbDataAdapter inforAdapter = new OleDbDataAdapter("select * from H_Claims where 1=0", sInforConnectionString);
- OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(inforAdapter);
- inforAdapter.InsertCommand = commandBuilder.GetInsertCommand(true);
- inforAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
- // Dataset
- DataSet dataSet = new DataSet();
- winbeatAdapter.SelectCommand.CommandTimeout = 1200;
- winbeatAdapter.Fill(dataSet, "Claim");
- inforAdapter.SelectCommand.CommandTimeout = 1200;
- inforAdapter.Fill(dataSet, "H_Claims");
- // Tables
- DataTable winbeatClaim = dataSet.Tables["Claim"];
- DataTable claim = dataSet.Tables["H_Claims"];
- // Log
- Log("Importing...");
- // Counts
- int processedCount = 0;
- int importedCount = 0;
- int updatedCount = 0;
- int duplicateCount = 0;
- // Import
- foreach (DataRow w in winbeatClaim.Rows) {
- // Counts
- ++processedCount;
- // Claim number
- object claimNumber = ClaimNumber(w["ClaimNumber"]);
- if (claimNumber == DBNull.Value) {
- LogError("Missing claim field: 'claimnumber'");
- continue;
- }
- // Status
- bool isOpen = true;
- string status = "Open";
- if ((w["DatePaidByUnderwriter"] != DBNull.Value) || (w["DateRejected"] != DBNull.Value) || (w["DateWithdrawn"] != DBNull.Value) ||
- (w["DateReportOnly"] != DBNull.Value) || (w["DatePaidByClient"] != DBNull.Value) || (w["DatePaidByOther"] != DBNull.Value))
- {
- isOpen = false;
- status = "Closed";
- }
- // WA strata
- if (ledger == WinbeatLedger.Melbourne) {
- string accountManagerCode = (w["AccountManager_Code"] != DBNull.Value ? ((string)w["AccountManager_Code"]).ToLower() : "");
- bool isWAStrata = (accountManagerCode.Equals("wastr1") || accountManagerCode.Equals("wastr2"));
- if ((sTeam == Team.PropertyClaims) && !isWAStrata)
- continue;
- else if ((sTeam == Team.GCCClaims) && isWAStrata)
- continue;
- }
- // Duplicate check
- OleDbCommand duplicateCommand = new OleDbCommand("select top 1 H_ClaimsID from H_Claims where Claim_Reference_Num = ?", inforConnection);
- duplicateCommand.Parameters.AddWithValue("@Claim_Reference_Num", Truncate(20, claimNumber));
- object claimID = duplicateCommand.ExecuteScalar();
- // Operation
- Operation operation = (((claimID == null) || (claimID == DBNull.Value)) ? Operation.Insert : Operation.Update);
- // Clear
- claim.Rows.Clear(); // Important, otherwise there may be leftover claims from the below retrieval of existing claim(s)
- // Claim row
- DataRow c = null;
- if (operation == Operation.Insert)
- c = claim.NewRow();
- else if ((operation == Operation.Update) && !insertOnly) {
- // Existing
- OleDbDataAdapter existingAdapter = new OleDbDataAdapter("select * from H_Claims where Claim_Reference_Num = '" + claimNumber + "' and Imported = 'T'", sInforConnectionString);
- DataSet existingDataset = new DataSet();
- existingAdapter.Fill(existingDataset, "H_Claims");
- claim = existingDataset.Tables["H_Claims"];
- // Row
- DataRow[] claims = claim.Select("Claim_Reference_Num = '" + claimNumber + "'");
- if (claims.Length > 0) {
- if (claims.Length > 1) {
- LogWarning("Claim found more than once: '" + claimNumber + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.MULTIPLE_CLAIMS_FOUND, (string)claimNumber);
- }
- c = claims[0];
- }
- }
- // Claim no longer found
- if (c == null) {
- if (!insertOnly) {
- LogError("Claim not in data set: '" + claimNumber + "'");
- IssueTracker.AddError(IssueTracker.Issue.CLAIM_NOT_IN_DATA_SET, (string)claimNumber);
- }
- continue;
- }
- // Claim
- if ((operation == Operation.Insert) || !insertOnly) {
- // SLX
- claimID = ((operation == Operation.Insert) ? Infor.IDFor("H_Claims", inforConnection) : c["H_ClaimsID"]);
- c["H_ClaimsID"] = claimID;
- c["CreateUser"] = "ADMIN";
- if (operation == Operation.Insert)
- c["CreateDate"] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
- c["ModifyUser"] = "ADMIN";
- c["ModifyDate"] = ((operation == Operation.Insert) ? c["CreateDate"] : DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture));
- // Claim
- c["Imported"] = "T";
- c["Claim_Reference_Num"] = Truncate(20, claimNumber);
- c["Claim_Type"] = "Claim";
- c["Claim_Status"] = status;
- if (ledger != WinbeatLedger.Underwriting)
- c["Claim_Stage"] = Truncate(200, w["UDD_ClaimNextAction"]);
- c["Reported_Date"] = ConvertDateTime(w["DateBrokerAdvised"], claimNumber);
- if (c["Reported_Date"] == DBNull.Value)
- c["Reported_Date"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- c["Reported_Time"] = ConvertDateTime(w["DateBrokerAdvised"], claimNumber);
- c["Client_Group"] = Truncate(400, w["ClientGroup_Abbrev"]);
- c["Claim_Detail"] = Truncate(400, w["Description"]);
- // Team
- c["Claim_Team_Name"] = TeamName();
- switch (sTeam) {
- case Team.RisksmartProperty: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Risksmart Property Team'", inforConnection); break;
- case Team.PropertyClaims: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Property Claims Team'", inforConnection); break;
- case Team.GCCClaims: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'GCC Claim Team'", inforConnection); break;
- }
- c["SeccodeID"] = c["Claim_Team"];
- // Policy
- c["Policy_No_Name"] = PolicyNumber(Truncate(200, w["Policy_PolicyNumber"]));
- c["Imported_Policy_Number"] = c["Policy_No_Name"];
- c["Policy_No"] = DBNull.Value;
- if (c["Policy_No_Name"] != DBNull.Value) {
- c["Policy_No"] = Infor.GetField("H_PolicyID", "H_Policy", "Policy_Number = '" + ((string)c["Policy_No_Name"]).Replace("'", "''") + "'", inforConnection) ?? DBNull.Value;
- if (c["Policy_No"] == DBNull.Value) {
- LogWarning("Policy not found (" + claimNumber + "): '" + c["Policy_No_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.POLICY_NOT_FOUND, (string)claimNumber, c["Policy_No_Name"].ToString());
- AddMissingPolicy((string)c["Policy_No_Name"], isOpen);
- }
- }
- //c["Policy_Section"] = Truncate(400, w["PolicyClass_Description"]);
- // Account
- c["Account_Name"] = w["Client_Name"];
- object accountCode = CustomerCode(w["Client_Code"]);
- c["Imported_Account_Code"] = Truncate(32, accountCode);
- c["Imported_Account_Name"] = c["Account_Name"];
- if (accountCode != DBNull.Value) {
- object accountCodeArg = ((string)accountCode).Replace("'", "''");
- c["AccountID"] = Infor.GetField("AccountID", "Account", "Type = 'Customer' and (Client_Code = '" + accountCodeArg +
- "' or ExternalAccountNo = '" + accountCodeArg + "')", inforConnection) ?? DBNull.Value;
- if (c["AccountID"] != DBNull.Value)
- c["Account_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["AccountID"] + "'", inforConnection);
- else {
- LogWarning("Account not found (" + claimNumber + "): '" + w["Client_Code"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.CUSTOMER_NOT_FOUND, (string)claimNumber, w["Client_Code"].ToString());
- AddMissingCustomer((string)w["Client_Code"], isOpen);
- }
- }
- c["Account_Period_From"] = w["Policy_InceptionDate"];
- c["Account_Period_To"] = w["Policy_ExpiryDate"];
- // Insurance
- c["Insurer_Name"] = w["Underwriter_Name"];
- object insurerCode = UnderwriterCode(w["Underwriter_Code"]);
- c["Imported_Insurer_Code"] = Truncate(32, insurerCode);
- c["Imported_Insurer_Name"] = c["Insurer_Name"];
- if (insurerCode != DBNull.Value) {
- object insurerCodeArg = ((string)insurerCode).Replace("'", "''");
- c["Insurer"] = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and (Client_Code = '" + insurerCodeArg +
- "' or ExternalAccountNo = '" + insurerCodeArg + "')", inforConnection) ?? DBNull.Value;
- if (c["Insurer"] != DBNull.Value)
- c["Insurer_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Insurer"] + "'", inforConnection);
- else {
- LogWarning("Insurer not found (" + claimNumber + "): '" + w["Underwriter_Code"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.UNDERWRITER_NOT_FOUND, (string)claimNumber, w["Underwriter_Code"].ToString());
- AddMissingUnderwriter((string)w["Underwriter_Code"], isOpen);
- }
- }
- c["Insured_Name"] = c["Account_Name"]; // Is this really correct?
- c["Insurer_Ref"] = Truncate(200, w["UnderwriterClaimNumber"]);
- // Broker
- c["Broker_Company_Name"] = w["PolicySubInter_Name"];
- object brokerCode = AssociateCode(w["PolicySubInter_Code"]);
- c["Imported_Broker_Code"] = Truncate(32, brokerCode);
- c["Imported_Broker_Name"] = c["Broker_Company_Name"];
- if (brokerCode != DBNull.Value) {
- object brokerCodeArg = ((string)brokerCode).Replace("'", "''");
- c["Broker_Company"] = Infor.GetField("AccountID", "Account", "Type = 'Associate' and (Client_Code = '" + brokerCodeArg +
- "' or ExternalAccountNo = '" + brokerCodeArg + "')", inforConnection) ?? DBNull.Value;
- if (c["Broker_Company"] != DBNull.Value)
- c["Broker_Company_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Broker_Company"] + "'", inforConnection);
- else {
- LogWarning("Broker company not found (" + claimNumber + "): '" + w["PolicySubInter_Code"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSOCIATE_NOT_FOUND, (string)claimNumber, w["PolicySubInter_Code"].ToString());
- AddMissingAssociate((string)c["Broker_Company_Name"], isOpen);
- }
- }
- // Assigned user
- c["Assigned_User"] = DBNull.Value;
- string username = null;
- if (ledger == WinbeatLedger.RealEstate)
- username = w["UDD_ClaimsHandler"] != DBNull.Value ? (string)UserName(w["UDD_ClaimsHandler"]) : null;
- else if (ledger == WinbeatLedger.Melbourne)
- username = w["UDD_ClaimOfficer"] != DBNull.Value ? (string)UserName(w["UDD_ClaimOfficer"]) : null;
- if (username != null) {
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = '" + username + "'", inforConnection) ?? DBNull.Value;
- if (c["Assigned_User"] == DBNull.Value) {
- // Log
- LogWarning("Assigned user not found: '" + username + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSIGNED_USER_NOT_FOUND, (string)claimNumber, username);
- AddMissingUser(username, isOpen);
- // Fallback user
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = 'Ms Megan Peacock'", inforConnection) ?? DBNull.Value;
- }
- }
- // Claimant
- if (ledger != WinbeatLedger.Underwriting) {
- c["Claimant_First_Name"] = Truncate(200, ConvertFirstName(w["UDD_ClaimantName"]));
- c["Claimant_Last_Name"] = Truncate(200, ConvertLastName(w["UDD_ClaimantName"]));
- }
- // Incident
- c["Incident_Date"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- c["Incident_Time"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- c["Incident_Summary"] = w["Description"];
- //if (ledger == WinbeatLedger.RealEstate)
- // c["Incident_Type"] = Truncate(200, w["UDD_ProximateCause"]);
- //else if (ledger == WinbeatLedger.Melbourne)
- // c["Incident_Type"] = Truncate(200, w["UDD_ClaimDetail"]);
- c["Incident_Type"] = Truncate(200, w["PolicyClass_Description"]);
- if (ledger != WinbeatLedger.Underwriting)
- c["Incident_Category"] = Truncate(400, w["UDD_ProximateCause"]);
- // Property
- c["Property_Claim_Ref"] = Truncate(200, claimNumber);
- if (c["Policy_No"] != DBNull.Value) {
- string policyNumber = ((string)c["Policy_No"]).Replace("'", "''");
- object streetNumber = Infor.GetField("Situation_Street_Number", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection) ?? DBNull.Value;
- object street = Infor.GetField("Situation_Street", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection) ?? DBNull.Value;
- if ((streetNumber != DBNull.Value) || (street != DBNull.Value))
- c["Property_Address_1"] = Truncate(200, (streetNumber != DBNull.Value ? (string)streetNumber + " " : "") + (street != DBNull.Value ? (string)street : ""));
- c["Property_Suburb"] = Truncate(200, Infor.GetField("Situation_Suburb", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection));
- c["Property_State"] = Truncate(32, Infor.GetField("Situation_State", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection));
- c["Property_Postalcode"] = Truncate(32, Infor.GetField("Situation_Postcode", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection));
- }
- c["Account_Manager_Property"] = Truncate(200, w["AccountManager_Code"]);
- // Misc
- c["ABN_Num"] = Truncate(200, w["Client_ABN"]);
- c["Cat_Code"] = Truncate(200, w["UDD_CatCode"]);
- c["Date_Of_Loss"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- if (ledger != WinbeatLedger.Underwriting) {
- c["Causation"] = Truncate(400, w["UDD_ProximateCause"]);
- //c["Complexity"] = Truncate(200, w["UDD_ClaimDetail"]);
- c["Complexity"] = Truncate(200, w["UDD_ClaimCategory"]);
- }
- if (ledger == WinbeatLedger.RealEstate)
- c["Are_You_GST_Registered"] = ConvertGST(w["UDD_GSTStatus"]); // Field quality is too poor
- // Notes
- if ((w["Notes"] != DBNull.Value) || (w["RejectReason"] != DBNull.Value) || (w["PaymentNotes"] != DBNull.Value)) {
- string notes = "";
- notes += w["Notes"] != DBNull.Value ? w["Notes"] + "\n\n" : "";
- notes += w["Notes"] != DBNull.Value ? "REJECT REASON:\n" + w["RejectReason"] + "\n\n" : "";
- notes += w["Notes"] != DBNull.Value ? "PAYMENT NOTES:\n" + w["PaymentNotes"] : "";
- c["Claim_Note"] = notes;
- }
- // Reserve
- c["Liability_Res_Source"] = w["EstAmount"];
- // State
- object uddStatusObject = w["UDD_ClaimStatus"] ?? DBNull.Value;
- string uddStatus = (uddStatusObject != DBNull.Value) ? uddStatusObject.ToString().ToLower() : "";
- c["Claim_Lodged"] = (uddStatus.Contains("lodge") && !uddStatus.Contains("not")) ? "T" : "F";
- c["Claim_Not_Lodged"] = (uddStatus.Contains("lodge") && uddStatus.Contains("not")) ? "T" : "F";
- c["Claim_Acknowledged"] = uddStatus.Contains("acknowl") ? "T" : "F";
- bool paymentSettlement = ((w["PaymentNotes"] != DBNull.Value) && ((string)w["PaymentNotes"]).ToLower().Contains("settlement"));
- c["Outcome_Settlement"] = (uddStatus.Contains("settle") || paymentSettlement) ? "T" : "F";
- c["Claim_Approved"] = uddStatus.Contains("approve") ? "T" : "F";
- c["Outcome_Declined"] = ((uddStatus.Contains("decline") || uddStatus.Contains("denied")) && !uddStatus.Contains("partial")) ? "T" : "F";
- c["Expert_Appointed"] = (uddStatus.Contains("appoint") || uddStatus.Contains("assessor")) ? "T" : "F";
- c["Indemnity_Granted"] = (uddStatus.Contains("indemnity") && !uddStatus.Contains("partial")) ? "T" : "F";
- c["Partial_Indemnity_Granted"] = (uddStatus.Contains("indemnity") && uddStatus.Contains("partial")) ? "T" : "F";
- c["Review"] = (ConvertDateTime(w["DateFollowup"], claimNumber) != DBNull.Value ? "T" : "F");
- c["Review_Date"] = ConvertDateTime(w["DateFollowup"], claimNumber);
- c["Claim_Closed"] = uddStatus.Contains("closed") ? "T" : "F";
- object[] potentialClosedDates = new object[] { w["DatePaidByUnderwriter"], w["DateRejected"], w["DateWithdrawn"],
- w["DateReportOnly"], w["DatePaidByClient"], w["DatePaidByOther"]};
- foreach (object d in potentialClosedDates) {
- object closedDate = ConvertDateTime(d, claimNumber);
- if (closedDate != DBNull.Value) {
- c["Claim_Closed"] = "T";
- c["Claim_Closed_Date"] = closedDate;
- }
- }
- // Outcome
- c["Outcome"] = DBNull.Value;
- if ((uddStatus.Contains("decline") || uddStatus.Contains("denied")) && !uddStatus.Contains("partial"))
- c["Outcome"] = "Declined";
- else if ((uddStatus.Contains("decline") || uddStatus.Contains("denied")) && uddStatus.Contains("partial"))
- c["Outcome"] = "Partial Decline";
- else if (uddStatus.Contains("paid"))
- c["Outcome"] = "Paid";
- else if (uddStatus.Contains("withdraw"))
- c["Outcome"] = "Withdrawn";
- // Insert
- object duplicateClaimID = duplicateCommand.ExecuteScalar();
- bool notDuplicate = (duplicateClaimID == null) || (duplicateClaimID == DBNull.Value);
- if (notDuplicate || ((operation == Operation.Update) && !notDuplicate)) {
- // Claim
- if (operation == Operation.Insert)
- claim.Rows.Add(c);
- inforAdapter.Update(claim);
- claim.Rows.Clear();
- Log((operation == Operation.Update ? "Updated " : "") + "Claim (" + claimID + "): " + claimNumber);
- if (operation == Operation.Insert)
- ++importedCount;
- else
- ++updatedCount;
- // Payment
- ImportWinBEATClaims_Payment(claimID, claimNumber.ToString(), operation, w, inforConnection);
- }
- }
- else
- ++duplicateCount;
- // Dispose
- duplicateCommand.Dispose();
- }
- // Close connection
- inforConnection.Close();
- // Summary
- Log("\n--------------------------------------------------------------------------------");
- Log("RESULTS (" + TeamName() + ": Importing WinBEAT claims (" + sTime + ")):");
- Log(" " + processedCount + " processed.");
- Log(" " + importedCount + " imported.");
- Log(" " + updatedCount + " updated.");
- Log(" " + duplicateCount + " ignored (duplicates)\n");
- // Summary
- IssueTracker.LogSummary(TeamName() + ": Importing WinBEAT claims (" + sTime + ")");
- // Missing
- LogMissingSummary(TeamName() + ": Importing WinBEAT claims (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- //--------------------------------------------------------------------------------
- private static object ImportWinBEATClaims_Payment(object claimID, string claimNumber, Operation operation, DataRow r, OleDbConnection connection) {
- // Has payment
- bool hasPayment = (r["AmountPaid"] != DBNull.Value) && (Single.Parse(r["AmountPaid"].ToString()) > 0.0f);
- if (!hasPayment) {
- if (operation == Operation.Insert)
- return DBNull.Value;
- else {
- // Delete previously imported payment, if it exists and is unchanged
- OleDbCommand deleteCommand = new OleDbCommand("delete from H_Payments where H_ClaimsID = ? and Imported = 'T' and ModifyDate = Imported_Date", connection);
- deleteCommand.Parameters.AddWithValue("@ClaimID", claimID);
- deleteCommand.ExecuteNonQuery();
- deleteCommand.Dispose();
- Log("Deleted Redundant Payment: " + claimNumber);
- return DBNull.Value;
- }
- }
- // ID
- object paymentID = null;
- if (operation == Operation.Insert)
- paymentID = Infor.IDFor("H_Payments", connection);
- if (operation == Operation.Update) {
- // Existing
- OleDbCommand existingCommand = new OleDbCommand("select top 1 H_PaymentsID from H_Payments where H_ClaimsID = ? and Imported = 'T' and ModifyDate = Imported_Date", connection);
- existingCommand.Parameters.AddWithValue("@ClaimID", claimID);
- paymentID = existingCommand.ExecuteScalar();
- existingCommand.Dispose();
- // Not found
- if ((paymentID == null) || (paymentID == DBNull.Value)) {
- LogWarning("Payment changed or missing (" + claimNumber + ")");
- IssueTracker.AddWarning(IssueTracker.Issue.PAYMENT_CHANGED_OR_MISSING, (string)claimNumber);
- return DBNull.Value;
- }
- }
- // Settlement
- bool isSettlement = ((r["PaymentNotes"] != DBNull.Value) && ((string)r["PaymentNotes"]).ToLower().Contains("settlement"));
- // Date
- string date = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
- // Insert / update
- OleDbCommand command;
- if (operation == Operation.Insert) {
- command = new OleDbCommand("insert into H_Payments (H_PaymentsID, H_ClaimsID, ModifyDate, Reserve_Type, Total_Gross, Total_Net, GST_Included, GST, Payment_Status, " +
- " Payment_Type, Is_Settlement, Date_Invoice_Received, Payment_Note, Imported, Imported_Date) " +
- "values (?, ?, ?, 'Liability Reserve', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", connection);
- command.Parameters.AddWithValue("@PaymentID", paymentID);
- }
- else {
- command = new OleDbCommand("update H_Payments set H_ClaimsID = ?, ModifyDate = ?, Reserve_Type = 'Liability Reserve', Total_Gross = ?, Total_Net = ?, GST_Included = ?, GST = ?, " +
- " Payment_Status = ?, Payment_Type = ?, Is_Settlement = ?, Date_Invoice_Received = ?, Payment_Note = ?, Imported = ?, Imported_Date = ? " +
- "where H_PaymentsID = ?", connection);
- }
- command.Parameters.AddWithValue("@ClaimID", claimID);
- command.Parameters.AddWithValue("@ModifyDate", date);
- command.Parameters.AddWithValue("@TotalGross", r["AmountPaid"]);
- command.Parameters.AddWithValue("@TotalNet", r["AmountPaid"]);
- command.Parameters.AddWithValue("@GSTIncluded", "F");
- command.Parameters.AddWithValue("@GST", 0.1);
- command.Parameters.AddWithValue("@PaymentStatus", "Paid");
- command.Parameters.AddWithValue("@PaymentType", isSettlement ? (object)"Settlement" : DBNull.Value);
- command.Parameters.AddWithValue("@IsSettlement", isSettlement ? "T" : "F");
- object dateInvoiceReceived = DBNull.Value;
- if (r["DatePaidByUnderwriter"] != DBNull.Value)
- dateInvoiceReceived = r["DatePaidByUnderwriter"];
- if (r["DatePaidByClient"] != DBNull.Value)
- dateInvoiceReceived = r["DatePaidByClient"];
- if (r["DatePaidByOther"] != DBNull.Value)
- dateInvoiceReceived = r["DatePaidByOther"];
- command.Parameters.AddWithValue("@DateInvoiceReceived", dateInvoiceReceived);
- command.Parameters.AddWithValue("@PaymentNote", r["PaymentNotes"]);
- command.Parameters.AddWithValue("@Imported", "T");
- command.Parameters.AddWithValue("@ImportedDate", date);
- if (operation == Operation.Update)
- command.Parameters.AddWithValue("@PaymentID", paymentID);
- command.ExecuteNonQuery();
- command.Dispose();
- // Log
- Log((operation == Operation.Update ? "Updated " : "") + "Payment (" + paymentID + "): " + claimNumber + ", " + r["AmountPaid"]);
- return paymentID;
- }
- //--------------------------------------------------------------------------------
- private static void ImportWinBEATClaims_OLD(WinbeatLedger ledger) {
- // Log
- Log("================================================================================");
- Log(TeamName() + ": Importing WinBEAT claims (" + sTime + ")");
- Log("================================================================================");
- // Connection string
- string connectionString;
- switch (ledger) {
- case WinbeatLedger.Melbourne: connectionString = sWBMelbourneConnectionString; break;
- case WinbeatLedger.RealEstate: connectionString = sWBRealEstateConnectionString; break;
- case WinbeatLedger.Underwriting: connectionString = sWBRisksmartPropertyConnectionString; break;
- default:
- LogError("Invalid team selected");
- return;
- }
- // Connection
- OleDbConnection inforConnection = new OleDbConnection(sInforConnectionString);
- inforConnection.Open();
- // Query
- string query = "select _C.*, _U.CatCode as UDD_CatCode, _U.ClaimStatus as UDD_ClaimStatus, ";
- if (ledger != WinbeatLedger.Underwriting) {
- query += "_U.ClaimantName as UDD_ClaimantName, _U.ClaimNextAction as UDD_ClaimNextAction, _U.ProximateCause as UDD_ProximateCause, " +
- "_U.ClaimDetail as UDD_ClaimDetail, _U.ClaimCategory as UDD_ClaimCategory, ";
- }
- if (ledger == WinbeatLedger.RealEstate)
- query += "_U.GSTStatus as UDD_GSTStatus, _U.ClaimsHandler as UDD_ClaimsHandler, ";
- else if (ledger == WinbeatLedger.Melbourne)
- query += "_U.ClaimOfficer as UDD_ClaimOfficer, ";
- query += "_CC.Code as Client_Code, _CC.Name as Client_Name, _CC.ABN as Client_ABN, " +
- "_AM.Code as AccountManager_Code, " +
- "_CCG.Abbrev as ClientGroup_Abbrev, _CCG.Code as ClientGroup_Code, " +
- "_CU.Code as Underwriter_Code, _CU.Name as Underwriter_Name, " +
- "_P.PolicyNumber as Policy_PolicyNumber, _P.InceptionDate as Policy_InceptionDate, _P.ExpiryDate as Policy_ExpiryDate, " +
- "_PC.Abbrev as PolicyClass_Abbrev, _PC.Description as PolicyClass_Description, " +
- "_PU.Code as PolicyUnderwriter_Code, " +
- "_PS.Code as PolicySubInter_Code, _PS.Name as PolicySubInter_Name " +
- "from Claim _C " +
- "left join UDDataClaim _U on _C.ClaimID = _U.ClaimID " +
- "left join Client _CC on _C.ClaimClientID = _CC.ClientID " +
- "left join AccountManager _AM on _CC.AccountManagerID = _AM.AccountManagerID " +
- "left join ClientGroup _CCG on _CC.ClientGroupID = _CCG.ClientGroupID " +
- "left join Underwriter _CU on _C.ClaimUnderwriterID = _CU.UnderwriterID " +
- "left join Policy _P on _C.PolicyID = _P.PolicyID " +
- "left join Class _PC on _P.ClassID = _PC.ClassID " +
- "left join Underwriter _PU on _P.UnderwriterID = _PU.UnderwriterID " +
- "left join SubInter _PS on _P.SubInterID = _PS.SubInterID";
- // Adapter
- Log("Retrieving claim data...");
- SqlDataAdapter winbeatAdapter = new SqlDataAdapter(query, connectionString);
- OleDbDataAdapter inforAdapter = new OleDbDataAdapter("select * from H_Claims where 1=0", sInforConnectionString);
- OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(inforAdapter);
- inforAdapter.InsertCommand = commandBuilder.GetInsertCommand(true);
- inforAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
- // Dataset
- DataSet dataSet = new DataSet();
- winbeatAdapter.SelectCommand.CommandTimeout = 1200;
- winbeatAdapter.Fill(dataSet, "Claim");
- inforAdapter.SelectCommand.CommandTimeout = 1200;
- inforAdapter.Fill(dataSet, "H_Claims");
- // Tables
- DataTable winbeatClaim = dataSet.Tables["Claim"];
- DataTable claim = dataSet.Tables["H_Claims"];
- // Counts
- int processedCount = 0;
- int importedCount = 0;
- int duplicateCount = 0;
- // Import
- foreach (DataRow w in winbeatClaim.Rows) {
- // Counts
- ++processedCount;
- // Claim number
- object claimNumber = ClaimNumber(w["ClaimNumber"]);
- if (claimNumber == DBNull.Value) {
- LogError("Missing claim field: 'claimnumber'");
- continue;
- }
- // Status
- bool isOpen = true;
- string status = "Open";
- if ((w["DatePaidByUnderwriter"] != DBNull.Value) || (w["DateRejected"] != DBNull.Value) || (w["DateWithdrawn"] != DBNull.Value) ||
- (w["DateReportOnly"] != DBNull.Value) || (w["DatePaidByClient"] != DBNull.Value) || (w["DatePaidByOther"] != DBNull.Value))
- {
- isOpen = false;
- status = "Closed";
- }
- // WA strata
- if (ledger == WinbeatLedger.Melbourne) {
- string accountManagerCode = (w["AccountManager_Code"] != DBNull.Value ? ((string)w["AccountManager_Code"]).ToLower() : "");
- bool isWAStrata = (accountManagerCode.Equals("wastr1") || accountManagerCode.Equals("wastr2"));
- if ((sTeam == Team.PropertyClaims) && !isWAStrata)
- continue;
- else if ((sTeam == Team.GCCClaims) && isWAStrata)
- continue;
- }
- // Duplicate check
- OleDbCommand duplicateCommand = new OleDbCommand("select top 1 H_ClaimsID from H_Claims where Claim_Reference_Num = ?", inforConnection);
- duplicateCommand.Parameters.AddWithValue("@Claim_Reference_Num", Truncate(20, claimNumber));
- object claimID = duplicateCommand.ExecuteScalar();
- // Claim
- if ((claimID == null) || (claimID == DBNull.Value)) {
- // New row
- DataRow c = claim.NewRow();
- // SLX
- claimID = Infor.IDFor("H_Claims", inforConnection);
- c["H_ClaimsID"] = claimID;
- c["CreateUser"] = "ADMIN";
- c["CreateDate"] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
- c["ModifyUser"] = "ADMIN";
- c["ModifyDate"] = c["CreateDate"];
- // Claim
- c["Imported"] = "T";
- c["Claim_Reference_Num"] = Truncate(20, claimNumber);
- c["Claim_Type"] = "Claim";
- c["Claim_Status"] = status;
- if (ledger != WinbeatLedger.Underwriting)
- c["Claim_Stage"] = Truncate(200, w["UDD_ClaimNextAction"]);
- c["Reported_Date"] = ConvertDateTime(w["DateBrokerAdvised"], claimNumber);
- if (c["Reported_Date"] == DBNull.Value)
- c["Reported_Date"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- c["Reported_Time"] = ConvertDateTime(w["DateBrokerAdvised"], claimNumber);
- c["Client_Group"] = Truncate(400, w["ClientGroup_Abbrev"]);
- c["Claim_Detail"] = Truncate(400, w["Description"]);
- // Team
- c["Claim_Team_Name"] = TeamName();
- switch (sTeam) {
- case Team.RisksmartProperty: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Risksmart Property Team'", inforConnection); break;
- case Team.PropertyClaims: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'Property Claims Team'", inforConnection); break;
- case Team.GCCClaims: c["Claim_Team"] = Infor.GetField("SeccodeID", "Seccode", "SeccodeTYpe = 'G' and SeccodeDesc = 'GCC Claim Team'", inforConnection); break;
- }
- c["SeccodeID"] = c["Claim_Team"];
- // Policy
- c["Policy_No_Name"] = PolicyNumber(Truncate(200, w["Policy_PolicyNumber"]));
- c["Imported_Policy_Number"] = c["Policy_No_Name"];
- c["Policy_No"] = DBNull.Value;
- if (c["Policy_No_Name"] != DBNull.Value) {
- c["Policy_No"] = Infor.GetField("H_PolicyID", "H_Policy", "Policy_Number = '" + ((string)c["Policy_No_Name"]).Replace("'", "''") + "'", inforConnection) ?? DBNull.Value;
- if (c["Policy_No"] == DBNull.Value) {
- LogWarning("Policy not found (" + claimNumber + "): '" + c["Policy_No_Name"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.POLICY_NOT_FOUND, (string)claimNumber, c["Policy_No_Name"].ToString());
- AddMissingPolicy((string)c["Policy_No_Name"], isOpen);
- }
- }
- //c["Policy_Section"] = Truncate(400, w["PolicyClass_Description"]);
- // Account
- c["Account_Name"] = w["Client_Name"];
- object accountCode = CustomerCode(w["Client_Code"]);
- c["Imported_Account_Code"] = Truncate(32, accountCode);
- c["Imported_Account_Name"] = c["Account_Name"];
- if (accountCode != DBNull.Value) {
- object accountCodeArg = ((string)accountCode).Replace("'", "''");
- c["AccountID"] = Infor.GetField("AccountID", "Account", "Type = 'Customer' and (Client_Code = '" + accountCodeArg +
- "' or ExternalAccountNo = '" + accountCodeArg + "')", inforConnection) ?? DBNull.Value;
- if (c["AccountID"] != DBNull.Value)
- c["Account_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["AccountID"] + "'", inforConnection);
- else {
- LogWarning("Account not found (" + claimNumber + "): '" + w["Client_Code"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.CUSTOMER_NOT_FOUND, (string)claimNumber, w["Client_Code"].ToString());
- AddMissingCustomer((string)w["Client_Code"], isOpen);
- }
- }
- c["Account_Period_From"] = w["Policy_InceptionDate"];
- c["Account_Period_To"] = w["Policy_ExpiryDate"];
- // Insurance
- c["Insurer_Name"] = w["Underwriter_Name"];
- object insurerCode = UnderwriterCode(w["Underwriter_Code"]);
- c["Imported_Insurer_Code"] = Truncate(32, insurerCode);
- c["Imported_Insurer_Name"] = c["Insurer_Name"];
- if (insurerCode != DBNull.Value) {
- object insurerCodeArg = ((string)insurerCode).Replace("'", "''");
- c["Insurer"] = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and (Client_Code = '" + insurerCodeArg +
- "' or ExternalAccountNo = '" + insurerCodeArg + "')", inforConnection) ?? DBNull.Value;
- if (c["Insurer"] != DBNull.Value)
- c["Insurer_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Insurer"] + "'", inforConnection);
- else {
- LogWarning("Insurer not found (" + claimNumber + "): '" + w["Underwriter_Code"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.UNDERWRITER_NOT_FOUND, (string)claimNumber, w["Underwriter_Code"].ToString());
- AddMissingUnderwriter((string)w["Underwriter_Code"], isOpen);
- }
- }
- c["Insured_Name"] = c["Account_Name"]; // Is this really correct?
- c["Insurer_Ref"] = Truncate(200, w["UnderwriterClaimNumber"]);
- // Broker
- c["Broker_Company_Name"] = w["PolicySubInter_Name"];
- object brokerCode = AssociateCode(w["PolicySubInter_Code"]);
- c["Imported_Broker_Code"] = Truncate(32, brokerCode);
- c["Imported_Broker_Name"] = c["Broker_Company_Name"];
- if (brokerCode != DBNull.Value) {
- object brokerCodeArg = ((string)brokerCode).Replace("'", "''");
- c["Broker_Company"] = Infor.GetField("AccountID", "Account", "Type = 'Associate' and (Client_Code = '" + brokerCodeArg +
- "' or ExternalAccountNo = '" + brokerCodeArg + "')", inforConnection) ?? DBNull.Value;
- if (c["Broker_Company"] != DBNull.Value)
- c["Broker_Company_Name"] = Infor.GetField("Account", "Account", "AccountID = '" + c["Broker_Company"] + "'", inforConnection);
- else {
- LogWarning("Broker company not found (" + claimNumber + "): '" + w["PolicySubInter_Code"] + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSOCIATE_NOT_FOUND, (string)claimNumber, w["PolicySubInter_Code"].ToString());
- AddMissingAssociate((string)c["Broker_Company_Name"], isOpen);
- }
- }
- // Assigned user
- c["Assigned_User"] = DBNull.Value;
- string username = null;
- if (ledger == WinbeatLedger.RealEstate)
- username = w["UDD_ClaimsHandler"] != DBNull.Value ? (string)UserName(w["UDD_ClaimsHandler"]) : null;
- else if (ledger == WinbeatLedger.Melbourne)
- username = w["UDD_ClaimOfficer"] != DBNull.Value ? (string)UserName(w["UDD_ClaimOfficer"]) : null;
- if (username != null) {
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = '" + username + "'", inforConnection) ?? DBNull.Value;
- if (c["Assigned_User"] == DBNull.Value) {
- // Log
- LogWarning("Assigned user not found: '" + username + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSIGNED_USER_NOT_FOUND, (string)claimNumber, username);
- AddMissingUser(username, isOpen);
- // Fallback user
- c["Assigned_User"] = Infor.GetField("UserID", "UserInfo", "Username = 'Ms Megan Peacock'", inforConnection) ?? DBNull.Value;
- }
- }
- // Claimant
- if (ledger != WinbeatLedger.Underwriting) {
- c["Claimant_First_Name"] = Truncate(200, ConvertFirstName(w["UDD_ClaimantName"]));
- c["Claimant_Last_Name"] = Truncate(200, ConvertLastName(w["UDD_ClaimantName"]));
- }
- // Incident
- c["Incident_Date"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- c["Incident_Time"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- c["Incident_Summary"] = w["Description"];
- //if (ledger == WinbeatLedger.RealEstate)
- // c["Incident_Type"] = Truncate(200, w["UDD_ProximateCause"]);
- //else if (ledger == WinbeatLedger.Melbourne)
- // c["Incident_Type"] = Truncate(200, w["UDD_ClaimDetail"]);
- c["Incident_Type"] = Truncate(200, w["PolicyClass_Description"]);
- if (ledger != WinbeatLedger.Underwriting)
- c["Incident_Category"] = Truncate(400, w["UDD_ProximateCause"]);
- // Property
- c["Property_Claim_Ref"] = Truncate(200, claimNumber);
- if (c["Policy_No"] != DBNull.Value) {
- string policyNumber = ((string)c["Policy_No"]).Replace("'", "''");
- object streetNumber = Infor.GetField("Situation_Street_Number", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection) ?? DBNull.Value;
- object street = Infor.GetField("Situation_Street", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection) ?? DBNull.Value;
- if ((streetNumber != DBNull.Value) || (street != DBNull.Value))
- c["Property_Address_1"] = Truncate(200, (streetNumber != DBNull.Value ? (string)streetNumber + " " : "") + (street != DBNull.Value ? (string)street : ""));
- c["Property_Suburb"] = Truncate(200, Infor.GetField("Situation_Suburb", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection));
- c["Property_State"] = Truncate(32, Infor.GetField("Situation_State", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection));
- c["Property_Postalcode"] = Truncate(32, Infor.GetField("Situation_Postcode", "H_Policy", "Policy_Number = '" + policyNumber + "'", inforConnection));
- }
- c["Account_Manager_Property"] = Truncate(200, w["AccountManager_Code"]);
- // Misc
- c["ABN_Num"] = Truncate(200, w["Client_ABN"]);
- c["Cat_Code"] = Truncate(200, w["UDD_CatCode"]);
- c["Date_Of_Loss"] = ConvertDateTime(w["DateOfLoss"], claimNumber);
- if (ledger != WinbeatLedger.Underwriting) {
- c["Causation"] = Truncate(400, w["UDD_ProximateCause"]);
- //c["Complexity"] = Truncate(200, w["UDD_ClaimDetail"]);
- c["Complexity"] = Truncate(200, w["UDD_ClaimCategory"]);
- }
- if (ledger == WinbeatLedger.RealEstate)
- c["Are_You_GST_Registered"] = ConvertGST(w["UDD_GSTStatus"]); // Field quality is too poor
- // Notes
- if ((w["Notes"] != DBNull.Value) || (w["RejectReason"] != DBNull.Value) || (w["PaymentNotes"] != DBNull.Value)) {
- string notes = "";
- notes += w["Notes"] != DBNull.Value ? w["Notes"] + "\n\n" : "";
- notes += w["Notes"] != DBNull.Value ? "REJECT REASON:\n" + w["RejectReason"] + "\n\n" : "";
- notes += w["Notes"] != DBNull.Value ? "PAYMENT NOTES:\n" + w["PaymentNotes"] : "";
- c["Claim_Note"] = notes;
- }
- // Reserve
- c["Liability_Res_Source"] = w["EstAmount"];
- // State
- object uddStatusObject = w["UDD_ClaimStatus"] ?? DBNull.Value;
- string uddStatus = (uddStatusObject != DBNull.Value) ? uddStatusObject.ToString().ToLower() : "";
- c["Claim_Lodged"] = (uddStatus.Contains("lodge") && !uddStatus.Contains("not")) ? "T" : "F";
- c["Claim_Not_Lodged"] = (uddStatus.Contains("lodge") && uddStatus.Contains("not")) ? "T" : "F";
- c["Claim_Acknowledged"] = uddStatus.Contains("acknowl") ? "T" : "F";
- bool paymentSettlement = ((w["PaymentNotes"] != DBNull.Value) && ((string)w["PaymentNotes"]).ToLower().Contains("settlement"));
- c["Outcome_Settlement"] = (uddStatus.Contains("settle") || paymentSettlement) ? "T" : "F";
- c["Claim_Approved"] = uddStatus.Contains("approve") ? "T" : "F";
- c["Outcome_Declined"] = ((uddStatus.Contains("decline") || uddStatus.Contains("denied")) && !uddStatus.Contains("partial")) ? "T" : "F";
- c["Expert_Appointed"] = (uddStatus.Contains("appoint") || uddStatus.Contains("assessor")) ? "T" : "F";
- c["Indemnity_Granted"] = (uddStatus.Contains("indemnity") && !uddStatus.Contains("partial")) ? "T" : "F";
- c["Partial_Indemnity_Granted"] = (uddStatus.Contains("indemnity") && uddStatus.Contains("partial")) ? "T" : "F";
- c["Review"] = (ConvertDateTime(w["DateFollowup"], claimNumber) != DBNull.Value ? "T" : "F");
- c["Review_Date"] = ConvertDateTime(w["DateFollowup"], claimNumber);
- c["Claim_Closed"] = uddStatus.Contains("closed") ? "T" : "F";
- object[] potentialClosedDates = new object[] { w["DatePaidByUnderwriter"], w["DateRejected"], w["DateWithdrawn"],
- w["DateReportOnly"], w["DatePaidByClient"], w["DatePaidByOther"]};
- foreach (object d in potentialClosedDates) {
- object closedDate = ConvertDateTime(d, claimNumber);
- if (closedDate != DBNull.Value) {
- c["Claim_Closed"] = "T";
- c["Claim_Closed_Date"] = closedDate;
- }
- }
- // Outcome
- c["Outcome"] = DBNull.Value;
- if ((uddStatus.Contains("decline") || uddStatus.Contains("denied")) && !uddStatus.Contains("partial"))
- c["Outcome"] = "Declined";
- else if ((uddStatus.Contains("decline") || uddStatus.Contains("denied")) && uddStatus.Contains("partial"))
- c["Outcome"] = "Partial Decline";
- else if (uddStatus.Contains("paid"))
- c["Outcome"] = "Paid";
- else if (uddStatus.Contains("withdraw"))
- c["Outcome"] = "Withdrawn";
- // Insert
- object duplicateClaimID = duplicateCommand.ExecuteScalar();
- if ((duplicateClaimID == null) || (duplicateClaimID == DBNull.Value)) {
- // Claim
- claim.Rows.Add(c);
- inforAdapter.Update(claim);
- claim.Rows.Clear();
- Log("Claim (" + claimID + "): " + claimNumber);
- ++importedCount;
- // Payment
- ImportWinBEATClaims_Payment(claimID, claimNumber.ToString(), Operation.Insert, w, inforConnection);
- }
- }
- else
- ++duplicateCount;
- // Dispose
- duplicateCommand.Dispose();
- }
- // Close connection
- inforConnection.Close();
- // Summary
- Log("\n--------------------------------------------------------------------------------");
- Log("RESULTS (" + TeamName() + ": Importing WinBEAT claims (" + sTime + ")):");
- Log(" " + processedCount + " processed.");
- Log(" " + importedCount + " imported.");
- Log(" " + duplicateCount + " ignored (duplicates)\n");
- // Summary
- IssueTracker.LogSummary(TeamName() + ": Importing WinBEAT claims (" + sTime + ")");
- // Missing
- LogMissingSummary(TeamName() + ": Importing WinBEAT claims (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- // LINKING ================================================================================
- //--------------------------------------------------------------------------------
- public static void LinkImportedClaims(Team team = Team.All, bool logOnly = false) {
- // Time
- sTime = DateTime.Now.ToString();
- // Log
- Log("================================================================================");
- Log("Linking imported claims (" + sTime + ")");
- Log("================================================================================");
- // Connection
- OleDbConnection inforConnection = new OleDbConnection(sInforConnectionString);
- inforConnection.Open();
- // Query
- string query = "select H_ClaimsID, Claim_Reference_Num, Claim_Status, Policy_No, Policy_No_Name, AccountID, Account_Name, Insurer, Insurer_Name, Broker_Company, Broker_Company_Name, " +
- "Incident_Date, Date_Of_Loss, Imported_Policy_Number, Imported_Account_Name, Imported_Account_Code, Imported_Insurer_Name, Imported_Insurer_Code, Imported_Broker_Name, " +
- "Imported_Broker_Code from H_Claims where Imported = 'T'";
- // Team
- sTeam = team;
- if (team != Team.All)
- query += " and Claim_Team_Name = '" + TeamName() + "'";
- // Adapter
- Log("Retrieving claim data...");
- OleDbDataAdapter inforAdapter = new OleDbDataAdapter(query, sInforConnectionString);
- OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(inforAdapter);
- // Dataset
- DataSet dataSet = new DataSet();
- inforAdapter.SelectCommand.CommandTimeout = 1200;
- inforAdapter.Fill(dataSet, "H_Claims");
- // Tables
- DataTable claim = dataSet.Tables["H_Claims"];
- // Counts
- int updatedPolicyCount = 0;
- int missingPolicyCount = 0;
- int updatedAccountCount = 0;
- int missingAccountCount = 0;
- int updatedInsurerCount = 0;
- int missingInsurerCount = 0;
- int updatedBrokerCount = 0;
- int missingBrokerCount = 0;
- // Import
- foreach (DataRow c in claim.Rows) {
- // Status
- bool isOpen = c["Claim_Status"].Equals("Open");
- // Policy
- object policyID = DBNull.Value;
- object policyNumber = DBNull.Value;
- if (c["Imported_Policy_Number"] != DBNull.Value) {
- //if ((c["Policy_No"] == DBNull.Value) && c["Policy_No_Name"].Equals(c["Imported_Policy_Number"])) {
- if (c["Policy_No_Name"].Equals(c["Imported_Policy_Number"])) {
- string importedPolicyNumber = (string)PolicyNumber(c["Imported_Policy_Number"]);
- // Query
- string policyWhereNumber = "Policy_Number = '" + importedPolicyNumber.Replace("'", "''") + "'";
- string policyWhereAccount = ((c["Account_Name"] != DBNull.Value) ? "Owner_AccountID in (select AccountID from Account where Account = '" + ((string)c["Account_Name"]).Replace("'", "''") + "')" : "1=1");
- string policyWhereDates = ((c["Incident_Date"] != DBNull.Value) ? "Inception_Date <= '" + ((DateTime)c["Incident_Date"]).ToString("s", CultureInfo.InvariantCulture) + "'" : "1=1");
- policyID = Infor.GetField("H_PolicyID", "H_Policy", policyWhereNumber + " and " + policyWhereAccount + " and " + policyWhereDates, inforConnection) ?? DBNull.Value;
- // Outcome
- if (policyID != DBNull.Value) {
- if ((c["Policy_No"] == DBNull.Value) || !policyID.Equals(c["Policy_No"])) {
- policyNumber = importedPolicyNumber;
- ++updatedPolicyCount;
- // Log
- if (logOnly) {
- object policyAccount = "";
- object policyInceptionDate = "";
- if (c["Policy_No"] != DBNull.Value) {
- policyAccount = Infor.GetField("_A.Account", "H_Policy _P left join Account _A on _P.Owner_AccountID = _A.AccountID", "H_PolicyID = '" + c["Policy_No"] + "'", inforConnection) ?? DBNull.Value;
- policyInceptionDate = Infor.GetField("Inception_Date", "H_Policy", "H_PolicyID = '" + c["Policy_No"] + "'", inforConnection) ?? DBNull.Value;
- }
- object newPolicyAccount = Infor.GetField("_A.Account", "H_Policy _P left join Account _A on _P.Owner_AccountID = _A.AccountID", "H_PolicyID = '" + policyID + "'", inforConnection) ?? DBNull.Value;
- object newPolicyInceptionDate = Infor.GetField("Inception_Date", "H_Policy", "H_PolicyID = '" + policyID + "'", inforConnection) ?? DBNull.Value;
- Log("Claim Policy (" + c["H_ClaimsID"] + "): " + c["Claim_Reference_Num"] + ", account:'" + c["Account_Name"] + "', " +
- "policy=[" + policyID + ", '" + policyNumber + "', '" + policyAccount + "', '" + policyInceptionDate + "'], " +
- "old_policy=[" + c["Policy_No"] + ", '" + c["Policy_No_Name"] + "', '" + newPolicyAccount + "', '" + newPolicyInceptionDate + "']");
- }
- }
- else
- policyID = DBNull.Value;
- }
- else {
- IssueTracker.AddWarning(IssueTracker.Issue.POLICY_NOT_FOUND, (string)c["Claim_Reference_Num"], (string)c["Imported_Policy_Number"]);
- AddMissingPolicy((string)c["Imported_Policy_Number"], isOpen);
- ++missingPolicyCount;
- }
- }
- }
- // Account
- object accountID = DBNull.Value;
- object accountName = DBNull.Value;
- if ((c["Imported_Account_Name"] != DBNull.Value) || (c["Imported_Account_Code"] != DBNull.Value)) {
- if ((c["AccountID"] == DBNull.Value) && c["Account_Name"].Equals(c["Imported_Account_Name"])) {
- if (c["Imported_Account_Code"] != DBNull.Value) {
- string importedAccountCode = ((string)CustomerCode(c["Imported_Account_Code"])).Replace("'", "''");
- accountID = Infor.GetField("AccountID", "Account", "Type = 'Customer' and (Client_Code = '" + importedAccountCode +
- "' or ExternalAccountNo = '" + importedAccountCode + "')", inforConnection) ?? DBNull.Value;
- if (accountID != DBNull.Value)
- accountName = Infor.GetField("Account", "Account", "AccountID = '" + accountID + "'", inforConnection) ?? DBNull.Value;
- }
- else {
- object importedAccountName = AccountName(c["Imported_Account_Name"]);
- if (importedAccountName != null)
- importedAccountName = ((string)importedAccountName).Replace("'", "''");
- accountID = Infor.GetField("AccountID", "Account", "Type = 'Customer' and (Account = '" + importedAccountName + "' or Client_Code = '" + importedAccountName +
- "' or ExternalAccountNo = '" + importedAccountName + "')", inforConnection) ?? DBNull.Value;
- if (accountID != DBNull.Value)
- accountName = importedAccountName;
- }
- // Result
- if (accountID != DBNull.Value)
- ++updatedAccountCount;
- else {
- string missing = (c["Imported_Account_Name"] != DBNull.Value ? (string)c["Imported_Account_Name"] : "");
- missing += (c["Imported_Account_Code"] != DBNull.Value ? (missing.Length != 0 ? " " : "") + "(" + (string)c["Imported_Account_Code"] + ")" : "");
- IssueTracker.AddWarning(IssueTracker.Issue.CUSTOMER_NOT_FOUND, (string)c["Claim_Reference_Num"], missing);
- AddMissingCustomer(missing, isOpen);
- ++missingAccountCount;
- }
- }
- }
- // Insurer
- object insurerID = DBNull.Value;
- object insurerName = DBNull.Value;
- if ((c["Imported_Insurer_Name"] != DBNull.Value) || (c["Imported_Insurer_Code"] != DBNull.Value)) {
- if ((c["Insurer"] == DBNull.Value) && c["Insurer_Name"].Equals(c["Imported_Insurer_Name"])) {
- if (c["Imported_Insurer_Code"] != DBNull.Value) {
- string importedInsurerCode = ((string)UnderwriterCode(c["Imported_Insurer_Code"])).Replace("'", "''");
- insurerID = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and (Client_Code = '" + importedInsurerCode +
- "' or ExternalAccountNo = '" + importedInsurerCode + "')", inforConnection) ?? DBNull.Value;
- if (insurerID != DBNull.Value)
- insurerName = Infor.GetField("Account", "Account", "AccountID = '" + insurerID + "'", inforConnection) ?? DBNull.Value;
- }
- else {
- object importedInsurerName = AccountName(c["Imported_Insurer_Name"]);
- if (importedInsurerName != null)
- importedInsurerName = ((string)importedInsurerName).Replace("'", "''");
- insurerID = Infor.GetField("AccountID", "Account", "Type = 'Underwriter' and (Account = '" + importedInsurerName + "' or Client_Code = '" + importedInsurerName +
- "' or ExternalAccountNo = '" + importedInsurerName + "')", inforConnection) ?? DBNull.Value;
- if (insurerID != DBNull.Value)
- insurerName = importedInsurerName;
- }
- // Result
- if (insurerID != DBNull.Value)
- ++updatedInsurerCount;
- else {
- string missing = (c["Imported_Insurer_Name"] != DBNull.Value ? (string)c["Imported_Insurer_Name"] : "");
- missing += (c["Imported_Insurer_Code"] != DBNull.Value ? (missing.Length != 0 ? " " : "") + "(" + (string)c["Imported_Insurer_Code"] + ")" : "");
- IssueTracker.AddWarning(IssueTracker.Issue.UNDERWRITER_NOT_FOUND, (string)c["Claim_Reference_Num"], missing);
- AddMissingUnderwriter(missing, isOpen);
- ++missingInsurerCount;
- }
- }
- }
- // Broker
- object brokerID = DBNull.Value;
- object brokerName = DBNull.Value;
- if ((c["Imported_Broker_Name"] != DBNull.Value) || (c["Imported_Broker_Code"] != DBNull.Value)) {
- if ((c["Broker_Company"] == DBNull.Value) && c["Broker_Company_Name"].Equals(c["Imported_Broker_Name"])) {
- if (c["Imported_Broker_Code"] != DBNull.Value) {
- string importedBrokerCode = ((string)AssociateCode(c["Imported_Broker_Code"])).Replace("'", "''");
- brokerID = Infor.GetField("AccountID", "Account", "Type = 'Associate' and (Client_Code = '" + importedBrokerCode +
- "' or ExternalAccountNo = '" + importedBrokerCode + "')", inforConnection) ?? DBNull.Value;
- if (brokerID != DBNull.Value)
- brokerName = Infor.GetField("Account", "Account", "AccountID = '" + brokerID + "'", inforConnection) ?? DBNull.Value;
- }
- else {
- object importedBrokerName = AccountName(c["Imported_Broker_Name"]);
- if (importedBrokerName != null)
- importedBrokerName = ((string)importedBrokerName).Replace("'", "''");
- brokerID = Infor.GetField("AccountID", "Account", "Type = 'Associate' and (Account = '" + importedBrokerName + "' or Client_Code = '" + importedBrokerName +
- "' or ExternalAccountNo = '" + importedBrokerName + "')", inforConnection) ?? DBNull.Value;
- if (brokerID != DBNull.Value)
- brokerName = importedBrokerName;
- }
- // Result
- if (brokerID != DBNull.Value)
- ++updatedBrokerCount;
- else {
- string missing = (c["Imported_Broker_Name"] != DBNull.Value ? (string)c["Imported_Broker_Name"] : "");
- missing += (c["Imported_Broker_Code"] != DBNull.Value ? (missing.Length != 0 ? " " : "") + "(" + (string)c["Imported_Broker_Code"] + ")" : "");
- IssueTracker.AddWarning(IssueTracker.Issue.ASSOCIATE_NOT_FOUND, (string)c["Claim_Reference_Num"], missing);
- AddMissingAssociate(missing, isOpen);
- ++missingBrokerCount;
- }
- }
- }
- // Change check
- if (logOnly || ((policyID == DBNull.Value) && (accountID == DBNull.Value) && (insurerID == DBNull.Value) && (brokerID == DBNull.Value)))
- continue;
- // Update query
- string updateQuery = "update H_Claims set ";
- int updateQueryLength = updateQuery.Length;
- if (policyID != DBNull.Value)
- updateQuery += ((updateQuery.Length > updateQueryLength) ? "," : "") + "Policy_No = ?, Policy_No_Name = ?";
- if (accountID != DBNull.Value)
- updateQuery += ((updateQuery.Length > updateQueryLength) ? "," : "") + "AccountID = ?, Account_Name = ?";
- if (insurerID != DBNull.Value)
- updateQuery += ((updateQuery.Length > updateQueryLength) ? "," : "") + "Insurer = ?, Insurer_Name = ?";
- if (brokerID != DBNull.Value)
- updateQuery += ((updateQuery.Length > updateQueryLength) ? "," : "") + "Broker_Company = ?, Broker_Company_Name = ?";
- updateQuery += " where H_ClaimsID = ?";
- // Update
- OleDbCommand command = new OleDbCommand(updateQuery, inforConnection);
- if (policyID != DBNull.Value) {
- command.Parameters.AddWithValue("@PolicyID", policyID);
- command.Parameters.AddWithValue("@PolicyNumber", policyNumber);
- }
- if (accountID != DBNull.Value) {
- command.Parameters.AddWithValue("@AccountID", accountID);
- command.Parameters.AddWithValue("@AccountName", accountName);
- }
- if (insurerID != DBNull.Value) {
- command.Parameters.AddWithValue("@InsurerID", insurerID);
- command.Parameters.AddWithValue("@InsurerName", insurerName);
- }
- if (brokerID != DBNull.Value) {
- command.Parameters.AddWithValue("@BrokerID", brokerID);
- command.Parameters.AddWithValue("@BrokerName", brokerName);
- }
- command.Parameters.AddWithValue("@ClaimID", c["H_ClaimsID"]);
- command.ExecuteNonQuery();
- // Log
- Log("Claim (" + c["H_ClaimsID"] + "): " + c["Claim_Reference_Num"] + (policyID != DBNull.Value ? ", policy='" + policyNumber + "'" : "") +
- (accountID != DBNull.Value ? ", account='" + accountName + "'" : "") + (insurerID != DBNull.Value ? ", insurer='" + insurerName + "'" : "") +
- (brokerID != DBNull.Value ? ", broker='" + brokerName + "'" : ""));
- }
- // Close connection
- inforConnection.Close();
- // Summary
- Log("\n--------------------------------------------------------------------------------");
- Log("RESULTS (Linking imported claims (" + sTime + ")):");
- Log(" " + updatedPolicyCount + " of " + (updatedPolicyCount + missingPolicyCount) + " missing policies updated.\n");
- Log(" " + updatedAccountCount + " of " + (updatedAccountCount + missingAccountCount) + " missing accounts updated.\n");
- Log(" " + updatedInsurerCount + " of " + (updatedInsurerCount + missingInsurerCount) + " missing insurers updated.\n");
- Log(" " + updatedBrokerCount + " of " + (updatedBrokerCount + missingBrokerCount) + " missing brokers updated.\n");
- // Summary
- IssueTracker.LogSummary("Linking imported claims (" + sTime + ")");
- // Missing
- LogMissingSummary("Linking imported claims (" + sTime + ")");
- // Whitespace
- Log("\n");
- }
- // TBA POLICY NUMBERS ================================================================================
- //--------------------------------------------------------------------------------
- public static void ImportTBAPolicyNumbers() {
- //select '(''', H_PolicyID, ''',''', OCNUM, ''',''', Invoice_Number, '''),' from sysdba.H_Policy
- //where Policy_Number like '%t/b/a%' and ((OCNum is not null and OCNum <> '') and (Invoice_Number is not null and Invoice_Number <> ''))
- //WinbeatLedger[] ledgers = new WinbeatLedger[] { WinbeatLedger.Melbourne, WinbeatLedger.RealEstate, WinbeatLedger.Underwriting };
- // Connection
- OleDbConnection connection = new OleDbConnection(sInforConnectionString);
- connection.Open();
- // Adapter
- //Log("Retrieving policy data...");
- //OleDbDataAdapter inforAdapter = new OleDbDataAdapter
- // Close
- connection.Close();
- }
- // DELEGATES ================================================================================
- //--------------------------------------------------------------------------------
- private static void MissingField(string name) {
- LogWarning("Missing field '" + name + "'");
- }
- //--------------------------------------------------------------------------------
- private static void ParseError(string name, Type type, string value) {
- LogWarning("Invalid value '" + name + "' : '" + value + "', expected " + type.ToString());
- }
- //--------------------------------------------------------------------------------
- private static void Truncated(string name, int length, int valueLength) {
- LogWarning("Truncated value '" + name + "' : " + length + " from " + valueLength);
- }
- // ACCOUNTS ================================================================================
- //--------------------------------------------------------------------------------
- private static string ConvertAccountType(string accountType) {
- if (accountType == null)
- return null;
- else if (accountType.ToLower().Equals("corporate"))
- return "Customer";
- else if (accountType.ToLower().Equals("insurer"))
- return "Underwriter";
- else
- return accountType;
- }
- // CONVERSION ================================================================================
- //--------------------------------------------------------------------------------
- private static object ConvertDDField(DataRow sourceRow, string ddField, string field, string[] preferredValues = null) {
- bool ddFieldHasValue = (sourceRow[ddField] != DBNull.Value);
- bool ddFieldHasPreferred = false;
- if ((preferredValues != null) && ddFieldHasValue)
- ddFieldHasPreferred = preferredValues.Contains(sourceRow[ddField]);
- ddFieldHasPreferred = true;
- bool fieldHasValue = (sourceRow[field] != DBNull.Value);
- bool fieldHasPreferred = false;
- if ((preferredValues != null) && fieldHasValue)
- fieldHasPreferred = preferredValues.Contains(sourceRow[field]);
- if (ddFieldHasPreferred)
- return sourceRow[ddField];
- else if (fieldHasPreferred)
- return sourceRow[field];
- else if (ddFieldHasValue)
- return sourceRow[ddField];
- else if (fieldHasValue)
- return sourceRow[field];
- else
- return DBNull.Value;
- }
- //--------------------------------------------------------------------------------
- public static object Truncate(int maxLength, object value) {
- if (value is string) {
- string sValue = (string)value;
- if (string.IsNullOrEmpty(sValue))
- return sValue;
- return (sValue.Length <= maxLength ? sValue : sValue.Substring(0, maxLength));
- }
- else
- return value;
- }
- //--------------------------------------------------------------------------------
- public static object ConvertDateTime(object value, object claimNumber) {
- if ((value == DBNull.Value) || !(value is DateTime))
- return DBNull.Value;
- DateTime dateTime = (DateTime)value;
- DateTime minimum = new DateTime(1753, 1, 1);
- DateTime maximum = new DateTime(9999, 12, 31, 23, 59, 59, 997);
- if ((dateTime >= minimum) && (dateTime <= maximum))
- return dateTime;
- else {
- LogWarning("Date out of range (" + claimNumber + "): '" + value + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.DATE_OUT_OF_RANGE, (string)claimNumber, value.ToString());
- return DBNull.Value;
- }
- }
- //--------------------------------------------------------------------------------
- public static object JoinStringFields(object field1, object field2, string joiner) {
- if ((field1 == DBNull.Value) && (field2 == DBNull.Value))
- return DBNull.Value;
- string result = "";
- if (field1 != DBNull.Value) {
- result += field1;
- if (field2 != DBNull.Value)
- result += joiner;
- }
- if (field2 != DBNull.Value)
- result += field2;
- return result;
- }
- //--------------------------------------------------------------------------------
- public static object ConvertFirstName(object name) {
- // Checks
- if (name == DBNull.Value)
- return DBNull.Value;
- // String
- string nameString = ConvertNameString(name);
- // First name
- if (nameString.Contains(",")) {
- // Last name, first name
- string[] names = nameString.Split(new char[] { ' ', '\t', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries);
- //return ((names.Length >= 2) ? names[1] : "");
- if (names.Length < 2)
- return "";
- return string.Join(" ", names, 1, Math.Max(1, names.Length - 1));
- }
- else {
- // First name, last name
- string[] names = nameString.Split(new char[] { ' ', '\t', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries);
- //return ((names.Length >= 1) ? names[0] : "");
- if (names.Length == 0)
- return "";
- return string.Join(" ", names, 0, Math.Max(1, names.Length - 1));
- }
- }
- //--------------------------------------------------------------------------------
- public static object ConvertLastName(object name) {
- // Checks
- if (name == DBNull.Value)
- return DBNull.Value;
- // String
- string nameString = ConvertNameString(name);
- // First name
- if (nameString.Contains(",")) {
- // Last name, first name
- string[] names = nameString.Split(new char[] { ' ', '\t', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries);
- return ((names.Length >= 1) ? names[0] : "");
- }
- else {
- // First name, last name
- string[] names = nameString.Split(new char[] { ' ', '\t', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries);
- //return ((names.Length >= 2) ? names[1] : "");
- return ((names.Length >= 2) ? names[names.Length - 1] : "");
- }
- }
- //--------------------------------------------------------------------------------
- private static string ConvertNameString(object name) {
- // String
- string nameString = (string)name;
- // & - drop everything after
- int andIndex = nameString.IndexOf("&");
- if (andIndex > 0)
- nameString = nameString.Substring(0, andIndex);
- // Trim
- return nameString.Trim();
- }
- //--------------------------------------------------------------------------------
- public static object ConvertWorkPhone(object phoneNumber) {
- if (phoneNumber == DBNull.Value)
- return DBNull.Value;
- string phoneString = ((string)phoneNumber).Trim();
- if (!phoneString.StartsWith("04"))
- return phoneString;
- else
- return DBNull.Value;
- }
- //--------------------------------------------------------------------------------
- public static object ConvertMobilePhone(object phoneNumber) {
- if (phoneNumber == DBNull.Value)
- return DBNull.Value;
- string phoneString = ((string)phoneNumber).Trim();
- if (phoneString.StartsWith("04"))
- return phoneString;
- else
- return DBNull.Value;
- }
- //--------------------------------------------------------------------------------
- public static string ConvertGST(object gst) {
- if ((gst == null) || (gst == DBNull.Value))
- return "No";
- string gstLower = ((string)gst).ToLower();
- if (gstLower.Contains("yes") || (gstLower.Length <= 3 && gstLower.StartsWith("y")) || gstLower.Equals("gst") || gstLower.Equals("100") ||
- gstLower.Equals("100%") || (gstLower.Contains("registered") && !gstLower.Contains("not")))
- {
- return "Yes";
- }
- else
- return "No";
- }
- //--------------------------------------------------------------------------------
- public static object RegionFromStore(string store, string claimNumber) {
- if (StringContains(store.ToLower(), new string[] { "minchinbury", "michinbury", "belmont", "blacktown", "gosford", "mt.druitt", "newcastle", "orange", "port macquarie", "richmond", "toukley" }))
- return "NSW - Minchinbury";
- else if (StringContains(store.ToLower(), new string[] { "prestons", "chatswood chase", "dee why", "hurtsville", "liverpool", "tuggeranong hyperdome", "wagga wagga" }))
- return "NSW - Prestons";
- else if (StringContains(store.ToLower(), new string[] { "brendale", "bundaberg", "caloundra", "hervey bay" }))
- return "QLD - Brendale";
- else if (StringContains(store.ToLower(), new string[] { "stapylton", "beenleigh", "coffs harbour", "mt gravatt" }))
- return "QLD - Stapylton";
- else if (StringContains(store.ToLower(), new string[] { "regency park", "modbury" }))
- return "SA - Regency Park";
- else if (StringContains(store.ToLower(), new string[] { "marion" }))
- return "SA - Marion (Formerly Oaklands Park)";
- else if (StringContains(store.ToLower(), new string[] { "dandenong", "morwell", "pakenham", "ringwood", "rosebud", "rosebud plaza" }))
- return "VIC - Dandenong";
- else if (StringContains(store.ToLower(), new string[] { "derrimut", "albury", "geelong", "horsham", "maryborough", "moonee ponds", "shepparton", "warrnambool", "wendouree", "werribee" }))
- return "VIC - Derrimut";
- else if (StringContains(store.ToLower(), new string[] { "jandakot" }))
- return "WA - Jandakot";
- else {
- LogWarning("Region could not be determined from store value ( " + claimNumber + "): '" + store + "'");
- IssueTracker.AddWarning(IssueTracker.Issue.REGION_COULD_NOT_BE_DETERMINED, (string)claimNumber, store);
- return "Non-ALDI";
- }
- }
- // CLAIM NUMBER SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialiseClaimNumberSubstitutions() {
- if (sClaimNumberSubstitutions.Count <= 0) {
- sClaimNumberSubstitutions.Add("0279-hon", "RS0565");
- }
- }
- //--------------------------------------------------------------------------------
- private static object ClaimNumber(object claimNumber) {
- if (claimNumber == DBNull.Value)
- return DBNull.Value;
- if (claimNumber == null)
- return null;
- string claimNumberString = ((string)claimNumber).ToLower();
- InitialiseClaimNumberSubstitutions();
- if (sClaimNumberSubstitutions.ContainsKey(claimNumberString))
- return sClaimNumberSubstitutions[claimNumberString];
- else
- return claimNumber;
- }
- // POLICY NUMBER SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialisePolicyNumberSubstitutions() {
- if (sPolicyNumberSubstitutions.Count <= 0) {
- // Univeral
- sPolicyNumberSubstitutions.Add("71 22228344 glr", "71 2228344 GLR");
- // Risksmart GCC
- sRGCPolicyNumberSubstitutions.Add(" b0621chon00114b25", "B0621CHON00114B25");
- sRGCPolicyNumberSubstitutions.Add("18a046139", "18A046139ISR");
- sRGCPolicyNumberSubstitutions.Add("18a046139 isr", "18A046139ISR");
- sRGCPolicyNumberSubstitutions.Add("18a046139isr", "18A046139ISR");
- sRGCPolicyNumberSubstitutions.Add("18a046140 isr", "18A046140ISR");
- sRGCPolicyNumberSubstitutions.Add("18a046140isr", "18A046140ISR");
- sRGCPolicyNumberSubstitutions.Add("71-2955095gpr", "712955095 GPR");
- sRGCPolicyNumberSubstitutions.Add("712228344 glr", "71 2228344 GLR");
- sRGCPolicyNumberSubstitutions.Add("782222182mbd", "78 2222182 MBD");
- sRGCPolicyNumberSubstitutions.Add("782222185mbd", "78 2222185 MBD");
- // Risksmart Property
- sRSPPolicyNumberSubstitutions.Add(" 93453595-20396", "93453595-20396");
- sRSPPolicyNumberSubstitutions.Add(" 93453595-45126", "93453595-45126");
- sRSPPolicyNumberSubstitutions.Add("03453595-42402", "93453595-42402");
- sRSPPolicyNumberSubstitutions.Add("42402", "93453595-11302");
- sRSPPolicyNumberSubstitutions.Add("11302", "93453595-11302");
- sRSPPolicyNumberSubstitutions.Add("11596", "93453595-11596");
- sRSPPolicyNumberSubstitutions.Add("11956", "93453595-11956");
- sRSPPolicyNumberSubstitutions.Add("13719", "93453595-13719");
- sRSPPolicyNumberSubstitutions.Add("14570", "93453595-14570");
- sRSPPolicyNumberSubstitutions.Add("14583", "93453595-14583");
- sRSPPolicyNumberSubstitutions.Add("14625", "93453595-14625");
- sRSPPolicyNumberSubstitutions.Add("14738", "93453595-14738");
- sRSPPolicyNumberSubstitutions.Add("15728", "93453595-15728");
- sRSPPolicyNumberSubstitutions.Add("16001", "93453595-16001");
- sRSPPolicyNumberSubstitutions.Add("17157", "93453595-17157");
- sRSPPolicyNumberSubstitutions.Add("18294", "93453595-18294");
- sRSPPolicyNumberSubstitutions.Add("18315", "93453595-18315");
- sRSPPolicyNumberSubstitutions.Add("19498", "93453595-19498");
- sRSPPolicyNumberSubstitutions.Add("19659", "93453595-19659");
- sRSPPolicyNumberSubstitutions.Add("20400", "93453595-20400");
- sRSPPolicyNumberSubstitutions.Add("20689", "93453595-20689");
- sRSPPolicyNumberSubstitutions.Add("20771", "93453595-20771");
- sRSPPolicyNumberSubstitutions.Add("20961", "93453595-20961");
- sRSPPolicyNumberSubstitutions.Add("22304", "93453595-22304");
- sRSPPolicyNumberSubstitutions.Add("22725", "93453595-22725");
- sRSPPolicyNumberSubstitutions.Add("23678", "93453595-23678");
- sRSPPolicyNumberSubstitutions.Add("23714", "93453595-23714");
- sRSPPolicyNumberSubstitutions.Add("23924", "93453595-23924");
- sRSPPolicyNumberSubstitutions.Add("23989", "93453595-23989");
- sRSPPolicyNumberSubstitutions.Add("24057", "93453595-24057");
- sRSPPolicyNumberSubstitutions.Add("24235", "93453595-24235");
- sRSPPolicyNumberSubstitutions.Add("24274", "93453595-24274");
- sRSPPolicyNumberSubstitutions.Add("24570", "93453595-24570");
- sRSPPolicyNumberSubstitutions.Add("24662", "93453595-24662");
- sRSPPolicyNumberSubstitutions.Add("24705", "93453595-24705");
- sRSPPolicyNumberSubstitutions.Add("24875", "93453595-24875");
- sRSPPolicyNumberSubstitutions.Add("24877", "93453595-24877");
- sRSPPolicyNumberSubstitutions.Add("25139", "93453595-25139");
- sRSPPolicyNumberSubstitutions.Add("25457", "93453595-25457");
- sRSPPolicyNumberSubstitutions.Add("30439", "93453595-30439");
- sRSPPolicyNumberSubstitutions.Add("31061", "93453595-31061");
- sRSPPolicyNumberSubstitutions.Add("31529", "93453595-31529");
- sRSPPolicyNumberSubstitutions.Add("31717", "93453595-31717");
- sRSPPolicyNumberSubstitutions.Add("32121", "93453595-32121");
- sRSPPolicyNumberSubstitutions.Add("32851", "93453595-32851");
- sRSPPolicyNumberSubstitutions.Add("33465", "93453595-33465");
- sRSPPolicyNumberSubstitutions.Add("93453595- 33465", "93453595-33465");
- sRSPPolicyNumberSubstitutions.Add("35453595-40496", "93453595-40496");
- sRSPPolicyNumberSubstitutions.Add("41791", "93453595-41791");
- sRSPPolicyNumberSubstitutions.Add("41811", "93453595-41811");
- sRSPPolicyNumberSubstitutions.Add("42290", "93453595-42290");
- sRSPPolicyNumberSubstitutions.Add("42521", "93453595-42521");
- sRSPPolicyNumberSubstitutions.Add("42567", "93453595-42567");
- sRSPPolicyNumberSubstitutions.Add("42743", "93453595-42743");
- sRSPPolicyNumberSubstitutions.Add("43098", "93453595-43098");
- sRSPPolicyNumberSubstitutions.Add("43153", "93453595-43153");
- sRSPPolicyNumberSubstitutions.Add("43259", "93453595-43259");
- sRSPPolicyNumberSubstitutions.Add("43662", "93453595-43662");
- sRSPPolicyNumberSubstitutions.Add("43738", "93453595-43738");
- sRSPPolicyNumberSubstitutions.Add("43900", "93453595-43900");
- sRSPPolicyNumberSubstitutions.Add("44207", "93453595-44207");
- sRSPPolicyNumberSubstitutions.Add("44659", "93453595-44659");
- sRSPPolicyNumberSubstitutions.Add("44699", "93453595-44699");
- sRSPPolicyNumberSubstitutions.Add("44755", "93453595-44755");
- sRSPPolicyNumberSubstitutions.Add("45110", "93453595-45110");
- sRSPPolicyNumberSubstitutions.Add("45176", "93453595-45176");
- sRSPPolicyNumberSubstitutions.Add("45688", "93453595-45688");
- sRSPPolicyNumberSubstitutions.Add("934535695-20070", "93453595-20070");
- sRSPPolicyNumberSubstitutions.Add("93453595- 00020", "93453595-000020HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595- 000127", "93453595-000127HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595- 000224", "93453595-000224HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595- 00894", "93453595-000894HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595- 000951", "93453595-000951HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595- 000979", "93453595-000979HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595- 001050", "93453595-001050HLL");
- sRSPPolicyNumberSubstitutions.Add("93453595 - 31825", "93453595-31825");
- sRSPPolicyNumberSubstitutions.Add("93453595- 10312", "93453595-10312");
- sRSPPolicyNumberSubstitutions.Add("93453595- 10344", "93453595-10344");
- sRSPPolicyNumberSubstitutions.Add("93453595- 11394", "93453595-11394");
- sRSPPolicyNumberSubstitutions.Add("93453595 11732", "93453595-11732");
- sRSPPolicyNumberSubstitutions.Add("93453595- 12005", "93453595-12005");
- sRSPPolicyNumberSubstitutions.Add("93453595- 12519", "93453595-12519");
- sRSPPolicyNumberSubstitutions.Add("93453595- 13437", "93453595-13437");
- sRSPPolicyNumberSubstitutions.Add("93453595- 13450", "93453595-13450");
- sRSPPolicyNumberSubstitutions.Add("93453595- 13580", "93453595-13580");
- sRSPPolicyNumberSubstitutions.Add("93453595- 13651", "93453595-13651");
- sRSPPolicyNumberSubstitutions.Add("93453595- 14573", "93453595-14573");
- sRSPPolicyNumberSubstitutions.Add("93453595- 15286", "93453595-15286");
- sRSPPolicyNumberSubstitutions.Add("93453595- 16292", "93453595-16292");
- sRSPPolicyNumberSubstitutions.Add("93453595- 16885", "93453595-16885");
- sRSPPolicyNumberSubstitutions.Add("93453595- 17618", "93453595-17618");
- sRSPPolicyNumberSubstitutions.Add("93453595- 18183", "93453595-18183");
- sRSPPolicyNumberSubstitutions.Add("93453595- 18296", "93453595-18296");
- sRSPPolicyNumberSubstitutions.Add("93453595- 18331", "93453595-18331");
- sRSPPolicyNumberSubstitutions.Add("93453595- 18830", "93453595-18830");
- sRSPPolicyNumberSubstitutions.Add("93453595- 19410", "93453595-19410");
- sRSPPolicyNumberSubstitutions.Add("93453595- 19703", "93453595-19703");
- sRSPPolicyNumberSubstitutions.Add("93453595- 19931", "93453595-19931");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20049", "93453595-20049");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20089", "93453595-20089");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20132", "93453595-20132");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20268", "93453595-20268");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20683", "93453595-20683");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20716", "93453595-20716");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20924", "93453595-20924");
- sRSPPolicyNumberSubstitutions.Add("93453595- 20938", "93453595-20938");
- sRSPPolicyNumberSubstitutions.Add("93453595- 21125", "93453595-21125");
- sRSPPolicyNumberSubstitutions.Add("93453595- 21537", "93453595-21537");
- sRSPPolicyNumberSubstitutions.Add("93453595- 21894", "93453595-21894");
- sRSPPolicyNumberSubstitutions.Add("93453595- 22700", "93453595-22700");
- sRSPPolicyNumberSubstitutions.Add("93453595- 23112", "93453595-23112");
- sRSPPolicyNumberSubstitutions.Add("93453595- 23383", "93453595-23383");
- sRSPPolicyNumberSubstitutions.Add("93453595- 23430", "93453595-23430");
- sRSPPolicyNumberSubstitutions.Add("93453595- 23640", "93453595-23640");
- sRSPPolicyNumberSubstitutions.Add("93453595- 23835", "93453595-23835");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24011", "93453595-24011");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24070", "93453595-24070");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24098", "93453595-24098");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24202", "93453595-24202");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24470", "93453595-24470");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24695", "93453595-24695");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24751", "93453595-24751");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24783", "93453595-24783");
- sRSPPolicyNumberSubstitutions.Add("93453595- 24804", "93453595-24804");
- sRSPPolicyNumberSubstitutions.Add("93453595- 25167", "93453595-25167");
- sRSPPolicyNumberSubstitutions.Add("93453595- 25575", "93453595-25575");
- sRSPPolicyNumberSubstitutions.Add("93453595- 25666", "93453595-25666");
- sRSPPolicyNumberSubstitutions.Add("93453595- 30411", "93453595-30411");
- sRSPPolicyNumberSubstitutions.Add("93453595 31765", "93453595-31765");
- sRSPPolicyNumberSubstitutions.Add("93453595- 32478", "93453595-32478");
- sRSPPolicyNumberSubstitutions.Add("93453595- 32590", "93453595-32590");
- sRSPPolicyNumberSubstitutions.Add("93453595- 33142", "93453595-33142");
- sRSPPolicyNumberSubstitutions.Add("93453595- 33290", "93453595-33290");
- sRSPPolicyNumberSubstitutions.Add("93453595- 40552", "93453595-40552");
- sRSPPolicyNumberSubstitutions.Add("93453595- 41632", "93453595-41632");
- sRSPPolicyNumberSubstitutions.Add("93453595- 41992", "93453595-41992");
- sRSPPolicyNumberSubstitutions.Add("93453595- 42343", "93453595-42343");
- sRSPPolicyNumberSubstitutions.Add("93453595 42385", "93453595-42385");
- sRSPPolicyNumberSubstitutions.Add("93453595- 42454", "93453595-42454");
- sRSPPolicyNumberSubstitutions.Add("93453595- 42553", "93453595-42553");
- sRSPPolicyNumberSubstitutions.Add("93453595- 42707", "93453595-42707");
- sRSPPolicyNumberSubstitutions.Add("93453595- 42807", "93453595-42807");
- sRSPPolicyNumberSubstitutions.Add("93453595- 42959", "93453595-42959");
- sRSPPolicyNumberSubstitutions.Add("93453595- 43079", "93453595-43079");
- sRSPPolicyNumberSubstitutions.Add("93453595- 43380", "93453595-43380");
- sRSPPolicyNumberSubstitutions.Add("93453595- 43568", "93453595-43568");
- sRSPPolicyNumberSubstitutions.Add("93453595- 43897", "93453595-43897");
- sRSPPolicyNumberSubstitutions.Add("93453595- 43900", "93453595-43900");
- sRSPPolicyNumberSubstitutions.Add("93453595- 43907", "93453595-43907");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44001", "93453595-44001");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44152", "93453595-44152");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44217", "93453595-44217");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44306", "93453595-44306");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44413", "93453595-44413");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44518", "93453595-44518");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44561", "93453595-44561");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44742", "93453595-44742");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44799", "93453595-44799");
- sRSPPolicyNumberSubstitutions.Add("93453595- 44828", "93453595-44828");
- sRSPPolicyNumberSubstitutions.Add("93453595- 45418", "93453595-45418");
- sRSPPolicyNumberSubstitutions.Add("93453595- 45570", "93453595-45570");
- sRSPPolicyNumberSubstitutions.Add("93453595- 45785", "93453595-45785");
- sRSPPolicyNumberSubstitutions.Add("93453595- 45812", "93453595-45812");
- sRSPPolicyNumberSubstitutions.Add("93453595- 46049", "93453595-46049");
- sRSPPolicyNumberSubstitutions.Add("9345359519906", "93453595-19906");
- sRSPPolicyNumberSubstitutions.Add("93453595-30834 (9a)", "93453595-30834");
- sRSPPolicyNumberSubstitutions.Add("93453595-30835 (9b)", "93453595-30835");
- sRSPPolicyNumberSubstitutions.Add("93453595-43952 (u 5)", "93453595-43952");
- sRSPPolicyNumberSubstitutions.Add("9345395-22956", "93453595-22956");
- sRSPPolicyNumberSubstitutions.Add("higstr-000096- lodged incorrectly", "HIGSTR-000096");
- sRSPPolicyNumberSubstitutions.Add("hu0029720\r\npolicy no:\r\nthe insured:\r\nstrata title - residential\r\nfrom 1/01/2017 to 1/01/2018\r\nhu0029720", "HU0029720");
- // Property Claims
- //sPRCPolicyNumberSubstitutions.Add();
- // GCC Claims
- //sGCCPolicyNumberSubstitutions.Add();
- }
- }
- //--------------------------------------------------------------------------------
- private static object PolicyNumber(object policyNumber) {
- if (policyNumber == DBNull.Value)
- return DBNull.Value;
- if (policyNumber == null)
- return null;
- string policyNumberString = ((string)policyNumber).ToLower();
- InitialisePolicyNumberSubstitutions();
- if (sPolicyNumberSubstitutions.ContainsKey(policyNumberString))
- return sPolicyNumberSubstitutions[policyNumberString];
- else {
- if ((sTeam == Team.RisksmartGCC) && sRGCPolicyNumberSubstitutions.ContainsKey(policyNumberString))
- return sRGCPolicyNumberSubstitutions[policyNumberString];
- else if ((sTeam == Team.RisksmartProperty) && sRSPPolicyNumberSubstitutions.ContainsKey(policyNumberString))
- return sRSPPolicyNumberSubstitutions[policyNumberString];
- else if ((sTeam == Team.PropertyClaims) && sPRCPolicyNumberSubstitutions.ContainsKey(policyNumberString))
- return sPRCPolicyNumberSubstitutions[policyNumberString];
- else if ((sTeam == Team.GCCClaims) && sGCCPolicyNumberSubstitutions.ContainsKey(policyNumberString))
- return sGCCPolicyNumberSubstitutions[policyNumberString];
- }
- // No substitute
- return policyNumber;
- }
- // ACCOUNT NAME SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialiseAccountNameSubstitutions() {
- if (sAccountNameSubstitutions.Count <= 0) {
- sAccountNameSubstitutions.Add("accident & health international", "Accidental & Health International");
- sAccountNameSubstitutions.Add("aldi - recovery settlement to aldi", "ALDI");
- sAccountNameSubstitutions.Add("allianz", "Allianz Australia Insurance Limited");
- sAccountNameSubstitutions.Add("bendigo district rsl", "Bendigo District RSL Sub-Branch Inc.");
- sAccountNameSubstitutions.Add("box hill rsl", "Box Hill RSL Sub-Branch Inc");
- sAccountNameSubstitutions.Add("catlin", "XL Catlin");
- sAccountNameSubstitutions.Add("chu", "CHU-NSW");
- sAccountNameSubstitutions.Add("chubb insurance", "Chubb Insurance Australia Ltd");
- sAccountNameSubstitutions.Add("duke of edinburgh", "The Duke Of Edinburghs International Award");
- sAccountNameSubstitutions.Add("ezko property services (aust) pty ltd", "Ezko");
- sAccountNameSubstitutions.Add("ezko property services (aust) retail pty ltd", "Ezko");
- sAccountNameSubstitutions.Add("folkestone limited", "Folkestone");
- sAccountNameSubstitutions.Add("gjk facility services", "GJ&K Cleaning Service Pty Ltd");
- sAccountNameSubstitutions.Add("guild insurance", "Guild Insurance Ltd");
- sAccountNameSubstitutions.Add("honan insurance brokers", "Honan Insurance Group Pty Ltd");
- //sAccountNameSubstitutions.Add("honan insurance group", "Honan Insurance Group Pty Ltd");
- sAccountNameSubstitutions.Add("Lloyds Honan LL", "Lloyds Honan");
- sAccountNameSubstitutions.Add("mecon winsure", "Mecon Insurance Group");
- sAccountNameSubstitutions.Add("miller insurance", "Millers");
- sAccountNameSubstitutions.Add("qbe", "QBE Insurance (Australia) Ltd - Melbourne");
- sAccountNameSubstitutions.Add("romak hardware distributors (aust) pty ltd", "Romak Hardware Distributors (Aust) Pty Ltd");
- sAccountNameSubstitutions.Add("whirlpool", "Whirlpool (Australia) Pty Ltd");
- sAccountNameSubstitutions.Add("xl insurance", "XL Insurance Company SE (Australian Branch)");
- sAccountNameSubstitutions.Add("xl", "XL Insurance Company SE (Australian Branch)");
- sAccountNameSubstitutions.Add("self insured", null);
- sAccountNameSubstitutions.Add("offshore market placement", null);
- }
- }
- //--------------------------------------------------------------------------------
- private static object AccountName(object accountName) {
- if (accountName == DBNull.Value)
- return DBNull.Value;
- if (accountName == null)
- return null;
- string accountNameString = ((string)accountName).ToLower();
- InitialiseAccountNameSubstitutions();
- if (sAccountNameSubstitutions.ContainsKey(accountNameString))
- return sAccountNameSubstitutions[accountNameString];
- else
- return accountName;
- }
- // CUSTOMER CODE SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialiseCustomerCodeSubstitutions() {
- if (sCustomerCodeSubstitutions.Count <= 0) {
- //sCodeSubstitutions.Add("lloyds", "Accidental & Health International");
- }
- }
- //--------------------------------------------------------------------------------
- private static object CustomerCode(object customerCode) {
- if (customerCode == DBNull.Value)
- return DBNull.Value;
- if (customerCode == null)
- return null;
- string customerCodeString = ((string)customerCode).ToLower();
- InitialiseCustomerCodeSubstitutions();
- if (sCustomerCodeSubstitutions.ContainsKey(customerCodeString))
- return sCustomerCodeSubstitutions[customerCodeString];
- else
- return customerCode;
- }
- // UNDERWRITER CODE SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialiseUnderwriterCodeSubstitutions() {
- if (sUnderwriterCodeSubstitutions.Count <= 0) {
- sUnderwriterCodeSubstitutions.Add("lloyds", "LLOYDS HON");
- sUnderwriterCodeSubstitutions.Add("chubb ll", "CHUBB");
- //sUnderwriterCodeSubstitutions.Add("guild ll", "guild");
- sUnderwriterCodeSubstitutions.Add("wrbk - nsw", "WRBERK");
- sUnderwriterCodeSubstitutions.Add("mob - vic", "MOB - NSW");
- sUnderwriterCodeSubstitutions.Add("vero - vic", "VERO");
- sUnderwriterCodeSubstitutions.Add("vero - nsw", "VERO");
- sUnderwriterCodeSubstitutions.Add("qbe", "QBEC");
- sUnderwriterCodeSubstitutions.Add("cgu", "CGU - VIC");
- sUnderwriterCodeSubstitutions.Add("chu", "CHU - VIC");
- }
- }
- //--------------------------------------------------------------------------------
- private static object UnderwriterCode(object underwriterCode) {
- if (underwriterCode == DBNull.Value)
- return DBNull.Value;
- if (underwriterCode == null)
- return null;
- string underwriterCodeString = ((string)underwriterCode).ToLower();
- InitialiseUnderwriterCodeSubstitutions();
- if (sUnderwriterCodeSubstitutions.ContainsKey(underwriterCodeString))
- return sUnderwriterCodeSubstitutions[underwriterCodeString];
- else
- return underwriterCodeString;
- }
- // ASSOCIATE CODE SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialiseAssociateCodeSubstitutions() {
- if (sAssociateCodeSubstitutions.Count <= 0) {
- //sAssociateCodeSubstitutions.Add("lloyds", "LLOYDS HON");
- }
- }
- //--------------------------------------------------------------------------------
- private static object AssociateCode(object associateCode) {
- if (associateCode == DBNull.Value)
- return DBNull.Value;
- if (associateCode == null)
- return null;
- string associateCodeString = ((string)associateCode).ToLower();
- InitialiseAssociateCodeSubstitutions();
- if (sAssociateCodeSubstitutions.ContainsKey(associateCodeString))
- return sAssociateCodeSubstitutions[associateCodeString];
- else
- return associateCodeString;
- }
- // USER NAME SUBSTITUTIONS ================================================================================
- //--------------------------------------------------------------------------------
- private static void InitialiseUserNameSubstitutions() {
- if (sUserNameSubstitutions.Count <= 0) {
- sUserNameSubstitutions.Add("admin", "Administrator");
- sUserNameSubstitutions.Add("aneta chlond", "Ms Aneta Chlond");
- sUserNameSubstitutions.Add("basia", "Ms Basia Harcombe");
- sUserNameSubstitutions.Add("basiah", "Ms Basia Harcombe");
- sUserNameSubstitutions.Add("basia harcombe", "Ms Basia Harcombe");
- sUserNameSubstitutions.Add("clarisa", "Ms Clarissa Morataya");
- sUserNameSubstitutions.Add("clarissa", "Ms Clarissa Morataya");
- sUserNameSubstitutions.Add("clarissam", "Ms Clarissa Morataya");
- sUserNameSubstitutions.Add("dak", "Mr Dak Wick");
- sUserNameSubstitutions.Add("dakq", "Mr Dak Wick");
- sUserNameSubstitutions.Add("dakw", "Mr Dak Wick");
- sUserNameSubstitutions.Add("dale polard", "Dale Pollard");
- sUserNameSubstitutions.Add("dalia i", "Ms Dalia Ismaiel");
- sUserNameSubstitutions.Add("dalia ismaeil", "Ms Dalia Ismaiel");
- sUserNameSubstitutions.Add("dalia ismaiel", "Ms Dalia Ismaiel");
- sUserNameSubstitutions.Add("daliai", "Ms Dalia Ismaiel");
- sUserNameSubstitutions.Add("gabby", "Ms Gabriell Wheeler");
- sUserNameSubstitutions.Add("gabriell", "Ms Gabriell Wheeler");
- sUserNameSubstitutions.Add("gabreillw", "Ms Gabriell Wheeler");
- sUserNameSubstitutions.Add("gabriellw", "Ms Gabriell Wheeler");
- sUserNameSubstitutions.Add("johnh", "Mr John Hawkins");
- sUserNameSubstitutions.Add("jordank", "Mr Jordan Kelly");
- sUserNameSubstitutions.Add("julian", "Julian Vyas");
- sUserNameSubstitutions.Add("maja", "Ms Maja Vujinovic");
- sUserNameSubstitutions.Add("majav", "Ms Maja Vujinovic");
- sUserNameSubstitutions.Add("manish", "Mr Manish Sharma");
- sUserNameSubstitutions.Add("manishs", "Mr Manish Sharma");
- sUserNameSubstitutions.Add("mary", "Ms Mary Matias");
- sUserNameSubstitutions.Add("mary matias", "Ms Mary Matias");
- sUserNameSubstitutions.Add("marynm", "Ms Mary Matias");
- sUserNameSubstitutions.Add("marym", "Ms Mary Matias");
- sUserNameSubstitutions.Add("megan eacock", "Ms Megan Peacock");
- sUserNameSubstitutions.Add("megan peacock", "Ms Megan Peacock");
- sUserNameSubstitutions.Add("megan peacok", "Ms Megan Peacock");
- sUserNameSubstitutions.Add("meganpeacock", "Ms Megan Peacock");
- sUserNameSubstitutions.Add("megn peacock", "Ms Megan Peacock");
- sUserNameSubstitutions.Add("nicole anderso", "Ms Nicole Anderson");
- sUserNameSubstitutions.Add("nicole anderson", "Ms Nicole Anderson");
- sUserNameSubstitutions.Add("perrie", "Mr Perry Xie");
- sUserNameSubstitutions.Add("perry", "Mr Perry Xie");
- sUserNameSubstitutions.Add("perry xie", "Mr Perry Xie");
- sUserNameSubstitutions.Add("poppu", "Ms Poppy Foxton");
- sUserNameSubstitutions.Add("poppy", "Ms Poppy Foxton");
- sUserNameSubstitutions.Add("poppy foxton", "Ms Poppy Foxton");
- sUserNameSubstitutions.Add("poppyf", "Ms Poppy Foxton");
- sUserNameSubstitutions.Add("shelleyt", "Shelley Thompson");
- sUserNameSubstitutions.Add("simon", "Simon Biggar");
- sUserNameSubstitutions.Add("sosina", "Ms Sosina Payne");
- sUserNameSubstitutions.Add("sosina payne", "Ms Sosina Payne");
- sUserNameSubstitutions.Add("stan", "Mr Stan Ogrizek");
- sUserNameSubstitutions.Add("stano", "Mr Stan Ogrizek");
- sUserNameSubstitutions.Add("taras", "Ms Tara Strangwick");
- sUserNameSubstitutions.Add("vaerie t", "Valerie Tuyau");
- sUserNameSubstitutions.Add("valerie t", "Valerie Tuyau");
- sUserNameSubstitutions.Add("yannick", "Mr Yannick Donnelly");
- sUserNameSubstitutions.Add("yannickd", "Mr Yannick Donnelly");
- }
- }
- //--------------------------------------------------------------------------------
- private static object UserName(object userName) {
- if (userName == DBNull.Value)
- return DBNull.Value;
- if (userName == null)
- return null;
- string userNameString = ((string)userName).ToLower();
- InitialiseUserNameSubstitutions();
- if (sUserNameSubstitutions.ContainsKey(userNameString))
- return sUserNameSubstitutions[userNameString];
- else
- return userName;
- }
- // STRINGS ================================================================================
- //--------------------------------------------------------------------------------
- public static bool StringContains(string value, string[] contains) {
- foreach (string c in contains) {
- if (value.Contains(c))
- return true;
- }
- return false;
- }
- // MISSING ================================================================================
- //--------------------------------------------------------------------------------
- private static void AddMissing(Dictionary<string, Tuple<int, int>> dictionary, string name, bool openClaim) {
- if (!dictionary.ContainsKey(name))
- dictionary.Add(name, new Tuple<int, int>(openClaim ? 1 : 0, !openClaim ? 1 : 0));
- else if (openClaim)
- dictionary[name] = new Tuple<int, int>(dictionary[name].Item1 + 1, dictionary[name].Item2);
- else
- dictionary[name] = new Tuple<int, int>(dictionary[name].Item1, dictionary[name].Item2 + 1);
- }
- //--------------------------------------------------------------------------------
- private static void AddMissingAccount(string name, bool openClaim = false) { AddMissing(sMissingAccounts, name, openClaim); }
- private static void AddMissingAssociate(string name, bool openClaim = false) { AddMissing(sMissingAssociates, name, openClaim); }
- private static void AddMissingUnderwriter(string name, bool openClaim = false) { AddMissing(sMissingUnderwriters, name, openClaim); }
- private static void AddMissingCustomer(string name, bool openClaim = false) { AddMissing(sMissingCustomers, name, openClaim); }
- private static void AddMissingPolicy(string name, bool openClaim = false) { AddMissing(sMissingPolicies, name, openClaim); }
- private static void AddMissingClaim(string name, bool openClaim = false) { AddMissing(sMissingClaims, name, openClaim); }
- private static void AddMissingUser(string name, bool openClaim = false) { AddMissing(sMissingUsers, name, openClaim); }
- //--------------------------------------------------------------------------------
- private static void LogMissingSummary(string description) {
- LogSummary("\n--------------------------------------------------------------------------------");
- LogSummary("MISSING SUMMARY (" + description + "):");
- LogMissingSummary("ACCOUNTS", sMissingAccounts);
- LogMissingSummary("ASSOCIATES (open, closed/notification)", sMissingAssociates);
- LogMissingSummary("UNDERWRITERS (open, closed/notification)", sMissingUnderwriters);
- LogMissingSummary("CUSTOMERS (open, closed/notification)", sMissingCustomers);
- LogMissingSummary("POLICIES (open, closed/notification)", sMissingPolicies);
- LogMissingSummary("CLAIMS", sMissingClaims);
- LogMissingSummary("USERS", sMissingUsers);
- }
- //--------------------------------------------------------------------------------
- private static void LogMissingSummary(string heading, Dictionary<string, Tuple<int, int>> dictionary) {
- // Checks
- if (dictionary.Count <= 0)
- return;
- // Heading
- LogSummary("\n " + heading + ":");
- // Summary
- // Open
- foreach (KeyValuePair<string, Tuple<int, int>> m in dictionary) {
- if (m.Value.Item1 > 0)
- LogSummary(" '" + m.Key + "' (" + m.Value.Item1 + ", " + m.Value.Item2 + ")");
- }
- // Closed
- foreach (KeyValuePair<string, Tuple<int, int>> m in dictionary) {
- if (m.Value.Item1 <= 0)
- LogSummary(" '" + m.Key + "' (" + m.Value.Item1 + ", " + m.Value.Item2 + ")");
- }
- // Clear
- dictionary.Clear();
- }
- // LOGGING ================================================================================
- //--------------------------------------------------------------------------------
- private static void OpenLog(string filename) {
- // Open
- try { sLogWriter = new StreamWriter(filename); }
- catch (Exception ex) { Log("Failed to open log: " + ex.Message); }
- }
- //--------------------------------------------------------------------------------
- private static void CloseLog() {
- if (sLogWriter != null) {
- sLogWriter.Close();
- sLogWriter = null;
- }
- }
- //--------------------------------------------------------------------------------
- private static void OpenSummaryLog(string filename) {
- // Open
- try { sSummaryLogWriter = new StreamWriter(filename, true); }
- catch (Exception ex) { Log("Failed to open summary log: " + ex.Message); }
- }
- //--------------------------------------------------------------------------------
- private static void CloseSummaryLog() {
- if (sSummaryLogWriter != null) {
- sSummaryLogWriter.Close();
- sSummaryLogWriter = null;
- }
- }
- //--------------------------------------------------------------------------------
- public static void Log(string message) {
- string output = (sLine > 0 ? "[" + sLine + "] " : "") + message;
- if (sLogWriter != null)
- sLogWriter.Write(output + "\n");
- Console.WriteLine(output);
- //Debug.WriteLine(output);
- }
- //--------------------------------------------------------------------------------
- public static void LogError(string message) {
- string output = (sLine > 0 ? "[" + sLine + "] " : "") + "ERROR: "+ message;
- if (sLogWriter != null)
- sLogWriter.Write(output + "\n");
- Console.WriteLine(output);
- //Debug.WriteLine(output);
- }
- //--------------------------------------------------------------------------------
- public static void LogWarning(string message) {
- string output = (sLine > 0 ? "[" + sLine + "] " : "") + "WARNING: " + message;
- if (sLogWriter != null)
- sLogWriter.Write(output + "\n");
- Console.WriteLine(output);
- //Debug.WriteLine(output);
- }
- //--------------------------------------------------------------------------------
- public static void LogSummary(string message) {
- if (sLogWriter != null)
- sLogWriter.Write(message + "\n");
- if (sSummaryLogWriter != null)
- sSummaryLogWriter.Write(message + "\n");
- Console.WriteLine(message);
- //Debug.WriteLine(message);
- }
- //================================================================================
- //********************************************************************************
- public class ImportConfig {
- public Team team;
- public string accessClaimAmendmentsCSVPath = ""; // risksmart gcc
- public string accountsContactsCSVPath = ""; // risksmart gcc
- public string policiesCSVPath = ""; // risksmart gcc
- public string timeslipsCSVPath = ""; // risksmart gcc
- public string keyContactsCSVPath = ""; // risksmart gcc
- public string paymentsCSVPath = ""; // access
- public string reservesCSVPath = ""; // access
- public bool importClaims = true; // risksmart gcc, risksmart property, property claims, gcc claims
- public bool updateWinBEATClaims = false;
- public ImportConfig(Team team = Team.None) {
- this.team = team;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement