noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_pre_op_ach.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_ach
00024  */
00025 require_once ('class_pre_operation.php');
00026 
00027 /*---------------------------------------------------------------------- */
00028 /*!\brief concerns the predefined operation for ACH ledger
00029  */
00030 class Pre_op_ach extends Pre_operation_detail
00031 {
00032     var $op;
00033     function __construct($cn,$p_id=0)
00034     {
00035         parent::__construct($cn,$p_id);
00036 
00037         $this->operation->od_direct='f';
00038     }
00039 
00040     function get_post()
00041     {
00042         parent::get_post();
00043         $this->operation->od_direct='f';
00044         $this->e_client=$_POST['e_client'];
00045         for ($i=0;$i<$this->operation->nb_item;$i++)
00046         {
00047             $march="e_march".$i;
00048             $this->$march=$_POST['e_march'.$i];
00049             $this->{"e_march".$i."_price"}=(isset ($_POST['e_march'.$i."_price"]))?$_POST['e_march'.$i."_price"]:0;
00050             $this->{"e_march".$i."_tva_id"}=(isset ($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
00051             $this->{"e_march".$i."_tva_amount"}=(isset($_POST['e_march'.$i."_tva_amount"]))?$_POST['e_march'.$i."_tva_amount"]:0;
00052             $this->{"e_quant".$i}=$_POST['e_quant'.$i];
00053 
00054         }
00055     }
00056 
00057     /*!
00058      * \brief save the detail and op in the database
00059      *
00060      */
00061     function save()
00062     {
00063         try
00064         {
00065             $this->db->start();
00066             if ($this->operation->save() == false )
00067                 return;
00068             // save the client
00069             $sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'.
00070                          ' values '.
00071                          "(%d,'%s','%s')",
00072                          $this->operation->od_id,
00073                          $this->e_client,
00074                          "f");
00075             $this->db->exec_sql($sql);
00076             // save the selling
00077             for ($i=0;$i<$this->operation->nb_item;$i++)
00078             {
00079                 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,opd_tva_id,opd_quantity,'.
00080                              'opd_debit,od_id,opd_tva_amount)'.
00081                              ' values '.
00082                              "('%s',%.2f,%d,%f,'%s',%d,%f)",
00083                              $this->{"e_march".$i},
00084                              $this->{"e_march".$i."_price"},
00085                              $this->{"e_march".$i."_tva_id"},
00086                              $this->{"e_quant".$i},
00087                              't',
00088                              $this->operation->od_id,
00089                              $this->{"e_march".$i."_tva_amount"}
00090                             );
00091                 $this->db->exec_sql($sql);
00092             }
00093         }
00094         catch (Exception $e)
00095         {
00096             echo ($e->getMessage());
00097             $this->db->rollback();
00098         }
00099         $this->db->commit();
00100     }
00101     /*!\brief compute an array accordingly with the FormVenView function
00102          * @return an array for filling the form
00103      */
00104     function compute_array()
00105     {
00106         $count=0;
00107         $a_op=$this->operation->load();
00108         $array=$this->operation->compute_array($a_op);
00109         $p_array=$this->load();
00110                 if ( empty ($p_array)) return array();
00111         foreach ($p_array as $row)
00112         {
00113             if ( $row['opd_debit']=='f')
00114             {
00115                 $array+=array('e_client'=>$row['opd_poste']);
00116             }
00117             else
00118             {
00119                 $array+=array("e_march".$count=>$row['opd_poste'],
00120                               "e_march".$count."_price"=>$row['opd_amount'],
00121                               "e_march".$count."_tva_id"=>$row['opd_tva_id'],
00122                               "e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
00123                               "e_quant".$count=>$row['opd_quantity']
00124                              );
00125                 $count++;
00126             }
00127         }
00128         return $array;
00129     }
00130     /**
00131      * @brief 
00132      * load the data from the database and return an array
00133      * \return an array
00134      */
00135     function load()
00136     {
00137         $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
00138              " opd_quantity,opd_tva_amount from op_predef_detail where od_id=".$this->operation->od_id.
00139              " order by opd_id";
00140         $res=$this->db->exec_sql($sql);
00141         $array=Database::fetch_all($res);
00142         return $array;
00143     }
00144     function set_od_id($p_id)
00145     {
00146         $this->operation->od_id=$p_id;
00147     }
00148    function display($p_array)
00149    {
00150         require_once('class_acc_ledger_purchase.php');
00151        global $g_parameter,$g_user;
00152        extract($p_array);
00153        $ledger=new Acc_Ledger_Purchase($this->db,$this->jrn_def_id);
00154         if ( $p_array != null ) extract($p_array);
00155 
00156         $flag_tva=$g_parameter->MY_TVA_USE;
00157         /* Add button */
00158         $f_add_button=new IButton('add_card');
00159         $f_add_button->label=_('Créer une nouvelle fiche');
00160                 $f_add_button->tabindex=-1;
00161         $f_add_button->set_attribute('ipopup','ipop_newcard');
00162         $f_add_button->set_attribute('jrn',$this->jrn_def_id);
00163         $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
00164 
00165         $f_add_button2=new IButton('add_card2');
00166                 $f_add_button2->tabindex=-1;
00167         $f_add_button2->label=_('Créer une nouvelle fiche');
00168         $f_add_button2->set_attribute('ipopup','ipop_newcard');
00169         $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
00170         //    $f_add_button2->set_attribute('jrn',$ledger->id);
00171         $f_add_button2->javascript="  this.jrn=\$('p_jrn').value;select_card_type(this);";
00172         $str_add_button="";
00173         $str_add_button2="";
00174         if ($g_user->check_action(FICADD)==1)
00175         {
00176                 $str_add_button=$f_add_button->input();
00177                 $str_add_button2=$f_add_button2->input();
00178         }
00179 
00180         $r="";
00181         $r.=dossier::hidden();
00182         $f_legend=_("En-tête facture fournisseur");
00183         $f_legend_detail=_("Détail articles acheté");
00184 
00185         // Ledger (p_jrn)
00186         //--
00187         /* if we suggest the next pj, then we need a javascript */
00188         $add_js="";
00189 
00190         // Display the customer
00191         //--
00192         $fiche='cred';
00193 
00194         // Save old value and set a new one
00195         //--
00196         $e_client=( isset ($e_client) )?$e_client:"";
00197         $e_client_label="&nbsp;";//str_pad("",100,".");
00198 
00199 
00200         // retrieve e_client_label
00201         //--
00202 
00203         if ( strlen(trim($e_client)) !=  0)
00204         {
00205             $fClient=new Fiche($ledger->db);
00206             $fClient->get_by_qcode($e_client);
00207             $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
00208                             ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
00209                             $fClient->strAttribut(ATTR_DEF_CP).' '.
00210                             $fClient->strAttribut(ATTR_DEF_CITY).' ';
00211 
00212 
00213         }
00214 
00215         $W1=new ICard();
00216         $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
00217         $W1->name="e_client";
00218         $W1->tabindex=3;
00219         $W1->value=$e_client;
00220         $W1->table=0;
00221         $W1->set_dblclick("fill_ipopcard(this);");
00222         $W1->set_attribute('ipopup','ipopcard');
00223 
00224         // name of the field to update with the name of the card
00225         $W1->set_attribute('label','e_client_label');
00226         // name of the field to update with the name of the card
00227         $W1->set_attribute('typecard','cred');
00228 
00229         // Add the callback function to filter the card on the jrn
00230         $W1->set_callback('filter_card');
00231         $W1->set_function('fill_data');
00232         $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
00233                                 $W1->name);
00234         $f_client_qcode=$W1->input();
00235         $client_label=new ISpan();
00236         $client_label->table=0;
00237         $f_client=$client_label->input("e_client_label",$e_client_label);
00238         $f_client_bt=$W1->search();
00239 
00240 
00241         // Record the current number of article
00242                 $min=$ledger->get_min_row();
00243         $p_article= ( isset ($nb_item))?$nb_item:$min;
00244         $max=($p_article < $min)?$min:$p_article;
00245 
00246         $e_comment=(isset($e_comment))?$e_comment:"";
00247         $Hid=new IHidden();
00248         $r.=$Hid->input("nb_item",$p_article);
00249         // For each article
00250         //--
00251         for ($i=0;$i< $max ;$i++)
00252         {
00253             // Code id, price & vat code
00254             //--
00255             $march=(isset(${"e_march$i"}))?${"e_march$i"}:""                   ;
00256             $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
00257                          ;
00258             /* use vat */
00259             if ( $g_parameter->MY_TVA_USE=='Y')
00260             {
00261                 $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
00262                 $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
00263             }
00264 
00265 
00266 
00267             $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
00268             // retrieve the tva label and name
00269             //--
00270             if ( strlen(trim($march))!=0  && strlen(trim($march_label))==0 )
00271             {
00272                 $fMarch=new Fiche($ledger->db);
00273                 $fMarch->get_by_qcode($march);
00274                 $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
00275                 /* vat use */
00276                 if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
00277                     $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
00278             }
00279             // Show input
00280             //--
00281             $W1=new ICard();
00282             $W1->label="";
00283             $W1->name="e_march".$i;
00284             $W1->value=$march;
00285             $W1->table=1;
00286             $W1->set_dblclick("fill_ipopcard(this);");
00287             $W1->set_attribute('ipopup','ipopcard');
00288 
00289             $W1->set_attribute('typecard','deb');
00290 
00291             // name of the field to update with the name of the card
00292             $W1->set_attribute('label','e_march'.$i.'_label');
00293             // name of the field with the price
00294             $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
00295             $W1->set_attribute('price','e_march'.$i.'_price');    /* via search */
00296 
00297             // name of the field with the TVA_ID
00298             $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
00299             // Add the callback function to filter the card on the jrn
00300             $W1->set_callback('filter_card');
00301             $W1->set_function('fill_data');
00302             $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
00303                                     $W1->name);
00304             $W1->readonly=false;
00305             $array[$i]['quick_code']=$W1->input();
00306             $array[$i]['bt']=$W1->search();
00307 
00308             $array[$i]['hidden']='';
00309             // For computing we need some hidden field for holding the value
00310             if ( $g_parameter->MY_TVA_USE=='Y')
00311             {
00312                 $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
00313             }
00314 
00315             if ( $g_parameter->MY_TVA_USE=='Y')
00316                 $tvac=new INum('tvac_march'.$i);
00317             else
00318                 $tvac=new IHidden('tvac_march'.$i);
00319 
00320             $tvac->readOnly=1;
00321             $tvac->value=0;
00322             $array[$i]['tvac']=$tvac->input();
00323 
00324             $htva=new INum('htva_march'.$i);
00325             $htva->readOnly=1;
00326 
00327             $htva->value=0;
00328             $array[$i]['htva']=$htva->input();
00329 
00330             if ( $g_parameter->MY_UPDLAB == 'Y')
00331             {
00332                 $Span=new IText("e_march".$i."_label");
00333                 $Span->css_size="100%";
00334             } else
00335             {
00336                 $Span=new ISpan("e_march".$i."_label");
00337             }
00338             $Span->value=$march_label;
00339             $Span->setReadOnly(false);
00340             // card's name, price
00341             //--
00342             $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
00343             // price
00344             $Price=new INum();
00345             $Price->setReadOnly(false);
00346             $Price->size=9;
00347             $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
00348             $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
00349             if ( $g_parameter->MY_TVA_USE=='Y')
00350             {
00351 
00352                 // vat label
00353                 //--
00354                 $Tva=new ITva_Popup($ledger->db);
00355                 $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
00356                 $Tva->in_table=true;
00357                 $Tva->set_attribute('compute',$i);
00358                 $Tva->value=$march_tva_id;
00359                 $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
00360 
00361                 // Tva_amount
00362 
00363                 // price
00364                 $Tva_amount=new INum();
00365                 $Tva_amount->setReadOnly(false);
00366                 $Tva_amount->size=9;
00367                 $Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
00368                 $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
00369             }
00370             // quantity
00371             //--
00372             $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
00373                    ;
00374             $Quantity=new INum();
00375             $Quantity->setReadOnly(false);
00376             $Quantity->size=9;
00377             $Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
00378             $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
00379 
00380         }
00381         $f_type=_('Fournisseur');
00382 
00383         ob_start();
00384         require_once('template/predf_ledger_detail.php');
00385         $r.=ob_get_contents();
00386         ob_end_clean();
00387 
00388         // Set correctly the REQUEST param for jrn_type
00389         $r.= HtmlInput::hidden('jrn_type','ACH');
00390         $r.= HtmlInput::button('add_item',_('Ajout article'),      ' onClick="ledger_add_row()"');
00391 
00392         return $r;
00393    }
00394 }
 All Data Structures Namespaces Files Functions Variables Enumerations