noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_pre_op_ods.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_ods
00024  */
00025 require_once ('class_pre_operation.php');
00026 
00027 /*---------------------------------------------------------------------- */
00028 /*!\brief concerns the predefined operation for ODS ledger
00029 */
00030 class Pre_op_ods 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         for ($i=0;$i<$this->operation->nb_item;$i++)
00044         {
00045 
00046             $this->{"e_account".$i}=$_POST['e_account'.$i];
00047             $this->{"e_account".$i."_amount"}=$_POST['e_account'.$i."_amount"];
00048             $this->{"e_account".$i."_type"}=$_POST['e_account'.$i."_type"];
00049 
00050         }
00051     }
00052     /*!
00053      * \brief save the detail and op in the database
00054      *
00055      */
00056     function save()
00057     {
00058         try
00059         {
00060             $this->db->start();
00061             if ($this->operation->save() == false )
00062                 return;
00063 
00064             // save the selling
00065             for ($i=0;$i<$this->operation->nb_item;$i++)
00066             {
00067                 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
00068                              'opd_debit,od_id)'.
00069                              ' values '.
00070                              "('%s',%.2f,'%s',%d)",
00071                              $this->{"e_account".$i},
00072                              $this->{"e_account".$i."_amount"},
00073                              ($this->{"e_account".$i."_type"}=='d')?'t':'f',
00074                              $this->operation->od_id
00075                             );
00076                 $this->db->exec_sql($sql);
00077             }
00078         }
00079         catch (Exception $e)
00080         {
00081             echo ($e->getMessage());
00082             $this->db->rollback();
00083         }
00084 
00085     }
00086     /*!\brief compute an array accordingly with the FormVenView function
00087      */
00088     function compute_array()
00089     {
00090         $count=0;
00091         $a_op=$this->operation->load();
00092         $array=$this->operation->compute_array($a_op);
00093         $p_array=$this->load();
00094         foreach ($p_array as $row)
00095         {
00096             $c=($row['opd_debit']=='t')?'d':'c';
00097             $array+=array("e_account".$count=>$row['opd_poste'],
00098                           "e_account".$count."_amount"=>$row['opd_amount'],
00099                           "e_account".$count."_type"=>$c
00100                          );
00101             $count++;
00102 
00103         }
00104         return $array;
00105     }
00106     /*!\brief load the data from the database and return an array
00107      * \return an array 
00108      */
00109     function load()
00110     {
00111         $sql="select opd_id,opd_poste,opd_amount,opd_debit".
00112              "  from op_predef_detail where od_id=".$this->operation->od_id.
00113              " order by opd_debit, opd_id,opd_amount";
00114         $res=$this->db->exec_sql($sql);
00115         $array=Database::fetch_all($res);
00116         return $array;
00117     }
00118     function set_od_id($p_id)
00119     {
00120         $this->operation->od_id=$p_id;
00121     }
00122 }
 All Data Structures Namespaces Files Functions Variables Enumerations