mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
- feat: Sales estimates.
- feat: Sales invoices. - feat: Sales payment receives. - feat: Purchases bills. - feat: Purchases bills payments that made to the vendors.
This commit is contained in:
@@ -6,6 +6,13 @@ import CachableModel from '@/lib/Cachable/CachableModel';
|
||||
|
||||
|
||||
export default class Bill extends mixin(TenantModel, [CachableModel]) {
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return ['dueAmount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
@@ -21,9 +28,9 @@ export default class Bill extends mixin(TenantModel, [CachableModel]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend query builder model.
|
||||
* Due amount of the given.
|
||||
*/
|
||||
static get QueryBuilder() {
|
||||
return CachableQueryBuilder;
|
||||
get dueAmount() {
|
||||
return Math.max(this.balance - this.paymentAmount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mixin } from 'objection';
|
||||
import { Model, mixin } from 'objection';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
|
||||
import CachableModel from '@/lib/Cachable/CachableModel';
|
||||
@@ -25,4 +25,33 @@ export default class BillPayment extends mixin(TenantModel, [CachableModel]) {
|
||||
static get QueryBuilder() {
|
||||
return CachableQueryBuilder;
|
||||
}
|
||||
|
||||
static changePaymentAmount(billId, amount) {
|
||||
const changeMethod = amount > 0 ? 'increment' : 'decrement';
|
||||
return this.tenant()
|
||||
.query()
|
||||
.where('id', billId)
|
||||
[changeMethod]('payment_amount', Math.abs(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const BillPaymentEntry = require('@/models/BillPaymentEntry');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Account model may belongs to account type.
|
||||
*/
|
||||
entries: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: this.relationBindKnex(BillPaymentEntry.default),
|
||||
join: {
|
||||
from: 'bills_payments.id',
|
||||
to: 'bills_payments_entries.billPaymentId',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
18
server/src/models/BillPaymentEntry.js
Normal file
18
server/src/models/BillPaymentEntry.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { mixin } from 'objection';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
|
||||
export default class BillPaymentEntry extends TenantModel {
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'bills_payments_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,42 @@ export default class Customer extends TenantModel {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Change vendor balance.
|
||||
* @param {Integer} customerId
|
||||
* @param {Numeric} amount
|
||||
*/
|
||||
static async changeBalance(customerId, amount) {
|
||||
const changeMethod = amount > 0 ? 'increment' : 'decrement';
|
||||
|
||||
await this.tenant()
|
||||
.query()
|
||||
.where('id', customerId)
|
||||
[changeMethod]('balance', Math.abs(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the given customer balance.
|
||||
* @param {Integer} customerId
|
||||
* @param {Integer} amount
|
||||
*/
|
||||
static async incrementBalance(customerId, amount) {
|
||||
await this.tenant()
|
||||
.query()
|
||||
.where('id', customerId)
|
||||
.increment('balance', amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the given customer balance.
|
||||
* @param {integer} customerId -
|
||||
* @param {integer} amount -
|
||||
*/
|
||||
static async decrementBalance(customerId, amount) {
|
||||
await this.tenant()
|
||||
.query()
|
||||
.where('id', customerId)
|
||||
.decrement('balance', amount);
|
||||
}
|
||||
}
|
||||
|
||||
18
server/src/models/InventoryTransaction.js
Normal file
18
server/src/models/InventoryTransaction.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Model } from 'objection';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
|
||||
export default class InventoryTransaction extends TenantModel {
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'inventory_transactions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Model timestamps.
|
||||
*/
|
||||
static get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
}
|
||||
35
server/src/models/ItemEntry.js
Normal file
35
server/src/models/ItemEntry.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import path from 'path';
|
||||
import { Model } from 'objection';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
|
||||
export default class ItemEntry extends TenantModel {
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'items_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return ['created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
return {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
static calcAmount(itemEntry) {
|
||||
const { discount, quantity, rate } = itemEntry;
|
||||
const total = quantity * rate;
|
||||
|
||||
return discount ? total - (total * discount * 0.01) : total;
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,6 @@ export default class PaymentReceive extends mixin(TenantModel, [CachableModel])
|
||||
return ['created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend query builder model.
|
||||
*/
|
||||
static get QueryBuilder() {
|
||||
return CachableQueryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
@@ -38,7 +31,7 @@ export default class PaymentReceive extends mixin(TenantModel, [CachableModel])
|
||||
modelClass: this.relationBindKnex(PaymentReceiveEntry.default),
|
||||
join: {
|
||||
from: 'payment_receives.id',
|
||||
to: 'payment_receives_entries.payment_receive_id',
|
||||
to: 'payment_receives_entries.paymentReceiveId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Model, mixin } from 'objection';
|
||||
import moment from 'moment';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
|
||||
import CachableModel from '@/lib/Cachable/CachableModel';
|
||||
|
||||
|
||||
export default class SaleEstimate extends mixin(TenantModel, [CachableModel]) {
|
||||
/**
|
||||
* Table name
|
||||
@@ -20,26 +18,19 @@ export default class SaleEstimate extends mixin(TenantModel, [CachableModel]) {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend query builder model.
|
||||
*/
|
||||
static get QueryBuilder() {
|
||||
return CachableQueryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const SaleEstimateEntry = require('@/models/SaleEstimateEntry');
|
||||
const ItemEntry = require('@/models/ItemEntry');
|
||||
|
||||
return {
|
||||
entries: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: this.relationBindKnex(SaleEstimateEntry.default),
|
||||
modelClass: this.relationBindKnex(ItemEntry.default),
|
||||
join: {
|
||||
from: 'sales_estimates.id',
|
||||
to: 'sales_estimate_entries.id',
|
||||
to: 'items_entries.referenceId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,6 +5,13 @@ import CachableQueryBuilder from '@/lib/Cachable/CachableQueryBuilder';
|
||||
import CachableModel from '@/lib/Cachable/CachableModel';
|
||||
|
||||
export default class SaleInvoice extends mixin(TenantModel, [CachableModel]) {
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return ['dueAmount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
@@ -20,27 +27,41 @@ export default class SaleInvoice extends mixin(TenantModel, [CachableModel]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend query builder model.
|
||||
* Due amount of the given.
|
||||
*/
|
||||
static get QueryBuilder() {
|
||||
return CachableQueryBuilder;
|
||||
get dueAmount() {
|
||||
return Math.max(this.balance - this.paymentAmount, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const SaleInvoiceEntry = require('@/models/SaleInvoiceEntry');
|
||||
const ItemEntry = require('@/models/ItemEntry');
|
||||
|
||||
return {
|
||||
entries: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: this.relationBindKnex(SaleInvoiceEntry.default),
|
||||
modelClass: this.relationBindKnex(ItemEntry.default),
|
||||
join: {
|
||||
from: 'sales_invoices.id',
|
||||
to: 'sales_invoices_entries.sale_invoice_id',
|
||||
to: 'items_entries.referenceId',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Change payment amount.
|
||||
* @param {Integer} invoiceId
|
||||
* @param {Numeric} amount
|
||||
*/
|
||||
static async changePaymentAmount(invoiceId, amount) {
|
||||
const changeMethod = amount > 0 ? 'increment' : 'decrement';
|
||||
|
||||
await this.tenant()
|
||||
.query()
|
||||
.where('id', invoiceId)
|
||||
[changeMethod]('payment_amount', Math.abs(amount));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,26 +19,19 @@ export default class SaleReceipt extends mixin(TenantModel, [CachableModel]) {
|
||||
return ['created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend query builder model.
|
||||
*/
|
||||
static get QueryBuilder() {
|
||||
return CachableQueryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const SaleReceiptEntry = require('@/models/SaleReceiptEntry');
|
||||
const ItemEntry = require('@/models/ItemEntry');
|
||||
|
||||
return {
|
||||
entries: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: this.relationBindKnex(SaleReceiptEntry.default),
|
||||
modelClass: this.relationBindKnex(ItemEntry.default),
|
||||
join: {
|
||||
from: 'sales_receipts.id',
|
||||
to: 'sales_receipt_entries.sale_receipt_id',
|
||||
to: 'items_entries.referenceId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -15,4 +15,41 @@ export default class Vendor extends TenantModel {
|
||||
static get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the vendor balance.
|
||||
* @param {Integer} customerId
|
||||
* @param {Number} amount
|
||||
* @return {Promise}
|
||||
*/
|
||||
static async changeBalance(vendorId, amount) {
|
||||
const changeMethod = amount > 0 ? 'increment' : 'decrement';
|
||||
|
||||
return this.tenant()
|
||||
.query()
|
||||
.where('id', vendorId)
|
||||
[changeMethod]('balance', Math.abs(amount));
|
||||
}
|
||||
|
||||
static changeDiffBalance(vendorId, oldVendorId, amount, oldAmount) {
|
||||
const diffAmount = (amount - oldAmount) * -1;
|
||||
const asyncOpers = [];
|
||||
|
||||
if (vendorId != oldVendorId) {
|
||||
const oldVendorOper = Vendor.changeBalance(
|
||||
oldVendorId,
|
||||
oldAmount
|
||||
);
|
||||
const vendorOper = Vendor.changeBalance(
|
||||
vendorId,
|
||||
(amount + diffAmount) * -1
|
||||
);
|
||||
asyncOpers.push(vendorOper);
|
||||
asyncOpers.push(oldVendorOper);
|
||||
} else {
|
||||
const balanceChangeOper = Vendor.changeBalance(vendorId, diffAmount);
|
||||
asyncOpers.push(balanceChangeOper);
|
||||
}
|
||||
return Promise.all(asyncOpers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,12 @@ import PaymentReceive from './PaymentReceive';
|
||||
import PaymentReceiveEntry from './PaymentReceiveEntry';
|
||||
import Bill from './Bill';
|
||||
import BillPayment from './BillPayment';
|
||||
import BillPaymentEntry from './BillPaymentEntry';
|
||||
import Resource from './Resource';
|
||||
import View from './View';
|
||||
import ItemEntry from './ItemEntry';
|
||||
import InventoryTransaction from './InventoryTransaction';
|
||||
import AccountType from './AccountType';
|
||||
|
||||
export {
|
||||
Customer,
|
||||
@@ -32,6 +36,10 @@ export {
|
||||
PaymentReceiveEntry,
|
||||
Bill,
|
||||
BillPayment,
|
||||
BillPaymentEntry,
|
||||
Resource,
|
||||
View,
|
||||
ItemEntry,
|
||||
InventoryTransaction,
|
||||
AccountType,
|
||||
};
|
||||
Reference in New Issue
Block a user