noalyss Version-9
operation_opening.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// Copyright Author Dany De Bontridder danydb@aevalys.eu 6/01/24
20/*!
21 * \file
22 * \brief Operation OUVERTURE
23 */
24
25/**
26 * @class
27 * @brief Operation ouverture
28 */
30{
31 private $signature;
32 private $from_folder;
33 private $exercice;
34
36 {
37 parent::__construct($p_id);
38 $this->signature = 'opening';
39
40 }
41
42 /**
43 * @return mixed
44 */
45 public function get_from_folder()
46 {
47 return $this->from_folder;
48 }
49
50 /**
51 * @param mixed $from_folder
52 */
53 public function set_from_folder($from_folder): void
54 {
55 $this->from_folder = $from_folder;
56 }
57
58 /**
59 * @return mixed
60 */
61 public function get_exercice()
62 {
63 return $this->exercice;
64 }
65
66 /**
67 * @param mixed $exercice
68 */
69 public function set_exercice($exercice): void
70 {
71 $this->exercice = $exercice;
72 }
73
74 public function get_signature(): string
75 {
76 return $this->signature;
77 }
78
79 function from_request()
80 {
81 $http = new HttpInput();
82 $this->exercice = $http->request("exercice", "number");
83 $this->from_folder = $http->request("dos_id", "number");
84 }
85
86 /**
87 * @brief insert data into data operation_exercice and operation_exercice_detail
88 * @return void
89 */
90 function insert()
91 {
93 $other_dossier = new Database($this->from_folder);
94
95 $sql = "
96with total_account as (
97 select sum(a.montant) as tot_amount, j_poste, f_id
98 from
99 (select j_id, case when j_debit='t' then j_montant
100 else j_montant * (-1) end as montant
101 from jrnx) as a
102 join jrnx using (j_id)
103 join parm_periode on (j_tech_per = p_id )
104 where
105 p_exercice=$1
106 and j_poste::text not like '7%'
107 and j_poste::text not like '6%'
108 group by j_poste,f_id
109 having (sum(a.montant) != 0 )
110 )
111select t1.tot_amount
112 ,t1.j_poste
113 ,(select pcm_lib from tmp_pcmn where pcm_val=t1.j_poste) as lib_accounting
114 ,t1.f_id
115 ,(select ad_value fd2 from fiche_detail fd2 where fd2.f_id=t1.f_id and fd2.ad_id=23) qcode
116,(select fd3.ad_value from fiche_detail fd3 where fd3.f_id=t1.f_id and fd3.ad_id=1) f_name
117,abs(t1.tot_amount) atot_amount
118,case when tot_amount <0 then 'f' else 't' end debit
119from total_account t1
120";
121 $exercice_report=$this->exercice+1;
122 $this->operation_exercice_sql->setp("oe_type", $this->signature)
123 ->setp("oe_dossier_id", $this->from_folder)
124 ->set("oe_text",_("Ecriture ouverture $exercice_report"))
125 ->setp("oe_exercice", $this->exercice);
126 try {
127 $cn->start();
128 $this->operation_exercice_sql->insert();
129 $array = $other_dossier->get_array($sql, array($this->exercice));
130 if (empty($array)) return;
131 foreach ($array as $item) {
133 $row->oe_id = $this->operation_exercice_sql->oe_id;
134 $row->oed_poste = (empty($item['qcode']))?$item["j_poste"]:null;
135 $row->oed_qcode = $item["qcode"];
136 $row->oed_amount = $item['atot_amount'];
137 $row->oed_label=(empty($item['qcode']))?$item['lib_accounting']:$item['f_name'];
138 $row->oed_debit = $item["debit"];
139 $row->save();
140 }
141 $cn->commit();
142
143 } catch (\Exception $e) {
144 $cn->rollback();
145 echo $e->getMessage();
146 throw $e;
147 }
148
149 }
150 public function display_result()
151 {
152 echo h2("Ouverture compte");
153
154 parent::display_result(); // TODO: Change the autogenerated stub
155 }
156}
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
contains the class for connecting to Noalyss
static connect()
manage the http input (get , post, request) and extract from an array
insert()
insert data into data operation_exercice and operation_exercice_detail