public InvoiceCommand(InvoiceTypes invoiceType, string invoiceNumber, Company owner, DateTime invoiceDate, DivisionMethods divisionMethod, AccountingTypes accountType, Invoice invoiceRefrence, List<long> orderRefrences, Currency currency, Company transporter, Company supplier, string description, List<InvoiceItemCommand> list) { // TODO: Complete member initialization InvoiceType = invoiceType; InvoiceNumber = invoiceNumber; Owner = owner; InvoiceDate = invoiceDate; DivisionMethod = divisionMethod; AccountingType = accountType; InvoiceRefrence = invoiceRefrence; OrdersRefrenceId = orderRefrences; Currency = currency; Transporter = transporter; Supplier = supplier; Description = description; InvoiceItems = list; }
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 CharterOut GetCharterOutStart(Company company, VesselInCompany vesselInCompany, DateTime date) { IListFetchStrategy<Charter> fetchStrategy = new ListFetchStrategy<Charter>() .Include(c => c.CharterItems).OrderBy(c => c.ActionDate); var foundCharterOut = charterOutRepository .Find(cho => cho.CharterType == CharterType.Start && date >= cho.ActionDate && cho.OwnerId == company.Id && cho.VesselInCompanyId == vesselInCompany.Id, fetchStrategy).LastOrDefault() as CharterOut; return foundCharterOut; }
//================================================================================ private Scrap( VesselInCompany vesselInCompany, Company secondParty, DateTime scrapDate) { //This is used to create instances by reflection to Insert Seed Data into DB. this.VesselInCompany = vesselInCompany; this.SecondParty = secondParty; this.ScrapDate = scrapDate; this.ApproveWorkflows = new List<ScrapWorkflowLog>(); this.ScrapDetails = new List<ScrapDetail>(); this.InventoryOperations = new List<InventoryOperation>(); }
internal Scrap( VesselInCompany vesselInCompany, Company secondParty, DateTime scrapDate, IScrapDomainService scrapDomainService, IVesselInCompanyDomainService vesselDomainService, ICompanyDomainService companyDomainService) : this() { this.validateCreation(vesselInCompany, secondParty, scrapDate, scrapDomainService, vesselDomainService, companyDomainService); this.ScrapDate = scrapDate; this.VesselInCompany = vesselInCompany; this.SecondParty = secondParty; this.ScrapDetails = new List<ScrapDetail>(); this.ApproveWorkflows = new List<ScrapWorkflowLog>(); }
public Invoice CreateInvoiceObject(InvoiceCommand invoiceCommand, IEnumerable<Good> goods, Company owner, Company transporter, Company supplier, Invoice invoiceRefrence, List<Order> orderRefrences, Currency currency, List<InvoiceItem> invoiceItems, List<InvoiceAdditionalPrice> invoiceAdditionalPriceList, bool forCalculate) { var invoice = new Invoice ( invoiceCommand.InvoiceType, invoiceCommand.InvoiceNumber, owner, invoiceCommand.InvoiceDate, invoiceCommand.DivisionMethod, invoiceCommand.AccountingType, invoiceRefrence, orderRefrences,currency,invoiceCommand.IsCreditor, transporter, supplier, invoiceCommand.Description, invoiceItems, invoiceAdditionalPriceList, invoiceConfigurator, invoiceDomainService, invoiceItemDomainService,goodUnitConvertorDomainService,invoiceAdditionalPriceDomainService,balanceDomainService); if (!forCalculate) { var init = workflowRepository.Single (c => c.WorkflowEntity == WorkflowEntities.Invoice && c.CurrentWorkflowStage == WorkflowStages.Initial); var invoiceWorkflow = new InvoiceWorkflowLog (invoice.Id, WorkflowEntities.Invoice, DateTime.Now, WorkflowActions.Init, //TODO: Fake ActorId 1101, "", init.Id, true); invoice.ApproveWorkFlows.Add(invoiceWorkflow); } return invoice; }
public VoyageLog( long id, long referencedVoyageId, DateTime changeDate, string voyageNumber, string description, VesselInCompany vesselInCompany, Company company, DateTime startDate, DateTime endDate, bool isActive) { Id = id; ReferencedVoyageId = referencedVoyageId; ChangeDate = changeDate; VoyageNumber = voyageNumber; Description = description; this.VesselInCompany = vesselInCompany; Company = company; StartDate = startDate; EndDate = endDate; IsActive = isActive; }
//================================================================================ public PricingValue GetPricingValue(Company introducer, VesselInCompany vesselInCompany, DateTime startDate, Good good) { var partyType = this.GetCharteringPartyType(vesselInCompany); PricingValue result = null; switch (GetPricingType(introducer, vesselInCompany, startDate)) { case OffHirePricingType.CharterPartyBase: var charterPartyBasePricingValues = this.getCharterPartyBasedPricingValues(introducer, vesselInCompany, partyType, startDate); if (charterPartyBasePricingValues != null && charterPartyBasePricingValues.Count != 0) { //The offhire pricing in Charty Party is not mandatory. result = charterPartyBasePricingValues.SingleOrDefault(pv => pv.Good.Id == good.Id); } break; case OffHirePricingType.IssueBase: switch (partyType) { case CharteringPartyType.ShipOwner: var charterInOffhire = this.GetRelevantCharterInOffhire(introducer, vesselInCompany, startDate); if (charterInOffhire == null) throw new ObjectNotFound("RelevantCharterInOffhire"); var relevantCharterInOffhireDetail = charterInOffhire.OffhireDetails.FirstOrDefault(od => od.Good.Id == good.Id); if (relevantCharterInOffhireDetail == null) throw new ObjectNotFound("RelevantCharterInOffhireDetail"); result = new PricingValue() { Currency = relevantCharterInOffhireDetail.Offhire.VoucherCurrency, Fee = relevantCharterInOffhireDetail.FeeInVoucherCurrency, Good = good }; break; case CharteringPartyType.Charterer: var voyage = voyageDomainService.GetVoyage(introducer, startDate); var issueBasePricingValues = this.GetIssueBasedPricingValues(voyage); if (issueBasePricingValues == null || issueBasePricingValues.Count == 0) throw new ObjectNotFound("IssueBased Pricing for Vessel not found."); var issueBasePricingValue = issueBasePricingValues.SingleOrDefault(pv => pv.Good.Id == good.Id); if (issueBasePricingValue == null) throw new ObjectNotFound("IssueBased Pricing for Good " + good.Name + " not found."); result = issueBasePricingValue; break; default: throw new InvalidArgument("PartyType"); } break; default: throw new InvalidArgument("PricingReferenceType"); } if (result != null && result.Fee.HasValue && result.Currency == null) throw new InvalidArgument("Pricing Value has Fee but no currency."); return result; }
//================================================================================ public PricingValue GetPricingValue(Company introducer, VesselInCompany vesselInCompany, DateTime startDateTime, Good good, Currency currency, DateTime currencyDateTime) { decimal? feeInNewCurrency = null; var pricingValue = GetPricingValue(introducer, vesselInCompany, startDateTime, good); if (pricingValue.Fee.HasValue && pricingValue.Currency != null) feeInNewCurrency = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency, currency, currencyDateTime); return new PricingValue() { Good = good, Currency = currency, Fee = feeInNewCurrency }; }
//================================================================================ 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>(); }
//================================================================================ public OffHirePricingType GetPricingType(Company company, VesselInCompany vesselInCompany, DateTime date) { var partyType = this.GetCharteringPartyType(vesselInCompany); var charterContract = this.GetCharterContract(company, vesselInCompany, partyType, date); switch (partyType) { case CharteringPartyType.ShipOwner: //If the given company is in the role of ShipOwner, it will be inferred that //the pricing type must be fetched from Charter-Out contract. return ((CharterOut)charterContract).OffHirePricingType; case CharteringPartyType.Charterer: //If the given company is in the role of Charterer, it will be inferred that //the pricing type must be fetched from Charter-In contract. return ((CharterIn)charterContract).OffHirePricingType; default: throw new ArgumentOutOfRangeException("PartyType"); } }
//================================================================================ private List<PricingValue> getCharterPartyBasedPricingValues(Company introducer, VesselInCompany vesselInCompany, CharteringPartyType introducerType, DateTime stratDate) { var charterContract = this.GetCharterContract(introducer, vesselInCompany, introducerType, stratDate); //TODO: OffhireFee might not be set. return charterContract.CharterItems.Select(ci => new PricingValue() { Good = ci.Good, Currency = ci.OffhireFee == 0 ? null : charterContract.Currency, Fee = ci.OffhireFee == 0 ? null : (decimal?)ci.OffhireFee }).ToList(); }
public Voyage GetVoyageContainingDuration(Company company, DateTime startDateTime, DateTime endDateTime) { if (startDateTime > endDateTime) throw new InvalidArgument("Invlaid duration.", "EndDateTime"); var voyage = this.voyageRepository.First(v => v.VesselInCompany.CompanyId == company.Id && v.StartDate <= startDateTime && v.EndDate >= endDateTime); return voyage; }
//================================================================================ //private void validateVesselCharteringTypeInCompany(Vessel vessel, CharteringPartyType partyType, IVesselDomainService vesselDomainService) //{ // VesselStates vesselState = vesselDomainService.GetVesselCurrentState(vessel.Id); // if (partyType == CharteringPartyType.Charterer && vesselState != VesselStates.CharterIn) // throw new BusinessRuleException("", "Vessel is not in Charter-In state for the company."); // if (partyType == CharteringPartyType.ShipOwner && vesselState != VesselStates.CharterOut) // throw new BusinessRuleException("", "Vessel is not in Charter-Out state for the company."); //} //================================================================================ private void validateOffhireReference(long referenceNumber, Company introducer, IOffhireManagementSystemDomainService offhireManagementSystemDomainService) { var finalizedOffhire = offhireManagementSystemDomainService.GetFinalizedOffhire(referenceNumber, introducer.Id); if (finalizedOffhire == null) throw new BusinessRuleException("", "The selected Offhire is not registered."); if (finalizedOffhire.HasVoucher) throw new BusinessRuleException("", "Offhire is already registered with voucher."); }
//================================================================================ public Offhire GetRelevantCharterInOffhire(Company shipOwner, VesselInCompany vesselInCompany, DateTime startDate) { var charterOutContract = GetCharterContract(shipOwner, vesselInCompany, CharteringPartyType.ShipOwner, startDate) as CharterOut; var charterInCompanyOffhire = GetCompanyValidOffhire(charterOutContract.Charterer, vesselInCompany, startDate); return charterInCompanyOffhire; }
//================================================================================ 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 validateUpdate( VesselInCompany vesselInCompany, Company secondParty, DateTime scrapDate, IScrapDomainService scrapDomainService, IVesselInCompanyDomainService vesselDomainService, ICompanyDomainService companyDomainService) { this.validateToBeOpen(); this.validateCompanyExistance(secondParty, companyDomainService); this.validateVesselExistance(vesselInCompany, vesselDomainService); this.validateVesselOwnedState(vesselInCompany, vesselDomainService); this.validateScrapDateToBeAfterTheLastVesselActivity(scrapDate, vesselInCompany, vesselDomainService); this.validateToBeTheOnlyScrapForVessel(vesselInCompany, scrapDomainService); }
//================================================================================ private void validateCompanyExistance(Company secondParty, ICompanyDomainService companyDomainService) { Company fetchedCompany = companyDomainService.Get(secondParty.Id); if (fetchedCompany == null) { throw new ObjectNotFound("Company Not Found"); } }
//================================================================================ public void Update( VesselInCompany vesselInCompany, Company secondParty, DateTime scrapDate, IScrapDomainService scrapDomainService, IVesselInCompanyDomainService vesselDomainService, ICompanyDomainService companyDomainService) { this.validateUpdate(vesselInCompany, secondParty, scrapDate, scrapDomainService, vesselDomainService, companyDomainService); this.VesselInCompany = vesselInCompany; this.SecondParty = secondParty; this.ScrapDate = scrapDate; }
//================================================================================ 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."); } }
//================================================================================ public List<PricingValue> GetPricingValues(Company introducer, VesselInCompany vesselInCompany, DateTime startDateTime) { var partyType = this.GetCharteringPartyType(vesselInCompany); var result = new List<PricingValue>(); switch (GetPricingType(introducer, vesselInCompany, startDateTime)) { case OffHirePricingType.CharterPartyBase: var charterPartyBasePricingValues = this.getCharterPartyBasedPricingValues(introducer, vesselInCompany, partyType, startDateTime); if (charterPartyBasePricingValues != null && charterPartyBasePricingValues.Count != 0) { //The offhire pricing in Charty Party is not mandatory. result.AddRange(charterPartyBasePricingValues); } break; case OffHirePricingType.IssueBase: switch (partyType) { case CharteringPartyType.ShipOwner: var charterInOffhire = this.GetRelevantCharterInOffhire(introducer, vesselInCompany, startDateTime); if (charterInOffhire == null) throw new ObjectNotFound("RelevantCharterInOffhire"); result.AddRange(charterInOffhire.OffhireDetails.Select(relOD => new PricingValue() { Currency = relOD.Offhire.VoucherCurrency, Fee = relOD.FeeInVoucherCurrency, Good = relOD.Good })); break; case CharteringPartyType.Charterer: var voyage = voyageDomainService.GetVoyage(introducer, startDateTime); var issueBasePricingValues = this.GetIssueBasedPricingValues(voyage); if (issueBasePricingValues == null || issueBasePricingValues.Count == 0) throw new ObjectNotFound("IssueBased Pricing for Vessel not found."); result.AddRange(issueBasePricingValues); break; default: throw new InvalidArgument("PartyType"); } break; default: throw new InvalidArgument("PricingReferenceType"); } if (result.Any(pricing => pricing.Fee.HasValue && pricing.Currency == null)) throw new InvalidArgument("Pricing Value has Fee but no currency."); return result; }
//================================================================================ 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"); } }
//================================================================================ public List<PricingValue> GetPricingValues(Company introducer, VesselInCompany vesselInCompany, DateTime startDateTime, Currency currency, DateTime currencyDateTime) { var pricingValues = GetPricingValues(introducer, vesselInCompany, startDateTime); var result = new List<PricingValue>(); foreach (var pricingValue in pricingValues) { decimal? feeInVoucherCurrency = null; if (pricingValue.Fee.HasValue && pricingValue.Currency != null) feeInVoucherCurrency = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency, currency, currencyDateTime); result.Add(new PricingValue() { Currency = currency, Good = pricingValue.Good, Fee = feeInVoucherCurrency }); } return result; }
//================================================================================ private void validateGoodUnitInCompany(Company company, Good good, GoodUnit unit) { if (!(good.CompanyId == company.Id && good.GoodUnits.Count(gu => gu.Id == unit.Id) == 1)) throw new BusinessRuleException("", string.Format("Selected Good '{0}' and Unit is not defined for Company.", good.Name)); }
//================================================================================ public bool IsOffhireRegistered(long referenceNumber, Company introducer) { return this.offhireRepository.Count(o => o.ReferenceNumber == referenceNumber && o.Introducer.Id == introducer.Id) > 0; }
//================================================================================ public string GetCharteringReferenceNumber(Company company, VesselInCompany vesselInCompany, CharteringPartyType partyType, DateTime date) { var charterContract = this.GetCharterContract(company, vesselInCompany, partyType, date); switch (partyType) { case CharteringPartyType.ShipOwner: //If the given company is in the role of ShipOwner, it will be inferred that //the pricing type must be fetched from Charter-Out contract. return charterContract.Id.ToString(); case CharteringPartyType.Charterer: //If the given company is in the role of Charterer, it will be inferred that //the pricing type must be fetched from Charter-In contract. return charterContract.Id.ToString(); default: throw new ArgumentOutOfRangeException("partyType"); } }
//================================================================================ public Charter GetCharterContract(Company introducer, VesselInCompany vesselInCompany, CharteringPartyType introducerType, DateTime stratDate) { switch (introducerType) { case CharteringPartyType.ShipOwner: //If the given company is in the role of ShipOwner, it will be inferred that //the pricing type must be fetched from Charter-Out contract. var foundCharterOut = charteringDomainService.GetCharterOutStart(introducer, vesselInCompany, stratDate); //TODO: State of CharterOut must be submitted. if (foundCharterOut == null /*|| foundCharterOut.State != States.Submitted*/) throw new BusinessRuleException("CharterOutForPricingType", "Charter-Out contract not found."); return foundCharterOut; case CharteringPartyType.Charterer: //If the given company is in the role of Charterer, it will be inferred that //the pricing type must be fetched from Charter-In contract. var foundCharterIn = charteringDomainService.GetCharterInStart(introducer, vesselInCompany, stratDate); if (foundCharterIn == null /*|| foundCharterIn.State != States.Submitted*/) throw new BusinessRuleException("CharterInForPricingType", "Charter-In contract not found."); return foundCharterIn; default: throw new InvalidArgument("IntroducerType"); } }
//================================================================================ public Offhire GetCompanyValidOffhire(Company company, VesselInCompany vesselInCompany, DateTime startDate) { ISingleResultFetchStrategy<Offhire> fetchStrategy = new SingleResultFetchStrategy<Offhire>() .Include(o => o.OffhireDetails); var offhire = offhireRepository.Single(o => o.Introducer.Id == company.Id && o.VesselInCompany.Id == vesselInCompany.Id && o.StartDateTime == startDate, fetchStrategy); if (offhire == null) throw new ObjectNotFound("CompanyValidOffhire"); //this.offhireConfigurator.Configure(offhire); if (!this.isOffhireSubmitted.IsSatisfiedBy(offhire)) throw new BusinessRuleException("", "No valid Offhire for Company found."); return offhire; }
public Voyage GetVoyage(Company company, DateTime date) { var voyage = this.voyageRepository.First(v => v.VesselInCompany.CompanyId == company.Id && v.StartDate <= date && v.EndDate >= date); return voyage; }
//================================================================================ private void validateVesselInCompanyExistance(DomainObjects.VesselInCompany vesselInCompany, Company introducer, ICompanyDomainService companyDomainService) { var vessels = companyDomainService.GetCompanyVessels(introducer.Id); if (vessels.Count(v => v.Id == vesselInCompany.Id) != 1) throw new BusinessRuleException("", "The vessel is not assigned to company."); }