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

  console.log('app product_sell 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('#a5_id').value = id || '';

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

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

});



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

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

    e.preventDefault();

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

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

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

    const due_days = $('#a5_due_days').val();

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

    const buyer = $('#a5_buyer').val();

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

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

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

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



    let req = {

      id,cat,inout,due_days,action_at,buyer,invoice,descr,qty,price

    }

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

      product_sell(req);

    } else {

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

    }

  });

})