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

View File

@ -61,8 +61,12 @@ export async function CreateEventCalendarHelper(
function mappingData(transaction) {
return {
summary: transaction.invoice_code,
description: `Booking for invoice ${transaction.invoice_code}`,
summary: transaction.customer_name ?? 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: {
dateTime: new Date(transaction.booking_date).toISOString(),
timeZone: 'Asia/Jakarta',

View File

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