import { BankAccount } from "@/types/Accounts/BankAccount"; import { getDatesForTimePeriod } from "@/lib/date"; import { atom } from "jotai"; import { atomWithStorage, createJSONStorage } from "jotai/utils"; import { atomFamily } from 'jotai-family' import { UnreconciledTransaction } from "./utils"; import { BankTransaction } from "@/types/Accounts/BankTransaction"; import { PaymentEntry } from "@/types/Accounts/PaymentEntry"; import { JournalEntry } from "@/types/Accounts/JournalEntry"; export interface SelectedBank extends Pick { logo?: string, logoDark?: string, darkModeInvert?: boolean, logoClassName?: string, account_currency?: string } export const selectedBankAccountAtom = atomWithStorage('bank-rec-selected-bank', null, undefined, { getOnInit: true }) export const bankRecDateAtom = atomWithStorage<{ fromDate: string, toDate: string }>("bank-rec-date", { fromDate: getDatesForTimePeriod('This Month').fromDate, toDate: getDatesForTimePeriod('This Month').toDate }) // eslint-disable-next-line @typescript-eslint/no-unused-vars export const bankRecClosingBalanceAtom = atomFamily((_id: string) => { return atom<{ value: number, stringValue: string | number | undefined }>({ value: 0, stringValue: '0.00' }) }) // eslint-disable-next-line @typescript-eslint/no-unused-vars export const bankRecSelectedTransactionAtom = atomFamily((_id: string) => { return atom([]) }) /** Action Modals */ export const bankRecTransferModalAtom = atom(false) export const bankRecRecordPaymentModalAtom = atom(false) export const bankRecRecordJournalEntryModalAtom = atom(false) export const bankRecUnreconcileModalAtom = atom('') export const bankRecMatchFilters = atomWithStorage('bank-rec-match-filters', ['payment_entry', 'journal_entry']) export const bankRecSearchText = atom('') export const bankRecAmountFilter = atom<{ value: number, stringValue?: string | number }>({ value: 0, stringValue: '0.00' }) export const bankRecTransactionTypeFilter = atom('All') export interface ActionLog { type: 'match' | 'payment' | 'transfer' | 'bank_entry' isBulk: boolean timestamp: number, items: ActionLogItem[], bulkCommonData?: { party_type?: string, party?: string, account?: string, bank_account?: string, } } export interface ActionLogItem { bankTransaction: BankTransaction, voucher: { reference_doctype: string, reference_name: string, reference_no?: string, reference_date?: string, posting_date: string, doc?: PaymentEntry | JournalEntry }, } const actionLogStorage = createJSONStorage(() => sessionStorage) export const bankRecActionLog = atomWithStorage('bank-rec-action-log', [], actionLogStorage, { getOnInit: true, })