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