Exemplo n.º 1
0
        static void MemberInitScanByBankCode(decimal BANK_CODE)
        {
            try
            {
                AppLib.WriteLogFileName = "NUBE_" + "MemberInitScanByBankCode";
                AppLib.WriteLogDT("START:");
                AppLib.WriteLog("MemberInitScanByBankCode");
                AppLib.WriteLog("------------------------");
                AppLib.WriteLog("");
                AppLib.WriteLog("");

                var bank = db.MASTERBANKs.FirstOrDefault(x => x.BANK_CODE == BANK_CODE);
                if (bank != null)
                {
                    AppLib.WriteLog("Bank Id: {0}, Bank Code : {1}, Bank Name : {2}", bank.BANK_CODE, bank.BANK_USERCODE, bank.BANK_NAME);
                    AppLib.DisplayClear();
                    int i = 1;
                    AppLib.WriteLog("{0,5} {1,-10} {2,-10} {3,-50} {4,-15} {5,-15} {6,-10} {7,-10} {8,-10} {9,-10} {10,-10} {11,-10} {12,-10} {13,-10} {14,-10} {15,-10} {16,-10} {17,-10} {18,-10} {19,-10} {20,-10} {21,-10} {22,-10} {23,-10} {24,-10}", "SNo", "Code", "MemberNo", "Member Name", "IC Old", "IC New", "DOB", "DOJ", "MEND", "LPAID", "SUBSAMT", "TSUBSAMT", "ACCSUBS", "SUBSDUE", "BFAMT", "TBFAMT", "ACCBF", "BFDUE", "TOTMNTS", "TOTMNTSPAD", "TOTMNTSDUE", "STATUSCDE", "RESIGNED", "STRUCKOFF", "STATUS");
                    var lstMember = db.MASTERMEMBERs.Where(x => x.BANK_CODE == BANK_CODE).OrderBy(x => x.DATEOFJOINING).Select(x => x.MEMBER_CODE).ToList();
                    foreach (var mmCode in lstMember)
                    {
                        AppLib.DisplayMsg(1, 1, string.Format("[ {0,10} - {1} ]", i, bank.MASTERMEMBERs.Count()));
                        var mm     = db.MASTERMEMBERs.FirstOrDefault(x => x.MEMBER_CODE == mmCode);
                        var Status = db.MemberMonthEndStatus.Where(x => x.MEMBER_CODE == mm.MEMBER_CODE).OrderBy(x => x.StatusMonth).FirstOrDefault();



                        string statusMsg = "";
                        if (Status == null)
                        {
                            Status    = new MemberMonthEndStatu();
                            statusMsg = "Status Record not Found";
                        }
                        else
                        {
                            decimal Subs = Status.MEMBERTYPE_CODE == 1 ? (mm.REJOINED == 0 ? 8 : 32) : (mm.REJOINED == 0 ? 4 : 16);
                            decimal BFs  = 3;

                            if (mm.DATEOFJOINING >= new DateTime(2005, 9, 1))
                            {
                                if (Status.SUBSCRIPTION_AMOUNT != Subs)
                                {
                                    statusMsg += "SUBSCRIPTION_AMOUNT MISMATCH, ";
                                }
                                if (Status.TOTALSUBCRP_AMOUNT != Subs)
                                {
                                    statusMsg += "TOTALSUBCRP_AMOUNT MISMATCH, ";
                                }
                                if (Status.ACCSUBSCRIPTION != Subs)
                                {
                                    statusMsg += "ACCSUBSCRIPTION MISMATCH, ";
                                }
                                if (Status.SUBSCRIPTIONDUE != 0)
                                {
                                    statusMsg += "SUBSCRIPTIONDUE MISMATCH, ";
                                }

                                if (Status.BF_AMOUNT != BFs)
                                {
                                    statusMsg += "BF_AMOUNT MISMATCH, ";
                                }
                                if (Status.TOTALBF_AMOUNT != BFs)
                                {
                                    statusMsg += "TOTALBF_AMOUNT MISMATCH, ";
                                }
                                if (Status.ACCBF != BFs)
                                {
                                    statusMsg += "ACCBF MISMATCH, ";
                                }
                                if (Status.BFDUE != 0)
                                {
                                    statusMsg += "BFDUE MISMATCH, ";
                                }

                                if (Status.TOTAL_MONTHS != 1)
                                {
                                    statusMsg += "TOTAL_MONTHS MISMATCH, ";
                                }
                                if (Status.TOTALMONTHSPAID != 1)
                                {
                                    statusMsg += "TOTALMONTHSPAID MISMATCH, ";
                                }
                                if (Status.TOTALMONTHSDUE != 0)
                                {
                                    statusMsg += "TOTALMONTHSDUE MISMATCH, ";
                                }

                                if (Status.STATUS_CODE != 1 && Status.STATUS_CODE != 5)
                                {
                                    statusMsg += "Status Coce Mismatch, ";
                                }

                                if (Status.STRUCKOFF == 1)
                                {
                                    statusMsg += "Struckoff Mismatch, ";
                                }

                                if (Status.RESIGNED == 1)
                                {
                                    statusMsg += "Resigned Mismatch, ";
                                }

                                if (mm.DATEOFJOINING.Value.Year != Status.LASTPAYMENTDATE.Value.Year || mm.DATEOFJOINING.Value.Month != Status.LASTPAYMENTDATE.Value.Month)
                                {
                                    statusMsg += "Last payment Date Mismatch, ";
                                }

                                if (mm.DATEOFJOINING.Value.Year != Status.StatusMonth.Value.Year || mm.DATEOFJOINING.Value.Month != Status.StatusMonth.Value.Month)
                                {
                                    statusMsg += "Status Month Date Mismatch, ";
                                }
                            }
                            else
                            {
                                if (Status.StatusMonth.Value.Year != 2005 || Status.StatusMonth.Value.Month != 09)
                                {
                                    statusMsg += "Status Month Date Mismatch, ";
                                }
                                var ts = DateTimeSpan.CompareDates(mm.DATEOFJOINING.Value, new DateTime(2005, 9, 1));
                                if ((Status.TOTALMONTHSPAID + Status.TOTALMONTHSDUE) != ((ts.Years * 12) + ts.Months) + 2)
                                {
                                    statusMsg += "Total Month Mismatch, ";
                                }

                                if (Status.ACCBF != (Status.TOTALMONTHSPAID * BFs))
                                {
                                    statusMsg += "Acc BF Mismatch, ";
                                }

                                if (Status.BFDUE != (Status.TOTALMONTHSDUE * BFs))
                                {
                                    statusMsg += "Due BF Mismatch, ";
                                }
                            }
                        }


                        if (!string.IsNullOrWhiteSpace(statusMsg))
                        {
                            //try
                            //{
                            //    MemberMonthEndErrorLog d = new MemberMonthEndErrorLog()
                            //    {
                            //        Member_Code = mm.MEMBER_CODE,
                            //        YY = mm.DATEOFJOINING.Value.Year,
                            //        MM = mm.DATEOFJOINING.Value.Month,
                            //        ErrorMsg = "Member_Init" + statusMsg
                            //    };
                            //}
                            //catch (Exception ex) { AppLib.WriteLog(ex); }
                            statusMsg = " Error=> " + statusMsg;
                        }

                        AppLib.WriteLog("{0,5} {1,-10} {2,-10} {3,-50} {4,-15} {5,-15} {6:dd/MM/yyyy} {7:dd/MM/yyyy} {8:dd/MM/yyyy} {9:dd/MM/yyyy} {10,-10} {11,-10} {12,-10} {13,-10} {14,-10} {15,-10} {16,-10} {17,-10} {18,-10} {19,-10} {20,-10} {21,-10} {22,-10} {23,-10} {24,-10}", i++, mm.MEMBER_CODE, mm.MEMBER_ID, mm.MEMBER_NAME, mm.ICNO_OLD, mm.ICNO_NEW, mm.DATEOFBIRTH, mm.DATEOFJOINING, Status.LASTPAYMENTDATE, Status.StatusMonth, Status.SUBSCRIPTION_AMOUNT, Status.TOTALSUBCRP_AMOUNT, Status.ACCSUBSCRIPTION, Status.SUBSCRIPTIONDUE, Status.BF_AMOUNT, Status.TOTALBF_AMOUNT, Status.ACCBF, Status.BFDUE, Status.TOTAL_MONTHS, Status.TOTALMONTHSPAID, Status.TOTALMONTHSPAID, Status.STATUS_CODE, Status.RESIGNED, Status.STRUCKOFF, statusMsg);
                    }
                }
                else
                {
                    AppLib.WriteLog("Bank Code {0} is not found", BANK_CODE);
                }
                AppLib.WriteLogDT("END:");
            }

            catch (Exception ex) { AppLib.WriteLog(ex); }
        }
        void MonthEndClosed()
        {
            try
            {
                var lstMemberMonthEndPrevious = db.MemberMonthEndStatus.Where(x => x.StatusMonth == dtMonthEndPrevious).ToList();
                var lstMemberMonthEnd         = db.MemberMonthEndStatus.Where(x => x.StatusMonth == dtMonthEnd).ToList();
                foreach (var mce in lstMonthEndClosed)
                {
                    var lstMember = lstMasterMember.Where(x => x.BANK_CODE == mce.BankCode).ToList();
                    foreach (var mm in lstMember)
                    {
                        var mmME_Pre = lstMemberMonthEndPrevious.FirstOrDefault(x => x.MEMBER_CODE == mm.MEMBER_CODE);
                        var mmME     = lstMemberMonthEnd.FirstOrDefault(x => x.MEMBER_CODE == mm.MEMBER_CODE);
                        var mmPaid   = lstPaidMember.FirstOrDefault(x => x.MemberCode == mm.MEMBER_CODE);


                        if (mmME_Pre == null)
                        {
                            if (mm.DATEOFJOINING?.Year == dtMonthEnd.Year && mm.DATEOFJOINING?.Month == dtMonthEnd.Month)
                            {
                                mmME_Pre = new MemberMonthEndStatu()
                                {
                                    LASTPAYMENTDATE = dtMonthEnd
                                };
                            }
                            else
                            {
                                MessageBox.Show($"Member Id[{mm.MEMBER_ID}] is not found on Previous month history.");
                                return;
                            }
                        }
                        if (mmME == null)
                        {
                            mmME             = new MemberMonthEndStatu();
                            mmME.StatusMonth = dtMonthEnd;
                            mmME.MEMBER_CODE = mm.MEMBER_CODE;

                            db.MemberMonthEndStatus.Add(mmME);
                        }

                        decimal BF   = 3;
                        decimal Ins  = 7;
                        decimal Subs = mmPaid == null ? mmME_Pre.SUBSCRIPTION_AMOUNT ?? 0 : mmPaid.Amount - (BF + Ins);

                        mmME.MEMBERTYPE_CODE  = mm.MEMBERTYPE_CODE;
                        mmME.BANK_CODE        = mm.BANK_CODE;
                        mmME.BRANCH_CODE      = mm.BRANCH_CODE;
                        mmME.NUBE_BRANCH_CODE = mm.MASTERBANKBRANCH.NUBE_BRANCH_CODE;

                        mmME.SUBSCRIPTION_AMOUNT     = Subs;
                        mmME.BF_AMOUNT               = BF;
                        mmME.INSURANCE_AMOUNT        = Ins;
                        mmME.ENTRYMODE               = "S";
                        mmME.TOTALMONTHSCONTRIBUTION = mmME_Pre.TOTALMONTHSCONTRIBUTION + 1;

                        if (mmPaid == null)
                        {
                            mmME.ACCSUBSCRIPTION = mmME_Pre.ACCSUBSCRIPTION;
                            mmME.ACCBF           = mmME_Pre.ACCBF;
                            mmME.ACCINSURANCE    = mmME_Pre.ACCINSURANCE;

                            mmME.SUBSCRIPTIONDUE = mmME_Pre.SUBSCRIPTIONDUE + Subs;
                            mmME.BFDUE           = mmME_Pre.BFDUE + BF;
                            mmME.INSURANCEDUE    = mmME_Pre.INSURANCEDUE + Ins;

                            if (dtMonthEnd.Month == 4)
                            {
                                mmME.CURRENT_YDTSUBSCRIPTION = 0;
                                mmME.CURRENT_YDTBF           = 0;
                                mmME.CURRENT_YDTINSURANCE    = 0;
                            }
                            else
                            {
                                mmME.CURRENT_YDTSUBSCRIPTION = mmME_Pre.CURRENT_YDTSUBSCRIPTION;
                                mmME.CURRENT_YDTBF           = mmME_Pre.CURRENT_YDTBF;
                                mmME.CURRENT_YDTINSURANCE    = mmME_Pre.CURRENT_YDTINSURANCE;
                            }


                            mmME.TOTALSUBCRP_AMOUNT    = 0;
                            mmME.TOTALBF_AMOUNT        = 0;
                            mmME.TOTALINSURANCE_AMOUNT = 0;

                            mmME.TOTAL_MONTHS = 0;

                            mmME.TOTALMONTHSPAID = mmME_Pre.TOTALMONTHSPAID;
                            mmME.TOTALMONTHSDUE  = mmME_Pre.TOTALMONTHSDUE + 1;

                            mmME.LASTPAYMENTDATE = mmME_Pre.LASTPAYMENTDATE;
                        }
                        else
                        {
                            mmME.ACCSUBSCRIPTION = mmME_Pre.ACCSUBSCRIPTION + Subs;
                            mmME.ACCBF           = mmME_Pre.ACCBF + BF;
                            mmME.ACCINSURANCE    = mmME_Pre.ACCINSURANCE + Ins;

                            mmME.SUBSCRIPTIONDUE = mmME_Pre.SUBSCRIPTIONDUE;
                            mmME.BFDUE           = mmME_Pre.BFDUE;
                            mmME.INSURANCEDUE    = mmME_Pre.INSURANCEDUE;

                            if (dtMonthEnd.Month == 4)
                            {
                                mmME.CURRENT_YDTSUBSCRIPTION = Subs;
                                mmME.CURRENT_YDTBF           = BF;
                                mmME.CURRENT_YDTINSURANCE    = Ins;
                            }
                            else
                            {
                                mmME.CURRENT_YDTSUBSCRIPTION = mmME_Pre.CURRENT_YDTSUBSCRIPTION + Subs;
                                mmME.CURRENT_YDTBF           = mmME_Pre.CURRENT_YDTBF + BF;
                                mmME.CURRENT_YDTINSURANCE    = mmME_Pre.CURRENT_YDTINSURANCE + Ins;
                            }



                            mmME.TOTALSUBCRP_AMOUNT    = Subs;
                            mmME.TOTALBF_AMOUNT        = BF;
                            mmME.TOTALINSURANCE_AMOUNT = Ins;

                            mmME.TOTAL_MONTHS = 1;

                            mmME.TOTALMONTHSPAID = mmME_Pre.TOTALMONTHSPAID + 1;
                            mmME.TOTALMONTHSDUE  = mmME_Pre.TOTALMONTHSDUE;


                            mmME.LASTPAYMENTDATE = dtMonthEnd;
                        }


                        var mmResign = db.RESIGNATIONs.FirstOrDefault(x => x.MEMBER_CODE == mm.MEMBER_CODE);

                        if (mmResign != null)
                        {
                            mmME.RESIGNED    = 1;
                            mmME.STATUS_CODE = (decimal)AppLib.MemberStatus.Resigned;
                        }
                        else if (mmME.LASTPAYMENTDATE.Value.MonthDiff(dtMonthEnd) >= 12)
                        {
                            mmME.STRUCKOFF   = 1;
                            mmME.STATUS_CODE = (decimal)AppLib.MemberStatus.StruckOff;
                        }
                        else if (mmME.TOTALMONTHSDUE > 3)
                        {
                            mmME.STATUS_CODE = (decimal)AppLib.MemberStatus.Defaulter;
                        }
                        else
                        {
                            mmME.STATUS_CODE = (decimal)AppLib.MemberStatus.Active;
                        }

                        mmME.USER_CODE = AppLib.iUserCode;

                        mmME.ENTRY_DATE = DateTime.Now;


                        mm.ACCSUBSCRIPTION = mmME.ACCSUBSCRIPTION;
                        mm.ACCBF           = mmME.ACCBF;
                        mm.ACCINSURANCE    = mmME.ACCINSURANCE;

                        mm.DUESUBSCRIPTION = mmME.SUBSCRIPTIONDUE;
                        mm.DUEBF           = mmME.BFDUE;
                        mm.DUEINSURANCE    = mmME.INSURANCEDUE;

                        mm.CURRENT_YTDSUBSCRIPTION = mmME.CURRENT_YDTSUBSCRIPTION;
                        mm.CURRENT_YTDBF           = mmME.CURRENT_YDTBF;
                        mm.CURRENT_YTDINSURANCE    = mmME.CURRENT_YDTINSURANCE;

                        mm.TOTALMONTHCONTRIBUTE = mmME.TOTALMONTHSCONTRIBUTION;
                        mm.TOTALMONTHSPAID      = mmME.TOTALMONTHSPAID;
                        mm.TOTALMONTHSDUE       = mmME.TOTALMONTHSDUE;

                        mm.MONTHLYSUBSCRIPTION = mmME.SUBSCRIPTION_AMOUNT;
                        mm.MONTHLYBF           = mmME.BF_AMOUNT;
                        mm.MONTHLYINSURANCE    = mmME.INSURANCE_AMOUNT;

                        mm.LASTPAYMENT_DATE = mmME.LASTPAYMENTDATE;
                        mm.STATUS_CODE      = mmME.STATUS_CODE;


                        mce.Closed += 1;
                        updateBankTotal();
                        System.Windows.Forms.Application.DoEvents();
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Month End Closed");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Month End not Closed");
            }
        }