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