public FuelReportApplicationService(
     IUnitOfWorkScope unitOfWorkScope,
     ICurrencyDomainService currencyDomainService,
     IVoyageDomainService voyageDomainService,
     IFuelReportDomainService fuelReportDomainService,
     IApproveFlowApplicationService approveFlowApplicationService)
 {
     this.unitOfWorkScope = unitOfWorkScope;
     this.currencyDomainService = currencyDomainService;
     this.voyageDomainService = voyageDomainService;
     this.fuelReportDomainService = fuelReportDomainService;
     this.approveFlowApplicationService = approveFlowApplicationService;
 }
 //================================================================================
 public FuelReportFacadeService(
     IFuelReportApplicationService appService,
     IFuelReportFuelReportDtoMapper fuelReportMapper,
     IFuelReportDetailToFuelReportDetailDtoMapper fuelReportDetailToFuelReportDetailDtoMapper,
     ICurrencyDomainService currencyDomainService,
     ICurrencyToCurrencyDtoMapper currencyToCurrencyDtoMapper,
     IFuelReportDomainService fuelReportDomainService,
     IInventoryOperationDomainService inventoryOperationDomainService,
     IInventoryOperationToInventoryOperationDtoMapper inventoryOperationMapper)
 {
     this.appService = appService;
     this.fuelReportMapper = fuelReportMapper;
     this.fuelReportDetailToFuelReportDetailDtoMapper = fuelReportDetailToFuelReportDetailDtoMapper;
     this.currencyToCurrencyDtoMapper = currencyToCurrencyDtoMapper;
     this.fuelReportDomainService = fuelReportDomainService;
     this.inventoryOperationDomainService = inventoryOperationDomainService;
     this.inventoryOperationMapper = inventoryOperationMapper;
     this.currencyDomainService = currencyDomainService;
 }
 public ApprovableFuelReportDomainService(
     IVoyageDomainService voyageDomainService,
     IFuelReportDomainService fuelReportDomainService,
     IInventoryOperationDomainService inventoryOperationDomainService,
     IGoodDomainService goodDomainService,
     IOrderDomainService orderDomainService,
     ICurrencyDomainService currencyDomainService,
     IBalanceDomainService balanceDomainService,
     IInventoryManagementDomainService inventoryManagementDomainService,
     IInventoryOperationNotifier inventoryOperationNotifier)
 {
     this.voyageDomainService = voyageDomainService;
     this.fuelReportDomainService = fuelReportDomainService;
     this.inventoryOperationDomainService = inventoryOperationDomainService;
     this.goodDomainService = goodDomainService;
     this.orderDomainService = orderDomainService;
     this.inventoryOperationNotifier = inventoryOperationNotifier;
     this.currencyDomainService = currencyDomainService;
     this.balanceDomainService = balanceDomainService;
     this.inventoryManagementDomainService = inventoryManagementDomainService;
 }
Ejemplo n.º 4
0
 public VoyageFacadeService(
     IVoyageDomainService voyageDomainService,
     IVoyageToVoyageDtoMapper voyageDtoMapper,
     IFuelReportDomainService fuelReportDomainService,
     IFuelReportFuelReportDtoMapper fuelReportDtoMapper,
     IInventoryOperationDomainService inventoryOperationDomainService,
     IInventoryOperationToInventoryOperationDtoMapper inventoryOperationDtoMapper,
     IVoyageLogDomainService voyageLogDomainService,
     IVoyageLogToVoyageLogDtoMapper voyageLogDtoMapper,
     IGoodToGoodDtoMapper goodDtoMapper)
 {
     this.voyageDomainService = voyageDomainService;
     this.voyageDtoMapper = voyageDtoMapper;
     //this.fuelReportDomainService = fuelReportDomainService;
     this.fuelReportDtoMapper = fuelReportDtoMapper;
     this.inventoryOperationDomainService = inventoryOperationDomainService;
     this.inventoryOperationDtoMapper = inventoryOperationDtoMapper;/**/
     this.voyageLogDtoMapper = voyageLogDtoMapper;
     this.goodDtoMapper = goodDtoMapper;
     this.voyageLogDomainService = voyageLogDomainService;
 }
Ejemplo n.º 5
0
        public OffhireDomainService(
            IOffhireRepository offhireRepository,
            IRepository<OffhireDetail> offhireDetailRepository,
            ICharteringDomainService charteringDomainService,
            IInventoryManagementDomainService inventoryManagementDomainService,
            IFuelReportDomainService fuelReportDomainService,
            IVesselInCompanyDomainService vesselDomainService, IVoyageDomainService voyageDomainService,
            ICurrencyDomainService currencyDomainService)
        {
            this.offhireRepository = offhireRepository;
            this.offhireDetailRepository = offhireDetailRepository;
            this.charteringDomainService = charteringDomainService;
            this.inventoryManagementDomainService = inventoryManagementDomainService;
            this.fuelReportDomainService = fuelReportDomainService;
            this.vesselDomainService = vesselDomainService;
            this.voyageDomainService = voyageDomainService;
            this.currencyDomainService = currencyDomainService;

            this.isOffhireOpen = new IsOffhireOpen();
            this.isOffhireSubmitted = new IsOffhireSubmitted();
            this.isOffhireSubmitRejected = new IsOffhireSubmitRejected();
            this.isOffhireCancelled = new IsOffhireCancelled();
        }
Ejemplo n.º 6
0
        //===================================================================================
        private void validateSubmittingState(IVoyageDomainService voyageDomainService,
            IFuelReportDomainService fuelReportDomainService, IInventoryOperationDomainService inventoryOperationDomainService, IGoodDomainService goodDomainService,
            IOrderDomainService orderDomainService, ICurrencyDomainService currencyDomainService,
            IInventoryManagementDomainService inventoryManagementDomainService)
        {
            validateToBeOpenOrSubmitRejected();

            validateVoyageId(this.VoyageId, voyageDomainService);

            //BR_FR37
            validatePreviousEndedVoyagesToBeIssued(
                voyageDomainService,
                fuelReportDomainService,
                inventoryOperationDomainService);

            //BR_FR38
            validatePreviousFuelReportsToBeFinalApproved(fuelReportDomainService);

            //BR_FR39
            validateFuelReportsOfPreviousDayForMandatoryType(
                fuelReportDomainService,
                goodDomainService);

            var isTheFirstReport = isCurrentFuelReportTheFirstOne(fuelReportDomainService);

            FuelReport previousFuelReport = getYesterdayLastFuelReport(fuelReportDomainService);

            validateFuelReportOfTheDayBefore(previousFuelReport, isTheFirstReport);

            foreach (var detailItem in this.FuelReportDetails)
            {
                FuelReportDetail fuelReportDetailOfYesterdayForRelevantGood =
                    getGoodRelevantFuelReportDetailOfYesterday(
                        detailItem.GoodId,
                        isTheFirstReport,
                        previousFuelReport);

                //All Edit Rules must be checked for details.
                detailItem.ValidateCurrentValues(
                    fuelReportDetailOfYesterdayForRelevantGood,
                    isTheFirstReport,
                    currencyDomainService);

                detailItem.ValidateTransferReferences(orderDomainService, inventoryManagementDomainService);
                detailItem.ValidateReceiveReferences(orderDomainService);
                detailItem.ValidateCorrectionReferences(isTheFirstReport, voyageDomainService, fuelReportDomainService);
            }
        }
Ejemplo n.º 7
0
        //===================================================================================
        /// <summary>
        /// BR_FR38
        /// </summary>
        private void validatePreviousFuelReportsToBeFinalApproved(IFuelReportDomainService fuelReportDomainService)
        {
            var previousNotFinalApprovedReports = fuelReportDomainService.GetPreviousNotFinalApprovedReports(this);

            if (previousNotFinalApprovedReports.Count() != 0)
                throw new BusinessRuleException("BR_FR38", "There are some not final approved Fuel Reports before current FuelReport.");
        }
Ejemplo n.º 8
0
        //===================================================================================
        /// <summary>
        /// BR_FR37
        /// </summary>
        private void validatePreviousEndedVoyagesToBeIssued(
            IVoyageDomainService voyageDomainService,
            IFuelReportDomainService fuelReportDomainService,
            IInventoryOperationDomainService inventoryOperationDomainService)
        {
            var notIssuedEOVFuelReportsOfPreviousVoyages = fuelReportDomainService.GetNotIssuedEOVFuelReportsOfPreviousVoyages(this);

            if (notIssuedEOVFuelReportsOfPreviousVoyages.Count != 0)
                throw new BusinessRuleException("BR_FR37", "There are some ended voyages before current Fuel Report with no issue for End Of Voyage Fuel Report.");
        }
Ejemplo n.º 9
0
        //===================================================================================
        /// <summary>
        /// BR_FR39
        /// </summary>
        private void validateFuelReportsOfPreviousDayForMandatoryType(
            IFuelReportDomainService fuelReportDomainService,
            IGoodDomainService goodDomainService)
        {
            return;
            var fuelReportsOfYesterday = fuelReportDomainService.GetFuelReportsFromYesterday(this);

            foreach (var yesterdayFuelReport in fuelReportsOfYesterday)
            {
                var mandatoryGoods = goodDomainService.GetMandatoryVesselGoods(this.VesselInCompanyId, yesterdayFuelReport.EventDate);

                //Validate the availability of all mandatory goods for previous day fuel report.
                if (mandatoryGoods.Count(
                    mg =>
                        !yesterdayFuelReport.FuelReportDetails.
                            Select(frd => frd.Good.Id).Contains(mg.Id)) > 0                    )
                    throw new BusinessRuleException("BR_FR39", "Some mandatory fuels not found in fuel report of yesterday.");
            }
        }
Ejemplo n.º 10
0
        //===================================================================================
        private bool isCurrentFuelReportTheFirstOne(IFuelReportDomainService fuelReportDomainService)
        {
            var isTheFirstOne = false;

            var oneDayBefore = this.EventDate.AddDays(-1).Date;

            long fuelReportsCountBeforeCurrentDay =
                fuelReportDomainService
                    .GetVesselFuelReports(this.VesselInCompany, null, oneDayBefore, true)
                        .Count();

            isTheFirstOne = (fuelReportsCountBeforeCurrentDay == 0);

            return isTheFirstOne;
        }
Ejemplo n.º 11
0
        //===================================================================================
        private void validatePositiveCorrectionReferenceToBeTheLastIssuedVoyage(bool isTheFirstFuelReport, IFuelReportDomainService fuelReportDomainService)
        {
            if (this.Correction.HasValue &&
                !isTheFirstFuelReport &&
                !this.CorrectionReference.IsEmpty() &&
                this.CorrectionType.HasValue &&
                this.CorrectionType.Value == CorrectionTypes.Plus)
            {
                var lastIssuedEOVFuelReportOfPreviousVoyages = fuelReportDomainService.GetLastIssuedEOVFuelReportOfPreviousVoyages(this.FuelReport);

                if (lastIssuedEOVFuelReportOfPreviousVoyages == null && !isTheFirstFuelReport)
                    throw new ObjectNotFound("LastIssuedEndOfVoyageFuelReport");

                Voyage lastIssuedVoyage = null;

                if (lastIssuedEOVFuelReportOfPreviousVoyages != null)
                    lastIssuedVoyage = lastIssuedEOVFuelReportOfPreviousVoyages.Voyage;

                if (lastIssuedVoyage == null || this.CorrectionReference.ReferenceType != ReferenceType.Voyage ||
                    this.CorrectionReference.ReferenceId != lastIssuedVoyage.Id)
                    throw new BusinessRuleException("", string.Format("Correction Reference Is not The Last Issued Voyage for '{0}'.", this.Good.Code));
                //throw new BusinessRuleException("", "سفر مرجع برای مقداراصلاحی آخرین سفر دارای حواله مصرف تائید نهایی شده باشد");
            }
        }
Ejemplo n.º 12
0
        //===================================================================================
        public FuelReportDetail UpdateFuelReportDetail(
            long fuelReportDetailId,
            double rob,
            double consumption,
            double? receive,
            ReceiveTypes? receiveType,
            double? transfer,
            TransferTypes? transferType,
            double? correction,
            CorrectionTypes? correctionType,
            decimal? correctionPrice,
            long? currencyId,
            Reference transferReference,
            Reference receiveReference,
            Reference correctionReference,
            IFuelReportDomainService fuelReportDomainService,
            ICurrencyDomainService currencyDomainService)
        {
            this.CheckToBeOperational();

            //BR_FR1
            validateToBeOpenOrSubmitRejected();

            FuelReportDetail updatingFuelReportDetail = FuelReportDetails.FirstOrDefault(c => c.Id == fuelReportDetailId);

            if (updatingFuelReportDetail == null) throw new ObjectNotFound("FuelReportDetail", fuelReportDetailId);

            validatePreviousFuelReportsToBeFinalApproved(fuelReportDomainService);

            //IOrderedEnumerable<FuelReport> fuelReportsOfYesterday =
            //    fuelReportDomainService
            //        .GetYesterdayFuelReports(this)
            //            .OrderBy(fr => fr.ReportDate);//The ordering is used to find the last report in previous day.

            //FuelReport previousFuelReport = null;

            //bool isTheFirstReport = false;

            //if (fuelReportsOfYesterday.Count() == 0)
            //{
            //    //If nothing found for previous day...

            //    isTheFirstReport = isCurrentFuelReportTheFirstOne(fuelReportDomainService);
            //}
            //else
            //{
            //    //Retrieve the last Fuel Report of yesterday.
            //    previousFuelReport = fuelReportsOfYesterday.LastOrDefault();
            //}

            //FuelReportDetail fuelReportDetailOfYesterdayForRelevantGood = null;

            //if (!isTheFirstReport)
            //{
            //    //TODO: The validation of fuel types against Yesterday valid fuel types must be revised.
            //    fuelReportDetailOfYesterdayForRelevantGood =
            //        previousFuelReport.FuelReportDetails.FirstOrDefault(c => c.GoodId == updatingFuelReportDetail.GoodId);

            //    if (fuelReportDetailOfYesterdayForRelevantGood == null)
            //        //Because current Fuel Report is not the first one,
            //        //its relevant Fuel Report Detail of yesterday must be found.
            //        throw new ObjectNotFound("FuelReportDetailOfYesterdayForRelevantGood");
            //}

            bool isTheFirstReport = isCurrentFuelReportTheFirstOne(fuelReportDomainService);

            FuelReport previousFuelReport = getYesterdayLastFuelReport(fuelReportDomainService);

            validateFuelReportOfTheDayBefore(previousFuelReport, isTheFirstReport);

            FuelReportDetail fuelReportDetailOfYesterdayForRelevantGood =
                getGoodRelevantFuelReportDetailOfYesterday(
                    updatingFuelReportDetail.GoodId,
                    isTheFirstReport,
                    previousFuelReport);

            if (this.State == States.Open)
            {
                updatingFuelReportDetail.Update(rob, consumption, receive, receiveType, transfer, transferType,
                                                correction, correctionType, correctionPrice, currencyId,
                                                transferReference,
                                                receiveReference,
                                                correctionReference,
                                                fuelReportDetailOfYesterdayForRelevantGood,
                                                isTheFirstReport,
                                                currencyDomainService);
            }
            else if (this.State == States.SubmitRejected)
            {
                updatingFuelReportDetail.Update(rob, consumption, fuelReportDetailOfYesterdayForRelevantGood, isTheFirstReport, currencyDomainService);
            }
            else
            {
                throw new InvalidOperation("UpdateFuelReportDetail", "The Fuel Report is in an invalid state.");
            }

            return updatingFuelReportDetail;
        }
Ejemplo n.º 13
0
        //===================================================================================
        public void UpdateConsumption(IFuelReportDomainService fuelReportDomainService)
        {
            //validatePreviousFuelReportsToBeFinalApproved(fuelReportDomainService);

            var previousFuelReports = fuelReportDomainService.GetFuelReportsFromYesterday(this);

            var previousFuelReport = previousFuelReports.LastOrDefault();

            if (previousFuelReport != null)
            {
                foreach (var fuelReportDetail in this.FuelReportDetails)
                {
                    var relevantFeulReportDetailOfPreviousDay = previousFuelReport.FuelReportDetails.FirstOrDefault(frd => frd.GoodId == fuelReportDetail.GoodId);

                    if (relevantFeulReportDetailOfPreviousDay != null)
                    {
                        fuelReportDetail.UpdateConsumption(relevantFeulReportDetailOfPreviousDay);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        //===================================================================================
        public void Submit(
            FuelReportState entityNewState,
            IVoyageDomainService voyageDomainService,
            IFuelReportDomainService fuelReportDomainService,
            IInventoryOperationDomainService inventoryOperationDomainService,
            IGoodDomainService goodDomainService,
            IOrderDomainService orderDomainService,
            ICurrencyDomainService currencyDomainService,
            IBalanceDomainService balanceDomainService,
            IInventoryManagementDomainService inventoryManagementDomainService,
            IInventoryOperationNotifier inventoryOperationNotifier)
        {
            this.CheckToBeOperational();

            validateSubmittingState(
                    voyageDomainService,
                    fuelReportDomainService,
                    inventoryOperationDomainService,
                    goodDomainService,
                    orderDomainService,
                    currencyDomainService,
                    inventoryManagementDomainService);

            sendDataToBalancingDomainService(balanceDomainService);

            if (this.FuelReportType == FuelReportTypes.EndOfVoyage ||
                this.FuelReportType == FuelReportTypes.EndOfYear ||
                this.FuelReportType == FuelReportTypes.EndOfMonth)
            {
                var inventoryResult = inventoryOperationNotifier.NotifySubmittingFuelReportConsumption(this);

                this.ConsumptionInventoryOperations.Add(inventoryResult);
            }
            else
            {
                foreach (var fuelReportDetail in this.FuelReportDetails)
                {
                    var inventoryResult = inventoryOperationNotifier.NotifySubmittingFuelReportDetail(fuelReportDetail, fuelReportDomainService);

                    if (inventoryResult != null)
                        fuelReportDetail.InventoryOperations.AddRange(inventoryResult);
                }

            }

            setEntityState(entityNewState);
        }
Ejemplo n.º 15
0
        //===================================================================================
        private FuelReport getYesterdayLastFuelReport(IFuelReportDomainService fuelReportDomainService)
        {
            IOrderedEnumerable<FuelReport> fuelReportsOfYesterday =
                fuelReportDomainService.GetFuelReportsFromYesterday(this)
                    .OrderBy(fr => fr.EventDate);//The ordering is used to find the last report from previous day till current Report.

            return fuelReportsOfYesterday.LastOrDefault();
        }
        public List<InventoryOperation> NotifySubmittingFuelReportDetail(FuelReportDetail source, IFuelReportDomainService fuelReportDomainService)
        {
            var result = new List<InventoryOperation>();

            try
            {
                if (source.Correction.HasValue && source.CorrectionType.HasValue)
                {
                    if (source.CorrectionType.Value == CorrectionTypes.Plus)
                    {
                        if (source.CorrectionReference.IsEmpty())
                        {
                            if (source.IsCorrectionPriceEmpty())
                            {
                                var lastReceiveFuelReportDetailBefore = fuelReportDomainService.GetLastReceiveFuelReportDetailBefore(source);

                                var lastReceiveInventoryOperationId = inventoryOperationManager.GetFueReportDetailReceiveOperationReference(lastReceiveFuelReportDetailBefore).OperationId;

                                result.AddRange(this.inventoryOperationManager.ManageFuelReportDetailIncrementalCorrectionUsingReferencePricing(source, lastReceiveInventoryOperationId, "PricingByLastReceipt",
                                    //TODO: Fake ActorId
                                    1101));
                            }
                            else
                            {
                                result.AddRange(this.inventoryOperationManager.ManageFuelReportDetailIncrementalCorrectionDirectPricing(source,
                                    //TODO: Fake ActorId
                                    1101));
                            }
                        }
                        else
                        {
                            if (source.CorrectionReference.ReferenceType.Value == ReferenceType.Voyage)
                            {
                                //var eovFuelReport = fuelReportDomainService.GetVoyageValidEndOfVoyageFuelReport(source.CorrectionReference.ReferenceId.Value);

                                //var consumptionInventoryOperationId = eovFuelReport.ConsumptionInventoryOperations.Last().InventoryOperationId;

                                var consumptionInventoryOperationId = fuelReportDomainService.GetVoyageConsumptionIssueOperation(source.CorrectionReference.ReferenceId.Value).InventoryOperationId;

                                result.AddRange(this.inventoryOperationManager.ManageFuelReportDetailIncrementalCorrectionUsingReferencePricing(source, consumptionInventoryOperationId, "PricingByIssuedVoyage",
                                    //TODO: Fake ActorId
                                    1101));
                            }
                        }
                    }
                    else
                    {
                        result.AddRange(this.inventoryOperationManager.ManageFuelReportDetailDecrementalCorrection(source,
                            //TODO: Fake ActorId
                                             1101));
                    }
                }

                result.AddRange(this.inventoryOperationManager.ManageFuelReportDetail(source,
                    //TODO: Fake ActorId
                    1101));
            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }
Ejemplo n.º 17
0
        //===================================================================================
        public void ValidateCorrectionReferences(
            bool isTheFirstFuelReport,
            //IOrderDomainService orderDomainService,
            IVoyageDomainService voyageDomainService,
            IFuelReportDomainService fuelReportDomainService
            //,IInventoryOperationDomainService inventoryOperationDomainService
            )
        {
            validateEmptyCorrectionValues();

            validatePositiveCorrectionPriceAndReference();

            //validateNegativeCorrectionReferenceValue(isTheFirstFuelReport, voyageDomainService);

            validateNegativeCorrectionWithEmptyPrice();

            validatePositiveCorrectionReferenceToBeTheLastIssuedVoyage(isTheFirstFuelReport, fuelReportDomainService);
            validateNegativeCorrectionReferenceToBeTheLastIssuedVoyage(isTheFirstFuelReport, fuelReportDomainService);
        }