class_pre_op_advanced.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta 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  *   PhpCompta 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 PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 4479 $ */
00020 
00021 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00022 
00023 /*!\file
00024  * \brief definition of the class Pre_Op_Advanced
00025  */
00026 require_once ('class_pre_operation.php');
00027 
00028 /*---------------------------------------------------------------------- */
00029 /*!\brief concerns the predefined operation for the operation from 'Ecriture direct'
00030  */
00031 class Pre_Op_Advanced extends Pre_operation_detail
00032 {
00033     var $op;
00034     function Pre_Op_Advanced($cn)
00035     {
00036         parent::__construct($cn);
00037         $this->operation->od_direct='t';
00038     }
00039     function get_post()
00040     {
00041         parent::get_post();
00042 
00043         extract($_POST);
00044 
00045         for ($i=0;$i<$this->operation->nb_item;$i++)
00046         {
00047             if ( ! isset ($_POST['poste'.$i]) && ! isset ($_POST['qc_'.$i]))
00048                 continue;
00049             $this->{'poste'.$i}=(isset($_POST['qc_'.$i]))?$_POST['qc_'.$i]:$_POST['poste'.$i];
00050             $this->{'isqc'.$i}=(isset($_POST['qc_'.$i]))?'t':'f';
00051             $this->{"amount".$i}=$_POST['amount'.$i];
00052             $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
00053 
00054         }
00055     }
00056     /*!
00057      * \brief save the detail and op in the database
00058      *
00059      */
00060     function save()
00061     {
00062         try
00063         {
00064             $this->db->start();
00065             if ($this->operation->save() == false )
00066                 return;
00067             // save the selling
00068             for ($i=0;$i<$this->operation->nb_item;$i++)
00069             {
00070                 if ( ! isset ($this->{"poste".$i}))
00071                     continue;
00072 
00073                 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
00074                              'opd_debit,od_id,opd_qc)'.
00075                              ' values '.
00076                              "('%s',%.2f,'%s',%d,'%s')",
00077                              $this->{"poste".$i},
00078                              $this->{"amount".$i},
00079                              $this->{"ck".$i},
00080                              $this->operation->od_id,
00081                              $this->{'isqc'.$i}
00082                             );
00083 
00084                 $this->db->exec_sql($sql);
00085 
00086             }
00087         }
00088         catch (Exception $e)
00089         {
00090             echo ($e->getMessage());
00091             $this->db->rollback();
00092         }
00093 
00094     }
00095     /*!\brief compute an array accordingly with the FormVenView function
00096      */
00097     function compute_array()
00098     {
00099         $count=0;
00100         $a_op=$this->operation->load();
00101         $array=$this->operation->compute_array($a_op);
00102         $array['desc']=$array['e_comm'];
00103         $p_array=$this->load();
00104                 if (empty($p_array)) return array();
00105         foreach ($p_array as $row)
00106         {
00107             $tmp_array=array("qc_".$count=>'',
00108                              "poste".$count=>'',
00109                              "amount".$count=>$row['opd_amount'],
00110                              'ck'.$count=>$row['opd_debit']
00111                             );
00112 
00113             if ( $row['opd_qc'] == 't' )
00114                 $tmp_array['qc_'.$count]=$row['opd_poste'];
00115             else
00116                 $tmp_array['poste'.$count]=$row['opd_poste'];
00117 
00118 
00119             if ( $row['opd_debit'] == 'f' )
00120                 unset ($tmp_array['ck'.$count]);
00121 
00122             $array+=$tmp_array;
00123             $count++;
00124 
00125         }
00126 
00127         return $array;
00128     }
00129     /*!\brief load the data from the database and return an array
00130      * \return an array
00131      */
00132     function load()
00133     {
00134         $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
00135              " opd_qc from op_predef_detail where od_id=".$this->operation->od_id.
00136              " order by opd_id";
00137         $res=$this->db->exec_sql($sql);
00138         $array=Database::fetch_all($res);
00139         return $array;
00140     }
00141     function set_od_id($p_id)
00142     {
00143         $this->operation->od_id=$p_id;
00144     }
00145 }