Improve nullify operation : if the period is closed, nullify in writing the reversed operation otherwise set amount to 0
This commit is contained in:
parent
0aeffe3a08
commit
b308a5d130
4 changed files with 49 additions and 9 deletions
|
|
@ -95,17 +95,19 @@ if ($p_id != -1 ) { // A
|
|||
// Test whether date of the operation is in a closed periode
|
||||
// get the period_id
|
||||
$period_id=getPeriodeFromDate($cn,$e_op_date);
|
||||
// Check the period_id
|
||||
if ( PeriodeClosed($cn,$period_id) == true ){
|
||||
// Check the period_id
|
||||
if ( PeriodeClosed($cn,$period_id) == 't' ){
|
||||
// if the operation is in a closed or centralized period
|
||||
// the operation is voided thanks the opposite operation
|
||||
StartSql($cn);
|
||||
$p_internal=SetInternalCode($cn,$p_id,$l_array['jr_id']);
|
||||
$grp_new=NextSequence($cn,'s_jrn_'.$l_array['jr_id']);
|
||||
$sql= "insert into jrn (
|
||||
jr_def_id,jr_montant,jr_comment,
|
||||
jr_date,jr_grpt_id,jr_internal
|
||||
,jr_tech_per, jr_valid
|
||||
) select jr_def_id,jr_montant,'Annulation '||jr_comment,
|
||||
to_date('$e_op_date','DD.MM.YYYY'),$seq ,'ANNULE',
|
||||
now(),$grp_new,'$p_internal',
|
||||
$period, true
|
||||
from
|
||||
jrn
|
||||
|
|
@ -113,6 +115,19 @@ if ($p_id != -1 ) { // A
|
|||
$Res=ExecSql($cn,$sql);
|
||||
// Check return code
|
||||
if ( $Res == false ) { Rollback($cn);exit(-1);}
|
||||
// Make also the change into jrnx
|
||||
$sql= "insert into jrnx (
|
||||
j_date,j_montant,j_poste,j_grpt,
|
||||
j_jrn_def,j_debit,j_text,j_internal,j_tech_user
|
||||
) select now(),j_montant,j_poste,$grp_new,
|
||||
j_jrn_def,j_debit,j_text,'$p_internal','".$User->id."'
|
||||
from
|
||||
jrnx
|
||||
where j_grpt=".$_POST['p_id'];
|
||||
$Res=ExecSql($cn,$sql);
|
||||
// Check return code
|
||||
if ( $Res == false ) { Rollback($cn);exit(-1);}
|
||||
|
||||
// the table stock must updated
|
||||
// also in the stock table
|
||||
$sql="delete from stock_goods where sg_id = any ( select sg_id
|
||||
|
|
|
|||
|
|
@ -355,21 +355,21 @@ function getPeriodeName($p_cn,$p_id,$pos='p_start') {
|
|||
$a=pg_fetch_array($ret,0);
|
||||
return $a['t'];
|
||||
}
|
||||
/* function getPeriodeFromDate
|
||||
/* function getPeriodeFromMonth
|
||||
**************************************************
|
||||
* Purpose : Return the period corresponding to the
|
||||
* date
|
||||
*
|
||||
* parm :
|
||||
* - p_cn database connection
|
||||
* - the date 'MM.YYYY'
|
||||
* - the month + year 'MM.YYYY'
|
||||
* gen :
|
||||
* - none
|
||||
*
|
||||
* return:
|
||||
* parm_periode.p_id
|
||||
*/
|
||||
function getPeriodeFromDate($p_cn,$p_date) {
|
||||
function getPeriodeFromMonth($p_cn,$p_date) {
|
||||
$R=ExecSql($p_cn,"select p_id from parm_periode where
|
||||
to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
|
||||
if ( pg_NumRows($R) == 0 )
|
||||
|
|
@ -378,5 +378,30 @@ function getPeriodeFromDate($p_cn,$p_date) {
|
|||
|
||||
return $a['p_id'];
|
||||
}
|
||||
/* function getPeriodeFromDate
|
||||
**************************************************
|
||||
* Purpose : Return the period corresponding to the
|
||||
* date
|
||||
*
|
||||
* parm :
|
||||
* - p_cn database connection
|
||||
* - the date 'DD.MM.YYYY'
|
||||
* gen :
|
||||
* - none
|
||||
*
|
||||
* return:
|
||||
* parm_periode.p_id
|
||||
*/
|
||||
function getPeriodeFromDate($p_cn,$p_date) {
|
||||
$R=ExecSql($p_cn,"select p_id from parm_periode where
|
||||
p_start <= to_date('$p_date','DD.MM.YYYY')
|
||||
and p_end >= to_date('$p_date','DD.MM.YYYY')
|
||||
");
|
||||
if ( pg_NumRows($R) == 0 )
|
||||
return -1;
|
||||
$a=pg_fetch_array($R,0);
|
||||
|
||||
return $a['p_id'];
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -749,7 +749,7 @@ function ParseFormula($p_cn,$p_label,$p_formula,$p_start,$p_end,$p_eval=true) {
|
|||
// then we must modify the cond for the periode
|
||||
$from=str_replace("FROM=","",$afrom[0]);
|
||||
// Get the periode
|
||||
$from=getPeriodeFromDate($p_cn,$from);
|
||||
$from=getPeriodeFromMonth($p_cn,$from);
|
||||
|
||||
// Compute the cond
|
||||
if ( $from == $p_end )
|
||||
|
|
|
|||
|
|
@ -401,14 +401,14 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null)
|
|||
$r.="<TD> Opération annulée</TD>";
|
||||
}
|
||||
else {
|
||||
if ( $row ['p_closed'] == 'f' && $p_jrn != 0 ) {
|
||||
// if ( $row ['p_closed'] == 'f' && $p_jrn != 0 ) {
|
||||
// TODO Add print
|
||||
$r.="<TD>";
|
||||
// cancel operation
|
||||
$r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\',\'%s\')">',
|
||||
"Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn);
|
||||
$r.="</TD>";
|
||||
}
|
||||
// }
|
||||
}
|
||||
//document
|
||||
$r.="<TD>".sprintf('<A class="detail" HREF="show_document.php?jrn=%s&jr_grpt_id=%s">%s</A>',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue