Compare commits

..

No commits in common. "9efa56b2bcd10f42335ed8f991d214ebc7288307" and "583b754315747cc811423c9dc85ecf9623598872" have entirely different histories.

3 changed files with 20 additions and 62 deletions

View File

@ -9,9 +9,7 @@ export function calculateSalesFormula(
throwError = false, throwError = false,
) { ) {
try { try {
const mapTaxes = mappingTaxes(taxes, formula, total); let { value, variable, tax_datas } = 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);
@ -43,10 +41,13 @@ export function calculateProfitFormula(
throwError = false, throwError = false,
) { ) {
try { try {
const mapTaxes = mappingTaxes(taxes, formula, total, profit_share); let { value, variable, tax_datas } = mappingTaxes(
let { value } = mapTaxes; taxes,
const { variable, tax_datas } = mapTaxes; formula,
console.log(formula, variable); total,
profit_share,
);
const result = math.simplify(formula, variable).toString(); const result = math.simplify(formula, variable).toString();
console.log(result, 'formula'); console.log(result, 'formula');
@ -63,9 +64,9 @@ export function calculateProfitFormula(
} }
function mappingTaxes(taxes, formula, total, profit_share = 0) { function mappingTaxes(taxes, formula, total, profit_share = 0) {
const value = 0; let value = 0;
const variable = {}; const variable = {};
const tax_datas = []; let 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;
@ -77,17 +78,14 @@ 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);
if (!keyData) { variable[key] = keyData.value / 100;
variable[key] = key;
} else { tax_datas.push({
variable[key] = keyData.value / 100; tax_id: keyData.id,
tax_datas.push({ tax_name: keyData.name,
tax_id: keyData.id, tax_value: keyData.value,
tax_name: keyData.name, tax_total_value: (keyData.value / 100) * Number(total),
tax_value: keyData.value, });
tax_total_value: (keyData.value / 100) * Number(total),
});
}
} else { } else {
switch (key) { switch (key) {
case 'profit_share': case 'profit_share':

View File

@ -7,12 +7,7 @@ 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 { import { Injectable } from '@nestjs/common';
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> {
@ -21,21 +16,6 @@ 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;
} }

View File

@ -1,8 +1,4 @@
import { import { Injectable } from '@nestjs/common';
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 {
@ -11,7 +7,6 @@ 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> {
@ -20,21 +15,6 @@ 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;
} }