Exemple #1
0
        public bool FundMaster_YearEnd()
        {
            try
            {
                var acYear1 = DB.ACYearMasters.Where(x => x.FundMasterId == Caller.FundMasterId && x.ACYear == Caller.AccYear).FirstOrDefault();
                if (acYear1 != null)
                {
                    var lstLedger = DB.Ledgers.Where(x => x.AccountGroup.FundMasterId == Caller.FundMasterId).OrderBy(x => x.LedgerCode).ThenBy(x => x.LedgerName).ToList();

                    int yy = DateTime.Now.Month < 4 ? DateTime.Now.Year - 1 : DateTime.Now.Year;
                    if (Caller.AccYear.Length > 4)
                    {
                        int.TryParse(Caller.AccYear.Substring(0, 4), out yy);
                    }

                    DateTime dtFrom = new DateTime(yy, 4, 1);
                    DateTime dtTo   = new DateTime(yy + 1, 3, 31);

                    DAL.ACYearMaster acYear2 = new DAL.ACYearMaster();
                    acYear2.ACYear         = string.Format("{0} - {1}", yy + 1, yy + 2);
                    acYear2.FundMasterId   = Caller.FundMasterId;
                    acYear2.ACYearStatusId = (int)Common.AppLib.ACYearStatus.Open;

                    foreach (var l in lstLedger)
                    {
                        decimal OPDr = 0, OPCr = 0, Dr = 0, Cr = 0;
                        LedgerBalance(l, dtFrom, dtTo, ref OPDr, ref OPCr, ref Dr, ref Cr);

                        if (Dr != 0 || Cr != 0)
                        {
                            acYear2.ACYearLedgerBalances.Add(new DAL.ACYearLedgerBalance()
                            {
                                LedgerId = l.Id, DrAmt = Dr, CrAmt = Cr
                            });
                        }
                    }
                    acYear1.ACYearStatusId = (int)Common.AppLib.ACYearStatus.Close;
                    DB.ACYearMasters.Add(acYear2);
                    DB.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex) { }
            return(false);
        }
Exemple #2
0
        public int FundMaster_Save(BLL.FundMaster fm)
        {
            try
            {
                DAL.FundMaster d = DB.FundMasters.Where(x => x.Id == fm.Id).FirstOrDefault();

                if (d == null)
                {
                    d = new DAL.FundMaster();
                    DB.FundMasters.Add(d);

                    fm.IsActive = true;
                    fm.toCopy <DAL.FundMaster>(d);

                    DateTime         dt   = DateTime.Now;
                    DAL.ACYearMaster acym = new DAL.ACYearMaster()
                    {
                        ACYear         = dt.Month > 3 ? string.Format("{0} - {1}", dt.Year, dt.Year + 1) : string.Format("{0} - {1}", dt.Year - 1, dt.Year),
                        ACYearStatusId = (int)AppLib.ACYearStatus.Open
                    };
                    d.ACYearMasters.Add(acym);

                    DB.SaveChanges();
                    fm.Id = d.Id;
                    if (d.Id != 0)
                    {
                        FundSetup(fm);
                        CurrencySetup(fm);
                    }
                }
                else
                {
                    fm.toCopy <DAL.FundMaster>(d);
                    DB.SaveChanges();
                }
                Clients.Clients(OtherLoginClientsOnGroup).FundMaster_Save(fm);

                return(fm.Id);
            }
            catch (Exception ex) { }
            return(0);
        }