function journal($year=2025){

  global $ar,$db;

  $dt=array();



  $sql=SELECT account_code from journal where `year`=.$year. group by account_code;

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

  if(mysqli_num_rows($res)>0) {  

    $dt[success]=true;

    $a=0;

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

      $dt[data][$r1[account_code]][name]=$ar[acc_name][$r1[account_code]];

      //$dt[data][title]=$ar[acc_name][$r1[account_code]];

      $sql2=SELECT a.*,b.descr,b.img from `journal` a JOIN `action` b ON a.action_id=b.id where a.account_code=.$r1[account_code]. and a.`year`=.$year. order by seq;

      $res2=mysqli_query($db,$sql2);

      $b=0;

      while($r2=mysqli_fetch_assoc($res2)) {

    if($r2[inout]==2) {

      $rp=-.ang2($r2[amount]);

      $col=red;

      //$p3=$r2[pay_to];       

    } else {

      $rp=ang2($r2[amount]);

      $col=green; 

      //$p3=$r2[pay_from];       

    }

      

        $dt[data][$r1[account_code]][items][$b]=$r2;

        $dt[data][$r1[account_code]][items][$b][image]=$ar[imgurl]..$r2[img];  

        $dt[data][$r1[account_code]][items][$b][rp]=$rp;

        $dt[data][$r1[account_code]][items][$b][col]=$col;

        $dt[data][$r1[account_code]][items][$b][tgl]=date(Y-m-d,$r2[action_at]);

        $dt[data][$r1[account_code]][items][$b][rp_debit]=ang2($r2[debit]);

        $dt[data][$r1[account_code]][items][$b][rp_credit]=ang2($r2[credit]);

        $dt[data][$r1[account_code]][items][$b][rp_balance]=ang2($r2[balance]);

        $b++;

      }

      $a++;

    }



  } else {

    $dt[error]=true;

    $dt[message]=data not found;

  }

  return $dt;

  $db->close();

}