Exemple #1
0
        public async Task <IActionResult> Receate([FromBody] LedgerModel newLedgerModel)
        {
            ServiceResponseModel <string> response = new ServiceResponseModel <string>();

            try
            {
                if (string.IsNullOrWhiteSpace(newLedgerModel.CompCode))
                {
                    throw new ArgumentNullException("CompCode is required");
                }
                if (string.IsNullOrWhiteSpace(newLedgerModel.AccYear))
                {
                    throw new ArgumentNullException("AccYear is required");
                }
                response = await _ledgerService.Receate(newLedgerModel);

                if (response.Data == null)
                {
                    return(NotFound(response));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
Exemple #2
0
        public ActionResult AddLedger(LedgerModel model)
        {
            var Data = obj.SaveLedger(model);

            TempData["Error"] = Data;
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        private void ListBoxItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (index)
            {
            case 0:
                LedgerModel model = (LedgerModel)ListBoxItems.SelectedItem;

                /*MainWindow window = new MainWindow();
                 * window.GridPrincipal.Children.Clear();
                 * window.GridPrincipal.Children.Add(new DisplayLedgers(model));*/
                callingForm.LedgerClicked(model);
                break;

            case 1:
                GroupModel groupModel = (GroupModel)ListBoxItems.SelectedItem;
                callingForm.GroupClicked(groupModel);
                break;

            case 2:
                CostCenterModel costCenterModel = (CostCenterModel)ListBoxItems.SelectedItem;
                callingForm.CostCenterClicked(costCenterModel);
                break;

            case 3:
                CostCategoryModel categoryModel = (CostCategoryModel)ListBoxItems.SelectedItem;
                callingForm.CategoryClicked(categoryModel);
                break;

            default:
                break;
            }
        }
        private void ParticularLedgerCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            paymentBills.Clear();
            LedgerModel model = (LedgerModel)ParticularLedgerCombobox.SelectedItem;

            if (model.credit_bal > model.debit_bal)
            {
                ParticularCurrentBalanceDataValue.Text = $"{model.current_bal} Cr";
            }
            else if (model.credit_bal < model.debit_bal)
            {
                ParticularCurrentBalanceDataValue.Text = $"{model.current_bal} Dr";
            }
            else
            {
                ParticularCurrentBalanceDataValue.Text = model.current_bal.ToString();
            }
            ParticularId = model.lid;

            availableBills = GlobalConfig.Connection.GetBill_ById(model);
            foreach (BillModel bill in availableBills)
            {
                PaymentBill pb = new PaymentBill();
                pb.reference = "Against";
                pb.emi       = bill.bill_name;
                pb.due_date  = bill.bill_due_date.Split(' ').First();
                pb.amount    = bill.bill_amount.ToString();

                paymentBills.Add(pb);
            }
        }
Exemple #5
0
        public async Task <IActionResult> GetAll([FromQuery] PageParams pageParams, [FromBody] LedgerModel getledgerModel)
        {
            ServiceResponseModel <IEnumerable <Ledger> > response = new ServiceResponseModel <IEnumerable <Ledger> >();

            try
            {
                if (string.IsNullOrWhiteSpace(getledgerModel.CompCode))
                {
                    throw new ArgumentNullException("CompCode is required");
                }
                if (string.IsNullOrWhiteSpace(getledgerModel.AccYear))
                {
                    throw new ArgumentNullException("AccYear is required");
                }
                var ledgerList = await _ledgerService.GetAll(pageParams, getledgerModel);

                Response.AddPaginationHeader(ledgerList.CurrentPage, ledgerList.PageSize, ledgerList.TotalCount, ledgerList.TotalPages);
                response.Data = ledgerList;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
        public async Task <PagedList <Ledger> > GetAll(PageParams pageParams, LedgerModel getledgerModel)
        {
            var query = _context.Ledgers
                        .Where(a => a.CompCode == getledgerModel.CompCode && a.AccYear == getledgerModel.AccYear)
                        .AsQueryable();

            switch (getledgerModel.OrderBy)
            {
            case "vouNo":
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.VouNo);
                break;

            case "vouDate":
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.VouDate).ThenBy(c => c.VouNo);
                break;

            case "accountId":
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.AccountId).ThenBy(c => c.VouDate);
                break;

            default:
                query = query.OrderBy(c => c.CompCode).ThenBy(c => c.AccYear).ThenBy(c => c.AccountId).ThenBy(c => c.VouDate);
                break;
            }

            return(await PagedList <Ledger> .CreateAsync(query, pageParams.PageNumber, pageParams.PageSize));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (ValidateForm())
            {
                LedgerModel         model         = new LedgerModel();
                MailingDetailsModel mailingModel  = new MailingDetailsModel();
                GroupModel          selectedGroup = (GroupModel)UnderGroupDropDown.SelectedItem;
                model.lid                    = ledger.lid;
                model.ledger_name            = LedgerNameValue.Text;
                model.ledger_alias           = LedgerAliasValue.Text;
                model.ledger_opening_balance = ledger.ledger_opening_balance;
                model.current_bal            = ledger.current_bal;
                model.credit_bal             = ledger.credit_bal;
                model.debit_bal              = ledger.debit_bal;
                model.under_group            = selectedGroup.group_id;
                if (BillBasedAccouting.IsChecked == true)
                {
                    model.bill_based_accounting = true;
                }
                else
                {
                    model.bill_based_accounting = false;
                }
                if (CostCentersApplicable.IsChecked == true)
                {
                    model.cost_centers_applicable = true;
                }
                else
                {
                    model.cost_centers_applicable = false;
                }
                if (EnableIntrestCalculations.IsChecked == true)
                {
                    model.enable_interest_calculations = true;
                }
                else
                {
                    model.enable_interest_calculations = false;
                }
                mailingModel.md_name    = MDNameValue.Text;
                mailingModel.md_address = MDAddressValue.Text;
                mailingModel.md_city    = MDCityValue.Text;
                mailingModel.md_state   = (string)StateValue.SelectedItem;
                mailingModel.md_country = "India";
                mailingModel.md_pincode = MDPincodeValue.Text;

                model.mailingModel = mailingModel;
                GlobalConfig.Connection.UpdateLedger(model);
                if (MessageBox.Show("Ledger Updated", "", MessageBoxButton.OK) == MessageBoxResult.OK)
                {
                    callingForm.Home(0);
                }
            }
            else
            {
                MessageBox.Show("Please Fill in the Details Properly!");
            }
        }
        public async Task <ServiceResponseModel <LedgerModel> > Add(LedgerModel newLedgerModel)
        {
            ServiceResponseModel <LedgerModel> serviceResponse = new ServiceResponseModel <LedgerModel>();
            Ledger ledger = _mapper.Map <Ledger>(newLedgerModel);
            await UnitOfWork.Ledgers.AddAsync(ledger);

            await UnitOfWork.Complete();

            serviceResponse.Data = newLedgerModel;
            return(serviceResponse);
        }
Exemple #9
0
        public async Task <LedgerModel> GetLedgerById(int ledgerId)
        {
            LedgerModel ledgerModel = null;

            IList <LedgerModel> ledgerModelList = await GetLedgerList(ledgerId, 0);

            if (null != ledgerModelList && ledgerModelList.Any())
            {
                ledgerModel = ledgerModelList.FirstOrDefault();
            }

            return(ledgerModel); // returns.
        }
Exemple #10
0
        public ActionResult AddLedger(int id = 0)
        {
            LedgerModel model = new LedgerModel();

            IEnumerable <SelectListItem> LedgerCat = (from z in db.tblLedgerGroups select z).AsEnumerable().Select(z => new SelectListItem()
            {
                Text = z.LedgerGroupName, Value = z.LedgerGroupId.ToString()
            });

            ViewBag.LedgerCat = new SelectList(LedgerCat, "Value", "Text");


            return(View(obj.EditLedgerModel(id)));
        }
        public async Task <ServiceResponseModel <LedgerModel> > Delete(LedgerModel delLedgerModel)
        {
            ServiceResponseModel <LedgerModel> serviceResponse = new ServiceResponseModel <LedgerModel>();
            Ledger delLedger = await UnitOfWork.Ledgers.SingleOrDefaultAsync(a =>
                                                                             a.CompCode == delLedgerModel.CompCode &&
                                                                             a.AccYear == delLedgerModel.AccYear &&
                                                                             a.VouNo == delLedgerModel.VouNo &&
                                                                             a.ItemSr == delLedgerModel.ItemSr);

            UnitOfWork.Ledgers.Remove(delLedger);
            await UnitOfWork.Complete();

            serviceResponse.Data = delLedgerModel;
            return(serviceResponse);
        }
        public DisplayLedgers(ICreateRequestor caller, LedgerModel model)
        {
            InitializeComponent();
            callingForm = caller;
            DateTime now   = DateTime.Now;
            string   date  = now.Day.ToString();
            string   month = now.Month.ToString();
            string   year  = now.Year.ToString();

            CurrentDate.Text = $"Date : {date}-{month}-{year}";
            ledger           = model;
            LoadListData();
            WireUpLists();
            WireUpForm();
        }
        public async Task <ServiceResponseModel <LedgerModel> > Edit(LedgerModel editLedgerModel)
        {
            ServiceResponseModel <LedgerModel> serviceResponse = new ServiceResponseModel <LedgerModel>();
            Ledger editLedger = await UnitOfWork.Ledgers.SingleOrDefaultAsync(a =>
                                                                              a.CompCode == editLedgerModel.CompCode &&
                                                                              a.AccYear == editLedgerModel.AccYear &&
                                                                              a.VouNo == editLedgerModel.VouNo &&
                                                                              a.ItemSr == editLedgerModel.ItemSr);

            _mapper.Map <LedgerModel, Ledger>(editLedgerModel, editLedger);
            serviceResponse.Data = editLedgerModel;
            UnitOfWork.Ledgers.Update(editLedger);
            await UnitOfWork.Complete();

            return(serviceResponse);
        }
Exemple #14
0
        public IEnumerable <LedgerModel> GetLedgerList(int ProductId)
        {
            var result = ent.GL_Ledgers.Where(x => x.ProductId == ProductId);
            List <LedgerModel> model = new List <LedgerModel>();

            foreach (var item in result)
            {
                LedgerModel obj = new LedgerModel
                {
                    LedgerId   = item.LedgerId,
                    LedgerName = item.LedgerName,
                };
                model.Add(obj);
            }
            return(model.AsEnumerable());
        }
        private double GetBalance(LedgerModel model)
        {
            double current = 0;

            if (model.credit_bal > model.debit_bal)
            {
                current = model.credit_bal - model.debit_bal;
            }
            else if (model.credit_bal < model.debit_bal)
            {
                current = model.debit_bal - model.credit_bal;
            }
            else
            {
                current = 0;
            }
            return(current);
        }
        private void AccountLedgerCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LedgerModel model = (LedgerModel)AccountLedgerCombobox.SelectedItem;

            if (model.credit_bal > model.debit_bal)
            {
                AccountCurrentBalanceDataValue.Text = $"{model.current_bal} Cr";
            }
            else if (model.credit_bal < model.debit_bal)
            {
                AccountCurrentBalanceDataValue.Text = $"{model.current_bal} Dr";
            }
            else
            {
                AccountCurrentBalanceDataValue.Text = model.current_bal.ToString();
            }
            AccountId = model.lid;
        }
        private void ParticularLedgerCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LedgerModel model = (LedgerModel)ParticularLedgerCombobox.SelectedItem;

            if (model.credit_bal > model.debit_bal)
            {
                ParticularCurrentBalanceDataValue.Text = $"{model.current_bal} Cr";
            }
            else if (model.credit_bal < model.debit_bal)
            {
                ParticularCurrentBalanceDataValue.Text = $"{model.current_bal} Dr";
            }
            else
            {
                ParticularCurrentBalanceDataValue.Text = model.current_bal.ToString();
            }
            ParticularBalance = model.current_bal;
            ParticularId      = model.lid;
        }
Exemple #18
0
 public List <LedgerModel> GetLedgerModels()
 {
     try
     {
         List <LedgerModel> ledgerModels = new List <LedgerModel>();
         var data = tRSEntities.Ledgers.Where(x => x.isActive == true).ToList();
         foreach (var item in data)
         {
             LedgerModel model = new LedgerModel
             {
                 id                 = item.id,
                 ledgername         = item.ledgername,
                 PAN                = item.PAN,
                 GSTIN              = item.GSTIN,
                 accountno          = item.accountno,
                 address            = item.address,
                 city               = item.city,
                 pincode            = item.pincode,
                 state              = item.state,
                 STDcode            = item.STDcode,
                 phoneno            = item.phoneno,
                 mobileno           = item.mobileno,
                 emailalert         = item.emailalert,
                 emailid            = item.emailid,
                 mobilealert        = item.mobilealert,
                 openingamount      = item.openingamount,
                 openingbalance     = item.openingbalance,
                 applicablelocation = item.applicablelocation,
                 remark             = item.remark,
                 isActive           = true,
                 statename          = tRSEntities.StateMasters.Where(x => x.id == item.state).Select(x => x.StateName).FirstOrDefault(),
                 cityname           = tRSEntities.CityMasters.Where(x => x.id == item.city).Select(x => x.cityName).FirstOrDefault(),
             };
             ledgerModels.Add(model);
         }
         return(ledgerModels);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #19
0
 public bool SaveLedger(LedgerModel model)
 {
     try
     {
         if (model != null)
         {
             Ledger ledger = new Ledger
             {
                 ledgername         = model.ledgername,
                 PAN                = model.PAN,
                 GSTIN              = model.GSTIN,
                 accountno          = model.accountno,
                 address            = model.address,
                 city               = model.city,
                 pincode            = model.pincode,
                 state              = model.state,
                 STDcode            = model.STDcode,
                 phoneno            = model.phoneno,
                 mobileno           = model.mobileno,
                 emailid            = model.emailid,
                 emailalert         = model.emailalert,
                 mobilealert        = model.mobilealert,
                 openingbalance     = model.openingbalance,
                 openingamount      = model.openingamount,
                 applicablelocation = model.applicablelocation,
                 remark             = model.remark,
                 isActive           = true,
             };
             tRSEntities.Ledgers.Add(ledger);
             tRSEntities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #20
0
        public async Task <int> CreateLedger(LedgerModel ledgerModel)
        {
            int ledgerId = 0;

            // assign values.
            Ledger ledger = new Ledger();

            ledger.LedgerCode      = ledgerModel.LedgerCode;
            ledger.LedgerName      = ledgerModel.LedgerName;
            ledger.IsGroup         = ledgerModel.IsGroup;
            ledger.IsMasterGroup   = ledgerModel.IsMasterGroup;
            ledger.ParentGroupId   = ledgerModel.ParentGroupId;
            ledger.IsDeActived     = ledgerModel.IsDeActived;
            ledger.TaxRegisteredNo = ledgerModel.TaxRegisteredNo;
            await Create(ledger);

            ledgerId = ledger.LedgerId;

            return(ledgerId); // returns.
        }
Exemple #21
0
        private async Task <LedgerModel> AssignValueToModel(Ledger ledger)
        {
            return(await Task.Run(() =>
            {
                LedgerModel ledgerModel = new LedgerModel();
                ledgerModel.LedgerId = ledger.LedgerId;
                ledgerModel.LedgerCode = ledger.LedgerCode;
                ledgerModel.LedgerName = ledger.LedgerName;
                ledgerModel.IsGroup = ledger.IsGroup;
                ledgerModel.IsMasterGroup = ledger.IsMasterGroup;
                ledgerModel.ParentGroupId = ledger.ParentGroupId;
                ledgerModel.IsDeActived = ledger.IsDeActived;
                ledgerModel.TaxRegisteredNo = ledger.TaxRegisteredNo;
                //######
                ledgerModel.ParentGroupName = null != ledger.ParentGroup ? ledger.ParentGroup.LedgerName : null;
                ledgerModel.PreparedByName = null != ledger.PreparedByUser ? ledger.PreparedByUser.UserName : null;

                return ledgerModel;
            }));
        }
Exemple #22
0
        public List <LedgerModel> ShowAllLedgerList()
        {
            List <LedgerModel> List = new List <LedgerModel>();
            var data = _entities.tblLedgerMasters.ToList();

            foreach (var item in data)
            {
                LedgerModel model = new LedgerModel();
                model.Id              = item.LedgerMasterId;
                model.LedgerName      = item.LedgerName;
                model.LedgerGroupId   = item.tblLedgerGroup.LedgerGroupId;
                model.LedgerGroupName = item.tblLedgerGroup.LedgerGroupName;
                model.OpeningBalance  = item.OPBalance;
                model.Date            = item.Date;
                model.Percentage      = item.Percentage;
                model.TransferType    = item.Transfer_Type;
                List.Add(model);
            }
            return(List);
        }
Exemple #23
0
        public async Task <bool> UpdateLedger(LedgerModel ledgerModel)
        {
            bool isUpdated = false;

            // get record.
            Ledger ledger = await GetByIdAsync(w => w.LedgerId == ledgerModel.LedgerId);

            if (null != ledger)
            {
                // assign values.
                ledger.LedgerCode      = ledgerModel.LedgerCode;
                ledger.LedgerName      = ledgerModel.LedgerName;
                ledger.IsGroup         = ledgerModel.IsGroup;
                ledger.IsMasterGroup   = ledgerModel.IsMasterGroup;
                ledger.ParentGroupId   = ledgerModel.ParentGroupId;
                ledger.IsDeActived     = ledgerModel.IsDeActived;
                ledger.TaxRegisteredNo = ledgerModel.TaxRegisteredNo;
                isUpdated = await Update(ledger);
            }

            return(isUpdated); // returns.
        }
Exemple #24
0
 public bool UpdateLedger(LedgerModel model)
 {
     try
     {
         var data = tRSEntities.Ledgers.Where(x => x.id == model.id && x.isActive == true).FirstOrDefault();
         if (data != null)
         {
             data.ledgername         = model.ledgername;
             data.PAN                = model.PAN;
             data.GSTIN              = model.GSTIN;
             data.accountno          = model.accountno;
             data.address            = model.address;
             data.city               = model.city;
             data.pincode            = model.pincode;
             data.state              = model.state;
             data.STDcode            = model.STDcode;
             data.phoneno            = model.phoneno;
             data.mobileno           = model.mobileno;
             data.emailid            = model.emailid;
             data.emailalert         = model.emailalert;
             data.mobilealert        = model.mobilealert;
             data.openingbalance     = model.openingbalance;
             data.openingamount      = model.openingamount;
             data.applicablelocation = model.applicablelocation;
             data.remark             = model.remark;
             data.isActive           = true;
             tRSEntities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #25
0
 public LedgerModel GetLedgerModel(int id)
 {
     try
     {
         var data = tRSEntities.Ledgers.Where(x => x.id == id && x.isActive == true).FirstOrDefault();
         if (data != null)
         {
             LedgerModel model = new LedgerModel();
             model.id                 = data.id;
             model.ledgername         = data.ledgername;
             model.PAN                = data.PAN;
             model.GSTIN              = data.GSTIN;
             model.accountno          = data.accountno;
             model.address            = data.address;
             model.city               = data.city;
             model.pincode            = data.pincode;
             model.state              = data.state;
             model.STDcode            = data.STDcode;
             model.phoneno            = data.phoneno;
             model.mobileno           = data.mobileno;
             model.emailid            = data.emailid;
             model.emailalert         = data.emailalert;
             model.mobilealert        = data.mobilealert;
             model.openingbalance     = data.openingbalance;
             model.openingamount      = data.openingamount;
             model.applicablelocation = data.applicablelocation;
             model.remark             = data.remark;
             return(model);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #26
0
        public LedgerModel EditLedgerModel(int Id)
        {
            LedgerModel model = new LedgerModel();

            if (Id != 0)
            {
                var data = _entities.tblLedgerMasters.Where(x => x.LedgerMasterId == Id).SingleOrDefault();
                model.Id = data.LedgerMasterId;

                model.LedgerName      = data.LedgerName;
                model.LedgerGroupId   = data.tblLedgerGroup.LedgerGroupId;
                model.LedgerGroupName = data.tblLedgerGroup.LedgerGroupName;
                model.Date            = data.Date;
                model.OpeningBalance  = data.OPBalance;
                model.Percentage      = data.Percentage;
                model.TransferType    = data.Transfer_Type;

                return(model);
            }
            else
            {
                return(model);
            }
        }
Exemple #27
0
        //public static Boolean AccountClosureTransaction(AccountClosureVM closureVM, AccountingDbContext accountingDb)
        //{
        //    using (var dbContextTransaction = accountingDb.Database.BeginTransaction())
        //    {
        //        try
        //        {
        //            FiscalYearModel fy = accountingDb.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault();

        //            if (fy != null)
        //            {
        //                fy.IsActive = false;
        //                UpdateFiscalYear(fy, accountingDb);
        //            }

        //            AddFiscalYear(closureVM.nextFiscalYear, accountingDb);

        //            closureVM.TnxModel.FiscalyearId = closureVM.nextFiscalYear.FiscalYearId;
        //            closureVM.TnxModel.VoucherId = 1;
        //            AddTransaction(closureVM.TnxModel, accountingDb);
        //            dbContextTransaction.Commit();
        //            return true;
        //        }
        //        catch (Exception ex)
        //        {
        //            dbContextTransaction.Rollback();
        //            throw ex;
        //        }
        //    }
        //}

        #region account closure
        //Ajay 24-10-2018
        public static bool AccountClosure(FiscalYearModel fiscalYear, AccountingDbContext accountingDBContext)
        {
            using (var dbContextTransaction = accountingDBContext.Database.BeginTransaction())
            {
                try
                {
                    //get active fiscal year and deactive it
                    FiscalYearModel fy = accountingDBContext.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault();
                    if (fy != null)
                    {
                        fy.IsActive = false;
                        UpdateFiscalYear(fy, accountingDBContext);
                    }
                    //add new fiscal year
                    AddFiscalYear(fiscalYear, accountingDBContext);
                    //get active ledgers with primary group Assets or Liabialities
                    var ledgers = (from led in accountingDBContext.Ledgers
                                   join ledGrp in accountingDBContext.LedgerGroups on led.LedgerGroupId equals ledGrp.LedgerGroupId
                                   where led.IsActive == true   // && (ledGrp.PrimaryGroup == "Assets" || ledGrp.PrimaryGroup == "Liabilities")
                                   select new
                    {
                        led.LedgerId,
                        led.OpeningBalance,
                        led.DrCr,
                        ledGrp.PrimaryGroup
                    }).ToList();

                    ledgers.ForEach(ledger =>
                    {
                        LedgerBalanceHistoryModel ledgerBalanceHistory = new LedgerBalanceHistoryModel();
                        LedgerModel led = accountingDBContext.Ledgers.Where(x => x.LedgerId == ledger.LedgerId).FirstOrDefault();
                        //calculate closing balance
                        if (ledger.PrimaryGroup == "Assets" || ledger.PrimaryGroup == "Liabilities")
                        {
                            double drAmount = accountingDBContext.TransactionItems
                                              .Where(x => x.LedgerId == ledger.LedgerId && x.DrCr == true)
                                              .Select(x => x.Amount).Sum().GetValueOrDefault();
                            double crAmount = accountingDBContext.TransactionItems
                                              .Where(x => x.LedgerId == ledger.LedgerId && x.DrCr == false)
                                              .Select(x => x.Amount).Sum().GetValueOrDefault();

                            if (led.DrCr == true)
                            {
                                drAmount = drAmount + led.OpeningBalance.Value;
                            }
                            if (led.DrCr == false)
                            {
                                crAmount = crAmount + led.OpeningBalance.Value;
                            }
                            if (drAmount > crAmount)
                            {
                                ledgerBalanceHistory.ClosingDrCr    = true;
                                ledgerBalanceHistory.ClosingBalance = drAmount - crAmount;

                                led.OpeningBalance = drAmount - crAmount;
                                led.DrCr           = true;
                            }
                            if (drAmount < crAmount)
                            {
                                ledgerBalanceHistory.ClosingDrCr    = false;
                                ledgerBalanceHistory.ClosingBalance = crAmount - drAmount;

                                led.OpeningBalance = crAmount - drAmount;
                                led.DrCr           = false;
                            }
                        }


                        //adding ledgerBalanceHistory
                        ledgerBalanceHistory.FiscalYearId   = accountingDBContext.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault().FiscalYearId;
                        ledgerBalanceHistory.LedgerId       = ledger.LedgerId;
                        ledgerBalanceHistory.OpeningBalance = ledger.OpeningBalance;
                        ledgerBalanceHistory.OpeningDrCr    = led.DrCr;
                        ledgerBalanceHistory.CreatedOn      = DateTime.Now;
                        ledgerBalanceHistory.CreatedBy      = fiscalYear.CreatedBy;
                        accountingDBContext.LedgerBalanceHistory.Add(ledgerBalanceHistory);
                        accountingDBContext.SaveChanges();


                        //updating ledger opening balance
                        accountingDBContext.Ledgers.Attach(led);
                        accountingDBContext.Entry(led).Property(x => x.OpeningBalance).IsModified = true;
                        accountingDBContext.Entry(led).Property(x => x.DrCr).IsModified           = true;
                        accountingDBContext.SaveChanges();
                    });



                    dbContextTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }
        /// <summary>
        /// Creates Receipt Voucher with Particular data, Updates Balance of both ledgers
        /// Add transaction bills and remove done bills from bills.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            VoucherModel    voucherModel    = new VoucherModel();
            ParticularModel particularModel = new ParticularModel();

            //Save Receipt Voucher

            //Balance Logic
            string balType = (string)balanceComboBox.SelectedItem;

            if (balType == credDeb[0])
            {
                double      amnt         = amount;
                LedgerModel accountModel = (LedgerModel)AccountLedgerCombobox.SelectedItem;
                LedgerModel particular   = (LedgerModel)ParticularLedgerCombobox.SelectedItem;
                //TODO Ledger Balance

                //update Particular Ledger
                particular.credit_bal  = particular.credit_bal + amnt;
                particular.current_bal = GetBalance(particular);
                GlobalConfig.Connection.UpdateLedger(particular);

                //update Account Ledger
                accountModel.debit_bal   = accountModel.debit_bal + amnt;
                accountModel.current_bal = GetBalance(accountModel);
                GlobalConfig.Connection.UpdateLedger(accountModel);
            }
            else if (balType == credDeb[1])
            {
                double      amnt         = amount;
                LedgerModel accountModel = (LedgerModel)AccountLedgerCombobox.SelectedItem;
                LedgerModel particular   = (LedgerModel)ParticularLedgerCombobox.SelectedItem;
                //TODO Ledger Balance

                //update Particular Ledger
                particular.debit_bal   = particular.debit_bal + amnt;
                particular.current_bal = GetBalance(particular);
                GlobalConfig.Connection.UpdateLedger(particular);

                //update Account Ledger
                accountModel.credit_bal  = accountModel.credit_bal + amnt;
                accountModel.current_bal = GetBalance(accountModel);
                GlobalConfig.Connection.UpdateLedger(accountModel);
            }

            //VoucherModel
            string d = DatePicker.SelectedDate.ToString().Split(' ').First();

            string[] dateList = d.Split('-');
            voucherModel.v_date = $"{dateList[2]}-{dateList[1]}-{dateList[0]}";
            if (vouchers.Count != 0)
            {
                voucherModel.v_number = vouchers[vouchers.Count - 1].vid + 1;
            }
            else
            {
                voucherModel.v_number = 1;
            }
            voucherModel.vtype   = "Receipt";
            voucherModel.account = AccountId;

            //Particular Model
            particularModel.particular_amount = double.Parse(AmountTextbox.Text);
            particularModel.particular_name   = ParticularId;

            voucherModel.Particular = particularModel;
            //Create Voucher And Particular Model.
            voucherModel = GlobalConfig.Connection.CreateVoucher(voucherModel);

            //Save Transactions
            SaveTransactions();
        }
        private void UpdateBalance()
        {
            LedgerModel accountModel = (LedgerModel)AccountLedgerCombobox.SelectedItem;
            LedgerModel particular   = (LedgerModel)ParticularLedgerCombobox.SelectedItem;
            string      balType      = (string)balanceComboBox.SelectedItem;
            double      amnt         = amount;

            if (balType == credDeb[0])
            {
                //update Particular Ledger
                double credBal = particular.credit_bal + amnt;
                double debBal  = particular.debit_bal;
                double curBal  = GetBalance(credBal, debBal);
                if (credBal > debBal)
                {
                    ParticularCurrentBalanceDataValue.Text = $"{curBal:0.00} Cr";
                }
                else if (credBal < debBal)
                {
                    ParticularCurrentBalanceDataValue.Text = $"{curBal:0.00} Dr";
                }
                else
                {
                    ParticularCurrentBalanceDataValue.Text = $"{curBal:0.00}";
                }

                //update Account Ledger
                double adebBal = accountModel.debit_bal + amnt;
                double acurBal = GetBalance(accountModel.credit_bal, adebBal);
                if (accountModel.credit_bal > adebBal)
                {
                    AccountCurrentBalanceDataValue.Text = $"{acurBal:0.00} Cr";
                }
                else if (accountModel.credit_bal < adebBal)
                {
                    AccountCurrentBalanceDataValue.Text = $"{acurBal:0.00} Dr";
                }
                else
                {
                    AccountCurrentBalanceDataValue.Text = $"{acurBal:0.00}";
                }
            }
            else if (balType == credDeb[1])
            {
                //update Particular Ledger
                double pdebBal = particular.debit_bal + amnt;
                double curBal  = GetBalance(particular.credit_bal, pdebBal);
                if (particular.credit_bal > pdebBal)
                {
                    ParticularCurrentBalanceDataValue.Text = $"{curBal:0.00} Cr";
                }
                else if (particular.credit_bal < pdebBal)
                {
                    ParticularCurrentBalanceDataValue.Text = $"{curBal:0.00} Dr";
                }
                else
                {
                    ParticularCurrentBalanceDataValue.Text = $"{curBal:0.00}";
                }

                //update Account Ledger
                double acredBal = accountModel.credit_bal + amnt;
                double acurBal  = GetBalance(acredBal, accountModel.debit_bal);
                if (acredBal > accountModel.debit_bal)
                {
                    AccountCurrentBalanceDataValue.Text = $"{acurBal:0.00} Cr";
                }
                else if (acredBal < accountModel.debit_bal)
                {
                    AccountCurrentBalanceDataValue.Text = $"{acurBal:0.00} Dr";
                }
                else
                {
                    AccountCurrentBalanceDataValue.Text = $"{acurBal:0.00}";
                }
            }
        }
Exemple #30
0
        public string SaveLedger(LedgerModel model)
        {
            tblLedgerMaster tb = new tblLedgerMaster();

            int    CurrentYear  = DateTime.Today.Year;
            int    PreviousYear = DateTime.Today.Year - 1;
            int    NextYear     = DateTime.Today.Year + 1;
            string PreYear      = PreviousYear.ToString();
            string NexYear      = NextYear.ToString();
            string CurYear      = CurrentYear.ToString();
            string FinYear      = null;

            if (DateTime.Today.Month > 3)
            {
                FinYear = CurYear + "-" + NexYear;
            }
            else
            {
                FinYear = PreYear + "-" + CurYear;
            }


            var duplicate = _entities.tblLedgerMasters.Where(o => o.LedgerName == model.LedgerName && o.tblLedgerGroup.LedgerGroupId == model.LedgerGroupId && o.OPBalance == model.OpeningBalance && o.Percentage == model.Percentage && o.Transfer_Type == model.TransferType).SingleOrDefault();

            if (duplicate == null)
            {
                try
                {
                    if (model.Id != 0)
                    {
                        tb = _entities.tblLedgerMasters.Where(x => x.LedgerMasterId == model.Id).SingleOrDefault();

                        tb.LedgerName    = model.LedgerName;
                        tb.LedgerGroup   = model.LedgerGroupId;
                        tb.Date          = model.Date;
                        tb.OPBalance     = model.OpeningBalance;
                        tb.Percentage    = model.Percentage;
                        tb.RecordId      = model.Record_Id;
                        tb.Transfer_Type = model.TransferType;
                        _entities.SaveChanges();

                        int id = tb.LedgerMasterId;

                        if (model.TransferType == "Credit")
                        {
                            Voucher_Entry_Credit tb1 = new Voucher_Entry_Credit();

                            if (_entities.Voucher_Entry_Credit.Where(x => x.voucher_ledger_accout_id == id) != null)
                            {
                                tb1 = _entities.Voucher_Entry_Credit.Where(x => x.voucher_ledger_accout_id == id && x.voucher_type == "OB").SingleOrDefault();

                                tb1.voucher_no        = tb.RecordId.ToString();
                                tb1.Voucher_date      = model.Date;
                                tb1.record_no         = tb.RecordId.ToString();
                                tb1.record_date       = model.Date;
                                tb1.voucher_sno       = 1;
                                tb1.voucher_tb        = "To";
                                tb1.voucher_cr_amount = model.OpeningBalance;

                                tb1.voucher_year   = FinYear.Trim();
                                tb1.create_date    = DateTime.Now;
                                tb1.from_form_name = "Ledger_master";
                                tb1.from_form_id   = id;
                                tb1.account_type   = "OB";
                                tb1.userid         = WebSecurity.CurrentUserId;
                                _entities.Voucher_Entry_Credit.Add(tb1);
                                _entities.SaveChanges();
                            }
                            else
                            {
                                tb1.voucher_no               = tb.RecordId.ToString();
                                tb1.Voucher_date             = model.Date;
                                tb1.record_no                = tb.RecordId.ToString();
                                tb1.record_date              = model.Date;
                                tb1.voucher_sno              = 1;
                                tb1.voucher_tb               = "To";
                                tb1.voucher_ledger_accout_id = id;
                                tb1.voucher_cr_amount        = model.OpeningBalance;
                                tb1.voucher_type             = "OB";
                                tb1.voucher_year             = FinYear.Trim();
                                tb1.create_date              = DateTime.Now;
                                tb1.from_form_name           = "Ledger_master";
                                tb1.from_form_id             = id;
                                tb1.account_type             = "OB";
                                tb1.userid = WebSecurity.CurrentUserId;
                                _entities.Voucher_Entry_Credit.Add(tb1);
                                _entities.SaveChanges();
                            }
                        }
                        else if (model.TransferType == "Debit")
                        {
                            Voucher_Entry_Debit tb2 = new Voucher_Entry_Debit();

                            if (_entities.Voucher_Entry_Debit.Where(x => x.voucher_ledger_accout_id == id) != null)
                            {
                                tb2 = _entities.Voucher_Entry_Debit.Where(x => x.voucher_ledger_accout_id == id && x.voucher_type == "OB").SingleOrDefault();

                                tb2.voucher_no         = tb.RecordId.ToString();
                                tb2.voucher_date       = model.Date;
                                tb2.record_no          = tb.RecordId.ToString();
                                tb2.record_date        = model.Date;
                                tb2.voucher_sno        = 1;
                                tb2.voucher_tb         = "To";
                                tb2.voucher_dbt_amount = model.OpeningBalance;

                                tb2.voucher_year   = DateTime.Now.ToFinancialYear();//FinYear.Trim();
                                tb2.create_date    = DateTime.Now;
                                tb2.from_form_name = "Ledger_master";
                                tb2.from_form_id   = model.Id;
                                tb2.account_type   = "OB";
                                tb2.userid         = WebSecurity.CurrentUserId;
                                _entities.Voucher_Entry_Debit.Add(tb2);
                                _entities.SaveChanges();
                            }
                            else
                            {
                                tb2.voucher_no               = tb.RecordId.ToString();
                                tb2.voucher_date             = model.Date;
                                tb2.record_no                = tb.RecordId.ToString();
                                tb2.record_date              = model.Date;
                                tb2.voucher_sno              = 1;
                                tb2.voucher_tb               = "To";
                                tb2.voucher_ledger_accout_id = id;
                                tb2.voucher_dbt_amount       = model.OpeningBalance;
                                tb2.voucher_type             = "OB";
                                tb2.voucher_year             = DateTime.Now.ToFinancialYear();//FinYear.Trim();
                                tb2.create_date              = DateTime.Now;
                                tb2.from_form_name           = "Ledger_master";
                                tb2.from_form_id             = model.Id;
                                tb2.account_type             = "OB";
                                tb2.userid = WebSecurity.CurrentUserId;
                                _entities.Voucher_Entry_Debit.Add(tb2);
                                _entities.SaveChanges();
                            }
                        }
                        return("Record Updated Successfully...");
                    }
                    else
                    {
                        tb.LedgerName  = model.LedgerName;
                        tb.LedgerGroup = model.LedgerGroupId;
                        tb.Date        = model.Date;
                        tb.OPBalance   = model.OpeningBalance;
                        if (_entities.tblLedgerMasters.Select(p => p.RecordId).Count() > 0)
                        {
                            tb.RecordId = _entities.tblLedgerMasters.Select(p => p.RecordId).Max() + 1;
                        }
                        else
                        {
                            tb.RecordId = 1;
                        }
                        tb.Percentage    = model.Percentage;
                        tb.Transfer_Type = model.TransferType;
                        _entities.tblLedgerMasters.Add(tb);
                        _entities.SaveChanges();
                        int id = tb.LedgerMasterId;

                        if (model.TransferType == "Credit")
                        {
                            Voucher_Entry_Credit tb1 = new Voucher_Entry_Credit();
                            tb1.voucher_no               = tb.RecordId.ToString();
                            tb1.Voucher_date             = model.Date;
                            tb1.record_no                = tb.RecordId.ToString();
                            tb1.record_date              = model.Date;
                            tb1.voucher_sno              = 1;
                            tb1.voucher_tb               = "To";
                            tb1.voucher_ledger_accout_id = id;
                            tb1.voucher_cr_amount        = model.OpeningBalance;
                            tb1.voucher_type             = "OB";
                            tb1.voucher_year             = FinYear.Trim();
                            tb1.create_date              = DateTime.Now;
                            tb1.from_form_name           = "Ledger_master";
                            tb1.from_form_id             = id;
                            tb1.account_type             = "OB";
                            tb1.userid = WebSecurity.CurrentUserId;
                            _entities.Voucher_Entry_Credit.Add(tb1);
                            _entities.SaveChanges();
                        }
                        else if (model.TransferType == "Debit")
                        {
                            Voucher_Entry_Debit tb2 = new Voucher_Entry_Debit();
                            tb2.voucher_no               = tb.RecordId.ToString();
                            tb2.voucher_date             = model.Date;
                            tb2.record_no                = tb.RecordId.ToString();
                            tb2.record_date              = model.Date;
                            tb2.voucher_sno              = 1;
                            tb2.voucher_tb               = "To";
                            tb2.voucher_ledger_accout_id = tb.LedgerMasterId;
                            tb2.voucher_dbt_amount       = model.OpeningBalance;
                            tb2.voucher_type             = "OB";
                            tb2.voucher_year             = DateTime.Now.ToFinancialYear();//FinYear.Trim();
                            tb2.create_date              = DateTime.Now;
                            tb2.from_form_name           = "Ledger_master";
                            tb2.from_form_id             = model.Id;
                            tb2.account_type             = "OB";
                            tb2.userid = WebSecurity.CurrentUserId;
                            _entities.Voucher_Entry_Debit.Add(tb2);
                            _entities.SaveChanges();
                        }


                        return("Record Saved Successfully...");
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
            else
            {
                return(model.LedgerName + " Already Exits");
            }
        }