Compare commits

...

40 Commits

Author SHA1 Message Date
Ahmed Bouhuolia
f381d433ec fix Customer note does not appear in pdf document 2024-10-19 16:28:01 +02:00
Ahmed Bouhuolia
2ee49f7496 Merge pull request #719 from bigcapitalhq/track-pdf-documents-views-events
feat: Track events of pdf documents views
2024-10-19 13:40:18 +02:00
Ahmed Bouhuolia
bb299aa595 feat: Track events of pdf documents views 2024-10-19 13:38:28 +02:00
Ahmed Bouhuolia
a66867463e Merge pull request #718 from bigcapitalhq/invoice-number-filename-document
feat: Invoice number in downloaded pdf document
2024-10-19 13:16:48 +02:00
Ahmed Bouhuolia
de50b89e5c feat: Invoice number in downloaded pdf document 2024-10-19 13:16:06 +02:00
Ahmed Bouhuolia
c4ee143354 Merge pull request #717 from bigcapitalhq/preline-statements
ffeat: Pre-line invoice statements
2024-10-19 11:00:31 +02:00
Ahmed Bouhuolia
a2227016e5 feat: Pre-line invoice statements 2024-10-19 10:59:46 +02:00
Ahmed Bouhuolia
4d6f65b179 Merge pull request #716 from bigcapitalhq/add-quantity-column-pdf-templates
feat: Add quantity column to pdf templates
2024-10-17 16:01:02 +02:00
Ahmed Bouhuolia
758ebbe261 feat: Add qty column to server-side pdf templates 2024-10-17 16:00:19 +02:00
Ahmed Bouhuolia
279890e922 feat: Add qty column to preview pdf templates: 2024-10-17 15:58:19 +02:00
Ahmed Bouhuolia
44fae36b82 Merge pull request #715 from bigcapitalhq/sync-account-norma-cashflow
fix: Sync account normal of cashflow GL entries
2024-10-16 20:12:51 +02:00
Ahmed Bouhuolia
fc2fac80af fix: Sync account normal of cashflow GL entries 2024-10-16 20:12:25 +02:00
Ahmed Bouhuolia
5ad9a9654b Merge pull request #714 from bigcapitalhq/sync-plaid-credit-card-account-type
fix: Sync Plaid credit card account type
2024-10-16 19:47:13 +02:00
Ahmed Bouhuolia
8a4034cc5d fix: Sync Plaid credit card account type 2024-10-16 19:46:39 +02:00
Ahmed Bouhuolia
5649657bf0 Merge pull request #713 from bigcapitalhq/i18napply
chore: Move i18nApply localization to the account transformer
2024-10-15 19:27:43 +02:00
Ahmed Bouhuolia
c929a7cb27 chore: Move i18nApply localization to the account transformer 2024-10-15 19:27:15 +02:00
Ahmed Bouhuolia
eeedb789a9 Merge pull request #711 from bigcapitalhq/fix-parse-non-lowercase-import
fix: Parse the uppercase values in importing
2024-10-14 20:02:31 +02:00
Ahmed Bouhuolia
321af8c271 fix: Parse the uppercase values in importing 2024-10-14 20:01:52 +02:00
Ahmed Bouhuolia
fd4d86e797 Merge pull request #710 from bigcapitalhq/fix-import-category-on-items
fix: Import category column of item resource
2024-10-14 19:49:54 +02:00
Ahmed Bouhuolia
49988e27a2 fix: Import category column of item resource 2024-10-14 19:49:32 +02:00
Ahmed Bouhuolia
8c94ee5982 Dump CHANGELOG 2024-10-14 13:58:57 +02:00
Ahmed Bouhuolia
2e73a34fef Merge pull request #709 from bigcapitalhq/track-viewed-events
feat: Track account, invoice and item viewed events
2024-10-14 12:16:40 +02:00
Ahmed Bouhuolia
ea7f987fe3 feat: Track account, invoice and item viewed events 2024-10-14 12:15:21 +02:00
Ahmed Bouhuolia
d55503f0c7 Update README.md 2024-10-13 23:10:43 +02:00
Ahmed Bouhuolia
f59b8166b6 Merge pull request #708 from bigcapitalhq/add-customize-templates-btn-to-edit-forms
feat: Add customize templates button to edit forms
2024-10-13 21:15:08 +02:00
Ahmed Bouhuolia
2c735d7edf feat: Add customize templates button to edit forms 2024-10-13 21:14:18 +02:00
Ahmed Bouhuolia
5b5ab9fe1e Merge pull request #707 from bigcapitalhq/refactor-date-field
refactor: invoice, estimate, receipt, credit note and payment received date input fields
2024-10-13 18:03:36 +02:00
Ahmed Bouhuolia
28ac9b2d90 refactor: invoice, estimate, receipt, credit note and payment received date input fields 2024-10-13 18:01:43 +02:00
Ahmed Bouhuolia
3300a6a499 Merge pull request #705 from bigcapitalhq/fix-invoice-form-layout
fix: Invoice form layout
2024-10-13 17:23:54 +02:00
Ahmed Bouhuolia
152a22baa0 fix: Remove unused scss files 2024-10-13 17:22:14 +02:00
Ahmed Bouhuolia
e873198238 feat: typeing AppIntlProvider 2024-10-13 16:51:04 +02:00
Ahmed Bouhuolia
68a0db91ee feat: form header fields 2024-10-13 13:56:13 +02:00
Ahmed Bouhuolia
ddea7be24a feat: Add css utilities to Box, Stack and Group components 2024-10-13 01:06:17 +02:00
Ahmed Bouhuolia
b7b86bb0c5 fix: Invoice form layout 2024-10-12 20:49:56 +02:00
Ahmed Bouhuolia
817ef906dc Merge pull request #701 from bigcapitalhq/fix-disable-tabs-customize
fix: Disable tabs of the pdf customization if the first field not filed up
2024-10-12 12:52:01 +02:00
Ahmed Bouhuolia
863c7693fa fix: Disable tabs of the pdf customization if the first field not filled up 2024-10-10 16:41:21 +02:00
Ahmed Bouhuolia
cf78255220 Merge pull request #700 from bigcapitalhq/fix-company-logo-dimenstion-pdf-template
fix: Set max width/height to company logo of pdf templates
2024-10-08 10:12:03 +02:00
Ahmed Bouhuolia
f9aa6abdd7 fix: Set max width/height to company logo of pdf templates 2024-10-08 10:11:40 +02:00
Ahmed Bouhuolia
0a5e40a0d8 Merge pull request #699 from bigcapitalhq/fix-remove-logo-pdf-template
fix: Delete company logo from the PDF template
2024-10-08 08:21:03 +02:00
Ahmed Bouhuolia
4aa445fe35 fix: Delete company logo from the pdf template 2024-10-08 08:20:35 +02:00
126 changed files with 3118 additions and 1867 deletions

View File

@@ -2,6 +2,43 @@
All notable changes to Bigcapital server-side will be in this file.
# [0.20.5]
* fix: Disable tabs of the pdf customization if the first field not filed up by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/701
* fix: Invoice form layout by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/705
* refactor: Invoice, estimate, receipt, credit note and payment received date input fields by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/707
* feat: Add customize templates button to edit forms by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/708
* feat: Track account, invoice and item viewed events by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/709
# [0.20.4]
* fix: Delete company logo from the PDF template by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/699
* fix: Set max width/height to company logo of pdf templates by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/700
# [0.20.3]
* feat: Assign default PDF template automatically by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/687
* fix: pdf template addresses controlling by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/688
* fix: Remove empty lines from address formats by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/690
* fix: Pdf templates layout by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/691
* feat: Download invoice pdf of the payment link by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/689
* fix: Display country name by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/693
* feat: Add shared packages to Docker container by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/694
# [0.20.2]
* feat: Assign default PDF template automatically by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/687
* fix: pdf template addresses controlling by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/688
* fix: Remove empty lines from address formats by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/690
* fix: Pdf templates layout by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/691
* feat: Download invoice pdf of the payment link by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/689
* fix: Display country name by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/693
* feat: Add shared packages to Docker container by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/694
# [0.20.1]
* fix: Getting uploaded object uri by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/684
# [0.20.0]
* feat: Customize pdf templates by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/667

View File

@@ -12,6 +12,9 @@
<a href="https://github.com/bigcapitalhq/bigcapital/commits/develop">
<img src="https://img.shields.io/github/commit-activity/m/bigcapitalhq/bigcapital/develop" />
</a>
<a href="https://hub.docker.com/u/bigcapitalhq">
<img src="https://img.shields.io/docker/pulls/bigcapitalhq/webapp" />
</a>
<a href="https://discord.com/invite/c8nPBJafeb">
<img src="https://img.shields.io/discord/1066514716752625725?label=Discord" alt="" />
</a>

View File

@@ -30,17 +30,17 @@ block head
flex: 1 1 0%;
}
.#{prefix}-big-title {
font-size: 60px;
font-size: 30px;
margin: 0;
line-height: 1;
font-weight: 500;
color: #333;
}
.#{prefix}-logo-wrap img {
height: auto;
width: auto;
max-width: 400px;
max-height: 160px;
width: 100%;
height: 100%;
max-width: 260px;
max-height: 100px;
}
.#{prefix}-terms-list {
display: flex;
@@ -108,7 +108,14 @@ block head
.#{prefix}-table__cell--right {
text-align: right;
}
.#{prefix}-table__cell--item .item {
display: flex;
flex-direction: column;
gap: 2px;
}
.#{prefix}-table__cell--item .item .item__description{
color: #5f6b7c;
}
.#{prefix}-totals {
display: flex;
flex-direction: column;
@@ -143,7 +150,7 @@ block head
color: #666;
}
.#{prefix}-statement__value {
/* Styles for statement value */
white-space: pre-line;
}
block content
@@ -183,17 +190,20 @@ block content
table(class=`${prefix}-table`)
thead
tr
th(class=`${prefix}-table__header`) #{'Item'}
th(class=`${prefix}-table__header`) #{'Description'}
th(class=`${prefix}-table__header`) #{'Rate'}
th(class=`${prefix}-table__header`) #{'Total'}
th(class=`${prefix}-table__header ${prefix}-table__header--item`) #{'Item'}
th(class=`${prefix}-table__header ${prefix}-table__header--quantity ${prefix}-table__header--right`) #{'Quantity'}
th(class=`${prefix}-table__header ${prefix}-table__header--rate ${prefix}-table__header--right`) #{'Rate'}
th(class=`${prefix}-table__header ${prefix}-table__header--total ${prefix}-table__header--right`) #{'Total'}
tbody
each line in lines
tr(class=`${prefix}-table__row`)
td(class=`${prefix}-table__cell`) #{line.item}
td(class=`${prefix}-table__cell`) #{line.description}
td(class=`${prefix}-table__cell--right`) #{line.rate}
td(class=`${prefix}-table__cell--right`) #{line.total}
td(class=`${prefix}-table__cell ${prefix}-table__cell--item ${prefix}-table__cell--item`)
div.item
div.item__label #{line.item}
div.item__description #{line.description}
td(class=`${prefix}-table__cell ${prefix}-table__cell--quantity ${prefix}-table__cell--right`) #{line.quantity}
td(class=`${prefix}-table__cell ${prefix}-table__cell--rate ${prefix}-table__cell--right`) #{line.rate}
td(class=`${prefix}-table__cell ${prefix}-table__cell--total ${prefix}-table__cell--right`) #{line.total}
div(class=`${prefix}-totals`)
if showSubtotal

View File

@@ -30,17 +30,17 @@ block head
flex: 1 1 0%;
}
.#{prefix}-big-title {
font-size: 60px;
font-size: 30px;
margin: 0;
line-height: 1;
font-weight: 500;
color: #333;
}
.#{prefix}-logo-wrap img {
height: auto;
width: auto;
max-width: 400px;
max-height: 160px;
width: 100%;
height: 100%;
max-width: 260px;
max-height: 100px;
}
.#{prefix}-terms {
display: flex;
@@ -96,6 +96,9 @@ block head
.#{prefix}-table__header--right {
text-align: right;
}
.#{prefix}-table__header--item{
width: 50%;
}
.#{prefix}-table__cell {
border-bottom: 1px solid #F6F6F6;
padding: 12px 10px;
@@ -109,6 +112,14 @@ block head
.#{prefix}-table__cell:last-of-type {
padding-right: 0;
}
.#{prefix}-table__cell--item .item {
display: flex;
flex-direction: column;
gap: 2px;
}
.#{prefix}-table__cell--item .item .item__description{
color: #5f6b7c;
}
.#{prefix}-totals {
display: flex;
flex-direction: column;
@@ -143,6 +154,7 @@ block head
color: #666;
}
.#{prefix}-statement__value {
white-space: pre-line;
}
block content
@@ -192,17 +204,20 @@ block content
table(class=`${prefix}-table`)
thead
tr
th(class=`${prefix}-table__header`) Item
th(class=`${prefix}-table__header`) Description
th(class=`${prefix}-table__header ${prefix}-table__header--right`) Rate
th(class=`${prefix}-table__header ${prefix}-table__header--right`) Total
th(class=`${prefix}-table__header ${prefix}-table__header--item`) Item
th(class=`${prefix}-table__header ${prefix}-table__header--quantity ${prefix}-table__header--right`) Qty
th(class=`${prefix}-table__header ${prefix}-table__header--rate ${prefix}-table__header--right`) Rate
th(class=`${prefix}-table__header ${prefix}-table__header--total ${prefix}-table__header--right`) Total
tbody
each line in lines
tr
td(class=`${prefix}-table__cell`) #{line.item}
td(class=`${prefix}-table__cell`) #{line.description}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total}
td(class=`${prefix}-table__cell ${prefix}-table__cell--item`)
div.item
div.item__label #{line.item}
div.item__description #{line.description}
td(class=`${prefix}-table__cell ${prefix}-table__cell--quantity ${prefix}-table__cell--right`) #{line.quantity}
td(class=`${prefix}-table__cell ${prefix}-table__cell--rate ${prefix}-table__cell--right`) #{line.rate}
td(class=`${prefix}-table__cell ${prefix}-table__cell--total ${prefix}-table__cell--right`) #{line.total}
//- Totals section
div(class=`${prefix}-totals`)
@@ -216,12 +231,12 @@ block content
div(class=`${prefix}-totals__item-amount`) #{total}
//- Statements section
if showTermsConditions && termsConditions
div(class=`${prefix}-statement`)
div(class=`${prefix}-statement__label`) #{termsConditionsLabel}
div(class=`${prefix}-statement__value`) #{termsConditions}
if showCustomerNote && customerNote
div(class=`${prefix}-statement`)
div(class=`${prefix}-statement__label`) #{customerNoteLabel}
div(class=`${prefix}-statement__value`) #{customerNote}
if showTermsConditions && termsConditions
div(class=`${prefix}-statement`)
div(class=`${prefix}-statement__label`) #{termsConditionsLabel}
div(class=`${prefix}-statement__value`) #{termsConditions}

View File

@@ -30,17 +30,17 @@ block head
flex: 1 1 0%;
}
.#{prefix}-big-title {
font-size: 60px;
font-size: 30px;
margin: 0;
line-height: 1;
font-weight: 500;
color: #333;
}
.#{prefix}-logo-wrap img {
height: auto;
width: auto;
max-width: 400px;
max-height: 160px;
width: 100%;
height: 100%;
max-width: 260px;
max-height: 100px;
}
.#{prefix}-details {
display: flex;
@@ -102,6 +102,9 @@ block head
.#{prefix}-table__header--right {
text-align: right;
}
.#{prefix}-table__header--item {
width: 50%;
}
.#{prefix}-table__cell {
border-bottom: 1px solid #F6F6F6;
padding: 12px 10px;
@@ -115,6 +118,14 @@ block head
.#{prefix}-table__cell--right {
text-align: right;
}
.#{prefix}-table__cell--item .item {
display: flex;
flex-direction: column;
gap: 2px;
}
.#{prefix}-table__cell--item .item__description {
color: #5f6b7c;
}
.#{prefix}-totals {
display: flex;
flex-direction: column;
@@ -149,7 +160,7 @@ block head
color: #666;
}
.#{prefix}-paragraph__value {
/* Styles for values within the paragraph section */
white-space: pre-line;
}
block content
//- block head
@@ -199,15 +210,18 @@ block content
table(class=`${prefix}-table`)
thead
tr
th(class=`${prefix}-table__header`) #{lineItemLabel}
th(class=`${prefix}-table__header`) #{lineDescriptionLabel}
th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{lineRateLabel}
th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{lineTotalLabel}
th(class=`${prefix}-table__header ${prefix}-table__header--item`) #{lineItemLabel}
th(class=`${prefix}-table__header ${prefix}-table__header--quantity ${prefix}-table__header--right`) #{lineQuantityLabel}
th(class=`${prefix}-table__header ${prefix}-table__header--rate ${prefix}-table__header--right`) #{lineRateLabel}
th(class=`${prefix}-table__header ${prefix}-table__header--total ${prefix}-table__header--right`) #{lineTotalLabel}
tbody
each line in lines
tr
td(class=`${prefix}-table__cell`) #{line.item}
td(class=`${prefix}-table__cell`) #{line.description}
td(class=`${prefix}-table__cell ${prefix}-table__cell--item`)
div.item
div.item__label #{line.item}
div.item__description #{line.description}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.quantity}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total}

View File

@@ -31,17 +31,17 @@ block head
flex: 1 1 0%;
}
.#{prefix}-big-title{
font-size: 60px;
font-size: 30px;
margin: 0;
line-height: 1;
font-weight: 500;
color: #333;
}
.#{prefix}-logo-wrap img {
height: auto;
width: auto;
max-width: 400px;
max-height: 160px;
width: 100%;
height: 100%;
max-width: 260px;
max-height: 100px;
}
.#{prefix}-terms-list{
display: flex;

View File

@@ -28,13 +28,13 @@ block head
flex: 1 1 0%;
}
.#{prefix}-logo-wrap img {
height: auto;
width: auto;
max-width: 400px;
max-height: 160px;
width: 100%;
height: 100%;
max-width: 260px;
max-height: 100px;
}
.#{prefix}-big-title {
font-size: 60px;
font-size: 30px;
margin: 0;
line-height: 1;
font-weight: 500;
@@ -92,6 +92,9 @@ block head
.#{prefix}-table__header--right {
text-align: right;
}
.#{prefix}-table__header--item{
width: 50%;
}
.#{prefix}-table__cell {
border-bottom: 1px solid #F6F6F6;
padding: 12px 10px;
@@ -105,6 +108,14 @@ block head
.#{prefix}-table__cell--right {
text-align: right;
}
.#{prefix}-table__cell--item .item {
display: flex;
flex-direction: column;
gap: 2px;
}
.#{prefix}-table__cell--item .item .item__description{
color: #5f6b7c;
}
.#{prefix}-totals {
display: flex;
flex-direction: column;
@@ -133,7 +144,9 @@ block head
margin-bottom: 20px;
}
.#{prefix}-statement__label {}
.#{prefix}-statement__value {}
.#{prefix}-statement__value {
white-space: pre-line;
}
block content
//- block head
@@ -178,17 +191,20 @@ block content
table(class=`${prefix}-table`)
thead(class=`${prefix}-table__header`)
tr
th(class=`${prefix}-table__header`) Item
th(class=`${prefix}-table__header`) Description
th(class=`${prefix}-table__header ${prefix}-table__header--right`) Rate
th(class=`${prefix}-table__header ${prefix}-table__header--right`) Total
th(class=`${prefix}-table__header ${prefix}-table__header--item`) Item
th(class=`${prefix}-table__header ${prefix}-table__header--quantity ${prefix}-table__header--right`) Qty
th(class=`${prefix}-table__header ${prefix}-table__header--rate ${prefix}-table__header--right`) Rate
th(class=`${prefix}-table__header ${prefix}-table__header--total ${prefix}-table__header--right`) Total
tbody
each line in lines
tr(class=`${prefix}-table__row`)
td(class=`${prefix}-table__cell`)= line.item
td(class=`${prefix}-table__cell`)= line.description
td(class=`${prefix}-table__cell${prefix}-table__cell--right`)= line.rate
td(class=`${prefix}-table__cell${prefix}-table__cell--right`)= line.total
td(class=`${prefix}-table__cell ${prefix}-table__cell--item`)
div.item
div.item__label #{line.item}
div.item__description #{line.description}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.quantity}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate}
td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total}
//- Totals Section
div(class=`${prefix}-totals`)

View File

@@ -471,13 +471,14 @@ export default class PaymentReceivesController extends BaseController {
ACCEPT_TYPE.APPLICATION_PDF,
]);
if (ACCEPT_TYPE.APPLICATION_PDF === acceptType) {
const pdfContent = await this.creditNotePdf.getCreditNotePdf(
const [pdfContent, filename] = await this.creditNotePdf.getCreditNotePdf(
tenantId,
creditNoteId
);
res.set({
'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length,
'Content-Disposition': `attachment; filename="${filename}"`,
});
res.send(pdfContent);
} else {

View File

@@ -408,7 +408,7 @@ export default class PaymentReceivesController extends BaseController {
res: Response,
next: NextFunction
) {
const { tenantId } = req;
const { tenantId } = req;
try {
const data = await this.paymentReceiveApplication.getPaymentReceivedState(
@@ -473,7 +473,7 @@ export default class PaymentReceivesController extends BaseController {
]);
// Response in pdf format.
if (ACCEPT_TYPE.APPLICATION_PDF === acceptType) {
const pdfContent =
const [pdfContent, filename] =
await this.paymentReceiveApplication.getPaymentReceivePdf(
tenantId,
paymentReceiveId
@@ -481,6 +481,7 @@ export default class PaymentReceivesController extends BaseController {
res.set({
'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length,
'Content-Disposition': `attachment; filename="${filename}"`,
});
res.send(pdfContent);
// Response in json format.

View File

@@ -398,13 +398,15 @@ export default class SalesEstimatesController extends BaseController {
]);
// Retrieves estimate in pdf format.
if (ACCEPT_TYPE.APPLICATION_PDF == acceptType) {
const pdfContent = await this.saleEstimatesApplication.getSaleEstimatePdf(
tenantId,
estimateId
);
const [pdfContent, filename] =
await this.saleEstimatesApplication.getSaleEstimatePdf(
tenantId,
estimateId
);
res.set({
'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length,
'Content-Disposition': `attachment; filename="${filename}"`,
});
res.send(pdfContent);
// Retrieves estimates in json format.

View File

@@ -441,13 +441,15 @@ export default class SaleInvoicesController extends BaseController {
]);
// Retrieves invoice in pdf format.
if (ACCEPT_TYPE.APPLICATION_PDF == acceptType) {
const pdfContent = await this.saleInvoiceApplication.saleInvoicePdf(
tenantId,
saleInvoiceId
);
const [pdfContent, filename] =
await this.saleInvoiceApplication.saleInvoicePdf(
tenantId,
saleInvoiceId
);
res.set({
'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length,
'Content-Disposition': `attachment; filename="${filename}"`,
});
res.send(pdfContent);
// Retrieves invoice in json format.

View File

@@ -113,7 +113,7 @@ export default class SalesReceiptsController extends BaseController {
CheckPolicies(SaleReceiptAction.View, AbilitySubject.SaleReceipt),
asyncMiddleware(this.getSaleReceiptState.bind(this)),
this.handleServiceErrors
);
);
router.get(
'/:id',
CheckPolicies(SaleReceiptAction.View, AbilitySubject.SaleReceipt),
@@ -356,13 +356,15 @@ export default class SalesReceiptsController extends BaseController {
]);
// Retrieves receipt in pdf format.
if (ACCEPT_TYPE.APPLICATION_PDF == acceptType) {
const pdfContent = await this.saleReceiptsApplication.getSaleReceiptPdf(
tenantId,
saleReceiptId
);
const [pdfContent, filename] =
await this.saleReceiptsApplication.getSaleReceiptPdf(
tenantId,
saleReceiptId
);
res.set({
'Content-Type': 'application/pdf',
'Content-Length': pdfContent.length,
'Content-Disposition': `attachment; filename="${filename}"`,
});
res.send(pdfContent);
// Retrieves receipt in json format.

View File

@@ -2,14 +2,22 @@ export const SALE_INVOICE_CREATED = 'Sale invoice created';
export const SALE_INVOICE_EDITED = 'Sale invoice edited';
export const SALE_INVOICE_DELETED = 'Sale invoice deleted';
export const SALE_INVOICE_MAIL_DELIVERED = 'Sale invoice mail delivered';
export const SALE_INVOICE_VIEWED = 'Sale invoice viewed';
export const SALE_INVOICE_PDF_VIEWED = 'Sale invoice PDF viewed';
export const SALE_ESTIMATE_CREATED = 'Sale estimate created';
export const SALE_ESTIMATE_EDITED = 'Sale estimate edited';
export const SALE_ESTIMATE_DELETED = 'Sale estimate deleted';
export const SALE_ESTIMATE_PDF_VIEWED = 'Sale estimate PDF viewed';
export const PAYMENT_RECEIVED_CREATED = 'Payment received created';
export const PAYMENT_RECEIVED_EDITED = 'payment received edited';
export const PAYMENT_RECEIVED_DELETED = 'Payment received deleted';
export const PAYMENT_RECEIVED_PDF_VIEWED = 'Payment received PDF viewed';
export const SALE_RECEIPT_PDF_VIEWED = 'Sale credit PDF viewed';
export const CREDIT_NOTE_PDF_VIEWED = 'Credit note PDF viewed';
export const BILL_CREATED = 'Bill created';
export const BILL_EDITED = 'Bill edited';
@@ -26,10 +34,12 @@ export const EXPENSE_DELETED = 'Expense deleted';
export const ACCOUNT_CREATED = 'Account created';
export const ACCOUNT_EDITED = 'Account Edited';
export const ACCOUNT_DELETED = 'Account deleted';
export const ACCOUNT_VIEWED = 'Account viewed';
export const ITEM_EVENT_CREATED = 'Item created';
export const ITEM_EVENT_EDITED = 'Item edited';
export const ITEM_EVENT_DELETED = 'Item deleted';
export const ITEM_EVENT_VIEWED = 'Item viewed';
export const AUTH_SIGNED_UP = 'Auth Signed-up';
export const AUTH_RESET_PASSWORD = 'Auth reset password';
@@ -79,7 +89,8 @@ export const PAYMENT_METHOD_DELETED = 'Payment method deleted';
export const INVOICE_PAYMENT_LINK_GENERATED = 'Invoice payment link generated';
export const STRIPE_INTEGRAION_CONNECTED = 'Stripe integration oauth2 connected';
export const STRIPE_INTEGRAION_CONNECTED =
'Stripe integration oauth2 connected';
// # Event Groups
export const ACCOUNT_GROUP = 'Account';

View File

@@ -129,6 +129,7 @@ export const ACCOUNT_TYPES = [
normal: ACCOUNT_NORMAL.CREDIT,
rootType: ACCOUNT_ROOT_TYPE.LIABILITY,
parentType: ACCOUNT_PARENT_TYPE.CURRENT_LIABILITY,
multiCurrency: true,
balanceSheet: true,
incomeSheet: false,
},

View File

@@ -294,7 +294,7 @@ export default {
name: 'item.field.note',
fieldType: 'text',
},
category: {
categoryId: {
name: 'item.field.category',
fieldType: 'relation',
relationModel: 'ItemCategory',

View File

@@ -11,6 +11,12 @@ export default class UncategorizedCashflowTransaction extends mixin(
) {
id!: number;
date!: Date | string;
/**
* Transaction amount.
* Negative represents to spending and positive to deposit/card charge.
* @param {number}
*/
amount!: number;
categorized!: boolean;
accountId!: number;

View File

@@ -14,6 +14,8 @@ export class AccountTransformer extends Transformer {
*/
public includeAttributes = (): string[] => {
return [
'accountTypeLabel',
'accountNormalFormatted',
'formattedAmount',
'flattenName',
'bankBalanceFormatted',
@@ -84,6 +86,22 @@ export class AccountTransformer extends Transformer {
return account.plaidItem?.isPaused || false;
};
/**
* Retrieves formatted account type label.
* @returns {string}
*/
protected accountTypeLabel = (account: any): string => {
return this.context.i18n.__(account.accountTypeLabel);
};
/**
* Retrieves formatted account normal.
* @returns {string}
*/
protected accountNormalFormatted = (account: any): string => {
return this.context.i18n.__(account.accountNormalFormatted);
};
/**
* Transformes the accounts collection to flat or nested array.
* @param {IAccount[]}

View File

@@ -3,6 +3,8 @@ import I18nService from '@/services/I18n/I18nService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { AccountTransformer } from './AccountTransform';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Service()
export class GetAccount {
@@ -15,6 +17,9 @@ export class GetAccount {
@Inject()
private transformer: TransformerInjectable;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve the given account details.
* @param {number} tenantId
@@ -39,10 +44,13 @@ export class GetAccount {
new AccountTransformer(),
{ accountsGraph }
);
return this.i18nService.i18nApply(
[['accountTypeLabel'], ['accountNormalFormatted']],
transformed,
tenantId
);
const eventPayload = {
tenantId,
accountId,
};
// Triggers `onAccountViewed` event.
await this.eventPublisher.emitAsync(events.accounts.onViewed, eventPayload);
return transformed;
};
}

View File

@@ -4,11 +4,27 @@ import {
Institution as PlaidInstitution,
AccountBase as PlaidAccount,
TransactionBase as PlaidTransactionBase,
AccountType as PlaidAccountType,
} from 'plaid';
import {
CreateUncategorizedTransactionDTO,
IAccountCreateDTO,
} from '@/interfaces';
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
/**
* Retrieves the system account type from the given Plaid account type.
* @param {PlaidAccountType} plaidAccountType
* @returns {string}
*/
const getAccountTypeFromPlaidAccountType = (
plaidAccountType: PlaidAccountType
) => {
if (plaidAccountType === PlaidAccountType.Credit) {
return ACCOUNT_TYPE.CREDIT_CARD;
}
return ACCOUNT_TYPE.BANK;
};
/**
* Transformes the Plaid account to create cashflow account DTO.
@@ -28,7 +44,7 @@ export const transformPlaidAccountToCreateAccount = R.curry(
code: '',
description: plaidAccount.official_name,
currencyCode: plaidAccount.balances.iso_currency_code,
accountType: 'cash',
accountType: getAccountTypeFromPlaidAccountType(plaidAccount.type),
active: true,
bankBalance: plaidAccount.balances.current,
accountMask: plaidAccount.mask,

View File

@@ -1,14 +1,7 @@
import { Inject, Service } from 'typedi';
import { Knex } from 'knex';
import {
ILedgerEntry,
ICashflowTransaction,
AccountNormal,
} from '../../interfaces';
import {
transformCashflowTransactionType,
getCashflowAccountTransactionsTypes,
} from './utils';
import { ILedgerEntry, ICashflowTransaction } from '../../interfaces';
import { transformCashflowTransactionType } from './utils';
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
import Ledger from '@/services/Accounting/Ledger';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@@ -70,7 +63,7 @@ export default class CashflowTransactionJournalEntries {
debit: cashflowTransaction.isCashDebit
? cashflowTransaction.localAmount
: 0,
accountNormal: AccountNormal.DEBIT,
accountNormal: cashflowTransaction?.cashflowAccount?.accountNormal,
index: 1,
};
};
@@ -143,6 +136,7 @@ export default class CashflowTransactionJournalEntries {
// Retrieves the cashflow transactions with associated entries.
const transaction = await CashflowTransaction.query(trx)
.findById(cashflowTransactionId)
.withGraphFetched('cashflowAccount')
.withGraphFetched('creditAccount');
// Retrieves the cashflow transaction ledger.

View File

@@ -4,6 +4,7 @@ import { CashflowAccountTransformer } from './CashflowAccountTransformer';
import TenancyService from '@/services/Tenancy/TenancyService';
import DynamicListingService from '@/services/DynamicListing/DynamicListService';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
@Service()
export default class GetCashflowAccountsService {
@@ -41,14 +42,20 @@ export default class GetCashflowAccountsService {
const accounts = await CashflowAccount.query().onBuild((builder) => {
dynamicList.buildQuery()(builder);
builder.whereIn('account_type', ['bank', 'cash']);
builder.whereIn('account_type', [
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.CREDIT_CARD,
]);
builder.modify('inactiveMode', filter.inactiveMode);
});
// Retrieves the transformed accounts.
return this.transformer.transform(
const transformed = await this.transformer.transform(
tenantId,
accounts,
new CashflowAccountTransformer()
);
return transformed;
}
}

View File

@@ -12,7 +12,7 @@ export class GetCashflowTransactionService {
private tenancy: HasTenancyService;
@Inject()
private transfromer: TransformerInjectable;
private transformer: TransformerInjectable;
/**
* Retrieve the given cashflow transaction.
@@ -37,7 +37,7 @@ export class GetCashflowTransactionService {
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);
// Transformes the cashflow transaction model to POJO.
return this.transfromer.transform(
return this.transformer.transform(
tenantId,
cashflowTransaction,
new CashflowTransactionTransformer()

View File

@@ -6,6 +6,8 @@ import { CreditNoteBrandingTemplate } from './CreditNoteBrandingTemplate';
import { CreditNotePdfTemplateAttributes } from '@/interfaces';
import HasTenancyService from '../Tenancy/TenancyService';
import { transformCreditNoteToPdfTemplate } from './utils';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Service()
export default class GetCreditNotePdf {
@@ -24,12 +26,19 @@ export default class GetCreditNotePdf {
@Inject()
private creditNoteBrandingTemplate: CreditNoteBrandingTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieves sale invoice pdf content.
* @param {number} tenantId - Tenant id.
* @param {number} creditNoteId - Credit note id.
* @returns {Promise<[Buffer, string]>}
*/
public async getCreditNotePdf(tenantId: number, creditNoteId: number) {
public async getCreditNotePdf(
tenantId: number,
creditNoteId: number
): Promise<[Buffer, string]> {
const brandingAttributes = await this.getCreditNoteBrandingAttributes(
tenantId,
creditNoteId
@@ -39,7 +48,37 @@ export default class GetCreditNotePdf {
'modules/credit-note-standard',
brandingAttributes
);
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent);
const filename = await this.getCreditNoteFilename(tenantId, creditNoteId);
const document = await this.chromiumlyTenancy.convertHtmlContent(
tenantId,
htmlContent
);
const eventPayload = { tenantId, creditNoteId };
// Triggers the `onCreditNotePdfViewed` event.
await this.eventPublisher.emitAsync(
events.creditNote.onPdfViewed,
eventPayload
);
return [document, filename];
}
/**
* Retrieves the filename pdf document of the given credit note.
* @param {number} tenantId
* @param {number} creditNoteId
* @returns {Promise<string>}
*/
public async getCreditNoteFilename(
tenantId: number,
creditNoteId: number
): Promise<string> {
const { CreditNote } = this.tenancy.models(tenantId);
const creditNote = await CreditNote.query().findById(creditNoteId);
return `Credit-${creditNote.creditNoteNumber}`;
}
/**

View File

@@ -11,6 +11,7 @@ import {
ACCOUNT_CREATED,
ACCOUNT_EDITED,
ACCOUNT_DELETED,
ACCOUNT_VIEWED,
} from '@/constants/event-tracker';
@Service()
@@ -31,6 +32,7 @@ export class AccountEventsTracker extends EventSubscriber {
events.accounts.onDeleted,
this.handleTrackDeletedAccountEvent
);
bus.subscribe(events.accounts.onViewed, this.handleTrackAccountViewedEvent);
}
private handleTrackAccountCreatedEvent = ({
@@ -62,4 +64,12 @@ export class AccountEventsTracker extends EventSubscriber {
properties: {},
});
};
private handleTrackAccountViewedEvent = ({ tenantId }) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: ACCOUNT_VIEWED,
properties: {},
});
};
}

View File

@@ -11,6 +11,7 @@ import {
ITEM_EVENT_CREATED,
ITEM_EVENT_EDITED,
ITEM_EVENT_DELETED,
ITEM_EVENT_VIEWED,
} from '@/constants/event-tracker';
@Service()
@@ -25,6 +26,7 @@ export class ItemEventsTracker extends EventSubscriber {
bus.subscribe(events.item.onCreated, this.handleTrackItemCreatedEvent);
bus.subscribe(events.item.onEdited, this.handleTrackEditedItemEvent);
bus.subscribe(events.item.onDeleted, this.handleTrackDeletedItemEvent);
bus.subscribe(events.item.onViewed, this.handleTrackViewedItemEvent);
}
private handleTrackItemCreatedEvent = ({
@@ -56,4 +58,14 @@ export class ItemEventsTracker extends EventSubscriber {
properties: {},
});
};
private handleTrackViewedItemEvent = ({
tenantId,
}: IItemEventDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: ITEM_EVENT_VIEWED,
properties: {},
});
};
}

View File

@@ -11,6 +11,7 @@ import {
PAYMENT_RECEIVED_CREATED,
PAYMENT_RECEIVED_EDITED,
PAYMENT_RECEIVED_DELETED,
PAYMENT_RECEIVED_PDF_VIEWED,
} from '@/constants/event-tracker';
@Service()
@@ -34,6 +35,10 @@ export class PaymentReceivedEventsTracker extends EventSubscriber {
events.paymentReceive.onDeleted,
this.handleTrackDeletedPaymentReceivedEvent
);
bus.subscribe(
events.paymentReceive.onPdfViewed,
this.handleTrackPdfViewedPaymentReceivedEvent
);
}
private handleTrackPaymentReceivedCreatedEvent = ({
@@ -65,4 +70,14 @@ export class PaymentReceivedEventsTracker extends EventSubscriber {
properties: {},
});
};
private handleTrackPdfViewedPaymentReceivedEvent = ({
tenantId,
}: IPaymentReceivedDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: PAYMENT_RECEIVED_PDF_VIEWED,
properties: {},
});
};
}

View File

@@ -11,6 +11,7 @@ import {
SALE_ESTIMATE_CREATED,
SALE_ESTIMATE_EDITED,
SALE_ESTIMATE_DELETED,
SALE_ESTIMATE_PDF_VIEWED,
} from '@/constants/event-tracker';
@Service()
@@ -34,6 +35,10 @@ export class SaleEstimateEventsTracker extends EventSubscriber {
events.saleEstimate.onDeleted,
this.handleTrackDeletedEstimateEvent
);
bus.subscribe(
events.saleEstimate.onPdfViewed,
this.handleTrackPdfViewedEstimateEvent
);
}
private handleTrackEstimateCreatedEvent = ({
@@ -65,4 +70,14 @@ export class SaleEstimateEventsTracker extends EventSubscriber {
properties: {},
});
};
private handleTrackPdfViewedEstimateEvent = ({
tenantId,
}: ISaleEstimateDeletedPayload) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: SALE_ESTIMATE_PDF_VIEWED,
properties: {},
});
};
}

View File

@@ -10,6 +10,8 @@ import {
SALE_INVOICE_CREATED,
SALE_INVOICE_DELETED,
SALE_INVOICE_EDITED,
SALE_INVOICE_PDF_VIEWED,
SALE_INVOICE_VIEWED,
} from '@/constants/event-tracker';
@Service()
@@ -33,6 +35,14 @@ export class SaleInvoiceEventsTracker extends EventSubscriber {
events.saleInvoice.onDeleted,
this.handleTrackDeletedInvoiceEvent
);
bus.subscribe(
events.saleInvoice.onViewed,
this.handleTrackViewedInvoiceEvent
);
bus.subscribe(
events.saleInvoice.onPdfViewed,
this.handleTrackPdfViewedInvoiceEvent
);
}
private handleTrackInvoiceCreatedEvent = ({
@@ -64,4 +74,20 @@ export class SaleInvoiceEventsTracker extends EventSubscriber {
properties: {},
});
};
private handleTrackViewedInvoiceEvent = ({ tenantId }) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: SALE_INVOICE_VIEWED,
properties: {},
});
};
private handleTrackPdfViewedInvoiceEvent = ({ tenantId }) => {
this.posthog.trackEvent({
distinctId: `tenant-${tenantId}`,
event: SALE_INVOICE_PDF_VIEWED,
properties: {},
});
};
}

View File

@@ -299,7 +299,7 @@ export const valueParser =
// Parses the enumeration value.
} else if (field.fieldType === 'enumeration') {
const option = get(field, 'options', []).find(
(option) => option.label === value
(option) => option.label?.toLowerCase() === value?.toLowerCase()
);
_value = get(option, 'key');
// Parses the numeric value.
@@ -433,8 +433,8 @@ export const getMapToPath = (to: string, group = '') =>
group ? `${group}.${to}` : to;
export const getImportsStoragePath = () => {
return path.join(global.__storage_dir, `/imports`);
}
return path.join(global.__storage_dir, `/imports`);
};
/**
* Deletes the imported file from the storage and database.

View File

@@ -3,6 +3,8 @@ import { IItem } from '@/interfaces';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import ItemTransformer from './ItemTransformer';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Inject()
export class GetItem {
@@ -12,6 +14,9 @@ export class GetItem {
@Inject()
private transformer: TransformerInjectable;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve the item details of the given id with associated details.
* @param {number} tenantId
@@ -31,6 +36,16 @@ export class GetItem {
.withGraphFetched('purchaseTaxRate')
.throwIfNotFound();
return this.transformer.transform(tenantId, item, new ItemTransformer());
const transformed = await this.transformer.transform(
tenantId,
item,
new ItemTransformer()
);
const eventPayload = { tenantId, itemId };
// Triggers the `onItemViewed` event.
await this.eventPublisher.emitAsync(events.item.onViewed, eventPayload);
return transformed;
}
}

View File

@@ -6,6 +6,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
import { SaleEstimatePdfTemplate } from '../Invoices/SaleEstimatePdfTemplate';
import { transformEstimateToPdfTemplate } from './utils';
import { EstimatePdfBrandingAttributes } from './constants';
import events from '@/subscribers/events';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
@Service()
export class SaleEstimatesPdf {
@@ -24,12 +26,22 @@ export class SaleEstimatesPdf {
@Inject()
private estimatePdfTemplate: SaleEstimatePdfTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve sale invoice pdf content.
* @param {number} tenantId -
* @param {ISaleInvoice} saleInvoice -
*/
public async getSaleEstimatePdf(tenantId: number, saleEstimateId: number) {
public async getSaleEstimatePdf(
tenantId: number,
saleEstimateId: number
): Promise<[Buffer, string]> {
const filename = await this.getSaleEstimateFilename(
tenantId,
saleEstimateId
);
const brandingAttributes = await this.getEstimateBrandingAttributes(
tenantId,
saleEstimateId
@@ -39,7 +51,32 @@ export class SaleEstimatesPdf {
'modules/estimate-regular',
brandingAttributes
);
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent);
const content = await this.chromiumlyTenancy.convertHtmlContent(
tenantId,
htmlContent
);
const eventPayload = { tenantId, saleEstimateId };
// Triggers the `onSaleEstimatePdfViewed` event.
await this.eventPublisher.emitAsync(
events.saleEstimate.onPdfViewed,
eventPayload
);
return [content, filename];
}
/**
* Retrieves the filename file document of the given estimate.
* @param {number} tenantId
* @param {number} estimateId
* @returns {Promise<string>}
*/
private async getSaleEstimateFilename(tenantId: number, estimateId: number) {
const { SaleEstimate } = this.tenancy.models(tenantId);
const estimate = await SaleEstimate.query().findById(estimateId);
return `Estimate-${estimate.estimateNumber}`;
}
/**

View File

@@ -17,7 +17,7 @@ export const transformEstimateToPdfTemplate = (
})),
total: estimate.formattedSubtotal,
subtotal: estimate.formattedSubtotal,
customerNote: estimate.customerNote,
customerNote: estimate.note,
termsConditions: estimate.termsConditions,
customerAddress: contactAddressTextFormat(estimate.customer),
};

View File

@@ -4,6 +4,8 @@ import { SaleInvoiceTransformer } from './SaleInvoiceTransformer';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { CommandSaleInvoiceValidators } from './CommandSaleInvoiceValidators';
import events from '@/subscribers/events';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
@Service()
export class GetSaleInvoice {
@@ -16,6 +18,9 @@ export class GetSaleInvoice {
@Inject()
private validators: CommandSaleInvoiceValidators;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve sale invoice with associated entries.
* @param {Number} saleInvoiceId -
@@ -41,10 +46,20 @@ export class GetSaleInvoice {
// Validates the given sale invoice existance.
this.validators.validateInvoiceExistance(saleInvoice);
return this.transformer.transform(
const transformed = await this.transformer.transform(
tenantId,
saleInvoice,
new SaleInvoiceTransformer()
);
const eventPayload = {
tenantId,
saleInvoiceId,
};
// Triggers the `onSaleInvoiceItemViewed` event.
await this.eventPublisher.emitAsync(
events.saleInvoice.onViewed,
eventPayload
);
return transformed;
}
}

View File

@@ -6,6 +6,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
import { transformInvoiceToPdfTemplate } from './utils';
import { InvoicePdfTemplateAttributes } from '@/interfaces';
import { SaleInvoicePdfTemplate } from './SaleInvoicePdfTemplate';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Service()
export class SaleInvoicePdf {
@@ -24,6 +26,9 @@ export class SaleInvoicePdf {
@Inject()
private invoiceBrandingTemplateService: SaleInvoicePdfTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve sale invoice pdf content.
* @param {number} tenantId - Tenant Id.
@@ -33,7 +38,9 @@ export class SaleInvoicePdf {
public async saleInvoicePdf(
tenantId: number,
invoiceId: number
): Promise<Buffer> {
): Promise<[Buffer, string]> {
const filename = await this.getInvoicePdfFilename(tenantId, invoiceId);
const brandingAttributes = await this.getInvoiceBrandingAttributes(
tenantId,
invoiceId
@@ -44,7 +51,35 @@ export class SaleInvoicePdf {
brandingAttributes
);
// Converts the given html content to pdf document.
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent);
const buffer = await this.chromiumlyTenancy.convertHtmlContent(
tenantId,
htmlContent
);
const eventPayload = { tenantId, saleInvoiceId: invoiceId };
// Triggers the `onSaleInvoicePdfViewed` event.
await this.eventPublisher.emitAsync(
events.saleInvoice.onPdfViewed,
eventPayload
);
return [buffer, filename];
}
/**
* Retrieves the filename pdf document of the given invoice.
* @param {number} tenantId
* @param {number} invoiceId
* @returns {Promise<string>}
*/
private async getInvoicePdfFilename(
tenantId: number,
invoiceId: number
): Promise<string> {
const { SaleInvoice } = this.tenancy.models(tenantId);
const invoice = await SaleInvoice.query().findById(invoiceId);
return `Invoice-${invoice.invoiceNo}`;
}
/**

View File

@@ -194,7 +194,7 @@ export const defaultInvoicePdfTemplateAttributes = {
// Entries
lineItemLabel: 'Item',
lineDescriptionLabel: 'Description',
lineQuantityLabel: 'Qty',
lineRateLabel: 'Rate',
lineTotalLabel: 'Total',

View File

@@ -6,6 +6,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
import { PaymentReceivedBrandingTemplate } from './PaymentReceivedBrandingTemplate';
import { transformPaymentReceivedToPdfTemplate } from './utils';
import { PaymentReceivedPdfTemplateAttributes } from '@/interfaces';
import events from '@/subscribers/events';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
@Service()
export default class GetPaymentReceivedPdf {
@@ -24,6 +26,9 @@ export default class GetPaymentReceivedPdf {
@Inject()
private paymentBrandingTemplateService: PaymentReceivedBrandingTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve sale invoice pdf content.
* @param {number} tenantId -
@@ -32,19 +37,51 @@ export default class GetPaymentReceivedPdf {
*/
async getPaymentReceivePdf(
tenantId: number,
paymentReceiveId: number
): Promise<Buffer> {
paymentReceivedId: number
): Promise<[Buffer, string]> {
const brandingAttributes = await this.getPaymentBrandingAttributes(
tenantId,
paymentReceiveId
paymentReceivedId
);
const htmlContent = await this.templateInjectable.render(
tenantId,
'modules/payment-receive-standard',
brandingAttributes
);
const filename = await this.getPaymentReceivedFilename(
tenantId,
paymentReceivedId
);
// Converts the given html content to pdf document.
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent);
const content = await this.chromiumlyTenancy.convertHtmlContent(
tenantId,
htmlContent
);
const eventPayload = { tenantId, paymentReceivedId };
// Triggers the `onCreditNotePdfViewed` event.
await this.eventPublisher.emitAsync(
events.paymentReceive.onPdfViewed,
eventPayload
);
return [content, filename];
}
/**
* Retrieves the filename of the given payment.
* @param {number} tenantId
* @param {number} paymentReceivedId
* @returns {Promise<string>}
*/
private async getPaymentReceivedFilename(
tenantId: number,
paymentReceivedId: number
): Promise<string> {
const { PaymentReceive } = this.tenancy.models(tenantId);
const payment = await PaymentReceive.query().findById(paymentReceivedId);
return `Payment-${payment.paymentReceiveNo}`;
}
/**

View File

@@ -6,6 +6,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
import { SaleReceiptBrandingTemplate } from './SaleReceiptBrandingTemplate';
import { transformReceiptToBrandingTemplateAttributes } from './utils';
import { ISaleReceiptBrandingTemplateAttributes } from '@/interfaces';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Service()
export class SaleReceiptsPdf {
@@ -24,6 +26,9 @@ export class SaleReceiptsPdf {
@Inject()
private saleReceiptBrandingTemplate: SaleReceiptBrandingTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieves sale invoice pdf content.
* @param {number} tenantId -
@@ -31,6 +36,8 @@ export class SaleReceiptsPdf {
* @returns {Promise<Buffer>}
*/
public async saleReceiptPdf(tenantId: number, saleReceiptId: number) {
const filename = await this.getSaleReceiptFilename(tenantId, saleReceiptId);
const brandingAttributes = await this.getReceiptBrandingAttributes(
tenantId,
saleReceiptId
@@ -42,7 +49,35 @@ export class SaleReceiptsPdf {
brandingAttributes
);
// Renders the html content to pdf document.
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent);
const content = await this.chromiumlyTenancy.convertHtmlContent(
tenantId,
htmlContent
);
const eventPayload = { tenantId, saleReceiptId };
// Triggers the `onSaleReceiptPdfViewed` event.
await this.eventPublisher.emitAsync(
events.saleReceipt.onPdfViewed,
eventPayload
);
return [content, filename];
}
/**
* Retrieves the filename file document of the given sale receipt.
* @param {number} tenantId
* @param {number} receiptId
* @returns {Promise<string>}
*/
public async getSaleReceiptFilename(
tenantId: number,
receiptId: number
): Promise<string> {
const { SaleReceipt } = this.tenancy.models(tenantId);
const receipt = await SaleReceipt.query().findById(receiptId);
return `Receipt-${receipt.receiptNumber}`;
}
/**

View File

@@ -74,6 +74,9 @@ export default {
* Accounts service.
*/
accounts: {
onViewed: 'onAccountViewed',
onListViewed: 'onAccountsListViewed',
onCreating: 'onAccountCreating',
onCreated: 'onAccountCreated',
@@ -127,6 +130,11 @@ export default {
* Sales invoices service.
*/
saleInvoice: {
onViewed: 'onSaleInvoiceItemViewed',
onListViewed: 'onSaleInvoiceListViewed',
onPdfViewed: 'onSaleInvoicePdfViewed',
onCreate: 'onSaleInvoiceCreate',
onCreating: 'onSaleInvoiceCreating',
onCreated: 'onSaleInvoiceCreated',
@@ -172,6 +180,8 @@ export default {
* Sales estimates service.
*/
saleEstimate: {
onPdfViewed: 'onSaleEstimatePdfViewed',
onCreating: 'onSaleEstimateCreating',
onCreated: 'onSaleEstimateCreated',
@@ -209,6 +219,8 @@ export default {
* Sales receipts service.
*/
saleReceipt: {
onPdfViewed: 'onSaleReceiptPdfViewed',
onCreating: 'onSaleReceiptsCreating',
onCreated: 'onSaleReceiptsCreated',
@@ -236,6 +248,8 @@ export default {
* Payment receipts service.
*/
paymentReceive: {
onPdfViewed: 'onPaymentReceivedPdfViewed',
onCreated: 'onPaymentReceiveCreated',
onCreating: 'onPaymentReceiveCreating',
@@ -338,6 +352,8 @@ export default {
* Items service.
*/
item: {
onViewed: 'onItemViewed',
onCreated: 'onItemCreated',
onCreating: 'onItemCreating',
@@ -456,6 +472,8 @@ export default {
* Credit note service.
*/
creditNote: {
onPdfViewed: 'onCreditNotePdfViewed',
onCreate: 'onCreditNoteCreate',
onCreating: 'onCreditNoteCreating',
onCreated: 'onCreditNoteCreated',
@@ -714,7 +732,7 @@ export default {
// Payment methods integrations
paymentIntegrationLink: {
onPaymentIntegrationLink: 'onPaymentIntegrationLink',
onPaymentIntegrationDeleteLink: 'onPaymentIntegrationDeleteLink'
onPaymentIntegrationDeleteLink: 'onPaymentIntegrationDeleteLink',
},
// Stripe Payment Integration
@@ -731,6 +749,6 @@ export default {
// Stripe Payment Webhooks
stripeWebhooks: {
onCheckoutSessionCompleted: 'onStripeCheckoutSessionCompleted',
onAccountUpdated: 'onStripeAccountUpdated'
}
onAccountUpdated: 'onStripeAccountUpdated',
},
};

View File

@@ -17,6 +17,8 @@
"@casl/ability": "^5.4.3",
"@casl/react": "^2.3.0",
"@craco/craco": "^5.9.0",
"@emotion/css": "^11.13.4",
"@emotion/react": "^11.13.3",
"@reduxjs/toolkit": "^1.2.5",
"@stripe/connect-js": "^3.3.12",
"@stripe/react-connect-js": "^3.3.13",
@@ -48,6 +50,7 @@
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"@welldone-software/why-did-you-render": "^6.0.0-rc.1",
"@xstyled/emotion": "^3.8.1",
"accounting": "^0.4.1",
"axios": "^1.6.0",
"basscss": "^8.0.2",
@@ -124,6 +127,7 @@
"style-loader": "0.23.1",
"styled-components": "^5.3.1",
"stylis-rtlcss": "^2.1.1",
"theme-ui": "^0.16.2",
"typescript": "^4.8.3",
"yup": "^0.28.1"
},

View File

@@ -35,6 +35,7 @@ const OneClickDemoPage = lazy(
const PaymentPortalPage = lazy(
() => import('@/containers/PaymentPortal/PaymentPortalPage'),
);
/**
* App inner.
*/
@@ -59,7 +60,10 @@ function AppInsider({ history }) {
children={<EmailConfirmation />}
/>
<Route path={'/auth'} children={<AuthenticationPage />} />
<Route path={'/payment/:linkId'} children={<PaymentPortalPage />} />
<Route
path={'/payment/:linkId'}
children={<PaymentPortalPage />}
/>
<Route path={'/'} children={<DashboardPrivatePages />} />
</Switch>
</Router>

View File

@@ -1,12 +1,31 @@
// @ts-nocheck
import React, { createContext } from 'react';
const AppIntlContext = createContext();
interface AppIntlContextValue {
currentLocale: string;
direction: 'rtl' | 'ltr';
isRTL: boolean;
isLTR: boolean;
}
const AppIntlContext = createContext<AppIntlContextValue>(
{} as AppIntlContextValue,
);
interface AppIntlProviderProps {
currentLocale: string;
isRTL: boolean;
children: React.ReactNode;
}
/**
* Application intl provider.
*/
function AppIntlProvider({ currentLocale, isRTL, children }) {
function AppIntlProvider({
currentLocale,
isRTL,
children,
}: AppIntlProviderProps) {
const provider = {
currentLocale,
isRTL,
@@ -21,6 +40,7 @@ function AppIntlProvider({ currentLocale, isRTL, children }) {
);
}
const useAppIntlContext = () => React.useContext(AppIntlContext);
const useAppIntlContext = () =>
React.useContext<AppIntlContextValue>(AppIntlContext);
export { AppIntlProvider, useAppIntlContext };

View File

@@ -2,6 +2,7 @@
import React from 'react';
import classnames from 'classnames';
import { LoadingIndicator } from '../Indicator';
import { css } from '@emotion/css';
export function DashboardInsider({
loading,
@@ -9,6 +10,7 @@ export function DashboardInsider({
name,
mount = false,
className,
style
}) {
return (
<div
@@ -17,9 +19,11 @@ export function DashboardInsider({
dashboard__insider: true,
'dashboard__insider--loading': loading,
[`dashboard__insider--${name}`]: !!name,
},
className,
)}
style={style}
>
<LoadingIndicator loading={loading} mount={mount}>
{children}

View File

@@ -1,9 +1,20 @@
// @ts-nocheck
import React from 'react';
import { ThemeProvider, StyleSheetManager } from 'styled-components';
import {
ThemeProvider as StyleComponentsThemeProvider,
StyleSheetManager,
} from 'styled-components';
import rtlcss from 'stylis-rtlcss';
import {
defaultTheme,
ThemeProvider as XStyledEmotionThemeProvider,
} from '@xstyled/emotion';
import { useAppIntlContext } from '../AppIntlProvider';
const theme = {
...defaultTheme,
bpPrefix: 'bp4',
};
interface DashboardThemeProviderProps {
children: React.ReactNode;
}
@@ -17,7 +28,11 @@ export function DashboardThemeProvider({
<StyleSheetManager
{...(direction === 'rtl' ? { stylisPlugins: [rtlcss] } : {})}
>
<ThemeProvider theme={{ dir: direction }}>{children}</ThemeProvider>
<StyleComponentsThemeProvider theme={{ dir: direction }}>
<XStyledEmotionThemeProvider theme={theme}>
{children}
</XStyledEmotionThemeProvider>
</StyleComponentsThemeProvider>
</StyleSheetManager>
);
}

View File

@@ -1,13 +1,15 @@
import React, { forwardRef, Ref } from 'react';
import { HTMLDivProps, Props } from '@blueprintjs/core';
import { SystemProps, x } from '@xstyled/emotion';
export interface BoxProps extends Props, HTMLDivProps {
className?: string;
}
export interface BoxProps
extends SystemProps,
Props,
Omit<HTMLDivProps, 'color'> {}
export const Box = forwardRef(
({ className, ...rest }: BoxProps, ref: Ref<HTMLDivElement>) => {
const Element = 'div';
const Element = x.div;
return <Element className={className} ref={ref} {...rest} />;
},

View File

@@ -1,5 +1,5 @@
import React from 'react';
import styled from 'styled-components';
import { SystemProps } from '@xstyled/emotion';
import { Box } from '../Box';
import { filterFalsyChildren } from './_utils';
@@ -12,7 +12,9 @@ export const GROUP_POSITIONS = {
apart: 'space-between',
};
export interface GroupProps extends React.ComponentPropsWithoutRef<'div'> {
export interface GroupProps
extends SystemProps,
Omit<React.ComponentPropsWithoutRef<'div'>, 'color'> {
/** Defines justify-content property */
position?: GroupPosition;
@@ -27,34 +29,30 @@ export interface GroupProps extends React.ComponentPropsWithoutRef<'div'> {
/** Defines align-items css property */
align?: React.CSSProperties['alignItems'];
flex?: React.CSSProperties['flex'];
}
const defaultProps: Partial<GroupProps> = {
position: 'left',
spacing: 20,
flex: 'none'
};
export function Group({ children, ...props }: GroupProps) {
const groupProps = {
...defaultProps,
...props,
};
export function Group({
position = 'left',
spacing = 20,
align = 'center',
noWrap,
children,
...props
}: GroupProps) {
const filteredChildren = filterFalsyChildren(children);
return <GroupStyled {...groupProps}>{filteredChildren}</GroupStyled>;
return (
<Box
boxSizing={'border-box'}
display={'flex'}
flexDirection={'row'}
alignItems={align}
flexWrap={noWrap ? 'nowrap' : 'wrap'}
justifyContent={GROUP_POSITIONS[position]}
gap={`${spacing}px`}
{...props}
>
{filteredChildren}
</Box>
);
}
const GroupStyled = styled(Box)`
box-sizing: border-box;
display: flex;
flex-direction: row;
flex: ${(props: GroupProps) => (props.flex)};
align-items: ${(props: GroupProps) => (props.align || 'center')};
flex-wrap: ${(props: GroupProps) => (props.noWrap ? 'nowrap' : 'wrap')};
justify-content: ${(props: GroupProps) =>
GROUP_POSITIONS[props.position || 'left']};
gap: ${(props: GroupProps) => props.spacing}px;
`;

View File

@@ -1,8 +1,9 @@
import React from 'react';
import styled from 'styled-components';
import { Box } from '../Box';
import { x, SystemProps } from '@xstyled/emotion';
export interface StackProps extends React.ComponentPropsWithoutRef<'div'> {
export interface StackProps
extends SystemProps,
Omit<React.ComponentPropsWithoutRef<'div'>, 'color'> {
/** Key of theme.spacing or number to set gap in px */
spacing?: number;
@@ -11,30 +12,22 @@ export interface StackProps extends React.ComponentPropsWithoutRef<'div'> {
/** justify-content CSS property */
justify?: React.CSSProperties['justifyContent'];
flex?: React.CSSProperties['flex'];
}
const defaultProps: Partial<StackProps> = {
spacing: 20,
align: 'stretch',
justify: 'top',
flex: 'none',
};
export function Stack(props: StackProps) {
const stackProps = {
...defaultProps,
...props,
};
return <StackStyled {...stackProps} />;
export function Stack({
spacing = 20,
align = 'stretch',
justify = 'top',
...restProps
}: StackProps) {
return (
<x.div
display={'flex'}
flexDirection="column"
justifyContent="justify"
gap={`${spacing}px`}
alignItems={align}
{...restProps}
/>
);
}
const StackStyled = styled(Box)`
display: flex;
flex-direction: column;
align-items: ${(props: StackProps) => props.align};
justify-content: justify;
gap: ${(props: StackProps) => props.spacing}px;
flex: ${(props: StackProps) => props.flex};
`;

View File

@@ -0,0 +1,91 @@
import React, { FC } from 'react';
import clsx from 'classnames';
import { x, SystemProps } from '@xstyled/emotion';
import { css } from '@emotion/css';
import { Group, GroupProps } from '@/components';
interface PageFormProps extends SystemProps {
children: React.ReactNode;
}
/**
* Page form layout.
* @returns {React.ReactNode}
*/
export const PageForm = ({ children, ...props }: PageFormProps) => {
return (
<x.div display="flex" flexDirection={'column'} overflow="hidden" {...props}>
{children}
</x.div>
);
};
PageForm.displayName = 'PageFormBody';
/**
* Page form body layout, by default the content body is scrollable.
* @returns {React.ReactNode}
*/
const PageFormBody: FC<{ children: React.ReactNode } & SystemProps> = ({
children,
...props
}) => {
return (
<x.div flex="1" overflow="auto" {...props}>
{children}
</x.div>
);
};
PageFormBody.displayName = 'PageFormBody';
/**
* Page form footer.
* @returns {React.ReactNode}
*/
const PageFormFooter: FC<{ children: React.ReactNode } & SystemProps> = ({ children }) => {
return <x.div>{children} </x.div>;
};
PageFormFooter.displayName = 'PageFormFooter';
const footerActionsStyle = `
width: 100%;
background: #fff;
padding: 14px 20px;
border-top: 1px solid rgb(210, 221, 226);
box-shadow: 0px -1px 4px 0px rgba(0, 0, 0, 0.05);
.bp4-button-group{
.bp4-button{
&:not(:last-child),
&.bp4-popover-wrapper:not(:last-child) {
border-right: 1px solid rgba(92, 112, 127, 0.3);
margin-right: 0;
&.bp4-intent-primary{
border-right: 1px solid rgba(255, 255, 255, 0.3);
}
}
}
}
`;
const PageFormFooterActions: FC<GroupProps> = ({
children,
className,
...restProps
}) => {
return (
<Group
spacing={20}
{...restProps}
className={clsx(css(footerActionsStyle), className)}
>
{children}
</Group>
);
};
PageFormFooterActions.displayName = 'PageFormFooterActions';
PageForm.Body = PageFormBody;
PageForm.Footer = PageFormFooter;
PageForm.FooterActions = PageFormFooterActions;

View File

@@ -2,3 +2,4 @@
export * from './FormTopbar';
export * from './FormTopbarSelectInputs';
export * from './PageFormBigNumber';
export * from './PageForm';

View File

@@ -1,13 +1,20 @@
// @ts-nocheck
import React from 'react';
import styled from 'styled-components';
import { x, SystemProps } from '@xstyled/emotion';
export function Paper({ children, className }) {
return <PaperRoot className={className}>{children}</PaperRoot>;
interface PaperProps extends SystemProps {
children: React.ReactNode;
}
const PaperRoot = styled.div`
border: 1px solid #d2dce2;
background: #fff;
padding: 10px;
`;
export const Paper = ({ children, ...props }: PaperProps) => {
return (
<x.div
background={'white'}
p={'10px'}
border={'1px solid #d2dce2'}
{...props}
>
{children}
</x.div>
);
};
Paper.displayName = 'Paper';

View File

@@ -1,7 +1,6 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import styled from 'styled-components';
import { CLASSES } from '@/constants/classes';
import { Row, Col, Paper } from '@/components';
@@ -12,7 +11,7 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
export default function MakeJournalFormFooter() {
return (
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<MakeJournalFooterPaper>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<MakeJournalFormFooterLeft />
@@ -23,10 +22,7 @@ export default function MakeJournalFormFooter() {
<MakeJournalFormFooterRight />
</Col>
</Row>
</MakeJournalFooterPaper>
</Paper>
</div>
);
}
const MakeJournalFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -51,8 +51,6 @@ export function BrandingTemplateForm<
const { mutateAsync: editPdfTemplate } = useEditPdfTemplate();
const initialValues = useBrandingTemplateFormInitialValues<T>(defaultValues);
const brandingState = useBrandingState();
const [, setIsLoading] = useState<boolean>(false);
// Uploads the attachments.
@@ -138,7 +136,6 @@ export function BrandingTemplateForm<
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={handleFormSubmit}
brandingState={brandingState || {}}
{...props}
/>
);

View File

@@ -1,6 +1,6 @@
import { Button } from '@blueprintjs/core';
import { Button, ButtonProps } from '@blueprintjs/core';
import styled from 'styled-components';
import { FFormGroup } from '@/components';
import { FFormGroup, Icon } from '@/components';
export const BrandingThemeFormGroup = styled(FFormGroup)`
margin-bottom: 0;
@@ -14,33 +14,21 @@ export const BrandingThemeFormGroup = styled(FFormGroup)`
}
`;
export const BrandingThemeSelectButton = styled(Button)`
position: relative;
padding-right: 26px;
export const BrandingThemeSelectButton = (props: ButtonProps) => {
return (
<Button
text={props?.text || 'Brand Theme'}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
minimal
{...props}
/>
);
};
&::after {
content: '';
display: inline-block;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 5px solid #98a1ae;
position: absolute;
right: -2px;
top: 50%;
margin-top: -2px;
margin-right: 12px;
border-radius: 1px;
}
`;
export const convertBrandingTemplatesToOptions = (brandingTemplates: Array<any>) => {
export const convertBrandingTemplatesToOptions = (
brandingTemplates: Array<any>,
) => {
return brandingTemplates?.map(
(template) =>
({ text: template.template_name, value: template.id } || []),
)
}
(template) => ({ text: template.template_name, value: template.id } || []),
);
};

View File

@@ -11,8 +11,8 @@ import { compose } from '@/utils';
function CreditNotePdfPreviewDialogContent({
subscriptionForm: { creditNoteId },
}) {
const { isLoading, pdfUrl } = usePdfCreditNote(creditNoteId);
const { isLoading, pdfUrl, filename } = usePdfCreditNote(creditNoteId);
return (
<DialogContent>
<div class="dialog__header-actions">
@@ -27,7 +27,7 @@ function CreditNotePdfPreviewDialogContent({
<AnchorButton
href={pdfUrl}
download={'creditNote.pdf'}
download={filename}
minimal={true}
outlined={true}
>

View File

@@ -14,7 +14,7 @@ function EstimatePdfPreviewDialogContent({
// #withDialogActions
closeDialog,
}) {
const { isLoading, pdfUrl } = usePdfEstimate(estimateId);
const { isLoading, pdfUrl, filename } = usePdfEstimate(estimateId);
return (
<DialogContent>
@@ -30,7 +30,7 @@ function EstimatePdfPreviewDialogContent({
<AnchorButton
href={pdfUrl}
download={'estimate.pdf'}
download={filename}
minimal={true}
outlined={true}
>

View File

@@ -13,7 +13,7 @@ function InvoicePdfPreviewDialogContent({
// #withDialog
closeDialog,
}) {
const { isLoading, pdfUrl } = usePdfInvoice(invoiceId);
const { isLoading, pdfUrl, filename } = usePdfInvoice(invoiceId);
return (
<DialogContent>
@@ -29,7 +29,7 @@ function InvoicePdfPreviewDialogContent({
<AnchorButton
href={pdfUrl}
download={'invoice.pdf'}
download={filename}
minimal={true}
outlined={true}
>

View File

@@ -11,7 +11,7 @@ import { compose } from '@/utils';
function PaymentReceivePdfPreviewDialogContent({
subscriptionForm: { paymentReceiveId },
}) {
const { isLoading, pdfUrl } = usePdfPaymentReceive(paymentReceiveId);
const { isLoading, pdfUrl, filename } = usePdfPaymentReceive(paymentReceiveId);
return (
<DialogContent>
@@ -27,7 +27,7 @@ function PaymentReceivePdfPreviewDialogContent({
<AnchorButton
href={pdfUrl}
download={'payment.pdf'}
download={filename}
minimal={true}
outlined={true}
>

View File

@@ -13,7 +13,7 @@ function ReceiptPdfPreviewDialogContent({
// #withDialogActions
closeDialog,
}) {
const { isLoading, pdfUrl } = usePdfReceipt(receiptId);
const { isLoading, pdfUrl, filename } = usePdfReceipt(receiptId);
return (
<DialogContent>
@@ -29,7 +29,7 @@ function ReceiptPdfPreviewDialogContent({
<AnchorButton
href={pdfUrl}
download={'receipt.pdf'}
download={filename}
minimal={true}
outlined={true}
>

View File

@@ -10,6 +10,8 @@ import { ElementCustomizeFields } from './ElementCustomizeFields';
import { ElementCustomizePreview } from './ElementCustomizePreview';
import { extractChildren } from '@/utils/extract-children';
import { ElementPreviewState } from '../BrandingTemplates/types';
import { TabProps } from '@blueprintjs/core';
import { useBrandingState } from '../BrandingTemplates/_utils';
export interface ElementCustomizeProps<T, Y>
extends ElementCustomizeFormProps<T, Y> {
@@ -17,13 +19,13 @@ export interface ElementCustomizeProps<T, Y>
children?: React.ReactNode;
}
export function ElementCustomize<T, Y extends ElementPreviewState>({
initialValues,
validationSchema,
brandingState,
onSubmit,
export interface ElementCustomizeContentProps {
children?: React.ReactNode;
}
export function ElementCustomizeContent({
children,
}: ElementCustomizeProps<T, Y>) {
}: ElementCustomizeContentProps) {
const PaperTemplate = React.useMemo(
() => extractChildren(children, ElementCustomize.PaperTemplate),
[children],
@@ -32,23 +34,34 @@ export function ElementCustomize<T, Y extends ElementPreviewState>({
() => extractChildren(children, ElementCustomize.FieldsTab),
[children],
);
const brandingState = useBrandingState();
const value = { PaperTemplate, CustomizeTabs, brandingState };
return (
<ElementCustomizeTabsControllerProvider>
<ElementCustomizeProvider value={value}>
<Group spacing={0} align="stretch">
<ElementCustomizeFields />
<ElementCustomizePreview />
</Group>
</ElementCustomizeProvider>
</ElementCustomizeTabsControllerProvider>
);
}
export function ElementCustomize<T, Y extends ElementPreviewState>({
initialValues,
validationSchema,
onSubmit,
children,
}: ElementCustomizeProps<T, Y>) {
return (
<ElementCustomizeForm
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={onSubmit}
>
<ElementCustomizeTabsControllerProvider>
<ElementCustomizeProvider value={value}>
<Group spacing={0} align="stretch">
<ElementCustomizeFields />
<ElementCustomizePreview />
</Group>
</ElementCustomizeProvider>
</ElementCustomizeTabsControllerProvider>
{children}
</ElementCustomizeForm>
);
}
@@ -63,16 +76,17 @@ ElementCustomize.PaperTemplate = ({
return <>{children}</>;
};
export interface ElementCustomizeContentProps {
export interface ElementCustomizeFieldsTabProps {
id: string;
label: string;
children?: React.ReactNode;
tabProps?: Partial<TabProps>;
}
ElementCustomize.FieldsTab = ({
id,
label,
children,
}: ElementCustomizeContentProps) => {
}: ElementCustomizeFieldsTabProps) => {
return <>{children}</>;
};

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { Box, Stack } from '@/components';
import { Tab, Tabs } from '@blueprintjs/core';
import { Tab, TabProps, Tabs } from '@blueprintjs/core';
import { ElementCustomizeHeader } from './ElementCustomizeHeader';
import {
ElementCustomizeTabsEnum,
@@ -11,7 +11,6 @@ import styles from './ElementCustomizeTabs.module.scss';
export function ElementCustomizeTabs() {
const { setCurrentTabId } = useElementCustomizeTabsController();
const { CustomizeTabs } = useElementCustomizeContext();
const tabItems = React.Children.map(CustomizeTabs, (node) => ({
@@ -32,9 +31,19 @@ export function ElementCustomizeTabs() {
onChange={handleChange}
className={styles.tabsList}
>
{tabItems?.map(({ id, label }: { id: string; label: string }) => (
<Tab id={id} key={id} title={label} />
))}
{tabItems?.map(
({
id,
label,
tabProps,
}: {
id: string;
label: string;
tabProps?: TabProps;
}) => (
<Tab id={id} key={id} title={label} {...tabProps} />
),
)}
</Tabs>
</Box>
</Stack>

View File

@@ -13,6 +13,9 @@ export function BrandingCompanyLogoUploadField() {
onChange={(file) => {
const imageUrl = file ? URL.createObjectURL(file) : '';
// Reset the logo key since it is changed.
setFieldValue('companyLogoKey', '');
setFieldValue('_companyLogoFile', file);
setFieldValue('companyLogoUri', imageUrl);
}}

View File

@@ -1,7 +1,6 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import styled from 'styled-components';
import { CLASSES } from '@/constants/classes';
import { Row, Col, Paper } from '@/components';
@@ -12,7 +11,7 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
export default function ExpenseFormFooter() {
return (
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<ExpensesFooterPaper>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<ExpenseFormFooterLeft />
@@ -23,11 +22,7 @@ export default function ExpenseFormFooter() {
<ExpenseFormFooterRight />
</Col>
</Row>
</ExpensesFooterPaper>
</Paper>
</div>
);
}
const ExpensesFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -110,7 +110,7 @@ export function StripePaymentMethod() {
</Menu>
}
>
<Button small icon={<MoreIcon size={16} />} />
<Button small icon={<MoreIcon height={10} width={10} />} />
</Popover>
)}
</Group>

View File

@@ -13,7 +13,7 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
export default function BillFormFooter() {
return (
<div class={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<BillFooterPaper>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<BillFormFooterLeft />
@@ -24,11 +24,7 @@ export default function BillFormFooter() {
<BillFormFooterRight />
</Col>
</Row>
</BillFooterPaper>
</Paper>
</div>
);
}
const BillFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -15,7 +15,7 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
export default function VendorCreditNoteFormFooter() {
return (
<div class={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<VendorCreditNoteFooterPaper>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<VendorCreditNoteFormFooterLeft />
@@ -26,11 +26,7 @@ export default function VendorCreditNoteFormFooter() {
<VendorCreditNoteFormFooterRight />
</Col>
</Row>
</VendorCreditNoteFooterPaper>
</Paper>
</div>
);
}
const VendorCreditNoteFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -15,7 +15,7 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
export default function PaymentMadeFooter() {
return (
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<PaymentReceiveFooterPaper>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<PaymentMadeFormFooterLeft />
@@ -26,11 +26,7 @@ export default function PaymentMadeFooter() {
<PaymentMadeFormFooterRight />
</Col>
</Row>
</PaymentReceiveFooterPaper>
</Paper>
</div>
);
}
const PaymentReceiveFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -1,14 +1,21 @@
import { useFormikContext } from 'formik';
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
import {
ElementCustomize,
ElementCustomizeContent,
} from '../../../ElementCustomize/ElementCustomize';
import { CreditNoteCustomizeGeneralField } from './CreditNoteCustomizeGeneralFields';
import { CreditNoteCustomizeContentFields } from './CreditNoteCutomizeContentFields';
import { CreditNotePaperTemplate, CreditNotePaperTemplateProps } from './CreditNotePaperTemplate';
import {
CreditNotePaperTemplate,
CreditNotePaperTemplateProps,
} from './CreditNotePaperTemplate';
import { CreditNoteBrandingState, CreditNoteCustomizeValues } from './types';
import { initialValues } from './constants';
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
import { useDrawerActions } from '@/hooks/state';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
import { useIsTemplateNamedFilled } from '@/containers/BrandingTemplates/utils';
export function CreditNoteCustomizeContent() {
const { payload, name } = useDrawerContext();
@@ -27,6 +34,16 @@ export function CreditNoteCustomizeContent() {
defaultValues={initialValues}
onSuccess={handleSuccess}
>
<CreditNoteCustomizeFormContent />
</BrandingTemplateForm>
);
}
function CreditNoteCustomizeFormContent() {
const isTemplateNameFilled = useIsTemplateNamedFilled();
return (
<ElementCustomizeContent>
<ElementCustomize.PaperTemplate>
<CreditNotePaperTemplateFormConnected />
</ElementCustomize.PaperTemplate>
@@ -35,10 +52,14 @@ export function CreditNoteCustomizeContent() {
<CreditNoteCustomizeGeneralField />
</ElementCustomize.FieldsTab>
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
<ElementCustomize.FieldsTab
id={'content'}
label={'Content'}
tabProps={{ disabled: !isTemplateNameFilled }}
>
<CreditNoteCustomizeContentFields />
</ElementCustomize.FieldsTab>
</BrandingTemplateForm>
</ElementCustomizeContent>
);
}
@@ -46,7 +67,10 @@ function CreditNotePaperTemplateFormConnected() {
const { values } = useFormikContext<CreditNoteCustomizeValues>();
const { brandingState } = useElementCustomizeContext();
const mergedProps: CreditNotePaperTemplateProps = { ...brandingState, ...values };
const mergedProps: CreditNotePaperTemplateProps = {
...brandingState,
...values,
};
return <CreditNotePaperTemplate {...mergedProps} />;
}

View File

@@ -1,3 +1,4 @@
import { Classes, Text } from '@blueprintjs/core';
import { Box, Group, Stack } from '@/components';
import {
PaperTemplate,
@@ -67,6 +68,12 @@ export interface CreditNotePaperTemplateProps extends PaperTemplateProps {
creditNoteNumebr?: string;
creditNoteNumberLabel?: string;
showCreditNoteNumber?: boolean;
// Entries
lineItemLabel?: string;
lineQuantityLabel?: string;
lineRateLabel?: string;
lineTotalLabel?: string;
}
export function CreditNotePaperTemplate({
@@ -127,6 +134,12 @@ export function CreditNotePaperTemplate({
creditNoteDate = 'September 3, 2024',
showCreditNoteDate = true,
creditNoteDateLabel = 'Credit Note Date',
// Entries
lineItemLabel = 'Item',
lineQuantityLabel = 'Qty',
lineRateLabel = 'Rate',
lineTotalLabel = 'Total',
}: CreditNotePaperTemplateProps) {
return (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
@@ -172,10 +185,23 @@ export function CreditNotePaperTemplate({
<Stack spacing={0}>
<PaperTemplate.Table
columns={[
{ label: 'Item', accessor: 'item' },
{ label: 'Description', accessor: 'description' },
{ label: 'Rate', accessor: 'rate', align: 'right' },
{ label: 'Total', accessor: 'total', align: 'right' },
{
label: lineItemLabel,
accessor: (data) => (
<Stack spacing={2}>
<Text>{data.item}</Text>
<Text
className={Classes.TEXT_MUTED}
style={{ fontSize: 12 }}
>
{data.description}
</Text>
</Stack>
),
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
]}
data={lines}
/>

View File

@@ -12,21 +12,30 @@ import {
Menu,
MenuItem,
} from '@blueprintjs/core';
import { If, Icon, FormattedMessage as T, Group, FSelect } from '@/components';
import { CLASSES } from '@/constants/classes';
import classNames from 'classnames';
import {
If,
Icon,
FormattedMessage as T,
Group,
FSelect,
PageForm,
} from '@/components';
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { useCreditNoteFormBrandingTemplatesOptions } from './utils';
import { MoreIcon } from '@/icons/More';
import { useDrawerActions } from '@/hooks/state';
import { DRAWERS } from '@/constants/drawers';
/**
* Credit note floating actions.
*/
export default function CreditNoteFloatingActions() {
const history = useHistory();
const { openDrawer } = useDrawerActions();
// Formik context.
const { resetForm, submitForm, isSubmitting } = useFormikContext();
@@ -79,143 +88,169 @@ export default function CreditNoteFloatingActions() {
resetForm();
};
// Handles the credit note customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'CreditNote' });
};
const brandingTemplatesOptions = useCreditNoteFormBrandingTemplatesOptions();
return (
<Group
spacing={10}
className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}
>
{/* ----------- Save And Open ----------- */}
<If condition={!creditNote || !creditNote?.is_open}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitOpenBtnClick}
text={<T id={'save_open'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'open_and_new'} />}
onClick={handleSubmitOpenAndNewBtnClick}
/>
<MenuItem
text={<T id={'open_continue_editing'} />}
onClick={handleSubmitOpenContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<PageForm.FooterActions position={'apart'} spacing={20}>
<Group spacing={10}>
{/* ----------- Save And Open ----------- */}
<If condition={!creditNote || !creditNote?.is_open}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
onClick={handleSubmitOpenBtnClick}
text={<T id={'save_open'} />}
/>
</Popover>
</ButtonGroup>
{/* ----------- Save As Draft ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
className={'ml1'}
onClick={handleSubmitDraftBtnClick}
text={<T id={'save_as_draft'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'open_and_new'} />}
onClick={handleSubmitOpenAndNewBtnClick}
/>
<MenuItem
text={<T id={'open_continue_editing'} />}
onClick={handleSubmitOpenContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
{/* ----------- Save As Draft ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
className={'ml1'}
onClick={handleSubmitDraftBtnClick}
text={<T id={'save_as_draft'} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save and New ----------- */}
<If condition={creditNote && creditNote?.is_open}>
<ButtonGroup>
<Button
loading={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitOpenBtnClick}
style={{ minWidth: '85px' }}
text={<T id={'save'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitOpenAndNewBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save and New ----------- */}
<If condition={creditNote && creditNote?.is_open}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
onClick={handleSubmitOpenBtnClick}
style={{ minWidth: '85px' }}
text={<T id={'save'} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={creditNote ? <T id={'reset'} /> : <T id={'clear'} />}
/>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitOpenAndNewBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={creditNote ? <T id={'reset'} /> : <T id={'clear'} />}
/>
</BrandingThemeFormGroup>
</Group>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
</Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>
{/* ----------- Setting Select ----------- */}
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
}

View File

@@ -1,12 +1,12 @@
// @ts-nocheck
import React from 'react';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { useHistory } from 'react-router-dom';
import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core';
import { defaultTo, isEmpty } from 'lodash';
import { CLASSES } from '@/constants/classes';
import { css } from '@emotion/css';
import {
CreateCreditNoteFormSchema,
EditCreditNoteFormSchema,
@@ -42,6 +42,7 @@ import {
CreditNoteExchangeRateSync,
CreditNoteSyncIncrementSettingsToForm,
} from './components';
import { PageForm } from '@/components/PageForm';
/**
* Credit note form.
@@ -148,36 +149,42 @@ function CreditNoteForm({
};
return (
<div
className={classNames(
CLASSES.PAGE_FORM,
CLASSES.PAGE_FORM_STRIP_STYLE,
CLASSES.PAGE_FORM_CREDIT_NOTE,
)}
<Formik
validationSchema={
isNewMode ? CreateCreditNoteFormSchema : EditCreditNoteFormSchema
}
initialValues={initialValues}
onSubmit={handleFormSubmit}
>
<Formik
validationSchema={
isNewMode ? CreateCreditNoteFormSchema : EditCreditNoteFormSchema
}
initialValues={initialValues}
onSubmit={handleFormSubmit}
<Form
className={css({
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
flex: 1,
})}
>
<Form>
<CreditNoteFormTopBar />
<CreditNoteFormHeader />
<CreditNoteItemsEntriesEditorField />
<CreditNoteFormFooter />
<CreditNoteFloatingActions />
<PageForm flex="1">
<PageForm.Body>
<CreditNoteFormTopBar />
<CreditNoteFormHeader />
<CreditNoteItemsEntriesEditorField />
<CreditNoteFormFooter />
</PageForm.Body>
{/*-------- Dialogs --------*/}
<CreditNoteFormDialogs />
<PageForm.Footer>
<CreditNoteFloatingActions />
</PageForm.Footer>
</PageForm>
{/*-------- Effects --------*/}
<CreditNoteSyncIncrementSettingsToForm />
<CreditNoteExchangeRateSync />
</Form>
</Formik>
</div>
{/*-------- Dialogs --------*/}
<CreditNoteFormDialogs />
{/*-------- Effects --------*/}
<CreditNoteSyncIncrementSettingsToForm />
<CreditNoteExchangeRateSync />
</Form>
</Formik>
);
}
export default compose(

View File

@@ -1,10 +1,7 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import styled from 'styled-components';
import { CLASSES } from '@/constants/classes';
import { Row, Col, Paper } from '@/components';
import { Row, Col, Paper, Stack } from '@/components';
import { CreditNoteFormFooterLeft } from './CreditNoteFormFooterLeft';
import { CreditNoteFormFooterRight } from './CreditNoteFormFooterRight';
import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmentButton';
@@ -14,8 +11,8 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
*/
export default function CreditNoteFormFooter() {
return (
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<CreditNoteFooterPaper>
<Stack mt={'20px'} px={'32px'} pb={'20px'} flex={1}>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<CreditNoteFormFooterLeft />
@@ -26,10 +23,7 @@ export default function CreditNoteFormFooter() {
<CreditNoteFormFooterRight />
</Col>
</Row>
</CreditNoteFooterPaper>
</div>
</Paper>
</Stack>
);
}
const CreditNoteFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -1,23 +1,28 @@
// @ts-nocheck
import React from 'react';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { useFormikContext } from 'formik';
import { CLASSES } from '@/constants/classes';
import CreditNoteFormHeaderFields from './CreditNoteFormHeaderFields';
import { getEntriesTotal } from '@/containers/Entries/utils';
import { PageFormBigNumber } from '@/components';
import { Group, PageFormBigNumber } from '@/components';
/**
* Credit note header.
*/
function CreditNoteFormHeader() {
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
<Group
position="apart"
align={'flex-start'}
display="flex"
bg="white"
p="25px 32px"
borderBottom="1px solid #d2dce2"
>
<CreditNoteFormHeaderFields />
<CreditNoteFormBigNumber />
</div>
</Group>
);
}

View File

@@ -5,6 +5,8 @@ import styled from 'styled-components';
import { FormGroup, InputGroup, Position } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { FastField, ErrorMessage, useFormikContext } from 'formik';
import { css } from '@emotion/css';
import { useTheme } from '@emotion/react';
import { CLASSES } from '@/constants/classes';
import {
@@ -14,26 +16,41 @@ import {
CustomerDrawerLink,
FFormGroup,
CustomersSelect,
Stack,
FDateInput,
} from '@/components';
import { customerNameFieldShouldUpdate } from './utils';
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
import { CreditNoteExchangeRateInputField } from './components';
import { CreditNoteTransactionNoField } from './CreditNoteTransactionNoField';
import {
momentFormatter,
tansformDateValue,
inputIntent,
handleDateChange,
} from '@/utils';
import { useCustomerUpdateExRate } from '@/containers/Entries/withExRateItemEntriesPriceRecalc';
const getCreditNoteFieldsStyle = (theme: Theme) => css`
.${theme.bpPrefix}-form-group {
margin-bottom: 0;
&.${theme.bpPrefix}-inline {
max-width: 450px;
}
.${theme.bpPrefix}-label {
min-width: 150px;
}
.${theme.bpPrefix}-form-content {
width: 100%;
}
}
`;
/**
* Credit note form header fields.
*/
export default function CreditNoteFormHeaderFields({}) {
export default function CreditNoteFormHeaderFields() {
const theme = useTheme();
const styleClassName = getCreditNoteFieldsStyle(theme);
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
<Stack spacing={18} flex={1} className={styleClassName}>
{/* ----------- Customer name ----------- */}
<CreditNoteCustomersSelect />
@@ -41,48 +58,35 @@ export default function CreditNoteFormHeaderFields({}) {
<CreditNoteExchangeRateInputField />
{/* ----------- Credit note date ----------- */}
<FastField name={'credit_note_date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'credit_note.label_credit_note_date'} />}
inline={true}
labelInfo={<FieldRequiredHint />}
className={classNames('form-group--credit_note_date', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="credit_note_date" />}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
value={tansformDateValue(value)}
onChange={handleDateChange((formattedDate) => {
form.setFieldValue('credit_note_date', formattedDate);
})}
popoverProps={{ position: Position.BOTTOM_LEFT, minimal: true }}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
}}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'credit_note_date'}
label={<T id={'credit_note.label_credit_note_date'} />}
labelInfo={<FieldRequiredHint />}
inline
fastField
>
<FDateInput
name={'credit_note_date'}
formatDate={(date) => date.toLocaleDateString()}
parseDate={(str) => new Date(str)}
popoverProps={{ position: Position.BOTTOM_LEFT, minimal: true }}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
fill: true
}}
fill
fastField
/>
</FFormGroup>
{/* ----------- Credit note # ----------- */}
<CreditNoteTransactionNoField />
{/* ----------- Reference ----------- */}
<FastField name={'reference_no'}>
{({ field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reference_no'} />}
inline={true}
className={classNames('form-group--reference', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="reference_no" />}
>
<InputGroup minimal={true} {...field} />
</FormGroup>
)}
</FastField>
</div>
<FormGroup label={<T id={'reference_no'} />} name={'reference_no'} inline>
<InputGroup name={'reference_no'} minimal />
</FormGroup>
</Stack>
);
}

View File

@@ -1,12 +1,14 @@
// @ts-nocheck
import React from 'react';
import { useParams } from 'react-router-dom';
import '@/style/pages/CreditNote/PageForm.scss';
import { css } from '@emotion/css';
import CreditNoteForm from './CreditNoteForm';
import { CreditNoteFormProvider } from './CreditNoteFormProvider';
import {
CreditNoteFormProvider,
useCreditNoteFormContext,
} from './CreditNoteFormProvider';
import { AutoExchangeRateProvider } from '@/containers/Entries/AutoExchangeProvider';
import { DashboardInsider } from '@/components';
/**
* Credit note form page.
@@ -18,8 +20,24 @@ export default function CreditNoteFormPage() {
return (
<CreditNoteFormProvider creditNoteId={idAsInteger}>
<AutoExchangeRateProvider>
<CreditNoteForm />
<CreditNoteFormPageContent />
</AutoExchangeRateProvider>
</CreditNoteFormProvider>
);
}
function CreditNoteFormPageContent() {
const { isBootLoading } = useCreditNoteFormContext();
return (
<DashboardInsider
loading={isBootLoading}
className={css`
min-height: calc(100vh - var(--top-offset));
max-height: calc(100vh - var(--top-offset));
`}
>
<CreditNoteForm />
</DashboardInsider>
);
}

View File

@@ -113,6 +113,13 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
})
: [];
const isBootLoading =
isItemsLoading ||
isCustomersLoading ||
isCreditNoteLoading ||
isInvoiceLoading ||
isBrandingTemplatesLoading;
// Provider payload.
const provider = {
items,
@@ -141,20 +148,11 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
// Credit note state
creditNoteState,
isCreditNoteStateLoading,
isBootLoading,
};
const isLoading =
isItemsLoading ||
isCustomersLoading ||
isCreditNoteLoading ||
isInvoiceLoading ||
isBrandingTemplatesLoading;
return (
<DashboardInsider loading={isLoading} name={'credit-note-form'}>
<CreditNoteFormContext.Provider value={provider} {...props} />
</DashboardInsider>
);
return <CreditNoteFormContext.Provider value={provider} {...props} />;
}
const useCreditNoteFormContext = () =>

View File

@@ -1,11 +1,10 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import { FastField } from 'formik';
import { CLASSES } from '@/constants/classes';
import ItemsEntriesTable from '@/containers/Entries/ItemsEntriesTable';
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
import { entriesFieldShouldUpdate } from './utils';
import { Box } from '@/components';
/**
* Credit note items entries editor field.
@@ -14,7 +13,7 @@ export default function CreditNoteItemsEntriesEditorField() {
const { items } = useCreditNoteFormContext();
return (
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
<Box p="18px 32px 0">
<FastField
name={'entries'}
items={items}
@@ -38,6 +37,6 @@ export default function CreditNoteItemsEntriesEditorField() {
/>
)}
</FastField>
</div>
</Box>
);
}

View File

@@ -1,14 +1,21 @@
import { useFormikContext } from 'formik';
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
import {
ElementCustomize,
ElementCustomizeContent,
} from '../../../ElementCustomize/ElementCustomize';
import { EstimateCustomizeGeneralField } from './EstimateCustomizeFieldsGeneral';
import { EstimateCustomizeContentFields } from './EstimateCustomizeFieldsContent';
import { EstimatePaperTemplate, EstimatePaperTemplateProps } from './EstimatePaperTemplate';
import {
EstimatePaperTemplate,
EstimatePaperTemplateProps,
} from './EstimatePaperTemplate';
import { EstimateBrandingState, EstimateCustomizeValues } from './types';
import { initialValues } from './constants';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
import { useDrawerActions } from '@/hooks/state';
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
import { useIsTemplateNamedFilled } from '@/containers/BrandingTemplates/utils';
export function EstimateCustomizeContent() {
const { payload, name } = useDrawerContext();
@@ -26,6 +33,16 @@ export function EstimateCustomizeContent() {
onSuccess={handleSuccess}
resource={'SaleEstimate'}
>
<EstimateCustomizeFormContent />
</BrandingTemplateForm>
);
}
function EstimateCustomizeFormContent() {
const isTemplateNameFilled = useIsTemplateNamedFilled();
return (
<ElementCustomizeContent>
<ElementCustomize.PaperTemplate>
<EstimatePaperTemplateFormConnected />
</ElementCustomize.PaperTemplate>
@@ -34,10 +51,14 @@ export function EstimateCustomizeContent() {
<EstimateCustomizeGeneralField />
</ElementCustomize.FieldsTab>
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
<ElementCustomize.FieldsTab
id={'content'}
label={'Content'}
tabProps={{ disabled: !isTemplateNameFilled }}
>
<EstimateCustomizeContentFields />
</ElementCustomize.FieldsTab>
</BrandingTemplateForm>
</ElementCustomizeContent>
);
}
@@ -47,9 +68,12 @@ export function EstimateCustomizeContent() {
*/
function EstimatePaperTemplateFormConnected() {
const { values } = useFormikContext<EstimateCustomizeValues>();
const { brandingState } = useElementCustomizeContext()
const { brandingState } = useElementCustomizeContext();
const mergedProps: EstimatePaperTemplateProps = { ...brandingState, ...values, }
const mergedProps: EstimatePaperTemplateProps = {
...brandingState,
...values,
};
return <EstimatePaperTemplate {...mergedProps} />;
}

View File

@@ -1,3 +1,4 @@
import { Classes, Text } from '@blueprintjs/core';
import { Box, Group, Stack } from '@/components';
import {
PaperTemplate,
@@ -69,6 +70,13 @@ export interface EstimatePaperTemplateProps extends PaperTemplateProps {
quantity: string;
total: string;
}>;
// Lines
lineItemLabel?: string,
lineQuantityLabel?: string,
lineRateLabel?: string,
lineTotalLabel?: string,
}
export function EstimatePaperTemplate({
@@ -134,6 +142,13 @@ export function EstimatePaperTemplate({
expirationDateLabel = 'Expiration Date',
showExpirationDate = true,
expirationDate = 'September 3, 2024',
// Entries
lineItemLabel = 'Item',
lineQuantityLabel = 'Qty',
lineRateLabel = 'Rate',
lineTotalLabel = 'Total',
}: EstimatePaperTemplateProps) {
return (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
@@ -183,10 +198,23 @@ export function EstimatePaperTemplate({
<Stack spacing={0}>
<PaperTemplate.Table
columns={[
{ label: 'Item', accessor: 'item' },
{ label: 'Description', accessor: 'description' },
{ label: 'Rate', accessor: 'rate', align: 'right' },
{ label: 'Total', accessor: 'total', align: 'right' },
{
label: lineItemLabel,
accessor: (data) => (
<Stack spacing={2}>
<Text>{data.item}</Text>
<Text
className={Classes.TEXT_MUTED}
style={{ fontSize: 12 }}
>
{data.description}
</Text>
</Stack>
),
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
]}
data={lines}
/>

View File

@@ -1,6 +1,5 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import {
Intent,
Button,
@@ -12,21 +11,25 @@ import {
MenuItem,
} from '@blueprintjs/core';
import { If, Icon, FormattedMessage as T, Group, FSelect } from '@/components';
import { CLASSES } from '@/constants/classes';
import { useHistory } from 'react-router-dom';
import { useFormikContext } from 'formik';
import { useEstimateFormContext } from './EstimateFormProvider';
import { useEstimateFormBrandingTemplatesOptions } from './utils';
import { useDrawerActions } from '@/hooks/state';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { PageForm } from '@/components/PageForm';
import { MoreIcon } from '@/icons/More';
import { DRAWERS } from '@/constants/drawers';
/**
* Estimate floating actions bar.
*/
export default function EstimateFloatingActions() {
const history = useHistory();
const { openDrawer } = useDrawerActions();
const { resetForm, submitForm, isSubmitting } = useFormikContext();
// Estimate form context.
@@ -78,147 +81,173 @@ export default function EstimateFloatingActions() {
resetForm();
};
// Handles the invoice customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'SaleEstimate' });
};
const brandingTemplatesOptions = useEstimateFormBrandingTemplatesOptions();
return (
<Group
spacing={10}
className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}
>
{/* ----------- Save And Deliver ----------- */}
<If condition={!estimate || !estimate?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitDeliverBtnClick}
text={<T id={'save_and_deliver'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'deliver_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
<MenuItem
text={<T id={'deliver_continue_editing'} />}
onClick={handleSubmitDeliverContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<PageForm.FooterActions position={'apart'} spacing={10}>
<Group spacing={10}>
{/* ----------- Save And Deliver ----------- */}
<If condition={!estimate || !estimate?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitDeliverBtnClick}
text={<T id={'save_and_deliver'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'deliver_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
<MenuItem
text={<T id={'deliver_continue_editing'} />}
onClick={handleSubmitDeliverContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
{/* ----------- Save As Draft ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
className={'ml1'}
onClick={handleSubmitDraftBtnClick}
text={<T id={'save_as_draft'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save and New ----------- */}
<If condition={estimate && estimate?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
onClick={handleSubmitDeliverBtnClick}
style={{ minWidth: '85px' }}
text={<T id={'save'} />}
/>
</Popover>
</ButtonGroup>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save As Draft ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
className={'ml1'}
onClick={handleSubmitDraftBtnClick}
text={<T id={'save_as_draft'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save and New ----------- */}
<If condition={estimate && estimate?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitDeliverBtnClick}
style={{ minWidth: '85px' }}
text={<T id={'save'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={estimate ? <T id={'reset'} /> : <T id={'clear'} />}
/>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={estimate ? <T id={'reset'} /> : <T id={'clear'} />}
/>
</BrandingThemeFormGroup>
</Group>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
</Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>
{/* ----------- More Select ----------- */}
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
}

View File

@@ -1,11 +1,10 @@
// @ts-nocheck
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { css } from '@emotion/css';
import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core';
import { sumBy, isEmpty, defaultTo } from 'lodash';
import { useHistory } from 'react-router-dom';
import { CLASSES } from '@/constants/classes';
import {
CreateEstimateFormSchema,
@@ -36,8 +35,9 @@ import {
handleErrors,
resetFormState,
} from './utils';
import { PageForm } from '@/components/PageForm';
/**
/**6
* Estimate form.
*/
function EstimateForm({
@@ -148,36 +148,42 @@ function EstimateForm({
};
return (
<div
className={classNames(
CLASSES.PAGE_FORM,
CLASSES.PAGE_FORM_STRIP_STYLE,
CLASSES.PAGE_FORM_ESTIMATE,
)}
<Formik
validationSchema={
isNewMode ? CreateEstimateFormSchema : EditEstimateFormSchema
}
initialValues={initialValues}
onSubmit={handleFormSubmit}
>
<Formik
validationSchema={
isNewMode ? CreateEstimateFormSchema : EditEstimateFormSchema
}
initialValues={initialValues}
onSubmit={handleFormSubmit}
<Form
className={css({
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
flex: 1
})}
>
<Form>
<EstimtaeFormTopBar />
<EstimateFormHeader />
<EstimateItemsEntriesField />
<EstimateFormFooter />
<EstimateFloatingActions />
<PageForm flex={1}>
<PageForm.Body>
<EstimtaeFormTopBar />
<EstimateFormHeader />
<EstimateItemsEntriesField />
<EstimateFormFooter />
</PageForm.Body>
{/*------- Dialogs -------*/}
<EstimateFormDialogs />
<PageForm.Footer>
<EstimateFloatingActions />
</PageForm.Footer>
</PageForm>
{/*------- Effects -------*/}
<EstimateIncrementSyncSettingsToForm />
<EstimateSyncAutoExRateToForm />
</Form>
</Formik>
</div>
{/*------- Dialogs -------*/}
<EstimateFormDialogs />
{/*------- Effects -------*/}
<EstimateIncrementSyncSettingsToForm />
<EstimateSyncAutoExRateToForm />
</Form>
</Formik>
);
}

View File

@@ -1,9 +1,7 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import styled from 'styled-components';
import { x } from '@xstyled/emotion';
import { CLASSES } from '@/constants/classes';
import { Row, Col, Paper } from '@/components';
import { EstimateFormFooterLeft } from './EstimateFormFooterLeft';
import { EstimateFormFooterRight } from './EstimateFormFooterRight';
@@ -14,8 +12,8 @@ import { UploadAttachmentButton } from '@/containers/Attachments/UploadAttachmen
*/
export default function EstiamteFormFooter() {
return (
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<EstimateFooterPaper>
<x.div mt={'20px'} px={'32px'} pb={'20px'} flex={1}>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<EstimateFormFooterLeft />
@@ -26,11 +24,7 @@ export default function EstiamteFormFooter() {
<EstimateFormFooterRight />
</Col>
</Row>
</EstimateFooterPaper>
</div>
</Paper>
</x.div>
);
}
const EstimateFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -1,22 +1,26 @@
// @ts-nocheck
import React, { useMemo } from 'react';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { useFormikContext } from 'formik';
import { CLASSES } from '@/constants/classes';
import { x } from '@xstyled/emotion';
import EstimateFormHeaderFields from './EstimateFormHeaderFields';
import { getEntriesTotal } from '@/containers/Entries/utils';
import { PageFormBigNumber } from '@/components';
import { Group, PageFormBigNumber } from '@/components';
// Estimate form top header.
function EstimateFormHeader() {
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
<Group
position="apart"
align={'flex-start'}
bg="white"
p="25px 32px"
borderBottom="1px solid #d2dce2"
>
<EstimateFormHeaderFields />
<EstimateFormBigTotal />
</div>
</Group>
);
}

View File

@@ -1,10 +1,9 @@
// @ts-nocheck
import styled from 'styled-components';
import classNames from 'classnames';
import { FormGroup, InputGroup, Position, Classes } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { FastField, ErrorMessage, useFormikContext } from 'formik';
import { Position, Classes } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
import { css } from '@emotion/css';
import {
FeatureCan,
FFormGroup,
@@ -13,15 +12,11 @@ import {
Icon,
CustomerDrawerLink,
CustomersSelect,
FInputGroup,
Stack,
FDateInput,
} from '@/components';
import {
momentFormatter,
tansformDateValue,
inputIntent,
handleDateChange,
} from '@/utils';
import { customersFieldShouldUpdate } from './utils';
import { CLASSES } from '@/constants/classes';
import { Features } from '@/constants';
import { ProjectsSelect } from '@/containers/Projects/components';
import {
@@ -31,15 +26,36 @@ import {
import { EstimateFormEstimateNumberField } from './EstimateFormEstimateNumberField';
import { useEstimateFormContext } from './EstimateFormProvider';
import { useCustomerUpdateExRate } from '@/containers/Entries/withExRateItemEntriesPriceRecalc';
import { useTheme } from '@emotion/react';
import { Theme } from '@xstyled/emotion';
const getEstimateFieldsStyle = (theme: Theme) => css`
.${theme.bpPrefix}-form-group {
margin-bottom: 0;
&.${theme.bpPrefix}-inline {
max-width: 470px;
}
.${theme.bpPrefix}-label {
min-width: 160px;
font-weight: 500;
}
.${theme.bpPrefix}-form-content {
width: 100%;
}
}
`;
/**
* Estimate form header.
*/
export default function EstimateFormHeader() {
const theme = useTheme();
const { projects } = useEstimateFormContext();
const styleClassName = getEstimateFieldsStyle(theme);
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
<Stack spacing={18} flex={1} className={styleClassName}>
{/* ----------- Customer name ----------- */}
<EstimateFormCustomerSelect />
@@ -47,78 +63,55 @@ export default function EstimateFormHeader() {
<EstimateExchangeRateInputField />
{/* ----------- Estimate Date ----------- */}
<FastField name={'estimate_date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'estimate_date'} />}
inline={true}
labelInfo={<FieldRequiredHint />}
className={classNames(CLASSES.FILL, 'form-group--estimate-date')}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="estimate_date" />}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
value={tansformDateValue(value)}
onChange={handleDateChange((formattedDate) => {
form.setFieldValue('estimate_date', formattedDate);
})}
popoverProps={{ position: Position.BOTTOM, minimal: true }}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
}}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'estimate_date'}
label={<T id={'estimate_date'} />}
labelInfo={<FieldRequiredHint />}
inline
fastField
>
<FDateInput
name={'estimate_date'}
formatDate={(date) => date.toLocaleDateString()}
parseDate={(str) => new Date(str)}
popoverProps={{ position: Position.BOTTOM_LEFT, minimal: true }}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
fill: true,
}}
fill
fastField
/>
</FFormGroup>
{/* ----------- Expiration date ----------- */}
<FastField name={'expiration_date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'expiration_date'} />}
labelInfo={<FieldRequiredHint />}
inline={true}
className={classNames(
CLASSES.FORM_GROUP_LIST_SELECT,
CLASSES.FILL,
'form-group--expiration-date',
)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="expiration_date" />}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
value={tansformDateValue(value)}
onChange={handleDateChange((formattedDate) => {
form.setFieldValue('expiration_date', formattedDate);
})}
popoverProps={{ position: Position.BOTTOM, minimal: true }}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
}}
/>
</FormGroup>
)}
</FastField>
<FFormGroup
name={'expiration_date'}
label={<T id={'expiration_date'} />}
inline
fastField
>
<FDateInput
name={'expiration_date'}
formatDate={(date) => date.toLocaleDateString()}
parseDate={(str) => new Date(str)}
popoverProps={{ position: Position.BOTTOM_LEFT, minimal: true }}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
fill: true,
}}
fill
fastField
/>
</FFormGroup>
{/* ----------- Estimate number ----------- */}
<EstimateFormEstimateNumberField />
{/* ----------- Reference ----------- */}
<FastField name={'reference'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reference'} />}
inline={true}
className={classNames('form-group--reference', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="reference" />}
>
<InputGroup minimal={true} {...field} />
</FormGroup>
)}
</FastField>
<FFormGroup name={'reference'} label={<T id={'reference'} />} inline fill>
<FInputGroup name={'reference'} minimal={true} />
</FFormGroup>
{/*------------ Project name -----------*/}
<FeatureCan feature={Features.Projects}>
@@ -136,7 +129,7 @@ export default function EstimateFormHeader() {
/>
</FFormGroup>
</FeatureCan>
</div>
</Stack>
);
}

View File

@@ -1,12 +1,15 @@
// @ts-nocheck
import React from 'react';
import { useParams } from 'react-router-dom';
import '@/style/pages/SaleEstimate/PageForm.scss';
import { css } from '@emotion/css';
import EstimateForm from './EstimateForm';
import { EstimateFormProvider } from './EstimateFormProvider';
import {
EstimateFormProvider,
useEstimateFormContext,
} from './EstimateFormProvider';
import { AutoExchangeRateProvider } from '@/containers/Entries/AutoExchangeProvider';
import { DashboardInsider } from '@/components';
/**
* Estimate form page.
@@ -18,8 +21,24 @@ export default function EstimateFormPage() {
return (
<EstimateFormProvider estimateId={idInteger}>
<AutoExchangeRateProvider>
<EstimateForm />
<EstimateFormPageContent />
</AutoExchangeRateProvider>
</EstimateFormProvider>
);
}
export function EstimateFormPageContent() {
const { isBootLoading } = useEstimateFormContext();
return (
<DashboardInsider
loading={isBootLoading}
className={css`
min-height: calc(100vh - var(--top-offset));
max-height: calc(100vh - var(--top-offset));
`}
>
<EstimateForm />
</DashboardInsider>
);
}

View File

@@ -103,6 +103,13 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
const isFeatureLoading =
isWarehouesLoading || isBranchesLoading || isProjectsLoading;
const isBootLoading =
isCustomersLoading ||
isItemsLoading ||
isEstimateLoading ||
isBrandingTemplatesLoading ||
isSaleEstimateStateLoading;
// Provider payload.
const provider = {
estimateId,
@@ -136,20 +143,11 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
// Estimate state
saleEstimateState,
isSaleEstimateStateLoading,
isBootLoading,
};
const isLoading =
isCustomersLoading ||
isItemsLoading ||
isEstimateLoading ||
isBrandingTemplatesLoading ||
isSaleEstimateStateLoading;
return (
<DashboardInsider loading={isLoading} name={'estimate-form'}>
<EstimateFormContext.Provider value={provider} {...props} />
</DashboardInsider>
);
return <EstimateFormContext.Provider value={provider} {...props} />;
}
const useEstimateFormContext = () =>

View File

@@ -1,8 +1,7 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import { x } from '@xstyled/emotion';
import { FastField } from 'formik';
import { CLASSES } from '@/constants/classes';
import ItemsEntriesTable from '@/containers/Entries/ItemsEntriesTable';
import { useEstimateFormContext } from './EstimateFormProvider';
import { entriesFieldShouldUpdate } from './utils';
@@ -14,7 +13,7 @@ export default function EstimateFormItemsEntriesField() {
const { items } = useEstimateFormContext();
return (
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
<x.div p="18px 32px 0">
<FastField
name={'entries'}
items={items}
@@ -38,6 +37,6 @@ export default function EstimateFormItemsEntriesField() {
/>
)}
</FastField>
</div>
</x.div>
);
}

View File

@@ -5,7 +5,10 @@ import {
InvoicePaperTemplate,
InvoicePaperTemplateProps,
} from './InvoicePaperTemplate';
import { ElementCustomize } from '../../../ElementCustomize/ElementCustomize';
import {
ElementCustomize,
ElementCustomizeContent,
} from '../../../ElementCustomize/ElementCustomize';
import { InvoiceCustomizeGeneralField } from './InvoiceCustomizeGeneralFields';
import { InvoiceCustomizeContentFields } from './InvoiceCutomizeContentFields';
import { InvoiceCustomizeFormValues, InvoiceCustomizeState } from './types';
@@ -13,11 +16,13 @@ import { InvoiceCustomizeSchema } from './InvoiceCustomizeForm.schema';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
import { useDrawerActions } from '@/hooks/state';
import { BrandingTemplateForm } from '@/containers/BrandingTemplates/BrandingTemplateForm';
import { initialValues } from './constants';
import { useElementCustomizeContext } from '@/containers/ElementCustomize/ElementCustomizeProvider';
import { initialValues } from './constants';
import { useIsTemplateNamedFilled } from '@/containers/BrandingTemplates/utils';
/**
* Invoice branding template customize.
* @return {JSX.Element}
*/
export function InvoiceCustomizeContent() {
const { payload, name } = useDrawerContext();
@@ -36,6 +41,20 @@ export function InvoiceCustomizeContent() {
onSuccess={handleSuccess}
resource={'SaleInvoice'}
>
<InvoiceCustomizeFormContent />
</BrandingTemplateForm>
);
}
/**
* Invoice branding template customize preview and fields.
* @returns {JSX.Element}
*/
function InvoiceCustomizeFormContent() {
const isTemplateNameFilled = useIsTemplateNamedFilled();
return (
<ElementCustomizeContent>
<ElementCustomize.PaperTemplate>
<InvoicePaperTemplateFormConnected />
</ElementCustomize.PaperTemplate>
@@ -44,16 +63,20 @@ export function InvoiceCustomizeContent() {
<InvoiceCustomizeGeneralField />
</ElementCustomize.FieldsTab>
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
<ElementCustomize.FieldsTab
id={'content'}
label={'Content'}
tabProps={{ disabled: !isTemplateNameFilled }}
>
<InvoiceCustomizeContentFields />
</ElementCustomize.FieldsTab>
</BrandingTemplateForm>
</ElementCustomizeContent>
);
}
/**
* Injects the `InvoicePaperTemplate` component props from the form and branding states.
* @param Component
* @param Component
* @returns {JSX.Element}
*/
const withInvoicePreviewTemplateProps = <P extends object>(
@@ -61,13 +84,17 @@ const withInvoicePreviewTemplateProps = <P extends object>(
) => {
return (props: Omit<P, keyof InvoicePaperTemplateProps>) => {
const { values } = useFormikContext<InvoiceCustomizeFormValues>();
const { brandingState, } = useElementCustomizeContext();
const { brandingState } = useElementCustomizeContext();
const mergedProps: InvoicePaperTemplateProps = { ...brandingState, ...values };
const mergedProps: InvoicePaperTemplateProps = {
...brandingState,
...values,
};
return <Component {...(props as P)} {...mergedProps} />;
};
};
export const InvoicePaperTemplateFormConnected =
R.compose(withInvoicePreviewTemplateProps)(InvoicePaperTemplate);
export const InvoicePaperTemplateFormConnected = R.compose(
withInvoicePreviewTemplateProps,
)(InvoicePaperTemplate);

View File

@@ -4,7 +4,7 @@
background-color: #fff;
color: #111;
box-shadow: inset 0 4px 0px 0 var(--invoice-primary-color), 0 10px 15px rgba(0, 0, 0, 0.05);
padding: 24px 30px;
padding: 30px 30px;
font-size: 12px;
position: relative;
margin: 0 auto;
@@ -12,7 +12,7 @@
height: 1123px;
}
.bigTitle{
font-size: 60px;
font-size: 30px;
margin: 0;
line-height: 1;
font-weight: 500;
@@ -105,7 +105,10 @@
overflow: hidden;
img{
max-width: 100%;
width: 100%;
height: 100%;
max-width: 260px;
max-height: 100px;
}
}
.logoImg {

View File

@@ -1,4 +1,4 @@
import React from 'react';
import { Classes, Text } from '@blueprintjs/core';
import { PaperTemplate, PaperTemplateTotalBorder } from './PaperTemplate';
import { Box, Group, Stack } from '@/components';
import {
@@ -9,6 +9,7 @@ import {
DefaultPdfTemplateAddressBilledTo,
DefaultPdfTemplateAddressBilledFrom,
} from '@/constants/PdfTemplates';
interface PapaerLine {
item?: string;
description?: string;
@@ -55,7 +56,7 @@ export interface InvoicePaperTemplateProps {
// Entries
lineItemLabel?: string;
lineDescriptionLabel?: string;
lineQuantityLabel?: string;
lineRateLabel?: string;
lineTotalLabel?: string;
@@ -129,7 +130,7 @@ export function InvoicePaperTemplate({
// Entries
lineItemLabel = 'Item',
lineDescriptionLabel = 'Description',
lineQuantityLabel = 'Qty',
lineRateLabel = 'Rate',
lineTotalLabel = 'Total',
@@ -214,7 +215,6 @@ export function InvoicePaperTemplate({
<Box dangerouslySetInnerHTML={{ __html: companyAddress }} />
</PaperTemplate.Address>
)}
{showCustomerAddress && (
<PaperTemplate.Address>
<strong>{billedToLabel}</strong>
@@ -226,8 +226,21 @@ export function InvoicePaperTemplate({
<Stack spacing={0}>
<PaperTemplate.Table
columns={[
{ label: lineItemLabel, accessor: 'item' },
{ label: lineDescriptionLabel, accessor: 'description' },
{
label: lineItemLabel,
accessor: (data) => (
<Stack spacing={2}>
<Text>{data.item}</Text>
<Text
className={Classes.TEXT_MUTED}
style={{ fontSize: 12 }}
>
{data.description}
</Text>
</Stack>
),
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
]}

View File

@@ -1,7 +1,7 @@
import React from 'react';
import clsx from 'classnames';
import { get } from 'lodash';
import { Box, Group, GroupProps, Stack } from '@/components';
import { get, isFunction } from 'lodash';
import { Box, Group, GroupProps } from '@/components';
import styles from './InvoicePaperTemplate.module.scss';
export interface PaperTemplateProps {
@@ -26,8 +26,9 @@ export function PaperTemplate({
interface PaperTemplateTableProps {
columns: Array<{
accessor: string;
accessor: string | ((data: Record<string, any>) => JSX.Element);
label: string;
value?: JSX.Element;
align?: 'left' | 'center' | 'right';
}>;
data: Array<Record<string, any>>;
@@ -71,7 +72,9 @@ PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => {
<tr>
{columns.map((column, index) => (
<td align={column.align} key={index}>
{get(_data, column.accessor)}
{isFunction(column?.accessor)
? column?.accessor(_data)
: get(_data, column.accessor)}
</td>
))}
</tr>
@@ -115,9 +118,9 @@ PaperTemplate.TotalLine = ({
);
};
PaperTemplate.MutedText = () => {};
PaperTemplate.MutedText = () => { };
PaperTemplate.Text = () => {};
PaperTemplate.Text = () => { };
PaperTemplate.AddressesGroup = (props: GroupProps) => {
return (

View File

@@ -1,5 +1,5 @@
// @ts-nocheck
import React, { useMemo } from 'react';
import React from 'react';
import {
Intent,
Button,
@@ -11,22 +11,25 @@ import {
MenuItem,
} from '@blueprintjs/core';
import { useHistory } from 'react-router-dom';
import classNames from 'classnames';
import { useFormikContext } from 'formik';
import { CLASSES } from '@/constants/classes';
import { If, Icon, FormattedMessage as T, Group, FSelect } from '@/components';
import { useInvoiceFormContext } from './InvoiceFormProvider';
import { useInvoiceFormBrandingTemplatesOptions } from './utils';
import { useDrawerActions } from '@/hooks/state';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { PageForm } from '@/components/PageForm';
import { MoreIcon } from '@/icons/More';
import { DRAWERS } from '@/constants/drawers';
/**
* Invoice floating actions bar.
*/
export default function InvoiceFloatingActions() {
const history = useHistory();
const { openDrawer } = useDrawerActions();
// Formik context.
const { resetForm, submitForm, isSubmitting } = useFormikContext();
@@ -80,145 +83,171 @@ export default function InvoiceFloatingActions() {
resetForm();
};
// Handles the invoice customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'SaleInvoice' });
};
const brandingTemplatesOptions = useInvoiceFormBrandingTemplatesOptions();
return (
<Group
spacing={10}
className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}
>
{/* ----------- Save And Deliver ----------- */}
<If condition={!invoice || !invoice?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitDeliverBtnClick}
text={<T id={'save_and_deliver'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'deliver_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
<MenuItem
text={<T id={'deliver_continue_editing'} />}
onClick={handleSubmitDeliverContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<PageForm.FooterActions spacing={10} position={'apart'}>
<Group spacing={10}>
{/* ----------- Save And Deliver ----------- */}
<If condition={!invoice || !invoice?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
onClick={handleSubmitDeliverBtnClick}
text={<T id={'save_and_deliver'} />}
/>
</Popover>
</ButtonGroup>
{/* ----------- Save As Draft ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
className={'ml1'}
onClick={handleSubmitDraftBtnClick}
text={<T id={'save_as_draft'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'deliver_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
<MenuItem
text={<T id={'deliver_continue_editing'} />}
onClick={handleSubmitDeliverContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
{/* ----------- Save As Draft ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
className={'ml1'}
onClick={handleSubmitDraftBtnClick}
text={<T id={'save_as_draft'} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save and New ----------- */}
<If condition={invoice && invoice?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
onClick={handleSubmitDeliverBtnClick}
style={{ minWidth: '85px' }}
text={<T id={'save'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Save and New ----------- */}
<If condition={invoice && invoice?.is_delivered}>
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
onClick={handleSubmitDeliverBtnClick}
style={{ minWidth: '85px' }}
text={<T id={'save'} />}
/>
</Popover>
</ButtonGroup>
</If>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDeliverAndNewBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
</If>
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={invoice ? <T id={'reset'} /> : <T id={'clear'} />}
/>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={invoice ? <T id={'reset'} /> : <T id={'clear'} />}
/>
</BrandingThemeFormGroup>
</Group>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
</Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOptions}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} />
)}
filterable={false}
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</Group>
</PageForm.FooterActions>
);
}

View File

@@ -1,12 +1,11 @@
// @ts-nocheck
import React from 'react';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core';
import { sumBy, isEmpty, defaultTo } from 'lodash';
import { useHistory } from 'react-router-dom';
import { CLASSES } from '@/constants/classes';
import { css } from '@emotion/css';
import {
getCreateInvoiceFormSchema,
getEditInvoiceFormSchema,
@@ -23,7 +22,7 @@ import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
import withSettings from '@/containers/Settings/withSettings';
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
import { AppToaster } from '@/components';
import { AppToaster, Box } from '@/components';
import { compose, orderingLinesIndexes, transactionNumber } from '@/utils';
import { useInvoiceFormContext } from './InvoiceFormProvider';
import { InvoiceFormActions } from './InvoiceFormActions';
@@ -34,12 +33,16 @@ import {
transformValueToRequest,
resetFormState,
} from './utils';
import { InvoiceExchangeRateSync, InvoiceNoSyncSettingsToForm } from './components';
import {
InvoiceExchangeRateSync,
InvoiceNoSyncSettingsToForm,
} from './components';
import { PageForm } from '@/components/PageForm';
/**
* Invoice form.
*/
function InvoiceForm({
function InvoiceFormRoot({
// #withSettings
invoiceNextNumber,
invoiceNumberPrefix,
@@ -61,7 +64,7 @@ function InvoiceForm({
createInvoiceMutate,
editInvoiceMutate,
submitPayload,
saleInvoiceState
saleInvoiceState,
} = useInvoiceFormContext();
// Invoice number.
@@ -156,30 +159,36 @@ function InvoiceForm({
const EditInvoiceFormSchema = getEditInvoiceFormSchema();
return (
<div
className={classNames(
CLASSES.PAGE_FORM,
CLASSES.PAGE_FORM_STRIP_STYLE,
CLASSES.PAGE_FORM_INVOICE,
)}
<Formik
validationSchema={
isNewMode ? CreateInvoiceFormSchema : EditInvoiceFormSchema
}
initialValues={initialValues}
onSubmit={handleSubmit}
>
<Formik
validationSchema={
isNewMode ? CreateInvoiceFormSchema : EditInvoiceFormSchema
}
initialValues={initialValues}
onSubmit={handleSubmit}
<Form
className={css({
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
flex: 1,
})}
>
<Form>
<InvoiceFormTopBar />
<InvoiceFormHeader />
<PageForm flex={1}>
<PageForm.Body>
<InvoiceFormTopBar />
<InvoiceFormHeader />
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
<InvoiceFormActions />
<InvoiceItemsEntriesEditorField />
</div>
<InvoiceFormFooter />
<InvoiceFloatingActions />
<Box p="18px 32px 0">
<InvoiceFormActions />
<InvoiceItemsEntriesEditorField />
</Box>
<InvoiceFormFooter />
</PageForm.Body>
<PageForm.Footer>
<InvoiceFloatingActions />
</PageForm.Footer>
{/*---------- Dialogs ----------*/}
<InvoiceFormDialogs />
@@ -187,13 +196,13 @@ function InvoiceForm({
{/*---------- Effects ----------*/}
<InvoiceNoSyncSettingsToForm />
<InvoiceExchangeRateSync />
</Form>
</Formik>
</div>
</PageForm>
</Form>
</Formik>
);
}
export default compose(
export const InvoiceForm = compose(
withDashboardActions,
withSettings(({ invoiceSettings }) => ({
invoiceNextNumber: invoiceSettings?.nextNumber,
@@ -203,4 +212,4 @@ export default compose(
invoiceTermsConditions: invoiceSettings?.termsConditions,
})),
withCurrentOrganization(),
)(InvoiceForm);
)(InvoiceFormRoot);

View File

@@ -1,18 +1,16 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import styled from 'styled-components';
import { x } from '@xstyled/emotion';
import { CLASSES } from '@/constants/classes';
import { Paper, Row, Col } from '@/components';
import { Row, Col, Paper } from '@/components';
import { InvoiceFormFooterLeft } from './InvoiceFormFooterLeft';
import { InvoiceFormFooterRight } from './InvoiceFormFooterRight';
import { UploadAttachmentButton } from '../../../Attachments/UploadAttachmentButton';
export default function InvoiceFormFooter() {
return (
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
<InvoiceFooterPaper>
<x.div mt={'20px'} px={'32px'} pb={'20px'} flex={1}>
<Paper p={'20px'}>
<Row>
<Col md={8}>
<InvoiceFormFooterLeft />
@@ -23,11 +21,7 @@ export default function InvoiceFormFooter() {
<InvoiceFormFooterRight />
</Col>
</Row>
</InvoiceFooterPaper>
</div>
</Paper>
</x.div>
);
}
const InvoiceFooterPaper = styled(Paper)`
padding: 20px;
`;

View File

@@ -1,13 +1,9 @@
// @ts-nocheck
import React from 'react';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { useFormikContext } from 'formik';
import { Group, PageFormBigNumber } from '@/components';
import InvoiceFormHeaderFields from './InvoiceFormHeaderFields';
import { CLASSES } from '@/constants/classes';
import { PageFormBigNumber } from '@/components';
import { useInvoiceDueAmount } from './utils';
/**
@@ -15,10 +11,16 @@ import { useInvoiceDueAmount } from './utils';
*/
function InvoiceFormHeader() {
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
<Group
position="apart"
align={'flex-start'}
bg="white"
p="25px 32px"
borderBottom="1px solid #d2dce2"
>
<InvoiceFormHeaderFields />
<InvoiceFormBigTotal />
</div>
</Group>
);
}

View File

@@ -2,30 +2,27 @@
import React from 'react';
import styled from 'styled-components';
import classNames from 'classnames';
import { FormGroup, InputGroup, Position, Classes } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { FastField, ErrorMessage, useFormikContext } from 'formik';
import { Position, Classes } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
import { css } from '@emotion/css';
import { Theme, useTheme } from '@emotion/react';
import {
FFormGroup,
FormattedMessage as T,
Col,
Row,
CustomerDrawerLink,
FieldRequiredHint,
FeatureCan,
CustomersSelect,
Stack,
FInputGroup,
Icon,
FDateInput,
} from '@/components';
import {
momentFormatter,
tansformDateValue,
inputIntent,
handleDateChange,
} from '@/utils';
import { CLASSES } from '@/constants/classes';
import { customerNameFieldShouldUpdate } from './utils';
import { useInvoiceFormContext } from './InvoiceFormProvider';
import { useCustomerUpdateExRate } from '@/containers/Entries/withExRateItemEntriesPriceRecalc';
import {
InvoiceExchangeRateInputField,
InvoiceProjectSelectButton,
@@ -36,99 +33,99 @@ import {
ProjectBillableEntriesLink,
} from '@/containers/Projects/components';
import { Features } from '@/constants';
import { useCustomerUpdateExRate } from '@/containers/Entries/withExRateItemEntriesPriceRecalc';
const getInvoiceFieldsStyle = (theme: Theme) => css`
.${theme.bpPrefix}-form-group {
margin-bottom: 0;
&.${theme.bpPrefix}-inline {
max-width: 450px;
}
.${theme.bpPrefix}-label {
min-width: 150px;
font-weight: 500;
}
.${theme.bpPrefix}-form-content {
width: 100%;
}
}
`;
/**
* Invoice form header fields.
*/
export default function InvoiceFormHeaderFields() {
// Invoice form context.
const theme = useTheme();
const { projects } = useInvoiceFormContext();
const { values } = useFormikContext();
const invoiceFieldsClassName = getInvoiceFieldsStyle(theme);
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
<Stack spacing={18} flex={1} className={invoiceFieldsClassName}>
{/* ----------- Customer name ----------- */}
<InvoiceFormCustomerSelect />
{/* ----------- Exchange rate ----------- */}
<InvoiceExchangeRateInputField />
<Row>
<Col xs={6}>
{/* ----------- Invoice date ----------- */}
<FastField name={'invoice_date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'invoice_date'} />}
inline={true}
labelInfo={<FieldRequiredHint />}
className={classNames('form-group--invoice-date', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="invoice_date" />}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
value={tansformDateValue(value)}
onChange={handleDateChange((formattedDate) => {
form.setFieldValue('invoice_date', formattedDate);
})}
popoverProps={{
position: Position.BOTTOM_LEFT,
minimal: true,
}}
/>
</FormGroup>
)}
</FastField>
</Col>
{/* ----------- Invoice date ----------- */}
<FFormGroup
name={'invoice_date'}
label={<T id={'invoice_date'} />}
labelInfo={<FieldRequiredHint />}
inline
fastField
>
<FDateInput
name={'invoice_date'}
formatDate={(date) => date.toLocaleDateString()}
parseDate={(str) => new Date(str)}
popoverProps={{
position: Position.BOTTOM_LEFT,
minimal: true,
fill: true,
}}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
}}
fill
fastField
/>
</FFormGroup>
<Col xs={6}>
{/* ----------- Due date ----------- */}
<FastField name={'due_date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'due_date'} />}
labelInfo={<FieldRequiredHint />}
inline={true}
className={classNames('form-group--due-date', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="due_date" />}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
value={tansformDateValue(value)}
onChange={handleDateChange((formattedDate) => {
form.setFieldValue('due_date', formattedDate);
})}
popoverProps={{
position: Position.BOTTOM_LEFT,
minimal: true,
}}
/>
</FormGroup>
)}
</FastField>
</Col>
</Row>
{/* ----------- Due date ----------- */}
<FFormGroup
name={'due_date'}
label={<T id={'due_date'} />}
labelInfo={<FieldRequiredHint />}
inline
fastField
>
<FDateInput
name={'due_date'}
formatDate={(date) => date.toLocaleDateString()}
parseDate={(str) => new Date(str)}
popoverProps={{
position: Position.BOTTOM_LEFT,
minimal: true,
fill: true,
}}
inputProps={{
leftIcon: <Icon icon={'date-range'} />,
fill: true,
}}
fill
fastField
/>
</FFormGroup>
{/* ----------- Invoice number ----------- */}
<InvoiceFormInvoiceNumberField />
{/* ----------- Reference ----------- */}
<FastField name={'reference_no'}>
{({ field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'reference'} />}
inline={true}
className={classNames('form-group--reference', CLASSES.FILL)}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="reference_no" />}
>
<InputGroup minimal={true} {...field} />
</FormGroup>
)}
</FastField>
<FFormGroup name={'reference_no'} label={<T id={'reference'} />} inline>
<FInputGroup name={'reference_no'} minimal={true} />
</FFormGroup>
{/*------------ Project name -----------*/}
<FeatureCan feature={Features.Projects}>
@@ -151,7 +148,7 @@ export default function InvoiceFormHeaderFields() {
)}
</FFormGroup>
</FeatureCan>
</div>
</Stack>
);
}

View File

@@ -1,25 +1,43 @@
// @ts-nocheck
import React from 'react';
import { useParams } from 'react-router-dom';
import '@/style/pages/SaleInvoice/PageForm.scss';
import InvoiceForm from './InvoiceForm';
import { InvoiceFormProvider } from './InvoiceFormProvider';
import { css } from '@emotion/css';
import { InvoiceForm } from './InvoiceForm';
import {
InvoiceFormProvider,
useInvoiceFormContext,
} from './InvoiceFormProvider';
import { AutoExchangeRateProvider } from '@/containers/Entries/AutoExchangeProvider';
import { DashboardInsider } from '@/components';
/**
* Invoice form page.
*/
export default function InvoiceFormPage() {
const { id } = useParams();
const idAsInteger = parseInt(id, 10);
const invoiceId = parseInt(id, 10);
return (
<InvoiceFormProvider invoiceId={idAsInteger}>
<InvoiceFormProvider invoiceId={invoiceId}>
<AutoExchangeRateProvider>
<InvoiceForm />
<InvoiceFormPageContent />
</AutoExchangeRateProvider>
</InvoiceFormProvider>
);
}
function InvoiceFormPageContent() {
const { isBootLoading } = useInvoiceFormContext();
return (
<DashboardInsider
loading={isBootLoading}
className={css`
min-height: calc(100vh - var(--top-offset));
max-height: calc(100vh - var(--top-offset));
`}
>
<InvoiceForm />
</DashboardInsider>
);
}

View File

@@ -132,6 +132,14 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
isProjectsLoading ||
isBrandingTemplatesLoading;
const isBootLoading =
isInvoiceLoading ||
isItemsLoading ||
isCustomersLoading ||
isEstimateLoading ||
isSettingsLoading ||
isInvoiceStateLoading;
const provider = {
invoice,
items,
@@ -170,21 +178,11 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
// Invoice state
saleInvoiceState,
isInvoiceStateLoading,
isBootLoading,
};
const isLoading =
isInvoiceLoading ||
isItemsLoading ||
isCustomersLoading ||
isEstimateLoading ||
isSettingsLoading ||
isInvoiceStateLoading;
return (
<DashboardInsider loading={isLoading} name={'invoice-form'}>
<InvoiceFormContext.Provider value={provider} {...props} />
</DashboardInsider>
);
return <InvoiceFormContext.Provider value={provider} {...props} />;
}
const useInvoiceFormContext = () =>

View File

@@ -1,6 +1,7 @@
// @ts-nocheck
import React from 'react';
import { FastField } from 'formik';
import { x } from '@xstyled/emotion';
import ItemsEntriesTable from '@/containers/Entries/ItemsEntriesTable';
import { useInvoiceFormContext } from './InvoiceFormProvider';
import { entriesFieldShouldUpdate } from './utils';

View File

@@ -1,6 +1,5 @@
// @ts-nocheck
import React from 'react';
import classNames from 'classnames';
import {
Intent,
Button,
@@ -12,15 +11,18 @@ import {
MenuItem,
} from '@blueprintjs/core';
import { useHistory } from 'react-router-dom';
import { FSelect, Group, Icon, FormattedMessage as T } from '@/components';
import { useFormikContext } from 'formik';
import { FSelect, Group, Icon, FormattedMessage as T } from '@/components';
import { useDrawerActions } from '@/hooks/state';
import { usePaymentReceiveFormContext } from './PaymentReceiveFormProvider';
import { CLASSES } from '@/constants/classes';
import {
BrandingThemeFormGroup,
BrandingThemeSelectButton,
} from '@/containers/BrandingTemplates/BrandingTemplatesSelectFields';
import { usePaymentReceivedFormBrandingTemplatesOptions } from './utils';
import { PageForm } from '@/components/PageForm';
import { MoreIcon } from '@/icons/More';
import { DRAWERS } from '@/constants/drawers';
/**
* Payment receive floating actions bar.
@@ -35,6 +37,8 @@ export default function PaymentReceiveFormFloatingActions() {
// History context.
const history = useHistory();
const { openDrawer } = useDrawerActions();
// Handle submit button click.
const handleSubmitBtnClick = (event) => {
setSubmitPayload({ redirect: true });
@@ -58,84 +62,109 @@ export default function PaymentReceiveFormFloatingActions() {
submitForm();
};
// Handles the invoice customize button click.
const handleCustomizeBtnClick = () => {
openDrawer(DRAWERS.BRANDING_TEMPLATES, { resource: 'PaymentReceive' });
};
const brandingTemplatesOpts =
usePaymentReceivedFormBrandingTemplatesOptions();
return (
<Group
spacing={10}
className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}
>
{/* ----------- Save and New ----------- */}
<ButtonGroup>
<PageForm.FooterActions position={'apart'} spacing={20}>
<Group spacing={10}>
{/* ----------- Save and New ----------- */}
<ButtonGroup>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
type="submit"
onClick={handleSubmitBtnClick}
style={{ minWidth: '85px' }}
text={!isNewMode ? <T id={'edit'} /> : <T id={'save'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitAndNewClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitContinueEditingBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
</ButtonGroup>
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
type="submit"
onClick={handleSubmitBtnClick}
style={{ minWidth: '85px' }}
text={!isNewMode ? <T id={'edit'} /> : <T id={'save'} />}
onClick={handleClearBtnClick}
text={!isNewMode ? <T id={'reset'} /> : <T id={'clear'} />}
/>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
</Group>
<Group spacing={0}>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOpts}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>
{/* ----------- Setting Select ----------- */}
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.TOP_RIGHT}
modifiers={{
offset: { offset: '0, 4' },
}}
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitAndNewClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitContinueEditingBtnClick}
text={'Customize Templates'}
onClick={handleCustomizeBtnClick}
/>
</Menu>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
disabled={isSubmitting}
intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
<Button minimal icon={<MoreIcon height={'14px'} width={'14px'} />} />
</Popover>
</ButtonGroup>
{/* ----------- Clear & Reset----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleClearBtnClick}
text={!isNewMode ? <T id={'reset'} /> : <T id={'clear'} />}
/>
{/* ----------- Cancel ----------- */}
<Button
className={'ml1'}
disabled={isSubmitting}
onClick={handleCancelBtnClick}
text={<T id={'cancel'} />}
/>
{/* ----------- Branding Template Select ----------- */}
<BrandingThemeFormGroup
name={'pdf_template_id'}
label={'Branding'}
inline
fastField
style={{ marginLeft: 20 }}
>
<FSelect
name={'pdf_template_id'}
items={brandingTemplatesOpts}
input={({ activeItem, text, label, value }) => (
<BrandingThemeSelectButton text={text || 'Brand Theme'} minimal />
)}
filterable={false}
popoverProps={{ minimal: true }}
/>
</BrandingThemeFormGroup>
</Group>
</Group>
</PageForm.FooterActions>
);
}

View File

@@ -1,15 +1,12 @@
// @ts-nocheck
import React, { useMemo } from 'react';
import React from 'react';
import { isEmpty, defaultTo } from 'lodash';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { Formik, Form } from 'formik';
import { useHistory } from 'react-router-dom';
import { Intent } from '@blueprintjs/core';
import { css } from '@emotion/css';
import '@/style/pages/PaymentReceive/PageForm.scss';
import { CLASSES } from '@/constants/classes';
import PaymentReceiveHeader from './PaymentReceiveFormHeader';
import PaymentReceiveFormBody from './PaymentReceiveFormBody';
import PaymentReceiveFloatingActions from './PaymentReceiveFloatingActions';
@@ -40,11 +37,12 @@ import {
getExceededAmountFromValues,
} from './utils';
import { PaymentReceiveSyncIncrementSettingsToForm } from './components';
import { PageForm } from '@/components/PageForm';
/**
* Payment Receive form.
*/
function PaymentReceiveForm({
function PaymentReceiveFormRoot({
// #withSettings
preferredDepositAccount,
paymentReceiveNextNumber,
@@ -159,30 +157,37 @@ function PaymentReceiveForm({
return createPaymentReceiveMutate(form).then(onSaved).catch(onError);
}
};
return (
<div
className={classNames(
CLASSES.PAGE_FORM,
CLASSES.PAGE_FORM_STRIP_STYLE,
CLASSES.PAGE_FORM_PAYMENT_RECEIVE,
)}
<Formik
initialValues={initialValues}
onSubmit={handleSubmitForm}
validationSchema={
isNewMode
? CreatePaymentReceiveFormSchema
: EditPaymentReceiveFormSchema
}
>
<Formik
initialValues={initialValues}
onSubmit={handleSubmitForm}
validationSchema={
isNewMode
? CreatePaymentReceiveFormSchema
: EditPaymentReceiveFormSchema
}
<Form
className={css({
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
flex: 1,
})}
>
<Form>
<PageForm flex={1}>
<PaymentReceiveInnerProvider>
<PaymentReceiveFormTopBar />
<PaymentReceiveHeader />
<PaymentReceiveFormBody />
<PaymentReceiveFormFooter />
<PaymentReceiveFloatingActions />
<PageForm.Body>
<PaymentReceiveFormTopBar />
<PaymentReceiveHeader />
<PaymentReceiveFormBody />
<PaymentReceiveFormFooter />
</PageForm.Body>
<PageForm.Footer>
<PaymentReceiveFloatingActions />
</PageForm.Footer>
{/* ------- Effects ------- */}
<PaymentReceiveSyncIncrementSettingsToForm />
@@ -191,13 +196,13 @@ function PaymentReceiveForm({
<PaymentReceiveFormAlerts />
<PaymentReceiveFormDialogs />
</PaymentReceiveInnerProvider>
</Form>
</Formik>
</div>
</PageForm>
</Form>
</Formik>
);
}
export default compose(
export const PaymentReceivedForm = compose(
withSettings(({ paymentReceiveSettings }) => ({
paymentReceiveSettings,
paymentReceiveNextNumber: paymentReceiveSettings?.nextNumber,
@@ -207,4 +212,4 @@ export default compose(
})),
withCurrentOrganization(),
withDialogActions,
)(PaymentReceiveForm);
)(PaymentReceiveFormRoot);

View File

@@ -2,15 +2,14 @@
import React from 'react';
import { FastField } from 'formik';
import PaymentReceiveItemsTable from './PaymentReceiveItemsTable';
import classNames from 'classnames';
import { CLASSES } from '@/constants/classes';
import { Box } from '@/components';
/**
* Payment Receive form body.
*/
export default function PaymentReceiveFormBody() {
return (
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
<Box p="18px 32px 0">
<FastField name={'entries'}>
{({ form: { values, setFieldValue }, field: { value } }) => (
<PaymentReceiveItemsTable
@@ -22,6 +21,6 @@ export default function PaymentReceiveFormBody() {
/>
)}
</FastField>
</div>
</Box>
);
}

Some files were not shown because too many files have changed in this diff Show More