NTP_V2/src/NTP.Application/Grains/Permits/PermitContracts.cs

619 lines
23 KiB
C#

namespace NTP.Application.Grains.Permits;
// ---------------------------------------------------------------------------------------------------------------
// Shared result type
// ---------------------------------------------------------------------------------------------------------------
/// <summary>
/// Result of a write operation. <c>Message</c> is the legacy Arabic text; <c>Success=false</c> is a business outcome
/// that legacy returned as a normal response (not an exception), e.g. "no destination available".
/// </summary>
public sealed record PermitOperationResult(bool Success, string Message, string? Code = null, long? PermitId = null,
IReadOnlyDictionary<string, object?>? Data = null)
{
public static PermitOperationResult Ok(string message, long? permitId = null, IReadOnlyDictionary<string, object?>? data = null) =>
new(true, message, null, permitId, data);
public static PermitOperationResult Fail(string code, string message, long? permitId = null) =>
new(false, message, code, permitId);
public const string DefaultOk = "تمت العملية بنجاح";
}
// ---------------------------------------------------------------------------------------------------------------
// Permit list / detail
// ---------------------------------------------------------------------------------------------------------------
/// <summary>getGNPermits filters (strFilter keys). Dates: creationDate = yyyy-MM-dd, tenderOrder = dd/MM/yyyy.</summary>
public sealed record PermitSearchQuery(
string? Tn = null, string? Pn = null, string? Status = null, long? DestAddressId = null,
string? TenderOrder = null, string? ShipmentMode = null, string? CreationDate = null, long? CompanyCode = null)
{
public bool HasFilter => !string.IsNullOrWhiteSpace(Tn) || !string.IsNullOrWhiteSpace(Pn) || !string.IsNullOrWhiteSpace(Status)
|| DestAddressId.HasValue || !string.IsNullOrWhiteSpace(TenderOrder) || !string.IsNullOrWhiteSpace(ShipmentMode)
|| !string.IsNullOrWhiteSpace(CreationDate) || CompanyCode.HasValue;
}
public sealed class PermitListItem
{
public long Id { get; set; }
public string? Pn { get; set; }
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? TrackingNo { get; set; }
public DateTime? CreationDate { get; set; }
public string? DestinationName { get; set; }
public string? Drvr { get; set; }
public string? CompName { get; set; }
public string? StatusCaption { get; set; }
public string? ShipmentStatusCode { get; set; }
public long? CompanyCode { get; set; }
public string? QueueNo { get; set; }
/// <summary>Calculated by the service: which action buttons the caller may use on this row.</summary>
public IReadOnlyList<string> Actions { get; set; } = [];
}
/// <summary>getGNList (permitsGrid.cfm): gate/clearance list.</summary>
public sealed record GatePermitQuery(string? Tn, string? Trn, string? Pn);
public sealed class GatePermitItem
{
public long Id { get; set; }
public string? PermNo { get; set; }
public string? Tn { get; set; }
public string? Drvr { get; set; }
public string? ShipmentMode { get; set; }
public string? ShipmentStatusCode { get; set; }
public string? StatusName { get; set; }
public long? CompanyCode { get; set; }
public string? CreatedBy { get; set; }
public string? LastUpdateDate { get; set; }
public string? FinalDestination { get; set; }
}
public sealed class PermitRow
{
public long Id { get; set; }
public string? Pn { get; set; }
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? Nnpn { get; set; }
public string? Drvr { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
public string? Tt { get; set; }
public string? ShipmentStatusCode { get; set; }
public long? CompanyCode { get; set; }
public long? Scrn { get; set; }
public long? Crn { get; set; }
public long? TrackingNo { get; set; }
public long? TripCounter { get; set; }
public string? InbondTypeCode { get; set; }
public long? OriginAddressId { get; set; }
public long? DestinationAddressId { get; set; }
public string? ShipmentMode { get; set; }
public string? IsActive { get; set; }
public string? Notes { get; set; }
public long? Firms { get; set; }
public string? DrvrMobile { get; set; }
public DateTime? CreationDate { get; set; }
}
public sealed class PermitInfoRow
{
public string? Pn { get; set; }
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? Nnpn { get; set; }
public string? ShipmentStatusCode { get; set; }
public string? Tt { get; set; }
public string? InbondTypeCode { get; set; }
public string? CargoTypeName { get; set; }
public string? QueueNo { get; set; }
public long? MobileShift { get; set; }
public long? CompanyCode { get; set; }
public string? CompanyName { get; set; }
public string? StatusCaption { get; set; }
public long? OrderId { get; set; }
}
public sealed class TruckInfoRow
{
public string? Tn { get; set; }
public string? ChasesNumber { get; set; }
public DateTime? RegDate { get; set; }
public string? Axials { get; set; }
}
public sealed class DriverInfoRow
{
public string? Nnpn { get; set; }
public string? Name { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
}
public sealed record TruckInfoDto(string Tn, string? ChasesNumber, string? Axials, string? RegDate);
public sealed record TrailerInfoDto(string Trn, string? ChasesNumber, string? Axials, string? RegDate);
public sealed record DriverInfoDto(string Nnpn, string? Name, string? Dln, string? Dled);
public sealed class PermitEventDto
{
public DateTime? EventDate { get; set; }
public string? EventType { get; set; }
public string? EventCaption { get; set; }
public string? DoneBy { get; set; }
public string? CurrentStatusCode { get; set; }
public string? CurrentStatus { get; set; }
public decimal? Weight { get; set; }
public string? Remarks { get; set; }
}
public sealed class PermitDetailDto
{
public long Id { get; set; }
public string? Pn { get; set; }
public string? StatusCode { get; set; }
public string? StatusCaption { get; set; }
public string? CompanyName { get; set; }
public long? CompanyCode { get; set; }
public string? QueueNo { get; set; }
public string? Shift { get; set; }
public string? CargoType { get; set; }
public string? OperationType { get; set; }
public string? OperationTypeCode { get; set; }
public TruckInfoDto? Truck { get; set; }
public TruckInfoDto? Trailer { get; set; }
public DriverInfoDto? Driver { get; set; }
public IReadOnlyList<string> Actions { get; set; } = [];
public IReadOnlyList<PermitEventDto> Events { get; set; } = [];
}
// ---------------------------------------------------------------------------------------------------------------
// Order requests (submitOrder / updateOrder / phone / weights ...)
// ---------------------------------------------------------------------------------------------------------------
public sealed record SubmitOrderRequest(string Tn, string Trn, string Nnpn, string Dln, string? Dled, string Name, string OpType);
public sealed record UpdateOrderRequest(string Tn, string Trn, string Nnpn, string Dln, string? Dled, string Name);
public sealed record ReasonRequest(string Reason);
public sealed record PhoneAcceptRequest(string? Remarks);
public sealed record PhoneRejectRequest(string Reason, int ExpiryDays);
public sealed record ClosePermitRequest(string Pn);
public sealed record SaveWeightsRequest(string Pn, string EmptyWeight, string GrossWeight, string DocumentNumber);
public sealed class StoredWeightsDto
{
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? Drvr { get; set; }
public string? EmptyWeight { get; set; }
public string? GrossWeight { get; set; }
public string? DocumentNumber { get; set; }
}
public sealed record AbsenceFeatureDto(bool Enabled);
// ---------------------------------------------------------------------------------------------------------------
// Queue / TCS permit
// ---------------------------------------------------------------------------------------------------------------
public sealed record QueueSearchQuery(string? Tn, string? Pn);
public sealed class QueueItem
{
public long Id { get; set; }
public string? Tn { get; set; }
public string? Pn { get; set; }
public DateTime? CreationDate { get; set; }
}
/// <summary>AddToQueue (CreateQueue.cfm): create an OPEN permit record (turn) for a truck.</summary>
public sealed record AddToQueueRequest(string Tn, string Tt, bool CheckStatuses = false);
public sealed record SeedPermitsRequest(IReadOnlyList<SeedPermitItem> Items);
public sealed record SeedPermitItem(long Scac, string NextStatus, string Tt, int Count);
/// <summary>createPermit (createPermit.cfm): the TCS "grain permit" form.</summary>
public sealed record CreateTcsPermitRequest(
long Routing, string Tn, string TrnAt, string Trn, string Tt, string Asrn, string? Can, string Nnpn, string Drvr, string Dln,
string Cat, string? Dled, string Nat, string ShipmentMode, string InbondTypeCode, string Firms, long OriginAddressId,
long DestinationAddressId, long RoutingTemplateId, string? Fop);
public sealed class TcsFormDataDto
{
public string? Tn { get; set; }
public string? TrnAt { get; set; }
public string? Trn { get; set; }
public string? Tt { get; set; }
public string? Drvr { get; set; }
public string? Cat { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
public string? Nat { get; set; }
public string? Nnpn { get; set; }
public long? RoutingTemplateId { get; set; }
public long? OriginAddressId { get; set; }
public long? DestinationAddressId { get; set; }
public string? Firms { get; set; }
public string? Asrn { get; set; }
public string? Can { get; set; }
public string? CanName { get; set; }
}
public sealed class RoutingTemplateDto
{
public long Id { get; set; }
public string? RouteName { get; set; }
}
public sealed class LookupItem
{
public long Id { get; set; }
public string? Name { get; set; }
}
public sealed class CodeLookupItem
{
public string Code { get; set; } = string.Empty;
public string? Caption { get; set; }
}
public sealed class DestinationQuotaPick
{
public long DestId { get; set; }
public string? DestName { get; set; }
}
public sealed record TcsPermitRequest(
string Firms, string InbondTypeCode, long RoutingTemplateId, string ShipmentMode, long OriginAddressId, long DestinationAddressId,
string Asrn, string? Fop, string? SealN, string? Tst, string CanName, string? Can, string Tn, string Trn, string TrnAt, string Tt,
string Nnpn, string Nat, string Cat, string Dln, string Drvr, string UserId, string CompanyName);
public sealed record TcsPermitResult(string? PermitNumber, string? StatusCode, string Error)
{
public bool Success => string.IsNullOrEmpty(Error);
}
public sealed record TcsFopDetail(string Error, string? Tn, string? Trn, string? TrnAt, string? Tt, string? OriginAddressId,
string? Drvr, string? Nat, string? Nnpn, string? Dln, string? Cat, string? Dled);
// ---------------------------------------------------------------------------------------------------------------
// Destinations / orders
// ---------------------------------------------------------------------------------------------------------------
public sealed record AssignByPnRequest(string Pn, long DestId, long ShipmentMode);
public sealed record AssignDestinationRequest(string Tn);
public sealed record SaveCompanyDestinationsRequest(IReadOnlyList<long> Destinations);
public sealed record ManualInputRequest(string Pn, long OrderId, string OrderDate, decimal Ltw, decimal Lgw);
public sealed class AllowedDestinationDto
{
public long OrderId { get; set; }
public string? Name { get; set; }
public long? Dest { get; set; }
public string? OrderDate { get; set; }
}
public sealed class OrderChoiceDto
{
public long Id { get; set; }
public string? DestName { get; set; }
}
public sealed class AllowedCargoDto
{
public long Location { get; set; }
public long Ct { get; set; }
public decimal Q { get; set; }
}
public sealed class OrderDetailsDto
{
public long? CargoTypeCode { get; set; }
public string? CargoType { get; set; }
public string? Location { get; set; }
public long? LocationCode { get; set; }
public string? MobileShift { get; set; }
public string? OrderDate { get; set; }
public string? Ct { get; set; }
public string? CtCaption { get; set; }
}
public sealed class OrderActivationRow
{
public long LocId { get; set; }
public long CtId { get; set; }
public string? Loc { get; set; }
public string? Ct { get; set; }
public decimal Total { get; set; }
public decimal Used { get; set; }
public string? StatusCode { get; set; }
}
public sealed record ActivateOrdersRequest(IReadOnlyList<string> Selected);
public sealed record DestinationSearchResult(string? Destination, long? Origin, string? Message);
public sealed record AssignDestinationResult(bool Success, string Message);
// ---------------------------------------------------------------------------------------------------------------
// Distribution
// ---------------------------------------------------------------------------------------------------------------
public sealed record DistributeRequest(string Category);
public sealed record ReleasePermitRequest(string Pn, string Scac, string Category, string QueueType);
public sealed record OpenPermitRequest(string Tn, string? CargoType, bool SaveScrn = true);
public sealed record OpenPermitWithDestinationRequest(string Pn, long Locations, string OrderDate, bool ReservedQueue);
public sealed record CompanyOpenPermitsRequest(int Count);
public sealed record CheckTripsRequest(long PermitId, string Tn, int MaxTnCount);
public sealed class DistributionSummaryRow
{
public long? CompanyCode { get; set; }
public string? Comp { get; set; }
public long Cnt { get; set; }
}
public sealed class DistributionPivotRow
{
public long? CompanyCode { get; set; }
public string? Company { get; set; }
public long Silos { get; set; }
public long Direct { get; set; }
public long Packed { get; set; }
}
public sealed class TruckDistributionDto
{
public string Status { get; set; } = string.Empty;
public string CompanyLocations { get; set; } = string.Empty;
public string Order { get; set; } = string.Empty;
public string ErrorMsg { get; set; } = string.Empty;
public long TrucksTotalQuantity { get; set; }
public long TenderTotalQuantity { get; set; }
}
public sealed class BlacklistedDistributionDto
{
public long BlacklistId { get; set; }
public string? Text { get; set; }
public long? CargoType { get; set; }
}
// ---------------------------------------------------------------------------------------------------------------
// Weighbridge
// ---------------------------------------------------------------------------------------------------------------
public sealed record WeighbridgeReadingRequest(string Tn, long Weight);
public sealed record WeighbridgeWeightsRequest(string Tn, long GrossWeight, long TareWeight);
public sealed record ManualWeighbridgeRequest(string Tn, long LocationId, long WeightIn, long WeightOut);
/// <summary>ws.cfc addWeightBridgeEvent: weighbridge integration reading (EN/EX) at a location.</summary>
public sealed record WeighbridgeEventRequest(string Tn, long Weight, long LocationId, string EventDate, string TrxType, string? UserId);
public sealed class WeighbridgeResult
{
public bool Success { get; set; }
public string ErrorCode { get; set; } = "0";
public string Message { get; set; } = string.Empty;
public string? Action { get; set; }
public long? PermitId { get; set; }
}
public sealed class TruckPermitBriefDto
{
public long Id { get; set; }
public string? Drvr { get; set; }
public string? Tn { get; set; }
public string? Pn { get; set; }
public string? ShipmentStatusCode { get; set; }
}
public sealed class WaybridgeEventDto
{
public string? Tn { get; set; }
public decimal? Weight { get; set; }
}
public sealed class LocationTruckCountDto
{
public string? Loc { get; set; }
public long Cnt { get; set; }
}
public sealed class WeighbridgePermitRow
{
public long Id { get; set; }
public string? ShipmentStatusCode { get; set; }
public long? OriginAddressId { get; set; }
public long? DestinationAddressId { get; set; }
}
public sealed class WeighbridgeRawRow
{
public string RowId { get; set; } = string.Empty;
public long LocationId { get; set; }
public string? CargoTruckNo { get; set; }
public decimal CargoWeightIn { get; set; }
public decimal CargoWeightOut { get; set; }
public decimal CargoWeightNet { get; set; }
public string GinTime { get; set; } = string.Empty;
public string GoutTime { get; set; } = string.Empty;
}
/// <summary>A row read from the external weighbridge database (table CARGO).</summary>
public sealed class ExternalCargoRow
{
public long LocationId { get; set; }
public string? CargoKey { get; set; }
public string? CargoState { get; set; }
public DateTime? CargoTimeIn { get; set; }
public decimal CargoWeightIn { get; set; }
public DateTime? CargoTimeOut { get; set; }
public decimal CargoWeightOut { get; set; }
public decimal CargoWeightNet { get; set; }
public string? CargoType { get; set; }
public string? CargoTypeTxt { get; set; }
public string? CargoDriverName { get; set; }
public string? CargoTruckNo { get; set; }
public string? CargoSource { get; set; }
}
// ---------------------------------------------------------------------------------------------------------------
// Printing
// ---------------------------------------------------------------------------------------------------------------
public sealed class AcceptPrintDto
{
public long Id { get; set; }
public string? Pn { get; set; }
public string? ShipmentStatusCode { get; set; }
public string? Shift { get; set; }
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? Drvr { get; set; }
public string? CompName { get; set; }
public string? OperationType { get; set; }
public string? Destination { get; set; }
public string? CargoType { get; set; }
public string? Location { get; set; }
public string? NextPn { get; set; }
public long? Crn { get; set; }
public long? Scrn { get; set; }
public string PrintedAt { get; set; } = string.Empty;
public bool HasOrder => Scrn.HasValue;
}
public sealed class PrintHeaderRow
{
public string? TrackingNo { get; set; }
public string? CompName { get; set; }
public string? Drvr { get; set; }
public string? Nnpn { get; set; }
public string? Tn { get; set; }
public string? ShipmentMode { get; set; }
public string? Destination { get; set; }
public string? Origin { get; set; }
}
public sealed class PrintWeightEvent
{
public long Id { get; set; }
public long? LocationId { get; set; }
public string? LocationName { get; set; }
public string? DoneBy { get; set; }
public decimal? Weight { get; set; }
public string? EventType { get; set; }
}
public sealed class PrintInDto
{
public PrintHeaderRow Header { get; set; } = new();
public decimal LoadingTare { get; set; }
public decimal LoadingGross { get; set; }
public decimal DischargeTare { get; set; }
public decimal DischargeGross { get; set; }
public WeightFigures Loading { get; set; } = new();
public WeightFigures Discharge { get; set; } = new();
public long TonDifference { get; set; }
public long KiloDifference { get; set; }
public string Sign { get; set; } = " ";
public string? LoadingLocation { get; set; }
/// <summary>Officer of the receiving weighing (discharge gross), else of the first weighing found; legacy printed qry.doneby.</summary>
public string? DoneBy { get; set; }
public string? DischargeLocation { get; set; }
}
public sealed class WeightFigures
{
public long Net { get; set; }
public long Ton { get; set; }
public long Kilo { get; set; }
}
public sealed class PrintOutDto
{
public PrintHeaderRow Header { get; set; } = new();
public long NetWeight { get; set; }
public long Ton { get; set; }
public long Kilo { get; set; }
public string? Location { get; set; }
public string? DoneBy { get; set; }
}
public sealed class PermitDetailsPrintDto
{
public long Id { get; set; }
public string? Pn { get; set; }
public string? StatusCode { get; set; }
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? TruckNationality { get; set; }
public string? TrailerType { get; set; }
public string? DriverName { get; set; }
public string? Nnpn { get; set; }
public string? Dln { get; set; }
public string? Cat { get; set; }
public DateTime? Dled { get; set; }
public string? DriverNationality { get; set; }
public string? ShipmentMode { get; set; }
public string? Operation { get; set; }
public string? Lane { get; set; }
public string? Origin { get; set; }
public string? Destination { get; set; }
public string? RouteName { get; set; }
public IReadOnlyList<PermitEventDto> Events { get; set; } = [];
}
// ---------------------------------------------------------------------------------------------------------------
// Auto call
// ---------------------------------------------------------------------------------------------------------------
public sealed record AutoCallRequest(string? Tn, string? ShipmentStatusCode, string? DestAddressId, string? TenderOrder,
string? ShipmentMode, string? CompanyCode);
public sealed class AutoCallDriverRow
{
public string? Name { get; set; }
public string? Phone { get; set; }
public string? Code1 { get; set; }
public string? Code2 { get; set; }
public string? Number1 { get; set; }
public string? Number2 { get; set; }
public string? Number3 { get; set; }
public string? Number4 { get; set; }
public string? Number5 { get; set; }
public string? Item { get; set; }
public string? FromDist { get; set; }
public string? Origin { get; set; }
public string? Week { get; set; }
public string? Day { get; set; }
public string? Month { get; set; }
public long Id { get; set; }
public long? MobileShift { get; set; }
}
/// <summary>Body of the dialer's callback (autoDail): referenceId = PN, key = CONFIRMED | POSTPONED | NO_ANSWER.</summary>
public sealed record AutoCallResponse(string? ReferenceId, string? Key, string? Value);
public sealed record AutoCallCallbackResult(string Code, string Message);