mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-10 01:41:59 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d9e3ccfb4 | ||
|
|
1bfe19f26c | ||
|
|
a371cedb67 | ||
|
|
4ed9c36ebd | ||
|
|
e24b23ce7e | ||
|
|
19fe6e2423 | ||
|
|
aec09f178b | ||
|
|
ffe51bae07 | ||
|
|
68231d5edb | ||
|
|
e1ea5c402c | ||
|
|
34b2c2c8b4 | ||
|
|
5d96fe6aa0 | ||
|
|
d2b5084b42 | ||
|
|
81fb0734d5 | ||
|
|
3639ce44e5 | ||
|
|
a7c00d60d5 | ||
|
|
932750b62d | ||
|
|
c90ffed67f | ||
|
|
e92c4486aa | ||
|
|
aaceea5338 | ||
|
|
4d54d180bc | ||
|
|
8fdd98e34d | ||
|
|
d53c5ee5e6 | ||
|
|
4082e4e2b8 | ||
|
|
0c689459cb | ||
|
|
40ef02f215 | ||
|
|
d369f0bb17 | ||
|
|
425d0293cc | ||
|
|
b621650975 | ||
|
|
40948160fe | ||
|
|
aa6b9dd295 | ||
|
|
05c2232b97 | ||
|
|
8f6325d529 | ||
|
|
0aa681043d | ||
|
|
40bddfdfeb | ||
|
|
d6e2f01d70 | ||
|
|
2344d3d34d |
36
.env.example
36
.env.example
@@ -8,26 +8,36 @@ 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
|
||||
PUBLIC_PROXY_SSL_PORT=443
|
||||
|
||||
# Agendash
|
||||
AGENDASH_AUTH_USER=agendash
|
||||
@@ -36,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
|
||||
18
CHANGELOG.md
18
CHANGELOG.md
@@ -2,6 +2,24 @@
|
||||
|
||||
All notable changes to Bigcapital server-side will be in this file.
|
||||
|
||||
## [0.9.1] - 28-05-2023
|
||||
|
||||
`@bigcapital/server`
|
||||
- fix: deleting ledger entries of manual journal.
|
||||
- fix: base currency should be enabled.
|
||||
- fix: delete invoice transaction issue.
|
||||
|
||||
`@bigcapital/webapp`
|
||||
- fix: general, accoutant and items preferences.
|
||||
- fix: auto-increment sale invoices, estiamtes, credit notes, payments and manual journals.
|
||||
- refactor: the setup organization form to use binded Formik components.
|
||||
|
||||
## [0.9.0] - 06-05-2023
|
||||
|
||||
`@bigcapital/server`
|
||||
|
||||
- [Sign-up restrictions](https://docs.bigcapital.ly/docs/deployment/signup_restriction) for self-hosting instances to disable signup or control the allowed email addresses and domains that can sign-up.
|
||||
|
||||
## [0.8.3] - 06-04-2023
|
||||
|
||||
`@bigcaptial/monorepo`
|
||||
|
||||
@@ -26,6 +26,6 @@ Bigcapital is a smart and open-source accounting and inventory software, Bigcapi
|
||||
- [Bug Tracker](https://github.com/bigcapitalhq/bigcapital/issues) - Notify us new bugs.
|
||||
- [Source Code](https://github.com/bigcapitalhq/bigcapital) - Github repo.
|
||||
|
||||
# Changlog
|
||||
# Changelog
|
||||
|
||||
Please see [Releases](https://github.com/bigcapitalhq/bigcapital/releases) for more information what has changed recently.
|
||||
|
||||
@@ -15,14 +15,14 @@ services:
|
||||
- ./data/logs/nginx/:/var/log/nginx
|
||||
- ./docker/certbot/certs/:/var/certs
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
- "${PUBLIC_PROXY_PORT:-80}:80"
|
||||
- "${PUBLIC_PROXY_SSL_PORT:-443}:443"
|
||||
tty: true
|
||||
depends_on:
|
||||
- server
|
||||
- webapp
|
||||
|
||||
webapp:
|
||||
webapp:
|
||||
container_name: bigcapital-webapp
|
||||
image: ghcr.io/bigcapitalhq/webapp:latest
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -41,7 +41,7 @@ export default class BalanceSheetStatementController extends BaseFinancialReport
|
||||
get balanceSheetValidationSchema(): ValidationChain[] {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
query('accounting_method').optional().isIn(['cash', 'accural']),
|
||||
query('accounting_method').optional().isIn(['cash', 'accrual']),
|
||||
|
||||
query('from_date').optional(),
|
||||
query('to_date').optional(),
|
||||
|
||||
@@ -58,7 +58,7 @@ export default class OrganizationController extends BaseController {
|
||||
private get organizationValidationSchema(): ValidationChain[] {
|
||||
return [
|
||||
check('name').exists().trim(),
|
||||
check('industry').optional().isString(),
|
||||
check('industry').optional({ nullable: true }).isString().trim().escape(),
|
||||
check('location').exists().isString().isISO31661Alpha2(),
|
||||
check('base_currency').exists().isISO4217(),
|
||||
check('timezone').exists().isIn(moment.tz.names()),
|
||||
|
||||
@@ -3,17 +3,17 @@ import AccountsData from '../data/accounts';
|
||||
|
||||
export default class SeedAccounts extends TenantSeeder {
|
||||
/**
|
||||
* Seeds initial accounts to the organization.
|
||||
* Seeds initial accounts to the organization.
|
||||
*/
|
||||
up(knex) {
|
||||
const data = AccountsData.map((account) => {
|
||||
return {
|
||||
...account,
|
||||
name: this.i18n.__(account.name),
|
||||
description: this.i18n.__(account.description),
|
||||
currencyCode: this.tenant.metadata.baseCurrency,
|
||||
};
|
||||
});
|
||||
const data = AccountsData.map((account) => ({
|
||||
...account,
|
||||
name: this.i18n.__(account.name),
|
||||
description: this.i18n.__(account.description),
|
||||
currencyCode: this.tenant.metadata.baseCurrency,
|
||||
seededAt: new Date(),
|
||||
})
|
||||
);
|
||||
return knex('accounts').then(async () => {
|
||||
// Inserts seed entries.
|
||||
return knex('accounts').insert(data);
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class SeedSettings extends TenantSeeder {
|
||||
up() {
|
||||
const settings = [
|
||||
// Orgnization settings.
|
||||
{ group: 'organization', key: 'accounting_basis', value: 'accural' },
|
||||
{ group: 'organization', key: 'accounting_basis', value: 'accrual' },
|
||||
|
||||
// Accounts settings.
|
||||
{ group: 'accounts', key: 'account_code_unique', value: true },
|
||||
|
||||
@@ -44,7 +44,7 @@ export interface IBalanceSheetQuery extends IFinancialSheetBranchesQuery {
|
||||
numberFormat: INumberFormatQuery;
|
||||
noneTransactions: boolean;
|
||||
noneZero: boolean;
|
||||
basis: 'cash' | 'accural';
|
||||
basis: 'cash' | 'accrual';
|
||||
accountIds: number[];
|
||||
|
||||
percentageOfColumn: boolean;
|
||||
|
||||
@@ -4,7 +4,7 @@ export interface ITrialBalanceSheetQuery {
|
||||
fromDate: Date | string;
|
||||
toDate: Date | string;
|
||||
numberFormat: INumberFormatQuery;
|
||||
basis: 'cash' | 'accural';
|
||||
basis: 'cash' | 'accrual';
|
||||
noneZero: boolean;
|
||||
noneTransactions: boolean;
|
||||
onlyActive: boolean;
|
||||
|
||||
@@ -10,7 +10,7 @@ export class LedgerRevert {
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
ledgerStorage: LedgerStorageService;
|
||||
private ledgerStorage: LedgerStorageService;
|
||||
|
||||
/**
|
||||
* Reverts the jouranl entries.
|
||||
|
||||
@@ -5,18 +5,13 @@ import {
|
||||
ICreditNoteDeletedPayload,
|
||||
ICreditNoteEditedPayload,
|
||||
ICreditNoteOpenedPayload,
|
||||
IRefundCreditNoteOpenedPayload,
|
||||
} from '@/interfaces';
|
||||
import CreditNoteGLEntries from './CreditNoteGLEntries';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export default class CreditNoteGLEntriesSubscriber {
|
||||
@Inject()
|
||||
creditNoteGLEntries: CreditNoteGLEntries;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private creditNoteGLEntries: CreditNoteGLEntries;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
|
||||
@@ -17,7 +17,7 @@ export const getDefaultPLQuery = (): IProfitLossSheetQuery => ({
|
||||
formatMoney: 'total',
|
||||
precision: 2,
|
||||
},
|
||||
basis: 'accural',
|
||||
basis: 'accrual',
|
||||
|
||||
noneZero: false,
|
||||
noneTransactions: false,
|
||||
|
||||
@@ -35,7 +35,7 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
formatMoney: 'total',
|
||||
precision: 2,
|
||||
},
|
||||
basis: 'accural',
|
||||
basis: 'accrual',
|
||||
noneZero: false,
|
||||
noneTransactions: true,
|
||||
onlyActive: false,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { difference, sumBy, omit, map } from 'lodash';
|
||||
import { difference } from 'lodash';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import {
|
||||
IManualJournalDTO,
|
||||
IManualJournalEntry,
|
||||
IManualJournal,
|
||||
IManualJournalEntryDTO,
|
||||
} from '@/interfaces';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ERRORS } from './constants';
|
||||
@@ -286,7 +285,7 @@ export class CommandManualJournalValidators {
|
||||
public validateJournalCurrencyWithAccountsCurrency = async (
|
||||
tenantId: number,
|
||||
manualJournalDTO: IManualJournalDTO,
|
||||
baseCurrency: string,
|
||||
baseCurrency: string
|
||||
) => {
|
||||
const { Account } = this.tenancy.models(tenantId);
|
||||
|
||||
|
||||
@@ -3,25 +3,20 @@ import * as R from 'ramda';
|
||||
import {
|
||||
IManualJournal,
|
||||
IManualJournalEntry,
|
||||
IAccount,
|
||||
ILedgerEntry,
|
||||
} from '@/interfaces';
|
||||
import { Knex } from 'knex';
|
||||
import Ledger from '@/services/Accounting/Ledger';
|
||||
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { LedgerRevert } from '@/services/Accounting/LedgerStorageRevert';
|
||||
|
||||
@Service()
|
||||
export class ManualJournalGLEntries {
|
||||
@Inject()
|
||||
ledgerStorage: LedgerStorageService;
|
||||
private ledgerStorage: LedgerStorageService;
|
||||
|
||||
@Inject()
|
||||
ledgerRevert: LedgerRevert;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Create manual journal GL entries.
|
||||
@@ -77,7 +72,7 @@ export class ManualJournalGLEntries {
|
||||
manualJournalId: number,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<void> => {
|
||||
return this.ledgerRevert.revertGLEntries(
|
||||
return this.ledgerStorage.deleteByReference(
|
||||
tenantId,
|
||||
manualJournalId,
|
||||
'Journal',
|
||||
@@ -86,7 +81,7 @@ export class ManualJournalGLEntries {
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrieves the ledger of the given manual journal.
|
||||
* @param {IManualJournal} manualJournal
|
||||
* @returns {Ledger}
|
||||
*/
|
||||
@@ -97,11 +92,13 @@ export class ManualJournalGLEntries {
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrieves the common entry details of the manual journal
|
||||
* @param {IManualJournal} manualJournal
|
||||
* @returns {}
|
||||
* @returns {Partial<ILedgerEntry>}
|
||||
*/
|
||||
private getManualJournalCommonEntry = (manualJournal: IManualJournal) => {
|
||||
private getManualJournalCommonEntry = (
|
||||
manualJournal: IManualJournal
|
||||
): Partial<ILedgerEntry> => {
|
||||
return {
|
||||
transactionNumber: manualJournal.journalNumber,
|
||||
referenceNumber: manualJournal.reference,
|
||||
@@ -118,7 +115,8 @@ export class ManualJournalGLEntries {
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrieves the ledger entry of the given manual journal and
|
||||
* its associated entry.
|
||||
* @param {IManualJournal} manualJournal -
|
||||
* @param {IManualJournalEntry} entry -
|
||||
* @returns {ILedgerEntry}
|
||||
@@ -149,7 +147,7 @@ export class ManualJournalGLEntries {
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrieves the ledger of the given manual journal.
|
||||
* @param {IManualJournal} manualJournal
|
||||
* @returns {ILedgerEntry[]}
|
||||
*/
|
||||
|
||||
@@ -23,8 +23,11 @@ export class ProjectBillableBillSubscriber {
|
||||
events.saleInvoice.onCreated,
|
||||
this.handleIncreaseBillableBill
|
||||
);
|
||||
bus.subscribe(events.saleInvoice.onEdited, this.handleDecreaseBillableBill);
|
||||
bus.subscribe(events.saleInvoice.onDeleted, this.handleEditBillableBill);
|
||||
bus.subscribe(events.saleInvoice.onEdited, this.handleEditBillableBill);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onDeleted,
|
||||
this.handleDecreaseBillableBill
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import async from 'async';
|
||||
import { ISaleInvoice, ISaleInvoiceDTO, ProjectLinkRefType } from '@/interfaces';
|
||||
import {
|
||||
ISaleInvoice,
|
||||
ISaleInvoiceDTO,
|
||||
ProjectLinkRefType,
|
||||
} from '@/interfaces';
|
||||
import { ProjectBillableExpense } from './ProjectBillableExpense';
|
||||
import { filterEntriesByRefType } from './_utils';
|
||||
|
||||
|
||||
@@ -21,13 +21,10 @@ export class ProjectBillableExpensesSubscriber {
|
||||
events.saleInvoice.onCreated,
|
||||
this.handleIncreaseBillableExpenses
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onEdited,
|
||||
this.handleDecreaseBillableExpenses
|
||||
);
|
||||
bus.subscribe(events.saleInvoice.onEdited, this.handleEditBillableExpenses);
|
||||
bus.subscribe(
|
||||
events.saleInvoice.onDeleted,
|
||||
this.handleEditBillableExpenses
|
||||
this.handleDecreaseBillableExpenses
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ USER root
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY package.json ./
|
||||
COPY package*.json ./
|
||||
COPY lerna.json ./
|
||||
|
||||
COPY ./packages/webapp/package.json /app/packages/webapp/package.json
|
||||
COPY ./packages/webapp/package*.json /app/packages/webapp/
|
||||
|
||||
RUN npm install
|
||||
RUN npm run bootstrap
|
||||
|
||||
11
packages/webapp/package-lock.json
generated
11
packages/webapp/package-lock.json
generated
@@ -1205,9 +1205,9 @@
|
||||
}
|
||||
},
|
||||
"@blueprintjs-formik/core": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@blueprintjs-formik/core/-/core-0.2.1.tgz",
|
||||
"integrity": "sha512-YGJe+QorDGbkWDSUg6x69LYGN62Kgvb92Iz/voqmszVRKj4KcoPvd/7coF8Jmu+ZQE6LcwM/9ccB2i63L99ITA==",
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@blueprintjs-formik/core/-/core-0.3.3.tgz",
|
||||
"integrity": "sha512-ko7g54YSEcSq2K/GEpmiTG0foGLqe7DwgXGhkGxYEiHhLAUv8WvQmrFsm8e/KOW7n8mLGq0uaZVe2l8m3JTGGQ==",
|
||||
"requires": {
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.keyby": "^4.6.0",
|
||||
@@ -7298,6 +7298,11 @@
|
||||
"locate-path": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"flat": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz",
|
||||
"integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ=="
|
||||
},
|
||||
"flat-cache": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "1.7.1",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@blueprintjs-formik/core": "^0.2.1",
|
||||
"@blueprintjs-formik/core": "^0.3.3",
|
||||
"@blueprintjs-formik/datetime": "^0.3.4",
|
||||
"@blueprintjs-formik/select": "^0.2.3",
|
||||
"@blueprintjs/core": "^3.50.2",
|
||||
@@ -16,8 +16,6 @@
|
||||
"@casl/react": "^2.3.0",
|
||||
"@craco/craco": "^5.9.0",
|
||||
"@reduxjs/toolkit": "^1.2.5",
|
||||
"@sentry/react": "^6.13.2",
|
||||
"@sentry/tracing": "^6.13.2",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.4.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
@@ -45,6 +43,7 @@
|
||||
"deepdash": "^5.3.9",
|
||||
"dependency-graph": "^0.11.0",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"flat": "^5.0.2",
|
||||
"formik": "^2.2.5",
|
||||
"http-proxy-middleware": "^1.0.0",
|
||||
"jest": "24.9.0",
|
||||
|
||||
@@ -20,24 +20,6 @@
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
|
||||
<% if (process.env.NODE_ENV === 'production') { %>
|
||||
<!-- Hotjar Tracking Code for https://app.bigcapital.ly/ -->
|
||||
<script>
|
||||
(function (h, o, t, j, a, r) {
|
||||
h.hj =
|
||||
h.hj ||
|
||||
function () {
|
||||
(h.hj.q = h.hj.q || []).push(arguments);
|
||||
};
|
||||
h._hjSettings = { hjid: 2774528, hjsv: 6 };
|
||||
a = o.getElementsByTagName('head')[0];
|
||||
r = o.createElement('script');
|
||||
r.async = 1;
|
||||
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
|
||||
a.appendChild(r);
|
||||
})(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
|
||||
</script>
|
||||
<% } %>
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
@@ -69,7 +51,5 @@
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css"
|
||||
type="text/css"
|
||||
/>
|
||||
<!-- <link href="https://cdn.syncfusion.com/ej2/material.css" rel="stylesheet"> -->
|
||||
<!-- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> -->
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -17,8 +17,8 @@ import AllocateLandedCostDialog from '@/containers/Dialogs/AllocateLandedCostDia
|
||||
import InvoicePdfPreviewDialog from '@/containers/Dialogs/InvoicePdfPreviewDialog';
|
||||
import EstimatePdfPreviewDialog from '@/containers/Dialogs/EstimatePdfPreviewDialog';
|
||||
import ReceiptPdfPreviewDialog from '@/containers/Dialogs/ReceiptPdfPreviewDialog';
|
||||
import MoneyInDialog from '@/containers/Dialogs/MoneyInDialog';
|
||||
import MoneyOutDialog from '@/containers/Dialogs/MoneyOutDialog';
|
||||
import MoneyInDialog from '@/containers/CashFlow/MoneyInDialog';
|
||||
import MoneyOutDialog from '@/containers/CashFlow/MoneyOutDialog';
|
||||
import BadDebtDialog from '@/containers/Dialogs/BadDebtDialog';
|
||||
import NotifyInvoiceViaSMSDialog from '@/containers/Dialogs/NotifyInvoiceViaSMSDialog';
|
||||
import NotifyReceiptViaSMSDialog from '@/containers/Dialogs/NotifyReceiptViaSMSDialog';
|
||||
|
||||
@@ -46,7 +46,7 @@ const SelectButton = styled(Button)`
|
||||
margin-right: 12px;
|
||||
border-radius: 1px;
|
||||
}
|
||||
&:not([class*='bp3-intent-']) {
|
||||
&:not([class*='bp3-intent-']):not(.bp3-disabled) {
|
||||
&,
|
||||
&:hover {
|
||||
background: #fff;
|
||||
|
||||
@@ -46,4 +46,5 @@ export enum DialogsName {
|
||||
EstimateExpenseForm = 'estimate-expense-form',
|
||||
ProjectInvoicingForm = 'project-invoicing-form',
|
||||
ProjectBillableEntriesForm = 'project-billable-entries',
|
||||
InvoiceNumberSettings = 'InvoiceNumberSettings'
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Formik, Form } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import intl from 'react-intl-universal';
|
||||
import * as R from 'ramda';
|
||||
import { defaultTo, isEmpty, omit } from 'lodash';
|
||||
import { isEmpty, omit } from 'lodash';
|
||||
import classNames from 'classnames';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
transformToEditForm,
|
||||
defaultManualJournal,
|
||||
} from './utils';
|
||||
import { JournalSyncIncrementSettingsToForm } from './components';
|
||||
|
||||
/**
|
||||
* Journal entries form.
|
||||
@@ -40,6 +41,7 @@ function MakeJournalEntriesForm({
|
||||
journalNextNumber,
|
||||
journalNumberPrefix,
|
||||
journalAutoIncrement,
|
||||
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
}) {
|
||||
@@ -69,6 +71,8 @@ function MakeJournalEntriesForm({
|
||||
}
|
||||
: {
|
||||
...defaultManualJournal,
|
||||
// If the auto-increment mode is enabled, take the next journal
|
||||
// number from the settings.
|
||||
...(journalAutoIncrement && {
|
||||
journal_number: journalNumber,
|
||||
}),
|
||||
@@ -116,7 +120,6 @@ function MakeJournalEntriesForm({
|
||||
entries: R.compose(orderingLinesIndexes)(entries),
|
||||
publish: submitPayload.publish,
|
||||
};
|
||||
|
||||
// Handle the request error.
|
||||
const handleError = ({
|
||||
response: {
|
||||
@@ -126,7 +129,6 @@ function MakeJournalEntriesForm({
|
||||
transformErrors(errors, { setErrors });
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
// Handle the request success.
|
||||
const handleSuccess = (errors) => {
|
||||
AppToaster.show({
|
||||
@@ -147,7 +149,6 @@ function MakeJournalEntriesForm({
|
||||
resetForm();
|
||||
}
|
||||
};
|
||||
|
||||
if (isNewMode) {
|
||||
createJournalMutate(form).then(handleSuccess).catch(handleError);
|
||||
} else {
|
||||
@@ -179,6 +180,9 @@ function MakeJournalEntriesForm({
|
||||
|
||||
{/* --------- Dialogs --------- */}
|
||||
<MakeJournalFormDialogs />
|
||||
|
||||
{/* --------- Effects --------- */}
|
||||
<JournalSyncIncrementSettingsToForm />
|
||||
</Form>
|
||||
</Formik>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,19 @@ import { PageFormBigNumber, FormattedMessage as T } from '@/components';
|
||||
import MakeJournalEntriesHeaderFields from './MakeJournalEntriesHeaderFields';
|
||||
|
||||
export default function MakeJournalEntriesHeader() {
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<MakeJournalEntriesHeaderFields />
|
||||
<MakeJournalHeaderBigNumber />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Big total number of make journal header.
|
||||
* @returns {React.ReactNode}
|
||||
*/
|
||||
function MakeJournalHeaderBigNumber() {
|
||||
const {
|
||||
values: { entries, currency_code },
|
||||
} = useFormikContext();
|
||||
@@ -17,14 +30,10 @@ export default function MakeJournalEntriesHeader() {
|
||||
const total = Math.max(totalCredit, totalDebit);
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<MakeJournalEntriesHeaderFields />
|
||||
|
||||
<PageFormBigNumber
|
||||
label={<T id={'amount'} />}
|
||||
amount={total}
|
||||
currencyCode={currency_code}
|
||||
/>
|
||||
</div>
|
||||
<PageFormBigNumber
|
||||
label={<T id={'amount'} />}
|
||||
amount={total}
|
||||
currencyCode={currency_code}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ import {
|
||||
Position,
|
||||
ControlGroup,
|
||||
} from '@blueprintjs/core';
|
||||
import { FastField, ErrorMessage } from 'formik';
|
||||
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import * as R from 'ramda';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import {
|
||||
momentFormatter,
|
||||
compose,
|
||||
inputIntent,
|
||||
handleDateChange,
|
||||
tansformDateValue,
|
||||
@@ -25,54 +25,101 @@ import {
|
||||
Icon,
|
||||
InputPrependButton,
|
||||
CurrencySelectList,
|
||||
FormattedMessage as T
|
||||
FormattedMessage as T,
|
||||
FInputGroup,
|
||||
FFormGroup,
|
||||
} from '@/components';
|
||||
import { useMakeJournalFormContext } from './MakeJournalProvider';
|
||||
import { JournalExchangeRateInputField } from './components';
|
||||
import { currenciesFieldShouldUpdate } from './utils';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import {
|
||||
currenciesFieldShouldUpdate,
|
||||
useObserveJournalNoSettings,
|
||||
} from './utils';
|
||||
|
||||
/**
|
||||
* Journal number field of make journal form.
|
||||
*/
|
||||
const MakeJournalTransactionNoField = R.compose(
|
||||
withDialogActions,
|
||||
withSettings(({ manualJournalsSettings }) => ({
|
||||
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
|
||||
})),
|
||||
)(
|
||||
({
|
||||
// #withDialog
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
journalAutoIncrement,
|
||||
}) => {
|
||||
const { setFieldValue, values } = useFormikContext();
|
||||
|
||||
const handleJournalNumberChange = () => {
|
||||
openDialog('journal-number-form');
|
||||
};
|
||||
const handleJournalNoBlur = (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (values.journal_number !== newValue && journalAutoIncrement) {
|
||||
openDialog('journal-number-form', {
|
||||
initialFormValues: {
|
||||
onceManualNumber: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
if (!journalAutoIncrement) {
|
||||
setFieldValue('journal_number', newValue);
|
||||
setFieldValue('journal_number_manually', newValue);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<FFormGroup
|
||||
name={'journal_number'}
|
||||
label={<T id={'journal_no'} />}
|
||||
labelInfo={
|
||||
<>
|
||||
<FieldRequiredHint />
|
||||
<FieldHint />
|
||||
</>
|
||||
}
|
||||
fill={true}
|
||||
inline={true}
|
||||
fastField={true}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<FInputGroup
|
||||
name={'journal_number'}
|
||||
fill={true}
|
||||
asyncControl={true}
|
||||
onBlur={handleJournalNoBlur}
|
||||
fastField={true}
|
||||
onChange={() => {}}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleJournalNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: <T id={'setting_your_auto_generated_journal_number'} />,
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FFormGroup>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Make journal entries header.
|
||||
*/
|
||||
function MakeJournalEntriesHeader({
|
||||
// #ownProps
|
||||
onJournalNumberChanged,
|
||||
|
||||
// #withDialog
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
journalAutoIncrement,
|
||||
journalNextNumber,
|
||||
journalNumberPrefix,
|
||||
}) {
|
||||
export default function MakeJournalEntriesHeader({}) {
|
||||
const { currencies } = useMakeJournalFormContext();
|
||||
|
||||
// Handle journal number change.
|
||||
const handleJournalNumberChange = () => {
|
||||
openDialog('journal-number-form');
|
||||
};
|
||||
|
||||
// Handle journal number blur.
|
||||
const handleJournalNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && journalAutoIncrement) {
|
||||
openDialog('journal-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
useObserveJournalNoSettings(journalNumberPrefix, journalNextNumber);
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||
{/*------------ Posting date -----------*/}
|
||||
@@ -106,46 +153,7 @@ function MakeJournalEntriesHeader({
|
||||
</FastField>
|
||||
|
||||
{/*------------ Journal number -----------*/}
|
||||
<FastField name={'journal_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'journal_no'} />}
|
||||
labelInfo={
|
||||
<>
|
||||
<FieldRequiredHint />
|
||||
<FieldHint />
|
||||
</>
|
||||
}
|
||||
className={'form-group--journal-number'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="journal_number" />}
|
||||
fill={true}
|
||||
inline={true}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
fill={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleJournalNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleJournalNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T id={'setting_your_auto_generated_journal_number'} />
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<MakeJournalTransactionNoField />
|
||||
|
||||
{/*------------ Reference -----------*/}
|
||||
<FastField name={'reference'}>
|
||||
@@ -219,12 +227,3 @@ function MakeJournalEntriesHeader({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ manualJournalsSettings }) => ({
|
||||
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
|
||||
journalNextNumber: manualJournalsSettings?.nextNumber,
|
||||
journalNumberPrefix: manualJournalsSettings?.numberPrefix,
|
||||
})),
|
||||
)(MakeJournalEntriesHeader);
|
||||
|
||||
@@ -10,17 +10,21 @@ export default function MakeJournalFormDialogs() {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Update the form once the journal number form submit confirm.
|
||||
const handleConfirm = ({ manually, incrementNumber }) => {
|
||||
setFieldValue('journal_number', incrementNumber || '');
|
||||
setFieldValue('journal_number_manually', manually);
|
||||
const handleConfirm = (settings) => {
|
||||
// Set the invoice transaction no. that cames from dialog to the form.
|
||||
// the `journal_number` will be empty except the increment mode is not auto.
|
||||
setFieldValue('journal_number', settings.transactionNumber);
|
||||
setFieldValue('journal_number_manually', '');
|
||||
|
||||
if (settings.incrementMode !== 'auto') {
|
||||
setFieldValue('journal_number_manually', settings.transactionNumber);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<JournalNumberDialog
|
||||
dialogName={'journal-number-form'}
|
||||
onConfirm={handleConfirm}
|
||||
/>
|
||||
</>
|
||||
<JournalNumberDialog
|
||||
dialogName={'journal-number-form'}
|
||||
onConfirm={handleConfirm}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Menu, MenuItem, Position, Button } from '@blueprintjs/core';
|
||||
import { Popover2 } from '@blueprintjs/popover2';
|
||||
import { useFormikContext } from 'formik';
|
||||
import * as R from 'ramda';
|
||||
|
||||
import {
|
||||
ExchangeRateInputGroup,
|
||||
@@ -24,6 +25,9 @@ import { CellType, Features, Align } from '@/constants';
|
||||
|
||||
import { useCurrentOrganization, useFeatureCan } from '@/hooks/state';
|
||||
import { useJournalIsForeign } from './utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import { transactionNumber } from '@/utils';
|
||||
import { useUpdateEffect } from '@/hooks';
|
||||
|
||||
/**
|
||||
* Contact header cell.
|
||||
@@ -199,3 +203,37 @@ export function JournalExchangeRateInputField({ ...props }) {
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs journal auto-increment settings to form.
|
||||
* @return {React.ReactNode}
|
||||
*/
|
||||
export const JournalSyncIncrementSettingsToForm = R.compose(
|
||||
withSettings(({ manualJournalsSettings }) => ({
|
||||
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
|
||||
journalNextNumber: manualJournalsSettings?.nextNumber,
|
||||
journalNumberPrefix: manualJournalsSettings?.numberPrefix,
|
||||
})),
|
||||
)(({ journalAutoIncrement, journalNextNumber, journalNumberPrefix }) => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
useUpdateEffect(() => {
|
||||
// Do not update if the journal auto-increment mode is disabled.
|
||||
if (!journalAutoIncrement) return null;
|
||||
|
||||
setFieldValue(
|
||||
'journal_number',
|
||||
transactionNumber(journalNumberPrefix, journalNextNumber),
|
||||
);
|
||||
}, [
|
||||
setFieldValue,
|
||||
journalNumberPrefix,
|
||||
journalNextNumber,
|
||||
journalAutoIncrement,
|
||||
]);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
JournalSyncIncrementSettingsToForm.displayName =
|
||||
'JournalSyncIncrementSettingsToForm';
|
||||
|
||||
@@ -6,7 +6,6 @@ import intl from 'react-intl-universal';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { sumBy, setWith, toSafeInteger, get, first } from 'lodash';
|
||||
import {
|
||||
transactionNumber,
|
||||
updateTableCell,
|
||||
repeatValue,
|
||||
transformToForm,
|
||||
@@ -46,7 +45,7 @@ export const defaultEntry = {
|
||||
|
||||
export const defaultManualJournal = {
|
||||
journal_number: '',
|
||||
journal_number_manually: false,
|
||||
journal_number_manually: '',
|
||||
journal_type: 'Journal',
|
||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
description: '',
|
||||
@@ -174,15 +173,6 @@ export const transformErrors = (resErrors, { setErrors, errors }) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const useObserveJournalNoSettings = (prefix, nextNumber) => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
React.useEffect(() => {
|
||||
const journalNo = transactionNumber(prefix, nextNumber);
|
||||
setFieldValue('journal_number', journalNo);
|
||||
}, [setFieldValue, prefix, nextNumber]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detarmines entries fast field should update.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import OwnerContributionFormFields from './OwnerContribution/OwnerContributionFormFields';
|
||||
import OtherIncomeFormFields from './OtherIncome/OtherIncomeFormFields';
|
||||
import TransferFromAccountFormFields from './TransferFromAccount/TransferFromAccountFormFields';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export default function MoneyInContentFields({ accountType }) {
|
||||
const handleTransactionType = () => {
|
||||
switch (accountType) {
|
||||
@@ -19,6 +25,5 @@ export default function MoneyInContentFields({ accountType }) {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return <React.Fragment>{handleTransactionType()}</React.Fragment>;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { Form } from 'formik';
|
||||
import MoneyInFormFields from './MoneyInFormFields';
|
||||
import MoneyInFormDialog from './MoneyInFormDialog';
|
||||
import MoneyInFloatingActions from './MoneyInFloatingActions';
|
||||
import { MoneyInOutSyncIncrementSettingsToForm } from '../_components';
|
||||
|
||||
/**
|
||||
* Money In form content.
|
||||
@@ -15,6 +16,7 @@ export default function MoneyInFormContent() {
|
||||
<MoneyInFormFields />
|
||||
<MoneyInFormDialog />
|
||||
<MoneyInFloatingActions />
|
||||
<MoneyInOutSyncIncrementSettingsToForm />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -11,12 +11,9 @@ export default function MoneyInFormDialog() {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Update the form once the transaction number form submit confirm.
|
||||
const handleTransactionNumberFormConfirm = ({
|
||||
incrementNumber,
|
||||
manually,
|
||||
}) => {
|
||||
setFieldValue('transaction_number', incrementNumber || '');
|
||||
setFieldValue('transaction_number_manually', manually);
|
||||
const handleTransactionNumberFormConfirm = (settings) => {
|
||||
setFieldValue('transaction_number', settings.transactionNumber);
|
||||
setFieldValue('transaction_number_manually', settings.transactionNumber);
|
||||
};
|
||||
return (
|
||||
<React.Fragment>
|
||||
@@ -16,14 +16,12 @@ import {
|
||||
InputPrependText,
|
||||
MoneyInputGroup,
|
||||
FieldRequiredHint,
|
||||
Icon,
|
||||
Col,
|
||||
Row,
|
||||
If,
|
||||
FeatureCan,
|
||||
BranchSelect,
|
||||
BranchSelectButton,
|
||||
InputPrependButton,
|
||||
ExchangeRateMutedField,
|
||||
} from '@/components';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
@@ -35,65 +33,26 @@ import {
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
compose,
|
||||
} from '@/utils';
|
||||
|
||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||
import {
|
||||
useObserveTransactionNoSettings,
|
||||
useSetPrimaryBranchToForm,
|
||||
useForeignAccount,
|
||||
BranchRowDivider,
|
||||
} from '../utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||
|
||||
/**
|
||||
* Other income form fields.
|
||||
*/
|
||||
function OtherIncomeFormFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
}) {
|
||||
export default function OtherIncomeFormFields() {
|
||||
// Money in dialog context.
|
||||
const { accounts, account, branches } = useMoneyInDailogContext();
|
||||
|
||||
const { values } = useFormikContext();
|
||||
|
||||
const amountFieldRef = useAutofocus();
|
||||
|
||||
const isForeigAccount = useForeignAccount();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Syncs transaction number settings with form.
|
||||
useObserveTransactionNoSettings(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
@@ -149,42 +108,7 @@ function OtherIncomeFormFields({
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/*------------ Transaction number -----------*/}
|
||||
<Field name={'transaction_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'transaction_number'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="transaction_number" />}
|
||||
className={'form-group--transaction_number'}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<MoneyInOutTransactionNoField />
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ amount -----------*/}
|
||||
@@ -298,12 +222,3 @@ function OtherIncomeFormFields({
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(OtherIncomeFormFields);
|
||||
@@ -17,11 +17,9 @@ import {
|
||||
InputPrependText,
|
||||
MoneyInputGroup,
|
||||
FieldRequiredHint,
|
||||
Icon,
|
||||
Col,
|
||||
Row,
|
||||
If,
|
||||
InputPrependButton,
|
||||
ExchangeRateMutedField,
|
||||
BranchSelect,
|
||||
BranchSelectButton,
|
||||
@@ -35,31 +33,20 @@ import {
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
compose,
|
||||
} from '@/utils';
|
||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||
import {
|
||||
useObserveTransactionNoSettings,
|
||||
useSetPrimaryBranchToForm,
|
||||
useForeignAccount,
|
||||
BranchRowDivider,
|
||||
} from '../../MoneyInDialog/utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||
|
||||
/**
|
||||
/**
|
||||
* Owner contribution form fields.
|
||||
*/
|
||||
function OwnerContributionFormFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
}) {
|
||||
export default function OwnerContributionFormFields() {
|
||||
// Money in dialog context.
|
||||
const { accounts, account, branches } = useMoneyInDailogContext();
|
||||
|
||||
@@ -69,31 +56,6 @@ function OwnerContributionFormFields({
|
||||
|
||||
const isForeigAccount = useForeignAccount();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Syncs transaction number settings with form.
|
||||
useObserveTransactionNoSettings(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
@@ -148,42 +110,7 @@ function OwnerContributionFormFields({
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/*------------ Transaction number -----------*/}
|
||||
<Field name={'transaction_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'transaction_number'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="transaction_number" />}
|
||||
className={'form-group--transaction_number'}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<MoneyInOutTransactionNoField />
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ amount -----------*/}
|
||||
@@ -294,12 +221,3 @@ function OwnerContributionFormFields({
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(OwnerContributionFormFields);
|
||||
@@ -17,11 +17,9 @@ import {
|
||||
InputPrependText,
|
||||
MoneyInputGroup,
|
||||
FieldRequiredHint,
|
||||
Icon,
|
||||
Col,
|
||||
Row,
|
||||
If,
|
||||
InputPrependButton,
|
||||
ExchangeRateMutedField,
|
||||
FeatureCan,
|
||||
BranchSelect,
|
||||
@@ -35,30 +33,20 @@ import {
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
compose,
|
||||
} from '@/utils';
|
||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||
import {
|
||||
useObserveTransactionNoSettings,
|
||||
useSetPrimaryBranchToForm,
|
||||
useForeignAccount,
|
||||
BranchRowDivider,
|
||||
} from '../../MoneyInDialog/utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||
|
||||
/**
|
||||
* Transfer from account form fields.
|
||||
*/
|
||||
function TransferFromAccountFormFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
}) {
|
||||
export default function TransferFromAccountFormFields() {
|
||||
// Money in dialog context.
|
||||
const { accounts, account, branches } = useMoneyInDailogContext();
|
||||
|
||||
@@ -67,33 +55,9 @@ function TransferFromAccountFormFields({
|
||||
|
||||
const { values } = useFormikContext();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
// Syncs transaction number settings with form.
|
||||
useObserveTransactionNoSettings(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
return (
|
||||
<React.Fragment>
|
||||
<FeatureCan feature={Features.Branches}>
|
||||
@@ -145,42 +109,7 @@ function TransferFromAccountFormFields({
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/*------------ Transaction number -----------*/}
|
||||
<Field name={'transaction_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'transaction_number'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="transaction_number" />}
|
||||
className={'form-group--transaction_number'}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<MoneyInOutTransactionNoField />
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ amount -----------*/}
|
||||
@@ -296,12 +225,3 @@ function TransferFromAccountFormFields({
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(TransferFromAccountFormFields);
|
||||
@@ -20,7 +20,6 @@ function MoneyOutContentFields({ accountType }) {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return <React.Fragment>{handleTransactionType()}</React.Fragment>;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
|
||||
import MoneyOutFormFields from './MoneyOutFormFields';
|
||||
import MoneyOutFormDialog from './MoneyOutFormDialog'
|
||||
import MoneyOutFormDialog from './MoneyOutFormDialog';
|
||||
import MoneyOutFloatingActions from './MoneyOutFloatingActions';
|
||||
import { MoneyInOutSyncIncrementSettingsToForm } from '../_components';
|
||||
|
||||
/**
|
||||
* Money out form content.
|
||||
*/
|
||||
@@ -12,8 +14,9 @@ export default function MoneyOutFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<MoneyOutFormFields />
|
||||
<MoneyOutFormDialog/>
|
||||
<MoneyOutFormDialog />
|
||||
<MoneyOutFloatingActions />
|
||||
<MoneyInOutSyncIncrementSettingsToForm />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -16,11 +16,9 @@ import {
|
||||
InputPrependText,
|
||||
MoneyInputGroup,
|
||||
FieldRequiredHint,
|
||||
Icon,
|
||||
Col,
|
||||
Row,
|
||||
If,
|
||||
InputPrependButton,
|
||||
FeatureCan,
|
||||
BranchSelect,
|
||||
BranchSelectButton,
|
||||
@@ -35,31 +33,21 @@ import {
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
compose,
|
||||
} from '@/utils';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
||||
import {
|
||||
useObserveTransactionNoSettings,
|
||||
useSetPrimaryBranchToForm,
|
||||
useForeignAccount,
|
||||
BranchRowDivider,
|
||||
} from '../utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||
|
||||
/**
|
||||
* Other expense form fields.
|
||||
*/
|
||||
function OtherExpnseFormFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
}) {
|
||||
export default function OtherExpnseFormFields() {
|
||||
// Money in dialog context.
|
||||
const { accounts, account, branches } = useMoneyOutDialogContext();
|
||||
|
||||
@@ -68,31 +56,6 @@ function OtherExpnseFormFields({
|
||||
|
||||
const amountFieldRef = useAutofocus();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Syncs transaction number settings with form.
|
||||
useObserveTransactionNoSettings(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
@@ -147,42 +110,7 @@ function OtherExpnseFormFields({
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/*------------ Transaction number -----------*/}
|
||||
<Field name={'transaction_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'transaction_number'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="transaction_number" />}
|
||||
className={'form-group--transaction_number'}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<MoneyInOutTransactionNoField />
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ amount -----------*/}
|
||||
@@ -296,12 +224,3 @@ function OtherExpnseFormFields({
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(OtherExpnseFormFields);
|
||||
@@ -17,8 +17,6 @@ import {
|
||||
InputPrependText,
|
||||
MoneyInputGroup,
|
||||
FieldRequiredHint,
|
||||
InputPrependButton,
|
||||
Icon,
|
||||
If,
|
||||
Col,
|
||||
Row,
|
||||
@@ -34,30 +32,19 @@ import {
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
compose,
|
||||
} from '@/utils';
|
||||
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
||||
import {
|
||||
useObserveTransactionNoSettings,
|
||||
useSetPrimaryBranchToForm,
|
||||
useForeignAccount,
|
||||
BranchRowDivider,
|
||||
} from '../../MoneyOutDialog/utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||
|
||||
/**
|
||||
* Owner drawings form fields.
|
||||
*/
|
||||
function OwnerDrawingsFormFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
}) {
|
||||
export default function OwnerDrawingsFormFields() {
|
||||
// Money out dialog context.
|
||||
const { accounts, account, branches } = useMoneyOutDialogContext();
|
||||
const { values } = useFormikContext();
|
||||
@@ -65,31 +52,6 @@ function OwnerDrawingsFormFields({
|
||||
|
||||
const amountFieldRef = useAutofocus();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Syncs transaction number settings with form.
|
||||
useObserveTransactionNoSettings(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
@@ -144,42 +106,7 @@ function OwnerDrawingsFormFields({
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/*------------ Transaction number -----------*/}
|
||||
<Field name={'transaction_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'transaction_number'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="transaction_number" />}
|
||||
className={'form-group--transaction_number'}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<MoneyInOutTransactionNoField />
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ amount -----------*/}
|
||||
@@ -291,12 +218,3 @@ function OwnerDrawingsFormFields({
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(OwnerDrawingsFormFields);
|
||||
@@ -48,19 +48,12 @@ import {
|
||||
} from '../utils';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||
|
||||
/**
|
||||
* Transfer to account form fields.
|
||||
*/
|
||||
function TransferToAccountFormFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
}) {
|
||||
export default function TransferToAccountFormFields() {
|
||||
// Money in dialog context.
|
||||
const { accounts, account, branches } = useMoneyOutDialogContext();
|
||||
const { values } = useFormikContext();
|
||||
@@ -68,31 +61,6 @@ function TransferToAccountFormFields({
|
||||
|
||||
const accountRef = useAutofocus();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Syncs transaction number settings with form.
|
||||
useObserveTransactionNoSettings(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
|
||||
// Sets the primary branch to form.
|
||||
useSetPrimaryBranchToForm();
|
||||
|
||||
@@ -147,42 +115,7 @@ function TransferToAccountFormFields({
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/*------------ Transaction number -----------*/}
|
||||
<Field name={'transaction_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'transaction_number'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="transaction_number" />}
|
||||
className={'form-group--transaction_number'}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<MoneyInOutTransactionNoField />
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ amount -----------*/}
|
||||
@@ -298,11 +231,3 @@ function TransferToAccountFormFields({
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(TransferToAccountFormFields);
|
||||
127
packages/webapp/src/containers/CashFlow/_components.tsx
Normal file
127
packages/webapp/src/containers/CashFlow/_components.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { InputGroup, Position, ControlGroup } from '@blueprintjs/core';
|
||||
import * as R from 'ramda';
|
||||
|
||||
import {
|
||||
FFormGroup,
|
||||
Icon,
|
||||
InputPrependButton,
|
||||
FormattedMessage as T,
|
||||
} from '@/components';
|
||||
import { useUpdateEffect } from '@/hooks';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
|
||||
/**
|
||||
* Syncs cashflow auto-increment settings to the form once update.
|
||||
*/
|
||||
export const MoneyInOutSyncIncrementSettingsToForm = R.compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(
|
||||
({
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
transactionNextNumber,
|
||||
transactionNumberPrefix,
|
||||
}) => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
useUpdateEffect(() => {
|
||||
// Do not update if the invoice auto-increment is disabled.
|
||||
if (!transactionAutoIncrement) return null;
|
||||
|
||||
const transactionNumber = transactionNumber(
|
||||
transactionNumberPrefix,
|
||||
transactionNextNumber,
|
||||
);
|
||||
setFieldValue('transaction_number', transactionNumber);
|
||||
}, [setFieldValue, transactionNumberPrefix, transactionNextNumber]);
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Money In/Out transaction number field.
|
||||
*/
|
||||
export const MoneyInOutTransactionNoField = R.compose(
|
||||
withDialogActions,
|
||||
withSettings(({ cashflowSetting }) => ({
|
||||
transactionAutoIncrement: cashflowSetting?.autoIncrement,
|
||||
transactionNextNumber: cashflowSetting?.nextNumber,
|
||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||
})),
|
||||
)(
|
||||
({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
transactionAutoIncrement,
|
||||
}) => {
|
||||
const { values, setFieldValue } = useFormikContext();
|
||||
|
||||
// Handle tranaction number changing.
|
||||
const handleTransactionNumberChange = () => {
|
||||
openDialog('transaction-number-form');
|
||||
};
|
||||
// Handle transaction no. field blur.
|
||||
const handleTransactionNoBlur = (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (values.transaction_number !== newValue && transactionAutoIncrement) {
|
||||
openDialog('transaction-number-form', {
|
||||
initialFormValues: {
|
||||
onceManualNumber: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
if (!transactionAutoIncrement) {
|
||||
setFieldValue('transaction_number', values.transaction_number);
|
||||
setFieldValue('transaction_number_manually', values.transaction_number);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<FFormGroup
|
||||
name={'transaction_number'}
|
||||
label={<T id={'transaction_number'} />}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={values.transaction_number}
|
||||
asyncControl={true}
|
||||
onBlur={handleTransactionNoBlur}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleTransactionNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T
|
||||
id={
|
||||
'cash_flow.setting_your_auto_generated_transaction_number'
|
||||
}
|
||||
/>
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FFormGroup>
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -7,8 +7,10 @@ export const mapStateToProps = (state, props) => {
|
||||
};
|
||||
|
||||
export const mapDispatchToProps = (dispatch) => ({
|
||||
openDialog: (name, payload) => dispatch({ type: t.OPEN_DIALOG, name, payload }),
|
||||
closeDialog: (name, payload) => dispatch({ type: t.CLOSE_DIALOG, name, payload }),
|
||||
openDialog: (name, payload) =>
|
||||
dispatch({ type: t.OPEN_DIALOG, name, payload }),
|
||||
closeDialog: (name, payload) =>
|
||||
dispatch({ type: t.CLOSE_DIALOG, name, payload }),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
export default connect(null, mapDispatchToProps);
|
||||
|
||||
@@ -65,7 +65,6 @@ function CreditNoteNumberDialogContent({
|
||||
const handleChange = (values) => {
|
||||
setReferenceFormValues(values);
|
||||
};
|
||||
|
||||
// Description.
|
||||
const description =
|
||||
referenceFormValues?.incrementMode === 'auto'
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
transformFormToSettings,
|
||||
transformSettingsToForm,
|
||||
} from '@/containers/JournalNumber/utils';
|
||||
import { DialogsName } from '@/constants/dialogs';
|
||||
|
||||
/**
|
||||
* invoice number dialog's content.
|
||||
@@ -39,7 +40,7 @@ function InvoiceNumberDialogContent({
|
||||
// Handle the form success.
|
||||
const handleSuccess = () => {
|
||||
setSubmitting(false);
|
||||
closeDialog('invoice-number-form');
|
||||
closeDialog(DialogsName.InvoiceNumberSettings);
|
||||
onConfirm(values);
|
||||
};
|
||||
// Handle the form errors.
|
||||
@@ -56,10 +57,9 @@ function InvoiceNumberDialogContent({
|
||||
// Save the settings.
|
||||
saveSettings({ options }).then(handleSuccess).catch(handleErrors);
|
||||
};
|
||||
|
||||
// Handle the dialog close.
|
||||
const handleClose = () => {
|
||||
closeDialog('invoice-number-form');
|
||||
closeDialog(DialogsName.InvoiceNumberSettings);
|
||||
};
|
||||
// Handle form change.
|
||||
const handleChange = (values) => {
|
||||
@@ -71,17 +71,19 @@ function InvoiceNumberDialogContent({
|
||||
? intl.get('invoice.auto_increment.auto')
|
||||
: intl.get('invoice.auto_increment.manually');
|
||||
|
||||
const initialFormValues = {
|
||||
...transformSettingsToForm({
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
}),
|
||||
...initialValues,
|
||||
};
|
||||
|
||||
return (
|
||||
<InvoiceNumberDialogProvider>
|
||||
<ReferenceNumberForm
|
||||
initialValues={{
|
||||
...transformSettingsToForm({
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
}),
|
||||
...initialValues,
|
||||
}}
|
||||
initialValues={initialFormValues}
|
||||
description={description}
|
||||
onSubmit={handleSubmitForm}
|
||||
onClose={handleClose}
|
||||
|
||||
@@ -30,7 +30,7 @@ export const getDefaultGeneralLedgerQuery = () => {
|
||||
return {
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||
basis: 'accural',
|
||||
basis: 'accrual',
|
||||
filterByOption: 'with-transactions',
|
||||
branchesIds: [],
|
||||
accountsIds: [],
|
||||
|
||||
@@ -13,7 +13,7 @@ export const getDefaultJournalQuery = () => {
|
||||
return {
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||
basis: 'accural',
|
||||
basis: 'accrual',
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function RadiosAccountingBasis(props) {
|
||||
{...rest}
|
||||
>
|
||||
<Radio label={intl.get('cash')} value="cash" />
|
||||
<Radio label={intl.get('accrual')} value="accural" />
|
||||
<Radio label={intl.get('accrual')} value="accrual" />
|
||||
</RadioGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
@@ -13,7 +13,7 @@ export function getDefaultTrialBalanceQuery() {
|
||||
return {
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||
basis: 'accural',
|
||||
basis: 'accrual',
|
||||
filterByOption: 'with-transactions',
|
||||
branchesIds: [],
|
||||
};
|
||||
|
||||
@@ -2,49 +2,49 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import * as Yup from 'yup';
|
||||
import { Formik, Form } from 'formik';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
|
||||
import '@/style/pages/ReferenceNumber/ReferenceNumber.scss';
|
||||
|
||||
import { FormObserver } from '@/components';
|
||||
import { FormattedMessage as T, FormObserver } from '@/components';
|
||||
import ReferenceNumberFormContent from './ReferenceNumberFormContent';
|
||||
import { transformValuesToForm } from './utils';
|
||||
import { saveInvoke } from '@/utils';
|
||||
import { saveInvoke, transformToForm } from '@/utils';
|
||||
|
||||
const initialFormValues = {
|
||||
incrementMode: 'auto',
|
||||
numberPrefix: '',
|
||||
nextNumber: '',
|
||||
onceManualNumber: '',
|
||||
};
|
||||
|
||||
// Validation schema.
|
||||
const validationSchema = Yup.object().shape({
|
||||
incrementMode: Yup.string(),
|
||||
numberPrefix: Yup.string(),
|
||||
nextNumber: Yup.number(),
|
||||
onceManualNumber: Yup.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Reference number form.
|
||||
*/
|
||||
export default function ReferenceNumberForm({
|
||||
onSubmit,
|
||||
onClose,
|
||||
initialValues,
|
||||
description,
|
||||
onSubmit,
|
||||
onClose,
|
||||
onChange,
|
||||
}) {
|
||||
// Validation schema.
|
||||
const validationSchema = Yup.object().shape({
|
||||
incrementMode: Yup.string(),
|
||||
numberPrefix: Yup.string(),
|
||||
nextNumber: Yup.number(),
|
||||
manualTransactionNo: Yup.string(),
|
||||
});
|
||||
// Initial values.
|
||||
const formInitialValues = useMemo(
|
||||
() => ({
|
||||
...initialValues,
|
||||
incrementMode:
|
||||
initialValues.incrementMode === 'auto' &&
|
||||
initialValues.manualTransactionNo
|
||||
? 'manual-transaction'
|
||||
: initialValues.incrementMode,
|
||||
}),
|
||||
[initialValues],
|
||||
);
|
||||
const formInitialValues = {
|
||||
...initialFormValues,
|
||||
...transformToForm(initialValues, initialFormValues),
|
||||
};
|
||||
// Handle the form submit.
|
||||
const handleSubmit = (values, methods) => {
|
||||
const parsed = transformValuesToForm(values);
|
||||
saveInvoke(onSubmit, { ...parsed, ...values }, methods);
|
||||
saveInvoke(onSubmit, { ...values, ...parsed }, methods);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { FastField, useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
import { FormGroup, InputGroup, Radio } from '@blueprintjs/core';
|
||||
import { If, Row, Col, ErrorMessage } from '@/components';
|
||||
|
||||
import { FormattedMessage as T, Row, Col, ErrorMessage } from '@/components';
|
||||
import { inputIntent } from '@/utils';
|
||||
|
||||
/**
|
||||
* Reference number form content.
|
||||
*/
|
||||
export default function ReferenceNumberFormContent() {
|
||||
const { values } = useFormikContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* ------------- Auto increment mode ------------- */}
|
||||
@@ -27,54 +25,13 @@ export default function ReferenceNumberFormContent() {
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
<If condition={values.incrementMode === 'auto'}>
|
||||
<Row>
|
||||
{/* ------------- Prefix ------------- */}
|
||||
<Col xs={4}>
|
||||
<FastField name={'numberPrefix'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'prefix'} />}
|
||||
className={'form-group--'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'numberPrefix'} />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
|
||||
{/* ------------- Next number ------------- */}
|
||||
<Col xs={6}>
|
||||
<FastField name={'nextNumber'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'next_number'} />}
|
||||
className={'form-group--next-number'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'nextNumber'} />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
</Row>
|
||||
</If>
|
||||
<ReferenceNumberAutoIncrement />
|
||||
|
||||
{/* ------------- Manual increment mode ------------- */}
|
||||
<FastField name={'incrementMode'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<Radio
|
||||
label={<T id={'auto_increment.field.manual_this_transaction'} />}
|
||||
label={<T id={'auto_increment.field.manually'} />}
|
||||
value="manual"
|
||||
onChange={() => {
|
||||
form.setFieldValue('incrementMode', 'manual');
|
||||
@@ -85,20 +42,70 @@ export default function ReferenceNumberFormContent() {
|
||||
</FastField>
|
||||
|
||||
{/* ------------- Transaction manual increment mode ------------- */}
|
||||
<If condition={values.manualTransactionNo}>
|
||||
<FastField name={'incrementMode'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<Radio
|
||||
label={<T id={'auto_increment.field.manually'} />}
|
||||
value="manual"
|
||||
onChange={() => {
|
||||
form.setFieldValue('incrementMode', 'manual-transaction');
|
||||
}}
|
||||
checked={field.value === 'manual-transaction'}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</If>
|
||||
<ReferenceNumberManualOnce />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ReferenceNumberAutoIncrement() {
|
||||
const { values } = useFormikContext();
|
||||
if (!values.incrementMode === 'auto') return null;
|
||||
|
||||
return (
|
||||
<Row>
|
||||
{/* ------------- Prefix ------------- */}
|
||||
<Col xs={4}>
|
||||
<FastField name={'numberPrefix'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'prefix'} />}
|
||||
className={'form-group--'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'numberPrefix'} />}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
|
||||
{/* ------------- Next number ------------- */}
|
||||
<Col xs={6}>
|
||||
<FastField name={'nextNumber'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'next_number'} />}
|
||||
className={'form-group--next-number'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'nextNumber'} />}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
|
||||
function ReferenceNumberManualOnce() {
|
||||
const { values } = useFormikContext();
|
||||
|
||||
// Do not show the field if the one manual transaction number is not presented.
|
||||
if (!values.onceManualNumber) return null;
|
||||
|
||||
return (
|
||||
<FastField name={'incrementMode'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<Radio
|
||||
label={<T id={'auto_increment.field.manual_this_transaction'} />}
|
||||
value="manual"
|
||||
onChange={() => {
|
||||
form.setFieldValue('incrementMode', 'manual-transaction');
|
||||
}}
|
||||
checked={field.value === 'manual-transaction'}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
transfromToSnakeCase,
|
||||
transactionNumber,
|
||||
} from '@/utils';
|
||||
import { omit } from 'lodash';
|
||||
|
||||
export const defaultInvoiceNoSettings = {
|
||||
nextNumber: '',
|
||||
@@ -13,8 +14,8 @@ export const defaultInvoiceNoSettings = {
|
||||
};
|
||||
|
||||
export const transformSettingsToForm = (settings) => ({
|
||||
...settings,
|
||||
incrementMode: settings.autoIncrement === 'true' ? 'auto' : 'manual',
|
||||
...omit(settings, ['autoIncrement']),
|
||||
incrementMode: settings.autoIncrement ? 'auto' : 'manual',
|
||||
});
|
||||
|
||||
export const transformFormToSettings = (values, group) => {
|
||||
@@ -25,13 +26,21 @@ export const transformFormToSettings = (values, group) => {
|
||||
return optionsMapToArray(options).map((option) => ({ ...option, group }));
|
||||
};
|
||||
|
||||
/**
|
||||
* Transaction number returns auto-increment if the increment mode is auto or
|
||||
* returns empty string if the increment mode is manually or returns the entered
|
||||
* manual text if the increment mode is manual once just in this transaction.
|
||||
*/
|
||||
export const transformValuesToForm = (values) => {
|
||||
const incrementNumber =
|
||||
const autoIncrementNumber = transactionNumber(
|
||||
values.numberPrefix,
|
||||
values.nextNumber,
|
||||
);
|
||||
const _transactionNumber =
|
||||
values.incrementMode === 'auto'
|
||||
? transactionNumber(values.numberPrefix, values.nextNumber)
|
||||
: values.manualTransactionNo;
|
||||
|
||||
const manually = values.incrementMode === 'auto' ? false : true;
|
||||
|
||||
return { incrementNumber, manually };
|
||||
? autoIncrementNumber
|
||||
: values.incrementMode === 'manual-transaction'
|
||||
? values.onceManualNumber
|
||||
: '';
|
||||
return { transactionNumber: _transactionNumber };
|
||||
};
|
||||
|
||||
@@ -2,12 +2,18 @@
|
||||
import * as Yup from 'yup';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
accounting_basis: Yup.string().required(),
|
||||
account_code_required: Yup.boolean().nullable(),
|
||||
account_code_unique: Yup.boolean().nullable(),
|
||||
withdrawal_account: Yup.number().nullable(),
|
||||
preferred_deposit_account: Yup.number().nullable(),
|
||||
preferred_advance_deposit: Yup.number().nullable(),
|
||||
organization: Yup.object({
|
||||
accountingBasis: Yup.string().required(),
|
||||
}),
|
||||
accounts: Yup.object({
|
||||
accountCodeRequired: Yup.boolean().nullable(),
|
||||
accountCodeUnique: Yup.boolean().nullable(),
|
||||
}),
|
||||
paymentReceives: Yup.object({
|
||||
preferredDepositAccount: Yup.number().nullable(),
|
||||
preferredAdvanceDeposit: Yup.number().nullable(),
|
||||
withdrawalAccount: Yup.number().nullable(),
|
||||
})
|
||||
});
|
||||
|
||||
export const AccountantSchema = Schema;
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Form, FastField, useFormikContext } from 'formik';
|
||||
import { Form, useFormikContext } from 'formik';
|
||||
import styled from 'styled-components';
|
||||
import {
|
||||
FormGroup,
|
||||
RadioGroup,
|
||||
Radio,
|
||||
Checkbox,
|
||||
Button,
|
||||
Intent,
|
||||
} from '@blueprintjs/core';
|
||||
import { FormGroup, Radio, Button, Intent } from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import {
|
||||
@@ -19,8 +12,9 @@ import {
|
||||
FieldRequiredHint,
|
||||
CardFooterActions,
|
||||
FFormGroup,
|
||||
FCheckbox,
|
||||
FRadioGroup,
|
||||
} from '@/components';
|
||||
import { handleStringChange, inputIntent } from '@/utils';
|
||||
import { ACCOUNT_PARENT_TYPE, ACCOUNT_TYPE } from '@/constants/accountTypes';
|
||||
import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
|
||||
@@ -30,7 +24,6 @@ import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
export default function AccountantForm() {
|
||||
const history = useHistory();
|
||||
const { accounts } = useAccountantFormContext();
|
||||
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
const handleCloseClick = () => {
|
||||
@@ -48,78 +41,54 @@ export default function AccountantForm() {
|
||||
}
|
||||
className={'accounts-checkbox'}
|
||||
>
|
||||
{/*------------ Account code (required) -----------*/}
|
||||
<FastField name={'account_code_required'} type={'checkbox'}>
|
||||
{({ field }) => (
|
||||
<FormGroup inline={true}>
|
||||
<Checkbox
|
||||
inline={true}
|
||||
label={
|
||||
<T
|
||||
id={'make_account_code_required_when_create_a_new_accounts'}
|
||||
/>
|
||||
}
|
||||
name={'account_code_required'}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/*------------ Account Code (required) -----------*/}
|
||||
<FFormGroup inline={true} name={'accounts.accountCodeRequired'}>
|
||||
<FCheckbox
|
||||
inline={true}
|
||||
label={
|
||||
<T id={'make_account_code_required_when_create_a_new_accounts'} />
|
||||
}
|
||||
name={'accounts.accountCodeRequired'}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/*------------ Account code (unique) -----------*/}
|
||||
<FastField name={'account_code_unique'} type={'checkbox'}>
|
||||
{({ field }) => (
|
||||
<FormGroup inline={true}>
|
||||
<Checkbox
|
||||
inline={true}
|
||||
label={
|
||||
<T
|
||||
id={
|
||||
'should_account_code_be_unique_when_create_a_new_account'
|
||||
}
|
||||
/>
|
||||
}
|
||||
name={'account_code_unique'}
|
||||
{...field}
|
||||
{/*------------ Account Code (unique) -----------*/}
|
||||
<FFormGroup
|
||||
name={'accounts.accountCodeUnique'}
|
||||
type={'checkbox'}
|
||||
inline={true}
|
||||
>
|
||||
<FCheckbox
|
||||
inline={true}
|
||||
label={
|
||||
<T
|
||||
id={'should_account_code_be_unique_when_create_a_new_account'}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
}
|
||||
name={'accounts.accountCodeUnique'}
|
||||
/>
|
||||
</FFormGroup>
|
||||
</FormGroup>
|
||||
|
||||
{/* ----------- Accounting basis ----------- */}
|
||||
<FastField name={'accounting_basis'}>
|
||||
{({
|
||||
form: { setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'accounting_basis_'} />
|
||||
</strong>
|
||||
}
|
||||
>
|
||||
<RadioGroup
|
||||
inline={true}
|
||||
selectedValue={value}
|
||||
onChange={handleStringChange((_value) => {
|
||||
setFieldValue('accounting_basis', _value);
|
||||
})}
|
||||
>
|
||||
<Radio label={intl.get('cash')} value="cash" />
|
||||
<Radio label={intl.get('accrual')} value="accrual" />
|
||||
</RadioGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/* ----------- Accounting Basis ----------- */}
|
||||
<FormGroup
|
||||
name={'organization.accountingBasis'}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'accounting_basis_'} />
|
||||
</strong>
|
||||
}
|
||||
>
|
||||
<FRadioGroup name={'organization.accountingBasis'} inline={true}>
|
||||
<Radio label={intl.get('cash')} value="cash" />
|
||||
<Radio label={intl.get('accrual')} value="accrual" />
|
||||
</FRadioGroup>
|
||||
</FormGroup>
|
||||
|
||||
{/* ----------- Deposit customer account ----------- */}
|
||||
{/* ----------- Deposit Customer Account ----------- */}
|
||||
<AccountantFormGroup
|
||||
name={'preferred_deposit_account'}
|
||||
name={'paymentReceives.preferredDepositAccount'}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'deposit_customer_account'} />
|
||||
@@ -136,7 +105,7 @@ export default function AccountantForm() {
|
||||
fastField={true}
|
||||
>
|
||||
<AccountsSelect
|
||||
name={'preferred_deposit_account'}
|
||||
name={'paymentReceives.preferredDepositAccount'}
|
||||
items={accounts}
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
filterByTypes={[
|
||||
@@ -148,9 +117,9 @@ export default function AccountantForm() {
|
||||
/>
|
||||
</AccountantFormGroup>
|
||||
|
||||
{/* ----------- Withdrawal vendor account ----------- */}
|
||||
{/* ----------- Withdrawal Vendor Account ----------- */}
|
||||
<AccountantFormGroup
|
||||
name={'withdrawal_account'}
|
||||
name={'billPayments.withdrawalAccount'}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'withdrawal_vendor_account'} />
|
||||
@@ -167,7 +136,7 @@ export default function AccountantForm() {
|
||||
fastField={true}
|
||||
>
|
||||
<AccountsSelect
|
||||
name={'withdrawal_account'}
|
||||
name={'billPayments.withdrawalAccount'}
|
||||
items={accounts}
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
filterByTypes={[
|
||||
@@ -179,9 +148,9 @@ export default function AccountantForm() {
|
||||
/>
|
||||
</AccountantFormGroup>
|
||||
|
||||
{/* ----------- Withdrawal customer account ----------- */}
|
||||
{/* ----------- Withdrawal Customer Account ----------- */}
|
||||
<AccountantFormGroup
|
||||
name={'preferred_advance_deposit'}
|
||||
name={'paymentReceives.preferredAdvanceDeposit'}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'customer_advance_deposit'} />
|
||||
@@ -198,7 +167,7 @@ export default function AccountantForm() {
|
||||
fastField={true}
|
||||
>
|
||||
<AccountsSelect
|
||||
name={'preferred_advance_deposit'}
|
||||
name={'paymentReceives.preferredAdvanceDeposit'}
|
||||
items={accounts}
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
filterByParentTypes={[ACCOUNT_PARENT_TYPE.CURRENT_ASSET]}
|
||||
|
||||
@@ -1,55 +1,66 @@
|
||||
// @ts-nocheck
|
||||
import React, { useEffect } from 'react';
|
||||
import * as R from 'ramda';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Formik } from 'formik';
|
||||
import { pick } from 'lodash';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { flatten, unflatten } from 'flat';
|
||||
|
||||
import { AppToaster } from '@/components';
|
||||
|
||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
|
||||
import AccountantForm from './AccountantForm';
|
||||
import { AccountantSchema } from './Accountant.schema';
|
||||
import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
import { transformToOptions } from './utils';
|
||||
import { compose, transformGeneralSettings } from '@/utils';
|
||||
import { transferObjectOptionsToArray } from './utils';
|
||||
import { compose, transformToForm, transfromToSnakeCase } from '@/utils';
|
||||
|
||||
import '@/style/pages/Preferences/Accounting.scss';
|
||||
|
||||
const defaultFormValues = flatten({
|
||||
organization: {
|
||||
accountingBasis: 'accrual',
|
||||
},
|
||||
accounts: {
|
||||
accountCodeRequired: false,
|
||||
accountCodeUnique: false,
|
||||
},
|
||||
billPayments: {
|
||||
withdrawalAccount: '',
|
||||
},
|
||||
paymentReceives: {
|
||||
preferredDepositAccount: '',
|
||||
preferredAdvanceDeposit: '',
|
||||
},
|
||||
});
|
||||
|
||||
// Accountant preferences.
|
||||
function AccountantFormPage({
|
||||
//# withDashboardActions
|
||||
changePreferencesPageTitle,
|
||||
|
||||
// #withSettings
|
||||
organizationSettings,
|
||||
paymentReceiveSettings,
|
||||
accountsSettings,
|
||||
billPaymentSettings,
|
||||
allSettings,
|
||||
}) {
|
||||
const { saveSettingMutate } = useAccountantFormContext();
|
||||
|
||||
const accountantSettings = {
|
||||
...billPaymentSettings,
|
||||
...accountsSettings,
|
||||
...pick(organizationSettings, ['accountingBasis']),
|
||||
...pick(paymentReceiveSettings, ['preferredDepositAccount', 'preferredAdvanceDeposit']),
|
||||
};
|
||||
|
||||
const initialValues = {
|
||||
...transformGeneralSettings(accountantSettings),
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
changePreferencesPageTitle(intl.get('accountant'));
|
||||
}, [changePreferencesPageTitle]);
|
||||
|
||||
const initialValues = unflatten({
|
||||
...defaultFormValues,
|
||||
...transformToForm(flatten(allSettings), defaultFormValues),
|
||||
});
|
||||
// Handle the form submitting.
|
||||
const handleFormSubmit = (values, { setSubmitting }) => {
|
||||
const options = transformToOptions(values);
|
||||
|
||||
const options = R.compose(
|
||||
transferObjectOptionsToArray,
|
||||
transfromToSnakeCase,
|
||||
)(values);
|
||||
setSubmitting(true);
|
||||
|
||||
const onSuccess = () => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_accountant_preferences_has_been_saved'),
|
||||
@@ -57,8 +68,7 @@ function AccountantFormPage({
|
||||
});
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
const onError = (errors) => {
|
||||
const onError = () => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||
@@ -75,18 +85,8 @@ function AccountantFormPage({
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettings(
|
||||
({
|
||||
organizationSettings,
|
||||
paymentReceiveSettings,
|
||||
accountsSettings,
|
||||
billPaymentSettings,
|
||||
}) => ({
|
||||
organizationSettings,
|
||||
paymentReceiveSettings,
|
||||
accountsSettings,
|
||||
billPaymentSettings,
|
||||
}),
|
||||
),
|
||||
withSettings(({ allSettings }) => ({
|
||||
allSettings,
|
||||
})),
|
||||
withDashboardActions,
|
||||
)(AccountantFormPage);
|
||||
|
||||
@@ -17,7 +17,7 @@ function AccountantFormProvider({ ...props }) {
|
||||
// Fetches the accounts list.
|
||||
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
||||
|
||||
//Fetches Organization Settings.
|
||||
// Fetches Organization Settings.
|
||||
const { isLoading: isSettingsLoading } = useSettings();
|
||||
|
||||
// Save Organization Settings.
|
||||
@@ -29,7 +29,7 @@ function AccountantFormProvider({ ...props }) {
|
||||
isAccountsLoading,
|
||||
saveSettingMutate,
|
||||
};
|
||||
|
||||
// Detarmines whether if any query is loading.
|
||||
const isLoading = isSettingsLoading || isAccountsLoading;
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,38 +1,6 @@
|
||||
// @ts-nocheck
|
||||
export const transformToOptions = (option) => {
|
||||
return [
|
||||
{
|
||||
key: 'accounting_basis',
|
||||
value: option.accounting_basis,
|
||||
group: 'organization',
|
||||
},
|
||||
{
|
||||
key: 'withdrawal_account',
|
||||
value: option.withdrawal_account,
|
||||
group: 'bill_payments',
|
||||
},
|
||||
{
|
||||
key: 'preferred_deposit_account',
|
||||
value: option.preferred_deposit_account,
|
||||
group: 'payment_receives',
|
||||
},
|
||||
{
|
||||
key: 'preferred_advance_deposit',
|
||||
value: option.preferred_advance_deposit,
|
||||
group: 'payment_receives',
|
||||
},
|
||||
{
|
||||
key: 'account_code_required',
|
||||
value: option.account_code_required,
|
||||
group: 'accounts',
|
||||
},
|
||||
{
|
||||
|
||||
key: 'account_code_unique',
|
||||
value: option.account_code_unique,
|
||||
group: 'accounts',
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
export const transferObjectOptionsToArray = (input) =>
|
||||
Object.entries(input).flatMap(([group, options]) =>
|
||||
Object.entries(options).map(([key, value]) => ({ group, key, value })),
|
||||
);
|
||||
|
||||
@@ -10,6 +10,7 @@ import { ActionMenuList, useCurrenciesTableColumns } from './components';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withAlertActions from '@/containers/Alert/withAlertActions';
|
||||
import styled from 'styled-components';
|
||||
|
||||
/**
|
||||
* Currencies table.
|
||||
@@ -46,7 +47,7 @@ function CurrenciesDataTable({
|
||||
};
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
<CurrencieDataTable
|
||||
columns={columns}
|
||||
data={currencies}
|
||||
loading={isCurrenciesLoading}
|
||||
@@ -68,3 +69,11 @@ export default compose(
|
||||
withDialogActions,
|
||||
withAlertActions,
|
||||
)(CurrenciesDataTable);
|
||||
|
||||
const CurrencieDataTable = styled(DataTable)`
|
||||
.table .th,
|
||||
.table .td {
|
||||
padding-top: 0.4rem;
|
||||
padding-bottom: 0.4rem;
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -3,15 +3,17 @@ import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import classNames from 'classnames';
|
||||
import { Form } from 'formik';
|
||||
import { Button, FormGroup, InputGroup, Intent } from '@blueprintjs/core';
|
||||
import { Button, FormGroup, Intent } from '@blueprintjs/core';
|
||||
import { TimezonePicker } from '@blueprintjs/timezone';
|
||||
import { ErrorMessage, FastField } from 'formik';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import {
|
||||
ListSelect,
|
||||
FieldRequiredHint,
|
||||
FormattedMessage as T,
|
||||
FFormGroup,
|
||||
FInputGroup,
|
||||
FSelect,
|
||||
} from '@/components';
|
||||
import { inputIntent } from '@/utils';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
@@ -46,153 +48,114 @@ export default function PreferencesGeneralForm({ isSubmitting }) {
|
||||
return (
|
||||
<Form>
|
||||
{/* ---------- Organization name ---------- */}
|
||||
<FastField name={'name'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'organization_name'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
intent={inputIntent({ error, touched })}
|
||||
className={'form-group--org-name'}
|
||||
helperText={<T id={'shown_on_sales_forms_and_purchase_orders'} />}
|
||||
>
|
||||
<InputGroup medium={'true'} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FFormGroup
|
||||
name={'name'}
|
||||
label={<T id={'organization_name'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
helperText={<T id={'shown_on_sales_forms_and_purchase_orders'} />}
|
||||
fastField={true}
|
||||
>
|
||||
<FInputGroup medium={'true'} name={'name'} fastField={true} />
|
||||
</FFormGroup>
|
||||
|
||||
{/* ---------- Industry ---------- */}
|
||||
<FastField name={'industry'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'organization_industry'} />}
|
||||
inline={true}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="industry" />}
|
||||
className={'form-group--org-industry'}
|
||||
>
|
||||
<InputGroup medium={'true'} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FFormGroup
|
||||
name={'industry'}
|
||||
label={<T id={'organization_industry'} />}
|
||||
inline={true}
|
||||
fastField={true}
|
||||
>
|
||||
<FInputGroup name={'industry'} medium={'true'} fastField={true} />
|
||||
</FFormGroup>
|
||||
|
||||
{/* ---------- Location ---------- */}
|
||||
<FastField name={'location'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'business_location'} />}
|
||||
className={classNames(
|
||||
'form-group--business-location',
|
||||
CLASSES.FILL,
|
||||
)}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="location" />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
>
|
||||
<ListSelect
|
||||
items={Countries}
|
||||
onItemSelect={({ value }) => {
|
||||
form.setFieldValue('location', value);
|
||||
}}
|
||||
selectedItem={value}
|
||||
selectedItemProp={'value'}
|
||||
defaultText={<T id={'select_business_location'} />}
|
||||
textProp={'name'}
|
||||
popoverProps={{ minimal: true }}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FFormGroup
|
||||
name={'location'}
|
||||
label={<T id={'business_location'} />}
|
||||
inline={true}
|
||||
fastField={true}
|
||||
>
|
||||
<FSelect
|
||||
name={'location'}
|
||||
items={Countries}
|
||||
valueAccessor={'countryCode'}
|
||||
labelAccessor={'countryCode'}
|
||||
textAccessor={'name'}
|
||||
placeholder={<T id={'select_business_location'} />}
|
||||
popoverProps={{ minimal: true }}
|
||||
fastField={true}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/* ---------- Base currency ---------- */}
|
||||
<FastField
|
||||
<FFormGroup
|
||||
name={'base_currency'}
|
||||
baseCurrencyDisabled={baseCurrencyDisabled}
|
||||
label={<T id={'base_currency'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
helperText={
|
||||
<T
|
||||
id={'you_can_t_change_the_base_currency_as_there_are_transactions'}
|
||||
/>
|
||||
}
|
||||
fastField={true}
|
||||
shouldUpdate={shouldBaseCurrencyUpdate}
|
||||
>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'base_currency'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={classNames('form-group--base-currency', CLASSES.FILL)}
|
||||
inline={true}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={
|
||||
<T
|
||||
id={
|
||||
'you_can_t_change_the_base_currency_as_there_are_transactions'
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ListSelect
|
||||
items={Currencies}
|
||||
onItemSelect={(currency) => {
|
||||
form.setFieldValue('base_currency', currency.key);
|
||||
}}
|
||||
selectedItem={value}
|
||||
selectedItemProp={'key'}
|
||||
defaultText={<T id={'select_base_currency'} />}
|
||||
textProp={'name'}
|
||||
labelProp={'key'}
|
||||
popoverProps={{ minimal: true }}
|
||||
disabled={baseCurrencyDisabled}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FSelect
|
||||
name={'base_currency'}
|
||||
items={Currencies}
|
||||
valueAccessor={'key'}
|
||||
textAccessor={'name'}
|
||||
labelAccessor={'key'}
|
||||
placeholder={<T id={'select_base_currency'} />}
|
||||
popoverProps={{ minimal: true }}
|
||||
disabled={baseCurrencyDisabled}
|
||||
fastField={true}
|
||||
shouldUpdate={shouldBaseCurrencyUpdate}
|
||||
baseCurrencyDisabled={baseCurrencyDisabled}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/* --------- Fiscal Year ----------- */}
|
||||
<FastField name={'fiscal_year'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'fiscal_year'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={classNames('form-group--fiscal-year', CLASSES.FILL)}
|
||||
inline={true}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<T id={'for_reporting_you_can_specify_any_month'} />}
|
||||
>
|
||||
<ListSelect
|
||||
items={FiscalYear}
|
||||
onItemSelect={(option) => {
|
||||
form.setFieldValue('fiscal_year', option.key);
|
||||
}}
|
||||
selectedItem={value}
|
||||
selectedItemProp={'key'}
|
||||
defaultText={<T id={'select_fiscal_year'} />}
|
||||
textProp={'name'}
|
||||
popoverProps={{ minimal: true }}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FFormGroup
|
||||
name={'fiscal_year'}
|
||||
label={<T id={'fiscal_year'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
helperText={<T id={'for_reporting_you_can_specify_any_month'} />}
|
||||
fastField={true}
|
||||
>
|
||||
<FSelect
|
||||
name={'fiscal_year'}
|
||||
items={FiscalYear}
|
||||
valueAccessor={'key'}
|
||||
textAccessor={'name'}
|
||||
placeholder={<T id={'select_fiscal_year'} />}
|
||||
popoverProps={{ minimal: true }}
|
||||
fastField={true}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/* ---------- Language ---------- */}
|
||||
<FastField name={'language'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'language'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
className={classNames('form-group--language', CLASSES.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="language" />}
|
||||
>
|
||||
<ListSelect
|
||||
items={Languages}
|
||||
selectedItemProp={'value'}
|
||||
textProp={'name'}
|
||||
defaultText={<T id={'select_language'} />}
|
||||
selectedItem={value}
|
||||
onItemSelect={(item) =>
|
||||
form.setFieldValue('language', item.value)
|
||||
}
|
||||
popoverProps={{ minimal: true }}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FormGroup
|
||||
name={'language'}
|
||||
label={<T id={'language'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
fastField={true}
|
||||
>
|
||||
<FSelect
|
||||
name={'language'}
|
||||
items={Languages}
|
||||
valueAccessor={'value'}
|
||||
textAccessor={'name'}
|
||||
placeholder={<T id={'select_language'} />}
|
||||
popoverProps={{ minimal: true }}
|
||||
fastField={true}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
{/* ---------- Time zone ---------- */}
|
||||
<FastField name={'timezone'}>
|
||||
@@ -222,30 +185,24 @@ export default function PreferencesGeneralForm({ isSubmitting }) {
|
||||
</FastField>
|
||||
|
||||
{/* --------- Data format ----------- */}
|
||||
<FastField name={'date_format'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'date_format'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
className={classNames('form-group--date-format', CLASSES.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="date_format" />}
|
||||
>
|
||||
<ListSelect
|
||||
items={dateFormats}
|
||||
onItemSelect={(dateFormat) => {
|
||||
form.setFieldValue('date_format', dateFormat.key);
|
||||
}}
|
||||
selectedItem={value}
|
||||
selectedItemProp={'key'}
|
||||
defaultText={<T id={'select_date_format'} />}
|
||||
textProp={'label'}
|
||||
popoverProps={{ minimal: true }}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<FFormGroup
|
||||
name={'date_format'}
|
||||
label={<T id={'date_format'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="date_format" />}
|
||||
fastField={true}
|
||||
>
|
||||
<FSelect
|
||||
name={'date_format'}
|
||||
items={dateFormats}
|
||||
valueAccessor={'key'}
|
||||
textAccessor={'label'}
|
||||
placeholder={<T id={'select_date_format'} />}
|
||||
popoverProps={{ minimal: true }}
|
||||
fastField={true}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
<CardFooterActions>
|
||||
<Button loading={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
||||
|
||||
@@ -40,6 +40,7 @@ function GeneralFormPage({
|
||||
|
||||
// Initial values.
|
||||
const initialValues = {
|
||||
...defaultValues,
|
||||
...transformToForm(organization.metadata, defaultValues),
|
||||
};
|
||||
// Handle the form submit.
|
||||
|
||||
@@ -23,6 +23,7 @@ function GeneralFormProvider({ ...props }) {
|
||||
const { isLoading: isOrganizationLoading, data: organization } =
|
||||
useCurrentOrganization();
|
||||
|
||||
// Fetch date format options.
|
||||
const { data: dateFormats, isLoading: isDateFormatsLoading } =
|
||||
useDateFormats();
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Form, useFormikContext } from 'formik';
|
||||
import { FormGroup, Button, Intent } from '@blueprintjs/core';
|
||||
import { Button, Intent } from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import styled from 'styled-components';
|
||||
import {
|
||||
AccountsSelect,
|
||||
FieldRequiredHint,
|
||||
@@ -30,7 +31,7 @@ export default function ItemForm() {
|
||||
return (
|
||||
<Form>
|
||||
{/* ----------- Preferred Sell Account ----------- */}
|
||||
<FormGroup
|
||||
<ItemFormGroup
|
||||
name={'preferred_sell_account'}
|
||||
label={
|
||||
<strong>
|
||||
@@ -53,10 +54,10 @@ export default function ItemForm() {
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
filterByParentTypes={[ACCOUNT_PARENT_TYPE.INCOME]}
|
||||
/>
|
||||
</FormGroup>
|
||||
</ItemFormGroup>
|
||||
|
||||
{/* ----------- Preferred Cost Account ----------- */}
|
||||
<FFormGroup
|
||||
<ItemFormGroup
|
||||
name={'preferred_cost_account'}
|
||||
label={
|
||||
<strong>
|
||||
@@ -79,10 +80,10 @@ export default function ItemForm() {
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
filterByParentTypes={[ACCOUNT_PARENT_TYPE.EXPENSE]}
|
||||
/>
|
||||
</FFormGroup>
|
||||
</ItemFormGroup>
|
||||
|
||||
{/* ----------- Preferred Inventory Account ----------- */}
|
||||
<FFormGroup
|
||||
<ItemFormGroup
|
||||
name={'preferred_inventory_account'}
|
||||
label={
|
||||
<strong>
|
||||
@@ -105,7 +106,7 @@ export default function ItemForm() {
|
||||
placeholder={<T id={'select_payment_account'} />}
|
||||
filterByTypes={[ACCOUNT_TYPE.INVENTORY]}
|
||||
/>
|
||||
</FFormGroup>
|
||||
</ItemFormGroup>
|
||||
|
||||
<CardFooterActions>
|
||||
<Button intent={Intent.PRIMARY} loading={isSubmitting} type="submit">
|
||||
@@ -118,3 +119,7 @@ export default function ItemForm() {
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
const ItemFormGroup = styled(FFormGroup)`
|
||||
max-width: 400px;
|
||||
`;
|
||||
|
||||
@@ -11,10 +11,21 @@ import ItemPreferencesForm from './ItemPreferencesForm';
|
||||
import { useItemPreferencesFormContext } from './ItemPreferencesFormProvider';
|
||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import { compose, optionsMapToArray, transformGeneralSettings } from '@/utils';
|
||||
import {
|
||||
compose,
|
||||
optionsMapToArray,
|
||||
transformGeneralSettings,
|
||||
transformToForm,
|
||||
} from '@/utils';
|
||||
|
||||
import '@/style/pages/Preferences/Accounting.scss';
|
||||
|
||||
const defaultFormValues = {
|
||||
preferred_sell_account: '',
|
||||
preferred_cost_account: '',
|
||||
preferred_inventory_account: '',
|
||||
};
|
||||
|
||||
// item form page preferences.
|
||||
function ItemPreferencesFormPage({
|
||||
// #withSettings
|
||||
@@ -25,16 +36,13 @@ function ItemPreferencesFormPage({
|
||||
}) {
|
||||
const { saveSettingMutate } = useItemPreferencesFormContext();
|
||||
|
||||
const itemPerferencesSettings = {
|
||||
...omit(itemsSettings, ['tableSize']),
|
||||
};
|
||||
|
||||
// Initial values.
|
||||
const initialValues = {
|
||||
preferred_sell_account: '',
|
||||
preferred_cost_account: '',
|
||||
preferred_inventory_account: '',
|
||||
...transformGeneralSettings(itemPerferencesSettings),
|
||||
...defaultFormValues,
|
||||
...transformToForm(
|
||||
transformGeneralSettings(itemsSettings),
|
||||
defaultFormValues,
|
||||
),
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -13,6 +13,15 @@ import BillFormHeaderFields from './BillFormHeaderFields';
|
||||
* Fill form header.
|
||||
*/
|
||||
function BillFormHeader() {
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<BillFormHeaderFields />
|
||||
<BillFormBigTotal />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function BillFormBigTotal() {
|
||||
const {
|
||||
values: { currency_code, entries },
|
||||
} = useFormikContext();
|
||||
@@ -21,14 +30,12 @@ function BillFormHeader() {
|
||||
const totalDueAmount = useMemo(() => sumBy(entries, 'amount'), [entries]);
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<BillFormHeaderFields />
|
||||
<PageFormBigNumber
|
||||
label={intl.get('due_amount')}
|
||||
amount={totalDueAmount}
|
||||
currencyCode={currency_code}
|
||||
/>
|
||||
</div>
|
||||
<PageFormBigNumber
|
||||
label={intl.get('due_amount')}
|
||||
amount={totalDueAmount}
|
||||
currencyCode={currency_code}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default BillFormHeader;
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
import { CreditNoteSyncIncrementSettingsToForm } from './components';
|
||||
|
||||
/**
|
||||
* Credit note form.
|
||||
@@ -105,7 +106,7 @@ function CreditNoteForm({
|
||||
open: submitPayload.open,
|
||||
};
|
||||
// Handle the request success.
|
||||
const onSuccess = (response) => {
|
||||
const onSuccess = () => {
|
||||
AppToaster.show({
|
||||
message: intl.get(
|
||||
isNewMode
|
||||
@@ -161,7 +162,12 @@ function CreditNoteForm({
|
||||
<CreditNoteItemsEntriesEditorField />
|
||||
<CreditNoteFormFooter />
|
||||
<CreditNoteFloatingActions />
|
||||
|
||||
{/*-------- Dialogs --------*/}
|
||||
<CreditNoteFormDialogs />
|
||||
|
||||
{/*-------- Effects --------*/}
|
||||
<CreditNoteSyncIncrementSettingsToForm />
|
||||
</Form>
|
||||
</Formik>
|
||||
</div>
|
||||
|
||||
@@ -1,25 +1,30 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import CreditNoteNumberDialog from '@/containers/Dialogs/CreditNoteNumberDialog';
|
||||
import { useFormikContext } from 'formik';
|
||||
import CreditNoteNumberDialog from '@/containers/Dialogs/CreditNoteNumberDialog';
|
||||
|
||||
/**
|
||||
* Credit note form dialogs.
|
||||
*/
|
||||
export default function CreditNoteFormDialogs() {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Update the form once the credit number form submit confirm.
|
||||
const handleCreditNumberFormConfirm = ({ incrementNumber, manually }) => {
|
||||
setFieldValue('credit_note_number', incrementNumber || '');
|
||||
setFieldValue('credit_note_no_manually', manually);
|
||||
const handleCreditNumberFormConfirm = (settings) => {
|
||||
// Set the credit note transaction no. that cames from dialog to the form.
|
||||
// the `credit_note_number` will be empty except the increment mode is not auto.
|
||||
setFieldValue('credit_note_number', settings.transactionNumber);
|
||||
setFieldValue('credit_note_number_manually', '');
|
||||
|
||||
if (settings.incrementMode !== 'auto') {
|
||||
setFieldValue('credit_note_number_manually', settings.transactionNumber);
|
||||
}
|
||||
};
|
||||
|
||||
const { setFieldValue } = useFormikContext();
|
||||
return (
|
||||
<React.Fragment>
|
||||
<CreditNoteNumberDialog
|
||||
dialogName={'credit-number-form'}
|
||||
onConfirm={handleCreditNumberFormConfirm}
|
||||
/>
|
||||
</React.Fragment>
|
||||
<CreditNoteNumberDialog
|
||||
dialogName={'credit-number-form'}
|
||||
onConfirm={handleCreditNumberFormConfirm}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,19 @@ import { PageFormBigNumber } from '@/components';
|
||||
* Credit note header.
|
||||
*/
|
||||
function CreditNoteFormHeader() {
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<CreditNoteFormHeaderFields />
|
||||
<CreditNoteFormBigNumber />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Big total number of credit note form header.
|
||||
* @returns {React.ReactNode}
|
||||
*/
|
||||
function CreditNoteFormBigNumber() {
|
||||
const {
|
||||
values: { entries, currency_code },
|
||||
} = useFormikContext();
|
||||
@@ -21,14 +34,11 @@ function CreditNoteFormHeader() {
|
||||
const totalAmount = React.useMemo(() => getEntriesTotal(entries), [entries]);
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||
<CreditNoteFormHeaderFields />
|
||||
<PageFormBigNumber
|
||||
label={intl.get('credit_note.label_amount_to_credit')}
|
||||
amount={totalAmount}
|
||||
currencyCode={currency_code}
|
||||
/>
|
||||
</div>
|
||||
<PageFormBigNumber
|
||||
label={intl.get('credit_note.label_amount_to_credit')}
|
||||
amount={totalAmount}
|
||||
currencyCode={currency_code}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import * as R from 'ramda';
|
||||
import classNames from 'classnames';
|
||||
import styled from 'styled-components';
|
||||
import {
|
||||
@@ -9,7 +10,8 @@ import {
|
||||
ControlGroup,
|
||||
} from '@blueprintjs/core';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import { FastField, Field, ErrorMessage } from 'formik';
|
||||
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import {
|
||||
CustomerSelectField,
|
||||
@@ -18,11 +20,10 @@ import {
|
||||
Icon,
|
||||
FormattedMessage as T,
|
||||
CustomerDrawerLink,
|
||||
FFormGroup,
|
||||
FInputGroup,
|
||||
} from '@/components';
|
||||
import {
|
||||
customerNameFieldShouldUpdate,
|
||||
useObserveCreditNoSettings,
|
||||
} from './utils';
|
||||
import { customerNameFieldShouldUpdate } from './utils';
|
||||
|
||||
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
@@ -30,49 +31,99 @@ import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { CreditNoteExchangeRateInputField } from './components';
|
||||
import {
|
||||
momentFormatter,
|
||||
compose,
|
||||
tansformDateValue,
|
||||
inputIntent,
|
||||
handleDateChange,
|
||||
} from '@/utils';
|
||||
|
||||
/**
|
||||
* Credit note transaction number field.
|
||||
*/
|
||||
const CreditNoteTransactionNoField = R.compose(
|
||||
withDialogActions,
|
||||
withSettings(({ creditNoteSettings }) => ({
|
||||
creditAutoIncrement: creditNoteSettings?.autoIncrement,
|
||||
creditNextNumber: creditNoteSettings?.nextNumber,
|
||||
creditNumberPrefix: creditNoteSettings?.numberPrefix,
|
||||
})),
|
||||
)(
|
||||
({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
creditAutoIncrement,
|
||||
}) => {
|
||||
const { values, setFieldValue } = useFormikContext();
|
||||
|
||||
// Handle credit number changing.
|
||||
const handleCreditNumberChange = () => {
|
||||
openDialog('credit-number-form');
|
||||
};
|
||||
// Handle credit note no. field blur.
|
||||
const handleCreditNoBlur = (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
// Show the confirmation dialog if the value has changed and auto-increment
|
||||
// mode is enabled.
|
||||
if (values.credit_note_no !== newValue && creditAutoIncrement) {
|
||||
openDialog('credit-number-form', {
|
||||
initialFormValues: {
|
||||
onceManualNumber: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
// Setting the credit note number to the form will be manually in case
|
||||
// auto-increment is disable.
|
||||
if (!creditAutoIncrement) {
|
||||
setFieldValue('credit_note_number', newValue);
|
||||
setFieldValue('credit_note_number_manually', newValue);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<FFormGroup
|
||||
name={'credit_note_number'}
|
||||
label={<T id={'credit_note.label_credit_note'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<FInputGroup
|
||||
name={'credit_note_number'}
|
||||
minimal={true}
|
||||
value={values.credit_note_number}
|
||||
asyncControl={true}
|
||||
onBlur={handleCreditNoBlur}
|
||||
onChange={() => {}}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleCreditNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T id={'setting_your_auto_generated_credit_note_number'} />
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FFormGroup>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Credit note form header fields.
|
||||
*/
|
||||
function CreditNoteFormHeaderFields({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
creditAutoIncrement,
|
||||
creditNumberPrefix,
|
||||
creditNextNumber,
|
||||
}) {
|
||||
export default function CreditNoteFormHeaderFields({}) {
|
||||
// Credit note form context.
|
||||
const { customers } = useCreditNoteFormContext();
|
||||
|
||||
// Handle credit number changing.
|
||||
const handleCreditNumberChange = () => {
|
||||
openDialog('credit-number-form');
|
||||
};
|
||||
|
||||
// Handle credit no. field blur.
|
||||
const handleCreditNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue && creditAutoIncrement) {
|
||||
openDialog('credit-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
incrementMode: 'manual-transaction',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Syncs credit number settings with form.
|
||||
useObserveCreditNoSettings(creditNumberPrefix, creditNextNumber);
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||
{/* ----------- Customer name ----------- */}
|
||||
@@ -119,7 +170,6 @@ function CreditNoteFormHeaderFields({
|
||||
name={'exchange_rate'}
|
||||
formGroupProps={{ label: ' ', inline: true }}
|
||||
/>
|
||||
|
||||
{/* ----------- Credit note date ----------- */}
|
||||
<FastField name={'credit_note_date'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
@@ -146,43 +196,8 @@ function CreditNoteFormHeaderFields({
|
||||
)}
|
||||
</FastField>
|
||||
{/* ----------- Credit note # ----------- */}
|
||||
<Field name={'credit_note_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'credit_note.label_credit_note'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
inline={true}
|
||||
className={classNames(
|
||||
'form-group--credit_note_number',
|
||||
CLASSES.FILL,
|
||||
)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="credit_note_number" />}
|
||||
>
|
||||
<ControlGroup fill={true}>
|
||||
<InputGroup
|
||||
minimal={true}
|
||||
value={field.value}
|
||||
asyncControl={true}
|
||||
onBlur={handleCreditNoBlur(form, field)}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
onClick: handleCreditNumberChange,
|
||||
icon: <Icon icon={'settings-18'} />,
|
||||
}}
|
||||
tooltip={true}
|
||||
tooltipProps={{
|
||||
content: (
|
||||
<T id={'setting_your_auto_generated_credit_note_number'} />
|
||||
),
|
||||
position: Position.BOTTOM_LEFT,
|
||||
}}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</Field>
|
||||
<CreditNoteTransactionNoField />
|
||||
|
||||
{/* ----------- Reference ----------- */}
|
||||
<FastField name={'reference_no'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
@@ -200,14 +215,6 @@ function CreditNoteFormHeaderFields({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ creditNoteSettings }) => ({
|
||||
creditAutoIncrement: creditNoteSettings?.autoIncrement,
|
||||
creditNextNumber: creditNoteSettings?.nextNumber,
|
||||
creditNumberPrefix: creditNoteSettings?.numberPrefix,
|
||||
})),
|
||||
)(CreditNoteFormHeaderFields);
|
||||
|
||||
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
||||
font-size: 11px;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import * as R from 'ramda';
|
||||
import { ExchangeRateInputGroup } from '@/components';
|
||||
import { useCurrentOrganization } from '@/hooks/state';
|
||||
import { useCreditNoteIsForeignCustomer } from './utils';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import { transactionNumber } from '@/utils';
|
||||
|
||||
/**
|
||||
* credit exchange rate input field.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function CreditNoteExchangeRateInputField({ ...props }) {
|
||||
export function CreditNoteExchangeRateInputField({ ...props }) {
|
||||
const currentOrganization = useCurrentOrganization();
|
||||
const { values } = useFormikContext();
|
||||
|
||||
@@ -27,4 +29,30 @@ import { useCreditNoteIsForeignCustomer } from './utils';
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs credit note auto-increment settings to form.
|
||||
* @return {React.ReactNode}
|
||||
*/
|
||||
export const CreditNoteSyncIncrementSettingsToForm = R.compose(
|
||||
withSettings(({ creditNoteSettings }) => ({
|
||||
creditAutoIncrement: creditNoteSettings?.autoIncrement,
|
||||
creditNextNumber: creditNoteSettings?.nextNumber,
|
||||
creditNumberPrefix: creditNoteSettings?.numberPrefix,
|
||||
})),
|
||||
)(({ creditAutoIncrement, creditNextNumber, creditNumberPrefix }) => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
useEffect(() => {
|
||||
// Do not update if the credit note auto-increment mode is disabled.
|
||||
if (!creditAutoIncrement) return;
|
||||
|
||||
setFieldValue(
|
||||
'credit_note_number',
|
||||
transactionNumber(creditNumberPrefix, creditNextNumber),
|
||||
);
|
||||
}, [setFieldValue, creditNumberPrefix, creditNextNumber]);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -40,7 +40,8 @@ export const defaultCreditNote = {
|
||||
customer_id: '',
|
||||
credit_note_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
credit_note_number: '',
|
||||
credit_note_no_manually: false,
|
||||
// Holds the credit note number that entered manually only.
|
||||
credit_note_number_manually: false,
|
||||
open: '',
|
||||
reference_no: '',
|
||||
note: '',
|
||||
@@ -130,18 +131,6 @@ export const entriesFieldShouldUpdate = (newProps, oldProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Syncs invoice no. settings with form.
|
||||
*/
|
||||
export const useObserveCreditNoSettings = (prefix, nextNumber) => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
React.useEffect(() => {
|
||||
const creditNo = transactionNumber(prefix, nextNumber);
|
||||
setFieldValue('credit_note_number', creditNo);
|
||||
}, [setFieldValue, prefix, nextNumber]);
|
||||
};
|
||||
|
||||
export const useSetPrimaryBranchToForm = () => {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
const { branches, isBranchesSuccess } = useCreditNoteFormContext();
|
||||
|
||||
@@ -19,6 +19,7 @@ import EstimateFloatingActions from './EstimateFloatingActions';
|
||||
import EstimateFormFooter from './EstimateFormFooter';
|
||||
import EstimateFormDialogs from './EstimateFormDialogs';
|
||||
import EstimtaeFormTopBar from './EstimtaeFormTopBar';
|
||||
import { EstimateIncrementSyncSettingsToForm } from './components';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
defaultEstimate,
|
||||
transfromsFormValuesToRequest,
|
||||
handleErrors,
|
||||
resetFormState,
|
||||
} from './utils';
|
||||
|
||||
/**
|
||||
@@ -40,7 +42,7 @@ function EstimateForm({
|
||||
// #withSettings
|
||||
estimateNextNumber,
|
||||
estimateNumberPrefix,
|
||||
estimateIncrementMode,
|
||||
estimateAutoIncrementMode,
|
||||
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
@@ -66,14 +68,16 @@ function EstimateForm({
|
||||
? { ...transformToEditForm(estimate) }
|
||||
: {
|
||||
...defaultEstimate,
|
||||
...(estimateIncrementMode && {
|
||||
// If the auto-increment mode is enabled, take the next estimate
|
||||
// number from the settings.
|
||||
...(estimateAutoIncrementMode && {
|
||||
estimate_number: estimateNumber,
|
||||
}),
|
||||
entries: orderingLinesIndexes(defaultEstimate.entries),
|
||||
currency_code: base_currency,
|
||||
}),
|
||||
}),
|
||||
[estimate, estimateNumber, estimateIncrementMode, base_currency],
|
||||
[estimate, estimateNumber, estimateAutoIncrementMode, base_currency],
|
||||
);
|
||||
|
||||
// Handles form submit.
|
||||
@@ -118,7 +122,7 @@ function EstimateForm({
|
||||
history.push('/estimates');
|
||||
}
|
||||
if (submitPayload.resetForm) {
|
||||
resetForm();
|
||||
resetFormState({ resetForm, initialValues, values });
|
||||
}
|
||||
};
|
||||
// Handle the request error.
|
||||
@@ -161,7 +165,11 @@ function EstimateForm({
|
||||
<EstimateFormFooter />
|
||||
<EstimateFloatingActions />
|
||||
|
||||
{/*------- Dialogs -------*/}
|
||||
<EstimateFormDialogs />
|
||||
|
||||
{/*------- Effects -------*/}
|
||||
<EstimateIncrementSyncSettingsToForm />
|
||||
</Form>
|
||||
</Formik>
|
||||
</div>
|
||||
@@ -172,7 +180,7 @@ export default compose(
|
||||
withSettings(({ estimatesSettings }) => ({
|
||||
estimateNextNumber: estimatesSettings?.nextNumber,
|
||||
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
||||
estimateIncrementMode: estimatesSettings?.autoIncrement,
|
||||
estimateAutoIncrementMode: estimatesSettings?.autoIncrement,
|
||||
})),
|
||||
withCurrentOrganization(),
|
||||
)(EstimateForm);
|
||||
|
||||
@@ -9,10 +9,14 @@ import EstimateNumberDialog from '@/containers/Dialogs/EstimateNumberDialog';
|
||||
export default function EstimateFormDialogs() {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Update the form once the invoice number form submit confirm.
|
||||
const handleEstimateNumberFormConfirm = ({ incrementNumber, manually }) => {
|
||||
setFieldValue('estimate_number', incrementNumber || '');
|
||||
setFieldValue('estimate_number_manually', manually);
|
||||
// Update the form once the estimate number form submit confirm.
|
||||
const handleEstimateNumberFormConfirm = (settings) => {
|
||||
setFieldValue('estimate_number', settings.transactionNumber);
|
||||
setFieldValue('estimate_number_manually', '');
|
||||
|
||||
if (settings.incrementMode !== 'auto') {
|
||||
setFieldValue('estimate_number_manually', settings.transactionNumber);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user