public OffhireFactory( IEntityConfigurator<Offhire> offhireConfigurator, IWorkflowRepository workflowRepository, IOffhireDomainService offhireDomainService, IVesselInCompanyDomainService vesselDomainService, ICompanyDomainService companyDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService, IOffhireManagementSystemDomainService offhireManagementSystemDomainService, IVoyageDomainService voyageDomainService, IActivityLocationDomainService activityLocationDomainService) { this.offhireConfigurator = offhireConfigurator; this.workflowRepository = workflowRepository; this.offhireDomainService = offhireDomainService; this.vesselDomainService = vesselDomainService; this.companyDomainService = companyDomainService; this.tankDomainService = tankDomainService; this.currencyDomainService = currencyDomainService; this.goodDomainService = goodDomainService; this.goodUnitDomainService = goodUnitDomainService; this.offhireManagementSystemDomainService = offhireManagementSystemDomainService; this.voyageDomainService = voyageDomainService; this.activityLocationDomainService = activityLocationDomainService; }
public OffhireApplicationService( IOffhireFactory offhireFactory, IOffhireRepository offhireRepository, IUnitOfWorkScope unitOfWorkScope, IOffhireDomainService offhireDomainService, IEntityConfigurator<Offhire> offhireConfigurator, IVesselInCompanyDomainService vesselDomianService, IVoyageDomainService voyageDomianService, ICompanyDomainService companyDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService, ITankDomainService tankDomainService, IActivityLocationDomainService activityLocationDomainService, IOffhireManagementSystemDomainService offhireManagementSystemDomainService) { this.offhireFactory = offhireFactory; this.offhireRepository = offhireRepository; this.unitOfWorkScope = unitOfWorkScope; this.offhireDomainService = offhireDomainService; this.vesselDomianService = vesselDomianService; this.companyDomainService = companyDomainService; this.currencyDomainService = currencyDomainService; this.goodDomainService = goodDomainService; this.goodUnitDomainService = goodUnitDomainService; this.tankDomainService = tankDomainService; this.activityLocationDomainService = activityLocationDomainService; this.offhireManagementSystemDomainService = offhireManagementSystemDomainService; this.voyageDomianService = voyageDomianService; this.offhireDomainService.SetConfigurator(offhireConfigurator); }
internal Offhire( long referenceNumber, DateTime startDateTime, DateTime endDateTime, Company introducer, VesselInCompany vesselInCompany, Voyage voyage, ActivityLocation offhireLocation, DateTime voucherDate, Currency voucherCurrency, //string pricingReferenceNumber, //OffHirePricingType pricingReferenceType, IOffhireDomainService offhireDomainService, IOffhireManagementSystemDomainService offhireManagementSystemDomainService, IVesselInCompanyDomainService vesselDomainService, IVoyageDomainService voyageDomainService, ICompanyDomainService companyDomainService, IActivityLocationDomainService activityLocationDomainService, ICurrencyDomainService currencyDomainService) : this() { //var pricingReference = new OffhirePricingReference() { Type = pricingReferenceType, Number = pricingReferenceNumber }; this.validateCreation( referenceNumber, startDateTime, endDateTime, introducer, vesselInCompany, voyage, offhireLocation, voucherDate, voucherCurrency, //pricingReference, offhireDomainService, offhireManagementSystemDomainService, vesselDomainService, voyageDomainService, companyDomainService, activityLocationDomainService, currencyDomainService); this.ReferenceNumber = referenceNumber; this.StartDateTime = startDateTime; this.EndDateTime = endDateTime; this.IntroducerType = offhireDomainService.GetCharteringPartyType(vesselInCompany); this.Introducer = introducer; this.VesselInCompany = vesselInCompany; this.Voyage = voyage; this.OffhireLocation = offhireLocation; this.VoucherDate = voucherDate; this.VoucherCurrencyId = voucherCurrency.Id; this.VoucherCurrency = voucherCurrency; this.PricingReference = this.createPricingReference(introducer, vesselInCompany, this.IntroducerType, voyage, startDateTime, offhireDomainService); }
public ApprovableOffhireDomainService( IOffhireDomainService offhireDomainService, IFinanceNotifier eventNotifier, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.offhireDomainService = offhireDomainService; this.eventNotifier = eventNotifier; this.tankDomainService = tankDomainService; this.currencyDomainService = currencyDomainService; this.goodDomainService = goodDomainService; this.goodUnitDomainService = goodUnitDomainService; }
internal OffhireDetail(decimal quantity, decimal feeInVoucherCurrency, decimal feeInMainCurrency, Good good, GoodUnit unit, Tank tank, Offhire offhire, IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) : this() { this.validateOffhire(offhire, offhireDomainService); this.validateValues(quantity, feeInVoucherCurrency, feeInMainCurrency, good, unit, tank, offhire, offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); this.Quantity = quantity; this.FeeInVoucherCurrency = feeInVoucherCurrency; this.FeeInMainCurrency = feeInMainCurrency; this.Good = good; this.Unit = unit; this.Tank = tank; this.Offhire = offhire; }
public OffhireFacadeService( IOffhireApplicationService offhireApplicationService, IOffhireDomainService offhireDomainService, IEntityConfigurator<Offhire> offhireConfigurator, IOffhireToOffhireDtoMapper offhireDtoMapper, IOffhireDetailToOffhireDetailDtoMapper offhireDetailDtoMapper, IInventoryOperationToInventoryOperationDtoMapper inventoryOperationDtoMapper, IOffhireManagementSystemDomainService offhireManagementSystemDomainService, IOffhireManagementSystemEntityToOffhireManagementSystemDtoMapper offhireManagementSystemDtoMapper, IOffhirePreparedDataToOffhireDtoMapper offhirePreparedDataToOffhireDtoMapper, IPricingValueToPricingValueDtoMapper pricingValueDtoMapper) { this.offhireApplicationService = offhireApplicationService; this.offhireDomainService = offhireDomainService; this.offhireDtoMapper = offhireDtoMapper; this.offhireDetailDtoMapper = offhireDetailDtoMapper; this.inventoryOperationDtoMapper = inventoryOperationDtoMapper; this.offhireManagementSystemDomainService = offhireManagementSystemDomainService; this.offhireManagementSystemDtoMapper = offhireManagementSystemDtoMapper; this.offhirePreparedDataToOffhireDtoMapper = offhirePreparedDataToOffhireDtoMapper; this.pricingValueDtoMapper = pricingValueDtoMapper; this.offhireDomainService.SetConfigurator(offhireConfigurator); }
//================================================================================ private void validateRelevantCharterInOffhireExistanceInChartererCompanyForCharterOutVessel( Company shipOwner, VesselInCompany vesselInCompany, DateTime date, IOffhireDomainService offhireDomainService) { try { offhireDomainService.GetRelevantCharterInOffhire(shipOwner, vesselInCompany, date); } catch (Exception ex) { throw new BusinessRuleException("", "Relevant CharterIn Offhire record for Charter Out Vessel not found."); } }
//================================================================================ private void validateOffhirePricingTypeForCharteredOutVessel( Company introducer, VesselInCompany vesselInCompany, Voyage voyage, DateTime satrtDate, OffHirePricingType offhirePricingType, IOffhireDomainService offhireDomainService) { switch (offhirePricingType) { case OffHirePricingType.CharterPartyBase: break; case OffHirePricingType.IssueBase: this.validateRelevantCharterInOffhireExistanceInChartererCompanyForCharterOutVessel( introducer, vesselInCompany, satrtDate, offhireDomainService); break; default: throw new InvalidArgument("OffhirePricingTypeForCharteredOut"); } }
//================================================================================ private void validateOffhireUniquenessInFuelManagementDomain(long referenceNumber, Company introducer, IOffhireDomainService offhireDomainService) { if (offhireDomainService.IsOffhireRegistered(referenceNumber, introducer)) throw new BusinessRuleException("", "The selected Offhire is already registered."); }
//================================================================================ private void validateOffhirePricingType( Company introducer, VesselInCompany vesselInCompany, Voyage voyage, DateTime satrtDate, CharteringPartyType partyType, OffHirePricingType offhirePricingType, IOffhireDomainService offhireDomainService) { switch (partyType) { case CharteringPartyType.Charterer: this.validateOffhirePricingTypeForCharteredInVessel( voyage, offhirePricingType, offhireDomainService); break; case CharteringPartyType.ShipOwner: this.validateOffhirePricingTypeForCharteredOutVessel( introducer, vesselInCompany, voyage, satrtDate, offhirePricingType, offhireDomainService); break; } }
//================================================================================ private void validateOffhirePricingTypeForCharteredInVessel( Voyage voyage, OffHirePricingType offhirePricingType, IOffhireDomainService offhireDomainService) { switch (offhirePricingType) { case OffHirePricingType.CharterPartyBase: break; case OffHirePricingType.IssueBase: this.validateVoyagePricedIssueExistanceForCharterInIssueBasedPricingVessel( voyage, offhireDomainService); break; default: throw new InvalidArgument("OffhirePricingTypeForCharteredIn"); } }
//================================================================================ public void Delete(IOffhireDomainService offhireDomainService) { while (OffhireDetails.Count > 0) { this.DeleteDetail(OffhireDetails[0].Id, offhireDomainService); } this.validateDeletion(); offhireDomainService.Delete(this); }
//================================================================================ private void validateDetails(IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.OffhireDetails.ForEach(sd => sd.Validate(offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService)); }
//================================================================================ internal void Update(decimal feeInVoucherCurrency, decimal feeInMainCurrency, IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateValues(this.Quantity, feeInVoucherCurrency, feeInMainCurrency, this.Good, this.Unit, this.Tank, this.Offhire, offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); this.FeeInVoucherCurrency = feeInVoucherCurrency; this.FeeInMainCurrency = feeInMainCurrency; }
//================================================================================ private void validateOffhire(Offhire offhire, IOffhireDomainService offhireDomainService) { if (offhire == null) throw new InvalidArgument("Offhire"); //Commented intentionally due to registration of Details along with the Offhire. //if (offhireDomainService.Get(offhire.Id) == null) // throw new ObjectNotFound("Offhire", offhire.Id); }
//================================================================================ private OffhirePricingReference createPricingReference(Company introducer, VesselInCompany vesselInCompany, CharteringPartyType partyType, Voyage voyage, DateTime startDateTime, IOffhireDomainService offhireDomainService) { var pricingType = offhireDomainService.GetPricingType(introducer, vesselInCompany, startDateTime); switch (pricingType) { case OffHirePricingType.CharterPartyBase: var charteringReferenceNumber = offhireDomainService.GetCharteringReferenceNumber(introducer, vesselInCompany, partyType, startDateTime); return new OffhirePricingReference() { Number = charteringReferenceNumber, Type = OffHirePricingType.CharterPartyBase }; case OffHirePricingType.IssueBase: var issueReferenceNumber = offhireDomainService.GetVoyageConsumptionIssueOperation(voyage.Id).ActionNumber; return new OffhirePricingReference() { Number = issueReferenceNumber, Type = OffHirePricingType.IssueBase }; default: throw new InvalidArgument("Pricing Type could not be retrieved.", "PricingType"); } }
//================================================================================ private void DeleteDetail(long offhireDetailId, IOffhireDomainService offhireDomainService) { this.validateDetailDeletion(); var offhireDetailToDelete = this.findDetail(offhireDetailId); offhireDomainService.DeleteOffhireDetail(offhireDetailToDelete); }
//================================================================================ public void ValidateMiddleApprove(IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateToBeOpen(); this.validateApproveAction(offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); }
//================================================================================ public OffhireDetail UpdateDetail( long offhireDetailId, decimal feeInVoucherCurrency, decimal feeInMainCurrency, IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { OffhireDetail offhireDetailToUpdate = this.findDetail(offhireDetailId); offhireDetailToUpdate.Update(feeInVoucherCurrency, feeInMainCurrency, offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); return offhireDetailToUpdate; }
//================================================================================ public void Submit(SubmittedState submittedState, IOffhireDomainService offhireDomainService, IFinanceNotifier eventNotifier, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateToBeOpenOrSubmitRejected(); this.validateApproveAction(offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); //Perform Submit operations. eventNotifier.NotifySubmittingOffhire(this); this.setState(submittedState); }
//================================================================================ private void validateVoyagePricedIssueExistanceForCharterInIssueBasedPricingVessel( Voyage voyage, IOffhireDomainService offhireDomainService) { var pricedIssueResult = offhireDomainService.GetVoyagePricedConsumptionIssue(voyage.CompanyId, voyage.Id); if (pricedIssueResult == null || pricedIssueResult.InventoryResultItems.Count == 0) throw new BusinessRuleException("", "The Consumption Issue is not priced yet in Inventory."); }
//================================================================================ private void validateCreation( long referenceNumber, DateTime startDateTime, DateTime endDateTime, Company introducer, VesselInCompany vesselInCompany, Voyage voyage, ActivityLocation offhireLocation, DateTime voucherDate, Currency voucherCurrency, //OffhirePricingReference pricingReference, IOffhireDomainService offhireDomainService, IOffhireManagementSystemDomainService offhireManagementSystemDomainService, IVesselInCompanyDomainService vesselDomainService, IVoyageDomainService voyageDomainService, ICompanyDomainService companyDomainService, IActivityLocationDomainService activityLocationDomainService, ICurrencyDomainService currencyDomainService) { this.validateCompanyExistance(introducer, companyDomainService); this.validateOffhireReference(referenceNumber, introducer, offhireManagementSystemDomainService); this.validateOffhireUniquenessInFuelManagementDomain(referenceNumber, introducer, offhireDomainService); this.validateCurrency(voucherCurrency, currencyDomainService); this.validateVoucherDate(voucherDate); this.validateVesselExistance(vesselInCompany, vesselDomainService); this.validateVesselInCompanyExistance(vesselInCompany, introducer, companyDomainService); this.validateVoyageExistance(voyage, voyageDomainService); this.validateVoyageInVesselOfCompanyExistance(voyage, vesselInCompany); this.validateOffhireDurationInVoyage(startDateTime, endDateTime, voyage); this.validateActivityLocation(offhireLocation, activityLocationDomainService); CharteringPartyType charteringPartyType = offhireDomainService.GetCharteringPartyType(vesselInCompany); var offhirePricingType = offhireDomainService.GetPricingType(introducer, vesselInCompany, startDateTime); this.validateOffhirePricingType(introducer, vesselInCompany, voyage, startDateTime, charteringPartyType, offhirePricingType, offhireDomainService); }
//================================================================================ public void Validate(IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateValues(this.Quantity, this.FeeInVoucherCurrency, this.FeeInMainCurrency, this.Good, this.Unit, this.Tank, this.Offhire, offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); }
//================================================================================ private void validateValues(decimal quantity, decimal feeInVoucherCurrency, decimal feeInMainCurrency, Good good, GoodUnit unit, Tank tank, Offhire offhire, IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateTank(tank, offhire, tankDomainService); this.validateGood(good, goodDomainService); this.validateGoodInTank(tank, good, offhire); this.validateGoodToBeUniqueInDetails(good, offhire); this.validateQuantity(quantity); this.validateFeeInMainCurrency(feeInMainCurrency); this.validateUnit(unit, goodUnitDomainService); this.validateGoodUnitInCompany(offhire.Introducer, good, unit); this.validateFeeInVoucherCurrency(feeInVoucherCurrency, offhire, good, offhireDomainService, currencyDomainService); }
//================================================================================ private void validateApproveAction( IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateDetailsExistance(); this.validateDetails(offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); }
//================================================================================ private void validateFeeInVoucherCurrency(decimal feeInVoucherCurrency, Offhire offhire, Good good, IOffhireDomainService offhireDomainService, ICurrencyDomainService currencyDomainService) { if (feeInVoucherCurrency < 0) throw new BusinessRuleException("", string.Format("Fee In Voucher Currency is negative for '{0}'.", good.Name)); var pricingValue = offhireDomainService.GetPricingValue(offhire.Introducer, offhire.VesselInCompany, offhire.StartDateTime, good); switch (offhire.PricingReference.Type) { case OffHirePricingType.CharterPartyBase: if (pricingValue != null && pricingValue.Fee.HasValue && pricingValue.Currency != null) { var charterPartyConvertedOffhireFee = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency.Id, offhire.VoucherCurrencyId, offhire.VoucherDate); if (feeInVoucherCurrency != charterPartyConvertedOffhireFee) throw new BusinessRuleException("", string.Format("The Offhire Fee for Good '{0}' is invlaid.", good.Name)); } break; case OffHirePricingType.IssueBase: if (pricingValue == null || !pricingValue.Fee.HasValue || pricingValue.Currency == null) throw new BusinessRuleException("", string.Format("IssueBased Pricing for Good '{0}' not found.", good.Name)); var issueBaseConvertedOffhireFee = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency.Id, offhire.VoucherCurrencyId, offhire.VoucherDate); if (feeInVoucherCurrency != issueBaseConvertedOffhireFee) throw new BusinessRuleException("", string.Format("The Offhire Fee for Good '{0}' is invlaid.", good.Name)); break; default: throw new InvalidArgument("PricingReferenceType"); } }