Fix :Sells and purchases transactions numbers to optional.

This commit is contained in:
elforjani3
2020-11-22 12:00:01 +02:00
parent f73ed19e77
commit 29d5f7d74b
9 changed files with 37 additions and 30 deletions

View File

@@ -158,7 +158,7 @@ function BillsDataTable({
{ {
id: 'bill_number', id: 'bill_number',
Header: formatMessage({ id: 'bill_number' }), Header: formatMessage({ id: 'bill_number' }),
accessor: (row) => `#${row.bill_number}`, accessor: (row) => (row.bill_number ? `#${row.bill_number}` : null),
width: 140, width: 140,
className: 'bill_number', className: 'bill_number',
}, },

View File

@@ -110,7 +110,7 @@ function PaymentMadeDataTable({
{ {
id: 'payment_number', id: 'payment_number',
Header: formatMessage({ id: 'payment_number' }), Header: formatMessage({ id: 'payment_number' }),
accessor: (row) => `#${row.payment_number}`, accessor: (row) => (row.payment_number ? `#${row.payment_number}` : null),
width: 140, width: 140,
className: 'payment_number', className: 'payment_number',
}, },

View File

@@ -14,6 +14,7 @@ const Schema = Yup.object().shape({
.label(formatMessage({ id: 'payment_account_' })), .label(formatMessage({ id: 'payment_account_' })),
payment_number: Yup.string() payment_number: Yup.string()
.max(DATATYPES_LENGTH.STRING) .max(DATATYPES_LENGTH.STRING)
.nullable()
.label(formatMessage({ id: 'payment_no_' })), .label(formatMessage({ id: 'payment_no_' })),
reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(), reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
description: Yup.string().max(DATATYPES_LENGTH.TEXT), description: Yup.string().max(DATATYPES_LENGTH.TEXT),

View File

@@ -162,7 +162,6 @@ function PaymentMadeFormHeader({
label={<T id={'payment_no'} />} label={<T id={'payment_no'} />}
inline={true} inline={true}
className={('form-group--payment_number', Classes.FILL)} className={('form-group--payment_number', Classes.FILL)}
labelInfo={<FieldRequiredHint />}
intent={ intent={
errors.payment_number && touched.payment_number && Intent.DANGER errors.payment_number && touched.payment_number && Intent.DANGER
} }

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect, useMemo, useCallback } from 'react'; import React, { useState, useEffect, useMemo, useCallback } from 'react';
import { Button } from '@blueprintjs/core'; import { Button } from '@blueprintjs/core';
import { FormattedMessage as T, useIntl } from 'react-intl'; import { FormattedMessage as T, useIntl } from 'react-intl';
import moment from 'moment'; import moment from 'moment';
import { sumBy } from 'lodash'; import { sumBy } from 'lodash';
@@ -26,7 +26,7 @@ const CellRenderer = (content, type) => (props) => {
const TotalCellRederer = (content, type) => (props) => { const TotalCellRederer = (content, type) => (props) => {
if (props.data.length === props.row.index + 1) { if (props.data.length === props.row.index + 1) {
return <Money amount={props.cell.row.original[type]} currency={'USD'} /> return <Money amount={props.cell.row.original[type]} currency={'USD'} />;
} }
return content(props); return content(props);
}; };
@@ -40,15 +40,17 @@ export default function PaymentMadeItemsTableEditor({
onUpdateData, onUpdateData,
data, data,
errors, errors,
noResultsMessage noResultsMessage,
}) { }) {
const transformedData = useMemo(() => { const transformedData = useMemo(() => {
const rows = [ ...data ]; const rows = [...data];
const totalRow = { const totalRow = {
due_amount: sumBy(data, 'due_amount'), due_amount: sumBy(data, 'due_amount'),
payment_amount: sumBy(data, 'payment_amount'), payment_amount: sumBy(data, 'payment_amount'),
}; };
if (rows.length > 0) { rows.push(totalRow) } if (rows.length > 0) {
rows.push(totalRow);
}
return rows; return rows;
}, [data]); }, [data]);
@@ -80,7 +82,7 @@ export default function PaymentMadeItemsTableEditor({
}, },
{ {
Header: formatMessage({ id: 'bill_number' }), Header: formatMessage({ id: 'bill_number' }),
accessor: (row) => `#${row?.bill_number}`, accessor: (row) => `#${row?.bill_number || ''}`,
Cell: CellRenderer(EmptyDiv, 'bill_number'), Cell: CellRenderer(EmptyDiv, 'bill_number'),
disableSortBy: true, disableSortBy: true,
className: 'bill_number', className: 'bill_number',
@@ -116,7 +118,7 @@ export default function PaymentMadeItemsTableEditor({
}; };
const rowClassNames = useCallback( const rowClassNames = useCallback(
(row) => ({ 'row--total': localData.length === row.index + 1 }), (row) => ({ 'row--total': localData.length === row.index + 1 }),
[localData], [localData],
); );
@@ -129,7 +131,7 @@ export default function PaymentMadeItemsTableEditor({
columnId, columnId,
value, value,
); );
newRows.splice(-1,1); // removes the total row. newRows.splice(-1, 1); // removes the total row.
setLocalData(newRows); setLocalData(newRows);
onUpdateData && onUpdateData(newRows); onUpdateData && onUpdateData(newRows);
@@ -138,10 +140,12 @@ export default function PaymentMadeItemsTableEditor({
); );
return ( return (
<div className={classNames( <div
CLASSES.DATATABLE_EDITOR, className={classNames(
CLASSES.DATATABLE_EDITOR_ITEMS_ENTRIES, CLASSES.DATATABLE_EDITOR,
)}> CLASSES.DATATABLE_EDITOR_ITEMS_ENTRIES,
)}
>
<DataTable <DataTable
columns={columns} columns={columns}
data={localData} data={localData}

View File

@@ -114,7 +114,7 @@ function EstimatesDataTable({
{ {
id: 'estimate_number', id: 'estimate_number',
Header: formatMessage({ id: 'estimate_number' }), Header: formatMessage({ id: 'estimate_number' }),
accessor: (row) => `#${row.estimate_number}`, accessor: (row) => (row.estimate_number ? `#${row.estimate_number}` : null),
width: 140, width: 140,
className: 'estimate_number', className: 'estimate_number',
}, },

View File

@@ -112,7 +112,7 @@ function InvoicesDataTable({
{ {
id: 'invoice_no', id: 'invoice_no',
Header: formatMessage({ id: 'invoice_no__' }), Header: formatMessage({ id: 'invoice_no__' }),
accessor: (row) => `#${row.invoice_no}`, accessor: (row) => (row.invoice_no ? `#${row.invoice_no}` : null),
width: 140, width: 140,
className: 'invoice_no', className: 'invoice_no',
}, },

View File

@@ -26,12 +26,12 @@ const CellRenderer = (content, type) => (props) => {
const TotalCellRederer = (content, type) => (props) => { const TotalCellRederer = (content, type) => (props) => {
if (props.data.length === props.row.index + 1) { if (props.data.length === props.row.index + 1) {
return <Money amount={props.cell.row.original[type]} currency={'USD'} /> return <Money amount={props.cell.row.original[type]} currency={'USD'} />;
} }
return content(props); return content(props);
}; };
export default function PaymentReceiveItemsTableEditor ({ export default function PaymentReceiveItemsTableEditor({
onClickClearAllLines, onClickClearAllLines,
onUpdateData, onUpdateData,
data, data,
@@ -39,12 +39,14 @@ export default function PaymentReceiveItemsTableEditor ({
noResultsMessage, noResultsMessage,
}) { }) {
const transformedData = useMemo(() => { const transformedData = useMemo(() => {
const rows = [ ...data ]; const rows = [...data];
const totalRow = { const totalRow = {
due_amount: sumBy(data, 'due_amount'), due_amount: sumBy(data, 'due_amount'),
payment_amount: sumBy(data, 'payment_amount'), payment_amount: sumBy(data, 'payment_amount'),
}; };
if (rows.length > 0) { rows.push(totalRow) } if (rows.length > 0) {
rows.push(totalRow);
}
return rows; return rows;
}, [data]); }, [data]);
@@ -81,7 +83,7 @@ export default function PaymentReceiveItemsTableEditor ({
Header: formatMessage({ id: 'invocie_number' }), Header: formatMessage({ id: 'invocie_number' }),
accessor: (row) => { accessor: (row) => {
const invNumber = row?.invoice_no || row?.id; const invNumber = row?.invoice_no || row?.id;
return `#INV-${invNumber}`; return `#INV-${invNumber || ''}`;
}, },
Cell: CellRenderer(EmptyDiv, 'invoice_no'), Cell: CellRenderer(EmptyDiv, 'invoice_no'),
disableSortBy: true, disableSortBy: true,
@@ -121,7 +123,7 @@ export default function PaymentReceiveItemsTableEditor ({
}; };
const rowClassNames = useCallback( const rowClassNames = useCallback(
(row) => ({ 'row--total': localData.length === row.index + 1 }), (row) => ({ 'row--total': localData.length === row.index + 1 }),
[localData], [localData],
); );
@@ -144,10 +146,12 @@ export default function PaymentReceiveItemsTableEditor ({
); );
return ( return (
<div className={classNames( <div
CLASSES.DATATABLE_EDITOR, className={classNames(
CLASSES.DATATABLE_EDITOR_ITEMS_ENTRIES, CLASSES.DATATABLE_EDITOR,
)}> CLASSES.DATATABLE_EDITOR_ITEMS_ENTRIES,
)}
>
<DataTable <DataTable
columns={columns} columns={columns}
data={localData} data={localData}
@@ -170,5 +174,4 @@ export default function PaymentReceiveItemsTableEditor ({
</div> </div>
</div> </div>
); );
}
}

View File

@@ -111,7 +111,7 @@ function ReceiptsDataTable({
{ {
id: 'receipt_number', id: 'receipt_number',
Header: formatMessage({ id: 'receipt_number' }), Header: formatMessage({ id: 'receipt_number' }),
accessor: (row) => `#${row.receipt_number}`, accessor: (row) => (row.receipt_number ? `#${row.receipt_number}` : null),
width: 140, width: 140,
className: 'receipt_number', className: 'receipt_number',
}, },