mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Inventory item details report.
feat: Cash flow statement report.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Model } from 'objection';
|
||||
import { Model, raw } from 'objection';
|
||||
import moment from 'moment';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
|
||||
@@ -138,6 +138,21 @@ export default class AccountTransaction extends TenantModel {
|
||||
query.sum('credit as credit');
|
||||
query.sum('debit as debit');
|
||||
query.select('contactId');
|
||||
},
|
||||
creditDebitSummation(query) {
|
||||
query.sum('credit as credit');
|
||||
query.sum('debit as debit');
|
||||
},
|
||||
groupByDateFormat(query, groupType = 'month') {
|
||||
const groupBy = {
|
||||
'day': '%Y-%m-%d',
|
||||
'month': '%Y-%m',
|
||||
'year': '%Y',
|
||||
};
|
||||
const dateFormat = groupBy[groupType];
|
||||
|
||||
query.select(raw(`DATE_FORMAT(DATE, '${dateFormat}')`).as('date'));
|
||||
query.groupByRaw(`DATE_FORMAT(DATE, '${dateFormat}')`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,6 +17,33 @@ export default class InventoryTransaction extends TenantModel {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve formatted reference type.
|
||||
* @return {string}
|
||||
*/
|
||||
get transcationTypeFormatted() {
|
||||
return InventoryTransaction.getReferenceTypeFormatted(this.transactionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference type formatted.
|
||||
*/
|
||||
static getReferenceTypeFormatted(referenceType) {
|
||||
const mapped = {
|
||||
'SaleInvoice': 'Sale invoice',
|
||||
'SaleReceipt': 'Sale receipt',
|
||||
'PaymentReceive': 'Payment receive',
|
||||
'Bill': 'Bill',
|
||||
'BillPayment': 'Payment made',
|
||||
'VendorOpeningBalance': 'Vendor opening balance',
|
||||
'CustomerOpeningBalance': 'Customer opening balance',
|
||||
'InventoryAdjustment': 'Inventory adjustment',
|
||||
'ManualJournal': 'Manual journal',
|
||||
'Journal': 'Manual journal',
|
||||
};
|
||||
return mapped[referenceType] || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Model modifiers.
|
||||
*/
|
||||
@@ -59,8 +86,47 @@ export default class InventoryTransaction extends TenantModel {
|
||||
static get relationMappings() {
|
||||
const Item = require('models/Item');
|
||||
const ItemEntry = require('models/ItemEntry');
|
||||
const InventoryTransactionMeta = require('models/InventoryTransactionMeta');
|
||||
const InventoryCostLots = require('models/InventoryCostLotTracker');
|
||||
|
||||
return {
|
||||
// Transaction meta.
|
||||
meta: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: InventoryTransactionMeta.default,
|
||||
join: {
|
||||
from: 'inventory_transactions.id',
|
||||
to: 'inventory_transaction_meta.inventoryTransactionId',
|
||||
},
|
||||
},
|
||||
// Item cost aggregated.
|
||||
itemCostAggregated: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: InventoryCostLots.default,
|
||||
join: {
|
||||
from: 'inventory_transactions.itemId',
|
||||
to: 'inventory_cost_lot_tracker.itemId',
|
||||
},
|
||||
filter(query) {
|
||||
query.select('itemId');
|
||||
query.sum('cost as cost');
|
||||
query.sum('quantity as quantity');
|
||||
query.groupBy('itemId');
|
||||
},
|
||||
},
|
||||
costLotAggregated: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: InventoryCostLots.default,
|
||||
join: {
|
||||
from: 'inventory_transactions.id',
|
||||
to: 'inventory_cost_lot_tracker.inventoryTransactionId',
|
||||
},
|
||||
filter(query) {
|
||||
query.sum('cost as cost');
|
||||
query.sum('quantity as quantity');
|
||||
query.groupBy('inventoryTransactionId');
|
||||
}
|
||||
},
|
||||
item: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Item.default,
|
||||
|
||||
29
server/src/models/InventoryTransactionMeta.js
Normal file
29
server/src/models/InventoryTransactionMeta.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Model, raw } from 'objection';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
|
||||
export default class InventoryTransactionMeta extends TenantModel {
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'inventory_transaction_meta';
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const InventoryTransactions = require('models/InventoryTransaction');
|
||||
|
||||
return {
|
||||
inventoryTransaction: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: InventoryTransactions.default,
|
||||
join: {
|
||||
from: 'inventory_transaction_meta.inventoryTransactionId',
|
||||
to: 'inventory_transactions.inventoryTransactionId'
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user