function action_add_v2($js){

  global $ar,$db;

  $dt=array();



  $sql3 = select id,id2,id-id2 as k from `action` where id-id2>0 order by id2 limit 1;

  $res3 = mysqli_query($db, $sql3);

  if(mysqli_num_rows($res3)>0) {

    $rw3 = mysqli_fetch_assoc($res3);

    $id2=$rw3[id2];

  } else {

    $sql4 = select * from `action` order by id desc limit 1;

    $res4 = mysqli_query($db, $sql4);

    $rw4 = mysqli_fetch_assoc($res4);

    if(isset($rw4[id]) && $rw4[id]>0) {

      $id2=$rw4[id]+1;

    } else {

      $id2=1;

    }

  }



  $idt=array(

    id=>$id2,

    action_at=>strtotime($js[action_at]),

    descr=>$js[descr],

    cat=>$js[cat],

    inout=>$js[inout],

    bank=>$js[bank],

    amount=>$js[amount],

    year=>date(Y,strtotime($js[action_at])),

    month=>date(Ym,strtotime($js[action_at])),

    tgl=>date(Y-m-d,strtotime($js[action_at])),

    update_at=>time(),

  );

  if(isset($js[pay_to])) {

    $idt[pay_to]=$js[pay_to];  

  }

  if(isset($js[pay_from])) {

    $idt[pay_from]=$js[pay_from];  

  }

  if(isset($js[invoice])) {

    $idt[invoice]=$js[invoice];  

  }

  if(isset($js[reff_sales_id])) {

    $idt[reff_sales_id]=$js[reff_sales_id];  

  }

  Insert($db,action,$idt,0);  

  tool_id2(action);

  $dt[action_id]=$id2;

  $dt[success]=true;

  return $dt;

}