function JournalCount_v2($year) {

  global $db,$ar;

  $sql6=update fcode set sel2=0;

  $res6=mysqli_query($db,$sql6);

  $sql3=SELECT * from action order by action_at,seq;

  $res3=mysqli_query($db,$sql3);

  while($r3=mysqli_fetch_assoc($res3)) {

      $udt3=array(

          seq=>$r3[seq],

      );

      Update($db,journal,$udt3,action_id=.$r3[id],0);

      Update($db,transaction,$udt3,action_id=.$r3[id],0);

  }

  $sql=SELECT account_code from journal group by account_code;

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

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

    $sql2=SELECT * from journal where year=.$year. and account_code=.$r1[account_code]. order by action_at asc, seq asc;

    //echo $sql2.<br>;

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

    $bal=0;

    $seq2=1;

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

      $bal=$bal+$r2[debit]-$r2[credit];

      $udt=array(

        balance=>$bal,

        seq2=>$seq2,

        update_at=>time(),

      );

      Update($db,journal,$udt,id=.$r2[id],0);

      $seq2++;

    } 

    $udt4=array(

      sel2=>1,

    );

    Update($db,fcode,$udt4,code=c.$r1[account_code].,0);  

  }  

}