feat: Link transations with payment methods

This commit is contained in:
Ahmed Bouhuolia
2024-09-15 19:42:43 +02:00
parent 542e61dbfc
commit 430cf19533
21 changed files with 581 additions and 8 deletions

View File

@@ -0,0 +1,27 @@
import { Model } from 'objection';
export class PaymentIntegration extends Model {
static get tableName() {
return 'payment_integrations';
}
static get idColumn() {
return 'id';
}
static get jsonSchema() {
return {
type: 'object',
required: ['service', 'enable'],
properties: {
id: { type: 'integer' },
service: { type: 'string' },
enable: { type: 'boolean' },
accountId: { type: 'string' },
options: { type: 'object' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
},
};
}
}

View File

@@ -413,6 +413,9 @@ export default class SaleInvoice extends mixin(TenantModel, [
const TaxRateTransaction = require('models/TaxRateTransaction');
const Document = require('models/Document');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
const {
TransactionPaymentService,
} = require('models/TransactionPaymentService');
return {
/**
@@ -509,7 +512,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
join: {
from: 'sales_invoices.warehouseId',
to: 'warehouses.id',
}
},
},
/**
@@ -566,12 +569,27 @@ export default class SaleInvoice extends mixin(TenantModel, [
modelClass: MatchedBankTransaction,
join: {
from: 'sales_invoices.id',
to: "matched_bank_transactions.referenceId",
to: 'matched_bank_transactions.referenceId',
},
filter(query) {
query.where('reference_type', 'SaleInvoice');
},
},
/**
* Sale invoice may belongs to payment methods.
*/
paymentMethods: {
relation: Model.HasManyRelation,
modelClass: TransactionPaymentService,
join: {
from: 'sales_invoices.id',
to: 'transactions_payment_services.referenceId',
},
filter: (query) => {
query.where('reference_type', 'SaleInvoice');
},
},
};
}

View File

@@ -0,0 +1,33 @@
import { Model, mixin } from 'objection';
import TenantModel from 'models/TenantModel';
export class TransactionPaymentService extends TenantModel {
/**
* Table name
*/
static get tableName() {
return 'transactions_payment_services';
}
static get jsonSchema() {
return {
type: 'object',
required: ['service', 'enable'],
properties: {
id: { type: 'integer' },
reference_id: { type: 'integer' },
reference_type: { type: 'string' },
service: { type: 'string' },
enable: { type: 'boolean' },
options: { type: 'object' },
},
};
}
/**
* Relationship mapping.
*/
static get relationMappings() {
return {};
}
}