fix: missing product code, buyPrice when create and edit and add (ราคาตัวแทน) for agentPrice product name
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
This commit is contained in:
parent
95ee32fc57
commit
a9201f715a
2 changed files with 47 additions and 26 deletions
|
|
@ -78,6 +78,7 @@ type ProductCreate = {
|
||||||
|
|
||||||
type ProductUpdate = {
|
type ProductUpdate = {
|
||||||
status?: "ACTIVE" | "INACTIVE";
|
status?: "ACTIVE" | "INACTIVE";
|
||||||
|
code?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
detail?: string;
|
detail?: string;
|
||||||
process?: number;
|
process?: number;
|
||||||
|
|
@ -302,7 +303,10 @@ export class ProductController extends Controller {
|
||||||
update: { value: { increment: 1 } },
|
update: { value: { increment: 1 } },
|
||||||
});
|
});
|
||||||
|
|
||||||
const listId = await flowAccount.createProducts(body);
|
const listId = await flowAccount.createProducts(
|
||||||
|
`${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||||
|
body,
|
||||||
|
);
|
||||||
|
|
||||||
return await tx.product.create({
|
return await tx.product.create({
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -390,10 +394,21 @@ export class ProductController extends Controller {
|
||||||
product.flowAccountProductIdSellPrice !== null &&
|
product.flowAccountProductIdSellPrice !== null &&
|
||||||
product.flowAccountProductIdAgentPrice !== null
|
product.flowAccountProductIdAgentPrice !== null
|
||||||
) {
|
) {
|
||||||
|
const mergedBody = {
|
||||||
|
...body,
|
||||||
|
code: body.code ?? product.code,
|
||||||
|
price: body.price ?? product.price,
|
||||||
|
agentPrice: body.agentPrice ?? product.agentPrice,
|
||||||
|
serviceCharge: body.serviceCharge ?? product.serviceCharge,
|
||||||
|
vatIncluded: body.vatIncluded ?? product.vatIncluded,
|
||||||
|
agentPriceVatIncluded: body.agentPriceVatIncluded ?? product.agentPriceVatIncluded,
|
||||||
|
serviceChargeVatIncluded: body.serviceChargeVatIncluded ?? product.serviceChargeVatIncluded,
|
||||||
|
};
|
||||||
|
|
||||||
await flowAccount.editProducts(
|
await flowAccount.editProducts(
|
||||||
product.flowAccountProductIdSellPrice,
|
product.flowAccountProductIdSellPrice,
|
||||||
product.flowAccountProductIdAgentPrice,
|
product.flowAccountProductIdAgentPrice,
|
||||||
body,
|
mergedBody,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw notFoundError("FlowAccountProductId");
|
throw notFoundError("FlowAccountProductId");
|
||||||
|
|
|
||||||
|
|
@ -455,19 +455,22 @@ const flowAccount = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// flowAccount POST create Product
|
// flowAccount POST create Product
|
||||||
async createProducts(body: JsonObject) {
|
async createProducts(code: String, body: JsonObject) {
|
||||||
const { token } = await flowAccountAPI.auth();
|
const { token } = await flowAccountAPI.auth();
|
||||||
|
|
||||||
const commonBody = {
|
const commonBody = {
|
||||||
productStructureType: null,
|
productStructureType: null,
|
||||||
type: "3",
|
type: 3,
|
||||||
|
code: `${code}`,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
sellDescription: body.detail,
|
sellDescription: body.detail,
|
||||||
sellVatType: 3,
|
sellVatType: 3,
|
||||||
unitName: "Unit",
|
buyPrice: body.serviceCharge,
|
||||||
|
buyVatType: body.serviceChargeVatIncluded ? 1 : 3,
|
||||||
|
buyDescription: body.detail,
|
||||||
};
|
};
|
||||||
|
|
||||||
const createProduct = async (price: any, vatIncluded: boolean) => {
|
const createProduct = async (name: string, price: any, vatIncluded: boolean) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(api + "/products", {
|
const res = await fetch(api + "/products", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -477,13 +480,14 @@ const flowAccount = {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
...commonBody,
|
...commonBody,
|
||||||
|
name: name,
|
||||||
sellPrice: price,
|
sellPrice: price,
|
||||||
sellVatType: vatIncluded ? 1 : 3,
|
sellVatType: vatIncluded ? 1 : 3,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`Request failed with status ${res.status}`);
|
throw new Error(`Request failed with status ${res.status} ${res}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let json: any = null;
|
let json: any = null;
|
||||||
|
|
@ -501,8 +505,12 @@ const flowAccount = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const [sellId, agentId] = await Promise.all([
|
const [sellId, agentId] = await Promise.all([
|
||||||
createProduct(body.price, /true/.test(`${body.vatIncluded}`)),
|
createProduct(`${body.name}`, body.price, /true/.test(`${body.vatIncluded}`)),
|
||||||
createProduct(body.agentPrice, /true/.test(`${body.agentPriceVatIncluded}`)),
|
createProduct(
|
||||||
|
`${body.name} (ราคาตัวแทน)`,
|
||||||
|
body.agentPrice,
|
||||||
|
/true/.test(`${body.agentPriceVatIncluded}`),
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -521,15 +529,16 @@ const flowAccount = {
|
||||||
|
|
||||||
const commonBody = {
|
const commonBody = {
|
||||||
productStructureType: null,
|
productStructureType: null,
|
||||||
type: "3",
|
type: 3,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
sellDescription: body.detail,
|
sellDescription: body.detail,
|
||||||
sellVatType: 3,
|
sellVatType: 3,
|
||||||
unitName: "Unit",
|
buyPrice: body.serviceCharge,
|
||||||
categoryName: "Car",
|
buyVatType: body.serviceChargeVatIncluded ? 1 : 3,
|
||||||
|
buyDescription: body.detail,
|
||||||
};
|
};
|
||||||
|
|
||||||
const editProduct = async (id: String, price: any, vatIncluded: boolean) => {
|
const editProduct = async (id: String, name: String, price: any, vatIncluded: boolean) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(api + `/products/${id}`, {
|
const res = await fetch(api + `/products/${id}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
|
@ -539,13 +548,14 @@ const flowAccount = {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
...commonBody,
|
...commonBody,
|
||||||
|
name: name,
|
||||||
sellPrice: price,
|
sellPrice: price,
|
||||||
sellVatType: vatIncluded ? 1 : 3,
|
sellVatType: vatIncluded ? 1 : 3,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`Request failed with status ${res.status}`);
|
throw new Error(`Request failed with status ${res.status} ${res}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let json: any = null;
|
let json: any = null;
|
||||||
|
|
@ -562,19 +572,15 @@ const flowAccount = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [sellId, agentId] = await Promise.all([
|
await Promise.all([
|
||||||
editProduct(sellPriceId, body.price, /true/.test(`${body.vatIncluded}`)),
|
editProduct(sellPriceId, `${body.name}`, body.price, /true/.test(`${body.vatIncluded}`)),
|
||||||
editProduct(agentPriceId, body.agentPrice, /true/.test(`${body.agentPriceVatIncluded}`)),
|
editProduct(
|
||||||
|
agentPriceId,
|
||||||
|
`${body.name} (ราคาตัวแทน)`,
|
||||||
|
body.agentPrice,
|
||||||
|
/true/.test(`${body.agentPriceVatIncluded}`),
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
|
||||||
ok: !!(agentId && sellId),
|
|
||||||
status: agentId && sellId ? 200 : 500,
|
|
||||||
data: {
|
|
||||||
productIdSellPrice: sellId,
|
|
||||||
productIdAgentPrice: agentId,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// flowAccount DELETE Product
|
// flowAccount DELETE Product
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue