public InventoryOperation GetEndOfYearFuelReportConsumptionInventoryOperation(FuelReport fuelReport)
        {
            fuelReport.CheckToBeNotCancelled();

            if (fuelReport.FuelReportType != FuelReportTypes.EndOfYear)
                throw new InvalidArgument("The FuelReport is not of type End Of Year to find Consumption Invenroty.", "fuelReport");

            return fuelReport.ConsumptionInventoryOperations.Last();
        }
        public List<InventoryOperation> GetFuelReportInventoryOperations(FuelReport fuelReport)
        {
            fuelReport.CheckToBeNotCancelled();

            return fuelReport.FuelReportDetails.SelectMany(frd => frd.InventoryOperations).ToList();

            //return inventoryOperationRepository.Find(
            //    inv =>
            //        fuelReport.FuelReportDetails
            //            .SelectMany(frd => frd.InventoryOperations)
            //            .Select(frdinv => frdinv.Id)
            //            .Contains(inv.Id)
            //).ToList();
        }
 public void Submit(FuelReport fuelReport, FuelReportState entityNewState)
 {
     fuelReport.Submit(
         entityNewState,
         this.voyageDomainService,
         this.fuelReportDomainService,
         this.inventoryOperationDomainService,
         this.goodDomainService,
         this.orderDomainService,
         this.currencyDomainService,
         this.balanceDomainService,
         inventoryManagementDomainService,
         this.inventoryOperationNotifier);
 }
        public InventoryOperation NotifySubmittingFuelReportConsumption(FuelReport fuelReport)
        {
            try
            {
                return this.inventoryOperationManager.ManageFuelReportConsumption(fuelReport,
                    //TODO: Fake ActorId
                    1101);
            }
            catch (Exception)
            {

                throw;
            }
        }
        //================================================================================
        public InventoryOperation ManageFuelReportConsumption(FuelReport fuelReport, int userId)
        {
            if (!(fuelReport.FuelReportType == FuelReportTypes.EndOfVoyage ||
                fuelReport.FuelReportType == FuelReportTypes.EndOfYear ||
                fuelReport.FuelReportType == FuelReportTypes.EndOfMonth))
                throw new InvalidArgument("The given entity is not EOV, EOM, EOY.", "charterOutStart");

            using (var dbContext = new InventoryDbContext())
            {
                using (var transaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
                {
                    InventoryOperation result = null;

                    //TODO: EOV-EOM-EOY
                    #region EOV-EOM-EOY

                    var goodsConsumption = new Dictionary<long, decimal>();

                    foreach (var detail in fuelReport.FuelReportDetails)
                    {
                        var consumption = calculateConsumption(detail);

                        goodsConsumption.Add(detail.GoodId, consumption);
                    }

                    var transactionReferenceNumber = fuelReport.Id.ToString();

                    var reference = findInventoryOperationReference(dbContext, InventoryOperationType.Issue, EOV_EOM_EOY_FUEL_REPORT_CONSUMPTION, transactionReferenceNumber);

                    //if (reference.OperationId == INVALID_ID)
                    if (reference == null)
                    {
                        string transactionCode, transactionMessage;

                        var operationReference =
                            issue(
                                  dbContext,
                                  (int)fuelReport.VesselInCompany.CompanyId,
                                  (int)fuelReport.VesselInCompany.VesselInInventory.Id,
                                  1,
                                  convertFuelReportConsumptionTypeToStoreType(fuelReport),
                                    null,
                                  EOV_EOM_EOY_FUEL_REPORT_CONSUMPTION,
                                  transactionReferenceNumber,
                                  userId,
                                  out transactionCode,
                                  out transactionMessage);

                        string transactionItemMessage;

                        var transactionItems = new List<TransactionItem>();

                        foreach (var fuelReportDetail in fuelReport.FuelReportDetails)
                        {
                            transactionItems.Add(new TransactionItem()
                                                 {
                                                     GoodId = (int)fuelReportDetail.Good.SharedGoodId,
                                                     CreateDate = DateTime.Now,
                                                     Description = fuelReportDetail.FuelReport.FuelReportType.ToString(),
                                                     QuantityAmount = goodsConsumption[fuelReportDetail.GoodId],
                                                     QuantityUnitId = getMeasurementUnitId(dbContext, fuelReportDetail.MeasuringUnit.Abbreviation),
                                                     TransactionId = (int)operationReference.OperationId,
                                                     UserCreatorId = userId
                                                 });
                        }

                        var registeredTransactionIds = addTransactionItems(dbContext, (int)operationReference.OperationId, transactionItems, userId, out transactionItemMessage);

                        string issuedItemsPricingMessage;

                        var pricingTransactionIds = registeredTransactionIds.Select(id => new TransactionItemPricingId() { Id = id, Description = "Voyage Consumption FIFO Pricing" });

                        try
                        {
                            priceIssuedItemsInFIFO(dbContext, pricingTransactionIds, userId, out issuedItemsPricingMessage, EOV_EOM_EOY_FUEL_REPORT_CONSUMPTION_PRICING, transactionReferenceNumber);
                        }
                        catch
                        {
                        }

                        result = new InventoryOperation(
                                       inventoryOperationId: operationReference.OperationId,
                                       actionNumber: string.Format("{0}/{1}", (InventoryOperationType)operationReference.OperationType, operationReference.OperationId),
                                       actionDate: DateTime.Now,
                                       actionType: InventoryActionType.Issue,
                                       fuelReportDetailId: null,
                                       charterId: null);
                    }
                    else
                    {
                        throw new InvalidOperation("EndOfVoyage/Month/Year inventory edit", "EndOfVoyage/Month/Year inventory edit is invalid");
                        var transactionItems = dbContext.TransactionItems.Where(ti => ti.TransactionId == reference.OperationId);
                    }

                    #endregion

                    transaction.Commit();

                    return result;
                }
            }
        }
 private int convertFuelReportConsumptionTypeToStoreType(FuelReport fuelReport)
 {
     switch (fuelReport.FuelReportType)
     {
         case FuelReportTypes.EndOfVoyage:
             return 14;
         case FuelReportTypes.EndOfYear:
             return 15;
         case FuelReportTypes.EndOfMonth:
             return 16;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
        //================================================================================
        public List<FuelReport> GetPreviousNotFinalApprovedReports(FuelReport fuelReport)
        {
            var fetchStrategy = new ListFetchStrategy<FuelReport>().OrderBy(c => c.EventDate);

            var result = this.fuelReportRepository.Find(
                                    Extensions.And(this.isFuelReportInFinalApprovedState.Not().Predicate, Extensions.And(this.isFuelReportOperational.Predicate, f => f.EventDate < fuelReport.EventDate)));

            return result.ToList();
        }
        //================================================================================
        public void SetFuelReportInventoryResults(InventoryResultCommand resultCommand, FuelReport fuelReport)
        {
            foreach (var item in resultCommand.Items)
            {
                var fuelReportDetail = fuelReport.FuelReportDetails.FirstOrDefault(frd => frd.Id == item.FuelReportDetailId);
                if (fuelReportDetail == null)
                {
                    throw new ObjectNotFound("resultBag.Item.DetailId");
                }

                var inventoryOperationToPersist = inventoryOperationFactory.Create(fuelReportDetail, item.OperationId, item.ActionNumber, item.ActionType, item.ActionDate);

                inventoryOperationRepository.Add(inventoryOperationToPersist);

                //if (fuelReportDetail.TransferReferenceOrderId.HasValue)
                //{
                //     orderDomainService.CloseOrder(fuelReportDetail.TransferReferenceOrderId.Value);
                //}

                //if (fuelReportDetail.ReceiveReferenceOrderId.HasValue)
                //{
                //      orderDomainService.CloseOrder(fuelReportDetail.ReceiveReferenceOrderId.Value);
                //}
            }

            //IFuelReportStateFactory stateFactory = ServiceLocator.Current.GetInstance<IFuelReportStateFactory>();

            //fuelReport.Close(stateFactory.CreateClosedState());
        }
        //================================================================================
        public List<FuelReport> GetNotIssuedEOVFuelReportsOfPreviousVoyages(FuelReport fuelReport)
        {
            var previousEOVFuelReports = getPreviousEOVFuelReports(fuelReport.EventDate);

            var notIssuedEOVFuelReportsOfPreviousVoyages =
                previousEOVFuelReports
                    .FindAll(eovfr => eovfr.ConsumptionInventoryOperations == null || eovfr.ConsumptionInventoryOperations.Count == 0);

            return notIssuedEOVFuelReportsOfPreviousVoyages;
        }
        //================================================================================
        public FuelReport GetLastIssuedEOVFuelReportOfPreviousVoyages(FuelReport fuelReport)
        {
            var previousEOVFuelReports = getPreviousEOVFuelReports(fuelReport.EventDate);

            var lastIssuedEOVFuelReportOfPreviousVoyages =
                previousEOVFuelReports
                    .FindAll(eovfr => eovfr.ConsumptionInventoryOperations != null && eovfr.ConsumptionInventoryOperations.Count > 0)
                    .OrderBy(eovfr=>eovfr.EventDate)
                    .LastOrDefault();

            return lastIssuedEOVFuelReportOfPreviousVoyages;
        }
        //================================================================================
        public List<FuelReport> GetFuelReportsFromYesterday(FuelReport fuelReport)
        {
            DateTime previousDayDate = fuelReport.EventDate.Date.AddDays(-1);

            return GetVesselFuelReports(fuelReport.VesselInCompany, previousDayDate, fuelReport.EventDate.AddMilliseconds(-1));
        }
Example #12
0
        //===================================================================================
        private void validateFuelReportOfTheDayBefore(
            FuelReport fuelReportOfTheDayBefore,
            bool isCurrentFuelReportTheFirst)
        {
            if (fuelReportOfTheDayBefore == null && !isCurrentFuelReportTheFirst)
                //This means that current Fuel Report is not the first one in the whole system and
                //has no Fuel Report in yesterday.
                throw new ObjectNotFound("FuelReportOfTheDayBefore"); //"No fuel report found for previous day.";

            if (fuelReportOfTheDayBefore != null)
            {
                //Checking FuelReport of the Day Before for final approval state.
                //TODO: The business rule code must be indicated.
                if (!isFuelReportClosed.IsSatisfiedBy(fuelReportOfTheDayBefore))
                    throw new BusinessRuleException("XXXXXX", "The previous Fuel Report must be Final Approved.");
            }
        }
Example #13
0
        //===================================================================================
        private FuelReportDetail getGoodRelevantFuelReportDetailOfYesterday(long goodId, bool isTheFirstReport, FuelReport previousFuelReport)
        {
            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 == 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", goodId);
            }

            return fuelReportDetailOfYesterdayForRelevantGood;
        }