Fix : cannot letter a record because remains old data

This commit is contained in:
sparkyx 2022-04-10 17:11:31 +02:00
parent 3dc0178455
commit f8d23563a0
5 changed files with 22 additions and 4 deletions

View file

@ -35,6 +35,8 @@ $http=new HttpInput();
if ( $g_user->check_dossier(dossier::id(),true) == 'X' ) exit(); if ( $g_user->check_dossier(dossier::id(),true) == 'X' ) exit();
$from_div = (isset($_REQUEST['ajax'])) ? 1 : $div; $from_div = (isset($_REQUEST['ajax'])) ? 1 : $div;
$clean_lettering=new Lettering($cn);
$clean_lettering->remove_incoherent();
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/* first detail for a card */ /* first detail for a card */

View file

@ -224,6 +224,7 @@ class Lettering
*/ */
public function save($p_array) public function save($p_array)
{ {
if (!isset($p_array['letter_j_id'])) if (!isset($p_array['letter_j_id']))
{ {
// if nothing selected then remove // if nothing selected then remove
@ -287,6 +288,7 @@ class Lettering
echo $exc->getMessage(); echo $exc->getMessage();
error_log($exc->getTraceAsString()); error_log($exc->getTraceAsString());
$this->db->rollback(); $this->db->rollback();
return;
} }
@ -384,7 +386,15 @@ class Lettering
ob_end_clean(); ob_end_clean();
return $r; return $r;
} }
/**
* @brief for some reason , sometimes, a record in letter_X doesn't have his counterpart
* in letter_Y
*/
function remove_incoherent()
{
$this->db->exec_sql("delete from letter_cred lc where jl_id not in (select jl_id from letter_deb)");
$this->db->exec_sql("delete from letter_deb lc where jl_id not in (select jl_id from letter_cred)");
}
/** /**
* wrapper : it call show_all, show_lettered or show_not_lettered depending * wrapper : it call show_all, show_lettered or show_not_lettered depending
* of the parameter * of the parameter
@ -392,6 +402,7 @@ class Lettering
*/ */
public function show_list($p_type) public function show_list($p_type)
{ {
switch ($p_type) switch ($p_type)
{ {
case 'all': case 'all':
@ -505,7 +516,9 @@ class Lettering_Account extends Lettering
isNumber($this->fil_amount_max)==1&& isNumber($this->fil_amount_max)==1&&
isNumber($this->fil_amount_min)==1&& isNumber($this->fil_amount_min)==1&&
($this->fil_amount_max!=0||$this->fil_amount_min!=0)) ($this->fil_amount_max!=0||$this->fil_amount_min!=0))
$filter_amount=" and (j_montant >= $this->fil_amount_min and j_montant<=$this->fil_amount_max or (coalesce(comptaproc.get_letter_jnt($p_jid),-1)= coalesce(comptaproc.get_letter_jnt(j_id),-1) and coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) "; $filter_amount=" and (j_montant >= $this->fil_amount_min and j_montant<=$this->fil_amount_max "
. " or (coalesce(comptaproc.get_letter_jnt($p_jid),-1)= coalesce(comptaproc.get_letter_jnt(j_id),-1) "
. " and coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
$sql=" $sql="
select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id, j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,

View file

@ -487,6 +487,9 @@ echo $export_pdf;
echo $export_print; echo $export_print;
$fiche = new Fiche($cn); $fiche = new Fiche($cn);
$histo=$http->get("histo","number"); $histo=$http->get("histo","number");
$clean_lettering=new Lettering($cn);
$clean_lettering->remove_incoherent();
for ($e = 0; $e < count($afiche); $e++) for ($e = 0; $e < count($afiche); $e++)
{ {
$array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc'); $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc');

View file

@ -124,7 +124,7 @@ $letter=new Lettering_Account($cn);
$letter->set_parameter('account',$http->get('acc')); $letter->set_parameter('account',$http->get('acc'));
$letter->set_parameter('start',$start->value); $letter->set_parameter('start',$start->value);
$letter->set_parameter('end',$end->value); $letter->set_parameter('end',$end->value);
$letter->remove_incoherent();
if ( $sel->selected == 0 ) if ( $sel->selected == 0 )
echo $letter->show_list('all'); echo $letter->show_list('all');
if ( $sel->selected == 1 ) if ( $sel->selected == 1 )

View file

@ -123,7 +123,7 @@ $quick_code=strtoupper(trim($http->get('acc')));
$letter->set_parameter('quick_code',$quick_code); $letter->set_parameter('quick_code',$quick_code);
$letter->set_parameter('start',$start->value); $letter->set_parameter('start',$start->value);
$letter->set_parameter('end',$end->value); $letter->set_parameter('end',$end->value);
$letter->remove_incoherent();
if ( $sel->selected == 0 ) if ( $sel->selected == 0 )
echo $letter->show_list('all'); echo $letter->show_list('all');
if ( $sel->selected == 1 ) if ( $sel->selected == 1 )