mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix: Typo payments made
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { ExcessPaymentDialog } from './dialogs/PaymentMadeExcessDialog';
|
||||
|
||||
export function PaymentMadeDialogs() {
|
||||
return (
|
||||
<>
|
||||
<ExcessPaymentDialog dialogName={'payment-made-excessed-payment'} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// @ts-nocheck
|
||||
import React, { useCallback } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
DataTableEditable,
|
||||
CloudLoadingIndicator,
|
||||
FormattedMessage as T,
|
||||
} from '@/components';
|
||||
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { usePaymentMadeEntriesTableColumns } from './components';
|
||||
import { usePaymentMadeInnerContext } from './PaymentMadeInnerProvider';
|
||||
import { compose, updateTableCell } from '@/utils';
|
||||
import { useFormikContext } from 'formik';
|
||||
|
||||
/**
|
||||
* Payment made items table.
|
||||
*/
|
||||
export default function PaymentMadeEntriesTable({
|
||||
onUpdateData,
|
||||
entries,
|
||||
currencyCode,
|
||||
}) {
|
||||
// Payment made inner context.
|
||||
const { isNewEntriesFetching } = usePaymentMadeInnerContext();
|
||||
|
||||
// Payment entries table columns.
|
||||
const columns = usePaymentMadeEntriesTableColumns();
|
||||
|
||||
// Formik context.
|
||||
const {
|
||||
values: { vendor_id },
|
||||
errors,
|
||||
} = useFormikContext();
|
||||
|
||||
// Handle update data.
|
||||
const handleUpdateData = useCallback(
|
||||
(rowIndex, columnId, value) => {
|
||||
const newRows = compose(updateTableCell(rowIndex, columnId, value))(
|
||||
entries,
|
||||
);
|
||||
onUpdateData(newRows);
|
||||
},
|
||||
[onUpdateData, entries],
|
||||
);
|
||||
// Detarmines the right no results message before selecting vendor and after
|
||||
// selecting vendor id.
|
||||
const noResultsMessage = vendor_id ? (
|
||||
<T
|
||||
id={
|
||||
'there_is_no_payable_bills_for_this_vendor_that_can_be_applied_for_this_payment'
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<T id={'please_select_a_vendor_to_display_all_open_bills_for_it'} />
|
||||
);
|
||||
|
||||
return (
|
||||
<CloudLoadingIndicator isLoading={isNewEntriesFetching}>
|
||||
<DataTableEditable
|
||||
progressBarLoading={isNewEntriesFetching}
|
||||
className={classNames(CLASSES.DATATABLE_EDITOR_ITEMS_ENTRIES)}
|
||||
columns={columns}
|
||||
data={entries}
|
||||
spinnerProps={false}
|
||||
payload={{
|
||||
errors: errors?.entries || [],
|
||||
updateData: handleUpdateData,
|
||||
currencyCode,
|
||||
}}
|
||||
noResults={noResultsMessage}
|
||||
/>
|
||||
</CloudLoadingIndicator>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
Intent,
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Popover,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from '@blueprintjs/core';
|
||||
import { Group, Icon, FormattedMessage as T } from '@/components';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
|
||||
/**
|
||||
* Payment made floating actions bar.
|
||||
*/
|
||||
export default function PaymentMadeFloatingActions() {
|
||||
// History context.
|
||||
const history = useHistory();
|
||||
|
||||
// Formik context.
|
||||
const { isSubmitting, resetForm, submitForm } = useFormikContext();
|
||||
|
||||
// Payment made form context.
|
||||
const { setSubmitPayload, paymentMadeId } = usePaymentMadeFormContext();
|
||||
|
||||
// Handle submit button click.
|
||||
const handleSubmitBtnClick = (event) => {
|
||||
setSubmitPayload({ redirect: true });
|
||||
};
|
||||
|
||||
// Handle clear button click.
|
||||
const handleClearBtnClick = (event) => {
|
||||
resetForm();
|
||||
};
|
||||
|
||||
// Handle cancel button click.
|
||||
const handleCancelBtnClick = (event) => {
|
||||
history.goBack();
|
||||
};
|
||||
|
||||
// Handle submit & new button click.
|
||||
const handleSubmitAndNewClick = (event) => {
|
||||
setSubmitPayload({ redirect: false, resetForm: true });
|
||||
submitForm();
|
||||
};
|
||||
|
||||
// Handle submit & continue editing button click.
|
||||
const handleSubmitContinueEditingBtnClick = (event) => {
|
||||
setSubmitPayload({ redirect: false, publish: true });
|
||||
submitForm();
|
||||
};
|
||||
|
||||
return (
|
||||
<Group
|
||||
spacing={10}
|
||||
className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}
|
||||
>
|
||||
{/* ----------- Save and New ----------- */}
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
loading={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitBtnClick}
|
||||
style={{ minWidth: '85px' }}
|
||||
text={paymentMadeId ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={<T id={'save_and_new'} />}
|
||||
onClick={handleSubmitAndNewClick}
|
||||
/>
|
||||
<MenuItem
|
||||
text={<T id={'save_continue_editing'} />}
|
||||
onClick={handleSubmitContinueEditingBtnClick}
|
||||
/>
|
||||
</Menu>
|
||||
}
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
|
||||
/>
|
||||
</Popover>
|
||||
</ButtonGroup>
|
||||
{/* ----------- Clear & Reset----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleClearBtnClick}
|
||||
text={paymentMadeId ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
/>
|
||||
{/* ----------- Cancel ----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleCancelBtnClick}
|
||||
text={<T id={'cancel'} />}
|
||||
/>
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { Row, Col, Paper } from '@/components';
|
||||
import { PaymentMadeFormFooterLeft } from './PaymentMadeFormFooterLeft';
|
||||
import { PaymentMadeFormFooterRight } from './PaymentMadeFormFooterRight';
|
||||
import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmentButton';
|
||||
|
||||
/**
|
||||
* Payment made form footer.
|
||||
*/
|
||||
export default function PaymentMadeFooter() {
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
|
||||
<PaymentReceiveFooterPaper>
|
||||
<Row>
|
||||
<Col md={8}>
|
||||
<PaymentMadeFormFooterLeft />
|
||||
<UploadAttachmentButton />
|
||||
</Col>
|
||||
|
||||
<Col md={4}>
|
||||
<PaymentMadeFormFooterRight />
|
||||
</Col>
|
||||
</Row>
|
||||
</PaymentReceiveFooterPaper>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const PaymentReceiveFooterPaper = styled(Paper)`
|
||||
padding: 20px;
|
||||
`;
|
||||
@@ -0,0 +1,37 @@
|
||||
// @ts-nocheck
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from '@/constants/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
vendor_id: Yup.string().label(intl.get('vendor_name_')).required(),
|
||||
payment_date: Yup.date().required().label(intl.get('payment_date_')),
|
||||
payment_account_id: Yup.number()
|
||||
.required()
|
||||
.label(intl.get('payment_account_')),
|
||||
payment_number: Yup.string()
|
||||
.nullable()
|
||||
.max(DATATYPES_LENGTH.STRING)
|
||||
.nullable()
|
||||
.label(intl.get('payment_no_')),
|
||||
reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
|
||||
description: Yup.string().max(DATATYPES_LENGTH.TEXT),
|
||||
branch_id: Yup.string(),
|
||||
exchange_rate: Yup.number(),
|
||||
entries: Yup.array().of(
|
||||
Yup.object().shape({
|
||||
id: Yup.number().nullable(),
|
||||
due_amount: Yup.number().nullable(),
|
||||
payment_amount: Yup.number().nullable().max(Yup.ref('due_amount')),
|
||||
bill_id: Yup.number()
|
||||
.nullable()
|
||||
.when(['payment_amount'], {
|
||||
is: (payment_amount) => payment_amount,
|
||||
then: Yup.number().required(),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export const CreatePaymentMadeFormSchema = Schema;
|
||||
export const EditPaymentMadeFormSchema = Schema;
|
||||
@@ -0,0 +1,184 @@
|
||||
// @ts-nocheck
|
||||
import React, { useMemo } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import classNames from 'classnames';
|
||||
import { Formik, Form, FormikHelpers } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { sumBy, defaultTo } from 'lodash';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { AppToaster } from '@/components';
|
||||
import PaymentMadeHeader from './PaymentMadeFormHeader';
|
||||
import PaymentMadeFloatingActions from './PaymentMadeFloatingActions';
|
||||
import PaymentMadeFooter from './PaymentMadeFooter';
|
||||
import PaymentMadeFormBody from './PaymentMadeFormBody';
|
||||
import PaymentMadeFormTopBar from './PaymentMadeFormTopBar';
|
||||
import { PaymentMadeDialogs } from './PaymentMadeDialogs';
|
||||
|
||||
import { PaymentMadeInnerProvider } from './PaymentMadeInnerProvider';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import { compose, orderingLinesIndexes } from '@/utils';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
import {
|
||||
EditPaymentMadeFormSchema,
|
||||
CreatePaymentMadeFormSchema,
|
||||
} from './PaymentMadeForm.schema';
|
||||
import {
|
||||
defaultPaymentMade,
|
||||
transformToEditForm,
|
||||
transformErrors,
|
||||
transformFormToRequest,
|
||||
getPaymentExcessAmountFromValues,
|
||||
} from './utils';
|
||||
|
||||
/**
|
||||
* Payment made form component.
|
||||
*/
|
||||
function PaymentMadeForm({
|
||||
// #withSettings
|
||||
preferredPaymentAccount,
|
||||
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
|
||||
// Payment made form context.
|
||||
const {
|
||||
isNewMode,
|
||||
paymentMadeId,
|
||||
paymentMadeEditPage,
|
||||
paymentEntriesEditPage,
|
||||
submitPayload,
|
||||
createPaymentMadeMutate,
|
||||
editPaymentMadeMutate,
|
||||
isExcessConfirmed,
|
||||
} = usePaymentMadeFormContext();
|
||||
|
||||
// Form initial values.
|
||||
const initialValues = useMemo(
|
||||
() => ({
|
||||
...(!isNewMode
|
||||
? {
|
||||
...transformToEditForm(paymentMadeEditPage, paymentEntriesEditPage),
|
||||
}
|
||||
: {
|
||||
...defaultPaymentMade,
|
||||
payment_account_id: defaultTo(preferredPaymentAccount),
|
||||
currency_code: base_currency,
|
||||
entries: orderingLinesIndexes(defaultPaymentMade.entries),
|
||||
}),
|
||||
}),
|
||||
[isNewMode, paymentMadeEditPage, paymentEntriesEditPage],
|
||||
);
|
||||
|
||||
// Handle the form submit.
|
||||
const handleSubmitForm = (
|
||||
values,
|
||||
{ setSubmitting, resetForm, setFieldError }: FormikHelpers<any>,
|
||||
) => {
|
||||
setSubmitting(true);
|
||||
|
||||
if (values.amount <= 0) {
|
||||
AppToaster.show({
|
||||
message: intl.get('you_cannot_make_payment_with_zero_total_amount'),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
setSubmitting(false);
|
||||
return;
|
||||
}
|
||||
const excessAmount = getPaymentExcessAmountFromValues(values);
|
||||
|
||||
// Show the confirmation popup if the excess amount bigger than zero and
|
||||
// has not been confirmed yet.
|
||||
if (excessAmount > 0 && !isExcessConfirmed) {
|
||||
openDialog('payment-made-excessed-payment');
|
||||
setSubmitting(false);
|
||||
|
||||
return;
|
||||
}
|
||||
// Transformes the form values to request body.
|
||||
const form = transformFormToRequest(values);
|
||||
|
||||
// Triggers once the save request success.
|
||||
const onSaved = () => {
|
||||
AppToaster.show({
|
||||
message: intl.get(
|
||||
isNewMode
|
||||
? 'the_payment_made_has_been_created_successfully'
|
||||
: 'the_payment_made_has_been_edited_successfully',
|
||||
),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
|
||||
submitPayload.redirect && history.push('/payments-made');
|
||||
submitPayload.resetForm && resetForm();
|
||||
};
|
||||
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
transformErrors(errors, { setFieldError });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
if (!isNewMode) {
|
||||
return editPaymentMadeMutate([paymentMadeId, form])
|
||||
.then(onSaved)
|
||||
.catch(onError);
|
||||
} else {
|
||||
return createPaymentMadeMutate(form).then(onSaved).catch(onError);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
CLASSES.PAGE_FORM,
|
||||
CLASSES.PAGE_FORM_STRIP_STYLE,
|
||||
CLASSES.PAGE_FORM_PAYMENT_MADE,
|
||||
)}
|
||||
>
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
validationSchema={
|
||||
isNewMode ? CreatePaymentMadeFormSchema : EditPaymentMadeFormSchema
|
||||
}
|
||||
onSubmit={handleSubmitForm}
|
||||
>
|
||||
<Form>
|
||||
<PaymentMadeInnerProvider>
|
||||
<PaymentMadeFormTopBar />
|
||||
<PaymentMadeHeader />
|
||||
<PaymentMadeFormBody />
|
||||
<PaymentMadeFooter />
|
||||
<PaymentMadeFloatingActions />
|
||||
<PaymentMadeDialogs />
|
||||
</PaymentMadeInnerProvider>
|
||||
</Form>
|
||||
</Formik>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettings(({ billPaymentSettings }) => ({
|
||||
paymentNextNumber: billPaymentSettings?.next_number,
|
||||
paymentNumberPrefix: billPaymentSettings?.number_prefix,
|
||||
preferredPaymentAccount: parseInt(billPaymentSettings?.withdrawalAccount),
|
||||
})),
|
||||
withCurrentOrganization(),
|
||||
withDialogActions,
|
||||
)(PaymentMadeForm);
|
||||
@@ -0,0 +1,28 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { FastField } from 'formik';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import PaymentMadeEntriesTable from './PaymentMadeEntriesTable';
|
||||
|
||||
export default function PaymentMadeFormBody() {
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||
<FastField name={'entries'}>
|
||||
{({
|
||||
form: { setFieldValue, values },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<PaymentMadeEntriesTable
|
||||
entries={value}
|
||||
onUpdateData={(newEntries) => {
|
||||
setFieldValue('entries', newEntries);
|
||||
}}
|
||||
currencyCode={values.currency_code}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { BaseCurrency, BaseCurrencyRoot } from '@/components';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
|
||||
/**
|
||||
* Payment made form currency tag.
|
||||
* @returns
|
||||
*/
|
||||
export default function PaymentMadeFormCurrencyTag() {
|
||||
const { isForeignVendor, selectVendor } = usePaymentMadeFormContext();
|
||||
|
||||
if (!isForeignVendor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<BaseCurrencyRoot>
|
||||
<BaseCurrency currency={selectVendor?.currency_code} />
|
||||
</BaseCurrencyRoot>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import styled from 'styled-components';
|
||||
import { FFormGroup, FEditableText, FormattedMessage as T } from '@/components';
|
||||
|
||||
/**
|
||||
* Payment made form footer left-side.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function PaymentMadeFormFooterLeft() {
|
||||
return (
|
||||
<React.Fragment>
|
||||
{/* --------- Internal Note--------- */}
|
||||
<InternalNoteFormGroup
|
||||
name={'statement'}
|
||||
label={<T id={'payment_made.form.internal_note.label'} />}
|
||||
fastField={true}
|
||||
>
|
||||
<FEditableText
|
||||
name={'statement'}
|
||||
placeholder={intl.get('payment_made.form.internal_note.placeholder')}
|
||||
fastField
|
||||
multiline
|
||||
/>
|
||||
</InternalNoteFormGroup>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
const InternalNoteFormGroup = styled(FFormGroup)`
|
||||
&.bp4-form-group {
|
||||
margin-bottom: 40px;
|
||||
|
||||
.bp4-label {
|
||||
font-size: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.bp4-form-content {
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,46 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { useFormikContext } from 'formik';
|
||||
import {
|
||||
T,
|
||||
TotalLines,
|
||||
TotalLine,
|
||||
TotalLineBorderStyle,
|
||||
TotalLineTextStyle,
|
||||
FormatNumber,
|
||||
} from '@/components';
|
||||
import { usePaymentMadeExcessAmount, usePaymentMadeTotals } from './utils';
|
||||
|
||||
export function PaymentMadeFormFooterRight() {
|
||||
const { formattedSubtotal, formattedTotal } = usePaymentMadeTotals();
|
||||
const excessAmount = usePaymentMadeExcessAmount();
|
||||
const {
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
return (
|
||||
<PaymentMadeTotalLines labelColWidth={'180px'} amountColWidth={'180px'}>
|
||||
<TotalLine
|
||||
title={<T id={'payment_made_form.label.subtotal'} />}
|
||||
value={formattedSubtotal}
|
||||
borderStyle={TotalLineBorderStyle.None}
|
||||
/>
|
||||
<TotalLine
|
||||
title={<T id={'payment_made_form.label.total'} />}
|
||||
value={formattedTotal}
|
||||
textStyle={TotalLineTextStyle.Bold}
|
||||
/>
|
||||
<TotalLine
|
||||
title={'Excess Amount'}
|
||||
value={<FormatNumber value={excessAmount} currency={currencyCode} />}
|
||||
textStyle={TotalLineTextStyle.Regular}
|
||||
/>
|
||||
</PaymentMadeTotalLines>
|
||||
);
|
||||
}
|
||||
|
||||
const PaymentMadeTotalLines = styled(TotalLines)`
|
||||
width: 100%;
|
||||
color: #555555;
|
||||
`;
|
||||
@@ -0,0 +1,43 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { Money, FormattedMessage as T } from '@/components';
|
||||
|
||||
import PaymentMadeFormHeaderFields from './PaymentMadeFormHeaderFields';
|
||||
import { usePaymentmadeTotalAmount } from './utils';
|
||||
|
||||
/**
|
||||
* Payment made header form.
|
||||
*/
|
||||
function PaymentMadeFormHeader() {
|
||||
// Formik form context.
|
||||
const {
|
||||
values: { currency_code },
|
||||
} = useFormikContext();
|
||||
|
||||
const totalAmount = usePaymentmadeTotalAmount();
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_PRIMARY)}>
|
||||
<PaymentMadeFormHeaderFields />
|
||||
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_BIG_NUMBERS)}>
|
||||
<div class="big-amount">
|
||||
<span class="big-amount__label">
|
||||
<T id={'amount_received'} />
|
||||
</span>
|
||||
|
||||
<h1 class="big-amount__number">
|
||||
<Money amount={totalAmount} currency={currency_code} />
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PaymentMadeFormHeader;
|
||||
@@ -0,0 +1,278 @@
|
||||
// @ts-nocheck
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import classNames from 'classnames';
|
||||
import { isEmpty, toSafeInteger } from 'lodash';
|
||||
import {
|
||||
FormGroup,
|
||||
InputGroup,
|
||||
Position,
|
||||
Classes,
|
||||
ControlGroup,
|
||||
Button,
|
||||
} from '@blueprintjs/core';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
|
||||
import { FormattedMessage as T, VendorsSelect } from '@/components';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
|
||||
import {
|
||||
FFormGroup,
|
||||
AccountsSelect,
|
||||
FieldRequiredHint,
|
||||
InputPrependText,
|
||||
Money,
|
||||
Hint,
|
||||
Icon,
|
||||
VendorDrawerLink,
|
||||
MoneyInputGroup,
|
||||
} from '@/components';
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
|
||||
import { PaymentMadeExchangeRateInputField } from './components';
|
||||
import {
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
inputIntent,
|
||||
compose,
|
||||
safeSumBy,
|
||||
fullAmountPaymentEntries,
|
||||
amountPaymentEntries,
|
||||
} from '@/utils';
|
||||
import { accountsFieldShouldUpdate, vendorsFieldShouldUpdate } from './utils';
|
||||
|
||||
/**
|
||||
* Payment made form header fields.
|
||||
*/
|
||||
function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
|
||||
// Formik form context.
|
||||
const {
|
||||
values: { entries },
|
||||
setFieldValue,
|
||||
} = useFormikContext();
|
||||
|
||||
// Payment made form context.
|
||||
const { accounts } = usePaymentMadeFormContext();
|
||||
|
||||
// Sumation of payable full-amount.
|
||||
const payableFullAmount = useMemo(
|
||||
() => safeSumBy(entries, 'due_amount'),
|
||||
[entries],
|
||||
);
|
||||
|
||||
// Handle receive full-amount 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 (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||
{/* ------------ Vendor name ------------ */}
|
||||
<PaymentFormVendorSelect />
|
||||
|
||||
{/* ----------- Exchange rate ----------- */}
|
||||
<PaymentMadeExchangeRateInputField
|
||||
name={'exchange_rate'}
|
||||
formGroupProps={{ label: ' ', inline: true }}
|
||||
/>
|
||||
|
||||
{/* ------------ Payment date ------------ */}
|
||||
<FastField name={'payment_date'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'payment_date'} />}
|
||||
inline={true}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={classNames('form-group--select-list', Classes.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="payment_date" />}
|
||||
>
|
||||
<DateInput
|
||||
{...momentFormatter('YYYY/MM/DD')}
|
||||
value={tansformDateValue(value)}
|
||||
onChange={handleDateChange((formattedDate) => {
|
||||
form.setFieldValue('payment_date', formattedDate);
|
||||
})}
|
||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||
inputProps={{
|
||||
leftIcon: <Icon icon={'date-range'} />,
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ------------ Full amount ------------ */}
|
||||
<Field name={'amount'}>
|
||||
{({
|
||||
form: {
|
||||
values: { currency_code, entries },
|
||||
},
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={<T id={'full_amount'} />}
|
||||
inline={true}
|
||||
className={('form-group--full-amount', Classes.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
labelInfo={<Hint />}
|
||||
helperText={<ErrorMessage name="amount" />}
|
||||
>
|
||||
<ControlGroup>
|
||||
<InputPrependText text={currency_code} />
|
||||
<MoneyInputGroup
|
||||
value={value}
|
||||
onChange={(value) => {
|
||||
setFieldValue('amount', value);
|
||||
}}
|
||||
onBlurValue={onFullAmountBlur}
|
||||
/>
|
||||
</ControlGroup>
|
||||
|
||||
{!isEmpty(entries) && (
|
||||
<Button
|
||||
onClick={handleReceiveFullAmountClick}
|
||||
className={'receive-full-amount'}
|
||||
small={true}
|
||||
minimal={true}
|
||||
>
|
||||
<T id={'receive_full_amount'} /> (
|
||||
<Money amount={payableFullAmount} currency={currency_code} />)
|
||||
</Button>
|
||||
)}
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
|
||||
{/* ------------ Payment number ------------ */}
|
||||
<FastField name={'payment_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'payment_no'} />}
|
||||
inline={true}
|
||||
className={('form-group--payment_number', Classes.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="payment_number" />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
minimal={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ------------ Payment account ------------ */}
|
||||
<FFormGroup
|
||||
name={'payment_account_id'}
|
||||
label={<T id={'payment_account'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
items={accounts}
|
||||
shouldUpdate={accountsFieldShouldUpdate}
|
||||
inline={true}
|
||||
fastField={true}
|
||||
>
|
||||
<AccountsSelect
|
||||
name={'payment_account_id'}
|
||||
items={accounts}
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
filterByTypes={[
|
||||
ACCOUNT_TYPE.CASH,
|
||||
ACCOUNT_TYPE.BANK,
|
||||
ACCOUNT_TYPE.OTHER_CURRENT_ASSET,
|
||||
]}
|
||||
shouldUpdate={accountsFieldShouldUpdate}
|
||||
fastField={true}
|
||||
fill={true}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/* ------------ Reference ------------ */}
|
||||
<FastField name={'reference'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'reference'} />}
|
||||
inline={true}
|
||||
className={classNames('form-group--reference', Classes.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="reference" />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
minimal={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vendor select field of payment receive form.
|
||||
* @returns {React.ReactNode}
|
||||
*/
|
||||
function PaymentFormVendorSelect() {
|
||||
// Formik form context.
|
||||
const { values, setFieldValue } = useFormikContext();
|
||||
|
||||
// Payment made form context.
|
||||
const { vendors, isNewMode, setPaymentVendorId } =
|
||||
usePaymentMadeFormContext();
|
||||
|
||||
return (
|
||||
<FFormGroup
|
||||
name={'vendor_id'}
|
||||
label={<T id={'vendor_name'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
fastField={true}
|
||||
shouldUpdate={vendorsFieldShouldUpdate}
|
||||
shouldUpdateDeps={{ items: vendors }}
|
||||
>
|
||||
<VendorsSelect
|
||||
name={'vendor_id'}
|
||||
items={vendors}
|
||||
placeholder={<T id={'select_vender_account'} />}
|
||||
onItemChange={(contact) => {
|
||||
setFieldValue('vendor_id', contact.id);
|
||||
setFieldValue('currency_code', contact?.currency_code);
|
||||
setPaymentVendorId(contact.id);
|
||||
}}
|
||||
disabled={!isNewMode}
|
||||
allowCreate={true}
|
||||
fastField={true}
|
||||
shouldUpdate={vendorsFieldShouldUpdate}
|
||||
shouldUpdateDeps={{ items: vendors }}
|
||||
/>
|
||||
{values.vendor_id && (
|
||||
<VendorButtonLink vendorId={values.vendor_id}>
|
||||
<T id={'view_vendor_details'} />
|
||||
</VendorButtonLink>
|
||||
)}
|
||||
</FFormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withCurrentOrganization())(PaymentMadeFormHeaderFields);
|
||||
|
||||
const VendorButtonLink = styled(VendorDrawerLink)`
|
||||
font-size: 11px;
|
||||
margin-top: 6px;
|
||||
`;
|
||||
@@ -0,0 +1,21 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import PaymentMadeForm from './PaymentMadeForm';
|
||||
import { PaymentMadeFormProvider } from './PaymentMadeFormProvider';
|
||||
|
||||
import '@/style/pages/PaymentMade/PageForm.scss';
|
||||
|
||||
/**
|
||||
* Payment made - Page form.
|
||||
*/
|
||||
export default function PaymentMadeFormPage() {
|
||||
const { id: paymentMadeId } = useParams();
|
||||
|
||||
return (
|
||||
<PaymentMadeFormProvider paymentMadeId={paymentMadeId}>
|
||||
<PaymentMadeForm />
|
||||
</PaymentMadeFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// @ts-nocheck
|
||||
import React, { createContext, useContext, useState } from 'react';
|
||||
import { Features } from '@/constants';
|
||||
import { useFeatureCan } from '@/hooks/state';
|
||||
import {
|
||||
useAccounts,
|
||||
useVendors,
|
||||
useItems,
|
||||
useBranches,
|
||||
usePaymentMadeEditPage,
|
||||
useSettings,
|
||||
useCreatePaymentMade,
|
||||
useEditPaymentMade,
|
||||
} from '@/hooks/query';
|
||||
import { DashboardInsider } from '@/components';
|
||||
|
||||
// Payment made form context.
|
||||
const PaymentMadeFormContext = createContext();
|
||||
|
||||
/**
|
||||
* Payment made form provider.
|
||||
*/
|
||||
function PaymentMadeFormProvider({ query, paymentMadeId, ...props }) {
|
||||
const [submitPayload, setSubmitPayload] = React.useState({});
|
||||
const [paymentVendorId, setPaymentVendorId] = React.useState(null);
|
||||
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||
|
||||
// Handle fetch accounts data.
|
||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||
|
||||
// Handle fetch Items data table or list.
|
||||
const {
|
||||
data: { items },
|
||||
isFetching: isItemsFetching,
|
||||
isLoading: isItemsLoading,
|
||||
} = useItems({ page_size: 10000 });
|
||||
|
||||
// Handle fetch venders data table or list.
|
||||
const {
|
||||
data: { vendors },
|
||||
isLoading: isVendorsLoading,
|
||||
} = useVendors({ page_size: 10000 });
|
||||
|
||||
// Handle fetch specific payment made details.
|
||||
const {
|
||||
data: { paymentMade: paymentMadeEditPage, entries: paymentEntriesEditPage },
|
||||
isFetching: isPaymentFetching,
|
||||
isLoading: isPaymentLoading,
|
||||
} = usePaymentMadeEditPage(paymentMadeId, {
|
||||
enabled: !!paymentMadeId,
|
||||
});
|
||||
|
||||
// Fetches the branches list.
|
||||
const {
|
||||
data: branches,
|
||||
isLoading: isBranchesLoading,
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches(query, { enabled: isBranchFeatureCan });
|
||||
|
||||
// Fetch payment made settings.
|
||||
useSettings();
|
||||
|
||||
// Create and edit payment made mutations.
|
||||
const { mutateAsync: createPaymentMadeMutate } = useCreatePaymentMade();
|
||||
const { mutateAsync: editPaymentMadeMutate } = useEditPaymentMade();
|
||||
|
||||
const isNewMode = !paymentMadeId;
|
||||
|
||||
const isFeatureLoading = isBranchesLoading;
|
||||
|
||||
const [isExcessConfirmed, setIsExcessConfirmed] = useState<boolean>(false);
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentMadeId,
|
||||
accounts,
|
||||
paymentEntriesEditPage,
|
||||
paymentMadeEditPage,
|
||||
vendors,
|
||||
items,
|
||||
branches,
|
||||
submitPayload,
|
||||
paymentVendorId,
|
||||
|
||||
isNewMode,
|
||||
isAccountsLoading,
|
||||
isItemsFetching,
|
||||
isItemsLoading,
|
||||
isVendorsLoading,
|
||||
isPaymentFetching,
|
||||
isPaymentLoading,
|
||||
isFeatureLoading,
|
||||
isBranchesSuccess,
|
||||
|
||||
createPaymentMadeMutate,
|
||||
editPaymentMadeMutate,
|
||||
|
||||
setSubmitPayload,
|
||||
setPaymentVendorId,
|
||||
|
||||
isExcessConfirmed,
|
||||
setIsExcessConfirmed,
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardInsider
|
||||
loading={
|
||||
isVendorsLoading ||
|
||||
isItemsLoading ||
|
||||
isAccountsLoading ||
|
||||
isPaymentLoading
|
||||
}
|
||||
name={'payment-made'}
|
||||
>
|
||||
<PaymentMadeFormContext.Provider value={provider} {...props} />
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
|
||||
const usePaymentMadeFormContext = () => useContext(PaymentMadeFormContext);
|
||||
|
||||
export { PaymentMadeFormProvider, usePaymentMadeFormContext };
|
||||
@@ -0,0 +1,57 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Alignment, NavbarGroup, Classes } from '@blueprintjs/core';
|
||||
import { useSetPrimaryBranchToForm } from './utils';
|
||||
import { useFeatureCan } from '@/hooks/state';
|
||||
import {
|
||||
BranchSelect,
|
||||
FeatureCan,
|
||||
FormTopbar,
|
||||
DetailsBarSkeletonBase,
|
||||
FormBranchSelectButton,
|
||||
} from '@/components';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import { Features } from '@/constants';
|
||||
|
||||
/**
|
||||
* Payment made from top bar.
|
||||
* @returns
|
||||
*/
|
||||
export default function PaymentMadeFormTopBar() {
|
||||
// Features guard.
|
||||
const { featureCan } = useFeatureCan();
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
// Can't display the navigation bar if branches feature is not enabled.
|
||||
if (!featureCan(Features.Branches)) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<FormTopbar>
|
||||
<NavbarGroup align={Alignment.LEFT}>
|
||||
<FeatureCan feature={Features.Branches}>
|
||||
<PaymentMadeFormSelectBranch />
|
||||
</FeatureCan>
|
||||
</NavbarGroup>
|
||||
</FormTopbar>
|
||||
);
|
||||
}
|
||||
|
||||
function PaymentMadeFormSelectBranch() {
|
||||
// payment made form context.
|
||||
const { branches, isBranchesLoading } = usePaymentMadeFormContext();
|
||||
|
||||
return isBranchesLoading ? (
|
||||
<DetailsBarSkeletonBase className={Classes.SKELETON} />
|
||||
) : (
|
||||
<BranchSelect
|
||||
name={'branch_id'}
|
||||
branches={branches}
|
||||
input={FormBranchSelectButton}
|
||||
popoverProps={{ minimal: true }}
|
||||
fill={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// @ts-nocheck
|
||||
import React, { createContext, useContext, useEffect } from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { usePaymentMadeNewPageEntries } from '@/hooks/query';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import { transformToNewPageEntries } from './utils';
|
||||
|
||||
const PaymentMadeInnerContext = createContext();
|
||||
|
||||
/**
|
||||
* Payment made inner form provider.
|
||||
*/
|
||||
function PaymentMadeInnerProvider({ ...props }) {
|
||||
// Payment made form context.
|
||||
const { isNewMode } = usePaymentMadeFormContext();
|
||||
|
||||
// Formik context.
|
||||
const {
|
||||
values: { vendor_id: vendorId },
|
||||
setFieldValue,
|
||||
} = useFormikContext();
|
||||
|
||||
const {
|
||||
data: newPageEntries,
|
||||
isLoading: isNewEntriesLoading,
|
||||
isFetching: isNewEntriesFetching,
|
||||
} = usePaymentMadeNewPageEntries(vendorId, {
|
||||
enabled: !!vendorId && isNewMode,
|
||||
keepPreviousData: true,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!isNewEntriesFetching && newPageEntries && isNewMode) {
|
||||
setFieldValue('entries', transformToNewPageEntries(newPageEntries));
|
||||
}
|
||||
}, [isNewEntriesFetching, newPageEntries, isNewMode, setFieldValue]);
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
newPageEntries,
|
||||
isNewEntriesLoading,
|
||||
isNewEntriesFetching,
|
||||
};
|
||||
|
||||
return <PaymentMadeInnerContext.Provider value={provider} {...props} />;
|
||||
}
|
||||
|
||||
const usePaymentMadeInnerContext = () => useContext(PaymentMadeInnerContext);
|
||||
|
||||
export { PaymentMadeInnerProvider, usePaymentMadeInnerContext };
|
||||
@@ -0,0 +1,93 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import moment from 'moment';
|
||||
import { Money, ExchangeRateInputGroup } from '@/components';
|
||||
import { MoneyFieldCell } from '@/components/DataTableCells';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { useCurrentOrganization } from '@/hooks/state';
|
||||
import { usePaymentMadeIsForeignCustomer } from './utils';
|
||||
|
||||
function BillNumberAccessor(row) {
|
||||
return row?.bill_no ? row?.bill_no : '-';
|
||||
}
|
||||
|
||||
function BillDateCell({ value }) {
|
||||
return moment(value).format('YYYY MMM DD');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mobey table cell.
|
||||
*/
|
||||
function MoneyTableCell({ row: { original }, value }) {
|
||||
return <Money amount={value} currency={original.currency_code} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment made entries table columns
|
||||
*/
|
||||
export function usePaymentMadeEntriesTableColumns() {
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: 'Bill date',
|
||||
id: 'bill_date',
|
||||
accessor: 'bill_date',
|
||||
Cell: BillDateCell,
|
||||
disableSortBy: true,
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
Header: intl.get('bill_number'),
|
||||
accessor: BillNumberAccessor,
|
||||
disableSortBy: true,
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
Header: intl.get('bill_amount'),
|
||||
accessor: 'amount',
|
||||
Cell: MoneyTableCell,
|
||||
disableSortBy: true,
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: intl.get('amount_due'),
|
||||
accessor: 'due_amount',
|
||||
Cell: MoneyTableCell,
|
||||
disableSortBy: true,
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: intl.get('payment_amount'),
|
||||
accessor: 'payment_amount',
|
||||
Cell: MoneyFieldCell,
|
||||
disableSortBy: true,
|
||||
width: 150,
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* payment made exchange rate input field.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function PaymentMadeExchangeRateInputField({ ...props }) {
|
||||
const currentOrganization = useCurrentOrganization();
|
||||
const { values } = useFormikContext();
|
||||
|
||||
const isForeignCustomer = usePaymentMadeIsForeignCustomer();
|
||||
|
||||
// Can't continue if the customer is not foreign.
|
||||
if (!isForeignCustomer) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ExchangeRateInputGroup
|
||||
fromCurrency={values.currency_code}
|
||||
toCurrency={currentOrganization.base_currency}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Dialog, DialogSuspense } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const ExcessPaymentDialogContent = React.lazy(() =>
|
||||
import('./PaymentMadeExcessDialogContent').then((module) => ({
|
||||
default: module.ExcessPaymentDialogContent,
|
||||
})),
|
||||
);
|
||||
|
||||
/**
|
||||
* Exess payment dialog of the payment made form.
|
||||
*/
|
||||
function ExcessPaymentDialogRoot({ dialogName, isOpen }) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={'Excess Payment'}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
style={{ width: 500 }}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ExcessPaymentDialogContent dialogName={dialogName} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export const ExcessPaymentDialog = compose(withDialogRedux())(
|
||||
ExcessPaymentDialogRoot,
|
||||
);
|
||||
|
||||
ExcessPaymentDialog.displayName = 'ExcessPaymentDialog';
|
||||
@@ -0,0 +1,93 @@
|
||||
// @ts-nocheck
|
||||
import * as R from 'ramda';
|
||||
import React from 'react';
|
||||
import { Button, Classes, Intent } from '@blueprintjs/core';
|
||||
import { Form, Formik, FormikHelpers, useFormikContext } from 'formik';
|
||||
import { FormatNumber } from '@/components';
|
||||
import { usePaymentMadeFormContext } from '../../PaymentMadeFormProvider';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { usePaymentMadeExcessAmount } from '../../utils';
|
||||
|
||||
interface ExcessPaymentValues {}
|
||||
function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) {
|
||||
const {
|
||||
submitForm,
|
||||
values: { currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
const { setIsExcessConfirmed } = usePaymentMadeFormContext();
|
||||
|
||||
// Handles the form submitting.
|
||||
const handleSubmit = (
|
||||
values: ExcessPaymentValues,
|
||||
{ setSubmitting }: FormikHelpers<ExcessPaymentValues>,
|
||||
) => {
|
||||
setSubmitting(true);
|
||||
setIsExcessConfirmed(true);
|
||||
|
||||
return submitForm().then(() => {
|
||||
setSubmitting(false);
|
||||
closeDialog(dialogName);
|
||||
});
|
||||
};
|
||||
// Handle close button click.
|
||||
const handleCloseBtn = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
const excessAmount = usePaymentMadeExcessAmount();
|
||||
|
||||
return (
|
||||
<Formik initialValues={{}} onSubmit={handleSubmit}>
|
||||
<Form>
|
||||
<ExcessPaymentDialogContentForm
|
||||
excessAmount={
|
||||
<FormatNumber value={excessAmount} currency={currencyCode} />
|
||||
}
|
||||
onClose={handleCloseBtn}
|
||||
/>
|
||||
</Form>
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
|
||||
export const ExcessPaymentDialogContent = R.compose(withDialogActions)(
|
||||
ExcessPaymentDialogContentRoot,
|
||||
);
|
||||
|
||||
interface ExcessPaymentDialogContentFormProps {
|
||||
excessAmount: string | number | React.ReactNode;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
function ExcessPaymentDialogContentForm({
|
||||
excessAmount,
|
||||
onClose,
|
||||
}: ExcessPaymentDialogContentFormProps) {
|
||||
const { submitForm, isSubmitting } = useFormikContext();
|
||||
|
||||
const handleCloseBtn = () => {
|
||||
onClose && onClose();
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<p style={{ marginBottom: 20 }}>
|
||||
Would you like to record the excess amount of{' '}
|
||||
<strong>{excessAmount}</strong> as credit payment from the vendor.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
onClick={() => submitForm()}
|
||||
>
|
||||
Save Payment as Credit
|
||||
</Button>
|
||||
<Button onClick={handleCloseBtn}>Cancel</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './PaymentMadeExcessDialog';
|
||||
@@ -0,0 +1,224 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { pick, first, sumBy } from 'lodash';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { AppToaster } from '@/components';
|
||||
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
|
||||
import {
|
||||
defaultFastFieldShouldUpdate,
|
||||
safeSumBy,
|
||||
transformToForm,
|
||||
orderingLinesIndexes,
|
||||
formattedAmount,
|
||||
} from '@/utils';
|
||||
import { useCurrentOrganization } from '@/hooks/state';
|
||||
import { PAYMENT_MADE_ERRORS } from '../constants';
|
||||
import {
|
||||
transformAttachmentsToForm,
|
||||
transformAttachmentsToRequest,
|
||||
} from '@/containers/Attachments/utils';
|
||||
|
||||
export const ERRORS = {
|
||||
PAYMENT_NUMBER_NOT_UNIQUE: 'PAYMENT.NUMBER.NOT.UNIQUE',
|
||||
};
|
||||
|
||||
// Default payment made entry values.
|
||||
export const defaultPaymentMadeEntry = {
|
||||
bill_id: '',
|
||||
payment_amount: '',
|
||||
currency_code: '',
|
||||
id: null,
|
||||
due_amount: null,
|
||||
amount: '',
|
||||
};
|
||||
|
||||
// Default initial values of payment made.
|
||||
export const defaultPaymentMade = {
|
||||
amount: '',
|
||||
vendor_id: '',
|
||||
payment_account_id: '',
|
||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
reference: '',
|
||||
payment_number: '',
|
||||
statement: '',
|
||||
currency_code: '',
|
||||
branch_id: '',
|
||||
exchange_rate: 1,
|
||||
entries: [],
|
||||
attachments: [],
|
||||
};
|
||||
|
||||
export const transformToEditForm = (paymentMade, paymentMadeEntries) => {
|
||||
const attachments = transformAttachmentsToForm(paymentMade);
|
||||
const appliedAmount = safeSumBy(paymentMadeEntries, 'payment_amount');
|
||||
|
||||
return {
|
||||
...transformToForm(paymentMade, defaultPaymentMade),
|
||||
entries: [
|
||||
...paymentMadeEntries.map((paymentMadeEntry) => ({
|
||||
...transformToForm(paymentMadeEntry, defaultPaymentMadeEntry),
|
||||
payment_amount: paymentMadeEntry.payment_amount || '',
|
||||
})),
|
||||
],
|
||||
attachments,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform the new page entries.
|
||||
*/
|
||||
export const transformToNewPageEntries = (entries) => {
|
||||
return entries.map((entry) => ({
|
||||
...transformToForm(entry, defaultPaymentMadeEntry),
|
||||
payment_amount: '',
|
||||
currency_code: entry.currency_code,
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines vendors fast field when update.
|
||||
*/
|
||||
export const vendorsFieldShouldUpdate = (newProps, oldProps) => {
|
||||
return (
|
||||
newProps.shouldUpdateDeps.items !== oldProps.shouldUpdateDeps.items ||
|
||||
defaultFastFieldShouldUpdate(newProps, oldProps)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines accounts fast field when update.
|
||||
*/
|
||||
export const accountsFieldShouldUpdate = (newProps, oldProps) => {
|
||||
return (
|
||||
newProps.items !== oldProps.items ||
|
||||
defaultFastFieldShouldUpdate(newProps, oldProps)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transformes the form values to request body.
|
||||
*/
|
||||
export const transformFormToRequest = (form) => {
|
||||
// Filters entries that have no `bill_id` or `payment_amount`.
|
||||
const entries = form.entries
|
||||
.filter((item) => item.bill_id && item.payment_amount)
|
||||
.map((entry) => ({
|
||||
...pick(entry, ['payment_amount', 'bill_id']),
|
||||
}));
|
||||
|
||||
const attachments = transformAttachmentsToRequest(form);
|
||||
|
||||
return { ...form, entries: orderingLinesIndexes(entries), attachments };
|
||||
};
|
||||
|
||||
export const useSetPrimaryBranchToForm = () => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
const { branches, isBranchesSuccess } = usePaymentMadeFormContext();
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isBranchesSuccess) {
|
||||
const primaryBranch = branches.find((b) => b.primary) || first(branches);
|
||||
|
||||
if (primaryBranch) {
|
||||
setFieldValue('branch_id', primaryBranch.id);
|
||||
}
|
||||
}
|
||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transformes the response errors types.
|
||||
*/
|
||||
export const transformErrors = (errors, { setFieldError }) => {
|
||||
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
||||
|
||||
if (getError(PAYMENT_MADE_ERRORS.PAYMENT_NUMBER_NOT_UNIQUE)) {
|
||||
setFieldError('payment_number', intl.get('payment_number_is_not_unique'));
|
||||
}
|
||||
if (getError(PAYMENT_MADE_ERRORS.WITHDRAWAL_ACCOUNT_CURRENCY_INVALID)) {
|
||||
AppToaster.show({
|
||||
message: intl.get(
|
||||
'payment_made.error.withdrawal_account_currency_invalid',
|
||||
),
|
||||
intent: Intent.DANGER,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const usePaymentMadeTotals = () => {
|
||||
const {
|
||||
values: { entries, currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
// Retrieves the invoice entries total.
|
||||
const total = React.useMemo(
|
||||
() => sumBy(entries, 'payment_amount'),
|
||||
[entries],
|
||||
);
|
||||
|
||||
// Retrieves the formatted total money.
|
||||
const formattedTotal = React.useMemo(
|
||||
() => formattedAmount(total, currencyCode),
|
||||
[total, currencyCode],
|
||||
);
|
||||
// Retrieves the formatted subtotal.
|
||||
const formattedSubtotal = React.useMemo(
|
||||
() => formattedAmount(total, currencyCode, { money: false }),
|
||||
[total, currencyCode],
|
||||
);
|
||||
|
||||
return {
|
||||
total,
|
||||
formattedTotal,
|
||||
formattedSubtotal,
|
||||
};
|
||||
};
|
||||
|
||||
export const usePaymentmadeTotalAmount = () => {
|
||||
const {
|
||||
values: { amount },
|
||||
} = useFormikContext();
|
||||
|
||||
return amount;
|
||||
};
|
||||
|
||||
export const usePaymentMadeAppliedAmount = () => {
|
||||
const {
|
||||
values: { entries },
|
||||
} = useFormikContext();
|
||||
|
||||
// Retrieves the invoice entries total.
|
||||
return React.useMemo(() => sumBy(entries, 'payment_amount'), [entries]);
|
||||
};
|
||||
|
||||
export const usePaymentMadeExcessAmount = () => {
|
||||
const appliedAmount = usePaymentMadeAppliedAmount();
|
||||
const totalAmount = usePaymentmadeTotalAmount();
|
||||
|
||||
return Math.abs(totalAmount - appliedAmount);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines whether the bill has foreign customer.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const usePaymentMadeIsForeignCustomer = () => {
|
||||
const { values } = useFormikContext();
|
||||
const currentOrganization = useCurrentOrganization();
|
||||
|
||||
const isForeignCustomer = React.useMemo(
|
||||
() => values.currency_code !== currentOrganization.base_currency,
|
||||
[values.currency_code, currentOrganization.base_currency],
|
||||
);
|
||||
return isForeignCustomer;
|
||||
};
|
||||
|
||||
export const getPaymentExcessAmountFromValues = (values) => {
|
||||
const appliedAmount = sumBy(values.entries, 'payment_amount');
|
||||
const totalAmount = values.amount;
|
||||
|
||||
return Math.abs(totalAmount - appliedAmount);
|
||||
};
|
||||
@@ -0,0 +1,186 @@
|
||||
// @ts-nocheck
|
||||
import {
|
||||
Button,
|
||||
Classes,
|
||||
NavbarDivider,
|
||||
NavbarGroup,
|
||||
Intent,
|
||||
Alignment,
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import {
|
||||
If,
|
||||
Can,
|
||||
Icon,
|
||||
FormattedMessage as T,
|
||||
DashboardActionViewsList,
|
||||
DashboardFilterButton,
|
||||
AdvancedFilterPopover,
|
||||
DashboardRowsHeightButton,
|
||||
DashboardActionsBar,
|
||||
} from '@/components';
|
||||
import { PaymentMadeAction, AbilitySubject } from '@/constants/abilityOption';
|
||||
|
||||
import withPaymentMade from './withPaymentMade';
|
||||
import withPaymentMadeActions from './withPaymentMadeActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
import { usePaymentMadesListContext } from './PaymentMadesListProvider';
|
||||
import { useRefreshPaymentMades } from '@/hooks/query/paymentMades';
|
||||
import { useDownloadExportPdf } from '@/hooks/query/FinancialReports/use-export-pdf';
|
||||
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Payment made actions bar.
|
||||
*/
|
||||
function PaymentMadeActionsBar({
|
||||
// #withPaymentMadesActions
|
||||
setPaymentMadesTableState,
|
||||
|
||||
// #withPaymentMades
|
||||
paymentMadesFilterConditions,
|
||||
|
||||
// #withSettings
|
||||
paymentMadesTableSize,
|
||||
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettingsActions
|
||||
addSetting,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
|
||||
// Exports pdf document.
|
||||
const { downloadAsync: downloadExportPdf } = useDownloadExportPdf();
|
||||
|
||||
// Payment receives list context.
|
||||
const { paymentMadesViews, fields } = usePaymentMadesListContext();
|
||||
|
||||
// Payment receive refresh action.
|
||||
const { refresh } = useRefreshPaymentMades();
|
||||
|
||||
// Handle new payment made button click.
|
||||
const handleClickNewPaymentMade = () => {
|
||||
history.push('/payments-made/new');
|
||||
};
|
||||
// Handle tab changing.
|
||||
const handleTabChange = (viewSlug) => {
|
||||
setPaymentMadesTableState({ viewSlug });
|
||||
};
|
||||
// Handle click a refresh payment receives.
|
||||
const handleRefreshBtnClick = () => {
|
||||
refresh();
|
||||
};
|
||||
// Handle table row size change.
|
||||
const handleTableRowSizeChange = (size) => {
|
||||
addSetting('billPayments', 'tableSize', size);
|
||||
};
|
||||
// Handle the import button click.
|
||||
const handleImportBtnClick = () => {
|
||||
history.push('/payments-made/import');
|
||||
};
|
||||
// Handle the export button click.
|
||||
const handleExportBtnClick = () => {
|
||||
openDialog(DialogsName.Export, { resource: 'bill_payment' });
|
||||
};
|
||||
// Handle the print button click.
|
||||
const handlePrintBtnClick = () => {
|
||||
downloadExportPdf({ resource: 'BillPayment' });
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<DashboardActionViewsList
|
||||
resourceName={'bill_payments'}
|
||||
views={paymentMadesViews}
|
||||
onChange={handleTabChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Can I={PaymentMadeAction.Create} a={AbilitySubject.PaymentMade}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'plus'} />}
|
||||
text={<T id={'new_payment_made'} />}
|
||||
onClick={handleClickNewPaymentMade}
|
||||
/>
|
||||
</Can>
|
||||
<AdvancedFilterPopover
|
||||
advancedFilterProps={{
|
||||
conditions: paymentMadesFilterConditions,
|
||||
defaultFieldKey: 'payment_number',
|
||||
fields: fields,
|
||||
onFilterChange: (filterConditions) => {
|
||||
setPaymentMadesTableState({ filterRoles: filterConditions });
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DashboardFilterButton
|
||||
conditionsCount={paymentMadesFilterConditions.length}
|
||||
/>
|
||||
</AdvancedFilterPopover>
|
||||
|
||||
<If condition={false}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'trash-16'} iconSize={16} />}
|
||||
text={<T id={'delete'} />}
|
||||
intent={Intent.DANGER}
|
||||
// onClick={handleBulkDelete}
|
||||
/>
|
||||
</If>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'print-16'} iconSize={'16'} />}
|
||||
text={<T id={'print'} />}
|
||||
onClick={handlePrintBtnClick}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'file-import-16'} />}
|
||||
text={<T id={'import'} />}
|
||||
onClick={handleImportBtnClick}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'file-export-16'} iconSize={'16'} />}
|
||||
text={<T id={'export'} />}
|
||||
onClick={handleExportBtnClick}
|
||||
/>
|
||||
|
||||
<NavbarDivider />
|
||||
<DashboardRowsHeightButton
|
||||
initialValue={paymentMadesTableSize}
|
||||
onChange={handleTableRowSizeChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
</NavbarGroup>
|
||||
<NavbarGroup align={Alignment.RIGHT}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="refresh-16" iconSize={14} />}
|
||||
onClick={handleRefreshBtnClick}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withPaymentMadeActions,
|
||||
withSettingsActions,
|
||||
withPaymentMade(({ paymentMadesTableState }) => ({
|
||||
paymentMadesFilterConditions: paymentMadesTableState.filterRoles,
|
||||
})),
|
||||
withSettings(({ billPaymentSettings }) => ({
|
||||
paymentMadesTableSize: billPaymentSettings?.tableSize,
|
||||
})),
|
||||
withDialogActions,
|
||||
)(PaymentMadeActionsBar);
|
||||
@@ -0,0 +1,55 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import '@/style/pages/PaymentMade/List.scss';
|
||||
|
||||
import { DashboardPageContent } from '@/components';
|
||||
import { PaymentMadesListProvider } from './PaymentMadesListProvider';
|
||||
import PaymentMadeActionsBar from './PaymentMadeActionsBar';
|
||||
import PaymentMadesTable from './PaymentMadesTable';
|
||||
|
||||
import withPaymentMades from './withPaymentMade';
|
||||
import withPaymentMadeActions from './withPaymentMadeActions';
|
||||
|
||||
import { compose, transformTableStateToQuery } from '@/utils';
|
||||
|
||||
/**
|
||||
* Payment mades list.
|
||||
*/
|
||||
function PaymentMadeList({
|
||||
// #withPaymentMades
|
||||
paymentMadesTableState,
|
||||
paymentsTableStateChanged,
|
||||
|
||||
// #withPaymentMadeActions
|
||||
resetPaymentMadesTableState,
|
||||
}) {
|
||||
// Resets the invoices table state once the page unmount.
|
||||
React.useEffect(
|
||||
() => () => {
|
||||
resetPaymentMadesTableState();
|
||||
},
|
||||
[resetPaymentMadesTableState],
|
||||
);
|
||||
|
||||
return (
|
||||
<PaymentMadesListProvider
|
||||
query={transformTableStateToQuery(paymentMadesTableState)}
|
||||
tableStateChanged={paymentsTableStateChanged}
|
||||
>
|
||||
<PaymentMadeActionsBar />
|
||||
|
||||
<DashboardPageContent>
|
||||
<PaymentMadesTable />
|
||||
</DashboardPageContent>
|
||||
</PaymentMadesListProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withPaymentMades(({ paymentMadesTableState, paymentsTableStateChanged }) => ({
|
||||
paymentMadesTableState,
|
||||
paymentsTableStateChanged,
|
||||
})),
|
||||
withPaymentMadeActions,
|
||||
)(PaymentMadeList);
|
||||
@@ -0,0 +1,61 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useHistory } from 'react-router';
|
||||
import { DashboardViewsTabs, FormattedMessage as T } from '@/components';
|
||||
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
import { usePaymentMadesListContext } from './PaymentMadesListProvider';
|
||||
import { transformPaymentViewsToTabs } from './utils';
|
||||
|
||||
import withPaymentMade from './withPaymentMade';
|
||||
import withPaymentMadeActions from './withPaymentMadeActions';
|
||||
|
||||
/**
|
||||
* Payment made views tabs.
|
||||
*/
|
||||
function PaymentMadeViewTabs({
|
||||
// #withPaymentMadesActions
|
||||
setPaymentMadesTableState,
|
||||
|
||||
// #withPaymentMade
|
||||
paymentMadesTableState,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
|
||||
// Payment receives list context.
|
||||
const { paymentMadesViews } = usePaymentMadesListContext();
|
||||
|
||||
// Handle the active tab changning.
|
||||
const handleTabsChange = (viewSlug) => {
|
||||
setPaymentMadesTableState({ viewSlug });
|
||||
};
|
||||
// Transformes payment views to tabs.
|
||||
const tabs = React.useMemo(
|
||||
() => transformPaymentViewsToTabs(paymentMadesViews),
|
||||
[paymentMadesViews],
|
||||
);
|
||||
|
||||
const handleClickNewView = () => {
|
||||
history.push('/custom_views/payments-made/new');
|
||||
};
|
||||
|
||||
return (
|
||||
<Navbar className={'navbar--dashboard-views'}>
|
||||
<NavbarGroup align={Alignment.LEFT}>
|
||||
<DashboardViewsTabs
|
||||
customViewId={paymentMadesTableState.customViewId}
|
||||
defaultTabText={<T id={'all_payments'} />}
|
||||
tabs={tabs}
|
||||
onNewViewTabClick={handleClickNewView}
|
||||
onChange={handleTabsChange}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</Navbar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withPaymentMadeActions,
|
||||
withPaymentMade(({ paymentMadesTableState }) => ({ paymentMadesTableState })),
|
||||
)(PaymentMadeViewTabs);
|
||||
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button, Intent } from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { EmptyStatus, Can, FormattedMessage as T } from '@/components';
|
||||
import { PaymentMadeAction, AbilitySubject } from '@/constants/abilityOption';
|
||||
|
||||
export default function PaymentMadesEmptyStatus() {
|
||||
const history = useHistory();
|
||||
|
||||
return (
|
||||
<EmptyStatus
|
||||
title={<T id={'payment_made.empty_status.title'} />}
|
||||
description={
|
||||
<p>
|
||||
<T id="payment_made_empty_status_description" />
|
||||
</p>
|
||||
}
|
||||
action={
|
||||
<>
|
||||
<Can I={PaymentMadeAction.Create} a={AbilitySubject.PaymentMade}>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
large={true}
|
||||
onClick={() => {
|
||||
history.push('/payments-made/new');
|
||||
}}
|
||||
>
|
||||
<T id={'new_bill_payment'} />
|
||||
</Button>
|
||||
|
||||
<Button intent={Intent.NONE} large={true}>
|
||||
<T id={'learn_more'} />
|
||||
</Button>
|
||||
</Can>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// @ts-nocheck
|
||||
import React, { createContext } from 'react';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
import { DashboardInsider } from '@/components/Dashboard';
|
||||
import {
|
||||
useResourceViews,
|
||||
usePaymentMades,
|
||||
useResourceMeta,
|
||||
} from '@/hooks/query';
|
||||
import { getFieldsFromResourceMeta } from '@/utils';
|
||||
|
||||
const PaymentMadesListContext = createContext();
|
||||
|
||||
/**
|
||||
* Accounts chart data provider.
|
||||
*/
|
||||
function PaymentMadesListProvider({ query, tableStateChanged, ...props }) {
|
||||
// Fetch accounts resource views and fields.
|
||||
const { data: paymentMadesViews, isLoading: isViewsLoading } =
|
||||
useResourceViews('bill_payments');
|
||||
|
||||
// Fetch the accounts resource fields.
|
||||
const {
|
||||
data: resourceMeta,
|
||||
isLoading: isResourceMetaLoading,
|
||||
isFetching: isResourceMetaFetching,
|
||||
} = useResourceMeta('bill_payments');
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { paymentMades, pagination, filterMeta },
|
||||
isLoading: isPaymentsLoading,
|
||||
isFetching: isPaymentsFetching,
|
||||
} = usePaymentMades(query, { keepPreviousData: true });
|
||||
|
||||
// Detarmines the datatable empty status.
|
||||
const isEmptyStatus =
|
||||
isEmpty(paymentMades) && !isPaymentsLoading && !tableStateChanged;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentMades,
|
||||
pagination,
|
||||
filterMeta,
|
||||
paymentMadesViews,
|
||||
|
||||
fields: getFieldsFromResourceMeta(resourceMeta.fields),
|
||||
resourceMeta,
|
||||
isResourceMetaLoading,
|
||||
isResourceMetaFetching,
|
||||
|
||||
isPaymentsLoading,
|
||||
isPaymentsFetching,
|
||||
isViewsLoading,
|
||||
isEmptyStatus,
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardInsider
|
||||
loading={isViewsLoading || isResourceMetaLoading}
|
||||
name={'payment-mades-list'}
|
||||
>
|
||||
<PaymentMadesListContext.Provider value={provider} {...props} />
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
|
||||
const usePaymentMadesListContext = () =>
|
||||
React.useContext(PaymentMadesListContext);
|
||||
|
||||
export { PaymentMadesListProvider, usePaymentMadesListContext };
|
||||
@@ -0,0 +1,144 @@
|
||||
// @ts-nocheck
|
||||
import React, { useCallback } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
import { TABLES } from '@/constants/tables';
|
||||
import {
|
||||
DataTable,
|
||||
DashboardContentTable,
|
||||
TableSkeletonRows,
|
||||
TableSkeletonHeader,
|
||||
} from '@/components';
|
||||
|
||||
import PaymentMadesEmptyStatus from './PaymentMadesEmptyStatus';
|
||||
|
||||
import withPaymentMade from './withPaymentMade';
|
||||
import withPaymentMadeActions from './withPaymentMadeActions';
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
|
||||
import { usePaymentMadesTableColumns, ActionsMenu } from './components';
|
||||
import { usePaymentMadesListContext } from './PaymentMadesListProvider';
|
||||
import { useMemorizedColumnsWidths } from '@/hooks';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
|
||||
/**
|
||||
* Payment made datatable transactions.
|
||||
*/
|
||||
function PaymentMadesTable({
|
||||
// #withPaymentMadeActions
|
||||
setPaymentMadesTableState,
|
||||
|
||||
// #withPaymentMade
|
||||
paymentMadesTableState,
|
||||
|
||||
// #withAlerts
|
||||
openAlert,
|
||||
|
||||
// #withDrawerActions
|
||||
openDrawer,
|
||||
|
||||
// #withSettings
|
||||
paymentMadesTableSize,
|
||||
}) {
|
||||
// Payment mades table columns.
|
||||
const columns = usePaymentMadesTableColumns();
|
||||
|
||||
// Payment mades list context.
|
||||
const {
|
||||
paymentMades,
|
||||
pagination,
|
||||
isEmptyStatus,
|
||||
isPaymentsLoading,
|
||||
isPaymentsFetching,
|
||||
} = usePaymentMadesListContext();
|
||||
|
||||
// History context.
|
||||
const history = useHistory();
|
||||
|
||||
// Handles the edit payment made action.
|
||||
const handleEditPaymentMade = (paymentMade) => {
|
||||
history.push(`/payments-made/${paymentMade.id}/edit`);
|
||||
};
|
||||
|
||||
// Handles the delete payment made action.
|
||||
const handleDeletePaymentMade = (paymentMade) => {
|
||||
openAlert('payment-made-delete', { paymentMadeId: paymentMade.id });
|
||||
};
|
||||
|
||||
// Handle view detail payment made.
|
||||
const handleViewDetailPaymentMade = ({ id }) => {
|
||||
openDrawer(DRAWERS.PAYMENT_MADE_DETAILS, { paymentMadeId: id });
|
||||
};
|
||||
|
||||
// Handle cell click.
|
||||
const handleCellClick = (cell, event) => {
|
||||
openDrawer(DRAWERS.PAYMENT_MADE_DETAILS, {
|
||||
paymentMadeId: cell.row.original.id,
|
||||
});
|
||||
};
|
||||
|
||||
// Local storage memorizing columns widths.
|
||||
const [initialColumnsWidths, , handleColumnResizing] =
|
||||
useMemorizedColumnsWidths(TABLES.PAYMENT_MADES);
|
||||
|
||||
// Handle datatable fetch data once the table state change.
|
||||
const handleDataTableFetchData = useCallback(
|
||||
({ pageIndex, pageSize, sortBy }) => {
|
||||
setPaymentMadesTableState({ pageIndex, pageSize, sortBy });
|
||||
},
|
||||
[setPaymentMadesTableState],
|
||||
);
|
||||
|
||||
// Display empty status instead of the table.
|
||||
if (isEmptyStatus) {
|
||||
return <PaymentMadesEmptyStatus />;
|
||||
}
|
||||
|
||||
return (
|
||||
<DashboardContentTable>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={paymentMades}
|
||||
onFetchData={handleDataTableFetchData}
|
||||
loading={isPaymentsLoading}
|
||||
headerLoading={isPaymentsLoading}
|
||||
progressBarLoading={isPaymentsFetching}
|
||||
manualSortBy={true}
|
||||
selectionColumn={true}
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
pagination={true}
|
||||
pagesCount={pagination.pagesCount}
|
||||
autoResetSortBy={false}
|
||||
autoResetPage={false}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
onCellClick={handleCellClick}
|
||||
initialColumnsWidths={initialColumnsWidths}
|
||||
onColumnResizing={handleColumnResizing}
|
||||
size={paymentMadesTableSize}
|
||||
payload={{
|
||||
onEdit: handleEditPaymentMade,
|
||||
onDelete: handleDeletePaymentMade,
|
||||
onViewDetails: handleViewDetailPaymentMade,
|
||||
}}
|
||||
/>
|
||||
</DashboardContentTable>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withPaymentMadeActions,
|
||||
withPaymentMade(({ paymentMadesTableState }) => ({ paymentMadesTableState })),
|
||||
withAlertsActions,
|
||||
withDrawerActions,
|
||||
withCurrentOrganization(),
|
||||
withSettings(({ billPaymentSettings }) => ({
|
||||
paymentMadesTableSize: billPaymentSettings?.tableSize,
|
||||
})),
|
||||
)(PaymentMadesTable);
|
||||
@@ -0,0 +1,39 @@
|
||||
// @ts-nocheck
|
||||
import React, { useEffect } from 'react';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
|
||||
import PaymentMadeViewTabs from './PaymentMadeViewTabs';
|
||||
|
||||
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Payment mades view page.
|
||||
*/
|
||||
function PaymentMadesViewPage({
|
||||
// #withAlertActions
|
||||
openAlert,
|
||||
}) {
|
||||
return (
|
||||
<Switch>
|
||||
<Route
|
||||
exact={true}
|
||||
path={['/payments-made/:custom_view_id/custom_view', '/payments-made']}
|
||||
>
|
||||
|
||||
{/* <PaymentMadeDataTable
|
||||
onDeletePaymentMade={handleDeletePaymentMade}
|
||||
onEditPaymentMade={handleEditPaymentMade}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
/> */}
|
||||
</Route>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertsActions,
|
||||
withDialogActions,
|
||||
)(PaymentMadesViewPage);
|
||||
@@ -0,0 +1,54 @@
|
||||
// @ts-nocheck
|
||||
import React, { createContext } from 'react';
|
||||
import { DashboardInsider } from '@/components/Dashboard';
|
||||
import {
|
||||
useResourceViews,
|
||||
useResourceFields,
|
||||
usePaymentMades,
|
||||
} from '@/hooks/query';
|
||||
|
||||
const PaymentMadesContext = createContext();
|
||||
|
||||
/**
|
||||
* Accounts chart data provider.
|
||||
*/
|
||||
function PaymentMadesProvider({ query, ...props }) {
|
||||
// Fetch accounts resource views and fields.
|
||||
const { data: paymentsViews, isLoading: isViewsLoading } =
|
||||
useResourceViews('bill_payments');
|
||||
|
||||
// Fetch the accounts resource fields.
|
||||
const { data: paymentsFields, isLoading: isFieldsLoading } =
|
||||
useResourceFields('bill_payments');
|
||||
|
||||
// Fetch accounts list according to the given custom view id.
|
||||
const {
|
||||
data: { paymentMades, pagination },
|
||||
isLoading: isPaymentsLoading,
|
||||
} = usePaymentMades(query);
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentMades,
|
||||
pagination,
|
||||
paymentsFields,
|
||||
paymentsViews,
|
||||
|
||||
isPaymentsLoading,
|
||||
isFieldsLoading,
|
||||
isViewsLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardInsider
|
||||
loading={isViewsLoading || isFieldsLoading}
|
||||
name={'payment_made'}
|
||||
>
|
||||
<PaymentMadesContext.Provider value={provider} {...props} />
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
|
||||
const usePaymentMadesContext = () => React.useContext(PaymentMadesContext);
|
||||
|
||||
export { PaymentMadesProvider, usePaymentMadesContext };
|
||||
@@ -0,0 +1,132 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import {
|
||||
Intent,
|
||||
Button,
|
||||
Popover,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuDivider,
|
||||
Position,
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import { Icon, Money, Can } from '@/components';
|
||||
import { PaymentMadeAction, AbilitySubject } from '@/constants/abilityOption';
|
||||
|
||||
import { safeCallback } from '@/utils';
|
||||
|
||||
export function AmountAccessor(row) {
|
||||
return <Money amount={row.amount} currency={row.currency_code} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions menu.
|
||||
*/
|
||||
export function ActionsMenu({
|
||||
row: { original },
|
||||
payload: { onEdit, onDelete, onViewDetails },
|
||||
}) {
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
icon={<Icon icon="reader-18" />}
|
||||
text={intl.get('view_details')}
|
||||
onClick={safeCallback(onViewDetails, original)}
|
||||
/>
|
||||
|
||||
<Can I={PaymentMadeAction.Edit} a={AbilitySubject.PaymentMade}>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
icon={<Icon icon="pen-18" />}
|
||||
text={intl.get('edit_payment_made')}
|
||||
onClick={safeCallback(onEdit, original)}
|
||||
/>
|
||||
</Can>
|
||||
<Can I={PaymentMadeAction.Delete} a={AbilitySubject.PaymentMade}>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
text={intl.get('delete_payment_made')}
|
||||
intent={Intent.DANGER}
|
||||
onClick={safeCallback(onDelete, original)}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
/>
|
||||
</Can>
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment mades table actions cell.
|
||||
*/
|
||||
export function ActionsCell(props) {
|
||||
return (
|
||||
<Popover
|
||||
content={<ActionsMenu {...props} />}
|
||||
position={Position.RIGHT_BOTTOM}
|
||||
>
|
||||
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payment mades table columns.
|
||||
*/
|
||||
export function usePaymentMadesTableColumns() {
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
id: 'payment_date',
|
||||
Header: intl.get('payment_date'),
|
||||
accessor: 'formatted_payment_date',
|
||||
width: 140,
|
||||
className: 'payment_date',
|
||||
clickable: true,
|
||||
},
|
||||
{
|
||||
id: 'vendor',
|
||||
Header: intl.get('vendor_name'),
|
||||
accessor: 'vendor.display_name',
|
||||
width: 140,
|
||||
className: 'vendor_id',
|
||||
clickable: true,
|
||||
},
|
||||
{
|
||||
id: 'payment_number',
|
||||
Header: intl.get('payment_number'),
|
||||
accessor: (row) =>
|
||||
row.payment_number ? `${row.payment_number}` : null,
|
||||
width: 140,
|
||||
className: 'payment_number',
|
||||
clickable: true,
|
||||
},
|
||||
{
|
||||
id: 'payment_account',
|
||||
Header: intl.get('payment_account'),
|
||||
accessor: 'payment_account.name',
|
||||
width: 140,
|
||||
className: 'payment_account_id',
|
||||
clickable: true,
|
||||
},
|
||||
{
|
||||
id: 'amount',
|
||||
Header: intl.get('amount'),
|
||||
accessor: AmountAccessor,
|
||||
width: 140,
|
||||
className: 'amount',
|
||||
align: 'right',
|
||||
clickable: true,
|
||||
},
|
||||
{
|
||||
id: 'reference_no',
|
||||
Header: intl.get('reference'),
|
||||
accessor: 'reference',
|
||||
width: 140,
|
||||
className: 'reference',
|
||||
clickable: true,
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// @ts-nocheck
|
||||
import { pick } from 'lodash';
|
||||
|
||||
export const transformPaymentViewsToTabs = (paymentMadeViews) => {
|
||||
return paymentMadeViews.map((view) => ({
|
||||
...pick(view, ['name', 'id']),
|
||||
}));
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
// @ts-nocheck
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
getPaymentMadesTableStateFactory,
|
||||
paymentsTableStateChangedFactory,
|
||||
} from '@/store/PaymentMades/paymentMades.selector';
|
||||
|
||||
export default (mapState) => {
|
||||
const getPaymentMadesTableState = getPaymentMadesTableStateFactory();
|
||||
const paymentsTableStateChanged = paymentsTableStateChangedFactory();
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
paymentMadesTableState: getPaymentMadesTableState(state, props),
|
||||
paymentsTableStateChanged: paymentsTableStateChanged(state, props),
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
setPaymentMadesTableState,
|
||||
resetPaymentMadesTableState,
|
||||
} from '@/store/PaymentMades/paymentMades.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setPaymentMadesTableState: (state) =>
|
||||
dispatch(setPaymentMadesTableState(state)),
|
||||
|
||||
resetPaymentMadesTableState: () => dispatch(resetPaymentMadesTableState()),
|
||||
});
|
||||
export default connect(null, mapDispatchToProps);
|
||||
@@ -0,0 +1,12 @@
|
||||
// @ts-nocheck
|
||||
import { connect } from 'react-redux';
|
||||
import { getPaymentMadeByIdFactory } from '@/store/PaymentMades/paymentMade.selector';
|
||||
|
||||
export default () => {
|
||||
const getPaymentMadeById = getPaymentMadeByIdFactory();
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
paymentMade: getPaymentMadeById(state, props),
|
||||
});
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
const PaymentMadeDeleteAlert = React.lazy(
|
||||
() => import('@/containers/Alerts/PaymentMades/PaymentMadeDeleteAlert'),
|
||||
);
|
||||
|
||||
export default [
|
||||
{ name: 'payment-made-delete', component: PaymentMadeDeleteAlert },
|
||||
];
|
||||
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { DashboardInsider } from '@/components';
|
||||
import { ImportView } from '@/containers/Import';
|
||||
|
||||
export default function PaymentsMadeImport() {
|
||||
const history = useHistory();
|
||||
|
||||
const handleCancelBtnClick = () => {
|
||||
history.push('/payments-made');
|
||||
};
|
||||
const handleImportSuccess = () => {
|
||||
history.push('/payments-made');
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardInsider name={'import-payment-mades'}>
|
||||
<ImportView
|
||||
resource={'bill_payment'}
|
||||
onCancelClick={handleCancelBtnClick}
|
||||
onImportSuccess={handleImportSuccess}
|
||||
/>
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { MenuItem } from '@blueprintjs/core';
|
||||
|
||||
import { Icon } from '@/components';
|
||||
import { RESOURCES_TYPES } from '@/constants/resourcesTypes';
|
||||
import { highlightText } from '@/utils';
|
||||
import { AbilitySubject, PaymentMadeAction } from '@/constants/abilityOption';
|
||||
import { DRAWERS } from '@/constants/drawers';
|
||||
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||
|
||||
/**
|
||||
* Universal search bill item select action.
|
||||
*/
|
||||
function PaymentsMadeUniversalSearchSelectComponent({
|
||||
// #ownProps
|
||||
resourceType,
|
||||
resourceId,
|
||||
|
||||
// #withDrawerActions
|
||||
openDrawer,
|
||||
}) {
|
||||
if (resourceType === RESOURCES_TYPES.PAYMENT_MADE) {
|
||||
openDrawer(DRAWERS.PAYMENT_MADE_DETAILS, { paymentMadeId: resourceId });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const PaymentsMadeUniversalSearchSelect = withDrawerActions(
|
||||
PaymentsMadeUniversalSearchSelectComponent,
|
||||
);
|
||||
|
||||
/**
|
||||
* Payment made universal search item.
|
||||
*/
|
||||
export function PaymentsMadeUniversalSearchItem(
|
||||
{ text, label, reference },
|
||||
{ handleClick, modifiers, query },
|
||||
) {
|
||||
return (
|
||||
<MenuItem
|
||||
active={modifiers.active}
|
||||
text={
|
||||
<div>
|
||||
<div>{highlightText(text, query)}</div>
|
||||
|
||||
<span class="bp4-text-muted">
|
||||
{reference.payment_number && (
|
||||
<>
|
||||
{highlightText(reference.payment_number, query)}
|
||||
<Icon icon={'caret-right-16'} iconSize={16} />
|
||||
</>
|
||||
)}
|
||||
{highlightText(reference.formatted_payment_date, query)}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
label={<div class="amount">{label}</div>}
|
||||
onClick={handleClick}
|
||||
className={'universal-search__item--payment-made'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment made resource item to search item.
|
||||
*/
|
||||
const paymentMadeToSearch = (payment) => ({
|
||||
id: payment.id,
|
||||
text: payment.vendor.display_name,
|
||||
label: payment.formatted_amount,
|
||||
reference: payment,
|
||||
});
|
||||
|
||||
/**
|
||||
* Binds universal search payment made configure.
|
||||
*/
|
||||
export const universalSearchPaymentMadeBind = () => ({
|
||||
resourceType: RESOURCES_TYPES.PAYMENT_MADE,
|
||||
optionItemLabel: intl.get('payments_made'),
|
||||
selectItemAction: PaymentsMadeUniversalSearchSelect,
|
||||
itemRenderer: PaymentsMadeUniversalSearchItem,
|
||||
itemSelect: paymentMadeToSearch,
|
||||
permission: {
|
||||
ability: PaymentMadeAction.View,
|
||||
subject: AbilitySubject.PaymentMade,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
export const PAYMENT_MADE_ERRORS = {
|
||||
PAYMENT_NUMBER_NOT_UNIQUE: 'PAYMENT.NUMBER.NOT.UNIQUE',
|
||||
WITHDRAWAL_ACCOUNT_CURRENCY_INVALID: 'WITHDRAWAL_ACCOUNT_CURRENCY_INVALID',
|
||||
INVALID_BILL_PAYMENT_AMOUNT: 'INVALID_BILL_PAYMENT_AMOUNT'
|
||||
};
|
||||
Reference in New Issue
Block a user