noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_pre_op_advanced.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief definition of the class Pre_Op_Advanced
00024  */
00025 require_once ('class_pre_operation.php');
00026 
00027 /*---------------------------------------------------------------------- */
00028 /*!\brief concerns the predefined operation for the operation from 'Ecriture direct'
00029  */
00030 class Pre_Op_Advanced extends Pre_operation_detail
00031 {
00032     var $op;
00033     function Pre_Op_Advanced($cn)
00034     {
00035         parent::__construct($cn);
00036         $this->operation->od_direct='t';
00037     }
00038     function get_post()
00039     {
00040         parent::get_post();
00041 
00042         extract($_POST);
00043 
00044         for ($i=0;$i<$this->operation->nb_item;$i++)
00045         {
00046             if ( ! isset ($_POST['poste'.$i]) && ! isset ($_POST['qc_'.$i]))
00047                 continue;
00048             $this->{'poste'.$i}=(trim($_POST['qc_'.$i]) != "" )?$_POST['qc_'.$i]:$_POST['poste'.$i];
00049             $this->{'isqc'.$i}=(trim($_POST['qc_'.$i]) != "")?'t':'f';
00050             $this->{"amount".$i}=$_POST['amount'.$i];
00051             $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
00052 
00053         }
00054     }
00055     /*!
00056      * \brief save the detail and op in the database
00057      *
00058      */
00059     function save()
00060     {
00061         try
00062         {
00063             $this->db->start();
00064             if ($this->operation->save() == false )
00065                 return;
00066             // save the selling
00067             for ($i=0;$i<$this->operation->nb_item;$i++)
00068             {
00069                 if ( ! isset ($this->{"poste".$i}))
00070                     continue;
00071 
00072                 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
00073                              'opd_debit,od_id,opd_qc)'.
00074                              ' values '.
00075                              "('%s',%.2f,'%s',%d,'%s')",
00076                              $this->{"poste".$i},
00077                              $this->{"amount".$i},
00078                              $this->{"ck".$i},
00079                              $this->operation->od_id,
00080                              $this->{'isqc'.$i}
00081                             );
00082 
00083                 $this->db->exec_sql($sql);
00084 
00085             }
00086         }
00087         catch (Exception $e)
00088         {
00089             echo ($e->getMessage());
00090             $this->db->rollback();
00091         }
00092 
00093     }
00094     /*!\brief compute an array accordingly with the FormVenView function
00095      */
00096     function compute_array()
00097     {
00098         $count=0;
00099         $a_op=$this->operation->load();
00100         $array=$this->operation->compute_array($a_op);
00101         $array['desc']=$array['e_comm'];
00102         $p_array=$this->load();
00103                 if (empty($p_array)) return array();
00104         foreach ($p_array as $row)
00105         {
00106             $tmp_array=array("qc_".$count=>'',
00107                              "poste".$count=>'',
00108                              "amount".$count=>$row['opd_amount'],
00109                              'ck'.$count=>$row['opd_debit']
00110                             );
00111 
00112             if ( $row['opd_qc'] == 't' )
00113                 $tmp_array['qc_'.$count]=$row['opd_poste'];
00114             else
00115                 $tmp_array['poste'.$count]=$row['opd_poste'];
00116 
00117 
00118             if ( $row['opd_debit'] == 'f' )
00119                 unset ($tmp_array['ck'.$count]);
00120 
00121             $array+=$tmp_array;
00122             $count++;
00123 
00124         }
00125 
00126         return $array;
00127     }
00128     /*!\brief load the data from the database and return an array
00129      * \return an array
00130      */
00131     function load()
00132     {
00133         $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
00134              " opd_qc from op_predef_detail where od_id=".$this->operation->od_id.
00135              " order by opd_id";
00136         $res=$this->db->exec_sql($sql);
00137         $array=Database::fetch_all($res);
00138         return $array;
00139     }
00140     function set_od_id($p_id)
00141     {
00142         $this->operation->od_id=$p_id;
00143     }
00144        function display($p_array)
00145     {
00146         global $g_parameter, $g_user;
00147         require_once 'class_acc_ledger.php';
00148         $legder=new Acc_Ledger($this->db,$this->jrn_def_id);
00149         $legder->nb=$legder->get_min_row();
00150 
00151         if ($p_array != null)
00152                 extract($p_array);
00153         $add_js = "";
00154        
00155         $ret = "";
00156         if ($g_user->check_action(FICADD) == 1)
00157         {
00158                 /* Add button */
00159                 $f_add_button = new IButton('add_card');
00160                 $f_add_button->label = _('Créer une nouvelle fiche');
00161                 $f_add_button->set_attribute('ipopup', 'ipop_newcard');
00162                 $f_add_button->set_attribute('jrn', $legder->id);
00163                 $f_add_button->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
00164                 $f_add_button->input();
00165         }
00166        
00167         $nb_row = (isset($nb_item) ) ? $nb_item : $legder->nb;
00168 
00169         $ret.=HtmlInput::hidden('nb_item', $nb_row);
00170         $ret.=HtmlInput::hidden('p_jrn', $this->jrn_def_id);
00171         $ret.=dossier::hidden();
00172         
00173         $ret.=dossier::hidden();
00174 
00175         $ret.=HtmlInput::hidden('jrn_type', $legder->get_type());
00176         $info = HtmlInput::infobulle(0);
00177         $info_poste = HtmlInput::infobulle(9);
00178         if ($g_user->check_action(FICADD) == 1)
00179                 $ret.=$f_add_button->input();
00180         $ret.='<table id="quick_item" style="width:100%">';
00181         $ret.='<tr>' .
00182                         '<th style="text-align:left">Quickcode' . $info . '</th>' .
00183                         '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' .
00184                         '<th style="text-align:left">' . _('Libellé') . '</th>' .
00185                         '<th style="text-align:left">' . _('Montant') . '</th>' .
00186                         '<th style="text-align:left">' . _('Débit') . '</th>' .
00187                         '</tr>';
00188 
00189 
00190         for ($i = 0; $i < $nb_row; $i++)
00191         {
00192                 // Quick Code
00193                 $quick_code = new ICard('qc_' . $i);
00194                 $quick_code->set_dblclick("fill_ipopcard(this);");
00195                 $quick_code->set_attribute('ipopup', 'ipopcard');
00196 
00197                 // name of the field to update with the name of the card
00198                 $quick_code->set_attribute('label', "ld" . $i);
00199                 $quick_code->set_attribute('jrn', $legder->id);
00200 
00201                 // name of the field to update with the name of the card
00202                 $quick_code->set_attribute('typecard', 'filter');
00203 
00204                 // Add the callback function to filter the card on the jrn
00205                 $quick_code->set_callback('filter_card');
00206                 $quick_code->set_function('fill_data');
00207                 $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
00208 
00209                 $quick_code->jrn = $legder->id;
00210                 $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . $i} : "";
00211 
00212                 $label = '';
00213                 if ($quick_code->value != '')
00214                 {
00215                         $Fiche = new Fiche($legder->db);
00216                         $Fiche->get_by_qcode($quick_code->value);
00217                         $label = $Fiche->strAttribut(ATTR_DEF_NAME);
00218                 }
00219 
00220 
00221                 // Account
00222                 $poste = new IPoste();
00223                 $poste->name = 'poste' . $i;
00224                 $poste->set_attribute('jrn', $legder->id);
00225                 $poste->set_attribute('ipopup', 'ipop_account');
00226                 $poste->set_attribute('label', 'ld' . $i);
00227                 $poste->set_attribute('account', 'poste' . $i);
00228                 $poste->set_attribute('dossier', Dossier::id());
00229 
00230                 $poste->value = (isset(${'poste' . $i})) ? ${"poste" . $i} : ''
00231                 ;
00232                 $poste->dbl_click_history();
00233 
00234 
00235                 if ($poste->value != '')
00236                 {
00237                         $Poste = new Acc_Account($legder->db);
00238                         $Poste->set_parameter('value', $poste->value);
00239                         $label = $Poste->get_lib();
00240                 }
00241 
00242                 // Description of the line
00243                 $line_desc = new IText();
00244                 $line_desc->name = 'ld' . $i;
00245                 $line_desc->size = 30;
00246                 $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . $i} :
00247                                 $label;
00248 
00249                 // Amount
00250                 $amount = new INum();
00251                 $amount->size = 10;
00252                 $amount->name = 'amount' . $i;
00253                 $amount->value = (isset(${'amount' . $i})) ? ${"amount" . $i} : ''
00254                 ;
00255                 $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
00256                 // D/C
00257                 $deb = new ICheckBox();
00258                 $deb->name = 'ck' . $i;
00259                 $deb->selected = (isset(${'ck' . $i})) ? true : false;
00260                 $deb->javascript = ' onChange="checkTotalDirect()"';
00261 
00262                 $ret.='<tr>';
00263                 $ret.='<td>' . $quick_code->input() . $quick_code->search() . '</td>';
00264                 $ret.='<td>' . $poste->input() .
00265                                 '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' .
00266                                 '</td>';
00267                 $ret.='<td>' . $line_desc->input() . '</td>';
00268                 $ret.='<td>' . $amount->input() . '</td>';
00269                 $ret.='<td>' . $deb->input() . '</td>';
00270                 $ret.='</tr>';
00271                 // If readonly == 1 then show CA
00272         }
00273         $ret.='</table>';
00274         return $ret;
00275     }
00276 }
 All Data Structures Namespaces Files Functions Variables Enumerations