Task 0002128: Clôture comptabilité française

This commit is contained in:
sparkyx 2024-01-07 17:17:10 +01:00
parent 948a509e1f
commit e723c5c5b1
14 changed files with 2027 additions and 833 deletions

View file

@ -0,0 +1,146 @@
<?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
*/
class Operation_Opening extends Operation_Exercice
{
private $signature;
private $from_folder;
private $exercice;
function __construct()
{
parent::__construct();
$this->signature = 'opening';
}
/**
* @return mixed
*/
public function get_from_folder()
{
return $this->from_folder;
}
/**
* @param mixed $from_folder
*/
public function set_from_folder($from_folder): void
{
$this->from_folder = $from_folder;
}
/**
* @return mixed
*/
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", "number");
$this->from_folder = $http->request("dos_id", "number");
}
/**
* @brief insert data into data operation_exercice and operation_exercice_detail
* @return void
*/
function insert()
{
$cn = Dossier::connect();
$other_dossier = new Database($this->from_folder);
$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 not like '7%'
and j_poste::text not 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 'f' else 't' end debit
from total_account t1
";
$exercice_report=$this->exercice+1;
$this->operation_exercice_sql->setp("oe_type", $this->signature)
->setp("oe_dossier_id", $this->from_folder)
->set("oe_text",_("Ecriture ouverture $exercice_report"))
->setp("oe_exercice", $this->exercice);
try {
$cn->start();
$this->operation_exercice_sql->insert();
$array = $other_dossier->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;
}
}
}