Files
bigcapital/server/src/models/SaleReceipt.js
a.bouhuolia 27483495cb feat: closed sale receipt status.
feat: approve and reject sale estimate.
feat: initial receipts, invoices, estimates and bills views.
2020-12-14 20:25:38 +02:00

115 lines
2.4 KiB
JavaScript

import { Model, mixin } from 'objection';
import TenantModel from 'models/TenantModel';
export default class SaleReceipt extends TenantModel {
/**
* Table name
*/
static get tableName() {
return 'sales_receipts';
}
/**
* Timestamps columns.
*/
get timestamps() {
return ['created_at', 'updated_at'];
}
/**
* Virtual attributes.
*/
static get virtualAttributes() {
return [
'isClosed',
'isDraft',
];
}
/**
* Detarmine whether the sale receipt closed.
* @return {boolean}
*/
get isClosed() {
return !!this.closedAt;
}
/**
* Detarmines whether the sale receipt drafted.
* @return {boolean}
*/
get isDraft() {
return !this.closedAt;
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Contact = require('models/Contact');
const Account = require('models/Account');
const AccountTransaction = require('models/AccountTransaction');
const ItemEntry = require('models/ItemEntry');
return {
customer: {
relation: Model.BelongsToOneRelation,
modelClass: Contact.default,
join: {
from: 'sales_receipts.customerId',
to: 'contacts.id',
},
filter(query) {
query.where('contact_service', 'customer');
}
},
depositAccount: {
relation: Model.BelongsToOneRelation,
modelClass: Account.default,
join: {
from: 'sales_receipts.depositAccountId',
to: 'accounts.id',
},
},
entries: {
relation: Model.HasManyRelation,
modelClass: ItemEntry.default,
join: {
from: 'sales_receipts.id',
to: 'items_entries.referenceId',
},
filter(builder) {
builder.where('reference_type', 'SaleReceipt');
},
},
transactions: {
relation: Model.HasManyRelation,
modelClass: AccountTransaction.default,
join: {
from: 'sales_receipts.id',
to: 'accounts_transactions.referenceId'
},
filter(builder) {
builder.where('reference_type', 'SaleReceipt');
},
}
};
}
/**
* Model defined fields.
*/
static get fields() {
return {
created_at: {
label: 'Created at',
column: 'created_at',
columnType: 'date',
},
};
}
}