示例#1
0
        internal FuelReportDetail(
            long id,
            long fuelReportId,
            double rob,
            string robUOM,
            double consumption,
            double? receive,
            ReceiveTypes? receiveType,
            double? transfer,
            TransferTypes? transferType,
            double? correction,
            CorrectionTypes? correctionType,
            decimal? correctionPrice,
            string correctionPriceCurrencyISOCode,
            long? correctionPriceCurrencyId,
            long fuelTypeId,
            long measuringUnitId,
            long tankId)
            : this()
        {
            //Id = id;
            FuelReportId = fuelReportId;

            //No validation performed due to unavailability of such validation.
            Consumption = consumption;
            Correction = correction;
            CorrectionPrice = correctionPrice;
            CorrectionPriceCurrencyISOCode = correctionPriceCurrencyISOCode;
            CorrectionType = correctionType;
            Receive = receive;
            ROB = rob;
            ROBUOM = robUOM;
            Transfer = transfer;
            ReceiveType = receiveType;
            TransferType = transferType;
            CorrectionPriceCurrencyId = correctionPriceCurrencyId;
            GoodId = fuelTypeId;
            MeasuringUnitId = measuringUnitId;
            TankId = tankId;
        }
示例#2
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;
        }
示例#3
0
        public FuelReportDetail CreateFuelReportDetail(long fuelReportId,
            double rob,
            string robUOM,
            double consumption,
            double? receive,
            ReceiveTypes? receiveType,
            double? transfer,
            TransferTypes? transferType,
            double? correction,
            CorrectionTypes? correctionType,
            decimal? correctionPrice,
            string correctionPriceCurrencyISOCode,
            long? correctionPriceCurrencyId,
            long fuelTypeId,
            long measuringUnitId,
            long tankId)
        {
            var fuelReportDetail = new FuelReportDetail(
                0,
                fuelReportId,
                rob,
                robUOM,
                consumption,
                receive,
                receiveType,
                transfer,
                transferType,
                correction,
                correctionType,
                correctionPrice,
                correctionPriceCurrencyISOCode,
                correctionPriceCurrencyId,
                fuelTypeId,
                measuringUnitId,
                tankId);

            return fuelReportDetail;
        }
        //================================================================================
        public FuelReportDetail UpdateFuelReportDetail(
            long fuelReportId,
            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)
        {
            var currentFuelReport = GetById(fuelReportId);

            var result = currentFuelReport.UpdateFuelReportDetail(
                fuelReportDetailId,
                rob,
                consumption,
                receive,
                receiveType,
                transfer,
                transferType,
                correction,
                correctionType,
                correctionPrice,
                currencyId,
                transferReference,
                receiveReference,
                correctionReference,
                fuelReportDomainService,
                currencyDomainService);

            try
            {
                this.unitOfWorkScope.Commit();
            }
            catch (OptimisticConcurrencyException ex)
            {
                throw new ConcurencyException("UpdateFuelReportDetail");
            }
            //            catch (Exception ex)
            //            {
            //                throw new UnHandleException(ex);
            //            }

            return result;
        }
示例#5
0
        private void validateValues(
            double rob,
            double consumption,
            double? receive,
            ReceiveTypes? receiveType,
            double? transfer,
            TransferTypes? transferType,
            double? correction,
            CorrectionTypes? correctionType,
            decimal? correctionPrice,
            long? correctionPriceCurrencyId,
            //ReferenceType? transferReferenceType,
            //long? transferReferenceEntityId,
            //ReferenceType? receiveReferenceType,
            //long? receiveReferenceEntityId,
            //ReferenceType? correctionReferenceType,
            //long? correctionReferenceEntityId,
            Reference transferReference,
            Reference receiveReference,
            Reference correctionReference,
            FuelReportDetail relevantFuelReportDetailOfTheDayBefore,
            bool isDetailOfFirstFuelReport,
            ICurrencyDomainService currencyDomainService)
        {
            refineValues(ref rob, ref consumption, ref receive, ref receiveType, ref transfer, ref transferType, ref correction, ref correctionType, ref correctionPrice, ref correctionPriceCurrencyId, ref transferReference, ref receiveReference, ref correctionReference);

            //BR_FR3
            validateConsumptionAndROBAvailability(consumption, rob);

            //BR_FR4
            validateNotNegativeConsumptionAndROB(consumption, rob);

            //BR_FR5
            validateReceiveType(receive, receiveType);

            //BR_FR6
            validateTransferType(transfer, transferType);

            //BR_FR7
            validateCorrectionType(correction, correctionType, correctionPriceCurrencyId,
                                                         correctionPrice, currencyDomainService);

            //validatePositiveCorrectionTypeCurrencyAndPriceValues(correction, correctionType, correctionPriceCurrencyId,
            //                                             correctionPrice, currencyDomainService);

            //BR_FR8
            validateNotNegativeReceiveTransferCorrection(receive, transfer, correction);

            //BR_FR9
            //This is already implemented via BR_FR5, BR_FR6, BR_FR7.

            //BR_FR34
            validateValuesForEndOfVoyageEndOfMonthEndOfYearFuelReport(
                rob,
                consumption,
                receive,
                receiveType,
                transfer,
                transferType,
                correction,
                correctionType,
                correctionPrice,
                correctionPriceCurrencyId);

            if (relevantFuelReportDetailOfTheDayBefore == null)
            {
                if (isDetailOfFirstFuelReport)
                {
                    //NOTE: No need to validate ROB for Details of the First Fuel Report in the system.
                }
                else
                {
                    //NOTE: The Detail of Yesterday Fuel Report is not found.
                    throw new ObjectNotFound(string.Format("RelevantFuelReportDetailOfTheDayBefore for '{0}'", this.Good.Code));
                }
            }
            else
            {
                //The Detail for Yesterday Report has been found.
                double? robOfTheDayBefore = relevantFuelReportDetailOfTheDayBefore.ROB;
                //double? receiveOfTheDayBefore = relevantFuelReportDetailOfTheDayBefore.Receive;
                //double? correctionOfTheDayBefore = relevantFuelReportDetailOfTheDayBefore.Correction;
                //CorrectionTypes? correctionTypeOfTheDayBefore = relevantFuelReportDetailOfTheDayBefore.CorrectionType;
                //double? transferOfTheDayBefore = relevantFuelReportDetailOfTheDayBefore.Transfer;

                //BR_FR10
                validateROB(
                    rob,
                    consumption,
                    receive,
                    correction,
                    correctionType,
                    transfer,
                    robOfTheDayBefore);
            }
        }
示例#6
0
 //===================================================================================
 /// <summary>
 /// BR_FR5
 /// </summary>
 private void validateReceiveType(double? receive, ReceiveTypes? receiveType)
 {
     //This business rule must be checked for non EndOfVoyage, EndOfMonth, EndOfYear FuelReports.
     if (FuelReport.FuelReportType != FuelReportTypes.EndOfVoyage &&
         FuelReport.FuelReportType != FuelReportTypes.EndOfMonth &&
         FuelReport.FuelReportType != FuelReportTypes.EndOfYear)
     {
         //fuelReportDetail.Receive > 0 : will be checked in BR_FR8
         if (receive.HasValue &&
             !(
                  receiveType.HasValue &&
                  Enum.IsDefined(typeof(ReceiveTypes), receiveType.Value)/* &&
                  receiveType.Value != ReceiveTypes.NotDefined*/
              )
             )
             throw new BusinessRuleException("BR_FR5", string.Format("The ReceiveType for '{0}' is not specified.", this.Good.Code));
     }
 }
示例#7
0
        private static void refineValues(ref double rob, ref double consumption, ref double? receive, ref ReceiveTypes? receiveType, ref double? transfer, ref TransferTypes? transferType, ref double? correction, ref CorrectionTypes? correctionType, ref decimal? correctionPrice, ref long? correctionPriceCurrencyId, ref Reference transferReference, ref Reference receiveReference, ref Reference correctionReference)
        {
            //Values refinement.
            //rob = !rob.HasValue || rob == 0 ? null : rob;
            //consumption = !consumption.HasValue || consumption == 0 ? null : consumption;
            receive = !receive.HasValue || receive == 0 ? null : receive;
            transfer = !transfer.HasValue || transfer == 0 ? null : transfer;
            correction = !correction.HasValue || correction == 0 ? null : correction;
            correctionPrice = !correctionPrice.HasValue || correctionPrice == 0 ? null : correctionPrice;
            correctionPriceCurrencyId = !correctionPriceCurrencyId.HasValue || correctionPriceCurrencyId == 0 ? null : correctionPriceCurrencyId;

            if (!receive.HasValue)
            {
                receiveType = null;
                receiveReference = Reference.Empty;
            }

            if (!transfer.HasValue)
            {
                transferType = null;
                transferReference = Reference.Empty;
            }

            if (!correction.HasValue)
            {
                correctionType = null;
                correctionPrice = null;
                correctionPriceCurrencyId = null;
                correctionReference = Reference.Empty;
            }
        }
示例#8
0
        internal void Update(
            double rob,
            double consumption,
            double? receive,
            ReceiveTypes? receiveType,
            double? transfer,
            TransferTypes? transferType,
            double? correction,
            CorrectionTypes? correctionType,
            decimal? correctionPrice,
            long? correctionPriceCurrencyId,
            Reference transferReference,
            Reference receiveReference,
            Reference correctionReference,
            FuelReportDetail relevantFuelReportDetailOfTheDayBefore,
            bool isDetailOfFirstFuelReport,
            ICurrencyDomainService currencyDomainService)
        {
            validateValues(rob, consumption, receive, receiveType, transfer, transferType, correction, correctionType,
                correctionPrice, correctionPriceCurrencyId,
                transferReference,
                receiveReference,
                correctionReference,
                relevantFuelReportDetailOfTheDayBefore, isDetailOfFirstFuelReport, currencyDomainService);

            refineValues(ref rob, ref consumption, ref receive, ref receiveType, ref transfer, ref transferType, ref correction, ref correctionType, ref correctionPrice, ref correctionPriceCurrencyId, ref transferReference, ref receiveReference, ref correctionReference);

            ROB = rob;
            Consumption = consumption;
            Receive = receive;
            ReceiveType = receiveType;
            Transfer = transfer;
            TransferType = transferType;
            Correction = correction;
            CorrectionPrice = correctionPrice;
            CorrectionType = correctionType;
            CorrectionPriceCurrencyId = correctionPriceCurrencyId;

            TransferReference = transferReference;
            ReceiveReference = receiveReference;
            CorrectionReference = correctionReference;
        }
示例#9
0
 //===================================================================================
 /// <summary>
 /// BR_FR34
 /// </summary>
 private void validateValuesForEndOfVoyageEndOfMonthEndOfYearFuelReport(
     double? rob,
     double? consumption,
     double? receive,
     ReceiveTypes? receiveType,
     double? transfer,
     TransferTypes? transferType,
     double? correction,
     CorrectionTypes? correctionType,
     decimal? correctionPrice,
     long? correctionPriceCurrencyId)
 {
     if (FuelReport.FuelReportType == FuelReportTypes.EndOfVoyage ||
         FuelReport.FuelReportType == FuelReportTypes.EndOfMonth ||
         FuelReport.FuelReportType == FuelReportTypes.EndOfYear)
     {
         if (!rob.HasValue ||
             !consumption.HasValue ||
             receive.HasValue ||
             receiveType.HasValue ||
             transfer.HasValue ||
             transferType.HasValue ||
             correction.HasValue ||
             correctionType.HasValue ||
             correctionPrice.HasValue ||
             correctionPriceCurrencyId.HasValue)
         {
             throw new BusinessRuleException("BR_FR34",
                                             string.Format("BR_FR34 : Values assignment for '{0}' is invalid against EndOfVoyage, EndOfMonth or EndOfYear Fuel Report.", this.Good.Code));
         }
     }
 }