// @ts-nocheck import React, { useMemo } from 'react'; import classNames from 'classnames'; import styled from 'styled-components'; import { FormGroup, InputGroup, Position, Classes, ControlGroup, Button, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { isEmpty, toSafeInteger } from 'lodash'; import { FastField, useFormikContext, ErrorMessage } from 'formik'; import { FeatureCan, CustomersSelect, FormattedMessage as T, FMoneyInputGroup, } from '@/components'; import { CLASSES } from '@/constants/classes'; import { safeSumBy, momentFormatter, tansformDateValue, handleDateChange, inputIntent, } from '@/utils'; import { FFormGroup, AccountsSelect, FieldRequiredHint, Icon, InputPrependText, CustomerDrawerLink, Hint, Money, } from '@/components'; import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider'; import { ACCOUNT_TYPE } from '@/constants/accountTypes'; import { ProjectsSelect } from '@/containers/Projects/components'; import { PaymentReceiveExchangeRateInputField, PaymentReceiveProjectSelectButton, } from './components'; import { amountPaymentEntries, fullAmountPaymentEntries, customersFieldShouldUpdate, accountsFieldShouldUpdate, } from './utils'; import { Features } from '@/constants'; import { PaymentReceivePaymentNoField } from './PaymentReceivePaymentNoField'; /** * Payment receive header fields. */ export default function PaymentReceiveHeaderFields() { // Payment receive form context. const { accounts, projects } = usePaymentReceiveFormContext(); // Formik form context. const { values: { entries, currency_code }, setFieldValue, } = useFormikContext(); // Calculates the full-amount received. const totalDueAmount = useMemo( () => safeSumBy(entries, 'due_amount'), [entries], ); // Handle receive full-amount link click. const handleReceiveFullAmountClick = () => { const newEntries = fullAmountPaymentEntries(entries); const fullAmount = safeSumBy(newEntries, 'payment_amount'); setFieldValue('entries', newEntries); setFieldValue('amount', fullAmount); }; // Handles the full-amount field blur. const onFullAmountBlur = (value) => { const newEntries = amountPaymentEntries(toSafeInteger(value), entries); setFieldValue('entries', newEntries); }; return (
{/* ------------- Customer name ------------- */} {/* ----------- Exchange rate ----------- */} {/* ------------- Payment date ------------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } inline={true} labelInfo={} className={classNames('form-group--select-list', CLASSES.FILL)} intent={inputIntent({ error, touched })} helperText={} > { form.setFieldValue('payment_date', formattedDate); })} popoverProps={{ position: Position.BOTTOM, minimal: true }} inputProps={{ leftIcon: , }} /> )} {/* ------------ Full amount ------------ */} } inline={true} labelInfo={} fastField > {!isEmpty(entries) && ( )} {/* ------------ Payment receive no. ------------ */} {/* ------------ Deposit account ------------ */} } inline={true} labelInfo={} items={accounts} shouldUpdate={accountsFieldShouldUpdate} fastField={true} > } placeholder={} filterByTypes={[ ACCOUNT_TYPE.CASH, ACCOUNT_TYPE.BANK, ACCOUNT_TYPE.OTHER_CURRENT_ASSET, ]} shouldUpdate={accountsFieldShouldUpdate} fastField={true} fill={true} /> {/* ------------ Reference No. ------------ */} } inline={true} fastField > {/*------------ Project name -----------*/} } inline={true} className={classNames('form-group--select-list', Classes.FILL)} >
); } const CustomerButtonLink = styled(CustomerDrawerLink)` font-size: 11px; margin-top: 6px; `; /** * Customer select field of payment receive form. * @returns {React.ReactNode} */ function PaymentReceiveCustomerSelect() { // Payment receive form context. const { customers, isNewMode } = usePaymentReceiveFormContext(); // Formik form context. const { values, setFieldValue } = useFormikContext(); return ( } inline={true} labelInfo={} name={'customer_id'} fastField={true} shouldUpdate={customersFieldShouldUpdate} shouldUpdateDeps={{ items: customers }} > } onItemChange={(customer) => { setFieldValue('customer_id', customer.id); setFieldValue('full_amount', ''); setFieldValue('currency_code', customer?.currency_code); }} popoverFill={true} disabled={!isNewMode} allowCreate={true} fastField={true} shouldUpdate={customersFieldShouldUpdate} shouldUpdateDeps={{ items: customers }} /> {values.customer_id && ( )} ); }