Skip to content

Commit

Permalink
Merge branch 'develop' into migrate-pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia authored Oct 4, 2023
2 parents f6a9f10 + 5df454d commit 38ad2d4
Show file tree
Hide file tree
Showing 12 changed files with 13,736 additions and 22 deletions.
13,663 changes: 13,663 additions & 0 deletions packages/server/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bigcapital/server",
"version": "0.10.1",
"version": "0.10.2",
"description": "",
"main": "src/server.ts",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions packages/server/src/models/ItemEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export default class ItemEntry extends TenantModel {
: getExlusiveTaxAmount(this.amount, this.taxRate);
}

static calcAmount(itemEntry) {
const { discount, quantity, rate } = itemEntry;
const total = quantity * rate;

return discount ? total - total * discount * 0.01 : total;
}

/**
* Item entry relations.
*/
Expand Down
15 changes: 14 additions & 1 deletion packages/webapp/src/containers/Entries/ItemsEntriesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ import {
useItemEntriesTableContext,
} from './ItemEntriesTableProvider';
import { useUncontrolled } from '@/hooks/useUncontrolled';
import { ItemEntry } from '@/interfaces/ItemEntries';

interface ItemsEntriesTableProps {
initialValue?: ItemEntry;
value?: ItemEntry[];
onChange?: (entries: ItemEntry[]) => void;
taxRates?: any[];
minLinesNumber?: number;
enableTaxRates?: boolean;
}

/**
* Items entries table.
*/
function ItemsEntriesTable(props) {
function ItemsEntriesTable(props: ItemsEntriesTableProps) {
const { value, initialValue, onChange } = props;

const [localValue, handleChange] = useUncontrolled({
Expand Down Expand Up @@ -119,8 +129,11 @@ ItemsEntriesTable.defaultProps = {
discount: '',
},
initialEntries: [],
taxRates: [],
items: [],
linesNumber: 1,
minLinesNumber: 1,
enableTaxRates: true,
};

export default ItemsEntriesTable;
20 changes: 12 additions & 8 deletions packages/webapp/src/containers/Entries/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const LandedCostHeaderCell = () => {
*/
export function useEditableItemsEntriesColumns() {
const { featureCan } = useFeatureCan();
const { landedCost } = useItemEntriesTableContext();
const { landedCost, enableTaxRates } = useItemEntriesTableContext();

const isProjectsFeatureEnabled = featureCan(Features.Projects);

Expand Down Expand Up @@ -132,13 +132,17 @@ export function useEditableItemsEntriesColumns() {
width: 70,
align: Align.Right,
},
{
Header: 'Tax rate',
accessor: 'tax_rate_id',
Cell: TaxRatesSuggestInputCell,
disableSortBy: true,
width: 110,
},
...(enableTaxRates
? [
{
Header: 'Tax rate',
accessor: 'tax_rate_id',
Cell: TaxRatesSuggestInputCell,
disableSortBy: true,
width: 110,
},
]
: []),
{
Header: intl.get('discount'),
accessor: 'discount',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default function BillFormBody({ defaultBill }) {
meta: { error, touched },
}) => (
<ItemsEntriesTable
entries={value}
onUpdateData={(entries) => {
value={value}
onChange={(entries) => {
setFieldValue('entries', entries);
}}
items={items}
Expand All @@ -37,6 +37,7 @@ export default function BillFormBody({ defaultBill }) {
currencyCode={values.currency_code}
itemType={ITEM_TYPE.PURCHASABLE}
landedCost={true}
enableTaxRates={false}
/>
)}
</FastField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ export default function VendorCreditNoteItemsEntriesEditor() {
meta: { error, touched },
}) => (
<ItemsEntriesTable
entries={value}
onUpdateData={(entries) => {
value={value}
onChange={(entries) => {
setFieldValue('entries', entries);
}}
items={items}
errors={error}
linesNumber={4}
currencyCode={values.currency_code}
enableTaxRates={false}
/>
)}
</FastField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ export default function CreditNoteItemsEntriesEditorField() {
meta: { error, touched },
}) => (
<ItemsEntriesTable
entries={value}
onUpdateData={(entries) => {
value={value}
onChange={(entries) => {
setFieldValue('entries', entries);
}}
items={items}
errors={error}
linesNumber={4}
currencyCode={values.currency_code}
enableTaxRates={false}
/>
)}
</FastField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ export default function EstimateFormItemsEntriesField() {
meta: { error, touched },
}) => (
<ItemsEntriesTable
entries={value}
onUpdateData={(entries) => {
value={value}
onChange={(entries) => {
setFieldValue('entries', entries);
}}
items={items}
errors={error}
linesNumber={4}
currencyCode={values.currency_code}
enableTaxRates={false}
/>
)}
</FastField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export const defaultEstimateEntry = {
amount: '',
};

const defaultEstimateEntryReq = {
index: 0,
item_id: '',
rate: '',
discount: '',
quantity: '',
description: '',
};

export const defaultEstimate = {
customer_id: '',
estimate_date: moment(new Date()).format('YYYY-MM-DD'),
Expand Down Expand Up @@ -148,7 +157,9 @@ export const transfromsFormValuesToRequest = (values) => {
...(values.estimate_number_manually && {
estimate_number: values.estimate_number,
}),
entries: entries.map((entry) => ({ ...omit(entry, ['amount']) })),
entries: entries.map((entry) => ({
...transformToForm(entry, defaultEstimateEntryReq),
})),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export default function ReceiptItemsEntriesEditor({ defaultReceipt }) {
meta: { error, touched },
}) => (
<ItemsEntriesTable
entries={value}
onUpdateData={(entries) => {
value={value}
onChange={(entries) => {
setFieldValue('entries', entries);
}}
items={items}
errors={error}
linesNumber={4}
currencyCode={values.currency_code}
enableTaxRates={false}
/>
)}
</FastField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export const defaultReceiptEntry = {
amount: '',
};

const defaultReceiptEntryReq = {
index: 0,
item_id: '',
rate: '',
discount: '',
quantity: '',
description: '',
};

export const defaultReceipt = {
customer_id: '',
deposit_account_id: '',
Expand Down Expand Up @@ -140,7 +149,9 @@ export const transformFormValuesToRequest = (values) => {
...(values.receipt_number_manually && {
receipt_number: values.receipt_number,
}),
entries: entries.map((entry) => ({ ...omit(entry, ['amount']) })),
entries: entries.map((entry) => ({
...transformToForm(entry, defaultReceiptEntryReq),
})),
closed: false,
};
};
Expand Down

0 comments on commit 38ad2d4

Please sign in to comment.