From 26afef570a78cbd6ee899c7905ab50eee60933cc Mon Sep 17 00:00:00 2001 From: sparkyx Date: Mon, 15 Oct 2007 13:25:35 +0000 Subject: [PATCH] Add the quick / direct writing ability --- doc/developper/html/doxygen.css | 80 ++++++++--- html/compta.php | 1 + html/fid.php | 8 +- include/bank.inc.php | 2 + include/class_acc_ledger.php | 217 ++++++++++++++++++++++++------ include/class_acexception.php | 31 +++++ include/class_anc_operation.php | 7 +- include/class_fiche.php | 104 +++++++++++++- include/class_plananalytic.php | 1 + include/class_poste.php | 4 +- include/class_pre_op_ach.php | 6 + include/class_pre_op_advanced.php | 74 ++++++---- include/class_pre_op_fin.php | 5 + include/class_pre_op_ods.php | 5 + include/class_pre_op_ven.php | 5 + include/class_pre_operation.php | 35 +++-- include/class_supplier.php | 23 ++-- include/class_widget.php | 9 ++ include/depense.inc.php | 2 + include/facture.inc.php | 1 + include/fiche_inc.php | 3 + include/quick_writing.inc.php | 131 ++++++++++++++++++ include/user_action_ach.php | 3 + include/user_action_fin.php | 2 + include/user_action_ods.php | 2 + include/user_action_ven.php | 4 + include/user_menu.php | 7 +- sql/upgrade.sql | 6 +- 28 files changed, 656 insertions(+), 122 deletions(-) create mode 100644 include/class_acexception.php create mode 100644 include/quick_writing.inc.php diff --git a/doc/developper/html/doxygen.css b/doc/developper/html/doxygen.css index bfccdecde..c7db1a8a0 100644 --- a/doc/developper/html/doxygen.css +++ b/doc/developper/html/doxygen.css @@ -80,7 +80,7 @@ A.codeRef:visited { font-weight: normal; color: #0000FF} A:hover { text-decoration: none; background-color: #f2f2ff } DL.el { margin-left: -1cm } .fragment { - font-family: sans-serif; + font-family: monospace, fixed; font-size: 95%; } PRE.fragment { @@ -96,14 +96,7 @@ PRE.fragment { padding-bottom: 4px; } DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px } -TD.md { background-color: #F4F4FB; font-weight: bold; } -TD.mdPrefix { - background-color: #F4F4FB; - color: #606060; - font-size: 80%; -} -TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; } -TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; } + DIV.groupHeader { margin-left: 16px; margin-top: 12px; @@ -156,13 +149,6 @@ SPAN.comment { color: #800000 } SPAN.preprocessor { color: #806020 } SPAN.stringliteral { color: #002080 } SPAN.charliteral { color: #008080 } -.mdTable { - border: 1px solid #868686; - background-color: #F4F4FB; -} -.mdRow { - padding: 8px 10px; -} .mdescLeft { padding: 0px 8px 4px 8px; font-size: 80%; @@ -308,3 +294,65 @@ HR { height: 1px; border-top: 1px solid black; } +/* Style for detailed member documentation */ +.memtemplate { + font-size: 80%; + color: #606060; + font-weight: normal; +} +.memnav { + background-color: #e8eef2; + border: 1px solid #84b0c7; + text-align: center; + margin: 2px; + margin-right: 15px; + padding: 2px; +} +.memitem { + padding: 4px; + background-color: #eef3f5; + border-width: 1px; + border-style: solid; + border-color: #dedeee; + -moz-border-radius: 8px 8px 8px 8px; +} +.memname { + white-space: nowrap; + font-weight: bold; +} +.memdoc{ + padding-left: 10px; +} +.memproto { + background-color: #d5e1e8; + width: 100%; + border-width: 1px; + border-style: solid; + border-color: #84b0c7; + font-weight: bold; + -moz-border-radius: 8px 8px 8px 8px; +} +.paramkey { + text-align: right; +} +.paramtype { + white-space: nowrap; +} +.paramname { + color: #602020; + font-style: italic; + white-space: nowrap; +} +/* End Styling for detailed member documentation */ + +/* for the tree view */ +.ftvtree { + font-family: sans-serif; + margin:0.5em; +} +.directory { font-size: 9pt; font-weight: bold; } +.directory h3 { margin: 0px; margin-top: 1em; font-size: 11pt; } +.directory > h3 { margin-top: 0; } +.directory p { margin: 0px; white-space: nowrap; } +.directory div { display: none; margin: 0px; } +.directory img { vertical-align: -30%; } diff --git a/html/compta.php b/html/compta.php index 82f22a925..fbfbd883e 100644 --- a/html/compta.php +++ b/html/compta.php @@ -43,6 +43,7 @@ include_once ("user_menu.php"); echo '
'; $action=$_REQUEST['p_action']; echo ShowMenuCompta("user_advanced.php?".dossier::get()); + echo '
'; // Get action diff --git a/html/fid.php b/html/fid.php index 3c44327d2..98a8b3e7a 100644 --- a/html/fid.php +++ b/html/fid.php @@ -1,10 +1,10 @@ '; $op=new Pre_operation($cn); $op->p_jrn=$p_jrn; + $op->od_direct='f'; + $hid=new widget("hidden"); echo $hid->IOValue("p_action","bank"); echo $hid->IOValue("sa","use_opd"); diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index c92299703..4a51910bd 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -28,6 +28,8 @@ require_once ('class_acc_operation.php'); require_once ('class_poste.php'); require_once ('class_pre_op_advanced.php'); require_once ('jrn.php'); +require_once ('class_acexception.php'); + /*!\brief Class for jrn * */ @@ -114,8 +116,8 @@ class Acc_Ledger { if ( $this->id != 0 ) { if ( $cent=='off' ) { - echo_debug('class_acc_ledger.php',__LINE__,"journaux non centralisé"); - // Journaux non centralisés + echo_debug('class_acc_ledger.php',__LINE__,"journaux non centralisé"); + // Journaux non centralisés $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, jr_internal, case j_debit when 't' then j_montant::text else ' ' end as deb_montant, @@ -131,8 +133,8 @@ class Acc_Ledger { " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ". $cond_limite); }else { - // Journaux centralisés - // echo'class_acc_ledger.php',__LINE__,"journaux centralisé"; + // Journaux centralisés + // echo'class_acc_ledger.php',__LINE__,"journaux centralisé"; $Sql="select jr_opid as j_id, c_order as int_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , @@ -161,8 +163,8 @@ class Acc_Ledger { } else { // Grand Livre if ( $cent == 'off') { - echo_debug('class_acc_ledger.php',__LINE__,"Grand livre non centralisé"); - // Non centralisé + echo_debug('class_acc_ledger.php',__LINE__,"Grand livre non centralisé"); + // Non centralisé $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, jr_internal, case j_debit when 't' then j_montant::text else ' ' end as deb_montant, @@ -178,8 +180,8 @@ class Acc_Ledger { $cond_limite); } else { - echo_debug('class_acc_ledger.php',__LINE__,"Grand livre centralisé"); - // Centralisé + echo_debug('class_acc_ledger.php',__LINE__,"Grand livre centralisé"); + // Centralisé $Sql="select jr_c_opid as j_id, c_order as int_j_id, c_j_id, @@ -321,7 +323,7 @@ class Acc_Ledger { // Non Centralise si cent=off //-- if ($cent=='off') - {// Non centralisé + {// Non centralisé $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); @@ -348,7 +350,7 @@ class Acc_Ledger { $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; - //Centralisé + //Centralisé //--- $id=($this->id == 0 ) ?"jr_c_opid as num":"jr_opid as num"; @@ -694,7 +696,7 @@ class Acc_Ledger { $res=pg_fetch_all($r); if ( empty($res) ) return null; - print_r($res); + return $res[0]; } /*! @@ -711,11 +713,11 @@ class Acc_Ledger { $sql="select jrn_def_class_cred ". " from jrn_def where ". " jrn_def_id = ".$this->id; - print_r($sql); + $r=ExecSql($this->db,$sql); $res=pg_fetch_all($r); - print_r($res); + if ( empty($res) ) return null; return $res[0]; } @@ -755,11 +757,13 @@ class Acc_Ledger { $ret.=$hidden->IOValue('p_jrn',$this->id); $ret.=$hidden->IOValue('nb_item',$this->nb); $ret.=dossier::hidden(); + $count=0; for ($i=0;$i<$this->nb;$i++) { $ret.=""; if ( trim(${'qc_'.$i})!="") { $oqc=new fiche($this->db); $oqc->GetByQCode(${'qc_'.$i},false); + $strPoste=$oqc->strAttribut(ATTR_DEF_ACCOUNT); $ret.="".${'qc_'.$i}.' - '. $oqc->strAttribut(ATTR_DEF_NAME).$hidden->IOValue('qc_'.$i,${'qc_'.$i}). ''; @@ -767,6 +771,7 @@ class Acc_Ledger { if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "") { $oposte=new poste($this->db,${'poste'.$i}); + $strPoste=$oposte->id; $ret.="".${"poste".$i}." - ". $oposte->GetName().$hidden->IOValue('poste'.$i,${'poste'.$i}). ''; @@ -784,12 +789,15 @@ class Acc_Ledger { if ( $own->MY_ANALYTIC!='nu') // use of AA { - // show form - $op=new Anc_Operation($this->db); - $null=($own->MY_ANALYTIC=='op')?1:0; - $ret.=''; - $ret.=$op->display_form_plan(null,$null,1,$i,round(${'amount'.$i},2)); - $ret.=''; + if ( ereg("^[6,7]+",$strPoste)) { + // show form + $op=new Anc_Operation($this->db); + $null=($own->MY_ANALYTIC=='op')?1:0; + $ret.=''; + $ret.=$op->display_form_plan(null,$null,1,$count,round(${'amount'.$i},2)); + $ret.=''; + $count++; + } } @@ -877,8 +885,8 @@ class Acc_Ledger { $poste->readonly=$p_readonly; $poste->extra=$this->id; $poste->extra2=$this->get_class_def(); - echo "get_class_Def returns"; - print_r($poste->extra2); + + $poste_span=new widget('span','','poste'.$i.'_label'); // Amount @@ -890,7 +898,7 @@ class Acc_Ledger { // D/C $deb=new widget('checkbox'); $deb->name='ck'.$i; - $deb->value=(isset(${'ck'.$i}))?${"ck".$i}:''; + $deb->selected=(isset(${'ck'.$i}))?true:false; $deb->readonly=$p_readonly; $ret.=''; @@ -906,20 +914,92 @@ class Acc_Ledger { $ret.=''; return $ret; } +/*! + * \brief verify that the operation can be saved + * \param $p_array array of data same layout that the $_POST from show_form + * + * + * \return the return value are 0 ok,1 incorrect balance, 2 date + * invalid, 3 invalid amount, 4 the card is not in the range of + * permitted card, 5 not in the user's period, 6 closed period + * + */ + function verify($p_array) + { + extract ($p_array); + $user=new cl_user($this->db); + + $tot_cred=0;$tot_deb=0; + // Check the periode and the date + if ( isDate($date) == null ) { + throw new AcException('Date invalide', 2); + } + list ($l_date_start,$l_date_end)=GetPeriode($this->db,$user->GetPeriode()); + + // Date dans la periode active + if ( cmpDate($date,$l_date_start)<0 || + cmpDate($date,$l_date_end)>0 ) + { + throw new AcException('Pas dans la periode active',5); + } + // Periode ferm� + if ( PeriodeClosed ($this->db,$user->GetPeriode())=='t' ) + { + return new AcException('Periode fermee',6); + } + + for ($i=0;$i<$this->nb;$i++) + { + $err=0; + + // Check the balance + if ( ! isset (${'amount'.$i})) + continue; + + if ( isNumber(${'amount'.$i} ) == 0 ) + throw new AcException('Montant invalide',3); + + $amount=round(${'amount'.$i},2); + $tot_deb+=(isset(${'ck'.$i}))?$amount:0; + $tot_cred+=(! isset(${'ck'.$i}))?$amount:0; + + // Check if the card is permitted + if ( isset (${'qc_'.$i}) && trim(${'qc_'.$i}) !="") { + $f=new fiche($this->db); + $f->quick_code=${'qc_'.$i}; + + if ( $f->belong_ledger($p_jrn) < 0 ) + throw new AcException("La fiche quick_code = ". + $f->quick_code." n\'est pas dans ce journal",4); + } + + // Check if the account is permitted + if ( isset (${'poste'.$i})) { + $p=new poste($this->db,${'poste'.$i}); + if ( $p->belong_ledger ($p_jrn) < 0 ) + throw new AcException("Le poste ".$p->id." n\'est pas dans ce journal",5); + } + + + } + if ( $tot_deb != $tot_cred ) + throw new AcException("Balance incorrecte debit = $tot_deb credit=$tot_cred ",1); + + } + /*! * \brief save the operation into the jrnx,jrn, , * CA and pre_def - * \param - * \param - * \param - * + * \param $p_array * - * \return + * \return array with [0] = false if failed otherwise true, [1] error + * code */ function save ($p_array) { extract ($p_array); - try { + $this->verify($p_array); + StartSql($this->db) ; $seq=NextSequence($this->db,'s_grpt'); @@ -928,6 +1008,8 @@ class Acc_Ledger { $group=NextSequence($this->db,"s_oa_group"); $own=new own($this->db); $tot_amount=0; + + $count=0; for ($i=0;$i<$this->nb;$i++) { if ( ! isset (${'qc_'.$i}) && ! isset(${'poste'.$i})) @@ -946,7 +1028,7 @@ class Acc_Ledger { } $acc_op->date=$date; $acc_op->desc=$desc; - $acc_op->amount=${'amount'.$i}; + $acc_op->amount=round(${'amount'.$i},2); $acc_op->grpt=$seq; $acc_op->poste=$poste; $acc_op->jrn=$this->id; @@ -957,14 +1039,18 @@ class Acc_Ledger { if ( $own->MY_ANALYTIC != "nu" ) { - // for each item, insert into operation_analytique */ - $op=new Anc_Operation($this->db); - $op->oa_group=$group; - $op->j_id=$j_id; - $op->oa_date=$date; - $op->oa_debit=($acc_op->type=='d' )?'t':'f'; - $op->oa_description=$desc; - $op->save_form_plan($p_array,$i); + if ( ereg("^[6,7]+",$poste)) { + + // for each item, insert into operation_analytique */ + $op=new Anc_Operation($this->db); + $op->oa_group=$group; + $op->j_id=$j_id; + $op->oa_date=$date; + $op->oa_debit=($acc_op->type=='d' )?'t':'f'; + $op->oa_description=$desc; + $op->save_form_plan($p_array,$count); + $count++; + } } } $acc_end=new Acc_Operation($this->db); @@ -986,7 +1072,11 @@ class Acc_Ledger { $opd->get_post(); $opd->save(); } - } catch (Exception $e) { + } + catch (AcException $a) { + throw $a; + } + catch (Exception $e) { Rollback($this->db); echo 'OPERATION ANNULEE '; echo '
'; @@ -994,6 +1084,7 @@ class Acc_Ledger { exit(); } Commit($this->db); + return true; } /*! @@ -1025,8 +1116,10 @@ class Acc_Ledger { $cn=DbConnect(dossier::id()); $_SESSION['g_user']='phpcompta'; $_SESSION['g_pass']='phpcompta'; - $id=(isset ($_POST['p_jrn']))?$_POST['p_jrn']:-1; + + $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; $a=new Acc_Ledger($cn,$id); + // Vide echo '
'; echo $a->select_ledger()->IOValue(); echo widget::submit_button('go','Test it'); @@ -1037,17 +1130,61 @@ class Acc_Ledger { echo $a->show_form(); echo widget::submit_button('post_id','Try me'); echo '
'; + // Show the predef operation + // Don't forget the p_jrn + echo '
'; + echo dossier::hidden(); + echo ''; + $op=new Pre_operation($cn); + $op->p_jrn=$id; + $op->od_direct='t'; + if ($op->count() != 0 ) + echo widget::submit_button('use_opd','Utilisez une op.prédéfinie'); + echo $op->show_button(); + echo '
'; + exit(); } + if ( isset($_POST['post_id' ])) { echo '
'; echo $a->show_form($_POST,1); echo widget::submit_button('save_it',"Sauver"); echo '
'; + exit(); } if ( isset($_POST['save_it' ])) { + print 'saving'; $array=$_POST; $array['save_opd']=1; - $a->save($array); + try { + $a->save($array); + } catch (AcException $e) { + echo '"; + echo '
'; + + echo $a->show_form($_POST); + echo widget::submit_button('post_id','Try me'); + echo '
'; + + } + exit(); + } + // The GET at the end because automatically repost when you don't + // specify the url in the METHOD field + if ( isset ($_GET['use_opd'])) { + $op=new Pre_op_advanced($cn); + $op->set_od_id($_REQUEST['pre_def']); + //$op->p_jrn=$id; + + $p_post=$op->compute_array(); + + echo '
'; + + echo $a->show_form($p_post); + echo widget::submit_button('post_id','Use predefined operation'); + echo '
'; + exit(); + } } diff --git a/include/class_acexception.php b/include/class_acexception.php new file mode 100644 index 000000000..10833e266 --- /dev/null +++ b/include/class_acexception.php @@ -0,0 +1,31 @@ +db); $a_plan=$plan->get_list(); - + if ( empty ($a_plan) ) return ""; $table_id="t".$p_seq; $hidden=new widget("hidden"); @@ -400,6 +400,7 @@ function get_balance($p_from,$p_to,$p_plan_id) for ( $i=1; $i <= $nb_row;$i++) { $result.=''; $count=0; + foreach ($a_plan as $r_plan) { $count++; @@ -475,8 +476,8 @@ function get_balance($p_from,$p_to,$p_plan_id) echo_debug(__FILE__.':'.__LINE__,"p_array is ",$p_array); extract($p_array); if ( !isset (${"nb_t".$p_item}) ) { - echo __FILE__.':'.__LINE."nb_t".$p_item." n'est pas defini !!!"; - exit(); + // echo __FILE__.':'.__LINE."nb_t".$p_item." n'est pas defini !!!"; + return; } $max=${"nb_t".$p_item}; echo_debug(__FILE__.':'.__LINE__.'- ', "max of row for CA = ".$max); diff --git a/include/class_fiche.php b/include/class_fiche.php index 2daedb0bc..26093d9c2 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -43,21 +43,25 @@ class fiche { var $attribut; /*! < $attribut array of attribut object */ var $fiche_def_ref; /*!< $fiche_def_ref Type */ var $row; /*! < All the row from the ledgers */ + var $quick_code; /*!< quick_code of the card */ function fiche($p_cn,$p_id=0) { $this->cn=$p_cn; $this->id=$p_id; + $this->quick_code=''; } /*! GetByQCode($p_qcode) * \brief Retrieve a card thx his quick_code - * complete the object + * complete the object,, set the id member of the object * \param $p_qcode quick_code (ad_id=23) * \param $p_all retrieve all the attribut of the card, possible value * are true, false retrieve only the f_id * \return 0 success 1 error not found */ - function GetByQCode($p_qcode,$p_all=true) + function GetByQCode($p_qcode=null,$p_all=true) { + if ( $p_qcode == null ) + $p_qcode=$this->quick_code; $p_qcode=FormatString($p_qcode); $sql="select f_id from jnt_fic_att_value join attr_value @@ -65,6 +69,7 @@ class fiche { $Res=ExecSql($this->cn,$sql); $r=pg_fetch_all($Res); echo_debug('fiche',__LINE__,'result:'.var_export($r,true).'size '.sizeof($r)); + if ( $r == null ) return 1; $this->id=$r[0]['f_id']; @@ -734,6 +739,21 @@ class fiche { return 1; return $r[0]['av_text']; } + + /*!\brief return the quick_code of a card + * \return null if not quick_code is found + */ + function get_quick_code() + { + $sql="select av_text from jnt_fic_att_value join attr_value + using (jft_id) where ad_id=23 and f_id=".$this->id; + $Res=ExecSql($this->cn,$sql); + $r=pg_fetch_all($Res); + if ( sizeof($r) == 0 ) + return null; + return $r[0]['av_text']; + } + /*!\brief Synonum of fiche::getAttribut */ function Get() @@ -947,5 +967,85 @@ function GetSoldeDetail($p_cond="") { else $this->fd_id=$R; } +/*! + *************************************************** + * \brief Check if a fiche is used by a jrn + * return 1 if the fiche is in the range otherwise 0, the quick_code + * or the id must be set + * + * + * \param $j_jrn journal_id + * \param $p_type : deb or cred default empty + * + *\todo fiche::belong_ledger this function will replace fiche_inc.php + *function isFicheOfJrn , it should be replaced everywhere in the code + * + * \return 1 if the fiche is in the range otherwise < 1 + * -1 the card doesn't exist + * -2 the ledger has no card to check + * + */ +function belong_ledger($p_jrn,$p_type="") +{ + // check if we have a quick_code or a f_id + if (($this->quick_code==null || $this->quick_code == "" ) + && $this->id == 0 ) { + echo 'erreur ni quick_code ni f_id ne sont donnes'; + exit(); + } + + //retrieve the quick_code + if ( $this->quick_code=="") + $this->quick_code=$this->get_quick_code(); + + + if ( $this->quick_code==null) + return -1; + + if ( $this->id == 0 ) + if ( $this->GetByQCode(null,false) == 1) + return -1; + + $get=""; + if ( $p_type == 'deb' ) { + $get='jrn_def_fiche_deb'; + } + if ( $p_type == 'cred' ) { + $get='jrn_def_fiche_cred'; + } + if ( $get != "" ) { + $Res=ExecSql($this->cn,"select $get as fiche from jrn_def where jrn_def_id=$p_jrn"); + } else { + // Get all the fiche type (deb and cred) + $Res=ExecSql($this->cn," select jrn_def_fiche_cred as fiche + from jrn_def where jrn_def_id=$p_jrn + union + select jrn_def_fiche_deb + from jrn_def where jrn_def_id=$p_jrn" + ); + } + $Max=pg_NumRows($Res); + if ( $Max==0) { + return -2; + } + // Normally Max must be == 1 + $list=pg_fetch_array($Res,0); + if ( $list['fiche']=="") { + return -3; + } + + $sql="select * + from fiche + where + fd_id in (".$list['fiche'].") and f_id= ".$this->id; + + $Res=ExecSql($this->cn,$sql); + $Max=pg_NumRows($Res); + if ($Max==0 ) + return 0; + else + return 1; +} + } ?> diff --git a/include/class_plananalytic.php b/include/class_plananalytic.php index 73401e672..016490b2c 100644 --- a/include/class_plananalytic.php +++ b/include/class_plananalytic.php @@ -160,6 +160,7 @@ class PlanAnalytic function header() { $res=""; $a_plan=$this->get_list(); + if ( empty($a_plan)) return ""; foreach ($a_plan as $r_plan) { $res.="".$r_plan['name'].""; diff --git a/include/class_poste.php b/include/class_poste.php index 931bcf5fd..bd5e5c620 100644 --- a/include/class_poste.php +++ b/include/class_poste.php @@ -286,7 +286,7 @@ function GetSoldeDetail($p_cond="") { /*! * \brief verify that the poste belong to a ledger * - * \return 0 ok, -1 no, -2 account doesn't exist + * \return 0 ok, -1 no */ function belong_ledger($p_jrn) { $filter=getDbValue($this->db,"select jrn_def_class_cred from jrn_def where jrn_def_id=$p_jrn"); @@ -317,7 +317,7 @@ function GetSoldeDetail($p_cond="") { if ($max > 0 ) return 0; else - return 1; + return -1; } static function test_me() { $cn=DbConnect(dossier::id()); diff --git a/include/class_pre_op_ach.php b/include/class_pre_op_ach.php index f2f229165..f6dc509d1 100644 --- a/include/class_pre_op_ach.php +++ b/include/class_pre_op_ach.php @@ -29,10 +29,16 @@ require_once ('class_pre_operation.php'); /*---------------------------------------------------------------------- */ class Pre_op_ach extends Pre_operation_detail { var $op; + function __construct($cn) { + parent::__construct($cn); + + $this->operation->od_direct='f'; + } function get_post() { echo_debug(__FILE__.':'.__LINE__.'- ','get_post'); parent::get_post(); + $this->operation->od_direct='f'; $this->e_client=$_POST['e_client']; for ($i=0;$i<$this->operation->nb_item;$i++) { $march="e_march".$i; diff --git a/include/class_pre_op_advanced.php b/include/class_pre_op_advanced.php index ffdd5dab4..1513fd58c 100644 --- a/include/class_pre_op_advanced.php +++ b/include/class_pre_op_advanced.php @@ -29,17 +29,23 @@ require_once ('class_pre_operation.php'); /*---------------------------------------------------------------------- */ class Pre_Op_Advanced extends Pre_operation_detail { var $op; - + function Pre_Op_Advanced($cn) { + parent::__construct($cn); + $this->operation->od_direct='t'; + } function get_post() { echo_debug(__FILE__.':'.__LINE__.'- ','get_post'); parent::get_post(); - // For advanced we use +5000 - $this->operation->p_jrn+=5000; + extract($_POST); + for ($i=0;$i<$this->operation->nb_item;$i++) { + if ( ! isset ($_POST['poste'.$i]) && ! isset ($_POST['qc_'.$i])) + continue; $this->{'poste'.$i}=(isset($_POST['qc_'.$i]))?$_POST['qc_'.$i]:$_POST['poste'.$i]; + $this->{'isqc'.$i}=(isset($_POST['qc_'.$i]))?'t':'f'; $this->{"amount".$i}=$_POST['amount'.$i]; - $this->{"ck".$i}=($_POST['ck'.$i]=='c')?'t':'f'; + $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f'; } } @@ -54,16 +60,22 @@ class Pre_Op_Advanced extends Pre_operation_detail { return; // save the selling for ($i=0;$i<$this->operation->nb_item;$i++) { - $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'. - 'opd_debit,od_id)'. - ' values '. - "('%s',%.2f,%d,%f,'%s',%d)", - $this->{"poste".$i}, - $this->{"amount".$i}, - $this->{"ck".$i}, - $this->operation->od_id - ); - ExecSql($this->db,$sql); + if ( ! isset ($this->{"poste".$i})) + continue; + + $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'. + 'opd_debit,od_id,opd_qc)'. + ' values '. + "('%s',%.2f,'%s',%d,'%s')", + $this->{"poste".$i}, + $this->{"amount".$i}, + $this->{"ck".$i}, + $this->operation->od_id, + $this->{'isqc'.$i} + ); + + ExecSql($this->db,$sql); + } } catch (Exception $e) { echo ($e->getMessage()); @@ -77,27 +89,37 @@ class Pre_Op_Advanced extends Pre_operation_detail { $count=0; $a_op=$this->operation->load(); $array=$this->operation->compute_array($a_op); + $array['desc']=$array['e_comm']; $p_array=$this->load(); foreach ($p_array as $row) { - if ( $row['opd_debit']=='t') { - $array+=array('e_client'=>$row['opd_poste']); - } else { - $array+=array("e_march".$count=>$row['opd_poste'], - "e_march".$count."_sell"=>$row['opd_amount'], - "e_march".$count."_tva_id"=>$row['opd_tva_id'], - "e_quant".$count=>$row['opd_quantity'] - ); - $count++; - } + $tmp_array=array("qc_".$count=>'', + "poste".$count=>'', + "amount".$count=>$row['opd_amount'], + 'ck'.$count=>$row['opd_debit'] + ); + + if ( $row['opd_qc'] == 't' ) + $tmp_array['qc_'.$count]=$row['opd_poste']; + else + $tmp_array['poste'.$count]=$row['opd_poste']; + + + if ( $row['opd_debit'] == 'f' ) + unset ($tmp_array['ck'.$count]); + + $array+=$tmp_array; + $count++; + } + return $array; } /*!\brief load the data from the database and return an array * \return an array */ function load() { - $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,". - " opd_quantity from op_predef_detail where od_id=".$this->operation->od_id. + $sql="select opd_id,opd_poste,opd_amount,opd_debit,". + " opd_qc from op_predef_detail where od_id=".$this->operation->od_id. " order by opd_id"; $res=ExecSql($this->db,$sql); $array=pg_fetch_all($res); diff --git a/include/class_pre_op_fin.php b/include/class_pre_op_fin.php index daff804fd..23f710ee3 100644 --- a/include/class_pre_op_fin.php +++ b/include/class_pre_op_fin.php @@ -29,10 +29,15 @@ require_once ('class_pre_operation.php'); /*---------------------------------------------------------------------- */ class Pre_op_fin extends Pre_operation_detail { var $op; + function __construct($cn) { + parent::__construct($cn); + $this->operation->od_direct='f'; + } function get_post() { echo_debug(__FILE__.':'.__LINE__.'- ','get_post'); parent::get_post(); + $this->operation->od_direct='f'; $this->e_bank_account=$_POST['e_bank_account']; for ($i=0;$i<$this->operation->nb_item;$i++) { $this->{"e_other".$i}=$_POST['e_other'.$i]; diff --git a/include/class_pre_op_ods.php b/include/class_pre_op_ods.php index fcd103346..ce7d90f67 100644 --- a/include/class_pre_op_ods.php +++ b/include/class_pre_op_ods.php @@ -29,10 +29,15 @@ require_once ('class_pre_operation.php'); /*---------------------------------------------------------------------- */ class Pre_op_ods extends Pre_operation_detail { var $op; + function __construct($cn) { + parent::__construct($cn); + $this->operation->od_direct='f'; + } function get_post() { echo_debug(__FILE__.':'.__LINE__.'- ','get_post'); parent::get_post(); + $this->operation->od_direct='f'; for ($i=0;$i<$this->operation->nb_item;$i++) { $this->{"e_account".$i}=$_POST['e_account'.$i]; diff --git a/include/class_pre_op_ven.php b/include/class_pre_op_ven.php index ffa90a4aa..a401591a9 100644 --- a/include/class_pre_op_ven.php +++ b/include/class_pre_op_ven.php @@ -29,10 +29,15 @@ require_once ('class_pre_operation.php'); /*---------------------------------------------------------------------- */ class Pre_op_ven extends Pre_operation_detail { var $op; + function __construct($cn) { + parent::__construct($cn); + $this->operation->od_direct='f'; + } function get_post() { echo_debug(__FILE__.':'.__LINE__.'- ','get_post'); parent::get_post(); + $this->operation->od_direct='f'; $this->e_client=$_POST['e_client']; for ($i=0;$i<$this->operation->nb_item;$i++) { $march="e_march".$i; diff --git a/include/class_pre_operation.php b/include/class_pre_operation.php index e5245d863..dcb225536 100644 --- a/include/class_pre_operation.php +++ b/include/class_pre_operation.php @@ -53,7 +53,8 @@ class Pre_operation } } function delete () { - $sql="delete from op_predef where od_id=".$this->od_id; + $sql="delete from op_predef where od_id=".$this->od_id. + " and od_direct ='".$this->od_direct."'"; ExecSql($this->db,$sql); } /*!\brief save the predef check first is the name is unique @@ -72,13 +73,14 @@ class Pre_operation echo '

Vous avez atteint le max. d\'opération prédéfinie, désolé

'; return false; } - $sql=sprintf('insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type)'. + $sql=sprintf('insert into op_predef (jrn_def_id,od_name,od_item,od_jrn_type,od_direct)'. 'values'. - "(%d,'%s',%d,'%s')", + "(%d,'%s',%d,'%s','%s')", $this->p_jrn, pg_escape_string($this->name), $this->nb_item, - $this->jrn_type); + $this->jrn_type, + $this->od_direct); ExecSql($this->db,$sql); $this->od_id=GetSequence($this->db,'op_def_op_seq'); return true; @@ -88,7 +90,9 @@ class Pre_operation */ function load() { $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type". - " from op_predef where od_id=".$this->od_id." order by od_name"; + " from op_predef where od_id=".$this->od_id. + " and od_direct='".$this->od_direct."'". + " order by od_name"; $res=ExecSql($this->db,$sql); $array=pg_fetch_all($res); echo_debug(__FILE__.':'.__LINE__.'- ','load pre_op',$array); @@ -112,8 +116,10 @@ class Pre_operation $select=new widget("select"); $value=make_array($this->db,"select od_id,od_name from op_predef ". - " where jrn_def_id=".$this->p_jrn. - " order by od_name"); + " where jrn_def_id=".$this->p_jrn. + " and od_direct ='".$this->od_direct."'". + " order by od_name"); + if ( empty($value)==true) return ""; $select->value=$value; $r=$select->IOValue("pre_def"); @@ -122,17 +128,19 @@ class Pre_operation /*!\brief count the number of pred operation for a ledger */ function count() { $a=CountSql($this->db,"select od_id,od_name from op_predef ". - " where jrn_def_id=".$this->p_jrn. - " order by od_name"); + " where jrn_def_id=".$this->p_jrn. + " and od_direct ='".$this->od_direct."'". + " order by od_name"); return $a; } /*!\brief get the list of the predef. operation of a ledger * \return string */ function get_list_ledger() { - $sql="select od_id,od_name from op_predef ". - " where jrn_def_id=".$this->p_jrn. - " order by od_name"; + $sql="select od_id,od_name from op_predef ". + " where jrn_def_id=".$this->p_jrn. + " and od_direct ='".$this->od_direct."'". + " order by od_name"; $res=ExecSql($this->db,$sql); $all=pg_fetch_all($res); return $all; @@ -143,11 +151,12 @@ class Pre_operation } class Pre_operation_detail { var $operation; - function Pre_operation_detail($p_cn) { + function __construct($p_cn) { $this->db=$p_cn; $this->operation=new Pre_operation($this->db); } + function get_post() { $this->operation->get_post(); } diff --git a/include/class_supplier.php b/include/class_supplier.php index 52ebc6b4a..9ecc2b8db 100644 --- a/include/class_supplier.php +++ b/include/class_supplier.php @@ -70,19 +70,16 @@ class Supplier extends fiche{ } -/*! \function Summary +/*! ************************************************** - \Brief show the default screen + * \brief show the default screen * - * parm : - * - p_search (filter) - * gen : - * - - * return: string to display + * \param p_search (filter) + * \return string to display */ function Summary($p_search) { - $str_dossier=dossier::get(); + $str_dossier=dossier::get(); $p_search=FormatString($p_search); $url=urlencode($_SERVER['REQUEST_URI']); $script=$_SERVER['PHP_SELF']; @@ -143,14 +140,14 @@ class Supplier extends fiche{ $r.=sprintf(' %15.2f€',$a['solde']); - $r.=sprintf('Contact', - $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE),$url); - $r.=sprintf('Courrier ', - $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE) ,$url); + $r.=sprintf('Contact', + $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE),$str_dossier,$url); + $r.=sprintf('Courrier ', + $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE) ,$str_dossier,$url); - $r.='Facture'; + $r.='Facture'; $r.=sprintf('Financier', $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE) ,$url); diff --git a/include/class_widget.php b/include/class_widget.php index 22f12ac51..30ad3e6c2 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -567,6 +567,7 @@ class widget { return $r; } + //------------------------------------------------------------------------ // JS_DATE //------------------------------------------------------------------------ @@ -629,5 +630,13 @@ class widget { function Reset ($p_value) { return ''; } + static function hidden($p_name,$p_value) { + return ''; + } + static function button_href($p_name,$p_value) { + return sprintf('', + $p_value, + $p_name); + } } diff --git a/include/depense.inc.php b/include/depense.inc.php index 057a61081..5d64b1577 100644 --- a/include/depense.inc.php +++ b/include/depense.inc.php @@ -328,6 +328,8 @@ if ( $p_jrn != -1 ) echo '
'; $op=new Pre_operation($cn); $op->p_jrn=$p_jrn; + $op->od_direct='f'; + $hid=new widget("hidden"); echo $hid->IOValue("p_action","depense"); echo dossier::hidden(); diff --git a/include/facture.inc.php b/include/facture.inc.php index 8aeb39878..5a4555dab 100644 --- a/include/facture.inc.php +++ b/include/facture.inc.php @@ -314,6 +314,7 @@ if ( $p_jrn != -1 ) echo ''; $op=new Pre_operation($cn); $op->p_jrn=$p_jrn; + $op->od_direct='f'; $hid=new widget("hidden"); echo $hid->IOValue("p_action","facture"); echo dossier::hidden(); diff --git a/include/fiche_inc.php b/include/fiche_inc.php index 9c95ca8cb..4aa6c75c6 100644 --- a/include/fiche_inc.php +++ b/include/fiche_inc.php @@ -223,6 +223,9 @@ function getFicheAttribut($p_cn,$p_id,$p_attr="") { * \param $p_fiche : quick_code * \param $p_type : deb or cred default empty * + *\todo fiche_inc.php function isFicheOfJrn this function is now in + * class_fiche with the name belong_ledger, it should be replace + * everywhere in the code * * \return 1 if the fiche is in the range otherwise 0 * diff --git a/include/quick_writing.inc.php b/include/quick_writing.inc.php new file mode 100644 index 000000000..f881b4db8 --- /dev/null +++ b/include/quick_writing.inc.php @@ -0,0 +1,131 @@ +'; + echo dossier::hidden(); + echo widget::hidden('p_action',$_REQUEST['p_action']); + + echo ''; + $op=new Pre_operation($cn); + $op->p_jrn=$id; + $op->od_direct='t'; + if ($op->count() != 0 ) + echo widget::submit_button('use_opd','Utilisez une op.prédéfinie'); + echo $op->show_button(); + echo '
'; + + echo '
'; + echo dossier::hidden(); + echo widget::hidden('p_action',$_REQUEST['p_action']); + + echo $ledger->show_form($p_array); + + echo widget::submit_button('summary','Sauvez'); + + + echo '
'; + + echo ''; +} + +$ledger=new Acc_Ledger($cn,$id); +// no ledger selected, propose one +if ($id == -1 ) + { + + // Vide + echo '
'; + echo dossier::hidden(); + echo widget::hidden('p_action',$_REQUEST['p_action']); + echo $ledger->select_ledger()->IOValue(); + echo widget::submit_button('show_form','Choix du journal'); + echo '
'; + exit(); + } +echo '
'; +echo '

Journal : '.$ledger->GetName().'

'; +echo widget::button_href('Autre journal','?p_action='.$_REQUEST['p_action'].'&'.dossier::get()); + +if ( isset($_GET['show_form']) || isset($_POST['correct_it']) ) { + show_direct_form($cn,$ledger,$_POST); + exit(); + } + +// reload with a predefined operation +// +if ( isset ($_GET['use_opd'])) { + $op=new Pre_op_advanced($cn); + $op->set_od_id($_REQUEST['pre_def']); + //$op->p_jrn=$id; + + $p_post=$op->compute_array(); + show_direct_form($cn,$ledger,$p_post); + + exit(); + + } +if ( isset($_POST['summary'])) { + echo '
'; + echo $ledger->show_form($_POST,1); + echo dossier::hidden(); + echo widget::hidden('p_action',$_REQUEST['p_action']); + + echo widget::submit_button('save_it',"Sauver"); + echo widget::submit_button('correct_it','Corriger'); + + $chk=new widget('checkbox'); + $chk->selected=false; + echo "Sauvez l'opération ?"; + echo $chk->IOValue('save_opd'); + + echo '
'; + exit(); + + } +if ( isset($_POST['save_it' ])) { + $array=$_POST; + + try { + $ledger->save($array); + } catch (AcException $e) { + echo '"; + show_direct_form($cn,$ledger,$_POST); + } + exit(); + } diff --git a/include/user_action_ach.php b/include/user_action_ach.php index dd35727f9..a02db288d 100644 --- a/include/user_action_ach.php +++ b/include/user_action_ach.php @@ -77,6 +77,7 @@ if ( $action == 'new' ) { // predef op. $op=new Pre_operation($cn); $op->p_jrn=$_GET['p_jrn']; + $op->od_direct='f'; echo '
'; echo $r; @@ -86,6 +87,8 @@ if ( $action == 'new' ) { echo '
'; $op=new Pre_operation($cn); $op->p_jrn=$_GET['p_jrn']; + $op->od_direct='f'; + $hid=new widget("hidden"); echo $hid->IOValue("action","use_opd"); echo dossier::hidden(); diff --git a/include/user_action_fin.php b/include/user_action_fin.php index a3746eaf2..0aff0b6ce 100644 --- a/include/user_action_fin.php +++ b/include/user_action_fin.php @@ -86,6 +86,8 @@ if ( $action == 'new' ) { echo ''; $op=new Pre_operation($cn); $op->p_jrn=$_GET['p_jrn']; + $op->od_direct='f'; + $hid=new widget("hidden"); echo $hid->IOValue("action","use_opd"); echo dossier::hidden(); diff --git a/include/user_action_ods.php b/include/user_action_ods.php index e30d6d5c1..a19d6dc4b 100644 --- a/include/user_action_ods.php +++ b/include/user_action_ods.php @@ -88,6 +88,8 @@ if ( $action == 'new' ) { echo ''; $op=new Pre_operation($cn); $op->p_jrn=$_GET['p_jrn']; + $op->od_direct='f'; + $hid=new widget("hidden"); echo $hid->IOValue("action","use_opd"); echo dossier::hidden(); diff --git a/include/user_action_ven.php b/include/user_action_ven.php index 29fa1a83f..184ddf73b 100644 --- a/include/user_action_ven.php +++ b/include/user_action_ven.php @@ -49,6 +49,8 @@ if ( ! isset ($_REQUEST['action'])) { if ( $action=="use_opd" ) { $op=new Pre_op_ven($cn); $op->set_od_id($_REQUEST['pre_def']); + $op->od_direct='f'; + $p_post=$op->compute_array(); echo_debug(__FILE__.':'.__LINE__.'- ','p_post = ',$p_post); $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$p_post,false,$p_post['nb_item']); @@ -103,6 +105,8 @@ if ( $action == 'insert_vente' ) { echo ''; $op=new Pre_operation($cn); $op->p_jrn=$_GET['p_jrn']; + $op->od_direct='f'; + $hid=new widget("hidden"); echo $hid->IOValue("action","use_opd"); echo dossier::hidden(); diff --git a/include/user_menu.php b/include/user_menu.php index a2a0e3ab8..4dbe3cc20 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -166,6 +166,9 @@ function ShowMenuCompta($p_high="") $default=5; if ( $_REQUEST['p_action']=='fiche') $default=6; + if ( $_REQUEST['p_action']=='quick_writing') + $default=4; + } $str_dossier=dossier::get(); $p_array=array( @@ -174,11 +177,11 @@ function ShowMenuCompta($p_high="") array("user_jrn.php?jrn_type=ACH&".$str_dossier,"Dépense"), array("user_jrn.php?jrn_type=FIN&".$str_dossier,"Financier"), array("user_jrn.php?jrn_type=ODS&".$str_dossier,"Op. Diverses"), - array('compta.php?p_action=quick_writing&'.$str_dossier,'Ecriture rapide'), + array('compta.php?p_action=quick_writing&'.$str_dossier,'Ecriture rapide','Ecriture directe dans les journaux',4), 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("user_advanced.php?".$str_dossier,"Avancé","Opérations délicates"), + array("user_advanced.php?".$str_dossier,"Avancé","Opérations délicates",7), ); $result=ShowItem($p_array,'H',"mtitle","mtitle",$default,' width="100%"'); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index ad1fa8f72..804ad0afe 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,2 +1,6 @@ delete from jrn where jr_internal is null; - delete from jrnx where j_grpt not in (select jr_grpt_id from jrn); +delete from jrnx where j_grpt not in (select jr_grpt_id from jrn); +alter table op_predef add od_direct bool; +update op_predef set od_direct=false; +alter table op_predef alter od_direct set not null; +alter table op_predef_detail add od_qc bool; \ No newline at end of file