From f00f8ffe0b2d24f8a91182df026d6202326b7c53 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Mon, 26 Apr 2010 21:29:48 +0000 Subject: [PATCH] Lettering for account and card are now finished --- html/ajax_misc.php | 152 ++++++++++++++++++------- html/js/acc_ledger.js | 34 +++++- include/class_lettering.php | 181 +++++++++++++++++++++++++++--- include/letter.inc.php | 1 + include/lettering.account.inc.php | 8 +- include/lettering.card.inc.php | 132 ++++++++++++++++++++++ include/template/letter_prop.php | 4 +- 7 files changed, 454 insertions(+), 58 deletions(-) create mode 100644 include/lettering.card.inc.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 41a5fafa2..e2bbd1227 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -195,49 +195,122 @@ EOF; /** *display the lettering */ -case 'dl': - require_once('class_lettering.php'); - $ret=new IButton('return'); - $ret->label=_('Retour'); - $ret->javascript="$('detail').hide();$('list').show();"; - $r=""; - // retrieve info for the given j_id (date, amount,side and comment) - $sql="select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,J_POSTE,j_qcode, + case 'dl': + require_once('class_lettering.php'); + $exercice=$user->get_exercice(); + $periode=new Periode($cn); + list($first_per,$last_per)=$periode->get_limit($exercice); + + $ret=new IButton('return'); + $ret->label=_('Retour'); + $ret->javascript="$('detail').hide();$('list').show();$('search').show();"; + $r=""; + // retrieve info for the given j_id (date, amount,side and comment) + $sql="select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,J_POSTE,j_qcode, jr_comment,j_montant, j_debit,jr_internal from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1"; - $arow=$cn->get_array($sql,array($j_id)); - $row=$arow[0]; + $arow=$cn->get_array($sql,array($j_id)); + $row=$arow[0]; - $r.='
'._('Lettrage').''; - $r.='Poste '.$row['j_poste'].' '.$row['j_qcode'].'
'; - $r.='Date : '.$row['j_date_fmt'].' ref :'.$row['jr_internal'].'
'; - $r.=h($row['jr_comment'])." montant: ".($row['j_montant'])." -- ".(($row['j_debit']=='t')?'D':'C'); - $r.='
'; - - // display a list of operation from the other side + box button - if ( $ot == 'account') { - $obj=new Lettering_Account($cn,$row['j_poste']); - $r.=$obj->show_letter($j_id); - } else if ($ot=='card') { - $obj=new Lettering_Card($cn,$row['j_qcode']); - $r.=$obj->show_letter($j_id); - } else { - $r.='Mauvais type objet'; - } - $html='
'; - $html.=HtmlInput::phpsessid(); - $html.=dossier::hidden(); - if ( isset($_REQUEST['p_action'])) $html.=HtmlInput::hidden('p_action',$_REQUEST['p_action']); - if ( isset($_REQUEST['sa'])) $html.=HtmlInput::hidden('sa',$_REQUEST['sa']); - if ( isset($_REQUEST['acc'])) $html.=HtmlInput::hidden('acc',$_REQUEST['acc']); + $r.='
'._('Lettrage').''; + $r.='Poste '.$row['j_poste'].' '.$row['j_qcode'].'
'; + $r.='Date : '.$row['j_date_fmt'].' ref :'.$row['jr_internal'].'
'; + $r.=h($row['jr_comment'])." montant: ".($row['j_montant'])." ".(($row['j_debit']=='t')?'D':'C'); + $r.='
'; + $r.='
'; + $r.=''; + $r.='
'; + // needed hidden var + $r.=HtmlInput::phpsessid(); + $r.=dossier::hidden(); + if ( isset($_REQUEST['p_action'])) $r.=HtmlInput::hidden('p_action',$_REQUEST['p_action']); + if ( isset($_REQUEST['sa'])) $r.=HtmlInput::hidden('sa',$_REQUEST['sa']); + if ( isset($_REQUEST['acc'])) $r.=HtmlInput::hidden('acc',$_REQUEST['acc']); + $r.=HtmlInput::hidden('j_id',$j_id); + $r.=HtmlInput::hidden('op',$op); + $r.=HtmlInput::hidden('ot',$ot); - $html.=$r; - $html.=HtmlInput::submit('record',_('Sauver')).$ret->input(); - $html.=''; - // echo $html;exit; - $html=escape_xml($html); + $r.=''; + //min amount + $line=td(_('Montant min. ')); + $min=new INum('min_amount'); + $min->value=(isset($min_amount))?$min_amount:0; - header('Content-type: text/xml; charset=UTF-8'); + $line.=td($min->input()); + // max amount + $line.=td(_('Montant max. ')); + $max=new INum('max_amount'); + $max->value=(isset($max_amount))?$max_amount:0; + $line.=td($max->input()); + $r.=tr($line); + + // start date + $start=new IDate('search_start'); + $start->value=(isset($search_start))?$search_start:$first_per->first_day(); + + + $line=td('Date Debut').td($start->input()); + // end date + $end=new IDate('search_end'); + $end->value=(isset($search_end))?$search_end:$last_per->last_day(); + $line.=td('Date Fin').td($end->input()); + $r.=tr($line); + // Side + $line=td('Debit / Credit'); + $iside=new ISelect('side'); + $iside->value=array( + array('label'=>_('Debit'),'value'=>0), + array('label'=>_('Credit'),'value'=>1), + array('label'=>_('Les 2'),'value'=>3) + ); + $iside->selected=(isset($side))?$side:0; + $r.=tr($line.td($iside->input())); + $r.='
'; + $r.='
'; + $r.='
'; + $r.=HtmlInput::submit('search','Rechercher'); + $r.='
'; + $r.=''; + $r.='
'; + + $form='
'; + + $form.='
'; + $form.=HtmlInput::phpsessid(); + $form.=dossier::hidden(); + if ( isset($_REQUEST['p_action'])) $form.=HtmlInput::hidden('p_action',$_REQUEST['p_action']); + if ( isset($_REQUEST['sa'])) $form.=HtmlInput::hidden('sa',$_REQUEST['sa']); + if ( isset($_REQUEST['acc'])) $form.=HtmlInput::hidden('acc',$_REQUEST['acc']); + // display a list of operation from the other side + box button + if ( $ot == 'account') { + $obj=new Lettering_Account($cn,$row['j_poste']); + if ( isset($search_start)) $obj->start=$search_start; + if ( isset ($search_end)) $obj->end=$search_end; + if ( isset ($max_amount)) $obj->fil_amount_max=$max_amount; + if ( isset ($min_amount)) $obj->fil_amount_min=$min_amount; + if ( isset ($side)) $obj->fil_deb=$side; + + $form.=$obj->show_letter($j_id); + } else if ($ot=='card') { + $obj=new Lettering_Card($cn,$row['j_qcode']); + if ( isset($search_start)) $obj->start=$search_start; + if ( isset ($search_end)) $obj->end=$search_end; + if ( isset ($max_amount)) $obj->fil_amount_max=$max_amount; + if ( isset ($min_amount)) $obj->fil_amount_min=$min_amount; + if ( isset ($side)) $obj->fil_deb=$side; + $form.=$obj->show_letter($j_id); + } else { + $form.='Mauvais type objet'; + } + + $form.=HtmlInput::submit('record',_('Sauver')).$ret->input(); + $form.='
'; + $form.='
'; + $html=$r.$form; + // echo $html;exit; + $html=escape_xml($html); + + header('Content-type: text/xml; charset=UTF-8'); echo << @@ -245,6 +318,5 @@ echo <<$html EOF; - - break; + break; } diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index d283cfbb6..aacf45143 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -493,6 +493,7 @@ function dsp_letter(obj) { } ); $('list').hide(); + $('search').hide(); $('detail').innerHTML=''; $('detail').show(); } catch(e){alert('dsp_letter '+e.message);} @@ -519,4 +520,35 @@ function success_dsp_letter(req) { } function error_dsp_letter(req) { alert('Erreur AJAX DSP_LETTER'); -} \ No newline at end of file +} + +function search_letter(obj) { + try { + var str_query=''; + if (obj.elements['gDossier'] ) str_query='gDossier='+obj.elements['gDossier'].value; + if (obj.elements['phpsessid'] ) str_query+='&PHPSESSID='+obj.elements['phpsessid'].value; + if (obj.elements['j_id'] ) str_query+='&j_id='+obj.elements['j_id'].value; + if (obj.elements['ot'] ) str_query+='&ot='+obj.elements['ot'].value; + if (obj.elements['op'] ) str_query+='&op='+obj.elements['op'].value; + if (obj.elements['min_amount'] ) str_query+='&min_amount='+obj.elements['min_amount'].value; + if (obj.elements['max_amount'] ) str_query+='&max_amount='+obj.elements['max_amount'].value; + if (obj.elements['search_start'] ) str_query+='&search_start='+obj.elements['search_start'].value; + if (obj.elements['search_end'] ) str_query+='&search_end='+obj.elements['search_end'].value; + if (obj.elements['side'] ) str_query+='&side='+obj.elements['side'].value; + + + var action=new Ajax.Request( + "ajax_misc.php", + { + method:'get', + parameters:str_query, + onFailure:error_dsp_letter, + onSuccess:success_dsp_letter + } + ); + $('list').hide(); + $('search').hide(); + $('detail').innerHTML=''; + $('detail').show(); + } catch(e){alert('search_letter '+e.message);} +} diff --git a/include/class_lettering.php b/include/class_lettering.php index 4c6508834..58fad0069 100644 --- a/include/class_lettering.php +++ b/include/class_lettering.php @@ -105,8 +105,10 @@ class Lettering @todo if only one row, we delete completely the lettering */ public function save($p_array) { - $this->db->start(); + $this->db->exec_sql('delete from jnt_letter where jl_id=$1',array($p_array['jnt_id'])); + + $this->db->start(); $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq"); $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)', array($jl_id)); @@ -119,22 +121,26 @@ class Lettering }else { $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',array($p_array['j_id'],$jl_id)); } - + $count=0; // save dest for($i=0;$idb->get_value('select j_debit,j_montant from jrnx where j_id=$1',array($p_array['letter_j_id'][$i])); if ( $deb == 't') { + $count++; // save into letter_deb $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($p_array['letter_j_id'][$i],$jl_id)); }else { + $count++; $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',array($p_array['letter_j_id'][$i],$jl_id)); } } //end if 1 } //end for // save into jnt_letter - + if ( $count==0) { + $this->db->rollback(); + } $this->db->commit(); } /** @@ -161,10 +167,6 @@ class Lettering ); */ } - protected function show_not_lettered() { - } - protected function show_lettered() { - } protected function show_all() { $this->get_all(); $r=""; @@ -174,13 +176,31 @@ class Lettering ob_clean(); return $r; } + protected function show_lettered() { + $this->get_letter(); + $r=""; + ob_start(); + require_once('template/letter_all.php'); + $r=ob_get_contents(); + ob_clean(); + return $r; + } + protected function show_not_lettered() { + $this->get_unletter(); + $r=""; + ob_start(); + require_once('template/letter_all.php'); + $r=ob_get_contents(); + ob_clean(); + return $r; + } public function show_list($p_type) { switch($p_type) { case 'all': return $this->show_all(); break; - case 'notletter': + case 'unletter': return $this->show_not_lettered(); break; case 'letter': @@ -193,9 +213,9 @@ class Lettering public function show_letter($p_jid) { $j_debit=$this->db->get_value('select j_Debit from jrnx where j_id=$1',array($p_jid)); $amount_init=$this->db->get_value('select j_montant from jrnx where j_id=$1',array($p_jid)); - $this->get_other_side($j_debit); + $this->get_filter(); // retrieve jnt_letter.id - $sql="select distinct(jl_id) from jnt_letter join letter_deb using (jl_id) join letter_cred using (jl_id) + $sql="select distinct(jl_id) from jnt_letter left outer join letter_deb using (jl_id) left outer join letter_cred using (jl_id) where letter_deb.j_id = $1 or letter_cred.j_id=$2"; $jnt_id=$this->db->get_value($sql,array($p_jid,$p_jid)); @@ -210,6 +230,7 @@ class Lettering return $r; } + public function update() { if ( $this->verify() != 0 ) return; } @@ -244,7 +265,7 @@ class Lettering_Account extends Lettering{ *@brief get other side *@param $j_debit f for cred or t for debit */ - public function get_other_side($j_debit) { + public function get_other_side_obsolete($j_debit) { $sql=" select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, j_montant,j_debit,jr_comment,jr_internal, @@ -257,6 +278,43 @@ order by j_date,j_id"; $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end)); } + public function get_filter() { + $filter_deb=''; + if (isset($this->fil_deb)) { + switch ($this->fil_deb) { + case 0: + $filter_deb=" and j_debit='t' "; + break; + case 1: + $filter_deb=" and j_debit='f' "; + break; + case 2: + $filter_deb=" "; + break; + } + + } + $filter_amount=""; + if ( isset ($this->fil_amount_max ) && + isset ($this->fil_amount_min ) && + isNumber($this->fil_amount_max)==1 && + isNumber($this->fil_amount_min)==1 && + ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) ) + $filter_amount=" and j_montant between $this->fil_amount_min and $this->fil_amount_max "; + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger +$filter_deb +$filter_amount +order by j_date,j_id"; + + $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end)); + } + public function get_all() { $sql=" @@ -267,6 +325,30 @@ coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') and $this->sql_ledger +order by j_date,j_id"; + $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end)); + } + public function get_letter() { + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger +and j_id in (select j_id from letter_deb join jnt_letter using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) ) +order by j_date,j_id"; + $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end)); + } + public function get_unletter() { + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger +and j_id not in (select j_id from letter_deb join jnt_letter using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) ) order by j_date,j_id"; $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end)); } @@ -274,11 +356,84 @@ order by j_date,j_id"; } class Lettering_Card extends Lettering{ - function __construct($p_init,$p_account=null) { + function __construct($p_init,$p_qcode=null) { parent::__construct($p_init); - $this->qcode=$p_qcode; + $this->quick_code=$p_qcode; $this->object_type='card'; } + public function get_filter() { + $filter_deb=''; + if (isset($this->fil_deb)) { + switch ($this->fil_deb) { + case 0: + $filter_deb=" and j_debit='t' "; + break; + case 1: + $filter_deb=" and j_debit='f' "; + break; + case 2: + $filter_deb=" "; + break; + } + + } + $filter_amount=""; + if ( isset ($this->fil_amount_max ) && + isset ($this->fil_amount_min ) && + isNumber($this->fil_amount_max)==1 && + isNumber($this->fil_amount_min)==1 && + ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) ) + $filter_amount=" and j_montant between $this->fil_amount_min and $this->fil_amount_max "; + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger +$filter_deb +$filter_amount +order by j_date,j_id"; + + $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end)); + } + public function get_all() { + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger + +order by j_date,j_id"; + $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end)); + } + + public function get_letter() { + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger +and j_id in (select j_id from letter_deb join jnt_letter using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) ) +order by j_date,j_id"; + $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end)); + } + public function get_unletter() { + $sql=" +select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt, +j_montant,j_debit,jr_comment,jr_internal, +coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter + from jrnx join jrn on (j_grpt = jr_grpt_id) +where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY') +and $this->sql_ledger +and j_id not in (select j_id from letter_deb join jnt_letter using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) ) +order by j_date,j_id"; + $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end)); + } } diff --git a/include/letter.inc.php b/include/letter.inc.php index 65c9c6a06..75b017b2e 100644 --- a/include/letter.inc.php +++ b/include/letter.inc.php @@ -48,5 +48,6 @@ if ($sa == 'poste') { } if ($sa=='qc') { + require_once('lettering.card.inc.php'); exit; } diff --git a/include/lettering.account.inc.php b/include/lettering.account.inc.php index e8aae33ba..f27bd3d5a 100644 --- a/include/lettering.account.inc.php +++ b/include/lettering.account.inc.php @@ -35,7 +35,7 @@ require_once('class_lettering.php'); echo IPoste::ipopup('ipop_account'); echo '
'; - +echo ''; if (! isset($_REQUEST['seek'])) exit; echo '
'; //-------------------------------------------------------------------------------- @@ -113,6 +113,10 @@ $letter->set_parameter('end',$_GET['end']); if ( $sel->selected == 0 ) echo $letter->show_list('all'); +if ( $sel->selected == 1 ) + echo $letter->show_list('letter'); +if ( $sel->selected == 2 ) + echo $letter->show_list('unletter'); echo '
'; echo '