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

  console.log('app action_in_add ready')

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

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

  let dt=js.data.result.menu.data[i];

  //console.log(dt)

  document.querySelector('#a4_inout').value = dt.inout || '';

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

  document.querySelector('#a4_bank').value = dt.bank || '';

  document.querySelector('#a4_debit').value = dt.debit || '';

  document.querySelector('#debit').value = dt.n_debit || '';

  let sCredit =`<div class="list list-outline list-dividers full-width">

    <ul>`;

  for (let a in dt.items) {

    sCredit +=`<li>

        <label class="item-radio item-radio-icon-start item-content">

          <input type="radio" name="a4_credit" value="`+dt.items[a].credit+`">

          <i class="icon icon-radio"></i>

          <div class="item-inner">

            <div class="item-title">`+dt.items[a].n_credit+` (`+dt.items[a].credit+`)</div>

          </div>

        </label>

      </li>`;

    }

  sCredit+=`</ul>

  </div>`;

  $$("#a4_credit").html(sCredit);



});



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

  $$('#action_in_add_button')['on']('click', function() {

  e.preventDefault();

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

    let credit = $('input[name="a4_credit"]:checked').val();

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

    let bank = $('#a4_bank').val();

    let cat = $('#a4_cat').val();

    let invoice = $('#a4_invoice').val();

    let pay_from = $('#a4_pay_from').val();

    let inout = $('#a4_inout').val();

    let amount = $('#a4_amount').val();

    let descr = $('#a4_descr').val();



    let req = {

      action_at,debit,credit,bank,cat,invoice,pay_from,inout,amount,descr

    }

    if (debit && credit && action_at && amount) {

      action_in_add(req);

      //console.log(req)

    } else {

      app.dialog.alert("All fields are required", "Add in transaction errors");

    }    

  })

});