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 static List<VoyageLog> CreateVoyagesLog(Voyage voyage) { return new List<VoyageLog>(); //{ // new VoyageLog // ( // 0, voyage.Id, DateTime.Now.AddDays(-5), voyage.VoyageNumber , voyage.Description, voyage.VesselInCompany, voyage.Company, // voyage.StartDate.AddHours(1), voyage.EndDate, true), // new VoyageLog // ( // 0, voyage.Id, DateTime.Now.AddDays(-3), voyage.VoyageNumber, voyage.Description, voyage.VesselInCompany, voyage.Company, // voyage.StartDate, voyage.EndDate.AddHours(1), false), // new VoyageLog // ( // 0, voyage.Id, DateTime.Now.AddHours(-17), voyage.VoyageNumber, voyage.Description, voyage.VesselInCompany, // voyage.Company, voyage.StartDate, voyage.EndDate.AddHours(3), false), // new VoyageLog // ( // 0, voyage.Id, DateTime.Now.AddMinutes(-45), voyage.VoyageNumber, voyage.Description, voyage.VesselInCompany, // voyage.Company, voyage.StartDate, voyage.EndDate.AddHours(17), true), //}; }
//================================================================================ public List<PricingValue> GetIssueBasedPricingValues(Voyage voyage) { if (voyage == null) throw new BusinessRuleException("", "No Voyage is selected for vessel to fetch Consumption Issue Prices."); var pricedIssueResult = this.GetVoyagePricedConsumptionIssue(voyage.CompanyId, voyage.Id); return pricedIssueResult.InventoryResultItems.Select(invi => new PricingValue() { Good = invi.Good, Currency = invi.Currency, Fee = invi.Price }).ToList(); }
//================================================================================ public FuelReport GetVoyageValidEndOfVoyageFuelReport(Voyage voyage) { if (voyage == null) return null; return GetVoyageValidEndOfVoyageFuelReport(voyage.Id); }
//================================================================================ //Commented due to be unusable //public void InvalidateAllPreviousEndOfVoyageFuelReports(FuelReport fuelReport) //{ // if (fuelReport.FuelReportType != FuelReportTypes.EndOfVoyage) // throw new ArgumentException("FuelReport is not of Type EndOfVoyage."); // var previousFuelReports = this.fuelReportRepository.Find( // Extensions.And(this.isFuelReportOperational.Predicate, fr => // fr.FuelReportType == Enums.FuelReportTypes.EndOfVoyage && // fr.ReportDate < fuelReport.ReportDate && // fr.VoyageId == fuelReport.VoyageId) // ); // IFuelReportStateFactory stateFactory = ServiceLocator.Current.GetInstance<IFuelReportStateFactory>(); // foreach (var previousFuelReport in previousFuelReports) // { // previousFuelReport.Invalidate(stateFactory.CreateInvalidState()); // } //} //================================================================================ public List<FuelReport> GetVoyageAllEndOfVoyageFuelReport(Voyage voyage) { return this.fuelReportRepository.Find( fr => fr.FuelReportType == Enums.FuelReportTypes.EndOfVoyage && voyage.Id == fr.VoyageId ).ToList(); }
//================================================================================ private Offhire( long referenceNumber, DateTime startDateTime, DateTime endDateTime, CharteringPartyType introducerType, Company introducer, VesselInCompany vesselInCompany, Voyage voyage, ActivityLocation offhireLocation, DateTime voucherDate, Currency voucherCurrency, string pricingReferenceNumber, OffHirePricingType pricingReferenceType, List<OffhireDetail> offhireDetails) { //This is used to create instances by reflection to Insert Seed Data into DB. this.ReferenceNumber = referenceNumber; this.StartDateTime = startDateTime; this.EndDateTime = endDateTime; this.IntroducerType = introducerType; this.Introducer = introducer; this.VesselInCompany = vesselInCompany; this.Voyage = voyage; this.OffhireLocation = offhireLocation; this.VoucherDate = voucherDate; this.VoucherCurrencyId = voucherCurrency.Id; this.VoucherCurrency = voucherCurrency; this.PricingReference = new OffhirePricingReference() { Type = pricingReferenceType, Number = pricingReferenceNumber }; this.OffhireDetails = offhireDetails; this.ApproveWorkflows = new List<OffhireWorkflowLog>(); }
//================================================================================ 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 validateVoyageInVesselOfCompanyExistance(Voyage voyage, VesselInCompany vesselInCompany) { if (voyage.VesselInCompany == null || voyage.VesselInCompany.Id != vesselInCompany.Id) throw new BusinessRuleException("", "Voyage is not for selected Vessel."); }
//================================================================================ private void validateVoyageExistance(Voyage voyage, IVoyageDomainService voyageDomainService) { if (voyage == null || voyageDomainService.Get(voyage.Id) == null) throw new BusinessRuleException("", "The voyage 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 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"); } }
//================================================================================ 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 validateOffhireDurationInVoyage(DateTime startDateTime, DateTime endDateTime, Voyage voyage) { if (!(startDateTime <= endDateTime && startDateTime >= voyage.StartDate && endDateTime <= voyage.EndDate)) throw new BusinessRuleException("", "The offhire period is not inside the voyage duration."); }
//================================================================================ 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); }
//================================================================================ 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"); } }