Merge pull request 'feat(SPG-800): add validation delete on data booking transaction' (#56) from fix/bug-firman into development
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
Reviewed-on: #56pull/58/head devel_20.1.11
commit
9efa56b2bc
|
@ -9,7 +9,9 @@ export function calculateSalesFormula(
|
||||||
throwError = false,
|
throwError = false,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
let { value, variable, tax_datas } = mappingTaxes(taxes, formula, total);
|
const mapTaxes = mappingTaxes(taxes, formula, total);
|
||||||
|
let { value } = mapTaxes;
|
||||||
|
const { variable, tax_datas } = mapTaxes;
|
||||||
|
|
||||||
const x1 = math.simplify(formula, variable).toString();
|
const x1 = math.simplify(formula, variable).toString();
|
||||||
console.log('Formula ', x1);
|
console.log('Formula ', x1);
|
||||||
|
@ -41,13 +43,10 @@ export function calculateProfitFormula(
|
||||||
throwError = false,
|
throwError = false,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
let { value, variable, tax_datas } = mappingTaxes(
|
const mapTaxes = mappingTaxes(taxes, formula, total, profit_share);
|
||||||
taxes,
|
let { value } = mapTaxes;
|
||||||
formula,
|
const { variable, tax_datas } = mapTaxes;
|
||||||
total,
|
console.log(formula, variable);
|
||||||
profit_share,
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = math.simplify(formula, variable).toString();
|
const result = math.simplify(formula, variable).toString();
|
||||||
console.log(result, 'formula');
|
console.log(result, 'formula');
|
||||||
|
|
||||||
|
@ -64,9 +63,9 @@ export function calculateProfitFormula(
|
||||||
}
|
}
|
||||||
|
|
||||||
function mappingTaxes(taxes, formula, total, profit_share = 0) {
|
function mappingTaxes(taxes, formula, total, profit_share = 0) {
|
||||||
let value = 0;
|
const value = 0;
|
||||||
const variable = {};
|
const variable = {};
|
||||||
let tax_datas = [];
|
const tax_datas = [];
|
||||||
const const_variable = ['profit_share', 'item_share', 'dpp'];
|
const const_variable = ['profit_share', 'item_share', 'dpp'];
|
||||||
|
|
||||||
const regex = /([a-zA-Z0-9_]+)/g;
|
const regex = /([a-zA-Z0-9_]+)/g;
|
||||||
|
@ -78,14 +77,17 @@ function mappingTaxes(taxes, formula, total, profit_share = 0) {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
if (!const_variable.includes(key)) {
|
if (!const_variable.includes(key)) {
|
||||||
const keyData = taxes.find((tax) => tax.name == key);
|
const keyData = taxes.find((tax) => tax.name == key);
|
||||||
variable[key] = keyData.value / 100;
|
if (!keyData) {
|
||||||
|
variable[key] = key;
|
||||||
tax_datas.push({
|
} else {
|
||||||
tax_id: keyData.id,
|
variable[key] = keyData.value / 100;
|
||||||
tax_name: keyData.name,
|
tax_datas.push({
|
||||||
tax_value: keyData.value,
|
tax_id: keyData.id,
|
||||||
tax_total_value: (keyData.value / 100) * Number(total),
|
tax_name: keyData.name,
|
||||||
});
|
tax_value: keyData.value,
|
||||||
|
tax_total_value: (keyData.value / 100) * Number(total),
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'profit_share':
|
case 'profit_share':
|
||||||
|
|
|
@ -7,7 +7,12 @@ import {
|
||||||
import { TransactionModel } from '../../../data/models/transaction.model';
|
import { TransactionModel } from '../../../data/models/transaction.model';
|
||||||
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
||||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { Injectable } from '@nestjs/common';
|
import {
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
UnprocessableEntityException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<TransactionEntity> {
|
export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<TransactionEntity> {
|
||||||
|
@ -16,6 +21,21 @@ export class BatchDeleteTransactionManager extends BaseBatchDeleteManager<Transa
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateData(data: TransactionEntity): Promise<void> {
|
async validateData(data: TransactionEntity): Promise<void> {
|
||||||
|
const allowDelete = [
|
||||||
|
STATUS.DRAFT,
|
||||||
|
STATUS.ACTIVE,
|
||||||
|
STATUS.CANCEL,
|
||||||
|
STATUS.PENDING,
|
||||||
|
STATUS.EXPIRED,
|
||||||
|
].includes(data.status);
|
||||||
|
|
||||||
|
if (!allowDelete) {
|
||||||
|
throw new UnprocessableEntityException({
|
||||||
|
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
|
message: `Gagal! data dengan status ${data.status} tidak bisa di hapus!`,
|
||||||
|
error: 'Unprocessable Entity',
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import {
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
UnprocessableEntityException,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||||
import { TransactionEntity } from '../../entities/transaction.entity';
|
import { TransactionEntity } from '../../entities/transaction.entity';
|
||||||
import {
|
import {
|
||||||
|
@ -7,6 +11,7 @@ import {
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
import { TransactionModel } from '../../../data/models/transaction.model';
|
import { TransactionModel } from '../../../data/models/transaction.model';
|
||||||
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
import { TransactionDeletedEvent } from '../../entities/event/transaction-deleted.event';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntity> {
|
export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntity> {
|
||||||
|
@ -15,6 +20,21 @@ export class DeleteTransactionManager extends BaseDeleteManager<TransactionEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
async validateProcess(): Promise<void> {
|
||||||
|
const allowDelete = [
|
||||||
|
STATUS.DRAFT,
|
||||||
|
STATUS.ACTIVE,
|
||||||
|
STATUS.CANCEL,
|
||||||
|
STATUS.PENDING,
|
||||||
|
STATUS.EXPIRED,
|
||||||
|
].includes(this.data.status);
|
||||||
|
|
||||||
|
if (!allowDelete) {
|
||||||
|
throw new UnprocessableEntityException({
|
||||||
|
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||||
|
message: `Gagal! data dengan status ${this.data.status} tidak bisa di hapus!`,
|
||||||
|
error: 'Unprocessable Entity',
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue