mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
50 lines
964 B
JavaScript
50 lines
964 B
JavaScript
import path from 'path';
|
|
import { Model } from 'objection';
|
|
import TenantModel from 'models/TenantModel';
|
|
|
|
export default class ItemEntry extends TenantModel {
|
|
/**
|
|
* Table name.
|
|
*/
|
|
static get tableName() {
|
|
return 'items_entries';
|
|
}
|
|
|
|
/**
|
|
* Timestamps columns.
|
|
*/
|
|
get timestamps() {
|
|
return ['created_at', 'updated_at'];
|
|
}
|
|
|
|
static get virtualAttributes() {
|
|
return ['amount'];
|
|
}
|
|
|
|
static amount() {
|
|
return this.calcAmount(this);
|
|
}
|
|
|
|
static calcAmount(itemEntry) {
|
|
const { discount, quantity, rate } = itemEntry;
|
|
const total = quantity * rate;
|
|
|
|
return discount ? total - (total * discount * 0.01) : total;
|
|
}
|
|
|
|
static get relationMappings() {
|
|
const Item = require('models/Item');
|
|
|
|
return {
|
|
item: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: Item.default,
|
|
join: {
|
|
from: 'items_entries.itemId',
|
|
to: 'items.id',
|
|
},
|
|
},
|
|
};
|
|
}
|
|
}
|