simpan

mail@pastecode.io avatar
unknown
javascript
2 years ago
4.9 kB
2
Indexable
Never
 let data_pos_reg_header = await showDatapos_reg_header_trxStatus(db); //trxStatus ==0 and isUploaded=0
    await createtTablepos_reg_payment(db);

    var fix = [];

    // console.log("start");

    data_pos_reg_header.map(async (index, key) => {
      let data_pos_reg_detail =
        await show_data_pos_reg_detail_find_trx_insert_cloud(db, index.trxNo);
      let data_pos_payment =
        await show_data_pos_reg_payment_find_trx_no_insert_cloud(
          db,
          index.trxNo
        );

      fix.push({
        data_pos_header: index,
        data_pos_reg_detail: data_pos_reg_detail,
        data_pos_payment: data_pos_payment,
      });

      // console.log(index.key);
    });



const showDatapos_reg_header_trxStatus = async (db) => {
  try {
    const pos_reg_header = [];
    const results = await db.executeSql(
      `SELECT * FROM pos_reg_header where trxStatus=0 and isUploaded=0`
    );
    results.forEach((result) => {
      for (let index = 0; index < result.rows.length; index++) {
        // pos_reg_header.push(result.rows.item(index));
        pos_reg_header.push({
          companyId: result.rows.item(index).companyId,
          companySiteId: result.rows.item(index).companySiteId,
          trxNo: result.rows.item(index).trxNo,
          trxDate: result.rows.item(index).trxDate,
          totalAmount: result.rows.item(index).totalAmount,
          totalQty: result.rows.item(index).totalQty,
          totalDiscount: result.rows.item(index).totalDiscount,
          totalTax: result.rows.item(index).totalTax,
          totalNet: result.rows.item(index).totalNet,
          serviceAmount: result.rows.item(index).serviceAmount,
          trxStatus: 1,
          cashierId: result.rows.item(index).cashierId,
          cashierName: result.rows.item(index).cashierName,
          shift: result.rows.item(index).shift,
          registerId: result.rows.item(index).registerId,
          regNo: result.rows.item(index).regNo,
          flagReturn: result.rows.item(index).flagReturn,
          originTrxNo: result.rows.item(index).originTrxNo,
          createdAt: result.rows.item(index).createdAt,
          isUploaded: result.rows.item(index).isUploaded,
        });
      }
    });
    return pos_reg_header;
  } catch (error) {
    return error;
    // throw Error("Failed get data !!!");
  }
};


const show_data_pos_reg_detail_find_trx_insert_cloud = async (db, trx) => {
  try {
    const pos_reg_detail = [];
    const results = await db.executeSql(
      `SELECT * FROM pos_reg_detail where trxNo="${trx}" `
    );
    results.forEach((result) => {
      for (let index = 0; index < result.rows.length; index++) {
        // pos_reg_detail.push(result.rows.item(index));
        pos_reg_detail.push([
          `${result.rows.item(index).trxNo}`,
          `${result.rows.item(index).seq}`,
          `${result.rows.item(index).posRegProductId}`,
          `${result.rows.item(index).barcode}`,
          `${result.rows.item(index).posDescription}`,
          `${result.rows.item(index).companyBrandId}`,
          `${result.rows.item(index).brandCode}`,
          `${result.rows.item(index).brandName}`,
          `${result.rows.item(index).mc}`,
          `${result.rows.item(index).vendorCode}`,
          `${result.rows.item(index).qty}`,
          `${result.rows.item(index).price}`,
          `${result.rows.item(index).discountAmount}`,
          `${result.rows.item(index).discountPct}`,
          `${result.rows.item(index).amount}`,
          `${result.rows.item(index).tax}`,
          `${result.rows.item(index).netAmount}`,
          `${result.rows.item(index).isTax}`,
          `${result.rows.item(index).trxStatus}`,
          `${result.rows.item(index).updatedAt}`,
        ]);
      }
    });
    return pos_reg_detail;
  } catch (error) {
    return error;
    // throw Error("Failed to get Data Siswa !!!");
  }
};

const show_data_pos_reg_payment_find_trx_no_insert_cloud = async (
  db,
  trxNo
) => {
  const pos_reg_payment = [];
  try {
    const results = await db.executeSql(
      `SELECT * FROM pos_reg_payment where trxNo="${trxNo}"`
    );
    results.forEach((result) => {
      for (let index = 0; index < result.rows.length; index++) {
        // pos_reg_payment.push(result.rows.item(index));
        pos_reg_payment.push([
          `${result.rows.item(index).trxNo}`,
          `${result.rows.item(index).seq}`,
          `${result.rows.item(index).payCode}`,
          `${result.rows.item(index).payment}`,
          `${result.rows.item(index).amount}`,
          `${result.rows.item(index).change}`,
          `${result.rows.item(index).payreff}`,
          `${result.rows.item(index).updatedAt}`,
        ]);
      }
    });
    return pos_reg_payment;
  } catch (error) {
    return pos_reg_payment;
    // return error;
    // throw Error("Failed to get Data Siswa !!!");
  }
};