feat(SPG-233) Integration Google Calendar API

fix/data
Aswin Ashar Abdullah 2024-08-02 18:36:42 +07:00
parent 2e4d5df17a
commit a1f7108bc5
3 changed files with 51 additions and 47 deletions

View File

@ -43,7 +43,6 @@ export class BookingHandler
([STATUS.ACTIVE, STATUS.SETTLED].includes(data.status) && ([STATUS.ACTIVE, STATUS.SETTLED].includes(data.status) &&
data.payment_type != TransactionPaymentType.COUNTER) data.payment_type != TransactionPaymentType.COUNTER)
) { ) {
console.log(data, 'data', old_data);
const booking = await this.bookingService.getOneByOptions({ const booking = await this.bookingService.getOneByOptions({
where: { where: {
id: data.id, id: data.id,
@ -58,7 +57,6 @@ export class BookingHandler
data.payment_type != TransactionPaymentType.COUNTER) && data.payment_type != TransactionPaymentType.COUNTER) &&
[STATUS.PENDING, STATUS.ACTIVE, STATUS.SETTLED].includes(data.status) [STATUS.PENDING, STATUS.ACTIVE, STATUS.SETTLED].includes(data.status)
) { ) {
console.log('here');
await this.couchService.createDoc( await this.couchService.createDoc(
{ {
_id: booking.id, _id: booking.id,

View File

@ -61,8 +61,12 @@ export async function CreateEventCalendarHelper(
function mappingData(transaction) { function mappingData(transaction) {
return { return {
summary: transaction.invoice_code, summary: transaction.customer_name ?? transaction.invoice_code,
description: `Booking for invoice ${transaction.invoice_code}`, description: `<b>Booking for invoice ${
transaction.invoice_code
}</b><p>List Items :</p><ul>${transaction.items.map(
(item) => `<li>${item.item_name}</li>`,
)}</ul>`,
start: { start: {
dateTime: new Date(transaction.booking_date).toISOString(), dateTime: new Date(transaction.booking_date).toISOString(),
timeZone: 'Asia/Jakarta', timeZone: 'Asia/Jakarta',

View File

@ -37,57 +37,59 @@ export class SettledTransactionHandler
relations: ['items'], relations: ['items'],
}); });
if (!settled || !oldSettled) return; if (settled || oldSettled) {
const queryRunner = this.dataService
.getRepository()
.manager.connection.createQueryRunner();
const queryRunner = this.dataService if (settled) {
.getRepository() const profit_formula = await this.formulaService.getOneByOptions({
.manager.connection.createQueryRunner(); where: {
type: FormulaType.PROFIT_SHARE,
},
});
if (settled) { const sales_price = await this.formulaService.getOneByOptions({
const profit_formula = await this.formulaService.getOneByOptions({ where: {
where: { type: FormulaType.SALES_PRICE,
type: FormulaType.PROFIT_SHARE, },
}, });
});
const sales_price = await this.formulaService.getOneByOptions({ const taxes = await this.taxService.getManyByOptions({
where: { where: {
type: FormulaType.SALES_PRICE, status: STATUS.ACTIVE,
}, },
}); });
const taxes = await this.taxService.getManyByOptions({ // const profit_share_value = this.calculateFormula(profit_formula.formula_string, taxes, data.payment_total_net_profit ?? 0);
where: { const { dpp_value, tax_datas } = calculateSalesFormula(
status: STATUS.ACTIVE, sales_price.formula_string,
}, taxes,
}); data.payment_total_net_profit ?? 0,
);
// const profit_share_value = this.calculateFormula(profit_formula.formula_string, taxes, data.payment_total_net_profit ?? 0); console.log(data, 'dsa');
const { dpp_value, tax_datas } = calculateSalesFormula( const google_calendar = await CreateEventCalendarHelper(data);
sales_price.formula_string,
taxes,
data.payment_total_net_profit ?? 0,
);
const google_calendar = await CreateEventCalendarHelper(data); Object.assign(data, {
payment_total_dpp: dpp_value,
profit_share_formula: profit_formula.formula_string,
sales_price_formula: sales_price.formula_string,
taxes: tax_datas,
calendar_id: google_calendar?.id,
calendar_link: google_calendar?.htmlLink,
});
} else if (oldSettled) {
console.log(data, 'data oldSettled');
const google_calendar = await CreateEventCalendarHelper(data);
Object.assign(data, { Object.assign(data, {
payment_total_dpp: dpp_value, calendar_id: null,
profit_share_formula: profit_formula.formula_string, calendar_link: null,
sales_price_formula: sales_price.formula_string, });
taxes: tax_datas, }
calendar_id: google_calendar?.id,
calendar_link: google_calendar?.htmlLink,
});
} else if (oldSettled) {
const google_calendar = await CreateEventCalendarHelper(data);
Object.assign(data, { await this.dataService.create(queryRunner, TransactionModel, data);
calendar_id: null,
calendar_link: null,
});
} }
await this.dataService.create(queryRunner, TransactionModel, data);
} }
} }