noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 var $sql;
37 function __construct($p_cn, $p_id=-1)
38 {
39 $this->table = "accounting_card";
40 $this->primary_key = "id";
41 $this->limit_fiche_qcode=0;
42 $this->name = array(
43 "id" => "id",
44 "pcm_val"=>"pcm_val",
45 "parent_accounting"=>"parent_accounting",
46 "pcm_lib"=>"pcm_lib",
47 "pcm_type"=>"pcm_type",
48 "fiche_qcode"=>"fiche_qcode",
49 "pcm_direct_use"=>"pcm_direct_use"
50 );
51
52 $this->type = array(
53 "id" => "numeric",
54 "pcm_val" => "text",
55 "parent_accounting" => "text",
56 "pcm_lib" => "text",
57 "pcm_type" => "text",
58 "fiche_qcode"=>"string",
59 "pcm_direct_use"=>"text"
60 );
61
62 $this->default = array(
63 "id" => "auto",
64 "fiche_qcode"=>"auto"
65 );
66 $this->sql="
67 SELECT pcm_val,
68 pcm_lib,
69 pcm_val_parent as parent_accounting,
70 pcm_type,
71 id,
72 pcm_direct_use,
73 (select string_agg(m.fiche_qcode,' , ')
74 from (select a.ad_value as fiche_qcode
75 from fiche_detail as a
76 join fiche_detail as b on (a.ad_id=23 and a.f_id=b.f_id and b.ad_id=5)
77 where b.ad_value=pcm_val::text order by a.ad_value %s)as m) as fiche_qcode
78 FROM public.tmp_pcmn
79
80";
81 parent::__construct($p_cn,$p_id);
82 }
83
84 public function count($p_where="", $p_array=null)
85 {
86 throw new Exception("not implemented");
87 }
88
89 public function delete()
90 {
91 $obj=new Tmp_Pcmn_SQL($this->cn,$this->id);
92 if ( $this->cn->get_value("select count(*) from jrnx where j_poste=$1",[$obj->pcm_val]) > 0)
93 {
94 throw new Exception(_("Impossible d'effacer : ce poste est utilisé"));
95 }
96 if ( $this->cn->get_value("select count(*) from tmp_pcmn where pcm_val_parent=$1",[$obj->pcm_val]) > 0)
97 {
98 throw new Exception(_("Impossible d'effacer : ce poste est utilisé"));
99 }
100 return $obj->delete();
101
102 }
103
104 public function exist()
105 {
106 $obj=new Tmp_Pcmn_SQL($this->cn,$this->id);
107 return $obj->exist();
108 }
109
110 public function insert()
111 {
112 $obj=new Tmp_Pcmn_SQL($this->cn);
113 $obj->set("pcm_val",$this->pcm_val);
114 $obj->set("pcm_lib",$this->pcm_lib);
115 $obj->set("pcm_type",$this->pcm_type);
116 $obj->set("pcm_val_parent",$this->parent_accounting);
117 $obj->set("pcm_direct_use",$this->pcm_direct_use);
118 $obj->insert();
119 $this->id=$obj->id;
120 }
121 public function get_pk_value()
122 {
123 return $this->id;
124 }
125 public function load():bool
126 {
128 if ( $this->get_limit_fiche_qcode() != 0 )
129 {
130 $sql=sprintf($this->sql," limit ".$this->get_limit_fiche_qcode());
131 } else
132 {
133 $sql=sprintf($this->sql," ");
134 }
135 $result=$this->cn->get_array($sql. " where id=$1",array ($this->$pk));
136 if ($this->cn->count()==0)
137 {
138 $this->$pk=-1;
139 return false;
140 }
141
142 foreach ($result[0] as $key=> $value)
143 {
144 $this->$key=$value;
145 }
146 return true;
147 }
148
149 public function seek($cond='', $p_array=null)
150 {
151 if ( $this->get_limit_fiche_qcode() != 0 )
152 {
153 $sql=sprintf($this->sql," limit ".$this->get_limit_fiche_qcode());
154 } else
155 {
156 $sql=sprintf($this->sql," ");
157 }
158 $ret=$this->cn->exec_sql($sql." ".$cond,$p_array);
159 return $ret;
160 }
161
162 public function update()
163 {
164 $obj=new Tmp_Pcmn_SQL($this->cn,$this->id);
165 $obj->set("pcm_val",$this->pcm_val);
166 $obj->set("pcm_lib",$this->pcm_lib);
167 $obj->set("pcm_type",$this->pcm_type);
168 $obj->set("pcm_val_parent",$this->parent_accounting);
169 $obj->set("pcm_direct_use",$this->pcm_direct_use);
170
171 $obj->update();
172 }
173 public function get_limit_fiche_qcode()
174 {
176 }
177
179 {
180 $this->limit_fiche_qcode=$limit_fiche_qcode;
181 }
182
183
184}
catch(Exception $e) $obj
$input_from cn
$from_poste name
_("actif, passif,charge,...")
$input_from type
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