예제 #1
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(LiquidationViewModel model)
        {
            var entity = model.ToEntity();

            this._LiquidationsRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
예제 #2
0
        /// <summary>
        /// Throw an exception if name is exist.
        /// </summary>
        /// <param name="model">Liquidation view model</param>
        public void ThrowExceptionIfExist(LiquidationViewModel model)
        {
            ConditionFilter <Liquidation, long> condition = new ConditionFilter <Liquidation, long>
            {
                Query = (entity =>
                         entity.Id != model.Id)
            };
            var existEntity = this._LiquidationsRepository.Get(condition).FirstOrDefault();

            if (existEntity != null)
            {
                throw new ItemAlreadyExistException();
            }
        }
예제 #3
0
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public LiquidationViewModel Update(LiquidationViewModel model)
        {
            //this.ThrowExceptionIfExist(model);

            var entity = this._LiquidationsRepository.Get(model.Id);

            entity = this._LiquidationsRepository.Update(entity);

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

            model = entity.ToModel();
            return(model);
        }
예제 #4
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public LiquidationViewModel Add(LiquidationViewModel model)
        {
            //this.ThrowExceptionIfExist(model);

            if (model.Journal == null)
            {
                var entity = model.ToEntity();

                foreach (var item in entity.LiquidationDetails)
                {
                    item.CreationDate = DateTime.Now;
                    var advance = this._advancesRepository.Get().FirstOrDefault(x => x.Id == item.AdvanceId);
                    if (advance != null)
                    {
                        advance.CurrentAmount -= item.Amount;
                        if (advance.CurrentAmount <= 0)
                        {
                            advance.IsClosed = true;
                        }
                        this._advancesRepository.Update(advance);
                    }
                }

                entity = this._LiquidationsRepository.Add(entity);


                #region Commit Changes
                this._unitOfWork.Commit();
                #endregion
                model.Id = entity.Id;

                //this._journalPostingsService.TryPostAutomatic(entity.Id, MovementType.PaymentMovement);
                model.Journal = this._journalPostingsService.Post(model.Id, MovementType.Liquidation);

                if (model.PaymentMovements != null)
                {
                    foreach (var paymentMovement in model.PaymentMovements)
                    {
                        var journals = this._paymentMovmentsService.Add(paymentMovement).Journal.journalDetails.Where(x => x.IsCreditor == false);

                        foreach (var journal in journals)
                        {
                            model.Journal.journalDetails.Add(journal);
                        }
                    }
                }

                model.Journal.Date = entity.CreationDate;

                foreach (var Journal in model.Journal.journalDetails)
                {
                    Journal.AccountFullCode = this._accountChartsRepository.Get().FirstOrDefault(x => x.Id == Journal.AccountId)?.FullCode;
                }
            }
            else if (model.Journal.PostingStatus == MersalAccountingService.Common.Enums.PostingStatus.Approved)
            {
                this._journalsService.AddJournal(model.Journal, PostingStatus.NeedAprove);
                var entity = this._LiquidationsRepository.Get(model.Id);
                if (entity != null)
                {
                    entity.IsPosted       = false;
                    entity.PostingDate    = DateTime.Now;
                    entity.PostedByUserId = this._currentUserService.CurrentUserId;
                    entity = this._LiquidationsRepository.Update(entity);
                }

                this._unitOfWork.Commit();
            }
            else if (model.Journal.PostingStatus == MersalAccountingService.Common.Enums.PostingStatus.Rejected)
            {
            }

            return(model);
        }