Plugins  LAST
 All Data Structures Files Functions Variables Pages
Public Member Functions
Install_Plugin Class Reference
Collaboration diagram for Install_Plugin:
Collaboration graph

Public Member Functions

 __construct (&$p_cn)
 
 install ()
 install the plugin, create all the needed schema, tables, proc in the database More...
 
 create_schema ()
 
 create_tables ()
 
 upgrade ($p_dest)
 Upgrade schema amortissement. More...
 
 __construct ($p_cn)
 
 install ()
 install the plugin, create all the needed schema, tables, proc in the database More...
 
 create_schema ()
 
 create_card ()
 
 create_table_parameter ()
 
 create_table ()
 
 upgrade ()
 
 __construct ($p_cn)
 
 install ()
 install the plugin, create all the needed schema, tables, proc in the database More...
 
 create_schema ()
 
 create_table_format_bank ()
 
 create_table_import ()
 
 create_table_temp_bank ()
 
 create_table_version ()
 
 __construct ($p_cn)
 
 install ()
 install the plugin, create all the needed schema, tables, proc in the database More...
 
 create_schema ()
 
 create_table_assujetti ()
 
 create_table_assujetti_child ()
 
 create_table_intra ()
 
 create_table_intra_child ()
 
 create_table_declaration_amount ()
 create the table tva_belge.declaration_amount More...
 
 create_table_parameter ()
 

Detailed Description

Definition at line 27 of file class_install_plugin.php.

Constructor & Destructor Documentation

Install_Plugin::__construct ( $p_cn)

Definition at line 30 of file class_install_plugin.php.

30  {
31  $this->cn=$p_cn;
32  }
Install_Plugin::__construct (   $p_cn)

Definition at line 33 of file class_install_plugin.php.

34  {
35  $this->cn = $p_cn;
36  }
Install_Plugin::__construct (   $p_cn)

Definition at line 29 of file class_install_plugin.php.

30  {
31  $this->cn=$p_cn;
32  }
Install_Plugin::__construct (   $p_cn)

Definition at line 30 of file class_install_plugin.php.

30  {
31  $this->cn=$p_cn;
32  }

Member Function Documentation

Install_Plugin::create_card ( )

Definition at line 65 of file class_install_plugin.php.

References $copro, $lot, ATTR_COPROP, and ATTR_IMMEUBLE.

Referenced by install().

66  {
67  // create categorie immeuble, lot et coprop.
68  $fiche_def = new Fiche_Def($this->cn);
69 
70  // Create categorie pour lot immeuble et coprop + attribut
71  $fiche_def->add(array(
72  'FICHE_REF' => 9,
73  'nom_mod' => 'Copropriétaires - plugin',
74  'fd_description'=>'Liste des copropriétaires, catégorie créée par le plugin copropriété',
75  'class_base' => null)
76  );
77  $copro = $fiche_def->id;
78  $lot_def = new Fiche_Def($this->cn);
79 
80  $lot_def->add(array(
81  'FICHE_REF' => 15,
82  'nom_mod' => 'Lots - plugin',
83  'fd_description'=>'Liste des lots, catégorie créée par le plugin copropriété',
84  'class_base' => null)
85  );
86  $lot = $lot_def->id;
87 
88  $imm_def = new Fiche_Def($this->cn);
89  $imm_def->add(array(
90  'FICHE_REF' => 15,
91  'nom_mod' => 'immeuble - plugin',
92  'fd_description'=>'Liste des immeubles, catégorie créée par le plugin copropriété',
93  'class_base' => null)
94  );
95  $immeuble = $imm_def->id;
96 
97  // creation attribut
98  $this->cn->exec_sql("insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_extra)
99  values (".ATTR_COPROP.",'Copropriétaire','select','22','select f_id,vw_name from vw_fiche_attr where fd_id = $copro ')");
100  $this->cn->exec_sql("insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_extra) values
101  (".ATTR_IMMEUBLE.",'Immeuble','select','22','select f_id,vw_name from vw_fiche_attr where fd_id = $immeuble ');");
102 
103  $lot_def->InsertAttribut(ATTR_COPROP); // lien vers coprop
104  $lot_def->InsertAttribut(ATTR_IMMEUBLE);// lien vers immeuble
105 
106  $imm_def->InsertAttribut(14); // adresse
107  $imm_def->InsertAttribut(15); // code postale
108  $imm_def->InsertAttribut(24); //ville
109  $imm_def->InsertAttribut(16); // pays
110 
111  $fiche_def->InsertAttribut(27); // gsm
112  $fiche_def->InsertAttribut(32); // prénom
113  $fiche_def->InsertAttribut(10); // date début
114  $fiche_def->InsertAttribut(33); // date fin
115  //
116  // creation vue (create_view_summary)
117  $this->cn->exec_sql("CREATE OR REPLACE VIEW coprop.summary AS
118  SELECT a.f_id AS lot_id, m.ad_value AS building_id, c.ad_value AS coprop_id
119  FROM fiche_detail a
120  JOIN fiche f1 ON f1.f_id = a.f_id
121  JOIN ( SELECT fd1.f_id, fd1.ad_value
122  FROM fiche_detail fd1
123  WHERE fd1.ad_id = ".ATTR_IMMEUBLE.") m ON m.f_id = a.f_id
124  JOIN ( SELECT fd1.f_id, fd1.ad_value
125  FROM fiche_detail fd1
126  WHERE fd1.ad_id = ".ATTR_COPROP.") c ON c.f_id = a.f_id
127  WHERE f1.fd_id = ".$lot." AND a.ad_id = 1");
128  $this->lot_id=$lot;
129  $this->immeuble_id=$immeuble;
130  $this->coprop_id=$copro;
131 
132  }
const ATTR_IMMEUBLE
const ATTR_COPROP
$lot
Definition: lot.inc.php:69
Install_Plugin::create_schema ( )

Definition at line 48 of file class_install_plugin.php.

Referenced by install().

49  {
50  $this->cn->exec_sql('create schema amortissement');
51  }
Install_Plugin::create_schema ( )

Definition at line 51 of file class_install_plugin.php.

51  {
52  $this->cn->exec_sql('create schema importbank');
53  }
Install_Plugin::create_schema ( )

Definition at line 53 of file class_install_plugin.php.

53  {
54  $this->cn->exec_sql('create schema tva_belge');
55  }
Install_Plugin::create_schema ( )

Definition at line 59 of file class_install_plugin.php.

60  {
61  $this->cn->exec_sql('create schema coprop');
62  $this->cn->exec_sql("create sequence coprop.appel_fond_id");
63  }
Install_Plugin::create_table ( )

Definition at line 161 of file class_install_plugin.php.

References $file.

Referenced by install().

162  {
163 
164  $file=dirname(__FILE__)."/../sql/create_table.sql";
165  $this->cn->execute_script($file);
166 
167  }
$file
Definition: import_bank.php:60
Install_Plugin::create_table_assujetti ( )

Definition at line 56 of file class_install_plugin.php.

References $sql.

Referenced by install().

56  {
57  $sql="
58 CREATE TABLE tva_belge.assujetti
59 (
60  a_id serial NOT NULL,
61  start_date date NOT NULL,
62  end_date date NOT NULL,
63  xml_oid oid,
64  periodicity character(1) NOT NULL,
65  tva_name text,
66  num_tva text,
67  adress text,
68  country text,
69  date_decl date DEFAULT now(),
70  periode_dec integer,
71  CONSTRAINT assujetti_pk PRIMARY KEY (a_id)
72 )
73 ";
74  $this->cn->exec_sql($sql);
75  }
$sql
Install_Plugin::create_table_assujetti_child ( )

Definition at line 76 of file class_install_plugin.php.

References $sql.

Referenced by install().

76  {
77  $sql="
78 CREATE TABLE tva_belge.assujetti_chld
79 (
80  ac_id serial NOT NULL,
81  a_id bigint,
82  ac_tvanum text NOT NULL,
83  ac_amount numeric(20,4) NOT NULL,
84  ac_vat numeric(20,4) NOT NULL,
85  ac_qcode text NOT NULL,
86  ac_name text NOT NULL,
87  CONSTRAINT assujetti_chld_pk PRIMARY KEY (ac_id),
88  CONSTRAINT assujetti_fk FOREIGN KEY (a_id)
89  REFERENCES tva_belge.assujetti (a_id) MATCH SIMPLE
90  ON UPDATE NO ACTION ON DELETE CASCADE
91 )
92 ";
93  $this->cn->exec_sql($sql);
94  }
$sql
Install_Plugin::create_table_declaration_amount ( )

create the table tva_belge.declaration_amount

Definition at line 140 of file class_install_plugin.php.

References $sql, and table.

Referenced by install().

140  {
141  $sql=<<<EOF
142  create table tva_belge.declaration_amount
143 (
144  da_id serial,
145  d00 numeric(20,4) default 0.0 not null,
146  d01 numeric(20,4) default 0.0 not null,
147  d02 numeric(20,4) default 0.0 not null,
148  d03 numeric(20,4) default 0.0 not null,
149  d44 numeric(20,4) default 0.0 not null,
150  d45 numeric(20,4) default 0.0 not null,
151  d46 numeric(20,4) default 0.0 not null,
152  d47 numeric(20,4) default 0.0 not null,
153  d48 numeric(20,4) default 0.0 not null,
154  d49 numeric(20,4) default 0.0 not null,
155  d81 numeric(20,4) default 0.0 not null,
156  d82 numeric(20,4) default 0.0 not null,
157  d83 numeric(20,4) default 0.0 not null,
158  d84 numeric(20,4) default 0.0 not null,
159  d85 numeric(20,4) default 0.0 not null,
160  d86 numeric(20,4) default 0.0 not null,
161  d87 numeric(20,4) default 0.0 not null,
162  d88 numeric(20,4) default 0.0 not null,
163  d54 numeric(20,4) default 0.0 not null,
164  d55 numeric(20,4) default 0.0 not null,
165  d56 numeric(20,4) default 0.0 not null,
166  d57 numeric(20,4) default 0.0 not null,
167  d61 numeric(20,4) default 0.0 not null,
168  d63 numeric(20,4) default 0.0 not null,
169  dxx numeric(20,4) default 0.0 not null,
170  d59 numeric(20,4) default 0.0 not null,
171  d62 numeric(20,4) default 0.0 not null,
172  d64 numeric(20,4) default 0.0 not null,
173  dyy numeric(20,4) default 0.0 not null,
174  d71 numeric(20,4) default 0.0 not null,
175  d72 numeric(20,4) default 0.0 not null,
176  d91 numeric(20,4) default 0.0 not null,
177  start_date date not null,
178  end_date date not null,
179  xml_oid oid,
180  periodicity char(1) not null,
181  tva_name text,
182  num_tva text,
183  adress text,
184  country text,
185  date_decl date default now(),
186  periode_dec integer,
187  CONSTRAINT declaration_amount_pkey PRIMARY KEY (da_id)
188  );
189 EOF;
190 $this->cn->exec_sql($sql);
191 
192  }
$categorie_appel table
$sql
Install_Plugin::create_table_format_bank ( )

Definition at line 54 of file class_install_plugin.php.

References $sql.

Referenced by install().

54  {
55  $sql="
56  CREATE TABLE importbank.format_bank
57  (
58  id serial NOT NULL,
59  format_name text NOT NULL,
60  jrn_def_id integer,
61  pos_lib integer,
62  pos_amount integer,
63  pos_date integer,
64  pos_operation_nb integer,
65  sep_decimal character(1),
66  sep_thousand character(1),
67  sep_field character(1),
68  format_date text,
69  nb_col integer,
70  skip integer,
71  pos_third integer,
72  pos_extra integer,
73  CONSTRAINT format_bank_pkey PRIMARY KEY (id),
74  CONSTRAINT fk_jrn FOREIGN KEY (jrn_def_id)
75  REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE
76  ON UPDATE CASCADE ON DELETE SET NULL
77  )";
78 
79  $this->cn->exec_sql($sql);
80  }
$sql
Install_Plugin::create_table_import ( )

Definition at line 81 of file class_install_plugin.php.

References $sql.

Referenced by install().

82  {
83  $sql="CREATE TABLE importbank.import
84  (
85  id serial NOT NULL,
86  i_date timestamp with time zone DEFAULT now(),
87  format_bank_id bigint,
88  CONSTRAINT import_pkey PRIMARY KEY (id),
89  CONSTRAINT fk_format_bank FOREIGN KEY (format_bank_id)
90  REFERENCES importbank.format_bank (id) MATCH SIMPLE
91  ON UPDATE CASCADE ON DELETE CASCADE )";
92  $this->cn->exec_sql($sql);
93  }
$sql
Install_Plugin::create_table_intra ( )

Definition at line 95 of file class_install_plugin.php.

References $sql.

Referenced by install().

95  {
96  $sql=<<<EOF
97 
98 CREATE TABLE tva_belge.intracomm
99 (
100  i_id serial NOT NULL,
101  start_date date not null,
102  end_date date not null,
103  xml_oid oid,
104  periodicity char(1) not null,
105  tva_name text,
106  num_tva text,
107  adress text,
108  country text,
109  date_decl date default now(),
110  periode_dec integer,
111  CONSTRAINT intracom_pk PRIMARY KEY (i_id)
112 )
113 EOF;
114  $this->cn->exec_sql($sql);
115  }
$sql
Install_Plugin::create_table_intra_child ( )

Definition at line 116 of file class_install_plugin.php.

References $sql.

Referenced by install().

116  {
117 $sql=<<<EOF
118 
119 CREATE TABLE tva_belge.intracomm_chld
120 (
121  ic_id serial,
122  i_id bigint,
123  ic_tvanum text NOT NULL,
124  ic_amount numeric(20,4) NOT NULL,
125  ic_code character varying(1) NOT NULL,
126  ic_periode character varying(6) NOT NULL,
127  ic_qcode text not null,
128  ic_name text not null,
129  CONSTRAINT intracom_chld_pk PRIMARY KEY (ic_id),
130  CONSTRAINT intracom_fk FOREIGN KEY (i_id)
131  REFERENCES tva_belge.intracomm (i_id) MATCH SIMPLE
132  ON UPDATE NO ACTION ON DELETE CASCADE
133 )
134 EOF;
135 $this->cn->exec_sql($sql);
136  }
$sql
Install_Plugin::create_table_parameter ( )

Definition at line 134 of file class_install_plugin.php.

References $array, and $sql.

Referenced by install().

135  {
136  $sql = <<<EOF
137 CREATE TABLE coprop.parameter
138 (
139  pr_id text NOT NULL,
140  pr_value text,
141  CONSTRAINT copro_parameter_pkey PRIMARY KEY (pr_id)
142  );
143 EOF;
144  $this->cn->exec_sql($sql);
145 // load default value
146  $array = array(
147  'categorie_lot' => $this->lot_id,
148  'categorie_coprop' => $this->coprop_id,
149  'categorie_immeuble' => $this->immeuble_id,
150  'categorie_appel' => 0,
151  'poste_appel' => 0,
152  'categorie_charge'=>0,
153  'journal_appel' => 0
154  );
155 
156  foreach ($array as $code => $value)
157  {
158  $this->cn->exec_sql('insert into coprop.parameter(pr_id,pr_value) values ($1,$2)', array($code, $value));
159  }
160  }
if(isset($_POST['remove'])) $array
$sql
Install_Plugin::create_table_parameter ( )

Definition at line 193 of file class_install_plugin.php.

References $array, and $sql.

193  {
194 $sql=<<<EOF
195 CREATE TABLE tva_belge.parameter
196 (
197  pcode text NOT NULL,
198  pvalue text,
199  paccount text,
200  CONSTRAINT parameter_pkey PRIMARY KEY (pcode)
201  );
202 EOF;
203 $this->cn->exec_sql($sql);
204 // load default value
205 $array=array(
206  'GRIL00'=>array('6',''),
207  'GRIL01'=>array('3',''),
208  'GRIL02'=>array('2',''),
209  'GRIL03'=>array('1',''),
210  'GRIL44'=>array('',''),
211  'GRIL45'=>array('',''),
212  'GRIL46'=>array('5','70%,71%'),
213  'GRIL47'=>array('',''),
214  'GRIL48'=>array('','7091'),
215  'GRIL49'=>array('','7092'),
216  'GRIL81'=>array('1,2,3','60%'),
217  'GRIL82'=>array('1,2,3','61%'),
218  'GRIL83'=>array('1,2,3','22%,23%,24%,25%'),
219  'GRIL84'=>array('1,2,3,4','6091'),
220  'GRIL85'=>array('',''),
221  'GRIL86'=>array('5','61%,22%,23%,24%,25%,60%'),
222  'GRIL87'=>array('',''),
223  'GRIL88'=>array('',''),
224  'GRIL54'=>array('1,2,3','7%'),
225  'GRIL55'=>array('',''),
226  'GRIL56'=>array('',''),
227  'GRIL57'=>array('',''),
228  'GRIL61'=>array('',''),
229  'GRIL63'=>array('',''),
230  'GRIL59'=>array('1,2,3','6%,22%,23%,24%,25%'),
231  'GRIL62'=>array('',''),
232  'GRIL64'=>array('',''),
233  'ATVA'=>array('','4117')
234  );
235 
236 foreach ($array as $code=>$value) {
237  $this->cn->exec_sql('insert into tva_belge.parameter(pcode,pvalue,paccount) values ($1,$2,$3)',
238  array($code,$value[0],$value[1]));
239  }
240 }
if(isset($_POST['remove'])) $array
$sql
Install_Plugin::create_table_temp_bank ( )

Definition at line 94 of file class_install_plugin.php.

References $sql.

Referenced by install().

95  {
96  $sql="CREATE TABLE importbank.temp_bank
97  (
98  id serial NOT NULL,
99  tp_date date NOT NULL,
100  jrn_def_id integer,
101  libelle text,
102  amount numeric(20,4),
103  ref_operation text,
104  status character(1) DEFAULT 'N'::bpchar,
105  import_id bigint,
106  tp_third text,
107  tp_extra text,
108  f_id integer,
109  tp_rec text,
110  tp_error_msg text,
111  CONSTRAINT temp_bank_pkey PRIMARY KEY (id),
112  CONSTRAINT fk_import_id FOREIGN KEY (import_id)
113  REFERENCES importbank.import (id) MATCH SIMPLE
114  ON UPDATE CASCADE ON DELETE CASCADE,
115  CONSTRAINT fk_jrn_temp_bank FOREIGN KEY (jrn_def_id)
116  REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE
117  ON UPDATE CASCADE ON DELETE SET NULL,
118  CONSTRAINT temp_bank_f_id_fkey FOREIGN KEY (f_id)
119  REFERENCES fiche (f_id) MATCH SIMPLE
120  ON UPDATE CASCADE ON DELETE CASCADE
121  )";
122  $this->cn->exec_sql($sql);
123  }
$sql
Install_Plugin::create_table_version ( )

Definition at line 124 of file class_install_plugin.php.

References $sql.

Referenced by install().

125  {
126  $sql="CREATE TABLE importbank.version
127  (
128  version integer NOT NULL,
129  CONSTRAINT version_pkey PRIMARY KEY (version)
130  )";
131  $this->cn->exec_sql($sql);
132  }
$sql
Install_Plugin::create_tables ( )

Definition at line 52 of file class_install_plugin.php.

References $table.

Referenced by install().

53  {
54  $this->cn->start();
55  $table="CREATE TABLE amortissement.amortissement
56 (
57  a_id serial NOT NULL,
58  f_id bigint NOT NULL,
59  account_deb account_type,
60  account_cred account_type,
61  a_amount numeric(20,2) NOT NULL DEFAULT 0,
62  a_nb_year numeric(4,2) NOT NULL DEFAULT 0,
63  a_start integer,
64  a_date date,
65  a_visible character(1) DEFAULT 'Y'::bpchar,
66  CONSTRAINT amortissement_pkey PRIMARY KEY (a_id),
67  CONSTRAINT amortissement_account_cred_fkey FOREIGN KEY (account_cred)
68  REFERENCES tmp_pcmn (pcm_val) MATCH SIMPLE
69  ON UPDATE NO ACTION ON DELETE NO ACTION,
70  CONSTRAINT amortissement_account_deb_fkey FOREIGN KEY (account_deb)
71  REFERENCES tmp_pcmn (pcm_val) MATCH SIMPLE
72  ON UPDATE NO ACTION ON DELETE NO ACTION,
73  CONSTRAINT amortissement_f_id_fkey FOREIGN KEY (f_id)
74  REFERENCES fiche (f_id) MATCH SIMPLE
75  ON UPDATE NO ACTION ON DELETE NO ACTION,
76  CONSTRAINT amortissement_f_id_key UNIQUE (f_id)
77 )";
78 
79  $this->cn->exec_sql($table);
80 
81  $table="CREATE TABLE amortissement.version
82 (
83  val integer primary key
84 )";
85 
86  $this->cn->exec_sql($table);
87 
88  $table="CREATE TABLE amortissement.amortissement_detail
89 (
90  ad_id serial NOT NULL,
91  ad_amount numeric(20,2) NOT NULL DEFAULT 0,
92  a_id bigint,
93  ad_year integer,
94  ad_percentage numeric(5,2),
95  CONSTRAINT amortissement_detail_pkey PRIMARY KEY (ad_id),
96  CONSTRAINT amortissement_detail_a_id_fkey FOREIGN KEY (a_id)
97  REFERENCES amortissement.amortissement (a_id) MATCH SIMPLE
98  ON UPDATE CASCADE ON DELETE CASCADE
99 )";
100 
101  $idx="CREATE INDEX fki_amortissement
102  ON amortissement.amortissement_detail
103  USING btree
104  (a_id);";
105 
106  $this->cn->exec_sql($table);
107 
108  $table="
109 CREATE TABLE amortissement.amortissement_histo
110 (
111  ha_id serial NOT NULL,
112  a_id bigint,
113  h_amount numeric(20,4) NOT NULL,
114  jr_internal text,
115  h_year integer NOT NULL,
116  h_pj text,
117  CONSTRAINT amortissement_histo_pkey PRIMARY KEY (ha_id),
118  CONSTRAINT amortissement_histo_a_id_fkey FOREIGN KEY (a_id)
119  REFERENCES amortissement.amortissement (a_id) MATCH SIMPLE
120  ON UPDATE CASCADE ON DELETE CASCADE
121 );";
122 
123  $idx="CREATE UNIQUE INDEX amortissement_histo_uq
124  ON amortissement.amortissement_histo
125  USING btree
126  (h_year, a_id);
127 
128 ";
129  $this->cn->exec_sql($table);
130 
131  $fct="CREATE OR REPLACE FUNCTION amortissement.amortissement_ins()
132  RETURNS trigger AS
133 \$BODY\$
134 declare
135 i int;
136 nyear int;
137 n_ad_amount numeric(20,2);
138 total numeric(20,2);
139 last_ad_id bigint;
140 begin
141  i :=0;
142  total := 0;
143  loop
144 
145  if i = NEW.a_nb_year then
146  exit ;
147  end if;
148  nyear := NEW.a_start +i;
149  n_ad_amount := NEW.a_amount/NEW.a_nb_year;
150 
151  total := total + n_ad_amount;
152 
153  if total > NEW.a_amount then
154  n_ad_amount := n_ad_amount - total + NEW.a_amount ;
155  end if;
156 
157  insert into amortissement.amortissement_detail(ad_year,ad_amount,a_id,ad_percentage) values (nyear,n_ad_amount,NEW.a_id,1/NEW.a_nb_year) returning ad_id into last_ad_id;
158  insert into amortissement.amortissement_histo(a_id,h_amount,h_year) values (NEW.a_id,0,nyear);
159  i := i+1;
160  end loop;
161  if total < NEW.a_amount then
162  n_ad_amount := n_ad_amount+NEW.a_amount-total;
163  update amortissement.amortissement_detail set ad_amount=n_ad_amount where ad_id=last_ad_id;
164  end if;
165  return NEW;
166 end;
167 
168 
169 \$BODY\$
170  LANGUAGE 'plpgsql'";
171 
172  $this->cn->exec_sql($fct);
173 
174  $comment_fct="COMMENT ON FUNCTION amortissement.amortissement_ins() IS 'Fill the table amortissement_detail after an insert'";
175 
176  $this->cn->exec_sql($comment_fct);
177 
178  $fct="CREATE OR REPLACE FUNCTION amortissement.amortissement_up()
179  RETURNS trigger AS
180 \$BODY\$
181 
182 declare
183 i int;
184 nyear int;
185 n_ad_amount numeric(20,2);
186 total numeric(20,2);
187 last_ad_id bigint;
188 n_pct numeric(5,2);
189 lha_id bigint;
190 begin
191  i :=0;
192  if NEW.a_nb_year != OLD.a_nb_year or NEW.a_start != OLD.a_start or NEW.a_amount != OLD.a_amount then
193  delete from amortissement.amortissement_detail where a_id=NEW.a_id;
194  delete from amortissement.amortissement_histo where a_id=NEW.a_id and
195  (h_year < NEW.a_start or h_year > NEW.a_start+NEW.a_nb_year-1);
196 
197  n_ad_amount := round(NEW.a_amount/NEW.a_nb_year,2);
198  n_pct := round(n_ad_amount / NEW.a_amount ,2);
199  loop
200 
201  if i = NEW.a_nb_year then
202  exit ;
203  end if;
204  nyear := NEW.a_start +i;
205 
206  select ha_id into lha_id from amortissement.amortissement_histo where a_id=NEW.a_id and h_year = nyear;
207 
208  if NOT FOUND then
209  insert into amortissement.amortissement_histo(a_id,h_year,h_amount) values (NEW.a_id,nyear,0);
210  end if;
211 
212  total := round(total + n_ad_amount,2);
213 
214  if total > NEW.a_amount then
215  n_ad_amount := NEW.a_amount - total - n_ad_amount;
216  end if;
217  insert into amortissement.amortissement_detail(ad_year,ad_amount,ad_percentage,a_id) values (nyear,n_ad_amount,1/NEW.a_nb_year,NEW.a_id) returning ad_id into last_ad_id;
218  i := i+1;
219  end loop;
220  if total < NEW.a_amount then
221  n_ad_amount := n_ad_amount+NEW.a_amount-total;
222  update amortissement.amortissement_detail set ad_amount=n_ad_amount where ad_id=last_ad_id;
223  end if;
224  end if;
225  return NEW;
226 end;
227 
228 \$BODY\$
229  LANGUAGE 'plpgsql' ";
230 
231  $this->cn->exec_sql($fct);
232 
233 
234  $trigger="CREATE TRIGGER amortissement_after_ins
235  AFTER INSERT
236  ON amortissement.amortissement
237  FOR EACH ROW
238  EXECUTE PROCEDURE amortissement.amortissement_ins();";
239 
240  $this->cn->exec_sql($trigger);
241 
242  $trigger="CREATE TRIGGER amortissement_after_up
243  AFTER UPDATE
244  ON amortissement.amortissement
245  FOR EACH ROW
246  EXECUTE PROCEDURE amortissement.amortissement_up();";
247 
248  $this->cn->exec_sql($trigger);
249  $this->cn->exec_sql("insert into amortissement.version values (1)");
250  $this->cn->commit();
251  }
while(($row=fgetcsv($fbank, 0, $sp))!==false) $table
Install_Plugin::install ( )

install the plugin, create all the needed schema, tables, proc in the database

Parameters
$p_dossieris the dossier id

Definition at line 39 of file class_install_plugin.php.

References create_schema(), and create_tables().

40  {
41  $this->cn->start();
42  // create the schema
43  $this->create_schema();
44  $this->create_tables();
45 
46  $this->cn->commit();
47  }
Install_Plugin::install ( )

install the plugin, create all the needed schema, tables, proc in the database

Parameters
$p_dossieris the dossier id

Definition at line 39 of file class_install_plugin.php.

References create_schema(), create_table_format_bank(), create_table_import(), create_table_temp_bank(), and create_table_version().

39  {
40  $this->cn->start();
41  // create the schema
42  $this->create_schema();
43  // create table + put default values
44  $this->create_table_format_bank();
45  $this->create_table_import();
46  $this->create_table_temp_bank();
47  $this->create_table_version();
48 
49  $this->cn->commit();
50  }
Install_Plugin::install ( )

install the plugin, create all the needed schema, tables, proc in the database

Parameters
$p_dossieris the dossier id

Definition at line 39 of file class_install_plugin.php.

References create_schema(), create_table_assujetti(), create_table_assujetti_child(), create_table_declaration_amount(), create_table_intra(), create_table_intra_child(), and create_table_parameter().

39  {
40  $this->cn->start();
41  // create the schema
42  $this->create_schema();
43  // create table + put default values
44  $this->create_table_parameter();
46  $this->create_table_intra();
47  $this->create_table_intra_child();
48  $this->create_table_assujetti();
50 
51  $this->cn->commit();
52  }
create_table_declaration_amount()
create the table tva_belge.declaration_amount
Install_Plugin::install ( )

install the plugin, create all the needed schema, tables, proc in the database

Parameters
$p_dossieris the dossier id

Definition at line 43 of file class_install_plugin.php.

References create_card(), create_schema(), create_table(), and create_table_parameter().

44  {
45  $this->cn->start();
46  // create the schema
47  $this->create_schema();
48 
49  // create table + put default values
50  $this->create_card();
51 
52  $this->create_table_parameter();
53 
54  $this->create_table();
55 
56  $this->cn->commit();
57  }
Install_Plugin::upgrade ( )

Definition at line 168 of file class_install_plugin.php.

References $cn, $file, $version, and COPROP_VERSION.

169  {
170  global $cn;
171  $version=$cn->get_value('select max(v_id) from coprop.version');
172  for ($i=$version+1;$i<=COPROP_VERSION;$i++)
173  {
174  $file=dirname(__FILE__)."/../sql/upgrade$i.sql";
175  $this->cn->execute_script($file);
176  }
177  }
const COPROP_VERSION
$version
Definition: index.php:89
$file
Definition: import_bank.php:60
global $cn
Install_Plugin::upgrade (   $p_dest)

Upgrade schema amortissement.

Parameters
type$p_dest

Definition at line 256 of file class_install_plugin.php.

References $file.

257  {
258  $this->cn->start();
259  try {
260  if ( $p_dest == 2 ) {
261 
262  $add_column = "alter table amortissement.amortissement add card_deb bigint";
263  $add_fk="alter table amortissement.amortissement add constraint card_deb_fk foreign key (card_deb) references public.fiche(f_id) on update cascade on delete set null";
264  $add_comment =" comment on column amortissement.amortissement.card_deb is 'Charge d''amortissement' ";
265  $this->cn->exec_sql($add_column);
266  $this->cn->exec_sql($add_fk);
267  $this->cn->exec_sql($add_comment);
268 
269  $add_column = "alter table amortissement.amortissement add card_cred bigint";
270  $add_fk="alter table amortissement.amortissement add constraint card_cred_fk foreign key (card_cred) references public.fiche(f_id) on update cascade on delete set null";
271  $add_comment =" comment on column amortissement.amortissement.card_cred is 'Poste amorti' ";
272 
273  $this->cn->exec_sql($add_column);
274  $this->cn->exec_sql($add_fk);
275  $this->cn->exec_sql($add_comment);
276  $sql_create_view="
277  create or replace view amortissement.v_amortissement_summary
278 as
279  select f_id,vw_name,vw_description,quick_code,
280  a_id,account_deb,account_cred,a_amount,a_nb_year,a_start,a_date,a_visible,
281  card_cred,(select j_qcode from vw_poste_qcode where f_id=card_cred) as card_cred_qcode,
282  card_deb,(select j_qcode from vw_poste_qcode where f_id=card_deb) as card_deb_qcode,
283  ( select coalesce(sum(h_amount),0) from amortissement.amortissement_histo where amortissement_histo.a_id=amortissement.a_id) as amort_done
284  from amortissement.amortissement
285  join public.vw_fiche_attr using (f_id)
286  ";
287  $this->cn->exec_sql($sql_create_view);
288  $add_comment=" comment on view amortissement.v_amortissement_summary is 'View of material with card'";
289  $this->cn->exec_sql($add_comment);
290  $this->cn->exec_sql(' insert into amortissement.version values(2)');
291  $this->cn->commit();
292  }
293  if ($p_dest == 3 )
294  {
295  $file=dirname(__FILE__);
296  $this->cn->execute_script($file.'/../sql/upgrade2.sql');
297  }
298  } catch (Exception $e) {
299  $this->cn->rollback;
300  }
301  }
$file
Definition: import_bank.php:60

The documentation for this class was generated from the following file: