$(document).on('page:beforein', '.page[data-name="product_retur"]', async function (e) {

  console.log('app product_retur ready')

  var id = e.detail.route.params.id;

  var cat = e.detail.route.params.c;

  console.log(id);

  let js = JSON.parse(localStorage.getItem('f01_data'));

  let dt= js.data.result.product_byid.data[id];

  document.querySelector('#a6_id').value = id || '';

  document.querySelector('#a6_cat').value = cat || '';

  document.querySelector('#a6_name').value = dt.name || '';

});



$$(document).on('page:init', '.page[data-name="product_retur"]', function(e) {

  $(document).off("click", "#product_retur_button").on("click", "#product_retur_button", function(e) {

    e.preventDefault();

    const id = $('#a6_id').val();

    const cat = $('#a6_cat').val();

    const inout = $('#a6_inout').val();

    const action_at = $('#a6_action_at').val();

    const to_from = $('#a6_to_from').val();

    const invoice = $('#a6_invoice').val();

    const descr = $('#a6_descr').val();

    const qty = $('#a6_qty').val();

    const price = $('#a6_price').val();



    let req = {

      id,cat,inout,action_at,to_from,invoice,descr,qty,price

    }

    if (id && cat && action_at && qty && price) {

      product_retur(req);

    } else {

      app.dialog.alert("All fields are required", "Product Retur Errors");

    }

  });

})