示例#1
0
        public async Task SafeBankMovement(BankMovementInputModel input)
        {
            var accType = this.accountingTypes.All().FirstOrDefault(t => t.Id == input.AccTypeId);

            var movement = new BankMovement
            {
                Date                = input.DateIn,
                Reason              = input.ReasonIn,
                OppositeSideName    = input.OSNameIn,
                OppositeSideAccount = input.OSAccIn,
                Amount              = decimal.Parse(input.AmountIn, NumberStyles.Number, CultureInfo.InvariantCulture),
                AccountingType      = accType,
            };

            if (accType.Code == CreditAccountingTypes.ПН503.ToString() && input.InvoiceIds.Any())
            {
                var company = this.companies.All().FirstOrDefault(c => c.Id == input.OSIdIn);
                if (company != null && !company.BankDetails.Any(bd => bd.BankIban.Contains(input.OSAccIn)))
                {
                    var bankDetails = new BankDetails
                    {
                        BankIban = input.OSAccIn,
                        AdminId  = company.AdminId,
                    };
                    company.BankDetails.Add(bankDetails);
                }

                if (accType.MovementType == "Credit")
                {
                    foreach (var id in input.InvoiceIds)
                    {
                        var invoice = this.invoiceOuts.All().FirstOrDefault(i => i.Id == id);
                        if (invoice != null)
                        {
                            await this.invoicesService.UpdateInvoiceOutStatusAsync(invoice.Id, InvoiceStatusNames.Paid.ToString());

                            invoice.BankMovementId = movement.Id;
                        }
                    }
                }
                else
                {
                    foreach (var id in input.InvoiceIds)
                    {
                        var invoice = this.invoiceIns.All().FirstOrDefault(i => i.Id == id);
                        if (invoice != null)
                        {
                            await this.invoicesService.UpdateInvoiceInStatusAsync(invoice.Id, InvoiceStatusNames.Paid.ToString());

                            invoice.BankMovementId = movement.Id;
                        }
                    }
                }
            }

            await this.bankMovements.AddAsync(movement);

            await this.bankMovements.SaveChangesAsync();
        }
示例#2
0
    public static GenericMovement MovementFromStruct(ManeuverHolder movementStruct)
    {
        GenericMovement result = null;

        if (movementStruct.Bearing == ManeuverBearing.Straight)
        {
            result = new StraightMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.KoiogranTurn)
        {
            result = new KoiogranTurnMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.Turn)
        {
            result = new TurnMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.Bank)
        {
            result = new BankMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.SegnorsLoop)
        {
            result = new SegnorsLoopMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.SegnorsLoopUsingTurnTemplate)
        {
            result = new SegnorsLoopUsingTurnTemplateMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.TallonRoll)
        {
            result = new TallonRollMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.Stationary)
        {
            result = new StationaryMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.SideslipBank)
        {
            result = new SideslipBankMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.SideslipTurn)
        {
            result = new SideslipTurnMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
        }
        else if (movementStruct.Bearing == ManeuverBearing.ReverseStraight)
        {
            if (movementStruct.Direction == ManeuverDirection.Forward)
            {
                result = new ReverseStraightMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
            }
            else
            {
                result = new ReverseBankMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity);
            }
        }

        return(result);
    }
示例#3
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public BankMovementViewModel Add(BankMovementViewModel model)
        {
            if (model.Journal == null)
            {
                this.ThrowExceptionIfExist(model);
                this._closedMonthsService.ValidateIfMonthIsClosed(model.Date.Value);

                var entity = model.ToEntity();

                if (entity.JournalTypeId == (long)JournalTypeEnum.PaymentPapers)
                {
                    IList <long> list = new List <long>();
                    foreach (var item in model.Cheques)
                    {
                        ClosedCheque closedCheque = new ClosedCheque
                        {
                            BankMovement = entity,
                            DonationId   = item.Id
                        };
                        this._closedChequeRepository.Add(closedCheque);
                        var donationEntity = this._donationsRepository.Get(item.Id);

                        //TODO:
                        //if (donationEntity.IsPosted)
                        //{
                        donationEntity.Exchangeable = true;
                        list.Add(entity.Id);
                        //}



                        donationEntity = this._donationsRepository.Update(donationEntity);
                    }

                    this._journalPostingsService.PostChecksUnderCollectionOfReceiptsMovement(list);
                }

                entity.CreatedByUserId = this._currentUserService.CurrentUserId;
                DateTime now = DateTime.Now;
                var      ar  = new BankMovement
                {
                    Description  = model.DescriptionAr,
                    Language     = Language.Arabic,
                    CreationDate = now
                };
                var en = new BankMovement
                {
                    Description  = model.DescriptionEn,
                    Language     = Language.English,
                    CreationDate = now
                };

                entity.ChildTranslatedBankMovements.Add(ar);
                entity.ChildTranslatedBankMovements.Add(en);



                entity = this._BankMovementsRepository.Add(entity);



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

                //entity.Code = entity.Id.ToString();
                //#region Commit Changes
                //this._unitOfWork.Commit();
                //#endregion

                //this._journalPostingsService.TryPostAutomatic(entity.Id, MovementType.BankMovement);
                if (entity.JournalTypeId == (long)JournalTypeEnum.DirectDonations &&
                    model.CostCenters != null &&
                    model.CostCenters.Any())
                {
                    foreach (var item in model.CostCenters)
                    {
                        var bankMovementCosCenter = new BankMovementCostCenters()
                        {
                            BankMovementId = entity.Id,
                            CostCenterId   = item.Id,
                            Amount         = (double)item.AssignValue
                        };

                        _bankMovementCostCentersRepository.Add(bankMovementCosCenter);
                        #region Commit Changes
                        this._unitOfWork.Commit();
                        #endregion
                    }
                }

                model         = entity.ToModel();
                model.Journal = this._journalPostingsService.Post(model.Id, MovementType.BankMovement);

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

                foreach (var Journal in model.Journal.journalDetails)
                {
                    Journal.AccountFullCode = this._accountChartsRepository.Get().FirstOrDefault(x => x.Id == Journal.AccountId).FullCode;
                }
                //model.Journal.DescriptionAr = model.DescriptionAr;
                //model.Journal.DescriptionEn = model.DescriptionEn;
            }
            else if (model.Journal.PostingStatus == PostingStatus.Approved)
            {
                this._journalsService.AddJournal(model.Journal, PostingStatus.NeedAprove);

                var entity = this._BankMovementsRepository.Get(model.Id);
                entity.IsPosted       = false;
                entity.PostingDate    = DateTime.Now;
                entity.PostedByUserId = this._currentUserService.CurrentUserId;
                entity = this._BankMovementsRepository.Update(entity);
                this._unitOfWork.Commit();
            }
            else if (model.Journal.PostingStatus == PostingStatus.Rejected)
            {
            }

            return(model);
        }