feat(invoice): add branch & warehouse schema.

This commit is contained in:
elforjani13
2022-02-07 13:45:00 +02:00
parent fe3314b5cb
commit 3b7e2ce812
7 changed files with 73 additions and 65 deletions

View File

@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
export default function FlagKit({ flage }) { export const FlagTag = ({ flage }) => {
return ( return (
<React.Fragment> <React.Fragment>
<Img <Img
@@ -10,7 +10,7 @@ export default function FlagKit({ flage }) {
/> />
</React.Fragment> </React.Fragment>
); );
} };
const Img = styled.img` const Img = styled.img`
display: inline-block; display: inline-block;

View File

@@ -1,3 +1,4 @@
export * from './CurrencyTag'; export * from './CurrencyTag';
export * from './FlagTag'

View File

@@ -3,53 +3,51 @@ import intl from 'react-intl-universal';
import { DATATYPES_LENGTH } from 'common/dataTypes'; import { DATATYPES_LENGTH } from 'common/dataTypes';
import { isBlank } from 'utils'; import { isBlank } from 'utils';
const getSchema = () => Yup.object().shape({ const getSchema = () =>
customer_id: Yup.string() Yup.object().shape({
.label(intl.get('customer_name_')) customer_id: Yup.string().label(intl.get('customer_name_')).required(),
.required(), invoice_date: Yup.date().required().label(intl.get('invoice_date_')),
invoice_date: Yup.date() due_date: Yup.date().required().label(intl.get('due_date_')),
.required() invoice_no: Yup.string()
.label(intl.get('invoice_date_')), .max(DATATYPES_LENGTH.STRING)
due_date: Yup.date() .label(intl.get('invoice_no_')),
.required() reference_no: Yup.string().min(1).max(DATATYPES_LENGTH.STRING),
.label(intl.get('due_date_')), delivered: Yup.boolean(),
invoice_no: Yup.string() from_estimate_id: Yup.string(),
.max(DATATYPES_LENGTH.STRING) invoice_message: Yup.string()
.label(intl.get('invoice_no_')), .trim()
reference_no: Yup.string().min(1).max(DATATYPES_LENGTH.STRING), .min(1)
delivered: Yup.boolean(), .max(DATATYPES_LENGTH.TEXT)
from_estimate_id: Yup.string(), .label(intl.get('note')),
invoice_message: Yup.string() terms_conditions: Yup.string()
.trim() .trim()
.min(1) .min(1)
.max(DATATYPES_LENGTH.TEXT) .max(DATATYPES_LENGTH.TEXT)
.label(intl.get('note')), .label(intl.get('note')),
terms_conditions: Yup.string() exchange_rate: Yup.number(),
.trim() branch_id: Yup.string(),
.min(1) warehouse_id: Yup.string(),
.max(DATATYPES_LENGTH.TEXT) entries: Yup.array().of(
.label(intl.get('note')), Yup.object().shape({
entries: Yup.array().of( quantity: Yup.number()
Yup.object().shape({ .nullable()
quantity: Yup.number() .max(DATATYPES_LENGTH.INT_10)
.nullable() .when(['rate'], {
.max(DATATYPES_LENGTH.INT_10) is: (rate) => rate,
.when(['rate'], { then: Yup.number().required(),
is: (rate) => rate, }),
then: Yup.number().required(), rate: Yup.number().nullable().max(DATATYPES_LENGTH.INT_10),
}), item_id: Yup.number()
rate: Yup.number().nullable().max(DATATYPES_LENGTH.INT_10), .nullable()
item_id: Yup.number() .when(['quantity', 'rate'], {
.nullable() is: (quantity, rate) => !isBlank(quantity) && !isBlank(rate),
.when(['quantity', 'rate'], { then: Yup.number().required(),
is: (quantity, rate) => !isBlank(quantity) && !isBlank(rate), }),
then: Yup.number().required(), discount: Yup.number().nullable().min(0).max(100),
}), description: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT),
discount: Yup.number().nullable().min(0).max(100), }),
description: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT), ),
}), });
),
});
export const getCreateInvoiceFormSchema = getSchema; export const getCreateInvoiceFormSchema = getSchema;
export const getEditInvoiceFormSchema = getSchema; export const getEditInvoiceFormSchema = getSchema;

View File

@@ -4,12 +4,13 @@ import {
InputGroup, InputGroup,
Position, Position,
ControlGroup, ControlGroup,
Classes,
} from '@blueprintjs/core'; } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime'; import { DateInput } from '@blueprintjs/datetime';
import { FastField, Field, ErrorMessage } from 'formik'; import { FastField, Field, ErrorMessage } from 'formik';
import { FormattedMessage as T, Col, Row } from 'components'; import { FormattedMessage as T, Col, Row } from 'components';
import { momentFormatter, compose, tansformDateValue } from 'utils'; import { momentFormatter, compose, tansformDateValue } from 'utils';
import { upperCase } from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import styled from 'styled-components'; import styled from 'styled-components';
@@ -25,19 +26,22 @@ import {
Icon, Icon,
InputPrependButton, InputPrependButton,
MoneyInputGroup, MoneyInputGroup,
FlagTag,
} from 'components'; } from 'components';
import ItemsSuggestField from 'components/ItemsSuggestField';
import { useInvoiceFormContext } from './InvoiceFormProvider'; import { useInvoiceFormContext } from './InvoiceFormProvider';
import withSettings from 'containers/Settings/withSettings'; import withSettings from 'containers/Settings/withSettings';
import withDialogActions from 'containers/Dialog/withDialogActions'; import withDialogActions from 'containers/Dialog/withDialogActions';
import { inputIntent, handleDateChange } from 'utils'; import { inputIntent, handleDateChange } from 'utils';
import BaseCurrency from './BaseCurrency'; import BaseCurrency from './BaseCurrency';
import FlagKit from './FlagKit';
const Data = [ const Data = [
{ {
id: '10', id: 10,
name: 'Due on Receipt',
},
{
id: 20,
name: 'Due on Receipt', name: 'Due on Receipt',
}, },
]; ];
@@ -118,7 +122,7 @@ function InvoiceFormHeaderFields({
</CustomerName> </CustomerName>
<ExchangeWrapp> <ExchangeWrapp>
<ExchangeLable> <ExchangeLable>
<FlagKit flage={'US'} /> 1 USD = <FlagTag flage={'US'} /> 1 USD =
</ExchangeLable> </ExchangeLable>
{/* ----------- Exchange reate ----------- */} {/* ----------- Exchange reate ----------- */}
@@ -138,14 +142,16 @@ function InvoiceFormHeaderFields({
value={field.value} value={field.value}
allowDecimals={false} allowDecimals={false}
allowNegativeValue={true} allowNegativeValue={true}
onChange={(value) => {}} onChange={(value) => {
setFieldValue('exchange_rate', value);
}}
intent={inputIntent({ error, touched })} intent={inputIntent({ error, touched })}
/> />
</FormGroup> </FormGroup>
)} )}
</Field> </Field>
<ExchangeLable> <ExchangeLable>
<FlagKit flage={'LY'} /> LYD <FlagTag flage={'LY'} /> LYD
</ExchangeLable> </ExchangeLable>
</ExchangeWrapp> </ExchangeWrapp>
<Row> <Row>

View File

@@ -17,30 +17,30 @@ export default function InvoiceFormTopBar() {
return ( return (
<Navbar className={'navbar--dashboard-topbar'}> <Navbar className={'navbar--dashboard-topbar'}>
<NavbarGroup align={Alignment.LEFT}> <NavbarGroup align={Alignment.LEFT}>
<FastField name={'branch'}> <FastField name={'branch_id'}>
{({ form, field: { value }, meta: { error, touched } }) => ( {({ form, field: { value }, meta: { error, touched } }) => (
<CustomSelectList <CustomSelectList
items={branches} items={branches}
text={'Branch'} text={'Branch'}
onItemSelected={(item) => { onItemSelected={({ id }) => {
form.setFieldValue('name', item.id); form.setFieldValue('branch_id', id);
}} }}
selectedItemId={value} selectedItemId={value}
buttonProps={{ buttonProps={{
icon: <Icon icon={'domain-16'} iconSize={20} />, icon: <Icon icon={'branch-16'} iconSize={20} />,
}} }}
/> />
)} )}
</FastField> </FastField>
<NavbarDivider /> <NavbarDivider />
<FastField name={'warehouse'}> <FastField name={'warehouse_id'}>
{({ form, field: { value }, meta: { error, touched } }) => ( {({ form, field: { value }, meta: { error, touched } }) => (
<CustomSelectList <CustomSelectList
items={warehouses} items={warehouses}
text={'Warehosue'} text={'Warehosue'}
onItemSelected={(item) => { onItemSelected={({ id }) => {
form.setFieldValue('warehouse', item.id); form.setFieldValue('warehouse_id', id);
}} }}
selectedItemId={value} selectedItemId={value}
buttonProps={{ buttonProps={{

View File

@@ -43,6 +43,9 @@ export const defaultInvoice = {
reference_no: '', reference_no: '',
invoice_message: '', invoice_message: '',
terms_conditions: '', terms_conditions: '',
exchange_rate: '',
branch_id: '',
warehouse_id: '',
entries: [...repeatValue(defaultInvoiceEntry, MIN_LINES_NUMBER)], entries: [...repeatValue(defaultInvoiceEntry, MIN_LINES_NUMBER)],
}; };

View File

@@ -528,7 +528,7 @@ export default {
], ],
viewBox: '0 0 24 24', viewBox: '0 0 24 24',
}, },
'domain-16': { 'branch-16': {
path: [ path: [
'M12 7V3H2v18h20V7H12zM6 19H4v-2h2v2zm0-4H4v-2h2v2zm0-4H4V9h2v2zm0-4H4V5h2v2zm4 12H8v-2h2v2zm0-4H8v-2h2v2zm0-4H8V9h2v2zm0-4H8V5h2v2zm10 12h-8v-2h2v-2h-2v-2h2v-2h-2V9h8v10zm-2-8h-2v2h2v-2zm0 4h-2v2h2v-2z', 'M12 7V3H2v18h20V7H12zM6 19H4v-2h2v2zm0-4H4v-2h2v2zm0-4H4V9h2v2zm0-4H4V5h2v2zm4 12H8v-2h2v2zm0-4H8v-2h2v2zm0-4H8V9h2v2zm0-4H8V5h2v2zm10 12h-8v-2h2v-2h-2v-2h2v-2h-2V9h8v10zm-2-8h-2v2h2v-2zm0 4h-2v2h2v-2z',
], ],