mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
import { Model } from 'objection';
|
|
import TenantModel from 'models/TenantModel';
|
|
|
|
export default class PaymentReceive extends TenantModel {
|
|
/**
|
|
* Table name
|
|
*/
|
|
static get tableName() {
|
|
return 'payment_receives';
|
|
}
|
|
|
|
/**
|
|
* Timestamps columns.
|
|
*/
|
|
get timestamps() {
|
|
return ['created_at', 'updated_at'];
|
|
}
|
|
|
|
/**
|
|
* Relationship mapping.
|
|
*/
|
|
static get relationMappings() {
|
|
const PaymentReceiveEntry = require('models/PaymentReceiveEntry');
|
|
const AccountTransaction = require('models/AccountTransaction');
|
|
const Contact = require('models/Contact');
|
|
const Account = require('models/Account');
|
|
|
|
return {
|
|
customer: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: Contact.default,
|
|
join: {
|
|
from: 'payment_receives.customerId',
|
|
to: 'contacts.id',
|
|
},
|
|
filter(query) {
|
|
query.where('contact_type', 'Customer');
|
|
}
|
|
},
|
|
|
|
depositAccount: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: Account.default,
|
|
join: {
|
|
from: 'payment_receives.depositAccountId',
|
|
to: 'accounts.id',
|
|
},
|
|
},
|
|
|
|
entries: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: PaymentReceiveEntry.default,
|
|
join: {
|
|
from: 'payment_receives.id',
|
|
to: 'payment_receives_entries.paymentReceiveId',
|
|
},
|
|
},
|
|
|
|
transactions: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: AccountTransaction.default,
|
|
join: {
|
|
from: 'payment_receives.id',
|
|
to: 'accounts_transactions.referenceId'
|
|
},
|
|
filter(builder) {
|
|
builder.where('reference_type', 'PaymentReceive');
|
|
},
|
|
}
|
|
};
|
|
}
|
|
}
|