mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: Assign default PDF template automatically
This commit is contained in:
@@ -95,6 +95,12 @@ export default class PaymentReceivesController extends BaseController {
|
||||
asyncMiddleware(this.getPaymentReceiveInvoices.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/state',
|
||||
CheckPolicies(PaymentReceiveAction.View, AbilitySubject.PaymentReceive),
|
||||
this.getPaymentReceivedState.bind(this),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id',
|
||||
CheckPolicies(PaymentReceiveAction.View, AbilitySubject.PaymentReceive),
|
||||
@@ -391,6 +397,29 @@ export default class PaymentReceivesController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @async
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
private async getPaymentReceivedState(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
const data = await this.paymentReceiveApplication.getPaymentReceivedState(
|
||||
tenantId
|
||||
);
|
||||
return res.status(200).send({ data });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given payment receive details.
|
||||
* @async
|
||||
|
||||
@@ -105,6 +105,12 @@ export default class SalesEstimatesController extends BaseController {
|
||||
asyncMiddleware(this.deleteEstimate.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/state',
|
||||
CheckPolicies(SaleEstimateAction.View, AbilitySubject.SaleEstimate),
|
||||
this.getSaleEstimateState.bind(this),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id',
|
||||
CheckPolicies(SaleEstimateAction.View, AbilitySubject.SaleEstimate),
|
||||
@@ -546,6 +552,23 @@ export default class SalesEstimatesController extends BaseController {
|
||||
}
|
||||
};
|
||||
|
||||
private getSaleEstimateState = async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
const data = await this.saleEstimatesApplication.getSaleEstimateState(
|
||||
tenantId
|
||||
);
|
||||
return res.status(200).send({ data });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles service errors.
|
||||
* @param {Error} error
|
||||
|
||||
@@ -130,6 +130,12 @@ export default class SaleInvoicesController extends BaseController {
|
||||
this.asyncMiddleware(this.getInvoicePaymentTransactions),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/state',
|
||||
CheckPolicies(SaleInvoiceAction.View, AbilitySubject.SaleInvoice),
|
||||
asyncMiddleware(this.getSaleInvoiceState.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id',
|
||||
CheckPolicies(SaleInvoiceAction.View, AbilitySubject.SaleInvoice),
|
||||
@@ -138,6 +144,7 @@ export default class SaleInvoicesController extends BaseController {
|
||||
asyncMiddleware(this.getSaleInvoice.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/',
|
||||
CheckPolicies(SaleInvoiceAction.View, AbilitySubject.SaleInvoice),
|
||||
@@ -453,6 +460,24 @@ export default class SaleInvoicesController extends BaseController {
|
||||
return res.status(200).send({ saleInvoice });
|
||||
}
|
||||
}
|
||||
|
||||
private async getSaleInvoiceState(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
|
||||
try {
|
||||
const data = await this.saleInvoiceApplication.getSaleInvoiceState(
|
||||
tenantId
|
||||
);
|
||||
return res.status(200).send({ data });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve paginated sales invoices with custom view metadata.
|
||||
* @param {Request} req
|
||||
|
||||
@@ -108,6 +108,12 @@ export default class SalesReceiptsController extends BaseController {
|
||||
this.handleServiceErrors,
|
||||
this.dynamicListService.handlerErrorsToResponse
|
||||
);
|
||||
router.get(
|
||||
'/state',
|
||||
CheckPolicies(SaleReceiptAction.View, AbilitySubject.SaleReceipt),
|
||||
asyncMiddleware(this.getSaleReceiptState.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:id',
|
||||
CheckPolicies(SaleReceiptAction.View, AbilitySubject.SaleReceipt),
|
||||
@@ -369,6 +375,30 @@ export default class SalesReceiptsController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
public async getSaleReceiptState(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
|
||||
// Retrieves receipt in pdf format.
|
||||
try {
|
||||
const data = await this.saleReceiptsApplication.getSaleReceiptState(
|
||||
tenantId
|
||||
);
|
||||
return res.status(200).send({ data });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sale receipt notification via SMS.
|
||||
* @param {Request} req
|
||||
|
||||
@@ -238,3 +238,8 @@ export interface PaymentReceivedPdfTemplateAttributes {
|
||||
showPaymentReceivedDate: boolean;
|
||||
paymentReceivedDateLabel: string;
|
||||
}
|
||||
|
||||
|
||||
export interface IPaymentReceivedState {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
@@ -144,3 +144,6 @@ export interface ISaleEstimateMailPresendEvent {
|
||||
messageOptions: SaleEstimateMailOptionsDTO;
|
||||
}
|
||||
|
||||
export interface ISaleEstimateState {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface PaymentIntegrationTransactionLinkEventPayload {
|
||||
referenceType: string;
|
||||
referenceId: number;
|
||||
saleInvoiceId: number;
|
||||
trx?: Knex.Transaction
|
||||
trx?: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface PaymentIntegrationTransactionLinkDeleteEventPayload {
|
||||
@@ -30,7 +30,7 @@ export interface PaymentIntegrationTransactionLinkDeleteEventPayload {
|
||||
referenceType: string;
|
||||
referenceId: number;
|
||||
oldSaleInvoiceId: number;
|
||||
trx?: Knex.Transaction
|
||||
trx?: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoice {
|
||||
@@ -174,7 +174,7 @@ export interface ISaleInvoiceDeletingPayload {
|
||||
tenantId: number;
|
||||
oldSaleInvoice: ISaleInvoice;
|
||||
saleInvoiceId: number;
|
||||
trx: Knex.Transaction;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface ISaleInvoiceDeletedPayload {
|
||||
@@ -339,3 +339,7 @@ export interface InvoicePdfTemplateAttributes {
|
||||
showStatement: boolean;
|
||||
statement: string;
|
||||
}
|
||||
|
||||
export interface ISaleInvocieState {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
|
||||
@@ -211,3 +211,8 @@ export interface ISaleReceiptBrandingTemplateAttributes {
|
||||
showReceiptDate: boolean;
|
||||
receiptDateLabel: string;
|
||||
}
|
||||
|
||||
|
||||
export interface ISaleReceiptState {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
import { Service } from 'typedi';
|
||||
import { ISaleEstimateState } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class GetSaleEstimateState {
|
||||
/**
|
||||
*
|
||||
* @param {Number} saleEstimateId -
|
||||
* @return {Promise<ISaleEstimateState>}
|
||||
*/
|
||||
public async getSaleEstimateState(
|
||||
tenantId: number
|
||||
): Promise<ISaleEstimateState> {
|
||||
return {
|
||||
defaultTemplateId: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { RejectSaleEstimate } from './RejectSaleEstimate';
|
||||
import { SaleEstimateNotifyBySms } from './SaleEstimateSmsNotify';
|
||||
import { SaleEstimatesPdf } from './SaleEstimatesPdf';
|
||||
import { SendSaleEstimateMail } from './SendSaleEstimateMail';
|
||||
import { GetSaleEstimateState } from './GetSaleEstimateState';
|
||||
|
||||
@Service()
|
||||
export class SaleEstimatesApplication {
|
||||
@@ -56,6 +57,9 @@ export class SaleEstimatesApplication {
|
||||
@Inject()
|
||||
private sendEstimateMailService: SendSaleEstimateMail;
|
||||
|
||||
@Inject()
|
||||
private getSaleEstimateStateService: GetSaleEstimateState;
|
||||
|
||||
/**
|
||||
* Create a sale estimate.
|
||||
* @param {number} tenantId - The tenant id.
|
||||
@@ -249,4 +253,13 @@ export class SaleEstimatesApplication {
|
||||
saleEstimateId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current state of the sale estimate.
|
||||
* @param {number} tenantId - The ID of the tenant.
|
||||
* @returns {Promise<ISaleEstimateState>} - A promise resolving to the sale estimate state.
|
||||
*/
|
||||
public getSaleEstimateStat(tenantId: number) {
|
||||
return this.getSaleEstimateStateService.getSaleEstimateState(tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Service } from 'typedi';
|
||||
import { ISaleInvocieState } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class GetSaleInvoiceState {
|
||||
/**
|
||||
*
|
||||
* @param {Number} saleInvoiceId -
|
||||
* @return {Promise<ISaleInvoice>}
|
||||
*/
|
||||
public async getSaleInvoiceState(
|
||||
tenantId: number
|
||||
): Promise<ISaleInvocieState> {
|
||||
return {
|
||||
defaultTemplateId: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import { SaleInvoiceNotifyBySms } from './SaleInvoiceNotifyBySms';
|
||||
import { SendInvoiceMailReminder } from './SendSaleInvoiceMailReminder';
|
||||
import { SendSaleInvoiceMail } from './SendSaleInvoiceMail';
|
||||
import { GetSaleInvoiceMailReminder } from './GetSaleInvoiceMailReminder';
|
||||
import { GetSaleInvoiceState } from './GetSaleInvoiceState';
|
||||
|
||||
@Service()
|
||||
export class SaleInvoiceApplication {
|
||||
@@ -73,6 +74,9 @@ export class SaleInvoiceApplication {
|
||||
@Inject()
|
||||
private getSaleInvoiceReminderService: GetSaleInvoiceMailReminder;
|
||||
|
||||
@Inject()
|
||||
private getSaleInvoiceStateService: GetSaleInvoiceState;
|
||||
|
||||
/**
|
||||
* Creates a new sale invoice with associated GL entries.
|
||||
* @param {number} tenantId
|
||||
@@ -169,6 +173,16 @@ export class SaleInvoiceApplication {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sale invoice state.
|
||||
* @param {number} tenantId
|
||||
* @param {number} saleInvoiceId
|
||||
* @returns
|
||||
*/
|
||||
public getSaleInvoiceState(tenantId: number) {
|
||||
return this.getSaleInvoiceStateService.getSaleInvoiceState(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given sale invoice as delivered.
|
||||
* @param {number} tenantId
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Service } from 'typedi';
|
||||
import { IPaymentReceivedState } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class GetPaymentReceivedState {
|
||||
/**
|
||||
* Retrieves the current state of the payment received.
|
||||
* @param {number} tenantId - The ID of the tenant.
|
||||
* @returns {Promise<IPaymentReceivedState>} - A promise resolving to the payment received state.
|
||||
*/
|
||||
public async getPaymentReceivedState(
|
||||
tenantId: number
|
||||
): Promise<IPaymentReceivedState> {
|
||||
return {
|
||||
defaultTemplateId: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { GetPaymentReceivedInvoices } from './GetPaymentReceivedInvoices';
|
||||
import { PaymentReceiveNotifyBySms } from './PaymentReceivedSmsNotify';
|
||||
import GetPaymentReceivedPdf from './GetPaymentReceivedPdf';
|
||||
import { SendPaymentReceiveMailNotification } from './PaymentReceivedMailNotification';
|
||||
import { GetPaymentReceivedState } from './GetPaymentReceivedState';
|
||||
|
||||
@Service()
|
||||
export class PaymentReceivesApplication {
|
||||
@@ -49,6 +50,9 @@ export class PaymentReceivesApplication {
|
||||
@Inject()
|
||||
private getPaymentReceivePdfService: GetPaymentReceivedPdf;
|
||||
|
||||
@Inject()
|
||||
private getPaymentReceivedStateService: GetPaymentReceivedState;
|
||||
|
||||
/**
|
||||
* Creates a new payment receive.
|
||||
* @param {number} tenantId
|
||||
@@ -223,4 +227,10 @@ export class PaymentReceivesApplication {
|
||||
paymentReceiveId
|
||||
);
|
||||
};
|
||||
|
||||
public getPaymentReceivedState = (tenantId: number) => {
|
||||
return this.getPaymentReceivedStateService.getPaymentReceivedState(
|
||||
tenantId
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Service } from 'typedi';
|
||||
import { ISaleReceiptState } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class GetSaleReceiptState {
|
||||
/**
|
||||
* Retireves the sale receipt state.
|
||||
* @param {Number} tenantId -
|
||||
* @return {Promise<ISaleReceiptState>}
|
||||
*/
|
||||
public async getSaleReceiptState(
|
||||
tenantId: number
|
||||
): Promise<ISaleReceiptState> {
|
||||
return {
|
||||
defaultTemplateId: 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
IFilterMeta,
|
||||
IPaginationMeta,
|
||||
ISaleReceipt,
|
||||
ISaleReceiptState,
|
||||
ISalesReceiptsFilter,
|
||||
SaleReceiptMailOpts,
|
||||
SaleReceiptMailOptsDTO,
|
||||
@@ -16,6 +17,7 @@ import { CloseSaleReceipt } from './CloseSaleReceipt';
|
||||
import { SaleReceiptsPdf } from './SaleReceiptsPdfService';
|
||||
import { SaleReceiptNotifyBySms } from './SaleReceiptNotifyBySms';
|
||||
import { SaleReceiptMailNotification } from './SaleReceiptMailNotification';
|
||||
import { GetSaleReceiptState } from './GetSaleReceiptState';
|
||||
|
||||
@Service()
|
||||
export class SaleReceiptApplication {
|
||||
@@ -46,6 +48,9 @@ export class SaleReceiptApplication {
|
||||
@Inject()
|
||||
private saleReceiptNotifyByMailService: SaleReceiptMailNotification;
|
||||
|
||||
@Inject()
|
||||
private getSaleReceiptStateService: GetSaleReceiptState;
|
||||
|
||||
/**
|
||||
* Creates a new sale receipt with associated entries.
|
||||
* @param {number} tenantId
|
||||
@@ -207,4 +212,13 @@ export class SaleReceiptApplication {
|
||||
saleReceiptId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current state of the sale receipt.
|
||||
* @param {number} tenantId - The ID of the tenant.
|
||||
* @returns {Promise<ISaleReceiptState>} - A promise resolving to the sale receipt state.
|
||||
*/
|
||||
public getSaleReceiptState(tenantId: number): Promise<ISaleReceiptState> {
|
||||
return this.getSaleReceiptStateService.getSaleReceiptState(tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,19 @@ import {
|
||||
useBranches,
|
||||
useSettingsCreditNotes,
|
||||
useInvoice,
|
||||
useGetCreditNoteState,
|
||||
CreditNoteStateResponse,
|
||||
} from '@/hooks/query';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
|
||||
const CreditNoteFormContext = React.createContext();
|
||||
interface CreditNoteFormProviderValue {
|
||||
creditNoteState: CreditNoteStateResponse;
|
||||
isCreditNoteStateLoading: boolean;
|
||||
}
|
||||
|
||||
const CreditNoteFormContext = React.createContext<CreditNoteFormProviderValue>(
|
||||
{} as CreditNoteFormProviderValue,
|
||||
);
|
||||
|
||||
/**
|
||||
* Credit note data provider.
|
||||
@@ -78,6 +87,10 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
const { data: brandingTemplates, isLoading: isBrandingTemplatesLoading } =
|
||||
useGetPdfTemplates({ resource: 'PaymentReceive' });
|
||||
|
||||
// Fetches the credit note state.
|
||||
const { data: creditNoteState, isLoading: isCreditNoteStateLoading } =
|
||||
useGetCreditNoteState();
|
||||
|
||||
// Handle fetching settings.
|
||||
useSettingsCreditNotes();
|
||||
|
||||
@@ -124,6 +137,10 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
// Branding templates.
|
||||
brandingTemplates,
|
||||
isBrandingTemplatesLoading,
|
||||
|
||||
// Credit note state
|
||||
creditNoteState,
|
||||
isCreditNoteStateLoading,
|
||||
};
|
||||
|
||||
const isLoading =
|
||||
@@ -140,6 +157,7 @@ function CreditNoteFormProvider({ creditNoteId, ...props }) {
|
||||
);
|
||||
}
|
||||
|
||||
const useCreditNoteFormContext = () => React.useContext(CreditNoteFormContext);
|
||||
const useCreditNoteFormContext = () =>
|
||||
React.useContext<CreditNoteFormProviderValue>(CreditNoteFormContext);
|
||||
|
||||
export { CreditNoteFormProvider, useCreditNoteFormContext };
|
||||
|
||||
@@ -58,6 +58,7 @@ function EstimateForm({
|
||||
submitPayload,
|
||||
createEstimateMutate,
|
||||
editEstimateMutate,
|
||||
saleEstimateState,
|
||||
} = useEstimateFormContext();
|
||||
|
||||
const estimateNumber = transactionNumber(
|
||||
@@ -79,6 +80,7 @@ function EstimateForm({
|
||||
currency_code: base_currency,
|
||||
terms_conditions: defaultTo(estimateTermsConditions, ''),
|
||||
note: defaultTo(estimateCustomerNotes, ''),
|
||||
pdf_template_id: saleEstimateState?.defaultTemplateId,
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
useSettingsEstimates,
|
||||
useCreateEstimate,
|
||||
useEditEstimate,
|
||||
useGetSaleEstimatesState,
|
||||
ISaleEstimatesStateResponse,
|
||||
} from '@/hooks/query';
|
||||
import { useProjects } from '@/containers/Projects/hooks';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
@@ -18,7 +20,12 @@ import { Features } from '@/constants';
|
||||
import { useFeatureCan } from '@/hooks/state';
|
||||
import { ITEMS_FILTER_ROLES } from './utils';
|
||||
|
||||
const EstimateFormContext = createContext();
|
||||
interface EstimateFormProviderValues {
|
||||
saleEstimateState: ISaleEstimatesStateResponse;
|
||||
isSaleEstimateStateLoading: boolean;
|
||||
}
|
||||
|
||||
const EstimateFormContext = createContext({} as EstimateFormProviderValues);
|
||||
|
||||
/**
|
||||
* Estimate form provider.
|
||||
@@ -76,6 +83,10 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
const { data: brandingTemplates, isLoading: isBrandingTemplatesLoading } =
|
||||
useGetPdfTemplates({ resource: 'SaleEstimate' });
|
||||
|
||||
// Fetches the sale estimate state.
|
||||
const { data: saleEstimateState, isLoading: isSaleEstimateStateLoading } =
|
||||
useGetSaleEstimatesState();
|
||||
|
||||
// Handle fetch settings.
|
||||
useSettingsEstimates();
|
||||
|
||||
@@ -118,15 +129,21 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
createEstimateMutate,
|
||||
editEstimateMutate,
|
||||
|
||||
// Branding templates
|
||||
brandingTemplates,
|
||||
isBrandingTemplatesLoading,
|
||||
|
||||
// Estimate state
|
||||
saleEstimateState,
|
||||
isSaleEstimateStateLoading,
|
||||
};
|
||||
|
||||
const isLoading =
|
||||
isCustomersLoading ||
|
||||
isItemsLoading ||
|
||||
isEstimateLoading ||
|
||||
isBrandingTemplatesLoading;
|
||||
isBrandingTemplatesLoading ||
|
||||
isSaleEstimateStateLoading;
|
||||
|
||||
return (
|
||||
<DashboardInsider loading={isLoading} name={'estimate-form'}>
|
||||
@@ -135,6 +152,7 @@ function EstimateFormProvider({ query, estimateId, ...props }) {
|
||||
);
|
||||
}
|
||||
|
||||
const useEstimateFormContext = () => useContext(EstimateFormContext);
|
||||
const useEstimateFormContext = () =>
|
||||
useContext<EstimateFormProviderValues>(EstimateFormContext);
|
||||
|
||||
export { EstimateFormProvider, useEstimateFormContext };
|
||||
|
||||
@@ -61,6 +61,7 @@ function InvoiceForm({
|
||||
createInvoiceMutate,
|
||||
editInvoiceMutate,
|
||||
submitPayload,
|
||||
saleInvoiceState
|
||||
} = useInvoiceFormContext();
|
||||
|
||||
// Invoice number.
|
||||
@@ -83,6 +84,7 @@ function InvoiceForm({
|
||||
currency_code: base_currency,
|
||||
invoice_message: defaultTo(invoiceCustomerNotes, ''),
|
||||
terms_conditions: defaultTo(invoiceTermsConditions, ''),
|
||||
pdf_template_id: saleInvoiceState?.defaultTemplateId,
|
||||
...newInvoice,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -16,13 +16,22 @@ import {
|
||||
useEditInvoice,
|
||||
useSettingsInvoices,
|
||||
useEstimate,
|
||||
useGetSaleInvoiceState,
|
||||
GetSaleInvoiceStateResponse,
|
||||
} from '@/hooks/query';
|
||||
import { useProjects } from '@/containers/Projects/hooks';
|
||||
import { useTaxRates } from '@/hooks/query/taxRates';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
import { useGetPaymentServices } from '@/hooks/query/payment-services';
|
||||
|
||||
const InvoiceFormContext = createContext();
|
||||
interface InvoiceFormContextValue {
|
||||
saleInvoiceState: GetSaleInvoiceStateResponse | null;
|
||||
isInvoiceStateLoading: boolean;
|
||||
}
|
||||
|
||||
const InvoiceFormContext = createContext<InvoiceFormContextValue>(
|
||||
{} as InvoiceFormContextValue,
|
||||
);
|
||||
|
||||
/**
|
||||
* Accounts chart data provider.
|
||||
@@ -100,6 +109,9 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
isSuccess: isBranchesSuccess,
|
||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||
|
||||
const { data: saleInvoiceState, isLoading: isInvoiceStateLoading } =
|
||||
useGetSaleInvoiceState();
|
||||
|
||||
// Handle fetching settings.
|
||||
const { isLoading: isSettingsLoading } = useSettingsInvoices();
|
||||
|
||||
@@ -154,6 +166,10 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
// Payment Services
|
||||
paymentServices,
|
||||
isPaymentServicesLoading,
|
||||
|
||||
// Invoice state
|
||||
saleInvoiceState,
|
||||
isInvoiceStateLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -172,6 +188,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
);
|
||||
}
|
||||
|
||||
const useInvoiceFormContext = () => React.useContext(InvoiceFormContext);
|
||||
const useInvoiceFormContext = () =>
|
||||
React.useContext<InvoiceFormContextValue>(InvoiceFormContext);
|
||||
|
||||
export { InvoiceFormProvider, useInvoiceFormContext };
|
||||
|
||||
@@ -69,6 +69,7 @@ function PaymentReceiveForm({
|
||||
editPaymentReceiveMutate,
|
||||
createPaymentReceiveMutate,
|
||||
isExcessConfirmed,
|
||||
paymentReceivedState,
|
||||
} = usePaymentReceiveFormContext();
|
||||
|
||||
// Payment receive number.
|
||||
@@ -77,29 +78,21 @@ function PaymentReceiveForm({
|
||||
paymentReceiveNextNumber,
|
||||
);
|
||||
// Form initial values.
|
||||
const initialValues = useMemo(
|
||||
() => ({
|
||||
...(!isEmpty(paymentReceiveEditPage)
|
||||
? transformToEditForm(paymentReceiveEditPage, paymentEntriesEditPage)
|
||||
: {
|
||||
...defaultPaymentReceive,
|
||||
// If the auto-increment mode is enabled, take the next payment
|
||||
// number from the settings.
|
||||
...(paymentReceiveAutoIncrement && {
|
||||
payment_receive_no: nextPaymentNumber,
|
||||
}),
|
||||
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
||||
currency_code: base_currency,
|
||||
const initialValues = {
|
||||
...(!isEmpty(paymentReceiveEditPage)
|
||||
? transformToEditForm(paymentReceiveEditPage, paymentEntriesEditPage)
|
||||
: {
|
||||
...defaultPaymentReceive,
|
||||
// If the auto-increment mode is enabled, take the next payment
|
||||
// number from the settings.
|
||||
...(paymentReceiveAutoIncrement && {
|
||||
payment_receive_no: nextPaymentNumber,
|
||||
}),
|
||||
}),
|
||||
[
|
||||
paymentReceiveEditPage,
|
||||
nextPaymentNumber,
|
||||
paymentEntriesEditPage,
|
||||
paymentReceiveAutoIncrement,
|
||||
preferredDepositAccount,
|
||||
],
|
||||
);
|
||||
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
||||
currency_code: base_currency,
|
||||
pdf_template_id: paymentReceivedState.defaultTemplateId,
|
||||
}),
|
||||
};
|
||||
// Handle form submit.
|
||||
const handleSubmitForm = (
|
||||
values,
|
||||
|
||||
@@ -12,11 +12,21 @@ import {
|
||||
useBranches,
|
||||
useCreatePaymentReceive,
|
||||
useEditPaymentReceive,
|
||||
usePaymentReceivedState,
|
||||
PaymentReceivedStateResponse,
|
||||
} from '@/hooks/query';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
|
||||
interface PaymentReceivedFormContextValue {
|
||||
isPaymentReceivedStateLoading: boolean;
|
||||
paymentReceivedState: PaymentReceivedStateResponse;
|
||||
}
|
||||
|
||||
// Payment receive form context.
|
||||
const PaymentReceiveFormContext = createContext();
|
||||
const PaymentReceiveFormContext =
|
||||
createContext<PaymentReceivedFormContextValue>(
|
||||
{} as PaymentReceivedFormContextValue,
|
||||
);
|
||||
|
||||
/**
|
||||
* Payment receive form provider.
|
||||
@@ -70,6 +80,12 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
|
||||
const { data: brandingTemplates, isLoading: isBrandingTemplatesLoading } =
|
||||
useGetPdfTemplates({ resource: 'PaymentReceive' });
|
||||
|
||||
// Fetches the payment received initial state.
|
||||
const {
|
||||
data: paymentReceivedState,
|
||||
isLoading: isPaymentReceivedStateLoading,
|
||||
} = usePaymentReceivedState();
|
||||
|
||||
// Detarmines whether the new mode.
|
||||
const isNewMode = !paymentReceiveId;
|
||||
|
||||
@@ -111,6 +127,10 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
|
||||
// Branding templates
|
||||
brandingTemplates,
|
||||
isBrandingTemplatesLoading,
|
||||
|
||||
// Payment received state
|
||||
isPaymentReceivedStateLoading,
|
||||
paymentReceivedState,
|
||||
};
|
||||
|
||||
const isLoading =
|
||||
@@ -127,6 +147,6 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
|
||||
}
|
||||
|
||||
const usePaymentReceiveFormContext = () =>
|
||||
useContext(PaymentReceiveFormContext);
|
||||
useContext<PaymentReceivedFormContextValue>(PaymentReceiveFormContext);
|
||||
|
||||
export { PaymentReceiveFormProvider, usePaymentReceiveFormContext };
|
||||
|
||||
@@ -63,6 +63,7 @@ function ReceiptForm({
|
||||
createReceiptMutate,
|
||||
submitPayload,
|
||||
isNewMode,
|
||||
saleReceiptState,
|
||||
} = useReceiptFormContext();
|
||||
|
||||
// The next receipt number.
|
||||
@@ -84,6 +85,7 @@ function ReceiptForm({
|
||||
currency_code: base_currency,
|
||||
receipt_message: receiptMessage,
|
||||
terms_conditions: receiptTermsConditions,
|
||||
pdf_template_id: saleReceiptState?.pdfTemplateId,
|
||||
}),
|
||||
};
|
||||
// Handle the form submit.
|
||||
|
||||
@@ -13,11 +13,20 @@ import {
|
||||
useItems,
|
||||
useCreateReceipt,
|
||||
useEditReceipt,
|
||||
useGetReceiptState,
|
||||
IGetReceiptStateResponse,
|
||||
} from '@/hooks/query';
|
||||
import { useProjects } from '@/containers/Projects/hooks';
|
||||
import { useGetPdfTemplates } from '@/hooks/query/pdf-templates';
|
||||
|
||||
const ReceiptFormContext = createContext();
|
||||
const ReceiptFormContext = createContext<ReceiptFormProviderValue>(
|
||||
{} as ReceiptFormProviderValue,
|
||||
);
|
||||
|
||||
interface ReceiptFormProviderValue {
|
||||
isSaleReceiptStateLoading: boolean;
|
||||
saleReceiptState: IGetReceiptStateResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receipt form provider.
|
||||
@@ -96,6 +105,10 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
const { data: brandingTemplates, isLoading: isBrandingTemplatesLoading } =
|
||||
useGetPdfTemplates({ resource: 'SaleReceipt' });
|
||||
|
||||
// Fetches the sale receipt state.
|
||||
const { data: saleReceiptState, isLoading: isSaleReceiptStateLoading } =
|
||||
useGetReceiptState();
|
||||
|
||||
// Fetch receipt settings.
|
||||
const { isLoading: isSettingLoading } = useSettingsReceipts();
|
||||
|
||||
@@ -137,6 +150,10 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
// Branding templates
|
||||
brandingTemplates,
|
||||
isBrandingTemplatesLoading,
|
||||
|
||||
// State
|
||||
isSaleReceiptStateLoading,
|
||||
saleReceiptState,
|
||||
};
|
||||
const isLoading =
|
||||
isReceiptLoading ||
|
||||
@@ -144,7 +161,8 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
isCustomersLoading ||
|
||||
isItemsLoading ||
|
||||
isSettingLoading ||
|
||||
isBrandingTemplatesLoading;
|
||||
isBrandingTemplatesLoading ||
|
||||
isSaleReceiptStateLoading;
|
||||
|
||||
return (
|
||||
<DashboardInsider loading={isLoading} name={'receipt-form'}>
|
||||
@@ -153,6 +171,7 @@ function ReceiptFormProvider({ receiptId, ...props }) {
|
||||
);
|
||||
}
|
||||
|
||||
const useReceiptFormContext = () => React.useContext(ReceiptFormContext);
|
||||
const useReceiptFormContext = () =>
|
||||
React.useContext<ReceiptFormProviderValue>(ReceiptFormContext);
|
||||
|
||||
export { ReceiptFormProvider, useReceiptFormContext };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { useQueryClient, useMutation } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import t from './types';
|
||||
@@ -356,3 +356,21 @@ export function useRefundCreditTransaction(id, props, requestProps) {
|
||||
export function usePdfCreditNote(creditNoteId) {
|
||||
return useRequestPdf({ url: `sales/credit_notes/${creditNoteId}` });
|
||||
}
|
||||
|
||||
export interface CreditNoteStateResponse {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
export function useGetCreditNoteState(
|
||||
options?: UseQueryOptions<CreditNoteStateResponse, Error>,
|
||||
): UseQueryResult<CreditNoteStateResponse, Error> {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<CreditNoteStateResponse, Error>(
|
||||
['CREDIT_NOTE_STATE'],
|
||||
() =>
|
||||
apiRequest
|
||||
.get('/sales/credit_notes/state')
|
||||
.then((res) => transformToCamelCase(res.data?.data)),
|
||||
{ ...options },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { useQueryClient, useMutation } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import t from './types';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
|
||||
@@ -270,3 +270,22 @@ export function useSaleEstimateDefaultOptions(estimateId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface ISaleEstimatesStateResponse {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
|
||||
export function useGetSaleEstimatesState(
|
||||
options?: UseQueryOptions<ISaleEstimatesStateResponse, Error>,
|
||||
): UseQueryResult<ISaleEstimatesStateResponse, Error> {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<ISaleEstimatesStateResponse, Error>(
|
||||
['SALE_ESTIMATES_STATE'],
|
||||
() =>
|
||||
apiRequest
|
||||
.get('/sales/estimates/state')
|
||||
.then((res) => transformToCamelCase(res.data?.data)),
|
||||
{ ...options },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { useQueryClient, useMutation } from 'react-query';
|
||||
import { useQueryClient, useMutation, useQuery } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
import { transformPagination, transformToCamelCase } from '@/utils';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import t from './types';
|
||||
@@ -341,3 +341,22 @@ export function useSaleInvoiceDefaultOptions(invoiceId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface GetSaleInvoiceStateResponse {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
|
||||
export function useGetSaleInvoiceState(
|
||||
options?: UseQueryOptions<GetSaleInvoiceStateResponse, Error>,
|
||||
): UseQueryResult<GetSaleInvoiceStateResponse, Error> {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<GetSaleInvoiceStateResponse, Error>(
|
||||
['SALE_INVOICE_STATE'],
|
||||
() =>
|
||||
apiRequest
|
||||
.get(`/sales/invoices/state`)
|
||||
.then((res) => transformToCamelCase(res.data?.data)),
|
||||
{ ...options },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import {
|
||||
useMutation,
|
||||
useQueryClient,
|
||||
QueryClient,
|
||||
UseQueryOptions,
|
||||
UseQueryResult,
|
||||
useQuery,
|
||||
} from 'react-query';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import { transformPagination, saveInvoke } from '@/utils';
|
||||
|
||||
import t from './types';
|
||||
import { useRequestPdf } from '../useRequestPdf';
|
||||
import t from './types';
|
||||
|
||||
// Common invalidate queries.
|
||||
const commonInvalidateQueries = (client) => {
|
||||
@@ -269,3 +275,31 @@ export function usePaymentReceiveDefaultOptions(paymentReceiveId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface PaymentReceivedStateResponse {
|
||||
defaultTemplateId: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the payment receive state.
|
||||
* @param {Record<string, any>} query - Query parameters for the request.
|
||||
* @param {UseQueryOptions<PaymentReceivedStateResponse, Error>} options - Optional query options.
|
||||
* @returns {UseQueryResult<PaymentReceivedStateResponse, Error>} The query result.
|
||||
*/
|
||||
export function usePaymentReceivedState(
|
||||
query: Record<string, any>,
|
||||
options?: UseQueryOptions<PaymentReceivedStateResponse, Error>,
|
||||
): UseQueryResult<PaymentReceivedStateResponse, Error> {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<PaymentReceivedStateResponse, Error>(
|
||||
[t.PAYMENT_RECEIVE_STATE, query],
|
||||
() =>
|
||||
apiRequest
|
||||
.get('/sales/payment_receives/state', { params: query })
|
||||
.then((res) => res.data),
|
||||
{
|
||||
...options,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
// @ts-nocheck
|
||||
import { useQueryClient, useMutation } from 'react-query';
|
||||
import {
|
||||
useQueryClient,
|
||||
useMutation,
|
||||
UseQueryResult,
|
||||
UseQueryOptions,
|
||||
useQuery,
|
||||
} from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import useApiRequest from '../useRequest';
|
||||
import { transformPagination } from '@/utils';
|
||||
@@ -244,3 +250,22 @@ export function useSaleReceiptDefaultOptions(invoiceId, props) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface IGetReceiptStateResponse {
|
||||
pdfTemplateId: number;
|
||||
}
|
||||
|
||||
export function useGetReceiptState(
|
||||
options?: UseQueryOptions<IGetReceiptStateResponse, Error>,
|
||||
): UseQueryResult<IGetReceiptStateResponse, Error> {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<IGetReceiptStateResponse, Error>(
|
||||
['SALE_RECEIPT_STATE'],
|
||||
() =>
|
||||
apiRequest
|
||||
.get(`/sales/receipts/state`)
|
||||
.then((res) => transformToCamelCase(res.data?.data)),
|
||||
{ ...options },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user