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

  console.log('app transaction_add ready')

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

  console.log(i)

  let js2 = JSON.parse(localStorage.getItem('f05_data'));

  let dtl = js2.data.result.account_trx.data.left;  

  //console.log(dtl);

  let dtr = js2.data.result.account_trx.data.right;  

  //console.log(dtr);

  let dta = js2.data.result.account_trx.data.all;  

  //console.log(dta);

  let js_action = JSON.parse(localStorage.getItem('f05_action'));

  let dt = js_action.data.byid[i];  

  console.log(dt)

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

    document.querySelector('#t1_action_at').value = dt.action_at || '';

  

  //console.log(dt)

  let sel_debit=`<option value="0"></option>`;

  for (let i in dta) {

  sel_debit +=`<option value="`+dta[i].code+`">`+dta[i].name+`</option>`;

  }

  $$("#t1_debit").html(sel_debit);



  let sel_credit=`<option value="0"></option>`;

  for (let i in dta) {

  sel_credit+=`<option value="`+dta[i].code+`">`+dta[i].name+`</option>`;

  }

  $$("#t1_credit").html(sel_credit);



});



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

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

    e.preventDefault();

    let action_at = $('#t1_action_at').val();

    let action_id = $('#t1_action_id').val();

    let debit = $('#t1_debit').val();

    let credit = $('#t1_credit').val();

    let req = {

      action_id,action_at,debit,credit

    }

    if (action_id,debit,credit) {

      transaction_add(req);

    } else {

      app.dialog.alert("All fields are required", "Edit Action Errors");

    }

  });

})