function retur_action($js,$v=0) {

  global $db,$ar;

  $dt=array();

/*  

cat=1, retur dr agen, menambah persediaan, mengurangi piutang

cat=2, retur ke supplier, mengurangi utang dan persediaan

persediaan/11202 dan utang dagang 21100

*/

  $rr[retur_descr][1]=;

  $rr[debit][1]      =41100;

  $rr[credit][1]     =11201;



  $rr[retur_descr][2]=;

  $rr[debit][2]      =21100;

  $rr[credit][2]     =11202;



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

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

  $r4 = mysqli_fetch_assoc($res4);

  $id1=$r4[id]+1;

  $id2=$r4[id]+2;



  $idt1=array(

    id=>$id1,

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

    pay_to=>$js[pay_to],

    pay_from=>$js[pay_from],

    invoice=>$js[invoice],

    inout=>$js[inout],

    descr=>$js[descr]. .$rr[retur_descr][$js[inout]],

    bank=>0,

    cat=>8,

    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(),

  );

  Insert($db,action,$idt1,$v);

  $js1=$js;

  $js1[action_id]=$id1;

  $js1[debit]=$rr[debit][$js[inout]];

  $js1[credit]=$rr[credit][$js[inout]];

  //$dt[trx]=transaction_add_v2($js1);

  transaction_add_v2($js1);

  

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

    $idt2=array(

      id=>$id2,

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

      pay_to=>$js[pay_to],

      pay_from=>$js[pay_from],

      invoice=>$js[invoice],

      inout=>$js[inout],

      descr=>$js[descr].,

      bank=>0,

      cat=>8,

      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(),

    );

    Insert($db,action,$idt2,$v);

    $js2=$js;

    $js2[action_id]=$id2;

    $js2[debit]=11202;

    $js2[credit]=51100;

    //$dt[trx]=transaction_add_v2($js2);

    transaction_add_v2($js2);

  }



  //catat di product_trx

  $js[action_at]=strtotime($js[action_at]);

  //$js[inout]=2;

  $js[remark]=$js[descr];

  $js[action_id]=$id1;

  product_trx($js);

  $dt[message]=add transaction succes;

  return $dt;

}