- 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:
Ahmed Bouhuolia
2020-08-03 22:46:50 +02:00
parent 56278a25f0
commit db28cd2aef
56 changed files with 3290 additions and 1208 deletions

View File

@@ -0,0 +1,26 @@
import { Customer } from '@/models';
export default class CustomerRepository {
static changeDiffBalance(customerId, oldCustomerId, amount, oldAmount) {
const diffAmount = (amount - oldAmount) * -1;
const asyncOpers = [];
if (customerId != oldCustomerId) {
const oldCustomerOper = Customer.changeBalance(
oldCustomerId,
oldAmount
);
const customerOper = Customer.changeBalance(
customerId,
(amount + diffAmount) * -1
);
asyncOpers.push(customerOper);
asyncOpers.push(oldCustomerOper);
} else {
const balanceChangeOper = Customer.changeBalance(customerId, diffAmount);
asyncOpers.push(balanceChangeOper);
}
return Promise.all(asyncOpers);
}
}

View File

@@ -0,0 +1,55 @@
import { omit } from 'lodash';
import BaseModelRepository from '@/repositories/BaseModelRepository';
import { PaymentReceiveEntry } from '@/models';
export default class PaymentReceiveEntryRepository extends BaseModelRepository {
/**
* Insert payment receive entries in bulk.
* @param {Array} entries
* @param {Integr} paymentReceiveId
* @return {Promise}
*/
static insertBulk(entries, paymentReceiveId) {
const opers = [];
entries.forEach((entry) => {
const insertOper = PaymentReceiveEntry.tenant()
.query()
.insert({
payment_receive_id: paymentReceiveId,
...entry,
});
opers.push(insertOper);
});
return Promise.all(opers);
}
/**
* Update payment receive entries in bulk.
* @param {Array} entries
* @return {Promise}
*/
static updateBulk(entries) {
const opers = [];
entries.forEach((entry) => {
const updateOper = PaymentReceiveEntry.tenant()
.query()
.patchAndFetchById(entry.id, {
...omit(entry, ['id', 'index']),
});
opers.push(updateOper);
});
return Promise.all(opers);
}
/**
* Deletes the given payment receive entries ids in bulk.
* @param {Array} entriesIds
* @return {Promise}
*/
static deleteBulk(entriesIds) {
return PaymentReceiveEntry.tenant()
.query()
.whereIn('id', entriesIds)
.delete();
}
}

View File

@@ -0,0 +1,7 @@
import { omit } from 'lodash';
import { PaymentReceiveEntry } from '@/models';
import BaseModelRepository from '@/repositories/BaseModelRepository';
export default class PaymentReceiveRepository extends BaseModelRepository {
}