function product_trx_count() {

  global $db,$ar;

  

  $sql4 = select product_id from product_trx group by product_id;

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

  while($rw4 = mysqli_fetch_assoc($res4)) {

    $sql = select * from product_trx where product_id=.$rw4[product_id]. order by action_at;

    $res = mysqli_query($db, $sql);

    $j[balance]=0;

    while($r=mysqli_fetch_assoc($res)) {

      $j[balance]=$j[balance]+$r[item_in]-$r[item_out];

      $udt=array(

        balance=>$j[balance],

      );

      Update($db,product_trx,$udt,id=.$r[id],0);

    }

    $udt=array(

      qty=>$j[balance],

    );

    Update($db,product,$udt,id=.$rw4[product_id],0);

  }

}