Merge pull request #21 from bigcapitalhq/BIG-263-optimize-sales-print-templates

`Big 263` optimize sales print templates
This commit is contained in:
Ahmed Bouhuolia
2022-01-11 17:25:44 +02:00
committed by GitHub
11 changed files with 238 additions and 5 deletions

View File

@@ -32,6 +32,8 @@ import ReconcileVendorCreditDialog from '../containers/Dialogs/ReconcileVendorCr
import LockingTransactionsDialog from '../containers/Dialogs/LockingTransactionsDialog';
import UnlockingTransactionsDialog from '../containers/Dialogs/UnlockingTransactionsDialog';
import UnlockingPartialTransactionsDialog from '../containers/Dialogs/UnlockingPartialTransactionsDialog';
import CreditNotePdfPreviewDialog from '../containers/Dialogs/CreditNotePdfPreviewDialog';
import PaymentReceivePdfPreviewDialog from '../containers/Dialogs/PaymentReceivePdfPreviewDialog';
/**
* Dialogs container.
@@ -74,6 +76,8 @@ export default function DialogsContainer() {
<UnlockingPartialTransactionsDialog
dialogName={'unlocking-partial-transactions'}
/>
<CreditNotePdfPreviewDialog dialogName={'credit-note-pdf-preview'} />
<PaymentReceivePdfPreviewDialog dialogName={'payment-pdf-preview'} />
</div>
);
}

View File

@@ -0,0 +1,47 @@
import React from 'react';
import { AnchorButton } from '@blueprintjs/core';
import { DialogContent, PdfDocumentPreview, T } from 'components';
import { usePdfCreditNote } from 'hooks/query';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
function CreditNotePdfPreviewDialogContent({
subscriptionForm: { creditNoteId },
}) {
const { isLoading, pdfUrl } = usePdfCreditNote(creditNoteId);
return (
<DialogContent>
<div class="dialog__header-actions">
<AnchorButton
href={pdfUrl}
target={'__blank'}
minimal={true}
outlined={true}
>
<T id={'pdf_preview.preview.button'} />
</AnchorButton>
<AnchorButton
href={pdfUrl}
download={'creditNote.pdf'}
minimal={true}
outlined={true}
>
<T id={'pdf_preview.download.button'} />
</AnchorButton>
</div>
<PdfDocumentPreview
height={760}
width={1000}
isLoading={isLoading}
url={pdfUrl}
/>
</DialogContent>
);
}
export default compose(withDialogActions)(CreditNotePdfPreviewDialogContent);

View File

@@ -0,0 +1,42 @@
import React from 'react';
import classNames from 'classnames';
import { T, Dialog, DialogSuspense } from 'components';
import withDialogRedux from 'components/DialogReduxConnect';
import { CLASSES } from 'common/classes';
import { compose } from 'utils';
const PdfPreviewDialogContent = React.lazy(() =>
import('./CreditNotePdfPreviewDialogContent'),
);
/**
* Credit note PDF previwe dialog.
*/
function CreditNotePdfPreviewDialog({
dialogName,
payload = { creditNoteId: null },
isOpen,
}) {
return (
<Dialog
name={dialogName}
title={<T id={'credit_note_preview.dialog.title'} />}
className={classNames(CLASSES.DIALOG_PDF_PREVIEW)}
autoFocus={true}
canEscapeKeyClose={true}
isOpen={isOpen}
style={{ width: '1000px' }}
>
<DialogSuspense>
<PdfPreviewDialogContent
dialogName={dialogName}
subscriptionForm={payload}
/>
</DialogSuspense>
</Dialog>
);
}
export default compose(withDialogRedux())(CreditNotePdfPreviewDialog);

View File

@@ -0,0 +1,49 @@
import React from 'react';
import { AnchorButton } from '@blueprintjs/core';
import { DialogContent, PdfDocumentPreview, T } from 'components';
import { usePdfPaymentReceive } from 'hooks/query';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils';
function PaymentReceivePdfPreviewDialogContent({
subscriptionForm: { paymentReceiveId },
}) {
const { isLoading, pdfUrl } = usePdfPaymentReceive(paymentReceiveId);
return (
<DialogContent>
<div class="dialog__header-actions">
<AnchorButton
href={pdfUrl}
target={'__blank'}
minimal={true}
outlined={true}
>
<T id={'pdf_preview.preview.button'} />
</AnchorButton>
<AnchorButton
href={pdfUrl}
download={'payment.pdf'}
minimal={true}
outlined={true}
>
<T id={'pdf_preview.download.button'} />
</AnchorButton>
</div>
<PdfDocumentPreview
height={760}
width={1000}
isLoading={isLoading}
url={pdfUrl}
/>
</DialogContent>
);
}
export default compose(withDialogActions)(
PaymentReceivePdfPreviewDialogContent,
);

View File

@@ -0,0 +1,44 @@
import React from 'react';
import classNames from 'classnames';
import { T, Dialog, DialogSuspense } from 'components';
import withDialogRedux from 'components/DialogReduxConnect';
import { CLASSES } from 'common/classes';
import { compose } from 'utils';
// Lazy loading the content.
const PdfPreviewDialogContent = React.lazy(() =>
import('./PaymentReceivePdfPreviewContent'),
);
/**
* Payment receive PDF preview dialog.
*/
function PaymentReceivePdfPreviewDialog({
dialogName,
payload = { paymentReceiveId: null },
isOpen,
}) {
return (
<Dialog
name={dialogName}
title={<T id={'payment_receive_preview.dialog.title'} />}
className={classNames(CLASSES.DIALOG_PDF_PREVIEW)}
autoFocus={true}
canEscapeKeyClose={true}
isOpen={isOpen}
style={{ width: '1000px' }}
>
<DialogSuspense>
<PdfPreviewDialogContent
dialogName={dialogName}
subscriptionForm={payload}
/>
</DialogSuspense>
</Dialog>
);
}
export default compose(withDialogRedux())(PaymentReceivePdfPreviewDialog);

View File

@@ -65,6 +65,11 @@ function CreditNoteDetailActionsBar({
openDialog('reconcile-credit-note', { creditNoteId });
};
// Handle print credit note.
const handlePrintCreditNote = () => {
openDialog('credit-note-pdf-preview', { creditNoteId });
};
return (
<DrawerActionsBar>
<NavbarGroup>
@@ -88,6 +93,14 @@ function CreditNoteDetailActionsBar({
<NavbarDivider />
</If>
</Can>
<Can I={CreditNoteAction.View} a={AbilitySubject.CreditNote}>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="print-16" />}
text={<T id={'print'} />}
onClick={handlePrintCreditNote}
/>
</Can>
<Can I={CreditNoteAction.Delete} a={AbilitySubject.CreditNote}>
<Button
className={Classes.MINIMAL}

View File

@@ -62,6 +62,11 @@ function PaymentReceiveActionsBar({
openDialog('notify-payment-via-sms', { paymentReceiveId });
};
// Handle print payment receive.
const handlePrintPaymentReceive = () => {
openDialog('payment-pdf-preview', { paymentReceiveId });
};
return (
<DrawerActionsBar>
<NavbarGroup>
@@ -74,6 +79,14 @@ function PaymentReceiveActionsBar({
/>
<NavbarDivider />
</Can>
<Can I={PaymentReceiveAction.View} a={AbilitySubject.PaymentReceive}>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="print-16" />}
text={<T id={'print'} />}
onClick={handlePrintPaymentReceive}
/>
</Can>
<Can I={PaymentReceiveAction.Delete} a={AbilitySubject.PaymentReceive}>
<Button
className={Classes.MINIMAL}

View File

@@ -2,6 +2,7 @@ import { useQueryClient, useMutation } from 'react-query';
import { useRequestQuery } from '../useQueryRequest';
import { transformPagination } from 'utils';
import useApiRequest from '../useRequest';
import { useRequestPdf } from '../utils';
import t from './types';
const commonInvalidateQueries = (queryClient) => {
@@ -341,3 +342,10 @@ export function useRefundCreditTransaction(id, props, requestProps) {
},
);
}
/**
* Retrieve the credit note pdf document data,
*/
export function usePdfCreditNote(creditNoteId) {
return useRequestPdf(`sales/credit_notes/${creditNoteId}`);
}

View File

@@ -2,6 +2,8 @@ import { useMutation, useQueryClient } from 'react-query';
import { useRequestQuery } from '../useQueryRequest';
import useApiRequest from '../useRequest';
import { transformPagination, saveInvoke } from 'utils';
import { useRequestPdf } from '../utils';
import t from './types';
// Common invalidate queries.
@@ -31,11 +33,11 @@ const commonInvalidateQueries = (client) => {
client.invalidateQueries(t.CREDIT_NOTE);
client.invalidateQueries(t.CREDIT_NOTES);
// Invalidate reconcile.
client.invalidateQueries(t.RECONCILE_CREDIT_NOTE);
client.invalidateQueries(t.RECONCILE_CREDIT_NOTES);
// Invalidate invoices payment transactions.
client.invalidateQueries(t.SALE_INVOICE_PAYMENT_TRANSACTIONS);
};
@@ -224,3 +226,10 @@ export function usePaymentReceiveSMSDetail(
},
);
}
/**
* Retrieve the payment receive pdf document data.
*/
export function usePdfPaymentReceive(paymentReceiveId) {
return useRequestPdf(`sales/payment_receives/${paymentReceiveId}`);
}

View File

@@ -1757,5 +1757,7 @@
"global_error.you_dont_have_permissions": "ليس لديك صلاحية الوصول إلى هذه الصفحة.",
"global_error.transactions_locked": "تم قفل المعاملات التي تمت قبل {lockedToDate}. ومن ثم لا يمكن القيام بأي عمل.",
"global_error.authorized_user_inactive": "المستخدم المصرح له تم تعطيلة."
}
"global_error.authorized_user_inactive": "المستخدم المصرح له تم تعطيلة.",
"credit_note_preview.dialog.title":"معاينة إشعار الدائن PDF",
"payment_receive_preview.dialog.title":"معاينة سند الزبون PDF"
}

View File

@@ -1737,5 +1737,7 @@
"global_error.you_dont_have_permissions": "You do not have permissions to access this page.",
"global_error.transactions_locked": "Transactions before {lockedToDate} has been locked. Hence action cannot be performed.",
"global_error.authorized_user_inactive": "The authorized user is inactive."
"global_error.authorized_user_inactive": "The authorized user is inactive.",
"credit_note_preview.dialog.title":"Credit Note PDF Preview",
"payment_receive_preview.dialog.title":"Payment Receive PDF Preview"
}