noalyss Version-9
pre_op_fin.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief definition of the class Pre_op_fin
24 */
25
26/*---------------------------------------------------------------------- */
27/*!\brief concerns the predefined operation for FIN ledger
28 */
30{
31 var $op;
32 function __construct($cn)
33 {
34 parent::__construct($cn);
35 $this->operation->od_direct='f';
36 }
37
38 function get_post()
39 {
40 parent::get_post();
41 $this->operation->od_direct='f';
42 $this->e_bank_account=$_POST['e_bank_account'];
43 for ($i=0;$i<$this->operation->nb_item;$i++)
44 {
45 $this->{"e_other".$i}=$_POST['e_other'.$i];
46 $this->{"e_other".$i."_comment"}=$_POST['e_other'.$i.'_comment'];
47 $this->{"e_other".$i."_amount"}=$_POST['e_other'.$i."_amount"];
48 }
49 }
50 /*!
51 * \brief save the detail and op in the database
52 *
53 */
54 function save()
55 {
56 try
57 {
58 $this->db->start();
59 if ($this->operation->save() == false )
60 return;
61 // save the client
62 $sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'.
63 ' values '.
64 "(%d,'%s','%s')",
65 $this->operation->od_id,
66 $this->e_bank_account,
67 "t");
68 $this->db->exec_sql($sql);
69 // save the selling
70 for ($i=0;$i<$this->operation->nb_item;$i++)
71 {
72 $sql=sprintf('insert into op_predef_detail (opd_poste,'.
73 'opd_amount,opd_comment,'.
74 'opd_debit,od_id)'.
75 ' values '.
76 "('%s',%.2f,'%s','%s',%d)",
77 $this->{"e_other".$i},
78 $this->{"e_other".$i."_amount"},
79 $this->{"e_other".$i."_comment"},
80 'f',
81 $this->operation->od_id
82 );
83 $this->db->exec_sql($sql);
84 }
85 }
86 catch (Exception $e)
87 {
89 echo ($e->getMessage());
90 $this->db->rollback();
91 }
92
93 }
94 /*!\brief compute an array accordingly with the FormVenView function
95 */
96 function compute_array()
97 {
98 $count=0;
99 $a_op=$this->operation->load();
100 $array=$this->operation->compute_array($a_op);
101 $p_array=$this->load();
102 foreach ($p_array as $row)
103 {
104 if ( $row['opd_debit']=='t')
105 {
106 $array+=array('e_bank_account'=>$row['opd_poste']);
107 }
108 else
109 {
110 $array+=array("e_other".$count=>$row['opd_poste'],
111 "e_other".$count."_amount"=>$row['opd_amount'],
112 "e_other".$count."_comment"=>$row['opd_comment']
113 );
114 $count++;
115 }
116 }
117 return $array;
118 }
119 /*!\brief load the data from the database and return an array
120 * \return an array or FALSE is nothing found
121 */
122 function load()
123 {
124 $sql="select opd_id,opd_poste,opd_amount,opd_comment,opd_debit".
125 " from op_predef_detail where od_id=$1 ".
126 " order by opd_id";
127 $res=$this->db->exec_sql($sql,[$this->operation->od_id]);
129 return $array;
130 }
131 function set_od_id($p_id)
132 {
133 $this->operation->od_id=$p_id;
134 }
135}
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
static fetch_all($ret)
wrapper for the function pg_fetch_all
concerns the predefined operation for FIN ledger
load()
load the data from the database and return an array
save()
save the detail and op in the database
compute_array()
compute an array accordingly with the FormVenView function
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
$_POST['ac']
Definition: do.php:310
$count
$SecUser db