Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/added', async (req, res) => {
- try {
- let body = req.body
- let response = await transaction.add(
- body.id_transaction,
- body.id_user,
- body.id_supplier,
- body.trx_amount_paid,
- body.trx_amount_cutting,
- body.trx_amount_discount,
- body.trx_startDate_nota,
- body.trx_endDate_nota,
- body.trx_number_nota
- ) //inserrt data
- //get product
- // // //insert into table product
- if (body.productList.length > 0) { //dataliost from react
- for(let items = body.productList.length -1; items >= 0; items--) {
- let thims = await product.id(body.productList[items].temp_id_product)
- let hers = thims.data
- let datStock = thims.data.map(i => i.prod_stock)
- var merged = datStock.reduce((prev, next) => {
- return prev.concat(next);
- });
- let daTrx = thims.data.map(i => i.prod_stock)
- var merged = daTrx.reduce((prev, next) => {
- return prev.concat(next);
- });
- for(let i= hers.length -1; i >=0; i--) {
- let endStock = Number(hers[i].prod_stock) + Number(body.productList[items].temp_prod_amount)
- let data = await mutation.add(
- body.id_transaction,
- body.productList[items].temp_id_product,
- hers[i].prod_stock,
- body.productList[items].temp_prod_amount,
- endStock
- )
- }
- let results = await product.updateStock(
- body.productList[items].temp_id_product,
- body.productList[items].temp_id_type,
- body.productList[items].temp_id_brand,
- body.productList[items].temp_prod_name,
- body.productList[items].temp_prod_amount, //add stock to product
- body.productList[items].temp_prod_purchase, //search average
- body.productList[items].temp_prod_selling,
- body.productList[items].temp_prod_cutted,
- body.productList[items].temp_prod_discount
- )
- for(let i= hers.length -1; i >=0; i--) {
- let endStock = Number(hers[i].prod_stock) + Number(body.productList[items].temp_prod_amount)
- let selfs = await mutation.update(
- daTrx,
- merged,
- body.productList[items].temp_prod_amount,
- endStock
- )
- }
- }
- }
- // //insert to tbl detail transaction
- // if (body.datalist.length > 0) { //dataliost from react
- // let response_d = 0;
- // for(let i = body.datalist.length -1; i >=0; i--) {
- // datas =
- // response_d = await transactionDetail.add(
- // body.id_transaction,
- // body.datalist[i].temp_id_product,
- // body.datalist[i].temp_prod_amount,
- // body.datalist[i].temp_prod_cutted,
- // body.datalist[i].temp_prod_discount,
- // )
- // }
- // }
- res.status(200).json(response)
- }catch(e) {
- console.log(e)
- res.sendStatus(500)
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement