noalyss Version-9
operation_closing.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
23 */
25{
26 private $signature ;
27 private $exercice;
28
30 {
31 parent::__construct($p_id);
32 $this->signature='closing';
33
34 }
35 public function get_exercice()
36 {
37 return $this->exercice;
38 }
39
40 /**
41 * @param mixed $exercice
42 */
43 public function set_exercice($exercice): void
44 {
45 $this->exercice = $exercice;
46 }
47 public function get_signature(): string
48 {
49 return $this->signature;
50 }
51
52 function from_request()
53 {
54 $http = new HttpInput();
55 $this->exercice = $http->request("exercice_cl", "number");
56 }
57 /**
58 * @brief insert data into data operation_exercice and operation_exercice_detail
59 * @return void
60 */
61 function insert()
62 {
64
65 $sql = "
66with total_account as (
67 select sum(a.montant) as tot_amount, j_poste, f_id
68 from
69 (select j_id, case when j_debit='t' then j_montant
70 else j_montant * (-1) end as montant
71 from jrnx) as a
72 join jrnx using (j_id)
73 join parm_periode on (j_tech_per = p_id )
74 where
75 p_exercice=$1
76 and( j_poste::text like '7%'
77 or j_poste::text like '6%')
78 group by j_poste,f_id
79 having (sum(a.montant) != 0 )
80 )
81select t1.tot_amount
82 ,t1.j_poste
83 ,(select pcm_lib from tmp_pcmn where pcm_val=t1.j_poste) as lib_accounting
84 ,t1.f_id
85 ,(select ad_value fd2 from fiche_detail fd2 where fd2.f_id=t1.f_id and fd2.ad_id=23) qcode
86,(select fd3.ad_value from fiche_detail fd3 where fd3.f_id=t1.f_id and fd3.ad_id=1) f_name
87,abs(t1.tot_amount) atot_amount
88,case when tot_amount <0 then 'f' else 't' end debit
89from total_account t1
90";
91 $exercice_report=$this->exercice;
92 $this->operation_exercice_sql->setp("oe_type", $this->signature)
93 ->setp("oe_dossier_id", Dossier::id())
94 ->set("oe_text",_("Ecriture cloture $exercice_report"))
95 ->setp("oe_exercice", $this->exercice);
96 try {
97 $cn->start();
98 $this->operation_exercice_sql->insert();
99 $array = $cn->get_array($sql, array($this->exercice));
100 if (empty($array)) return;
101 foreach ($array as $item) {
103 $row->oe_id = $this->operation_exercice_sql->oe_id;
104 $row->oed_poste = (empty($item['qcode']))?$item["j_poste"]:null;
105 $row->oed_qcode = $item["qcode"];
106 $row->oed_amount = $item['atot_amount'];
107 $row->oed_label=(empty($item['qcode']))?$item['lib_accounting']:$item['f_name'];
108 $row->oed_debit = $item["debit"];
109 $row->save();
110 }
111 $cn->commit();
112
113 } catch (\Exception $e) {
114 $cn->rollback();
115 echo $e->getMessage();
116 throw $e;
117 }
118
119 }
120 public function display_result()
121 {
122 echo h2("ClĂ´ture compte");
123
124 parent::display_result(); // TODO: Change the autogenerated stub
125 }
126}
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
static id()
return the 'gDossier' value after a check
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