// @ts-nocheck import React from 'react'; import { Intent, Tag, Menu, MenuItem, MenuDivider, ProgressBar, } from '@blueprintjs/core'; import intl from 'react-intl-universal'; import clsx from 'classnames'; import { CLASSES } from '@/constants/classes'; import { FormatDateCell, FormattedMessage as T, AppToaster, Choose, If, Icon, Can, } from '@/components'; import { formattedAmount, safeCallback, calculateStatus } from '@/utils'; import { SaleInvoiceAction, PaymentReceiveAction, AbilitySubject, } from '@/constants/abilityOption'; export function InvoiceStatus({ invoice }) { return ( {intl.get('overdue_by', { overdue: invoice.overdue_days })} {intl.get('due_in', { due: invoice.remaining_days })} {intl.get('day_partially_paid', { due: formattedAmount(invoice.due_amount, invoice.currency_code), })} ); } export const statusAccessor = (row) => { return (
); }; export const handleDeleteErrors = (errors) => { if ( errors.find( (error) => error.type === 'INVOICE_HAS_ASSOCIATED_PAYMENT_ENTRIES', ) ) { AppToaster.show({ message: intl.get('the_invoice_cannot_be_deleted'), intent: Intent.DANGER, }); } if ( errors.find( (error) => error.type === 'INVOICE_AMOUNT_SMALLER_THAN_PAYMENT_AMOUNT', ) ) { AppToaster.show({ message: intl.get('the_payment_amount_that_received'), intent: Intent.DANGER, }); } if ( errors.find( (error) => error.type === 'SALE_INVOICE_HAS_APPLIED_TO_CREDIT_NOTES', ) ) { AppToaster.show({ message: intl.get( 'invoices.error.you_couldn_t_delete_sale_invoice_that_has_reconciled', ), intent: Intent.DANGER, }); } }; export function ActionsMenu({ payload: { onEdit, onDeliver, onDelete, onConvert, onQuick, onViewDetails, onPrint, onSendMail, }, row: { original }, }) { return ( } text={intl.get('view_details')} onClick={safeCallback(onViewDetails, original)} /> } text={intl.get('edit_invoice')} onClick={safeCallback(onEdit, original)} /> } text={intl.get('invoice.convert_to_credit_note')} onClick={safeCallback(onConvert, original)} /> } text={intl.get('mark_as_delivered')} onClick={safeCallback(onDeliver, original)} /> } text={intl.get('add_payment')} onClick={safeCallback(onQuick, original)} /> } text={'Send Mail'} onClick={safeCallback(onSendMail, original)} /> } text={intl.get('print')} onClick={safeCallback(onPrint, original)} /> } /> ); } /** * Retrieve invoices table columns. */ export function useInvoicesTableColumns() { return React.useMemo( () => [ { id: 'invoice_date', Header: intl.get('invoice_date'), accessor: 'invoice_date_formatted', width: 110, className: 'invoice_date', clickable: true, textOverview: true, }, { id: 'customer', Header: intl.get('customer_name'), accessor: 'customer.display_name', width: 180, className: 'customer_id', clickable: true, textOverview: true, }, { id: 'invoice_no', Header: intl.get('invoice_no__'), accessor: 'invoice_no', width: 100, className: 'invoice_no', clickable: true, textOverview: true, }, { id: 'amount', Header: intl.get('amount'), accessor: 'total_formatted', width: 120, align: 'right', clickable: true, textOverview: true, className: clsx(CLASSES.FONT_BOLD), }, { id: 'status', Header: intl.get('status'), accessor: (row) => statusAccessor(row), width: 160, className: 'status', clickable: true, }, { id: 'due_date', Header: intl.get('due_date'), accessor: 'due_date', Cell: FormatDateCell, width: 110, className: 'due_date', clickable: true, textOverview: true, }, { id: 'reference_no', Header: intl.get('reference_no'), accessor: 'reference_no', width: 90, className: 'reference_no', clickable: true, textOverview: true, }, ], [], ); }