altocompta/include/class/operation_closing.class.php
2025-06-23 15:49:16 +02:00

130 lines
No EOL
4.1 KiB
PHP

<?php
/*
* This file is part of NOALYSS.
*
* NOALYSS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* NOALYSS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright Author Dany De Bontridder danydb@aevalys.eu 6/01/24
/*!
* \file
* \brief Closing operation
*/
/*!
* \class Operation_Closing
* \brief closing operation , end of exercice for French accountancy
*/
class Operation_Closing extends Operation_Exercice
{
private $signature ;
private $exercice;
function __construct($p_id)
{
parent::__construct($p_id);
$this->signature='closing';
}
public function get_exercice()
{
return $this->exercice;
}
/**
* @param mixed $exercice
*/
public function set_exercice($exercice): void
{
$this->exercice = $exercice;
}
public function get_signature(): string
{
return $this->signature;
}
function from_request()
{
$http = new HttpInput();
$this->exercice = $http->request("exercice_cl", "number");
}
/**
* @brief insert data into data operation_exercice and operation_exercice_detail
* @return void
*/
function insert()
{
$cn = Dossier::connect();
$sql = "
with total_account as (
select sum(a.montant) as tot_amount, j_poste, f_id
from
(select j_id, case when j_debit='t' then j_montant
else j_montant * (-1) end as montant
from jrnx) as a
join jrnx using (j_id)
join parm_periode on (j_tech_per = p_id )
where
p_exercice=$1
and( j_poste::text like '7%'
or j_poste::text like '6%')
group by j_poste,f_id
having (sum(a.montant) != 0 )
)
select t1.tot_amount
,t1.j_poste
,(select pcm_lib from tmp_pcmn where pcm_val=t1.j_poste) as lib_accounting
,t1.f_id
,(select ad_value fd2 from fiche_detail fd2 where fd2.f_id=t1.f_id and fd2.ad_id=23) qcode
,(select fd3.ad_value from fiche_detail fd3 where fd3.f_id=t1.f_id and fd3.ad_id=1) f_name
,abs(t1.tot_amount) atot_amount
,case when tot_amount <0 then 't' else 'f' end debit
from total_account t1
";
$exercice_report=$this->exercice;
$this->operation_exercice_sql->setp("oe_type", $this->signature)
->setp("oe_dossier_id", Dossier::id())
->set("oe_text",_("Ecriture cloture $exercice_report"))
->setp("oe_exercice", $this->exercice);
try {
$cn->start();
$this->operation_exercice_sql->insert();
$array = $cn->get_array($sql, array($this->exercice));
if (empty($array)) return;
foreach ($array as $item) {
$row = new Operation_Exercice_Detail_SQL($cn);
$row->oe_id = $this->operation_exercice_sql->oe_id;
$row->oed_poste = (empty($item['qcode']))?$item["j_poste"]:null;
$row->oed_qcode = $item["qcode"];
$row->oed_amount = $item['atot_amount'];
$row->oed_label=(empty($item['qcode']))?$item['lib_accounting']:$item['f_name'];
$row->oed_debit = $item["debit"];
$row->save();
}
$cn->commit();
} catch (\Exception $e) {
$cn->rollback();
echo $e->getMessage();
throw $e;
}
}
public function display_result()
{
echo h2("Clôture compte");
parent::display_result(); // TODO: Change the autogenerated stub
}
}