mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: wip attach attachments to resource models
This commit is contained in:
@@ -403,6 +403,7 @@ export default class Bill extends mixin(TenantModel, [
|
||||
const BillLandedCost = require('models/BillLandedCost');
|
||||
const Branch = require('models/Branch');
|
||||
const TaxRateTransaction = require('models/TaxRateTransaction');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
vendor: {
|
||||
@@ -465,6 +466,25 @@ export default class Bill extends mixin(TenantModel, [
|
||||
builder.where('reference_type', 'Bill');
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Bill may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'bills.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'Bill');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ export default class BillPayment extends mixin(TenantModel, [
|
||||
const Vendor = require('models/Vendor');
|
||||
const Account = require('models/Account');
|
||||
const Branch = require('models/Branch');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
entries: {
|
||||
@@ -114,6 +115,25 @@ export default class BillPayment extends mixin(TenantModel, [
|
||||
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');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -174,6 +174,7 @@ export default class CreditNote extends mixin(TenantModel, [
|
||||
const ItemEntry = require('models/ItemEntry');
|
||||
const Customer = require('models/Customer');
|
||||
const Branch = require('models/Branch');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -233,6 +234,25 @@ export default class CreditNote extends mixin(TenantModel, [
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Credit note may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'credit_notes.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'CreditNote');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ export default class Expense extends mixin(TenantModel, [
|
||||
static get relationMappings() {
|
||||
const Account = require('models/Account');
|
||||
const ExpenseCategory = require('models/ExpenseCategory');
|
||||
const Media = require('models/Media');
|
||||
const Document = require('models/Document');
|
||||
const Branch = require('models/Branch');
|
||||
|
||||
return {
|
||||
@@ -217,21 +217,21 @@ export default class Expense extends mixin(TenantModel, [
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Expense transaction may has many attached attachments.
|
||||
*/
|
||||
media: {
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Media.default,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'expenses_transactions.id',
|
||||
through: {
|
||||
from: 'media_links.model_id',
|
||||
to: 'media_links.media_id',
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'media.id',
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_name', 'Expense');
|
||||
query.where('model_ref', 'Expense');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -94,9 +94,9 @@ export default class ManualJournal extends mixin(TenantModel, [
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Media = require('models/Media');
|
||||
const AccountTransaction = require('models/AccountTransaction');
|
||||
const ManualJournalEntry = require('models/ManualJournalEntry');
|
||||
const ManualJournal = require('models/ManualJournal');
|
||||
|
||||
return {
|
||||
entries: {
|
||||
@@ -121,19 +121,23 @@ export default class ManualJournal extends mixin(TenantModel, [
|
||||
query.where('referenceType', 'Journal');
|
||||
},
|
||||
},
|
||||
media: {
|
||||
|
||||
/**
|
||||
* Manual journal may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Media.default,
|
||||
modelClass: ManualJournal.default,
|
||||
join: {
|
||||
from: 'manual_journals.id',
|
||||
through: {
|
||||
from: 'media_links.model_id',
|
||||
to: 'media_links.media_id',
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'media.id',
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_name', 'ManualJournal');
|
||||
query.where('model_ref', 'ManualJournal');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -56,6 +56,7 @@ export default class PaymentReceive extends mixin(TenantModel, [
|
||||
const Customer = require('models/Customer');
|
||||
const Account = require('models/Account');
|
||||
const Branch = require('models/Branch');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
customer: {
|
||||
@@ -111,6 +112,25 @@ export default class PaymentReceive extends mixin(TenantModel, [
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Payment transaction may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'payment_receives.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'PaymentReceive');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,7 @@ export default class SaleEstimate extends mixin(TenantModel, [
|
||||
const ItemEntry = require('models/ItemEntry');
|
||||
const Customer = require('models/Customer');
|
||||
const Branch = require('models/Branch');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
customer: {
|
||||
@@ -219,6 +220,25 @@ export default class SaleEstimate extends mixin(TenantModel, [
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Sale estimate transaction may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'sales_estimates.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'Expense');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -410,7 +410,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
const Branch = require('models/Branch');
|
||||
const Account = require('models/Account');
|
||||
const TaxRateTransaction = require('models/TaxRateTransaction');
|
||||
const DocumentLink = require('models/DocumentLink');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -526,17 +526,21 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
},
|
||||
|
||||
/**
|
||||
* Invoice may has many attachments.
|
||||
* Sale invoice transaction may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: DocumentLink.default,
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'sales_invoices.id',
|
||||
to: 'document_links.modelId',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter: (builder) => {
|
||||
builder.where('modelRef', 'SaleInvoice');
|
||||
filter(query) {
|
||||
query.where('model_ref', 'Expense');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -108,6 +108,7 @@ export default class SaleReceipt extends mixin(TenantModel, [
|
||||
const AccountTransaction = require('models/AccountTransaction');
|
||||
const ItemEntry = require('models/ItemEntry');
|
||||
const Branch = require('models/Branch');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
customer: {
|
||||
@@ -167,6 +168,25 @@ export default class SaleReceipt extends mixin(TenantModel, [
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Sale receipt transaction may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'sales_receipts.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'SaleReceipt');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,7 @@ export default class VendorCredit extends mixin(TenantModel, [
|
||||
const Vendor = require('models/Vendor');
|
||||
const ItemEntry = require('models/ItemEntry');
|
||||
const Branch = require('models/Branch');
|
||||
const Document = require('models/Document');
|
||||
|
||||
return {
|
||||
vendor: {
|
||||
@@ -215,6 +216,25 @@ export default class VendorCredit extends mixin(TenantModel, [
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Vendor credit may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document.default,
|
||||
join: {
|
||||
from: 'vendor_credits.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'VendorCredit');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user