public LedgerDetailCostCenterChildWindow(LedgerHeaderViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
     _viewModel  = viewModel;
     _viewModel.GetSubDetailData();
 }
Exemplo n.º 2
0
        public CostDimChildWindow(LedgerHeaderViewModel TempViewModel)
        {
            InitializeComponent();
            var viewModel = new CostDimChildViewModel(TempViewModel);

            DataContext = viewModel;
            _viewModel  = viewModel;
        }
Exemplo n.º 3
0
        public CostDimChildViewModel(LedgerHeaderViewModel ledgerHeaderViewModel)
        {
            if (!IsDesignTime)
            {
                LedgerHeaderViewModel = ledgerHeaderViewModel;
                GetItemPermissions(PermissionItemName.Account.ToString());
                Glclient = new GlServiceClient();

                MainRowList     = new SortableCollectionView <TblCostDimDetailViewModel>();
                SelectedMainRow = new TblCostDimDetailViewModel();

                Glclient.GetTblCostDimSetupHeaderForAccountCompleted += (s, sv) =>
                {
                    if (sv.Result != null)
                    {
                        foreach (var row in sv.Result.TblCostDimDetails)
                        {
                            var newrow = new TblCostDimDetailViewModel();
                            newrow.InjectFrom(row);
                            newrow.CostCenterPerRow = row.TblCostCenter1;
                            MainRowList.Add(newrow);
                        }
                    }

                    Loading = false;

                    if (MainRowList.Any() && (SelectedMainRow == null))
                    {
                        SelectedMainRow = MainRowList.FirstOrDefault();
                    }
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };

                Glclient.SaveTblCostDimHeaderCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        MessageBox.Show(ev.Error.Message);
                    }
                    try
                    {
                        ledgerHeaderViewModel.SelectedDetailRow.TblCostDimHeader = ev.Result;
                        ledgerHeaderViewModel.SaveMainRow();
                    }
                    catch (Exception)
                    {
                    }
                };
                GetMaindata();
            }
        }
Exemplo n.º 4
0
 public LedgerDetailChildWindow(LedgerHeaderViewModel viewModel)
 {
     InitializeComponent();
     TxtBalanceJournalValue.Text    = "0";
     TxtBalancePerVoucherValue.Text = "0";
     TxtCreditJournalValue.Text     = "0";
     TxtCreditPerVoucherValue.Text  = "0";
     TxtDebitJournalValue.Text      = "0";
     TxtDebitPerVouchervalue.Text   = "0";
     DataContext = viewModel;
     _viewModel  = viewModel;
     _viewModel.GetDetailData();
     if (_viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "LedgerPostWithApproval") != null || _viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "LedgerPostWithoutApproval") != null)
     {
         BtnPost.Visibility = Visibility.Visible;
     }
     if (_viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "LedgerApprove") != null)
     {
         BtnApprove.Visibility = Visibility.Visible;
     }
 }
Exemplo n.º 5
0
 public Ledger()
 {
     InitializeComponent();
     _viewModel  = (LedgerHeaderViewModel)LayoutRoot.DataContext;
     DataContext = _viewModel;
     _viewModel.PremCompleted += (s, sv) =>
     {
         if (_viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "LedgerPostWithApproval") != null || _viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "LedgerPostWithoutApproval") != null)
         {
             MainGrid.Columns.SingleOrDefault(x => x.SortMemberPath == "Posted").Visibility = Visibility.Visible;
         }
         if (_viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "LedgerApprove") != null)
         {
             MainGrid.Columns.SingleOrDefault(x => x.SortMemberPath == "Approved").Visibility =
                 Visibility.Visible;
         }
         if (_viewModel.CustomePermissions.SingleOrDefault(x => x.Code == "ReverseGLTransaction") != null)
         {
             BtnReverse.Visibility = Visibility.Visible;
         }
     };
 }
Exemplo n.º 6
0
        public ActionResult PaymentCancelWizard(int id)//DocumentTypeId
        {
            PrepareViewBag(id);
            LedgerHeaderViewModel vm = new LedgerHeaderViewModel();

            vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            vm.SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

            //Getting Settings
            var settings = new LedgerSettingService(_unitOfWork).GetLedgerSettingForDocument(id, vm.DivisionId, vm.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreateForCancel", "LedgerSetting", new { id = id }).Warning("Please create payment cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }

            ViewBag.ProcessId = settings.ProcessId;
            return(View());
        }
Exemplo n.º 7
0
        public void LedgerPostingDB(ref LedgerHeaderViewModel LedgerHeaderViewModel, IEnumerable <CalculationHeaderCharge> HeaderTable, IEnumerable <CalculationLineCharge> LineTable, ref ApplicationDbContext Context)
        {
            int PersonAccountId = 6612;
            int LedgerHeaderId  = 0;

            if (LedgerHeaderViewModel.LedgerHeaderId == 0)
            {
                LedgerHeader LedgerHeader = new LedgerHeader();

                LedgerHeader.DocHeaderId  = LedgerHeaderViewModel.DocHeaderId;
                LedgerHeader.DocTypeId    = LedgerHeaderViewModel.DocTypeId;
                LedgerHeader.DocDate      = LedgerHeaderViewModel.DocDate;
                LedgerHeader.DocNo        = LedgerHeaderViewModel.DocNo;
                LedgerHeader.DivisionId   = LedgerHeaderViewModel.DivisionId;
                LedgerHeader.SiteId       = LedgerHeaderViewModel.SiteId;
                LedgerHeader.PartyDocNo   = LedgerHeaderViewModel.PartyDocNo;
                LedgerHeader.PartyDocDate = LedgerHeaderViewModel.PartyDocDate;
                LedgerHeader.Narration    = LedgerHeaderViewModel.Narration;
                LedgerHeader.Remark       = LedgerHeaderViewModel.Remark;
                LedgerHeader.CreatedBy    = LedgerHeaderViewModel.CreatedBy;
                LedgerHeader.ProcessId    = LedgerHeaderViewModel.ProcessId;
                LedgerHeader.CreatedDate  = DateTime.Now.Date;
                LedgerHeader.ModifiedBy   = LedgerHeaderViewModel.ModifiedBy;
                LedgerHeader.ModifiedDate = DateTime.Now.Date;
                LedgerHeader.ObjectState  = Model.ObjectState.Added;
                Context.LedgerHeader.Add(LedgerHeader);
                //new LedgerHeaderService(_unitOfWork).Create(LedgerHeader);
            }
            else
            {
                int          LedHeadId    = LedgerHeaderViewModel.LedgerHeaderId;
                LedgerHeader LedgerHeader = (from p in Context.LedgerHeader
                                             where p.LedgerHeaderId == LedHeadId
                                             select p).FirstOrDefault();

                LedgerHeader.DocHeaderId  = LedgerHeaderViewModel.DocHeaderId;
                LedgerHeader.DocTypeId    = LedgerHeaderViewModel.DocTypeId;
                LedgerHeader.DocDate      = LedgerHeaderViewModel.DocDate;
                LedgerHeader.DocNo        = LedgerHeaderViewModel.DocNo;
                LedgerHeader.DivisionId   = LedgerHeaderViewModel.DivisionId;
                LedgerHeader.ProcessId    = LedgerHeaderViewModel.ProcessId;
                LedgerHeader.SiteId       = LedgerHeaderViewModel.SiteId;
                LedgerHeader.PartyDocNo   = LedgerHeaderViewModel.PartyDocNo;
                LedgerHeader.PartyDocDate = LedgerHeaderViewModel.PartyDocDate;
                LedgerHeader.Narration    = LedgerHeaderViewModel.Narration;
                LedgerHeader.Remark       = LedgerHeaderViewModel.Remark;
                LedgerHeader.ModifiedBy   = LedgerHeaderViewModel.ModifiedBy;
                LedgerHeader.ModifiedDate = DateTime.Now.Date;
                LedgerHeader.ObjectState  = Model.ObjectState.Modified;
                Context.LedgerHeader.Add(LedgerHeader);
                //new LedgerHeaderService(_unitOfWork).Update(LedgerHeader);

                IEnumerable <Ledger> LedgerList = (from p in Context.Ledger
                                                   where p.LedgerHeaderId == LedHeadId
                                                   select p).ToList();
                foreach (Ledger item in LedgerList)
                {
                    item.ObjectState = Model.ObjectState.Deleted;
                    Context.Ledger.Remove(item);
                    //new LedgerService(_unitOfWork).Delete(item);
                }

                LedgerHeaderId = LedgerHeader.LedgerHeaderId;
            }


            IEnumerable <LedgerPostingViewModel> LedgerHeaderAmtDr = (from H in HeaderTable
                                                                      join A in Context.LedgerAccount on H.PersonID equals A.PersonId into LedgerAccountTable
                                                                      from LedgerAccountTab in LedgerAccountTable.DefaultIfEmpty()
                                                                      where H.LedgerAccountDrId != null && H.Amount != 0 && H.Amount != null
                                                                      select new LedgerPostingViewModel
            {
                LedgerAccountId = (int)(H.LedgerAccountDrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : H.LedgerAccountDrId),
                ContraLedgerAccountId = (H.LedgerAccountCrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : H.LedgerAccountCrId),
                CostCenterId = H.CostCenterId,
                AmtDr = Math.Abs((H.Amount > 0 ? H.Amount : 0) ?? 0),
                AmtCr = Math.Abs((H.Amount < 0 ? H.Amount : 0) ?? 0)
            }).ToList();

            IEnumerable <LedgerPostingViewModel> LedgerHeaderAmtCr = (from H in HeaderTable
                                                                      join A in Context.LedgerAccount on H.PersonID equals A.PersonId into LedgerAccountTable
                                                                      from LedgerAccountTab in LedgerAccountTable.DefaultIfEmpty()
                                                                      where H.LedgerAccountCrId != null && H.Amount != 0 && H.Amount != null
                                                                      select new LedgerPostingViewModel
            {
                LedgerAccountId = (int)(H.LedgerAccountCrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : H.LedgerAccountCrId),
                ContraLedgerAccountId = (H.LedgerAccountDrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : H.LedgerAccountDrId),
                CostCenterId = H.CostCenterId,
                AmtCr = Math.Abs((H.Amount > 0 ? H.Amount : 0) ?? 0),
                AmtDr = Math.Abs((H.Amount < 0 ? H.Amount : 0) ?? 0)
            }).ToList();

            IEnumerable <LedgerPostingViewModel> LedgerLineAmtDr = (from L in LineTable
                                                                    join A in Context.LedgerAccount on L.PersonID equals A.PersonId into LedgerAccountTable
                                                                    from LedgerAccountTab in LedgerAccountTable.DefaultIfEmpty()
                                                                    where L.LedgerAccountDrId != null && L.Amount != 0 && L.Amount != null
                                                                    select new LedgerPostingViewModel
            {
                LedgerAccountId = (int)(L.LedgerAccountDrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : L.LedgerAccountDrId),
                ContraLedgerAccountId = (L.LedgerAccountCrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : L.LedgerAccountCrId),
                CostCenterId = L.CostCenterId,
                AmtDr = Math.Abs((L.Amount > 0 ? L.Amount : 0) ?? 0),
                AmtCr = Math.Abs((L.Amount < 0 ? L.Amount : 0) ?? 0)
            }).ToList();

            IEnumerable <LedgerPostingViewModel> LedgerLineAmtCr = (from L in LineTable
                                                                    join A in Context.LedgerAccount on L.PersonID equals A.PersonId into LedgerAccountTable
                                                                    from LedgerAccountTab in LedgerAccountTable.DefaultIfEmpty()
                                                                    where L.LedgerAccountCrId != null && L.Amount != 0 && L.Amount != null
                                                                    select new LedgerPostingViewModel
            {
                LedgerAccountId = (int)(L.LedgerAccountCrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : L.LedgerAccountCrId),
                ContraLedgerAccountId = (L.LedgerAccountDrId == PersonAccountId ? LedgerAccountTab.LedgerAccountId : L.LedgerAccountDrId),
                CostCenterId = L.CostCenterId,
                AmtCr = Math.Abs((L.Amount > 0 ? L.Amount : 0) ?? 0),
                AmtDr = Math.Abs((L.Amount < 0 ? L.Amount : 0) ?? 0)
            }).ToList();


            IEnumerable <LedgerPostingViewModel> LedgerCombind = LedgerHeaderAmtDr.Union(LedgerHeaderAmtCr).Union(LedgerLineAmtDr).Union(LedgerLineAmtCr).ToList();

            //IEnumerable<LedgerPostingViewModel> LedgerPost = (from L in LedgerCombind
            //                                                 group new { L } by new { L.LedgerAccountId, L.ContraLedgerAccountId, L.CostCenterId } into Result
            //                                                 select new LedgerPostingViewModel
            //                                                 {
            //                                                     LedgerAccountId = Result.Key.LedgerAccountId,
            //                                                     ContraLedgerAccountId = Result.Key.ContraLedgerAccountId,
            //                                                     CostCenterId = Result.Key.CostCenterId,
            //                                                     AmtDr = Result.Sum(i => i.L.AmtDr),
            //                                                     AmtCr = Result.Sum(i => i.L.AmtCr)
            //                                                 }).ToList();



            IEnumerable <LedgerPostingViewModel> LedgerPost1 = from L in LedgerCombind
                                                               join Ca in db.LedgerAccount on L.ContraLedgerAccountId equals Ca.LedgerAccountId into ContraLedgerAccountTable
                                                               from ContraLedgerAccountTab in ContraLedgerAccountTable.DefaultIfEmpty()
                                                               join Cag in db.LedgerAccountGroup on ContraLedgerAccountTab.LedgerAccountGroupId equals Cag.LedgerAccountGroupId into ContraLedgerAccountGroupTable
                                                               from ContraLedgerAccountGroupTab in ContraLedgerAccountGroupTable.DefaultIfEmpty()
                                                               group new { L, ContraLedgerAccountGroupTab } by new { L.LedgerAccountId, L.ContraLedgerAccountId, L.CostCenterId } into Result
                                                 select new LedgerPostingViewModel
            {
                LedgerAccountId              = Result.Key.LedgerAccountId,
                ContraLedgerAccountId        = Result.Key.ContraLedgerAccountId,
                ContraLedgerAccountWeightage = Result.Max(i => i.ContraLedgerAccountGroupTab.Weightage ?? 0),
                CostCenterId = Result.Key.CostCenterId,
                AmtDr        = Result.Sum(i => i.L.AmtDr),
                AmtCr        = Result.Sum(i => i.L.AmtCr)
            };


            IEnumerable <LedgerPostingViewModel> LedgerPost2 = from L in LedgerPost1
                                                               group new { L } by new { L.LedgerAccountId, L.CostCenterId } into Result
                                                 select new LedgerPostingViewModel
            {
                LedgerAccountId = Result.Key.LedgerAccountId,
                ContraLedgerAccountWeightage = Result.Max(i => i.L.ContraLedgerAccountWeightage ?? 0),
                CostCenterId = Result.Key.CostCenterId,
                AmtDr        = Result.Sum(i => i.L.AmtDr) - Result.Sum(i => i.L.AmtCr) > 0 ? Result.Sum(i => i.L.AmtDr) - Result.Sum(i => i.L.AmtCr) : 0,
                AmtCr        = Result.Sum(i => i.L.AmtCr) - Result.Sum(i => i.L.AmtDr) > 0 ? Result.Sum(i => i.L.AmtCr) - Result.Sum(i => i.L.AmtDr) : 0,
            };

            IEnumerable <LedgerPostingViewModel> LedgerPost = from L2 in LedgerPost2
                                                              join L1 in LedgerPost1 on new { A1 = L2.LedgerAccountId, A2 = L2.CostCenterId, A3 = L2.ContraLedgerAccountWeightage } equals new { A1 = L1.LedgerAccountId, A2 = L1.CostCenterId, A3 = L1.ContraLedgerAccountWeightage } into LedgerPost1Table
            from LedgerPost1Tab in LedgerPost1Table.DefaultIfEmpty()
            group new { LedgerPost1Tab, L2 } by new { L2.LedgerAccountId, L2.CostCenterId } into Result
                                                 select new LedgerPostingViewModel
            {
                LedgerAccountId       = Result.Key.LedgerAccountId,
                ContraLedgerAccountId = Result.Max(i => i.LedgerPost1Tab.ContraLedgerAccountId),
                CostCenterId          = Result.Key.CostCenterId,
                AmtDr = Result.Max(i => i.L2.AmtDr),
                AmtCr = Result.Max(i => i.L2.AmtCr)
            };



            var temp = (from L in LedgerPost
                        group L by 1 into Result
                        select new
            {
                AmtDr = Result.Sum(i => i.AmtDr),
                AmtCr = Result.Sum(i => i.AmtCr)
            }).FirstOrDefault();


            if (temp != null)
            {
                if (temp.AmtDr != temp.AmtCr)
                {
                    throw new Exception("Debit amount and credit amount is not equal.Check account posting.");
                }
            }



            foreach (LedgerPostingViewModel item in LedgerPost)
            {
                Ledger Ledger = new Ledger();

                if (LedgerHeaderId != 0)
                {
                    Ledger.LedgerHeaderId = LedgerHeaderId;
                }
                Ledger.LedgerAccountId       = item.LedgerAccountId;
                Ledger.ContraLedgerAccountId = item.ContraLedgerAccountId;


                var TempCostCenter = (from C in Context.CostCenter
                                      where C.CostCenterId == item.CostCenterId && C.LedgerAccountId == item.LedgerAccountId
                                      select new { CostCenterId = C.CostCenterId }).FirstOrDefault();

                if (TempCostCenter != null)
                {
                    Ledger.CostCenterId = item.CostCenterId;
                }



                Ledger.AmtDr     = item.AmtDr * (LedgerHeaderViewModel.ExchangeRate ?? 1);
                Ledger.AmtCr     = item.AmtCr * (LedgerHeaderViewModel.ExchangeRate ?? 1);
                Ledger.Narration = "";

                //new LedgerService(_unitOfWork).Create(Ledger);
                Ledger.ObjectState = Model.ObjectState.Added;
                Context.Ledger.Add(Ledger);
            }
        }