// GET: AccountCharts/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AccountChart accountChart = db.AccountCharts.Find(id);

            if (accountChart == null)
            {
                return(HttpNotFound());
            }

            var canBeDeleted = !(accountChart.TransactionLines.Any() || accountChart.Transactions.Any());

            ModalDelete model = new ModalDelete();

            model.Action     = "Delete";
            model.Controller = "AccountCharts";
            model.Id         = id.ToString();
            model.Name       = accountChart.Name;
            model.IsSubmit   = true;

            if (!canBeDeleted)
            {
                model.ModalMessage  = "This account cannot be deleted, its already contains transactions";
                model.DisableSubmit = true;
            }

            return(PartialView("_ModalDelete", model));
            //return View(accountChart);
        }
Exemple #2
0
        public async Task <IActionResult> Edit(Guid id, [Bind("ID,AccountCode,Description,IncomeOrExpense")] AccountChart accountChart)
        {
            if (id != accountChart.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(accountChart);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountChartExists(accountChart.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(accountChart));
        }
        public IList <AccountChart> UpdateCurrentValueOfParentAccountChartTree(long?parentAccountChartId, decimal amount, bool isCreditor)
        {
            List <AccountChart> list = new List <AccountChart>();

            AccountChart parentAccountChart = list.FirstOrDefault(x => x.Id == parentAccountChartId);

            if (parentAccountChart == null)
            {
                parentAccountChart = this._accountChartsRepository
                                     .Get(null)
                                     .Where(x => x.Id == parentAccountChartId)
                                     .FirstOrDefault();
            }

            if (parentAccountChart != null)
            {
                if (isCreditor)
                {
                    if (parentAccountChart.CurrentCreditBalance.HasValue == false)
                    {
                        parentAccountChart.CurrentCreditBalance = amount;
                    }
                    else
                    {
                        parentAccountChart.CurrentCreditBalance += amount;
                    }
                }
                else
                {
                    if (parentAccountChart.CurrentDebitBalance.HasValue == false)
                    {
                        parentAccountChart.CurrentDebitBalance = amount;
                    }
                    else
                    {
                        parentAccountChart.CurrentDebitBalance += amount;
                    }
                }

                this._accountChartsRepository.Update(parentAccountChart);
                list.Add(parentAccountChart);

                if (parentAccountChart.ParentAccountChartId.HasValue)
                {
                    list.AddRange(this.UpdateCurrentValueOfParentAccountChartTree(parentAccountChart.ParentAccountChartId, amount, isCreditor));
                }
            }
            //else
            //{

            //}

            return(list);
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("ID,AccountCode,Description,IncomeOrExpense")] AccountChart accountChart)
        {
            if (ModelState.IsValid)
            {
                accountChart.ID = Guid.NewGuid();
                _context.Add(accountChart);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(accountChart));
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            AccountChart accountChart = db.AccountCharts.Find(id);

            if (accountChart.Transactions.Any() || accountChart.TransactionLines.Any())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            db.AccountCharts.Remove(accountChart);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: AccountCharts/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AccountChart accountChart = db.AccountCharts.Find(id);

            if (accountChart == null)
            {
                return(HttpNotFound());
            }
            return(View(accountChart));
        }
        public ActionResult Create(AccountChart accountChart)
        {
            accountChart.DateEntered  = DateTime.Now;
            accountChart.EnteredBy    = new Guid(Operator().Id);
            accountChart.OwnerGroupId = Operator().OwnerGroupId;

            if (ModelState.IsValid)
            {
                accountChart.Id = Guid.NewGuid();
                db.AccountCharts.Add(accountChart);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(accountChart));
        }
        public ActionResult Edit([Bind(Include = "Id,Code,Name,IsActive,Type,ShowInRegister")] AccountChart accountChart)
        {
            AccountChart accountChartDb = db.AccountCharts.Find(accountChart.Id);

            accountChartDb.Code           = accountChart.Code;
            accountChartDb.Name           = accountChart.Name;
            accountChartDb.Type           = accountChart.Type;
            accountChartDb.ShowInRegister = accountChart.ShowInRegister;
            accountChartDb.DateLastEdited = DateTime.Now;
            accountChartDb.EditedBy       = new Guid(Operator().Id);

            if (ModelState.IsValid)
            {
                db.Entry(accountChartDb).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(accountChartDb));
        }
Exemple #9
0
        public InventoryMovementAddViewModel AddInventoryMovement(InventoryMovementAddViewModel model)
        {
            if (model.Journal == null)
            {
                this._closedMonthsService.ValidateIfMonthIsClosed(model.Date.Value);

                DateTime CurrentDate = DateTime.Now;
                var      entity      = model.ToEntity();

                foreach (var item in entity.InventoryMovementCostCenter)
                {
                    item.CreationDate = CurrentDate;
                }

                var movementTypeList = this._inventoryMovementTypeRepository.Get(null).ToList();

                foreach (var item in entity.InventoryProductHistorys)
                {
                    item.CreationDate = CurrentDate;
                    item.InventoryId  = model.InventoryId;

                    var movementType = movementTypeList.FirstOrDefault(x => x.Id == model.InventoryMovementTypeId);
                    if (movementType.Type == InventoryMovementTypeEnum.GiftsIn ||
                        movementType.Type == InventoryMovementTypeEnum.InventoryIn ||
                        movementType.Type == InventoryMovementTypeEnum.PositiveInventoryDifferences)
                    {
                        var product = new Product
                        {
                            BrandId           = item.BrandId,
                            InventoryId       = item.InventoryId,
                            MeasurementUnitId = item.MeasurementUnitId,
                            NetValue          = item.NetValue,
                            Price             = item.Price,
                            Quantity          = item.Quantity
                        };
                        this._ProductsRepository.Add(product);
                    }
                    else if (movementType.Type == InventoryMovementTypeEnum.GiftsOut ||
                             movementType.Type == InventoryMovementTypeEnum.InventoryOut ||
                             movementType.Type == InventoryMovementTypeEnum.NegativeInventoryDifferences ||
                             movementType.Type == InventoryMovementTypeEnum.Consists)
                    {
                    }
                    else if (movementType.Type == InventoryMovementTypeEnum.Reservation)
                    {
                        var existProduct = this._ProductsRepository.Get(null).Where(x =>
                                                                                    x.BrandId == item.BrandId && x.MeasurementUnitId == item.MeasurementUnitId);

                        if (existProduct.Count() > 0)
                        {
                        }
                        else
                        {
                            var product = new Product
                            {
                                BrandId           = item.BrandId,
                                InventoryId       = item.InventoryId,
                                MeasurementUnitId = item.MeasurementUnitId,
                                NetValue          = item.NetValue,
                                Price             = item.Price,
                                Quantity          = item.Quantity,
                                LockedCount       = item.Quantity
                            };
                            this._ProductsRepository.Add(product);
                        }
                    }
                    else if (movementType.Type == InventoryMovementTypeEnum.ReservationRebate)
                    {
                    }
                }


                //foreach (var item in model.Products)
                //{
                //   var productEntity = item.ToEntity();
                //   productEntity.InventoryId = model.InventoryId;
                //   this._ProductsRepository.Add(productEntity);
                //}


                #region translation
                entity.Description  = "";
                entity.CreationDate = CurrentDate;
                entity.Code         = model.Code;
                entity.Date         = model.Date;
                entity.Language     = Language.None;

                InventoryMovement InventoryMovementAr = new InventoryMovement
                {
                    Description  = model.DescriptionAr,
                    Language     = Language.Arabic,
                    CreationDate = CurrentDate
                };

                InventoryMovement InventoryMovementEn = new InventoryMovement
                {
                    Description  = model.DescriptionEn,
                    Language     = Language.English,
                    CreationDate = CurrentDate
                };

                entity.ChildTranslatedInventoryMovements.Add(InventoryMovementAr);
                entity.ChildTranslatedInventoryMovements.Add(InventoryMovementEn);
                #endregion


                entity = this._InventoryMovementsRepository.Add(entity);

                #region Commit Changes
                this._unitOfWork.Commit();
                #endregion

                #region Generate New Code
                try
                {
                    ConditionFilter <InventoryMovement, long> condition = new ConditionFilter <InventoryMovement, long>
                    {
                        Query = x =>
                                x.ParentKeyInventoryMovement == null &&
                                string.IsNullOrEmpty(x.Code) == false
                        ,
                        Order = Order.Descending
                    };

                    var  z          = this._InventoryMovementsRepository.Get(condition);
                    var  lastEntity = z.FirstOrDefault();
                    long newCode    = 1;

                    if (lastEntity != null)
                    {
                        try
                        {
                            newCode = long.Parse(lastEntity.Code) + 1;
                        }
                        catch
                        {
                            newCode = entity.Id;
                        }
                    }
                    entity.Code = newCode.ToString();
                }
                catch
                {
                    entity.Code = entity.Id.ToString();
                }

                entity = this._InventoryMovementsRepository.Update(entity);

                this._unitOfWork.Commit();
                #endregion

                model.Id   = entity.Id;
                model.Code = entity.Code;
                //model = entity.ToModel();
                if (movementTypeList.FirstOrDefault(x => x.Id == model.InventoryMovementTypeId).Type == InventoryMovementTypeEnum.InventoryOut)
                {
                    model.Journal = this._journalPostingsService.Post(model.Id, MovementType.StoreMovement);

                    model.Journal.Date = model.Date.Value;

                    foreach (var Journal in model.Journal.journalDetails)
                    {
                        AccountChart accountChart = this._accountChartsRepository.Get().FirstOrDefault(x => x.Id == Journal.AccountId);
                        if (accountChart != null)
                        {
                            Journal.AccountFullCode = accountChart.FullCode;
                        }
                    }
                    model.Journal.DescriptionAr = model.DescriptionAr;
                    model.Journal.DescriptionEn = model.DescriptionEn;
                }
            }
            else if (model.Journal.PostingStatus == PostingStatus.Approved)
            {
                model.Journal.PostingStatus = PostingStatus.NeedAprove;
                Journal journal = model.Journal.ToEntity();
                journal = this._journalsRepository.Add(journal);

                Journal journalAr = new Journal
                {
                    Description      = model.Journal.DescriptionAr,
                    Language         = Language.Arabic,
                    ParentKeyJournal = journal
                };
                journalAr = this._journalsRepository.Add(journalAr);
                journal.ChildTranslatedJournals.Add(journalAr);

                Journal journalEn = new Journal
                {
                    Description      = model.Journal.DescriptionEn,
                    Language         = Language.English,
                    ParentKeyJournal = journal
                };
                journalEn = this._journalsRepository.Add(journalEn);
                journal.ChildTranslatedJournals.Add(journalEn);
                var entity = this._InventoryMovementsRepository.Get(model.Id);
                entity.IsPosted       = false;
                entity.PostingDate    = DateTime.Now;
                entity.PostedByUserId = this._currentUserService.CurrentUserId;
                entity = this._InventoryMovementsRepository.Update(entity);
                this._unitOfWork.Commit();
            }
            else if (model.Journal.PostingStatus == PostingStatus.Rejected)
            {
            }
            return(model);
        }
        public GenericCollectionViewModel <ListAccountChartDocumentLightViewModel> GetByFilter(AccountChartDocumentFilterViewModel model)
        {
            var lang = this._languageService.CurrentLanguage;
            ConditionFilter <AccountChartDocument, long> condition = new ConditionFilter <AccountChartDocument, long>()
            {
                Order = Order.Descending
            };

            if (model.Sort?.Count > 0)
            {
                if (model.Sort[0].Dir != "desc")
                {
                    condition.Order = Order.Ascending;
                }
            }


            // The IQueryable data to query.
            IQueryable <AccountChartDocument> queryableData = this._accountDocumentRepository.Get(condition);

            //queryableData = queryableData.Where(x => x.Language == lang && x.ParentKeyBank != null);

            if (model.AccountChartId.HasValue)
            {
                queryableData = queryableData.Where(x => x.AccountChartId == model.AccountChartId.Value);
            }

            //if (string.IsNullOrEmpty(model.Name) == false)
            //    queryableData = queryableData.Where(x => x.Name.Contains(model.Name));

            //if (model.OpeningCreditFrom.HasValue)
            //    queryableData = queryableData.Where(x => x.ParentKeyBank.OpeningCredit >= model.OpeningCreditFrom);

            //if (model.OpeningCreditTo.HasValue)
            //    queryableData = queryableData.Where(x => x.ParentKeyBank.OpeningCredit <= model.OpeningCreditTo);

            //if (model.DateFrom.HasValue)
            //    queryableData = queryableData.Where(x => x.ParentKeyBank.Date >= model.DateFrom);

            //if (model.DateTo.HasValue)
            //    queryableData = queryableData.Where(x => x.ParentKeyBank.Date <= model.DateTo);


            var entityCollection = queryableData.ToList();
            var accountIds       = entityCollection.Select(x => x.AccountChartId).Distinct();
            var dtoCollection    = new List <ListAccountChartDocumentLightViewModel>(); //entityCollection.Select(entity => entity.ToListModel()).ToList();

            foreach (var item in accountIds)
            {
                var ViewModel = entityCollection.Select(x => x.ToListModel()).FirstOrDefault(x => x.AccountChartId == item); //dtoCollection.Find(x => x.AccountId == item);

                AccountChart accountChart = this._accountChartsRepository.Get().FirstOrDefault(x => x.Id == item);

                ViewModel.AccountChartName = $"{accountChart.ParentAccountChart.FullCode}-{accountChart.ChildTranslatedAccountCharts.FirstOrDefault(x => x.Language == lang).Name}";

                dtoCollection.Add(ViewModel);


                //if (item.ParentKeyBank != null)
                //{
                //    ViewModel.BankName = item.ParentKeyBank.ChildTranslatedBanks.First(x => x.Language == lang).Name;
                //}
            }

            var total = dtoCollection.Count();

            dtoCollection = dtoCollection.Skip(model.PageIndex * model.PageSize).Take(model.PageSize).ToList();
            var result = new GenericCollectionViewModel <ListAccountChartDocumentLightViewModel>
            {
                Collection = dtoCollection,
                TotalCount = total,
                PageIndex  = model.PageIndex,
                PageSize   = model.PageSize
            };

            return(result);
        }
Exemple #11
0
        public BalanceSheetReportViewModel GetOpeningBalance(BalanceSheetReportViewModel source, long accountChartId, DateTime?dateFrom, DateTime?dateTo, AccountChart accountChart = null)
        {
            if (accountChart == null)
            {
                accountChart = this._AccountChartsRepository.Get(accountChartId);
            }

            //DateTime? dateBefore = dateFrom.Value.Subtract(new TimeSpan(1, 0, 0, 0));

            if (accountChart.IsDebt.HasValue &&
                accountChart.OpeningCredit.HasValue &&
                accountChart.CreationDate <= dateTo)
            {
                if (dateFrom.HasValue && accountChart.CreationDate < dateFrom)
                {
                    source.OpeningCredit += (accountChart.IsDebt.Value == false) ? accountChart.OpeningCredit : 0;
                    source.OpeningDebit  += (accountChart.IsDebt.Value == true) ? accountChart.OpeningCredit : 0;
                }
                else
                {
                    source.CreditorValue += (accountChart.IsDebt.Value == false) ? accountChart.OpeningCredit : 0;
                    source.DebtorValue   += (accountChart.IsDebt.Value == true) ? accountChart.OpeningCredit : 0;
                }
            }

            if (accountChart.AccountTypeId == (long)AccountTypeEnum.Sub)
            {
                var transCollection = this._TransactionsRepository.Get(null).Where(x =>
                                                                                   x.Journal.PostingStatus == PostingStatus.Approved &&
                                                                                   x.AccountChartId == accountChartId &&
                                                                                   x.CreationDate <= dateTo
                                                                                   //x.Journal.Date <= dateTo
                                                                                   );

                if (transCollection.Count() > 0)
                {
                    foreach (var trans in transCollection)
                    {
                        if (dateFrom.HasValue && trans.CreationDate < dateFrom)
                        {
                            if (trans.IsCreditor == true)
                            {
                                source.OpeningCredit += trans.Amount;
                            }
                            else
                            {
                                source.OpeningDebit += trans.Amount;
                            }
                        }
                        else
                        {
                            if (trans.IsCreditor == true)
                            {
                                source.CreditorValue += trans.Amount;
                            }
                            else
                            {
                                source.DebtorValue += trans.Amount;
                            }
                        }
                    }
                }
            }

            if (accountChart.ChildAccountCharts.Count > 0)
            {
                foreach (var item in accountChart.ChildAccountCharts)
                {
                    source = this.GetOpeningBalance(source, item.Id, dateFrom, dateTo);
                }
            }

            return(source);
        }
        public IList <AccountChart> UpdateCurrentValueOfAccountChartTreeByJournal(long journalId, List <Transaction> transactionList = null)
        {
            List <AccountChart> list = new List <AccountChart>();

            if (transactionList != null && transactionList.Count > 0)
            {
                foreach (var trans in transactionList)
                {
                    if (trans.AccountChartId.HasValue == true)
                    {
                        AccountChart account = list.FirstOrDefault(x => x.Id == trans.AccountChartId.Value);
                        if (account == null)
                        {
                            account = this._accountChartsRepository.Get(trans.AccountChartId.Value);
                        }

                        if (account != null)
                        {
                            if (trans.IsCreditor)
                            {
                                if (account.CurrentCreditBalance.HasValue == false)
                                {
                                    account.CurrentCreditBalance = trans.Amount;
                                }
                                else
                                {
                                    account.CurrentCreditBalance += trans.Amount;
                                }
                            }
                            else
                            {
                                if (account.CurrentDebitBalance.HasValue == false)
                                {
                                    account.CurrentDebitBalance = trans.Amount;
                                }
                                else
                                {
                                    account.CurrentDebitBalance += trans.Amount;
                                }
                            }

                            this._accountChartsRepository.Update(account);
                            list.Add(account);

                            list.AddRange(this.UpdateCurrentValueOfParentAccountChartTree(
                                              account.ParentAccountChartId,
                                              trans.Amount,
                                              trans.IsCreditor
                                              ));
                        }
                    }
                }
            }
            else
            {
                var transCollection = this._transactionsRepository.Get(null).Where(x => x.JournalId == journalId);

                if (transCollection.Count() > 0)
                {
                    foreach (var trans in transCollection)
                    {
                        if (trans.AccountChartId.HasValue == true)
                        {
                            //var account = this._accountChartsRepository.Get(trans.AccountChartId.Value);
                            AccountChart account = list.FirstOrDefault(x => x.Id == trans.AccountChartId.Value);
                            if (account == null)
                            {
                                account = this._accountChartsRepository.Get(trans.AccountChartId.Value);
                            }

                            if (account != null)
                            {
                                if (trans.IsCreditor)
                                {
                                    if (account.CurrentCreditBalance.HasValue == false)
                                    {
                                        account.CurrentCreditBalance = trans.Amount;
                                    }
                                    else
                                    {
                                        account.CurrentCreditBalance += trans.Amount;
                                    }
                                }
                                else
                                {
                                    if (account.CurrentDebitBalance.HasValue == false)
                                    {
                                        account.CurrentDebitBalance = trans.Amount;
                                    }
                                    else
                                    {
                                        account.CurrentDebitBalance += trans.Amount;
                                    }
                                }

                                this._accountChartsRepository.Update(account);
                                list.Add(account);

                                list.AddRange(this.UpdateCurrentValueOfParentAccountChartTree(
                                                  account.ParentAccountChartId,
                                                  trans.Amount,
                                                  trans.IsCreditor
                                                  ));
                            }
                        }
                    }
                }
            }

            return(list);
        }