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             $poste=HtmlInput::default_value_post("poste".$i, null);
00047             $qcode=HtmlInput::default_value_post("qc_".$i, null);
00048             
00049             if ( $poste == null && $qcode == null )                continue;
00050             
00051             if ($poste != null && trim ($poste) != "")
00052             {
00053                 $this->{'poste'.$i}=$poste;
00054                  $this->{'isqc'.$i}='f';
00055             }
00056             
00057             if ( $qcode != null && trim ($qcode) != "") {
00058                 $this->{'isqc'.$i}=(trim($_POST['qc_'.$i]) != "")?'t':'f';
00059                 $this->{'poste'.$i}=trim ($qcode);
00060             }   
00061             $this->{"amount".$i}=$_POST['amount'.$i];
00062             $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
00063 
00064         }
00065     }
00066     /*!
00067      * \brief save the detail and op in the database
00068      *
00069      */
00070     function save()
00071     {
00072         try
00073         {
00074             if ($this->operation->save() == false )
00075                 return;
00076             $this->db->start();
00077             // save the selling
00078             for ($i=0;$i<$this->operation->nb_item;$i++)
00079             {
00080                 if ( ! isset ($this->{"poste".$i}))
00081                     continue;
00082 
00083                 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
00084                              'opd_debit,od_id,opd_qc)'.
00085                              ' values '.
00086                              "('%s',%.2f,'%s',%d,'%s')",
00087                              $this->{"poste".$i},
00088                              $this->{"amount".$i},
00089                              $this->{"ck".$i},
00090                              $this->operation->od_id,
00091                              $this->{'isqc'.$i}
00092                             );
00093 
00094                 $this->db->exec_sql($sql);
00095 
00096             }
00097              $this->db->commit();
00098             
00099         }
00100         catch (Exception $e)
00101         {
00102             echo ($e->getMessage());
00103             $this->db->rollback();
00104         }
00105 
00106     }
00107     /*!\brief compute an array accordingly with the FormVenView function
00108      */
00109     function compute_array()
00110     {
00111         $count=0;
00112         $a_op=$this->operation->load();
00113         $array=$this->operation->compute_array($a_op);
00114         $array['desc']=$array['e_comm'];
00115         $p_array=$this->load();
00116                 if (empty($p_array)) return array();
00117         foreach ($p_array as $row)
00118         {
00119             $tmp_array=array("qc_".$count=>'',
00120                              "poste".$count=>'',
00121                              "amount".$count=>$row['opd_amount'],
00122                              'ck'.$count=>$row['opd_debit']
00123                             );
00124 
00125             if ( $row['opd_qc'] == 't' )
00126                 $tmp_array['qc_'.$count]=$row['opd_poste'];
00127             else
00128                 $tmp_array['poste'.$count]=$row['opd_poste'];
00129 
00130 
00131             if ( $row['opd_debit'] == 'f' )
00132                 unset ($tmp_array['ck'.$count]);
00133 
00134             $array+=$tmp_array;
00135             $count++;
00136 
00137         }
00138 
00139         return $array;
00140     }
00141     /*!\brief load the data from the database and return an array
00142      * \return an array
00143      */
00144     function load()
00145     {
00146         $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
00147              " opd_qc from op_predef_detail where od_id=".$this->operation->od_id.
00148              " order by opd_id";
00149         $res=$this->db->exec_sql($sql);
00150         $array=Database::fetch_all($res);
00151         return $array;
00152     }
00153     function set_od_id($p_id)
00154     {
00155         $this->operation->od_id=$p_id;
00156     }
00157        function display($p_array)
00158     {
00159         global $g_parameter, $g_user;
00160         require_once 'class_acc_ledger.php';
00161         $legder=new Acc_Ledger($this->db,$this->jrn_def_id);
00162         $legder->nb=$legder->get_min_row();
00163 
00164         if ($p_array != null)
00165                 extract($p_array);
00166         $add_js = "";
00167        
00168         $ret = "";
00169         if ($g_user->check_action(FICADD) == 1)
00170         {
00171                 /* Add button */
00172                 $f_add_button = new IButton('add_card');
00173                 $f_add_button->label = _('Créer une nouvelle fiche');
00174                 $f_add_button->set_attribute('ipopup', 'ipop_newcard');
00175                 $f_add_button->set_attribute('jrn', $legder->id);
00176                 $f_add_button->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
00177                 $f_add_button->input();
00178         }
00179        
00180         $nb_row = (isset($nb_item) ) ? $nb_item : $legder->nb;
00181 
00182         $ret.=HtmlInput::hidden('nb_item', $nb_row);
00183         $ret.=HtmlInput::hidden('p_jrn', $this->jrn_def_id);
00184         $ret.=dossier::hidden();
00185         
00186         $ret.=dossier::hidden();
00187 
00188         $ret.=HtmlInput::hidden('jrn_type', $legder->get_type());
00189         $info = HtmlInput::infobulle(0);
00190         $info_poste = HtmlInput::infobulle(9);
00191         if ($g_user->check_action(FICADD) == 1)
00192                 $ret.=$f_add_button->input();
00193         $ret.='<table id="quick_item" style="width:100%">';
00194         $ret.='<tr>' .
00195                         '<th style="text-align:left">Quickcode' . $info . '</th>' .
00196                         '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' .
00197                         '<th style="text-align:left">' . _('Libellé') . '</th>' .
00198                         '<th style="text-align:left">' . _('Montant') . '</th>' .
00199                         '<th style="text-align:left">' . _('Débit') . '</th>' .
00200                         '</tr>';
00201 
00202 
00203         for ($i = 0; $i < $nb_row; $i++)
00204         {
00205                 // Quick Code
00206                 $quick_code = new ICard('qc_' . $i);
00207                 $quick_code->set_dblclick("fill_ipopcard(this);");
00208                 $quick_code->set_attribute('ipopup', 'ipopcard');
00209 
00210                 // name of the field to update with the name of the card
00211                 $quick_code->set_attribute('label', "ld" . $i);
00212                 $quick_code->set_attribute('jrn', $legder->id);
00213 
00214                 // name of the field to update with the name of the card
00215                 $quick_code->set_attribute('typecard', 'filter');
00216 
00217                 // Add the callback function to filter the card on the jrn
00218                 $quick_code->set_callback('filter_card');
00219                 $quick_code->set_function('fill_data');
00220                 $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
00221 
00222                 $quick_code->jrn = $legder->id;
00223                 $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . $i} : "";
00224 
00225                 $label = '';
00226                 if ($quick_code->value != '')
00227                 {
00228                         $Fiche = new Fiche($legder->db);
00229                         $Fiche->get_by_qcode($quick_code->value);
00230                         $label = $Fiche->strAttribut(ATTR_DEF_NAME);
00231                 }
00232 
00233 
00234                 // Account
00235                 $poste = new IPoste();
00236                 $poste->name = 'poste' . $i;
00237                 $poste->set_attribute('jrn', $legder->id);
00238                 $poste->set_attribute('ipopup', 'ipop_account');
00239                 $poste->set_attribute('label', 'ld' . $i);
00240                 $poste->set_attribute('account', 'poste' . $i);
00241                 $poste->set_attribute('dossier', Dossier::id());
00242 
00243                 $poste->value = (isset(${'poste' . $i})) ? ${"poste" . $i} : ''
00244                 ;
00245                 $poste->dbl_click_history();
00246 
00247 
00248                 if ($poste->value != '')
00249                 {
00250                         $Poste = new Acc_Account($legder->db);
00251                         $Poste->set_parameter('value', $poste->value);
00252                         $label = $Poste->get_lib();
00253                 }
00254 
00255                 // Description of the line
00256                 $line_desc = new IText();
00257                 $line_desc->name = 'ld' . $i;
00258                 $line_desc->size = 30;
00259                 $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . $i} :
00260                                 $label;
00261 
00262                 // Amount
00263                 $amount = new INum();
00264                 $amount->size = 10;
00265                 $amount->name = 'amount' . $i;
00266                 $amount->value = (isset(${'amount' . $i})) ? ${"amount" . $i} : ''
00267                 ;
00268                 $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
00269                 // D/C
00270                 $deb = new ICheckBox();
00271                 $deb->name = 'ck' . $i;
00272                 $deb->selected = (isset(${'ck' . $i})) ? true : false;
00273                 $deb->javascript = ' onChange="checkTotalDirect()"';
00274 
00275                 $ret.='<tr>';
00276                 $ret.='<td>' . $quick_code->input() . $quick_code->search() . '</td>';
00277                 $ret.='<td>' . $poste->input() .
00278                                 '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' .
00279                                 '</td>';
00280                 $ret.='<td>' . $line_desc->input() . '</td>';
00281                 $ret.='<td>' . $amount->input() . '</td>';
00282                 $ret.='<td>' . $deb->input() . '</td>';
00283                 $ret.='</tr>';
00284                 // If readonly == 1 then show CA
00285         }
00286         $ret.='</table>';
00287         return $ret;
00288     }
00289 }
 All Data Structures Namespaces Files Functions Variables Enumerations