mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
Merge branch 'develop'
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
import React from 'react';
|
||||
import { sumBy, round } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import { defaultFastFieldShouldUpdate } from 'utils';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
/**
|
||||
* Retrieve the landed cost transaction by the given id.
|
||||
*/
|
||||
export function getCostTransactionById(id, transactions) {
|
||||
return transactions.find((trans) => trans.id === id);
|
||||
}
|
||||
import { defaultFastFieldShouldUpdate } from 'utils';
|
||||
import { MoneyFieldCell } from 'components';
|
||||
|
||||
export const defaultInitialItem = {
|
||||
entry_id: '',
|
||||
cost: '',
|
||||
};
|
||||
|
||||
// Default form initial values.
|
||||
export const defaultInitialValues = {
|
||||
transaction_type: 'Bill',
|
||||
transaction_id: '',
|
||||
transaction_entry_id: '',
|
||||
amount: '',
|
||||
allocation_method: 'quantity',
|
||||
items: [defaultInitialItem],
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve transaction entries of the given transaction id.
|
||||
@@ -17,10 +29,23 @@ export function getEntriesByTransactionId(transactions, id) {
|
||||
return transaction ? transaction.entries : [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} transaction
|
||||
* @param {*} transactionEntryId
|
||||
* @returns
|
||||
*/
|
||||
export function getTransactionEntryById(transaction, transactionEntryId) {
|
||||
return transaction.entries.find((entry) => entry.id === transactionEntryId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} total
|
||||
* @param {*} allocateType
|
||||
* @param {*} entries
|
||||
* @returns
|
||||
*/
|
||||
export function allocateCostToEntries(total, allocateType, entries) {
|
||||
return R.compose(
|
||||
R.when(
|
||||
@@ -43,12 +68,12 @@ export function allocateCostToEntries(total, allocateType, entries) {
|
||||
export function allocateCostByValue(total, entries) {
|
||||
const totalAmount = sumBy(entries, 'amount');
|
||||
|
||||
const _entries = entries.map((entry) => ({
|
||||
const entriesMapped = entries.map((entry) => ({
|
||||
...entry,
|
||||
percentageOfValue: entry.amount / totalAmount,
|
||||
}));
|
||||
|
||||
return _entries.map((entry) => ({
|
||||
return entriesMapped.map((entry) => ({
|
||||
...entry,
|
||||
cost: round(entry.percentageOfValue * total, 2),
|
||||
}));
|
||||
@@ -74,6 +99,13 @@ export function allocateCostByQuantity(total, entries) {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the landed cost transaction by the given id.
|
||||
*/
|
||||
export function getCostTransactionById(id, transactions) {
|
||||
return transactions.find((trans) => trans.id === id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines the transactions selet field when should update.
|
||||
*/
|
||||
@@ -84,7 +116,55 @@ export function transactionsSelectShouldUpdate(newProps, oldProps) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} entries
|
||||
* @returns
|
||||
*/
|
||||
export function resetAllocatedCostEntries(entries) {
|
||||
return entries.map((entry) => ({ ...entry, cost: 0 }));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves allocate landed cost entries table columns.
|
||||
*/
|
||||
export const useAllocateLandedCostEntriesTableColumns = () => {
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: intl.get('item'),
|
||||
accessor: 'item.name',
|
||||
disableSortBy: true,
|
||||
width: '150',
|
||||
},
|
||||
{
|
||||
Header: intl.get('quantity'),
|
||||
accessor: 'quantity',
|
||||
disableSortBy: true,
|
||||
width: '100',
|
||||
},
|
||||
{
|
||||
Header: intl.get('rate'),
|
||||
accessor: 'rate',
|
||||
disableSortBy: true,
|
||||
width: '100',
|
||||
align: 'right',
|
||||
},
|
||||
{
|
||||
Header: intl.get('amount'),
|
||||
accessor: 'amount',
|
||||
disableSortBy: true,
|
||||
align: 'right',
|
||||
width: '100',
|
||||
},
|
||||
{
|
||||
Header: intl.get('cost'),
|
||||
accessor: 'cost',
|
||||
width: '150',
|
||||
Cell: MoneyFieldCell,
|
||||
disableSortBy: true,
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user