//Policy Approval and posting to accounts public object InsuranceTransactionPosting(IEnumerable <INSURANCE_LEDGER> ledger) { var db = new SibaModel(); using (var trans = db.Database.BeginTransaction()) { try { int polSysID; var policy = db.INS_UWD_POLICY_HEAD.Find(ledger.FirstOrDefault().IGL_POL_SYS_ID); //save policy header history var historyPolicy = new INS_UWD_HPOLICY_HEAD(); historyPolicy.Map(policy); historyPolicy.POLH_TXN_STATE = "P"; db.INS_UWD_HPOLICY_HEAD.Add(historyPolicy); //insert policy fee history policy.INS_UDW_POL_FEES.ForEach(f => { var historyPolFee = new INS_UDW_HPOL_FEES(); historyPolFee.Map(f); db.INS_UDW_HPOL_FEES.Add(historyPolFee); }); //insert policy vehicle risk hsitory policy.INS_UWD_VEHICLE_RISK.ForEach(r => { //var historyRisk = new INS_UWD_HVEHICLE_RISK(); //historyRisk.Map(r); //db.INS_UWD_HVEHICLE_RISK.Add(historyRisk); //save risk cover history r.INS_UWD_RISK_COVERS.ForEach(c => { var historyCover = new INS_UWD_HRISK_COVERS(); historyCover.Map(c); db.INS_UWD_HRISK_COVERS.Add(historyCover); //save cover discount history c.INS_UDW_COVER_DISCLOAD.ForEach(d => { var hisDiscLoad = new INS_UDW_HCOVER_DISCLOAD(); hisDiscLoad.Map(d); db.INS_UDW_HCOVER_DISCLOAD.Add(hisDiscLoad); }); }); //save risk fee history r.INS_UDW_VEHICLE_FEES.ForEach(f => { var historyFee = new INS_UDW_HVEHICLE_FEES(); historyFee.Map(f); db.INS_UDW_HVEHICLE_FEES.Add(historyFee); }); //save risk discount history r.INS_UDW_RISK_DISCLOAD.ForEach(d => { var historyDiscount = new INS_UDW_HRISK_DISCLOAD(); historyDiscount.Map(d); db.INS_UDW_HRISK_DISCLOAD.Add(historyDiscount); }); //save risk excess history r.INS_UDW_RISK_EXCESS.ForEach(e => { var historyExcess = new INS_UDW_HRISK_EXCESS(); historyExcess.Map(e); db.INS_UDW_HRISK_EXCESS.Add(historyExcess); }); policy.INS_RI_FAC_INWARD.ForEach(inw => { var historyRIFacInward = new INS_HRI_FAC_INWARD(); historyRIFacInward.Map(inw); db.INS_HRI_FAC_INWARD.Add(historyRIFacInward); inw.INS_RI_FAC_INW_COMPANY.ForEach(c => { var historyInFacCompany = new INS_HRI_FAC_INW_COMPANY(); historyInFacCompany.Map(c); db.INS_HRI_FAC_INW_COMPANY.Add(historyInFacCompany); }); }); policy.INS_RI_FAC_OUTWARD.ForEach(otw => { var historyRIFacOutward = new INS_HRI_FAC_OUTWARD(); historyRIFacOutward.Map(otw); db.INS_HRI_FAC_OUTWARD.Add(historyRIFacOutward); }); policy.INS_UWD_FIRE_LOCRISK.ForEach(loc => { var historyFireRisk = new INS_UWD_HFIRE_LOCRISK(); historyFireRisk.Map(loc); db.INS_UWD_HFIRE_LOCRISK.Add(historyFireRisk); }); policy.INS_UWD_FIRE_LOCINT.ForEach(b => { var historyFireInt = new INS_UWD_HFIRE_LOCINT(); historyFireInt.Map(b); db.INS_UWD_HFIRE_LOCINT.Add(historyFireInt); b.INS_UWD_RISK_COVERS.ForEach(c => { var historyCovers = new INS_UWD_HRISK_COVERS(); historyCovers.Map(c); db.INS_UWD_HRISK_COVERS.Add(historyCovers); }); }); policy.INS_UDW_TRAVEL_RISK_HEAD.ForEach(trah => { var historyTravelHead = new INS_UDW_HTRAVEL_RISK_HEAD(); historyTravelHead.Map(trah); db.INS_UDW_HTRAVEL_RISK_HEAD.Add(historyTravelHead); }); policy.INS_UDW_TRAVEL_RISK.ForEach(t => { var historyTra = new INS_UDW_HTRAVEL_RISK(); historyTra.Map(t); db.INS_UDW_HTRAVEL_RISK.Add(historyTra); t.INS_UWD_RISK_COVERS.ForEach(c => { var historyCovers = new INS_UWD_HRISK_COVERS(); historyCovers.Map(c); db.INS_UWD_HRISK_COVERS.Add(historyCovers); }); }); }); //todo: insert other product risk history ledger.ForEach(l => { polSysID = (int)l.IGL_POL_SYS_ID; if (l.IGL_STATUS.Equals("U")) { //insurance ledger head to general ledger head mapping var glHeader = new ACCT_GL_HEAD { TH_ACCT_YEAR = (short)l.IGL_ACCT_DATE.Value.Year, TH_ANALYSIS_01 = null, TH_BATCH_ID = l.IGL_SYS_ID, TH_COMP_CODE = null, TH_CRTE_BY = "System", TH_CRTE_DATE = DateTime.Now, TH_DEPT_CODE = null, TH_DOC_CAL_MONTH = (byte)l.IGL_ACCT_DATE.Value.Month, TH_DOC_CAL_YEAR = (short)l.IGL_ACCT_DATE.Value.Year, TH_DOC_DATE = l.IGL_ACCT_DATE, TH_DOC_NO = l.IGL_DOC_NUMBER, TH_DOC_TYPE = l.IGL_TXN_DOC_TYPE, TH_MOD_BY = "", TH_MOD_DATE = null, TH_OFFICE_CODE = null, TH_STATUS = "A", TH_TXN_REF = l.IG_REF_DOC, TH_TXN_REF_DT = l.IGL_ACCT_DATE, TH_NARRATION = l.IGL_NARRATION }; db.ACCT_GL_HEAD.Add(glHeader); db.SaveChanges(); //insurance sub ledger to general ledger detail mapping l.INSURANCE_SUB_LEDGER.ForEach(s => { db.ACCT_GL_DETAIL.Add(new ACCT_GL_DETAIL { TD_AMT_BC = s.ISL_AMOUNT_BC, TD_AMT_FC = s.ISL_AMOUNT_FC, TD_ANNALYSIS_1 = s.ISL_SUB_LEDGER, TD_CRTE_BY = "System", TD_CRTE_DATE = DateTime.Now, TD_CURR_CODE = s.ISL_CURRENCY, TD_CURR_RATE = s.ISL_FX_RATE, TD_DEPT_CODE = s.ISL_OFFICE, TD_DOC_DATE = s.ISL_ACCT_DATE, TD_DOC_NO = null,//glHeader.TH_DOC_NO, TD_DOC_REF = null, TD_LINE_NARRATION = s.ISL_NARRATION, TD_DRCR_FLAG = s.ISL_DR_CR, TD_OFFICE_CODE = s.ISL_OFFICE, TD_SEQ_NO = 0, TD_TH_SYS_ID = glHeader.TH_SYS_ID, TD_STATUS = "A", TD_SUB_ACCT_LV1 = s.ISL_SUB_LEDGER, TD_SUB_ACCT_LV2 = s.ISL_SUB_LEDGER, TD_MAIN_ACCT_CODE = s.ISL_ACCT_NUMBER }); }); //insurance ledger header to open entry mapping db.ACCT_TXN_OPEN_ENTRY.Add(new ACCT_TXN_OPEN_ENTRY { OE_TXN_REF_ID = l.IGL_SYS_ID.ToString(), //OE_TXN_REF_ID = l.IGL_SYS_ID.ToString(), OE_R_BATCH_ID = null, OE_DOC_TYPE = l.IGL_TXN_DOC_TYPE, OE_DOC_NO = l.IGL_DOC_NUMBER, OE_LINE_NO = null, OE_DOC_DATE = l.IGL_ACCT_DATE, OE_DUE_DATE = l.IGL_ACCT_DATE, OE_CUST_CODE = l.IGL_CUST_CODE, OE_MAIN_ACCT_CODE = l.IGL_ACCOUNT_CODE, OE_SUB_ACCT_CODE = null, OE_DR_CR = l.IGL_DR_CR, OE_OFFICE_CODE = null, OE_CURR_CODE = l.IGL_CURRENCY, OE_CURR_RATE = l.IGL_FX_RATE, OE_ORGNL_FC_AMT = l.IGL_AMOUNT_FC, OE_ORGNL_BC_AMT = l.IGL_AMOUNT_BC, OE_ADJ_FC_AMT = null, OE_ADJ_BC_AMT = null, OE_UNPOST_ADJ_FC_AMT = null, OE_UNPOST_ADJ_BC_AMT = null, OE_ACCT_YEAR = (short)l.IGL_ACCT_DATE.Value.Year, OE_DOC_CAL_MONTH = (byte)l.IGL_ACCT_DATE.Value.Month, OE_CRTE_BY = "System", OE_CRTE_DATE = DateTime.Now, }); //update insurance ledger status to posted(P) var dbLedger = db.INSURANCE_LEDGER.Find(l.IGL_SYS_ID); db.INSURANCE_LEDGER.Attach(dbLedger); dbLedger.IGL_STATUS = "P"; //update Policy Transaction state after Approval (P) var dbPolTxn = db.INS_UWD_POLICY_HEAD.Find(l.IGL_POL_SYS_ID); db.INS_UWD_POLICY_HEAD.Attach(dbPolTxn); dbPolTxn.POLH_TXN_STATE = "P"; } }); db.SaveChanges(); trans.Commit(); //return policy status var POLH_TXN_STATE = "P"; return(new { POLH_TXN_STATE }); } catch (Exception e) { trans.Rollback(); throw; } } }
public static bool PolicyHistoryInsert(INS_UWD_POLICY_HEAD policy) { var db = new SibaModel(); using (db) { using (var trans = db.Database.BeginTransaction()) { try { //save policy header history var historyPolicy = new INS_UWD_HPOLICY_HEAD(); historyPolicy.Map(policy); db.INS_UWD_HPOLICY_HEAD.Add(historyPolicy); //save policy vehicle risk hsitory policy.INS_UWD_VEHICLE_RISK.ForEach(r => { var historyRisk = new INS_UWD_HVEHICLE_RISK(); historyRisk.Map(r); db.INS_UWD_HVEHICLE_RISK.Add(historyRisk); //save risk cover history r.INS_UWD_RISK_COVERS.ForEach(c => { var historyCover = new INS_UWD_HRISK_COVERS(); historyCover.Map(c); db.INS_UWD_HRISK_COVERS.Add(historyCover); //save cover discount history c.INS_UDW_COVER_DISCLOAD.ForEach(d => { var hisDiscLoad = new INS_UDW_HCOVER_DISCLOAD(); hisDiscLoad.Map(d); db.INS_UDW_HCOVER_DISCLOAD.Add(hisDiscLoad); }); }); //save risk fee history r.INS_UDW_VEHICLE_FEES.ForEach(f => { var historyFee = new INS_UDW_HVEHICLE_FEES(); historyFee.Map(f); db.INS_UDW_HVEHICLE_FEES.Add(historyFee); }); //save risk discount history r.INS_UDW_RISK_DISCLOAD.ForEach(d => { var historyDiscount = new INS_UDW_HRISK_DISCLOAD(); historyDiscount.Map(d); db.INS_UDW_HRISK_DISCLOAD.Add(historyDiscount); }); //save risk excess history r.INS_UDW_RISK_EXCESS.ForEach(e => { var historyExcess = new INS_UDW_HRISK_EXCESS(); historyExcess.Map(e); db.INS_UDW_HRISK_EXCESS.Add(historyExcess); }); }); //todo: save other product risk history db.SaveChanges(); trans.Commit(); return(true); } catch (Exception) { trans.Rollback(); throw; } } } }