Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.post('/added', async (req, res) => {
  2.   try {
  3.     let body = req.body
  4.     let response = await transaction.add(
  5.       body.id_transaction,
  6.       body.id_user,
  7.       body.id_supplier,
  8.       body.trx_amount_paid,
  9.       body.trx_amount_cutting,
  10.       body.trx_amount_discount,
  11.       body.trx_startDate_nota,
  12.       body.trx_endDate_nota,
  13.       body.trx_number_nota
  14.     ) //inserrt data
  15.    
  16.     //get product
  17.  
  18.     // // //insert into table product
  19.     if (body.productList.length > 0) { //dataliost from react
  20.       for(let items = body.productList.length -1; items >= 0; items--) {
  21.         let thims = await product.id(body.productList[items].temp_id_product)
  22.         let hers = thims.data
  23.         let datStock = thims.data.map(i => i.prod_stock)
  24.         var merged = datStock.reduce((prev, next) => {
  25.           return prev.concat(next);
  26.         });
  27.         let daTrx = thims.data.map(i => i.prod_stock)
  28.         var merged = daTrx.reduce((prev, next) => {
  29.           return prev.concat(next);
  30.         });
  31.  
  32.  
  33.         for(let i= hers.length -1; i >=0; i--) {
  34.           let endStock = Number(hers[i].prod_stock) +  Number(body.productList[items].temp_prod_amount)
  35.           let data = await mutation.add(
  36.             body.id_transaction,
  37.             body.productList[items].temp_id_product,
  38.             hers[i].prod_stock,
  39.             body.productList[items].temp_prod_amount,
  40.             endStock
  41.             )
  42.         }
  43.  
  44.         let results = await product.updateStock(
  45.           body.productList[items].temp_id_product,
  46.           body.productList[items].temp_id_type,
  47.           body.productList[items].temp_id_brand,
  48.           body.productList[items].temp_prod_name,
  49.           body.productList[items].temp_prod_amount, //add stock to product
  50.           body.productList[items].temp_prod_purchase, //search average
  51.           body.productList[items].temp_prod_selling,
  52.           body.productList[items].temp_prod_cutted,
  53.           body.productList[items].temp_prod_discount
  54.           )
  55.  
  56.         for(let i= hers.length -1; i >=0; i--) {
  57.           let endStock = Number(hers[i].prod_stock) +  Number(body.productList[items].temp_prod_amount)
  58.           let selfs = await mutation.update(
  59.           daTrx,
  60.           merged,
  61.           body.productList[items].temp_prod_amount,
  62.           endStock
  63.           )
  64.         }
  65.       }
  66.     }
  67.      // //insert to tbl detail transaction
  68.     // if (body.datalist.length > 0) { //dataliost from react
  69.     //   let response_d = 0;
  70.     //   for(let i = body.datalist.length -1; i >=0; i--) {
  71.     //     datas =
  72.     //     response_d = await transactionDetail.add(
  73.     //       body.id_transaction,
  74.     //       body.datalist[i].temp_id_product,
  75.     //       body.datalist[i].temp_prod_amount,
  76.     //       body.datalist[i].temp_prod_cutted,
  77.     //       body.datalist[i].temp_prod_discount,
  78.     //     )
  79.     //   }
  80.     // }
  81.     res.status(200).json(response)
  82.   }catch(e) {
  83.     console.log(e)
  84.     res.sendStatus(500)
  85.   }
  86. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement