function product_trx($js) {

  global $db,$ar;

  //$dt=array();

  //echo <pre>; print_r($js); echo </pre>;

  //beli=add inout=1; jual=minus; inout=2

  $sql4 = select id from product_trx order by id desc limit 1;

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

  $rw4 = mysqli_fetch_assoc($res4);

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

    $id2=$rw4[id]+1;

  } else {

    $id2=1;

  }

  $idt=array(

    id=>$id2,

    action_at=>$js[action_at],

    action_id=>$js[action_id],

    product_id=>$js[product_id],

    item_code=>$js[item_code],

    inout=>$js[inout],

    invoice=>$js[invoice],

    remark=>$js[descr],

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

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

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

    update_at=>time(),

  );

  $udt=array(

    action_at=>$js[action_at],

    action_id=>$js[action_id],

    product_id=>$js[product_id],

    item_code=>$js[item_code],

    inout=>$js[inout],

    invoice=>$js[invoice],

    remark=>$js[descr],

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

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

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

    update_at=>time(),

  );

  if($js[inout]==1) {

    $idt[item_in]=$udt[item_in]=$js[qty];

  } else {

    $idt[item_out]=$udt[item_out]=$js[qty];

  }

  InsertUpdate($db,product_trx,$idt,$udt,0);

}