90 lines
5.9 KiB
C#
90 lines
5.9 KiB
C#
using NTP.Application.Common;
|
|
|
|
namespace NTP.Application.Refinery.Trips;
|
|
|
|
/// <summary>Configuration of the trips slice (section "Refinery:Trips").</summary>
|
|
public sealed class TripOptions
|
|
{
|
|
public const string SectionName = "Refinery:Trips";
|
|
|
|
/// <summary>
|
|
/// Largest net wage a payment action accepts (legacy application.REFINERY_MAX_PAYMENT_AMOUNT, defined outside the repository;
|
|
/// the caption ERROR.PAYMENT_ISNOT_ALLOW_FOR_BIG_AMOUNT says 500 dinars). UNVERIFIED default.
|
|
/// </summary>
|
|
public decimal MaxPaymentAmount { get; set; } = 500m;
|
|
}
|
|
|
|
/// <summary>Reads <see cref="TripOptions"/> (Application has no Options package; implemented in Infrastructure).</summary>
|
|
public interface ITripSettingsService
|
|
{
|
|
TripOptions Value { get; }
|
|
}
|
|
|
|
public sealed record TripLock(string? StatusCode, int DieselCharge);
|
|
|
|
public sealed record CardInfo(long Id, decimal CurrentBalance);
|
|
|
|
/// <summary>Data access of the refinery trips (REFINERY_TRIPS and its view, cards, logs, DB functions).</summary>
|
|
public interface ITripRepository
|
|
{
|
|
// ---- reads
|
|
Task<PagedResult<TripRow>> SearchAsync(TripQuery query, PageRequest page, CancellationToken ct = default);
|
|
Task<TripRecord?> GetAsync(long id, CancellationToken ct = default);
|
|
/// <summary>SELECT ... FOR UPDATE of the trip (inside a transaction): serialises two operators acting on the same trip.</summary>
|
|
Task<TripLock?> LockAsync(long id, CancellationToken ct = default);
|
|
Task<TripWallet?> GetActiveWalletByTruckAsync(string tn, CancellationToken ct = default);
|
|
Task<TripWallet?> GetWalletAsync(long walletId, CancellationToken ct = default);
|
|
/// <summary>REFINERY_VARIABLES AUTDIT_MODE = 1 (legacy checkAuditMode).</summary>
|
|
Task<bool> GetAuditModeAsync(CancellationToken ct = default);
|
|
/// <summary>FIRST_ADVANCE_PAYMENT valid today (legacy getFirstPaymentValue).</summary>
|
|
Task<decimal?> GetFirstPaymentValueAsync(CancellationToken ct = default);
|
|
/// <summary>All KEY_NAME / KEY_VALUE of the variables valid on the (truncated) loading date.</summary>
|
|
Task<IReadOnlyList<KeyValuePair<string, string?>>> GetVariablesAsync(DateTime loadingDate, CancellationToken ct = default);
|
|
/// <summary>WATER_FLAG of the trip, or null when the column does not exist yet in this database / is empty.</summary>
|
|
Task<int?> GetWaterFlagAsync(long id, CancellationToken ct = default);
|
|
/// <summary>CalculateRefinaryDiesel(id); null when the function finds no price (ORA-01403).</summary>
|
|
Task<decimal?> CalculateDieselAsync(long id, CancellationToken ct = default);
|
|
/// <summary>CalculateRefinaryAmount(id); null when the function finds no price (ORA-01403).</summary>
|
|
Task<decimal?> CalculateAmountAsync(long id, CancellationToken ct = default);
|
|
Task<bool> HasTransferLogAsync(long id, CancellationToken ct = default);
|
|
Task<IReadOnlyList<TripRecord>> GetTripsOfPeriodAsync(DateTime from, DateTime to, CancellationToken ct = default);
|
|
|
|
// ---- diesel cards
|
|
Task<CardInfo?> GetActiveCardAsync(string tn, CancellationToken ct = default);
|
|
Task<decimal?> GetLastCardLogAmountAsync(string pn, string methodName, CancellationToken ct = default);
|
|
Task InsertCardLogAsync(long cardId, string methodName, decimal before, decimal after, decimal amount, string userId, string pn, CancellationToken ct = default);
|
|
Task UpdateCardBalanceAsync(long cardId, decimal balance, string userId, long tripId, CancellationToken ct = default);
|
|
|
|
// ---- writes on the trip
|
|
Task MarkFirstAdvanceAsync(long id, string userId, CancellationToken ct = default);
|
|
Task MarkSecondAdvanceAsync(long id, string userId, decimal secondPaymentValue, CancellationToken ct = default);
|
|
Task MarkAdvanceReversedAsync(long id, string userId, int dieselCharge, CancellationToken ct = default);
|
|
/// <summary>Legacy NetWageAmount: stores the computed figures on the trip.</summary>
|
|
Task SaveAmountsAsync(long id, string userId, TripAmounts amounts, CancellationToken ct = default);
|
|
/// <summary>RECEIPT (READY_TO_PAY) and EXCHANGE_AUDIT (PENDING_EXCHANGE): new status + received by / date.</summary>
|
|
Task SetStatusReceivedAsync(long id, string userId, string status, CancellationToken ct = default);
|
|
/// <summary>Status EXCHANGED. <paramref name="setReceived"/> also fills RECEIVED_BY/DATE (not done by the bank-transfer PAYMENT).</summary>
|
|
Task MarkExchangedAsync(long id, string userId, string? remarks, string? paymentOptions, bool setReceived, long? walletId, CancellationToken ct = default);
|
|
Task<decimal> BumpDinarakReferenceAsync(long id, string userId, CancellationToken ct = default);
|
|
Task SetVoucherSerialAsync(long id, long serial, CancellationToken ct = default);
|
|
/// <summary>Legacy DAO.CONFIRM_EXCHANGE: EXCHANGED with wallet / user / date taken from the last Dinarak log and EXCHANGE log rows.</summary>
|
|
Task ConfirmExchangeAsync(long id, string userId, CancellationToken ct = default);
|
|
|
|
// ---- history
|
|
Task InsertLogAsync(long tripId, string methodName, string userId, string oldJson, string newJson, CancellationToken ct = default);
|
|
Task<PagedResult<TripLogRow>> SearchLogAsync(long tripId, PageRequest page, CancellationToken ct = default);
|
|
|
|
// ---- reports
|
|
Task<IReadOnlyList<TripReportRow>> ReportAsync(TripQuery query, CancellationToken ct = default);
|
|
Task<IReadOnlyList<DieselReportRow>> DieselReportAsync(DieselReportQuery query, CancellationToken ct = default);
|
|
Task<IReadOnlyList<CardRow>> CardsAsync(string? tn, CancellationToken ct = default);
|
|
Task<IReadOnlyList<TripReportRow>> BankReportAsync(BankReportQuery query, CancellationToken ct = default);
|
|
}
|
|
|
|
/// <summary>Voucher serial of the cash voucher (NTP.SYSTEM_VARIABLES VOUCHER_SERIAL_NO, legacy GenerateSerialNumber('VOUCHER')). NTP-schema connection.</summary>
|
|
public interface IVoucherSerialRepository
|
|
{
|
|
/// <summary>Takes the next number (locks the row until commit) and returns <c>{yyyy}{seq:00000}</c> as a number.</summary>
|
|
Task<long> NextAsync(CancellationToken ct = default);
|
|
}
|