noalyss Version-9
acc_plan_sql.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2016) Author Dany De Bontridder <dany@alchimerys.be>
21
22/**
23 * @file
24 * @brief Layer above Tmp_Pcmn_Sql
25 */
26require_once NOALYSS_INCLUDE."/database/tmp_pcmn_sql.class.php";
27/**
28 * @brief this class is above tmp_pcmn_sql and is a view of tmp_pcmn
29 * @see Tmp_Pcmn_SQL
30 * @see Acc_Plan_MTable
31 */
33{
34
36 function __construct($p_cn, $p_id=-1)
37 {
38 $this->table = "accounting_card";
39 $this->primary_key = "id";
40 $this->limit_fiche_qcode=0;
41 $this->name = array(
42 "id" => "id",
43 "pcm_val"=>"pcm_val",
44 "parent_accounting"=>"parent_accounting",
45 "pcm_lib"=>"pcm_lib",
46 "pcm_type"=>"pcm_type",
47 "fiche_qcode"=>"fiche_qcode",
48 "pcm_direct_use"=>"pcm_direct_use"
49 );
50
51 $this->type = array(
52 "id" => "numeric",
53 "pcm_val" => "text",
54 "parent_accounting" => "text",
55 "pcm_lib" => "text",
56 "pcm_type" => "text",
57 "fiche_qcode"=>"string",
58 "pcm_direct_use"=>"text"
59 );
60
61 $this->default = array(
62 "id" => "auto",
63 "fiche_qcode"=>"auto"
64 );
65 $this->sql="
66 SELECT pcm_val,
67 pcm_lib,
68 pcm_val_parent as parent_accounting,
69 pcm_type,
70 id,
71 pcm_direct_use,
72 (select string_agg(m.fiche_qcode,' , ')
73 from (select a.ad_value as fiche_qcode
74 from fiche_detail as a
75 join fiche_detail as b on (a.ad_id=23 and a.f_id=b.f_id and b.ad_id=5)
76 where b.ad_value=pcm_val::text order by a.ad_value %s)as m) as fiche_qcode
77 FROM public.tmp_pcmn
78
79";
80 parent::__construct($p_cn,$p_id);
81 }
82
83 public function count($p_where="", $p_array=null)
84 {
85 throw new Exception("not implemented");
86 }
87
88 public function delete()
89 {
90 $obj=new Tmp_Pcmn_SQL($this->cn,$this->id);
91 if ( $this->cn->get_value("select count(*) from jrnx where j_poste=$1",[$obj->pcm_val]) > 0)
92 {
93 throw new Exception(_("Impossible d'effacer : ce poste est utilisé"));
94 }
95 if ( $this->cn->get_value("select count(*) from tmp_pcmn where pcm_val_parent=$1",[$obj->pcm_val]) > 0)
96 {
97 throw new Exception(_("Impossible d'effacer : ce poste est utilisé"));
98 }
99 return $obj->delete();
100
101 }
102
103 public function exist()
104 {
105 $obj=new Tmp_Pcmn_SQL($this->cn,$this->id);
106 return $obj->exist();
107 }
108
109 public function insert()
110 {
111 $obj=new Tmp_Pcmn_SQL($this->cn);
112 $obj->set("pcm_val",$this->pcm_val);
113 $obj->set("pcm_lib",$this->pcm_lib);
114 $obj->set("pcm_type",$this->pcm_type);
115 $obj->set("pcm_val_parent",$this->parent_accounting);
116 $obj->set("pcm_direct_use",$this->pcm_direct_use);
117 $obj->insert();
118 $this->id=$obj->id;
119 }
120 public function get_pk_value()
121 {
122 return $this->id;
123 }
124 public function load():bool
125 {
127 if ( $this->get_limit_fiche_qcode() != 0 )
128 {
129 $sql=sprintf($this->sql," limit ".$this->get_limit_fiche_qcode());
130 } else
131 {
132 $sql=sprintf($this->sql," ");
133 }
134 $result=$this->cn->get_array($sql. " where id=$1",array ($this->$pk));
135 if ($this->cn->count()==0)
136 {
137 $this->$pk=-1;
138 return false;
139 }
140
141 foreach ($result[0] as $key=> $value)
142 {
143 $this->$key=$value;
144 }
145 return true;
146 }
147
148 public function seek($cond='', $p_array=null)
149 {
150 if ( $this->get_limit_fiche_qcode() != 0 )
151 {
152 $sql=sprintf($this->sql," limit ".$this->get_limit_fiche_qcode());
153 } else
154 {
155 $sql=sprintf($this->sql," ");
156 }
157 $ret=$this->cn->exec_sql($sql." ".$cond,$p_array);
158 return $ret;
159 }
160
161 public function update()
162 {
163 $obj=new Tmp_Pcmn_SQL($this->cn,$this->id);
164 $obj->set("pcm_val",$this->pcm_val);
165 $obj->set("pcm_lib",$this->pcm_lib);
166 $obj->set("pcm_type",$this->pcm_type);
167 $obj->set("pcm_val_parent",$this->parent_accounting);
168 $obj->set("pcm_direct_use",$this->pcm_direct_use);
169
170 $obj->update();
171 }
172 public function get_limit_fiche_qcode()
173 {
175 }
176
178 {
179 $this->limit_fiche_qcode=$limit_fiche_qcode;
180 }
181
182
183}
$input_from cn
Definition: balance.inc.php:66
$from_poste name
$input_from type
Definition: balance.inc.php:65
this class is above tmp_pcmn_sql and is a view of tmp_pcmn
load()
Load the current row return false if not found.
set_limit_fiche_qcode($limit_fiche_qcode)
__construct($p_cn, $p_id=-1)
count($p_where="", $p_array=null)
exist()
Count the number of record with the id ,.
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
$primary_key
Array of logical and real name.
ORM abstract of the table public.tmp_pcmn.
$all table