import { ClsService } from 'nestjs-cls';
import { PaymentSettlementRepository } from './repositories/payment-settlement.repository';
import { SettlementPaymentRepository } from './repositories/settlement-payment.repository';
import { BookingSettlementMasterRepository } from './repositories/booking-settlement-master.repository';
import { SettlementAnalyticsRepository } from './repositories/settlement-analytics.repository';
import { PaymentSettlementEntity } from '../../entities/payment-settlement.entity';
import { BookingSettlementMasterEntity } from '../../entities/booking-settlement-master.entity';
import { SettlementPaymentEntity, SettlementPaymentMode } from '../../entities/settlement-payment.entity';
import { SettlementPaymentType } from '../../common/constants/settlement-payment-type';
import { BookingPaymentStatus } from '../../entities/booking.entity';
import { TaxSlabResolverService } from '../../common/services/tax-slab-resolver.service';
import { Repository } from 'typeorm';
import { BookingEntity } from '../../entities/booking.entity';
import { QueryEntity } from '../../entities/query.entity';
import { PaymentCollectionRepository } from './repositories/payment-collection.repository';
import { CustomerCreditLedgerRepository } from './repositories/customer-credit-ledger.repository';
import { SupplierPayoutRepository } from './repositories/supplier-payout.repository';
import { PayoutExcessTreatment, SupplierPayoutEntity } from '../../entities/supplier-payout.entity';
import { PaymentCollectionEntity, CollectionExcessTreatment, CollectionPartyType } from '../../entities/payment-collection.entity';
import { BankAccountService } from '../bank-account/bank-account.service';
export interface RecordPaymentInput {
    paid_amount: number;
    paid_date: string;
    mode: SettlementPaymentMode;
    ref_no?: string | null;
    notes?: string | null;
}
export interface SettlementBreakdown {
    added?: Array<Record<string, unknown>>;
    dropped?: Array<Record<string, unknown>>;
    modified?: Array<Record<string, unknown>>;
}
interface RecordFromBookingInput {
    booking_id: string;
    amount: number;
    currency_id: string;
    due_date: string;
}
interface RecordDeltaInput {
    booking_id: string;
    delta: number;
    currency_id: string;
    due_date: string;
    breakdown?: SettlementBreakdown | null;
    source?: string;
    triggered_by_change_request_id?: string | null;
}
interface RecordSupplierPayableInput {
    booking_id: string;
    supplier_id: string;
    amount: number;
    currency_id: string;
    due_date: string;
    source_item_type: string;
    source_item_id: string;
}
export interface CollectOutstandingBookingRow {
    booking_id: string;
    booking_number: string | null;
    guest_name: string | null;
    guest_mobile: string | null;
    travel_date: string | null;
    travel_end_date: string | null;
    due_date: string;
    amount: number;
    amount_settled: number;
    outstanding: number;
    currency_id: string;
    currency_code: string;
    destination_id: string | null;
    destination_name: string | null;
    has_pan_card: boolean;
    lines: Array<{
        settlement_id: string;
        outstanding: number;
        due_date: string;
    }>;
}
export declare class PaymentSettlementService {
    private readonly settlements;
    private readonly payments;
    private readonly masters;
    private readonly analytics;
    private readonly cls;
    private readonly taxResolver;
    private readonly bookingRepo;
    private readonly queryRepo;
    private readonly collections;
    private readonly creditLedger;
    private readonly payouts;
    private readonly bankAccounts;
    constructor(settlements: PaymentSettlementRepository, payments: SettlementPaymentRepository, masters: BookingSettlementMasterRepository, analytics: SettlementAnalyticsRepository, cls: ClsService, taxResolver: TaxSlabResolverService, bookingRepo: Repository<BookingEntity>, queryRepo: Repository<QueryEntity>, collections: PaymentCollectionRepository, creditLedger: CustomerCreditLedgerRepository, payouts: SupplierPayoutRepository, bankAccounts: BankAccountService);
    private resolvePaymentSnapshot;
    aggregateBySupplier(opts: Parameters<SettlementAnalyticsRepository['bySupplier']>[0]): Promise<{
        items: Array<{
            supplier_id: string;
            supplier_name: string;
            bookings_count: number;
            total_owed: number;
            total_paid: number;
            outstanding: number;
            oldest_unsettled_booking: {
                booking_number: string;
                created_at: string;
            } | null;
        }>;
        meta: {
            total: number;
            page: number;
            limit: number;
            totalPages: number;
        };
    }>;
    aggregateByAgent(opts: Parameters<SettlementAnalyticsRepository['byAgent']>[0]): Promise<{
        items: Array<{
            sales_agent_id: string;
            agent_name: string;
            bookings_count: number;
            total_billed: number;
            total_collected: number;
            total_supplier_owed: number;
            total_supplier_paid: number;
            realised_margin: number;
        }>;
        meta: {
            total: number;
            page: number;
            limit: number;
            totalPages: number;
        };
    }>;
    aggregateBySource(opts: Parameters<SettlementAnalyticsRepository['bySource']>[0]): Promise<{
        items: Array<{
            source_id: string;
            source_name: string;
            bookings_count: number;
            total_billed: number;
            total_collected: number;
            total_supplier_owed: number;
            total_supplier_paid: number;
            realised_margin: number;
        }>;
        meta: {
            total: number;
            page: number;
            limit: number;
            totalPages: number;
        };
    }>;
    aggregateByService(opts: Parameters<SettlementAnalyticsRepository['byService']>[0]): Promise<{
        items: Array<{
            source_item_type: string;
            service_id: string;
            service_name: string;
            bookings_sold: number;
            total_selling: number;
            total_cost: number;
            outstanding: number;
            margin: number;
            margin_pct: number | null;
        }>;
        meta: {
            total: number;
            page: number;
            limit: number;
            totalPages: number;
        };
    }>;
    findForBooking(bookingId: string): Promise<PaymentSettlementEntity[]>;
    findById(id: string): Promise<PaymentSettlementEntity | null>;
    findPayments(settlementId: string): Promise<SettlementPaymentEntity[]>;
    findPaginated(query: import('./dto/settlement-query.dto').SettlementQueryDto): Promise<{
        items: PaymentSettlementEntity[];
        meta: {
            total: number;
            page: number;
            limit: number;
            totalPages: number;
        };
    }>;
    findDetail(id: string): Promise<{
        settlement: PaymentSettlementEntity;
        payments: SettlementPaymentEntity[];
    } | null>;
    stats(from?: string, to?: string, destinationId?: string): Promise<{
        pending_collections: number;
        pending_refunds: number;
        settled_collections: number;
        settled_refunds: number;
        window: {
            from: string;
            to: string;
        };
    }>;
    editAmount(settlementId: string, newAmount: number, reason: string): Promise<PaymentSettlementEntity>;
    appendNote(settlementId: string, text: string): Promise<PaymentSettlementEntity>;
    private buildNoteAppend;
    exportToExcel(query: import('./dto/settlement-query.dto').SettlementQueryDto): Promise<Buffer<import("exceljs").Buffer>>;
    recordFromBooking(input: RecordFromBookingInput): Promise<PaymentSettlementEntity | null>;
    recordItineraryDelta(input: RecordDeltaInput): Promise<PaymentSettlementEntity | null>;
    recordPayment(settlementId: string, input: RecordPaymentInput): Promise<{
        settlement: PaymentSettlementEntity;
        payment: SettlementPaymentEntity;
    }>;
    recordSupplierPayable(input: RecordSupplierPayableInput): Promise<PaymentSettlementEntity | null>;
    adjustSupplierPayable(input: {
        booking_id: string;
        supplier_id: string;
        source_item_type: string;
        source_item_id: string;
        new_amount: number;
        currency_id: string;
        due_date: string;
    }): Promise<PaymentSettlementEntity | null>;
    voidPayment(paymentId: string, reason: string): Promise<{
        settlement: PaymentSettlementEntity;
        payment: SettlementPaymentEntity;
    }>;
    recomputeBookingPaymentStatus(bookingId: string): Promise<BookingPaymentStatus>;
    ensureMaster(input: {
        booking_id: string;
        currency_id: string;
    }): Promise<BookingSettlementMasterEntity>;
    recomputeMaster(masterId: string): Promise<BookingSettlementMasterEntity | null>;
    placeOnHold(masterId: string, reason: string): Promise<BookingSettlementMasterEntity>;
    releaseHold(masterId: string): Promise<BookingSettlementMasterEntity>;
    findMasterPaginated(query: import('./dto/master-list-query.dto').MasterListQueryDto): Promise<{
        items: BookingSettlementMasterEntity[];
        meta: {
            total: number;
            page: number;
            limit: number;
            totalPages: number;
        };
    }>;
    findMasterDetail(id: string): Promise<{
        master: BookingSettlementMasterEntity;
        children: PaymentSettlementEntity[];
    } | null>;
    private assertMasterNotOnHold;
    private snapshotSalesAgent;
    findCustomerOutstanding(input: {
        mobile: string;
        currency_id?: string;
        exclude_collection_id?: string;
    }): Promise<CollectOutstandingBookingRow[]>;
    assertExactCollectAllocations(input: {
        party_type?: CollectionPartyType;
        customer_mobile?: string | null;
        source_id?: string | null;
        customer_name?: string | null;
        payment_date: string;
        mode: SettlementPaymentMode;
        currency_id: string;
        received_amount: number;
        allocations: Array<{
            settlement_id: string;
            amount: number;
        }>;
    }): Promise<void>;
    resolveCollectBankAccountIds(input: {
        mode: SettlementPaymentMode;
        debit_bank_account_id?: string | null;
        credit_bank_account_id?: string | null;
    }): Promise<{
        debit_bank_account_id: string | null;
        credit_bank_account_id: string | null;
    }>;
    collectPayment(input: {
        party_type?: CollectionPartyType;
        customer_mobile?: string | null;
        source_id?: string | null;
        customer_name?: string | null;
        payment_date: string;
        payment_type?: SettlementPaymentType | null;
        mode: SettlementPaymentMode;
        ref_no?: string | null;
        debit_bank_account_id?: string | null;
        credit_bank_account_id?: string | null;
        currency_id: string;
        received_amount: number;
        receive_currency_id?: string | null;
        exchange_rate?: number | null;
        exchange_rate_quote?: number | null;
        received_amount_receive_currency?: number | null;
        roe?: number | null;
        credit_applied?: number | null;
        allocations: Array<{
            settlement_id: string;
            amount: number;
        }>;
        excess_treatment?: CollectionExcessTreatment | null;
        notes?: string | null;
        collected_by_type?: 'OWN' | 'SUPPLIER' | null;
        collector_name?: string | null;
        collector_supplier_id?: string | null;
        collector_driver_id?: string | null;
    }): Promise<{
        collection: PaymentCollectionEntity;
        payments: SettlementPaymentEntity[];
    }>;
    findCollectionDetail(id: string): Promise<{
        collection: PaymentCollectionEntity & {
            source_name?: string | null;
            debit_bank_name?: string | null;
            debit_account_name?: string | null;
            credit_bank_name?: string | null;
            credit_account_name?: string | null;
        };
        payments: Array<SettlementPaymentEntity & {
            booking_number: string | null;
            source_item_type: string | null;
            service_name: string | null;
            travel_date: string | null;
            guest_name: string | null;
        }>;
    } | null>;
    findCustomerBalance(input: {
        mobile: string;
        currency_id?: string;
    }): Promise<{
        mobile: string;
        currency_id: string | null;
        expected: number;
        received: number;
        balance: number;
        credit: number;
    }>;
    searchCustomersByName(input: {
        q: string;
    }): Promise<Array<{
        guest_name: string;
        guest_mobile: string;
        guest_email: string | null;
    }>>;
    findSourceOutstanding(input: {
        source_id: string;
        currency_id?: string;
        exclude_collection_id?: string;
    }): Promise<CollectOutstandingBookingRow[]>;
    findSourceBalance(input: {
        source_id: string;
        currency_id?: string;
    }): Promise<{
        source_id: string;
        currency_id: string | null;
        expected: number;
        received: number;
        balance: number;
        credit: number;
    }>;
    findSupplierOutstanding(input: {
        supplier_id: string;
        currency_id?: string;
    }): Promise<Array<{
        settlement_id: string;
        booking_id: string;
        booking_number: string | null;
        guest_name: string | null;
        service_type: string | null;
        source_item_type: string | null;
        service_date: string | null;
        due_date: string;
        amount: number;
        amount_settled: number;
        outstanding: number;
        currency_id: string;
        currency_code: string;
        destination_name: string | null;
    }>>;
    findSupplierBalance(input: {
        supplier_id: string;
        currency_id?: string;
    }): Promise<{
        supplier_id: string;
        currency_id: string | null;
        expected: number;
        received: number;
        balance: number;
        credit: number;
    }>;
    paySupplier(input: {
        supplier_id: string;
        supplier_name?: string | null;
        payment_date: string;
        payment_type?: SettlementPaymentType | null;
        mode: SettlementPaymentMode;
        ref_no?: string | null;
        debit_bank_account_id?: string | null;
        credit_bank_account_id?: string | null;
        currency_id: string;
        paid_amount: number;
        credit_applied?: number | null;
        allocations: Array<{
            settlement_id: string;
            amount: number;
        }>;
        excess_treatment?: PayoutExcessTreatment | null;
        notes?: string | null;
    }): Promise<{
        payout: SupplierPayoutEntity;
        payments: SettlementPaymentEntity[];
    }>;
    private applyPayoutLedger;
    findPayoutDetail(id: string): Promise<{
        payout: SupplierPayoutEntity & {
            debit_bank_name?: string | null;
            debit_account_name?: string | null;
            credit_bank_name?: string | null;
            credit_account_name?: string | null;
        };
        payments: Array<SettlementPaymentEntity & {
            booking_number: string | null;
            source_item_type: string | null;
            travel_date: string | null;
            guest_name: string | null;
        }>;
    } | null>;
    listOfficePaymentHistory(query: {
        search?: string;
        customer_mobile?: string;
        source_id?: string;
        page?: number;
        limit?: number;
        date_from?: string;
        date_to?: string;
        currency_id?: string;
    }): Promise<{
        items: PaymentHistoryListRow[];
        meta: PaymentHistoryListMeta;
    }>;
    findOfficeHistoryDetail(id: string): Promise<PaymentHistoryDetail | null>;
    updateCollection(id: string, input: {
        payment_date: string;
        mode: SettlementPaymentMode;
        ref_no?: string | null;
        debit_bank_account_id?: string | null;
        credit_bank_account_id?: string | null;
        currency_id: string;
        received_amount: number;
        receive_currency_id?: string | null;
        exchange_rate?: number | null;
        exchange_rate_quote?: number | null;
        received_amount_receive_currency?: number | null;
        roe?: number | null;
        credit_applied?: number | null;
        allocations: Array<{
            settlement_id: string;
            amount: number;
        }>;
        excess_treatment?: CollectionExcessTreatment | null;
        notes?: string | null;
        collected_by_type?: 'OWN' | 'SUPPLIER' | null;
        collector_name?: string | null;
        collector_supplier_id?: string | null;
        collector_driver_id?: string | null;
    }): Promise<PaymentHistoryDetail>;
    private rewindSettlementPaid;
    private reverseCreditLedgerForCollection;
    private loadAndValidateAllocations;
    private applyCollectionLedger;
}
export interface PaymentHistoryListRow {
    id: string;
    payment_date: string;
    party_type: CollectionPartyType;
    party_name: string;
    payment_type: SettlementPaymentType;
    receive_currency_code: string;
    received_amount: number;
    posted: boolean;
}
export interface PaymentHistoryListMeta {
    total: number;
    page: number;
    limit: number;
    totalPages: number;
}
export interface PaymentHistoryDetail {
    kind: 'OFFICE' | 'MD';
    id: string;
    posted: boolean;
    payment_collection_id: string | null;
    receipt_no: string | null;
    party_type: CollectionPartyType;
    customer_mobile: string | null;
    source_id: string | null;
    source_name: string | null;
    customer_name: string | null;
    payment_date: string;
    payment_type: SettlementPaymentType;
    mode: SettlementPaymentMode;
    ref_no: string | null;
    debit_bank_account_id: string | null;
    credit_bank_account_id: string | null;
    currency_id: string;
    receive_currency_id: string | null;
    exchange_rate: number | null;
    exchange_rate_quote: number | null;
    received_amount: number;
    received_amount_receive_currency: number | null;
    roe: number | null;
    credit_applied: number;
    excess_treatment: CollectionExcessTreatment | null;
    notes: string | null;
    collected_by_type: 'OWN' | 'SUPPLIER' | null;
    collector_name: string | null;
    collector_supplier_id: string | null;
    collector_driver_id: string | null;
    md_booking_id: string | null;
    md_transport_item_id: string | null;
    payments: Array<{
        settlement_id: string;
        paid_amount: number;
        booking_id: string | null;
        booking_number: string | null;
        guest_name: string | null;
        guest_mobile: string | null;
        travel_date: string | null;
    }>;
}
export declare function normaliseMobileForLedger(raw: string): string;
export {};
