Compare commits
10 Commits
docker-com
...
filter-led
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bf008a9cb | ||
|
|
4d9e3ccfb4 | ||
|
|
1bfe19f26c | ||
|
|
a371cedb67 | ||
|
|
4ed9c36ebd | ||
|
|
e24b23ce7e | ||
|
|
19fe6e2423 | ||
|
|
aec09f178b | ||
|
|
ffe51bae07 | ||
|
|
68231d5edb |
32
.env.example
32
.env.example
@@ -8,26 +8,32 @@ MAIL_FROM_NAME=
|
||||
MAIL_FROM_ADDRESS=
|
||||
|
||||
# Database
|
||||
DB_USER=
|
||||
DB_HOST=
|
||||
DB_PASSWORD=
|
||||
DB_CHARSET=
|
||||
DB_HOST=mysql
|
||||
DB_USER=bigcapital
|
||||
DB_PASSWORD=bigcapital
|
||||
DB_ROOT_PASSWORD=root
|
||||
DB_CHARSET=utf8
|
||||
|
||||
# System database
|
||||
SYSTEM_DB_NAME=bigcapital_system
|
||||
# SYSTEM_DB_USER=
|
||||
# SYSTEM_DB_PASSWORD=
|
||||
# SYSTEM_DB_NAME=
|
||||
# SYSTEM_DB_CHARSET=
|
||||
|
||||
# Tenants databases
|
||||
# Tenant databases
|
||||
TENANT_DB_NAME_PERFIX=bigcapital_tenant_
|
||||
|
||||
# MongoDB
|
||||
MONGODB_DATABASE_URL=mongodb://localhost/bigcapital
|
||||
|
||||
# Authentication
|
||||
JWT_SECRET=b0JDZW56RnV6aEthb0RGPXVEcUI
|
||||
# TENANT_DB_HOST=
|
||||
# TENANT_DB_USER=
|
||||
# TENANT_DB_PASSWORD=
|
||||
# TENANT_DB_CHARSET=
|
||||
|
||||
# Application
|
||||
BASE_URL=https://bigcapital.ly
|
||||
CONTACT_US_MAIL=support@bigcapital.ly
|
||||
JWT_SECRET=b0JDZW56RnV6aEthb0RGPXVEcUI
|
||||
|
||||
# Jobs MongoDB
|
||||
MONGODB_DATABASE_URL=mongodb://localhost/bigcapital
|
||||
|
||||
# App proxy
|
||||
PUBLIC_PROXY_PORT=80
|
||||
@@ -40,4 +46,4 @@ AGENDASH_AUTH_PASSWORD=123123
|
||||
# Sign-up restrictions
|
||||
SIGNUP_DISABLED=true
|
||||
SIGNUP_ALLOWED_DOMAINS=
|
||||
SIGNUP_ALLOWED_EMAILS=
|
||||
SIGNUP_ALLOWED_EMAILS=
|
||||
|
||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
docker/nginx/scripts/build-nginx.sh text eol=lf
|
||||
docker/mariadb/docker-entrypoint.sh text eol=lf
|
||||
@@ -94,12 +94,12 @@ services:
|
||||
mysql:
|
||||
container_name: bigcapital-mysql
|
||||
build:
|
||||
context: ./docker/mysql
|
||||
context: ./docker/mariadb
|
||||
environment:
|
||||
- MYSQL_DATABASE=${SYSTEM_DB_NAME}
|
||||
- MYSQL_USER=${DB_USER}
|
||||
- MYSQL_PASSWORD=${DB_PASSWORD}
|
||||
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
|
||||
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
|
||||
volumes:
|
||||
- mysql:/var/lib/mysql
|
||||
expose:
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
version: '3.3'
|
||||
|
||||
services:
|
||||
mysql:
|
||||
mariadb:
|
||||
build:
|
||||
context: ./docker/mysql
|
||||
context: ./docker/mariadb
|
||||
environment:
|
||||
- MYSQL_DATABASE=${SYSTEM_DB_NAME}
|
||||
- MYSQL_USER=${DB_USER}
|
||||
- MYSQL_PASSWORD=${DB_PASSWORD}
|
||||
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
|
||||
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
|
||||
volumes:
|
||||
- mysql:/var/lib/mysql
|
||||
expose:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM mysql:5.7
|
||||
FROM mariadb:10.2
|
||||
|
||||
USER root
|
||||
ADD my.cnf /etc/mysql/conf.d/my.cnf
|
||||
@@ -17,7 +17,7 @@ ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
|
||||
COPY ./init.sql /scripts/init.template.sql
|
||||
COPY ./docker-entrypoint.sh /docker-entrypoint-initdb.d/docker-initialize.sh
|
||||
|
||||
# The scripts in the docker-entrypoint-initdb.d/ directory are executed as
|
||||
# The scripts in the `docker-entrypoint-initdb.d/` directory are executed as
|
||||
# the mysql user inside the MySQL Docker container.
|
||||
RUN chown -R mysql:root /docker-entrypoint-initdb.d
|
||||
RUN chown -R mysql:root /scripts
|
||||
@@ -1,2 +1,3 @@
|
||||
GRANT ALL PRIVILEGES ON *.* TO '{MYSQL_USER}'@'%' IDENTIFIED BY '{MYSQL_PASSWORD}' WITH GRANT OPTION;
|
||||
|
||||
FLUSH PRIVILEGES;
|
||||
@@ -65,6 +65,9 @@ exports.getCommonWebpackOptions = ({
|
||||
},
|
||||
],
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
};
|
||||
|
||||
if (isDev) {
|
||||
|
||||
@@ -4,6 +4,8 @@ export interface ILedger {
|
||||
|
||||
getEntries(): ILedgerEntry[];
|
||||
|
||||
filter(cb: (entry: ILedgerEntry) => boolean): ILedger;
|
||||
|
||||
whereAccountId(accountId: number): ILedger;
|
||||
whereContactId(contactId: number): ILedger;
|
||||
whereFromDate(fromDate: Date | string): ILedger;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import async from 'async';
|
||||
import { Knex } from 'knex';
|
||||
import { ILedger, ISaleContactsBalanceQueuePayload } from '@/interfaces';
|
||||
import {
|
||||
ILedger,
|
||||
ILedgerEntry,
|
||||
ISaleContactsBalanceQueuePayload,
|
||||
} from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TenantMetadata } from '@/system/models';
|
||||
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||
|
||||
@Service()
|
||||
export class LedgerContactsBalanceStorage {
|
||||
@@ -49,6 +54,29 @@ export class LedgerContactsBalanceStorage {
|
||||
await this.saveContactBalance(tenantId, ledger, contactId, trx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters AP/AR ledger entries.
|
||||
* @param {number} tenantId
|
||||
* @param {Knex.Transaction} trx
|
||||
* @returns {Promise<(entry: ILedgerEntry) => boolean>}
|
||||
*/
|
||||
private filterARAPLedgerEntris = async (
|
||||
tenantId: number,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<(entry: ILedgerEntry) => boolean> => {
|
||||
const { Account } = this.tenancy.models(tenantId);
|
||||
|
||||
const ARAPAcounts = await Account.query(trx).whereIn('accountType', [
|
||||
ACCOUNT_TYPE.ACCOUNTS_RECEIVABLE,
|
||||
ACCOUNT_TYPE.ACCOUNTS_PAYABLE,
|
||||
]);
|
||||
const ARAPAcountsIds = ARAPAcounts.map((a) => a.id);
|
||||
|
||||
return (entry: ILedgerEntry) => {
|
||||
return ARAPAcountsIds.indexOf(entry.accountId) !== -1;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
@@ -63,16 +91,24 @@ export class LedgerContactsBalanceStorage {
|
||||
trx?: Knex.Transaction
|
||||
): Promise<void> => {
|
||||
const { Contact } = this.tenancy.models(tenantId);
|
||||
const contact = await Contact.query().findById(contactId);
|
||||
const contact = await Contact.query(trx).findById(contactId);
|
||||
|
||||
// Retrieves the given tenant metadata.
|
||||
const tenantMeta = await TenantMetadata.query().findOne({ tenantId });
|
||||
|
||||
|
||||
// Detarmines whether the contact has foreign currency.
|
||||
const isForeignContact = contact.currencyCode !== tenantMeta.baseCurrency;
|
||||
|
||||
// Filters the ledger base on the given contact id.
|
||||
const contactLedger = ledger.whereContactId(contactId);
|
||||
const filterARAPLedgerEntris = await this.filterARAPLedgerEntris(
|
||||
tenantId,
|
||||
trx
|
||||
);
|
||||
const contactLedger = ledger
|
||||
// Filter entries only that have contact id.
|
||||
.whereContactId(contactId)
|
||||
// Filter entries on AR/AP accounts.
|
||||
.filter(filterARAPLedgerEntris);
|
||||
|
||||
const closingBalance = isForeignContact
|
||||
? contactLedger
|
||||
|
||||
@@ -55,7 +55,7 @@ export class CreateCustomer {
|
||||
} as ICustomerEventCreatingPayload);
|
||||
|
||||
// Creates a new contact as customer.
|
||||
const customer = await Contact.query().insertAndFetch({
|
||||
const customer = await Contact.query(trx).insertAndFetch({
|
||||
...customerObj,
|
||||
});
|
||||
// Triggers `onCustomerCreated` event.
|
||||
|
||||
Reference in New Issue
Block a user