diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 2fdcc3500..41a5fafa2 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -31,6 +31,8 @@ * - if code is set then fill the field code * - if compute is set then add event to call clean_tva and compute_ledger @Acc_Ledger_Sold::input +* Part 2 +* dl : display form to modify, add and delete lettering for a given operation * */ require_once('class_database.php'); @@ -190,4 +192,59 @@ echo <<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, +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]; + + $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']); + + $html.=$r; + $html.=HtmlInput::submit('record',_('Sauver')).$ret->input(); + $html.='
'; + // echo $html;exit; + $html=escape_xml($html); + + header('Content-type: text/xml; charset=UTF-8'); +echo << + +detail +$html + +EOF; + + break; } diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index aeb0513ac..d283cfbb6 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -475,3 +475,48 @@ function filter_card(obj,queryString){ else { queryString=queryString+'&j='+jrn;} return queryString; } + /** + *@brief to display the lettering for the operation, call + * ajax function + *@param obj object attribut : phpsessid, gDossier,j_id,obj_type + */ +function dsp_letter(obj) { + try { + var queryString='?gDossier='+obj.gDossier+'&PHPSESSID='+obj.phpsessid+'&j_id='+obj.j_id+'&op=dl'+'&ot='+this.obj_type; + var action=new Ajax.Request( + "ajax_misc.php", + { + method:'get', + parameters:queryString, + onFailure:error_dsp_letter, + onSuccess:success_dsp_letter + } + ); + $('list').hide(); + $('detail').innerHTML=''; + $('detail').show(); + } catch(e){alert('dsp_letter '+e.message);} +} + +function success_dsp_letter(req) { + try{ + var answer=req.responseXML; + var a=answer.getElementsByTagName('code'); + var html=answer.getElementsByTagName('value'); + if ( a.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);} + var name_ctl=a[0].firstChild.nodeValue; + var code_html=getNodeText(html[0]); + code_html=unescape_xml(code_html); + $('detail').innerHTML=code_html; + } + catch (e) { + alert(e.message);} + try{ + code_html.evalScripts();} + catch(e){ + alert("Impossible executer script de la reponse\n"+e.message);} + +} +function error_dsp_letter(req) { + alert('Erreur AJAX DSP_LETTER'); +} \ No newline at end of file diff --git a/include/class_lettering.php b/include/class_lettering.php new file mode 100644 index 000000000..194a46c7e --- /dev/null +++ b/include/class_lettering.php @@ -0,0 +1,283 @@ +column_name,"email"=>"column_name_email","val3"=>0); */ + protected $variable=array("account"=>"account", + "quick_code"=>"quick_code", + "start"=>"start", + "end"=>"end", + "periode"=>"periode", + "sql_ledger"=>"sql_ledger" + ) + ; + function __construct ($p_init) { + $this->db=$p_init; + $a=new User($p_init); + $exercice=$a->get_exercice(); + $this->start='01.01.'.$exercice; + $this->end='31.12.'.$exercice; + // available ledgers + $this->sql_ledger=str_replace('jrn_def_id','jr_def_id',$a->get_ledger_sql('ALL',3)); + + } + public function get_parameter($p_string) { + if ( array_key_exists($p_string,$this->variable) ) { + $idx=$this->variable[$p_string]; + return $this->$idx; + } + else + throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant'); + } + public function set_parameter($p_string,$p_value) { + if ( array_key_exists($p_string,$this->variable) ) { + $idx=$this->variable[$p_string]; + $this->$idx=$p_value; + } + else + throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant'); + } + public function get_info() { return var_export(self::$variable,true); } + public function verify() { + // Verify that the elt we want to add is correct + } + /** + *@brief save from array + *@param $p_array +@code + 'phpsessid' => string 'a2c261a2f48b0045a8c28276afd31f5c' (length=32) + 'gDossier' => string '13' (length=2) + 'letter_j_id' => + array + 0 => string '5' (length=1) + 1 => string '23' (length=2) + 2 => string '67' (length=2) + 3 => string '136' (length=3) + 4 => string '139' (length=3) + 5 => string '145' (length=3) + 6 => string '374' (length=3) + 7 => string '148' (length=3) + 8 => string '156' (length=3) + 9 => string '254' (length=3) + 10 => string '277' (length=3) + 'ck0' => string 'on' (length=2) + 'ck1' => string 'on' (length=2) + 'ck10' => string 'on' (length=2) + 'j_id' => string '142' (length=3) + 'jnt_id' => string '-2' (length=2) + 'record' => string 'Sauver' (length=6) +@endcode + */ + 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'])); + $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)); + + // save the source + $deb=$this->db->get_value('select j_debit,j_montant from jrnx where j_id=$1',array($p_array['j_id'])); + if ( $deb == 't') { + // 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['j_id'],$jl_id)); + }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)); + } + + // 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') { + // 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 { + $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 + + $this->db->commit(); + } + /** + *@brief retrieve * row thanks a condition + */ + public function seek($cond,$p_array=null) + { + /* + $sql="select * from * where $cond"; + return $this->cn->get_array($cond,$p_array) + */ + } + public function insert() { + if ( $this->verify() != 0 ) return; + /* please adapt + $sql="insert into tva_rate (tva_label,tva_rate,tva_comment,tva_poste) ". + " values ($1,$2,$3,$4) returning tva_id"; + $this->tva_id=$this->cn->get_value( + $sql, + array($this->tva_label, + $this->tva_rate, + $this->tva_comment, + $this->tva_poste) + ); + */ + } + protected function show_not_lettered() { + } + protected function show_lettered() { + } + protected function show_all() { + $this->get_all(); + $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': + return $this->show_not_lettered(); + break; + case 'letter': + return $this->show_lettered(); + break; + } + throw new Exception ("[$p_type] is no unknown"); + } + + 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); + // retrieve jnt_letter.id + $sql="select distinct(jl_id) from jnt_letter join letter_deb using (jl_id) 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)); + + if ($this->db->count()==0 ) $jnt_id=-2; + + ob_start(); + require_once('template/letter_prop.php'); + $r=ob_get_contents(); + ob_clean(); + $r.=HtmlInput::hidden('j_id',$p_jid); + $r.=HtmlInput::hidden('jnt_id',$jnt_id); + + return $r; + } + public function update() { + if ( $this->verify() != 0 ) return; + } + + public function load() { + + $sql="select tva_label,tva_rate, tva_comment,tva_poste from tva_rate where tva_id=$1"; + if ( Database::num_row($res) == 0 ) return; + foreach ($res as $idx=>$value) { $this->$idx=$value; } + } + + public function delete() { + /* $sql="delete from tva_rate where tva_id=$1"; + $res=$this->cn->exec_sql($sql,array($this->tva_id)); + */ + } + /** + * Unit test for the class + */ + static function test_me() { + } + +} + +class Lettering_Account extends Lettering{ + function __construct($p_init,$p_account=null) { + parent::__construct($p_init); + $this->account=$p_account; + $this->object_type='account'; + } + /** + *@brief get other side + *@param $j_debit f for cred or t for debit + */ + public function get_other_side($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, +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_debit != $4 + +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=" +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 + +order by j_date,j_id"; + $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end)); + } + +} + +class Lettering_Card extends Lettering{ + function __construct($p_init,$p_account=null) { + parent::__construct($p_init); + $this->qcode=$p_qcode; + $this->object_type='card'; + } + + +} \ No newline at end of file diff --git a/include/lettering.account.inc.php b/include/lettering.account.inc.php new file mode 100644 index 000000000..e8aae33ba --- /dev/null +++ b/include/lettering.account.inc.php @@ -0,0 +1,120 @@ +'; + +echo '
'; +echo dossier::hidden(); +echo HtmlInput::phpsessid(); +echo HtmlInput::hidden('p_action','let'); +echo HtmlInput::hidden('sa','poste'); +echo ''; + +$poste=new IPoste(); +$poste->name="acc"; +$poste->table=1; +$poste->set_attribute('phpsessid',$_REQUEST['PHPSESSID']); +$poste->set_attribute('jrn',0); +$poste->set_attribute('gDossier',dossier::id()); +$poste->set_attribute('ipopup','ipop_account'); +$poste->set_attribute('label','account_label'); +$poste->set_attribute('account','acc'); +if (isset($_GET['acc'])) $poste->value=$_GET['acc']; +$poste_span=new ISpan('account_label'); +$r= td(_('Lettrage pour le poste comptable ')). + $poste->input(). + td($poste_span->input()); +echo tr($r); +// limit of the year +$exercice=$User->get_exercice(); +$periode=new Periode($cn); +list($first_per,$last_per)=$periode->get_limit($exercice); + +$start=new IDate('start'); +$start->value=(isset($_GET['start']))?$_GET['start']:$first_per->first_day(); +$r=td(_('Date début')); +$r.=td($start->input()); +echo tr($r); + +$end=new IDate('end'); +$end->value=(isset($_GET['end']))?$_GET['end']:$last_per->last_day(); +$r=td(_('Date fin')); +$r.=td($end->input()); +echo tr($r); + +// type of lettering : all, lettered, not lettered +$sel=new ISelect('type_let'); +$sel->value=array( + array('value'=>0,'label'=>_('Toutes opérations')), + array('value'=>1,'label'=>_('Opérations lettrées')), + array('value'=>2,'label'=>_('Opérations NON lettrées')) + ); +if (isset($_GET['type_let'])) $sel->selected=$_GET['type_let']; + +$r= td("Filtre "). + td($sel->input()); + +echo tr($r); +echo '
'; +echo '
'; +echo HtmlInput::submit("seek",_('Recherche')); +echo '
'; + +if (! isset($_REQUEST['seek'])) exit; +echo '
'; +//-------------------------------------------------------------------------------- +// record the data +//-------------------------------------------------------------------------------- +if ( isset($_POST['record'])) { + $letter=new Lettering_Account($cn); + $letter->save($_POST); +} +//-------------------------------------------------------------------------------- +// Show the result +//-------------------------------------------------------------------------------- +echo '
'; +$letter=new Lettering_Account($cn); +$letter->set_parameter('account',$_GET['acc']); +$letter->set_parameter('start',$_GET['start']); +$letter->set_parameter('end',$_GET['end']); + +if ( $sel->selected == 0 ) + echo $letter->show_list('all'); + +echo '
'; +echo ''; \ No newline at end of file diff --git a/include/template/letter_all.php b/include/template/letter_all.php new file mode 100644 index 000000000..2fd6e824a --- /dev/null +++ b/include/template/letter_all.php @@ -0,0 +1,49 @@ + + + + + + + + + + +content);$i++): +?> + + + + + + + + + + +
+ + + + + + + + + + + +
+content[$i]['letter']==-1)?"x":$this->content[$i]['letter']; +$js="this.gDossier=".dossier::id(). + ";this.phpsessid='".$_REQUEST['PHPSESSID']."'". + ";this.j_id=".$this->content[$i]['j_id']. + ";this.obj_type='".$this->object_type."'". + ";dsp_letter(this)"; + +?> + + content[$i]['j_date_fmt']?> content[$i]['jr_internal'])?> content[$i]['jr_comment'])?> content[$i]['j_montant']?> content[$i]['j_debit']=='t')?'D':'C'?>
\ No newline at end of file diff --git a/include/template/letter_prop.php b/include/template/letter_prop.php new file mode 100644 index 000000000..21ee28c54 --- /dev/null +++ b/include/template/letter_prop.php @@ -0,0 +1,63 @@ + + + + + + + + + + + +content);$i++): +?> + + + + + + + + + + +content[$i]['letter'] && $this->content[$i]['j_debit']=='t')?$this->content[$i]['j_montant']:0; + $amount_cred+=( $jnt_id == $this->content[$i]['letter'] && $this->content[$i]['j_debit']=='f')?$this->content[$i]['j_montant']:0; + + endfor; +?> +

+

+ +
+ + + + + + + + + + + + +
+content[$i]['j_id']); + + if ($this->content[$i]['j_id']==$p_jid) continue; +$check=new ICheckbox('ck'.$i); +if ( $jnt_id == $this->content[$i]['letter'] ) $check->selected=true; else $check->selected=false; +echo $check->input(); +?> + +content[$i]['letter']==-1)?" ":$this->content[$i]['letter']; +?> + + content[$i]['j_date_fmt']?> content[$i]['jr_internal']?> content[$i]['jr_comment']?> content[$i]['j_montant']?> content[$i]['j_debit']=='t')?'D':'C'?>
\ No newline at end of file diff --git a/include/user_menu.php b/include/user_menu.php index 64417ca9f..40edc5891 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -178,7 +178,9 @@ function ShowMenuCompta($p_high="") case 'fin': $default=3; break; - + case 'let': + $default=10; + break; } } echo_debug('user_menu.php',__LINE__,'defaut is '.$default); @@ -193,6 +195,7 @@ function ShowMenuCompta($p_high="") array("compta.php?p_action=impress&".$str_dossier,_("Impression"),_("Impression"),5), array("compta.php?p_action=fiche&".$str_dossier,_("Fiche"),_("Ajouter, modifier ou effacer des fiches"),6), + array("compta.php?p_action=let&".$str_dossier,_("Lettrage"),_("Ajouter, modifier ou effacer des lettrage"),10), array("user_advanced.php?".$str_dossier,_("Avancé"),_("Opérations délicates"),7), ); diff --git a/sql/trunk/07_lettering.sql b/sql/trunk/07_lettering.sql new file mode 100644 index 000000000..786278bf8 --- /dev/null +++ b/sql/trunk/07_lettering.sql @@ -0,0 +1,30 @@ +drop table if exists letter_deb; +drop table if exists letter_cred; +drop table if exists jnt_letter cascade; +create table jnt_letter( + jl_id serial not null, + jl_amount_deb numeric(20,4), + constraint jnt_letter_pk primary key (jl_id) + ); +create table letter_deb ( + ld_id serial, + j_id bigint not null, + jl_id bigint not null, + constraint letter_deb_pk primary key (ld_id), + constraint letter_deb_fk foreign key (j_id) references jrnx(j_id) on update cascade on delete cascade, + constraint jnt_deb_fk foreign key (jl_id) references jnt_letter(jl_id) on update cascade on delete cascade + ); + +create table letter_cred ( + lc_id serial, + j_id bigint not null, + jl_id bigint not null, + constraint letter_cred_pk primary key (lc_id), + constraint letter_cred_fk foreign key (j_id) references jrnx(j_id) on update cascade on delete cascade, + constraint jnt_cred_fk foreign key (jl_id) references jnt_letter(jl_id) on update cascade on delete cascade + ); + + +alter table jnt_letter owner to trunk; +alter table letter_deb owner to trunk; +alter table letter_cred owner to trunk; \ No newline at end of file diff --git a/sql/trunk/08_get_letter_jnt.sql b/sql/trunk/08_get_letter_jnt.sql new file mode 100644 index 000000000..964f9e301 --- /dev/null +++ b/sql/trunk/08_get_letter_jnt.sql @@ -0,0 +1,16 @@ +create or replace function comptaproc.get_letter_jnt(a bigint) returns bigint +as +$_$ +declare + nResult bigint; +begin + select jl_id into nResult from jnt_letter join letter_deb using (jl_id) where j_id = a; + if NOT FOUND then + select jl_id into nResult from jnt_letter join letter_cred using (jl_id) where j_id = a; + if NOT found then + return null; + end if; + end if; +return nResult; +end; +$_$ language plpgsql \ No newline at end of file diff --git a/sql/trunk/09_index.sql b/sql/trunk/09_index.sql new file mode 100644 index 000000000..13ac7b37e --- /dev/null +++ b/sql/trunk/09_index.sql @@ -0,0 +1,14 @@ +-- Index: xx_grpt_id + +-- DROP INDEX xx_grpt_id; + +CREATE INDEX xx_grpt_id + ON jrnx + USING btree + (j_grpt); + CREATE INDEX x_grpt_id + ON jrn + USING btree + (jr_grpt_id); +create index letter_deb_fkidx on letter_deb(j_id); +create index letter_cred_fkidx on letter_cred(j_id); \ No newline at end of file diff --git a/sql/trunk/reset.sh b/sql/trunk/reset.sh index 43d6cee2b..5be15929d 100644 --- a/sql/trunk/reset.sh +++ b/sql/trunk/reset.sh @@ -1,4 +1,12 @@ dropdb trunk_testdossier13 +dropdb trunk_testmod1 +dropdb trunk_testmod2 createdb -O trunk trunk_testdossier13 -pg_restore -U trunk -O -v -d trunk_testdossier13 ~/Desktop/base\ de\ données/alchimerysdossier2009.bin +pg_restore -U trunk -O -v -d trunk_testdossier13 ~/Desktop/base\ de\ données/alchimerysdossier2010.bin +createdb -O trunk trunk_testmod1 +createdb -O trunk trunk_testmod2 +pg_restore -U trunk -O -v -d trunk_testmod1 mod1.dmp +pg_restore -U trunk -O -v -d trunk_testmod2 mod2.dmp + +