mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: wip send an invoice mail the customer email
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { check, param, query } from 'express-validator';
|
||||
import { body, check, param, query } from 'express-validator';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import BaseController from '../BaseController';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
@@ -145,6 +145,39 @@ export default class SaleInvoicesController extends BaseController {
|
||||
this.handleServiceErrors,
|
||||
this.dynamicListService.handlerErrorsToResponse
|
||||
);
|
||||
router.get(
|
||||
'/:id/mail-reminder',
|
||||
this.specificSaleInvoiceValidation,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getSaleInvoiceMailReminder.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.post(
|
||||
'/:id/mail-reminder',
|
||||
[
|
||||
...this.specificSaleInvoiceValidation,
|
||||
body('from').isString().exists(),
|
||||
body('to').isString().exists(),
|
||||
body('body').isString().exists(),
|
||||
body('attach_invoice').exists().isBoolean().toBoolean(),
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.sendSaleInvoiceMailReminder.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.post(
|
||||
'/:id/mail',
|
||||
[
|
||||
...this.specificSaleInvoiceValidation,
|
||||
body('from').isString().exists(),
|
||||
body('to').isString().exists(),
|
||||
body('body').isString().exists(),
|
||||
body('attach_invoice').exists().isBoolean().toBoolean(),
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.sendSaleInvoiceMail.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -630,6 +663,81 @@ export default class SaleInvoicesController extends BaseController {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
public async sendSaleInvoiceMail(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { id: invoiceId } = req.params;
|
||||
|
||||
try {
|
||||
await this.saleInvoiceApplication.sendSaleInvoiceMail(
|
||||
tenantId,
|
||||
invoiceId
|
||||
);
|
||||
return res.status(200).send({});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
public async getSaleInvoiceMailReminder(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { id: invoiceId } = req.params;
|
||||
|
||||
try {
|
||||
await this.saleInvoiceApplication.getSaleInvoiceMailReminder(
|
||||
tenantId,
|
||||
invoiceId
|
||||
);
|
||||
return res.status(200).send({});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
public async sendSaleInvoiceMailReminder(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const { id: invoiceId } = req.params;
|
||||
|
||||
try {
|
||||
await this.saleInvoiceApplication.sendSaleInvoiceMailReminder(
|
||||
tenantId,
|
||||
invoiceId
|
||||
);
|
||||
return res.status(200).send({});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles service errors.
|
||||
* @param {Error} error
|
||||
|
||||
@@ -186,3 +186,11 @@ export enum SaleInvoiceAction {
|
||||
Writeoff = 'Writeoff',
|
||||
NotifyBySms = 'NotifyBySms',
|
||||
}
|
||||
|
||||
export interface SendInvoiceMailDTO {
|
||||
to: string;
|
||||
from: string;
|
||||
subject: string;
|
||||
body: string;
|
||||
attachInvoice?: boolean;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import { ApproveSaleEstimate } from './ApproveSaleEstimate';
|
||||
import { RejectSaleEstimate } from './RejectSaleEstimate';
|
||||
import { SaleEstimateNotifyBySms } from './SaleEstimateSmsNotify';
|
||||
import { SaleEstimatesPdf } from './SaleEstimatesPdf';
|
||||
import { SendSaleEstimateMail } from './SendSaleEstimateMail';
|
||||
|
||||
@Service()
|
||||
export class SaleEstimatesApplication {
|
||||
@@ -50,6 +51,9 @@ export class SaleEstimatesApplication {
|
||||
@Inject()
|
||||
private saleEstimatesPdfService: SaleEstimatesPdf;
|
||||
|
||||
@Inject()
|
||||
private sendEstimateMailService: SendSaleEstimateMail;
|
||||
|
||||
/**
|
||||
* Create a sale estimate.
|
||||
* @param {number} tenantId - The tenant id.
|
||||
@@ -209,4 +213,14 @@ export class SaleEstimatesApplication {
|
||||
saleEstimate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
* @param {number} saleEstimateId
|
||||
* @returns
|
||||
*/
|
||||
public sendSaleEstimateMail(tenantId: number, saleEstimateId: number) {
|
||||
return this.sendEstimateMailService.sendMail(tenantId, saleEstimateId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export class SendSaleEstimateMail {
|
||||
sendMail(tenantId: number, saleEstimateId: number) {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class GetSaleInvoiceMailReminder {
|
||||
public getInvoiceMailReminder(tenantId: number, saleInvoiceId: number) {}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
ISystemUser,
|
||||
ITenantUser,
|
||||
InvoiceNotificationType,
|
||||
SendInvoiceMailDTO,
|
||||
} from '@/interfaces';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { CreateSaleInvoice } from './CreateSaleInvoice';
|
||||
@@ -24,6 +25,9 @@ import { WriteoffSaleInvoice } from './WriteoffSaleInvoice';
|
||||
import { SaleInvoicePdf } from './SaleInvoicePdf';
|
||||
import { GetInvoicePaymentsService } from './GetInvoicePaymentsService';
|
||||
import { SaleInvoiceNotifyBySms } from './SaleInvoiceNotifyBySms';
|
||||
import { SendInvoiceMailReminder } from './SendSaleInvoiceMailReminder';
|
||||
import { SendSaleInvoiceMail } from './SendSaleInvoiceMail';
|
||||
import { GetSaleInvoiceMailReminder } from './GetSaleInvoiceMailReminder';
|
||||
|
||||
@Service()
|
||||
export class SaleInvoiceApplication {
|
||||
@@ -60,6 +64,15 @@ export class SaleInvoiceApplication {
|
||||
@Inject()
|
||||
private invoiceSms: SaleInvoiceNotifyBySms;
|
||||
|
||||
@Inject()
|
||||
private sendInvoiceReminderService: SendInvoiceMailReminder;
|
||||
|
||||
@Inject()
|
||||
private sendSaleInvoiceMailService: SendSaleInvoiceMail;
|
||||
|
||||
@Inject()
|
||||
private getSaleInvoiceReminderService: GetSaleInvoiceMailReminder;
|
||||
|
||||
/**
|
||||
* Creates a new sale invoice with associated GL entries.
|
||||
* @param {number} tenantId
|
||||
@@ -279,4 +292,49 @@ export class SaleInvoiceApplication {
|
||||
invoiceSmsDetailsDTO
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the metadata of invoice mail reminder.
|
||||
* @param {number} tenantId
|
||||
* @param {number} saleInvoiceId
|
||||
* @returns {}
|
||||
*/
|
||||
public getSaleInvoiceMailReminder(tenantId: number, saleInvoiceId: number) {
|
||||
return this.getSaleInvoiceReminderService.getInvoiceMailReminder(
|
||||
tenantId,
|
||||
saleInvoiceId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends reminder of the given invoice to the invoice's customer.
|
||||
* @param {number} tenantId
|
||||
* @param {number} saleInvoiceId
|
||||
* @returns {}
|
||||
*/
|
||||
public sendSaleInvoiceMailReminder(tenantId: number, saleInvoiceId: number) {
|
||||
return this.sendInvoiceReminderService.sendInvoiceMailReminder(
|
||||
tenantId,
|
||||
saleInvoiceId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
* @param {number} saleInvoiceId
|
||||
* @param {SendInvoiceMailDTO} messageDTO
|
||||
* @returns
|
||||
*/
|
||||
public sendSaleInvoiceMail(
|
||||
tenantId: number,
|
||||
saleInvoiceId: number,
|
||||
messageDTO: SendInvoiceMailDTO
|
||||
) {
|
||||
return this.sendSaleInvoiceMailService.sendSaleInvoiceMail(
|
||||
tenantId,
|
||||
saleInvoiceId,
|
||||
messageDTO
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Service } from 'typedi';
|
||||
import { SendInvoiceMailDTO } from '@/interfaces';
|
||||
|
||||
|
||||
@Service()
|
||||
export class SendSaleInvoiceMail {
|
||||
public sendSaleInvoiceMail(
|
||||
tenantId: number,
|
||||
saleInvoiceId: number,
|
||||
messageDTO: SendInvoiceMailDTO
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Service } from 'typedi';
|
||||
|
||||
@Service()
|
||||
export class SendInvoiceMailReminder {
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
* @param {number} saleInvoiceId
|
||||
*/
|
||||
public sendInvoiceMailReminder(tenantId: number, saleInvoiceId: number) {}
|
||||
}
|
||||
Reference in New Issue
Block a user