mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
import { Model } from 'objection';
|
|
import moment from 'moment';
|
|
import TenantModel from 'models/TenantModel';
|
|
|
|
export default class InventoryCostLotTracker extends TenantModel {
|
|
/**
|
|
* Table name
|
|
*/
|
|
static get tableName() {
|
|
return 'inventory_cost_lot_tracker';
|
|
}
|
|
|
|
/**
|
|
* Model timestamps.
|
|
*/
|
|
static get timestamps() {
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Model modifiers.
|
|
*/
|
|
static get modifiers() {
|
|
return {
|
|
groupedEntriesCost(query) {
|
|
query.select(['entry_id', 'transaction_id', 'transaction_type']);
|
|
|
|
query.groupBy('item_id');
|
|
query.groupBy('entry_id');
|
|
query.groupBy('transaction_id');
|
|
query.groupBy('transaction_type');
|
|
|
|
query.sum('cost as cost');
|
|
},
|
|
filterDateRange(query, startDate, endDate, type = 'day') {
|
|
const dateFormat = 'YYYY-MM-DD HH:mm:ss';
|
|
const fromDate = moment(startDate).startOf(type).format(dateFormat);
|
|
const toDate = moment(endDate).endOf(type).format(dateFormat);
|
|
|
|
if (startDate) {
|
|
query.where('date', '>=', fromDate);
|
|
}
|
|
if (endDate) {
|
|
query.where('date', '<=', toDate);
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* Relationship mapping.
|
|
*/
|
|
static get relationMappings() {
|
|
const Item = require('models/Item');
|
|
|
|
return {
|
|
item: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: Item.default,
|
|
join: {
|
|
from: 'inventory_cost_lot_tracker.itemId',
|
|
to: 'items.id',
|
|
},
|
|
},
|
|
};
|
|
}
|
|
}
|