mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
185
packages/server/src/modules/BillPayments/models/BillPayment.ts
Normal file
185
packages/server/src/modules/BillPayments/models/BillPayment.ts
Normal file
@@ -0,0 +1,185 @@
|
||||
import { Model, mixin } from 'objection';
|
||||
// import TenantModel from 'models/TenantModel';
|
||||
// import ModelSetting from './ModelSetting';
|
||||
// import BillPaymentSettings from './BillPayment.Settings';
|
||||
// import CustomViewBaseModel from './CustomViewBaseModel';
|
||||
// import { DEFAULT_VIEWS } from '@/services/Sales/PaymentReceived/constants';
|
||||
// import ModelSearchable from './ModelSearchable';
|
||||
import { BaseModel } from '@/models/Model';
|
||||
import { BillPaymentEntry } from './BillPaymentEntry';
|
||||
import { Vendor } from '@/modules/Vendors/models/Vendor';
|
||||
import { Document } from '@/modules/ChromiumlyTenancy/models/Document';
|
||||
|
||||
export class BillPayment extends BaseModel{
|
||||
vendorId: number;
|
||||
amount: number;
|
||||
currencyCode: string;
|
||||
paymentAccountId: number;
|
||||
paymentNumber: string;
|
||||
paymentDate: string;
|
||||
paymentMethod: string;
|
||||
reference: string;
|
||||
userId: number;
|
||||
statement: string;
|
||||
exchangeRate: number;
|
||||
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
|
||||
branchId?: number;
|
||||
|
||||
entries?: BillPaymentEntry[];
|
||||
vendor?: Vendor;
|
||||
attachments?: Document[];
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'bills_payments';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return ['localAmount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment amount in local currency.
|
||||
* @returns {number}
|
||||
*/
|
||||
get localAmount() {
|
||||
return this.amount * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model settings.
|
||||
*/
|
||||
// static get meta() {
|
||||
// return BillPaymentSettings;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
// static get relationMappings() {
|
||||
// const BillPaymentEntry = require('models/BillPaymentEntry');
|
||||
// const AccountTransaction = require('models/AccountTransaction');
|
||||
// const Vendor = require('models/Vendor');
|
||||
// const Account = require('models/Account');
|
||||
// const Branch = require('models/Branch');
|
||||
// const Document = require('models/Document');
|
||||
|
||||
// return {
|
||||
// entries: {
|
||||
// relation: Model.HasManyRelation,
|
||||
// modelClass: BillPaymentEntry.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.id',
|
||||
// to: 'bills_payments_entries.billPaymentId',
|
||||
// },
|
||||
// filter: (query) => {
|
||||
// query.orderBy('index', 'ASC');
|
||||
// },
|
||||
// },
|
||||
|
||||
// vendor: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: Vendor.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.vendorId',
|
||||
// to: 'contacts.id',
|
||||
// },
|
||||
// filter(query) {
|
||||
// query.where('contact_service', 'vendor');
|
||||
// },
|
||||
// },
|
||||
|
||||
// paymentAccount: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: Account.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.paymentAccountId',
|
||||
// to: 'accounts.id',
|
||||
// },
|
||||
// },
|
||||
|
||||
// transactions: {
|
||||
// relation: Model.HasManyRelation,
|
||||
// modelClass: AccountTransaction.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.id',
|
||||
// to: 'accounts_transactions.referenceId',
|
||||
// },
|
||||
// filter(builder) {
|
||||
// builder.where('reference_type', 'BillPayment');
|
||||
// },
|
||||
// },
|
||||
|
||||
// /**
|
||||
// * Bill payment may belongs to branch.
|
||||
// */
|
||||
// branch: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: Branch.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.branchId',
|
||||
// to: 'branches.id',
|
||||
// },
|
||||
// },
|
||||
|
||||
// /**
|
||||
// * Bill payment may has many attached attachments.
|
||||
// */
|
||||
// attachments: {
|
||||
// relation: Model.ManyToManyRelation,
|
||||
// modelClass: Document.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.id',
|
||||
// through: {
|
||||
// from: 'document_links.modelId',
|
||||
// to: 'document_links.documentId',
|
||||
// },
|
||||
// to: 'documents.id',
|
||||
// },
|
||||
// filter(query) {
|
||||
// query.where('model_ref', 'BillPayment');
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
|
||||
/**
|
||||
* Retrieve the default custom views, roles and columns.
|
||||
*/
|
||||
// static get defaultViews() {
|
||||
// return DEFAULT_VIEWS;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Model search attributes.
|
||||
*/
|
||||
static get searchRoles() {
|
||||
return [
|
||||
{ fieldKey: 'payment_number', comparator: 'contains' },
|
||||
{ condition: 'or', fieldKey: 'reference_no', comparator: 'contains' },
|
||||
{ condition: 'or', fieldKey: 'amount', comparator: 'equals' },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents mutate base currency since the model is not empty.
|
||||
*/
|
||||
static get preventMutateBaseCurrency() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Model } from 'objection';
|
||||
// import TenantModel from 'models/TenantModel';
|
||||
import { BaseModel } from '@/models/Model';
|
||||
import { Bill } from '@/modules/Bills/models/Bill';
|
||||
import { BillPayment } from './BillPayment';
|
||||
|
||||
export class BillPaymentEntry extends BaseModel {
|
||||
public billPaymentId: number;
|
||||
public billId: number;
|
||||
public paymentAmount: number;
|
||||
public index: number;
|
||||
|
||||
bill?: Bill;
|
||||
payment?: BillPayment;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'bills_payments_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const { Bill } = require('../../Bills/models/Bill');
|
||||
const { BillPayment } = require('../../BillPayments/models/BillPayment');
|
||||
|
||||
return {
|
||||
payment: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: BillPayment,
|
||||
join: {
|
||||
from: 'bills_payments_entries.billPaymentId',
|
||||
to: 'bills_payments.id',
|
||||
},
|
||||
},
|
||||
bill: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Bill,
|
||||
join: {
|
||||
from: 'bills_payments_entries.billId',
|
||||
to: 'bills.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user