start(); $Res=$p_cn->exec_sql($sql); $Res=$p_cn->exec_sql("update jrnx set j_centralized='t' where j_tech_per=".$p_periode); // Set correctly the number of operation id (jr_opid) for each journal // get the existing jrn_def_id //-- $Res = $p_cn->exec_sql("select jrn_def_id from jrn_def"); $MaxJrn=Database::num_row($Res); // for each jrn_def_id for ( $i=0; $i < $MaxJrn;$i++) { $row=Database::fetch_array($Res,$i); // get the op related to that jrn_def_id $sql=sprintf("select jr_id from jrn where jr_tech_per=%d and jr_def_id = %d order by jr_date,jr_grpt_id desc", $p_periode, $row['jrn_def_id'] ); $Res2=$p_cn->exec_sql($sql); $MaxLine=Database::num_row($Res2); $jrn_def_id=$row['jrn_def_id']; /* if seq doesn't exist create it */ if ( $p_cn->exist_sequence('s_jrn_'.$jrn_def_id) == false ) { $p_cn->create_sequence('s_jrn_'.$jrn_def_id); } for ($e=0;$e < $MaxLine;$e++) { // each line is updated with a sequence $line=Database::fetch_array($Res2,$e); $jr_id=$line['jr_id']; $sql=sprintf ("update jrn set jr_opid = (select nextval('s_jrn_%d')) where jr_id =%d", $jrn_def_id, $jr_id); $Ret=$p_cn->exec_sql($sql); } } // Put jr_c_opid in centralized // for each jrn_def_id // get the op related to that jrn_def_id $sql=sprintf("select jr_id from jrn where jr_tech_per=%d order by jr_date,jr_grpt_id desc", $p_periode ); $Res2=$p_cn->exec_sql($sql); $MaxLine=Database::num_row($Res2); for ($e=0;$e < $MaxLine;$e++) { // each line is updated with a sequence $line=Database::fetch_array($Res2,$e); $jr_id=$line['jr_id']; $sql=sprintf ("update jrn set jr_c_opid = (select nextval('s_central')) where jr_id =%d", $jr_id); $Ret=$p_cn->exec_sql($sql); } // Set the order of the jrn $Res=$p_cn->exec_sql("select c_id from centralized inner join jrn on c_grp = jr_grpt_id order by jr_c_opid, c_debit desc"); for ( $e=0;$e < Database::num_row($Res);$e++) { $row=Database::fetch_array($Res,$e); $sql=sprintf ("update centralized set c_order = (select nextval('s_central_order')) where c_id = %d",$row['c_id']); $Res2=$p_cn->exec_sql($sql); } $p_cn->exec_sql("update parm_periode set p_central=true where p_id=$p_periode"); } catch(Exception $e) { rollback($p_cn); return ERROR; } $p_cn->commit(); return NOERROR; } ?>