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

  global $db,$ar;

  $dt=array();

/*  



cat=4=jual tunai

- id1

- persediaan berkurang //credit: 11202

- hpp debit //51100



-id2

- terima cash dr penjualan //debit 11101

- penjualan bertambah //credit 41100



cat=7=jual kredit

- id1

- persediaan berkurang //credit: 11202

- hpp debit //51100



-id2

- piutang berambah dr penjualan //debit 11201

- penjualan bertambah //credit 41100



item_inout=2 (berkurang)



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

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

persediaan/11202 dan utang dagang 21100

*/





  $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;



  //catat penjualan-hpp



  $idt1=array(

    id=>$id1,

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

    pay_from=>$js[pay_from],

    invoice=>$js[invoice],

    reff_sales_id=>$js[reff_sales_id],

    inout=>1,

    descr=>$js[descr],

    bank=>0,

    cat=>$js[cat],

    amount=>$js[qty]*$js[hpp],

    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]=51100; //hpp

  $js1[credit]=11202; //persediaan

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

  transaction_add_v2($js1);



  $rr[descr][4]   =Terima cash dari ;

  $rr[debit][4]   =11101;

  $rr[credit][4]  =41100;

  $rr[bank][4]    =1;



  $rr[descr][7]   =Piutang .$js[due_days]. hari dari ;

  $rr[debit][7]   =11201;

  $rr[credit][7]  =41100;

  $rr[bank][7]    =0;







  // catat cash-penjuala (jika 4), piutang-penjualan (jika 7)

  $idt2=array(

    id=>$id2,

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

    pay_from=>$js[pay_from],

    invoice=>$js[invoice],

    reff_sales_id=>$js[reff_sales_id],

    inout=>1,

    descr=>$rr[descr][$js[cat]]. .$js[descr],

    bank=>$rr[bank][$js[cat]],

    cat=>$js[cat],

    amount=>$js[qty]*$js[price_per_unit],

    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]=$rr[debit][$js[cat]];

  $js2[credit]=$rr[credit][$js[cat]];

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

  transaction_add_v2($js2);



  //catat di product_trx

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

  $js3[inout]=2;

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

  $js3[action_id]=$id1;

  product_trx($js3);

  $dt[message]=add transaction succes;



  $udt_41=array(

    action_id_1=>$id1,

    action_id_2=>$id2,

  );

  Update($db,sales,$udt_41,id=.$js[reff_sales_id],$v);



  return $dt;

}