noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 26/34: Task 0002128: Clôture comptabilité fra


From: dwm
Subject: [Noalyss-commit] [noalyss] 26/34: Task 0002128: Clôture comptabilité française
Date: Wed, 17 Jan 2024 12:54:08 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit 15182958d725699324df24a9d2084e8f7eb6d44f
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Jan 7 18:31:40 2024 +0100

    Task 0002128: Clôture comptabilité française
---
 html/ajax_misc.php                                 |   7 +-
 html/js/acc_ledger.js                              |  55 ++++++--
 include/ajax/ajax_operation_exercice.php           | 112 ++++++++++++++--
 include/class/operation_closing.class.php          |  87 ++++++++++++-
 include/class/operation_exercice.class.php         | 143 ++++++++++++++++++++-
 include/class/operation_opening.class.php          |  10 +-
 include/database/operation_exercice_sql.class.php  |   3 +-
 include/lib/icon_action.class.php                  |  11 ++
 include/lib/table_data_sql.class.php               |  15 +++
 include/operation_exercice.inc.php                 |  34 ++++-
 .../operation_exercice-input_row-error.php}        |  28 ++--
 .../template/operation_exercice-input_transfer.php |  56 ++++++++
 include/template/operation_exercice-list_draft.php | 100 ++++++++++++++
 sql/upgrade.sql                                    |   2 +
 14 files changed, 614 insertions(+), 49 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 173edfb35..63b197768 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -338,7 +338,12 @@ $path = array(
     "operation_exercice+display_total"=>"ajax_operation_exercice",
     // delete row  in exercice (opening/closing) operation
     "operation_exercice+delete_row"=>"ajax_operation_exercice",
-
+    // date in exercice (opening/closing) operation
+    "operation_exercice+date"=>"ajax_operation_exercice",
+    // text  in exercice (opening/closing) operation
+    "operation_exercice+text"=>"ajax_operation_exercice",
+    // transfer operation to accountancy
+    'operation_exercice+transfer'=>"ajax_operation_exercice",
 ) ;
 
 if (array_key_exists($op, $path)) {
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index 8c205ff85..5952e76b9 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -1697,7 +1697,7 @@ var operation_exercice = {
             console.error('oe-update_periode', e.message);
         }
     },
-    modify_row: function (row_operation_exercice,oe_id) {
+    modify_row: function (row_operation_exercice, oe_id) {
         try {
             var dgbox = "operation_exercice_bx";
             waiting_box();
@@ -1708,7 +1708,7 @@ var operation_exercice = {
             console.debug(row_operation_exercice);
             var queryString = {
                 op: 'operation_exercice+modify_row',
-                oe_id : oe_id,
+                oe_id: oe_id,
                 row_id: row_operation_exercice,
                 gDossier: $('gDossier').value
             };
@@ -1764,18 +1764,20 @@ var operation_exercice = {
                         }
 
                         if (req.responseJSON['status'] == "OK") {
-                            rowid=req.responseJSON['row_id'];
+                            rowid = req.responseJSON['row_id'];
                             if (queryString['row_id'] == -1) {
                                 var row = new Element("tr");
-                                row.id="oe_"+rowid;
-                                row.setAttribute("oed_id",rowid);
-                                
row.setAttribute("oe_id",req.responseJSON['oe_id']);
+                                row.id = "oe_" + rowid;
+                                row.setAttribute("oed_id", rowid);
+                                row.setAttribute("oe_id", 
req.responseJSON['oe_id']);
                                 row.update(req.responseJSON['content']);
                                 $("operation_exercice_tb").appendChild(row);
-                                row.addEventListener("click",function(event) 
{operation_exercice.click_modify_row(row)})
+                                row.addEventListener("click", function (event) 
{
+                                    operation_exercice.click_modify_row(row)
+                                })
 
-                            } else{
-                                
$("oe_"+rowid).update(req.responseJSON['content']);
+                            } else {
+                                $("oe_" + 
rowid).update(req.responseJSON['content']);
                             }
                             new Effect.Highlight("oe_" + 
req.responseJSON['row_id'], {
                                 startcolor: '#FAD4D4',
@@ -1863,6 +1865,39 @@ var operation_exercice = {
         }
     },
     click_modify_row: function (item) {
-        
operation_exercice.modify_row(item.getAttribute("oed_id"),item.getAttribute("oe_id"));
+        operation_exercice.modify_row(item.getAttribute("oed_id"), 
item.getAttribute("oe_id"));
+    },
+    /**
+     * check and transfer if it is good
+     */
+    transfer: function () {
+        try {
+            var dgbox = "oe_transfer_div";
+            waiting_box();
+
+            var queryString = 
$("operation_exercice_transfer_frm").serialize(true);
+            var action = new Ajax.Request(
+                "ajax_misc.php",
+                {
+                    method: 'GET',
+                    parameters: queryString,
+                    onFailure: ajax_misc_failure,
+                    onSuccess: function (req) {
+                        remove_waiting_box();
+                        if (req.responseText == 'NOCONX') {
+                            reconnect();
+                            return;
+                        }
+                        var answer=req.responseJSON;
+console.debug(answer['content']);
+                        
$('operation_exercice_transfer_info').update(answer.content);
+
+
+                    }
+                }
+            );
+        } catch (e) {
+            alert_box(e.message);
+        }
     }
 }
diff --git a/include/ajax/ajax_operation_exercice.php 
b/include/ajax/ajax_operation_exercice.php
index 0b253ac3d..af43693b6 100644
--- a/include/ajax/ajax_operation_exercice.php
+++ b/include/ajax/ajax_operation_exercice.php
@@ -52,14 +52,14 @@ if ($op == "operation_exercice+update_periode") {
 if ($op == "operation_exercice+modify_row") {
     try {
         $row_id = $http->post("row_id", "number", -1);
-        $oe_id=$http->post("oe_id","number");
+        $oe_id = $http->post("oe_id", "number");
     } catch (\Exception $e) {
         echo $e->getMessage();
         return;
     }
     $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id);
-    $operation_detail_sql->oe_id=$oe_id;
-  if ( $row_id == -1)  $operation_detail_sql->oed_debit='f';
+    $operation_detail_sql->oe_id = $oe_id;
+    if ($row_id == -1) $operation_detail_sql->oed_debit = 'f';
     Operation_Exercice::input_row($operation_detail_sql);
 
     return;
@@ -86,7 +86,7 @@ if ($op == "operation_exercice+save_row") {
         ->setp("oed_qcode", $qcode)
         ->setp("oed_label", $label)
         ->setp("oed_amount", $amount)
-        ->setp("oe_id",$oe_id)
+        ->setp("oe_id", $oe_id)
         ->setp("oed_debit", $debit);
     try {
         $operation_detail_sql->save();
@@ -94,7 +94,7 @@ if ($op == "operation_exercice+save_row") {
 
         ob_start();
         $operation_exercice = new Operation_Exercice();
-        if ($row_id == -1 ) {
+        if ($row_id == -1) {
             $operation_exercice->display_row($data, true);
         } else {
 
@@ -140,14 +140,108 @@ if ($op == "operation_exercice+delete_row") {
     try {
         $row_id = $http->get("row_id", "number");
         $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, 
$row_id);
-        $oe_id=$operation_detail_sql->oe_id;
-        $other_row=$cn->get_value("select oed_id from 
operation_exercice_detail where oe_id=$1 limit 1 ",
-        [$oe_id]);
+        $oe_id = $operation_detail_sql->oe_id;
+        $other_row = $cn->get_value("select oed_id from 
operation_exercice_detail where oe_id=$1 limit 1 ",
+            [$oe_id]);
 
         $operation_detail_sql->delete();
-        echo json_response(array("status"=>"OK","row_id"=>$other_row));
+        echo json_response(array("status" => "OK", "row_id" => $other_row));
     } catch (\Exception $e) {
         echo $e->getMessage();
         return;
     }
 }
+//-------------------------------------------------------------------------------------------
+// Change the date
+//-------------------------------------------------------------------------------------------
+if ($op == "operation_exercice+date") {
+    try {
+        $oe_id = $http->request("oe_id", "number");
+    } catch (\Exception $e) {
+        echo $e->getMessage();
+    }
+    $input = $http->request("input");
+    $action = $http->request("ieaction", "string", "display");
+    $ajax_date = Inplace_Edit::build($input);
+    $ajax_date->add_json_param("op", "operation_exercice+date");
+    $ajax_date->add_json_param("gDossier", Dossier::id());
+    $ajax_date->add_json_param("oe_id", $oe_id);
+    $ajax_date->set_callback("ajax_misc.php");
+
+    if ($action == "display") {
+
+        echo $ajax_date->ajax_input();
+    }
+    if ($action == "ok") {
+        $value = $http->request("value");
+        $cn->exec_sql("update operation_exercice set 
oe_date=to_date($1,'DD.MM.YYYY') where oe_id=$2", [$value, $oe_id]);
+        $ajax_date->set_value($value);
+        echo $ajax_date->value();
+    }
+    if ($action == "cancel") {
+
+        echo $ajax_date->value();
+    }
+    return;
+}
+//-------------------------------------------------------------------------------------------
+// Change the text
+//-------------------------------------------------------------------------------------------
+if ($op == "operation_exercice+text") {
+    try {
+        $oe_id = $http->request("oe_id", "number");
+    } catch (\Exception $e) {
+        echo $e->getMessage();
+    }
+    $input = $http->request("input");
+    $action = $http->request("ieaction", "string", "display");
+    $ajax_text = Inplace_Edit::build($input);
+    $ajax_text->add_json_param("op", "operation_exercice+text");
+    $ajax_text->add_json_param("gDossier", Dossier::id());
+    $ajax_text->add_json_param("oe_id", $oe_id);
+    $ajax_text->set_callback("ajax_misc.php");
+
+    if ($action == "display") {
+
+        echo $ajax_text->ajax_input();
+    }
+    if ($action == "ok") {
+        $value = $http->request("value");
+        $cn->exec_sql("update operation_exercice set oe_text=$1 where 
oe_id=$2", [$value, $oe_id]);
+        $ajax_text->set_value($value);
+        echo $ajax_text->value();
+    }
+    if ($action == "cancel") {
+
+        echo $ajax_text->value();
+    }
+    return;
+}
+//-------------------------------------------------------------------------------------------
+// Check and transfer to accountancy if OK
+//-------------------------------------------------------------------------------------------
+if ($op == "operation_exercice+transfer") {
+    try {
+        $operation_exercice_id = $http->request("oe_id", "number");
+        $ledger_id = $http->request('p_jrn', "number");
+        if ($g_user->check_jrn($ledger_id) == "X") throw new \Exception 
(EXC_FORBIDDEN);
+    } catch (\Exception $e) {
+        echo $e->getMessage();
+        return;
+    }
+    // first , check that everything is ok
+    $operation_exercice = new Operation_Exercice($operation_exercice_id);
+
+    global $oe_result, $oe_status;
+    $answer = array();
+    $operation_exercice->submit_transfer($ledger_id);
+    $answer['status'] = $oe_status;
+    if ($answer['status'] == 'NOK') {
+        $answer['content'] = span($oe_result, 'class=warning');
+    }else {
+        $answer['content'] = span($oe_result);
+
+    }
+    echo json_response($answer);
+    return;
+}
\ No newline at end of file
diff --git a/include/class/operation_closing.class.php 
b/include/class/operation_closing.class.php
index b82a6bc1d..2794e22d3 100644
--- a/include/class/operation_closing.class.php
+++ b/include/class/operation_closing.class.php
@@ -24,13 +24,26 @@
 class Operation_Closing extends Operation_Exercice
 {
     private $signature ;
+    private $exercice;
 
-    function __construct()
+    function __construct($p_id)
     {
-        parent::__construct();
+        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;
@@ -38,6 +51,76 @@ class Operation_Closing extends Operation_Exercice
 
     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 'f' else 't' 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
     }
 }
\ No newline at end of file
diff --git a/include/class/operation_exercice.class.php 
b/include/class/operation_exercice.class.php
index 076463357..d76e4bd05 100644
--- a/include/class/operation_exercice.class.php
+++ b/include/class/operation_exercice.class.php
@@ -26,6 +26,7 @@ class Operation_Exercice
 {
     protected $operation_exercice_sql;
 
+
     public function __construct($p_id = -1)
     {
         $this->operation_exercice_sql = new 
Operation_Exercice_SQL(Dossier::connect(), $p_id);
@@ -42,6 +43,27 @@ class Operation_Exercice
 
     function display_result()
     {
+        $date = new IDate("exercice_date");
+        $date->id = "exercice_date";
+        $date->value = 
format_date($this->operation_exercice_sql->getp("oe_date"), "DD.MM.YYYY");
+        $inplace_date = new Inplace_Edit($date);
+        $inplace_date->add_json_param("op", "operation_exercice+date");
+        $inplace_date->add_json_param("gDossier", Dossier::id());
+        $inplace_date->add_json_param("oe_id", 
$this->operation_exercice_sql->oe_id);
+        $inplace_date->set_callback("ajax_misc.php");
+        echo _("Date"), $inplace_date->input();
+
+        $text_operation = new IText("text_operation");
+        $text_operation->id = uniqid("text");
+        $text_operation->size = 80;
+        $text_operation->value = 
$this->operation_exercice_sql->getp("oe_text");
+        $inplace_text = new Inplace_Edit($text_operation);
+        $inplace_text->add_json_param("op", "operation_exercice+text");
+        $inplace_text->add_json_param("gDossier", Dossier::id());
+        $inplace_text->add_json_param("oe_id", 
$this->operation_exercice_sql->oe_id);
+        $inplace_text->set_callback("ajax_misc.php");
+        echo $inplace_text->input();
+
         $cn = Dossier::connect();
         // get data
         $a_data = $cn->get_array("
@@ -59,6 +81,7 @@ class Operation_Exercice
 
         ", [$this->operation_exercice_sql->oe_id]);
         $aheader = array(_("Poste"), _("Fiche"), _("Libellé"), _("Montant"), 
_("Débit/Crédit"));
+        echo '<div></div>';
         echo \HtmlInput::filter_table("operation_exercice_tb", '0,1,2,3,4', 1);
         echo \HtmlInput::button_action(_("Ajouter une ligne"), 
sprintf("operation_exercice.modify_row('-1','%s')", 
$this->operation_exercice_sql->oe_id));
         echo '<table class="result" id="operation_exercice_tb">';
@@ -107,7 +130,7 @@ select sum(signed_amount) delta,sum(debit) 
debit,sum(credit) credit from saldo_d
 
         echo span(sprintf(_("Débit   %s"), nbm($total['debit'])), $style);
         echo span(sprintf(_("Crédit  %s"), nbm($total['credit'])), $style);
-        $s="";
+        $s = "";
         if ($total['delta'] > 0) {
             $s = " Solde débiteur ";
         }
@@ -150,7 +173,125 @@ select sum(signed_amount) delta,sum(debit) 
debit,sum(credit) credit from saldo_d
      */
     public static function input_row(Operation_Exercice_Detail_SQL 
$operation_detail_sql)
     {
+        $operation=new 
Operation_Exercice_SQL($operation_detail_sql->get_cn(),$operation_detail_sql->getp("oe_id"));
+        if ( $operation->getp("oe_transfer_date") !="") {
+            require_once NOALYSS_TEMPLATE . 
"/operation_exercice-input_row-error.php";
+            return;
+        }
+
         require_once NOALYSS_TEMPLATE . "/operation_exercice-input_row.php";
     }
 
+    /**
+     * @brief input data for transfering
+     * @return void
+     */
+    function input_transfer()
+    {
+        $operation=$this->operation_exercice_sql;
+        if ( $operation->getp("oe_transfer_date") !="") {
+            echo '<span class="warning">';
+            printf(_("Opération transférée le %s")
+                ,$operation->getp("oe_transfer_date") );
+            echo '</span>';
+            return;
+        }
+        require_once NOALYSS_TEMPLATE . 
"/operation_exercice-input_transfer.php";
+    }
+
+    /**
+     * @brief transfer to accountancy
+     * @param $ledger_id int the ledger id (jrn_def_id)
+     * @return void
+     */
+    function submit_transfer($ledger_id)
+    {
+        global $oe_result; // result of operation
+        global $oe_data; // transform data to array used by Acc_Ledger::insert
+        global $oe_status ; // status OK or NOK
+        $cn = Dossier::connect();
+
+        $this->transform($ledger_id);
+
+        $oe_status = "OK";
+        $ledger = new Acc_Ledger($cn, $ledger_id);
+        try {
+            $cn->start();
+            if ($this->operation_exercice_sql->getp("oe_transfer_date")!="") 
throw new \Exception("duplicate",EXC_DUPLICATE);
+            if ( empty($oe_data['e_date']  ) ) throw new \Exception ("Date 
null",2);
+            $ledger->verify_operation($oe_data);
+            $ledger->save($oe_data);
+            $oe_result=_("Détail opération");
+            $oe_result.=sprintf('<a class="detail" style="display:inline" 
href="javascript:modifyOperation(%d,%d)">%s</a><hr>',
+                $ledger->jr_id, dossier::id(), $ledger->internal);
+
+            $cn->exec_sql("update operation_exercice set 
oe_transfer_date=to_timestamp($1,'DD.MM.YY HH24:MI') ,  jr_internal=$2 where 
oe_id=$3",
+            [date('d.m.Y 
H:i'),$ledger->internal,$this->operation_exercice_sql->oe_id]);
+
+            $cn->commit();
+            return true;
+        } catch (\Exception $e) {
+//            $a_error=array(2=>_("la date est obligatoire",),1=>_('Crédit et 
débit non équilibré'),3=>_("Montant invalide"),
+//                4=>_("Fiche non permise dans ce journal"),6=>_("Période 
fermée ou inexistante"),EXC_DUPLICATE=>_("Opération déja transférée"));
+//            $exc_code=$e->getCode();
+//
+//            if ( isset($a_error[$exc_code] ) )
+//                $oe_result=$a_error[$e->getCode()];
+//            else
+            $oe_result=$e->getMessage();
+
+            $oe_status='NOK';
+            $cn->rollback();
+        }
+        return false;
+
+    }
+
+    function transform($ledger_id)
+    {
+        global $oe_data; // transform data to array used by 
Acc_Ledger::verify_operation
+        $cn = Dossier::connect();
+        $acc_ledger=new \Acc_Ledger($cn, $ledger_id);
+        $oe_data = array();
+        $oe_data['p_currency_code'] = 0;
+        $oe_data['p_currency_rate'] = 1;
+        $oe_data['p_jrn'] = $ledger_id;
+        $oe_data['e_date'] = $this->operation_exercice_sql->oe_date;
+        $oe_data['desc']=$this->operation_exercice_sql->getp("oe_text");
+        $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn);
+        $all_operation = $operation_detail_sql->collect_objects(' where oe_id 
= $1',[$this->operation_exercice_sql->oe_id]);
+        $nb = 0;
+        foreach ($all_operation as $item) {
+            $oe_data['qc_' . $nb] = $item->oed_qcode;
+            $oe_data['poste' . $nb] = $item->oed_poste;
+            $oe_data['ld' . $nb] = $item->oed_label;
+            $oe_data['amount' . $nb] = $item->oed_amount;
+
+            if ($item->oed_debit == "t") $oe_data['ck' . $nb] = 't';
+            $nb++;
+        }
+        $oe_data['nb_item']=$nb;
+        $oe_data['e_pj']=$acc_ledger->guess_pj();
+        $oe_data['e_pj_suggest']=$acc_ledger->guess_pj();
+        $oe_data['mt']=microtime(true);
+        
$oe_data['jr_optype']=($this->operation_exercice_sql->getp('oe_type')=='opening')?'OPE':'CLO';
+
+    }
+
+    public static function list_draft()
+    {
+
+        require_once NOALYSS_TEMPLATE."/operation_exercice-list_draft.php";
+
+    }
+
+    public static function delete($aOperation_id)
+    {
+        $cn=Dossier::connect();
+        foreach ($aOperation_id as $operation_id)
+        {
+            $cn->exec_sql("delete from operation_exercice where 
oe_id=$1",[$operation_id]);
+        }
+    }
+
 }
diff --git a/include/class/operation_opening.class.php 
b/include/class/operation_opening.class.php
index 298a2ca8d..4252cb972 100644
--- a/include/class/operation_opening.class.php
+++ b/include/class/operation_opening.class.php
@@ -28,9 +28,9 @@ class Operation_Opening extends Operation_Exercice
     private $from_folder;
     private $exercice;
 
-    function __construct()
+    function __construct($p_id)
     {
-        parent::__construct();
+        parent::__construct($p_id);
         $this->signature = 'opening';
 
     }
@@ -143,4 +143,10 @@ from total_account t1
         }
 
     }
+    public function display_result()
+    {
+        echo h2("Ouverture compte");
+
+        parent::display_result(); // TODO: Change the autogenerated stub
+    }
 }
\ No newline at end of file
diff --git a/include/database/operation_exercice_sql.class.php 
b/include/database/operation_exercice_sql.class.php
index c295d9002..9bb256b8d 100644
--- a/include/database/operation_exercice_sql.class.php
+++ b/include/database/operation_exercice_sql.class.php
@@ -49,6 +49,7 @@ class Operation_Exercice_SQL extends Table_Data_SQL
             "tech_date" => "tech_date",
             "oe_dossier_id" => "oe_dossier_id",
             "oe_exercice" => "oe_exercice",
+            "oe_transfer_date"=>"oe_transfer_date"
 
         );
         /*
@@ -63,7 +64,7 @@ class Operation_Exercice_SQL extends Table_Data_SQL
             "tech_date" => "date",
             "oe_dossier_id" => "number",
             "oe_exercice" => "number",
-
+            "oe_transfer_date"=>"date"
         );
 
 
diff --git a/include/lib/icon_action.class.php 
b/include/lib/icon_action.class.php
index ed6ad1c23..d189cc3e1 100644
--- a/include/lib/icon_action.class.php
+++ b/include/lib/icon_action.class.php
@@ -306,6 +306,17 @@ class Icon_Action
                 $p_javascript);
         return $r;
     }
+
+    static function detail_anchor($p_id,$url)
+    {
+        $r=sprintf('
+    <A HREF="%s">
+    <span id="%s"  class="smallicon icon" 
style="margin-left:5px">&#xe803;</span></A>',
+            $url
+                ,$p_id);
+
+        return $r;
+    }
     static function more($p_id,$p_javascript)
     {
         $r=sprintf('<span id="%s" onclick="%s" class="smallicon icon" 
style="margin-left:5px">&#xe824;</span>',
diff --git a/include/lib/table_data_sql.class.php 
b/include/lib/table_data_sql.class.php
index d34699623..7b5428adc 100644
--- a/include/lib/table_data_sql.class.php
+++ b/include/lib/table_data_sql.class.php
@@ -140,7 +140,22 @@ abstract class Table_Data_SQL extends Data_SQL
         $sql=" delete from ".$this->table." where ".$this->primary_key."= $1";
         $this->cn->exec_sql($sql,array($this->$pk));
     }
+    /**
+     * @brief update the value of a column with an expression for $value for 
the current record
+     * @param $column_exp string like column = $1 or column=function($1)
+     * @param $value value replacing $1
+     * @note you can use it for entering a date with the hour and minute like 
this
+     *  $this->column_update("field_date = to_date($1,'DD.MM.YY 
HH24:MI'),date('d.m.Y H:i'))
+     *
+     * @return Table_Data_SQL
+     */
+    function column_update($column_expr,$value) {
+        $pk=$this->primary_key;
+        $sql="update ".$this->table." set {$column_expr} where 
{$this->primary_key} = $2";
+        $this->cn->exec_sql($sql,[$value,$this->$pk]);
+        return $this;
 
+    }
     public function update()
     {
         $this->verify();
diff --git a/include/operation_exercice.inc.php 
b/include/operation_exercice.inc.php
index 40555f4b6..b54a25388 100644
--- a/include/operation_exercice.inc.php
+++ b/include/operation_exercice.inc.php
@@ -26,6 +26,15 @@ $http=new HttpInput();
 if ( $http->request("sa","string","") == "" )
 {
     Operation_Exercice::input_source();
+    Operation_Exercice::list_draft();
+    return;
+
+}
+if ( $http->request("sa","string" ) == "remove" )
+{
+    Operation_Exercice::delete($http->post("operation_list"));
+    Operation_Exercice::input_source();
+    Operation_Exercice::list_draft();
     return;
 }
 if ( $http->request("sa") == "opening")
@@ -34,16 +43,35 @@ if ( $http->request("sa") == "opening")
     $operation_exercice_id= $http->get("operation_exercice_id","number",-1);
     $operation_opening=new Operation_Opening($operation_exercice_id);
     try {
-        // take data from request
-        $operation_opening->from_request();
         if ( $operation_exercice_id == -1 ) {
+            // take data from request
+            $operation_opening->from_request();
             $operation_opening->insert();
         }
         // Display result
         $operation_opening->display_result();
+        $operation_opening->input_transfer();
+    } catch (\Exception $e) {
+        echo $e->getMessage();
+    }
+    return;
+}
+if ( $http->request("sa") == "closing")
+{
 
+    $operation_exercice_id= $http->get("operation_exercice_id","number",-1);
+    $operation_closing=new Operation_Closing($operation_exercice_id);
+    try {
+        if ( $operation_exercice_id == -1 ) {
+            // take data from request
+            $operation_closing->from_request();
+            $operation_closing->insert();
+        }
+        // Display result
+        $operation_closing->display_result();
+        $operation_closing->input_transfer();
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
     return;
-}
\ No newline at end of file
+}
diff --git a/include/class/operation_closing.class.php 
b/include/template/operation_exercice-input_row-error.php
similarity index 66%
copy from include/class/operation_closing.class.php
copy to include/template/operation_exercice-input_row-error.php
index b82a6bc1d..f6b2c0e9c 100644
--- a/include/class/operation_closing.class.php
+++ b/include/template/operation_exercice-input_row-error.php
@@ -16,28 +16,16 @@
  *   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
+// Copyright Author Dany De Bontridder danydb@aevalys.eu 11/01/24
 /*! 
  * \file
- * \brief 
+ * \brief operation already transfered
  */
-class Operation_Closing extends Operation_Exercice
-{
-    private $signature ;
 
-    function __construct()
-    {
-        parent::__construct();
-        $this->signature='closing';
+Noalyss\Dbg::echo_file(__FILE__);
+echo \HtmlInput::title_box("", "operation_exercice_bx");
 
-    }
-    public function get_signature(): string
-    {
-        return $this->signature;
-    }
-
-    function from_request()
-    {
-
-    }
-}
\ No newline at end of file
+printf(_("Opération transférée le %s"),$operation->getp("oe_transfer_date") );
+echo '<ul class="aligned-block">';
+echo \HtmlInput::button_close("operation_exercice_bx") ;
+echo '</li>';
\ No newline at end of file
diff --git a/include/template/operation_exercice-input_transfer.php 
b/include/template/operation_exercice-input_transfer.php
new file mode 100644
index 000000000..bd8a32867
--- /dev/null
+++ b/include/template/operation_exercice-input_transfer.php
@@ -0,0 +1,56 @@
+<?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 7/01/24
+/*! 
+ * \file
+ * \brief propose to transfer
+ */
+Noalyss\Dbg::echo_file(__FILE__);
+$cn=Dossier::connect();
+?>
+<?=HtmlInput::button_action(_("Transfert"),"$('operation_exercice_transfer_info').update();$('oe_transfer_div').show()")?>
+<div class="inner_box" id="oe_transfer_div" style="display:none;position: 
fixed;top:25%;overflow-scrolling: auto">
+    <?= HtmlInput::title_box(_("Transfert à la comptabilité"), 
"oe_transfer_div") ?>
+    <form method="POST" id="operation_exercice_transfer_frm" 
onsubmit="operation_exercice.transfer();return false;">
+        <?php
+        echo HtmlInput::array_to_hidden(array("ac", "gDossier"), $_REQUEST);
+        echo HtmlInput::hidden("op", "operation_exercice+transfer");
+        echo HtmlInput::hidden("oe_id", $this->operation_exercice_sql->oe_id);
+        // show the ledger
+
+        $ledger = new Acc_Ledger($cn, 0);
+        $wLedger = $ledger->select_ledger('ODS', 2, FALSE);
+        if ($wLedger == null)
+            throw new Exception(_('Pas de journal disponible'));
+
+        echo _("Journal destination"), $wLedger->input();
+
+        ?>
+        <div id="operation_exercice_transfer_info" ></div>
+        <ul class="aligned-block">
+            <li>
+                <?= \HtmlInput::submit("save", _("Sauve")) ?>
+            </li>
+            <li>
+                <?= \HtmlInput::button_hide("oe_transfer_div") ?>
+            </li>
+
+        </ul>
+    </form>
+</div>
diff --git a/include/template/operation_exercice-list_draft.php 
b/include/template/operation_exercice-list_draft.php
new file mode 100644
index 000000000..2b176b6f1
--- /dev/null
+++ b/include/template/operation_exercice-list_draft.php
@@ -0,0 +1,100 @@
+<?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 11/01/24
+/*! 
+ * \file
+ * \brief display draft  OPERATION_EXERCICE
+ */
+$http = new HttpInput();
+$cn=Dossier::connect();
+$a_operation = $cn->get_array("select oe_id
+    ,to_char(oe_date,'DD.MM.YY') str_date
+    ,to_char(oe_transfer_date,'DD.MM.YY') str_transfer_date
+    ,to_char(tech_date,'DD.MM.YY HH24:MI') draft_date
+    ,jr_internal
+    ,tech_user
+    ,oe_text 
+    ,oe_type
+ from operation_exercice order by oe_id desc");
+
+$aUrl = ["ac" => $http->request("ac"), "gDossier" => Dossier::id()];
+$checkbox=new ICheckBox("operation_list[]");
+$checkbox->set_range("operation_range");
+?>
+<form method="POST">
+    <?php
+    echo \HtmlInput::array_to_hidden(["gDossier", "sa"], $_REQUEST);
+    echo \HtmlInput::hidden("sa", "remove");
+    ?>
+<table class="result">
+    <tr>
+        <th>
+            <?= _("Date brouillon") ?>
+        </th>
+        <th>
+            <?= _("Date opération") ?>
+        </th>
+        <th>
+            <?= _("Description") ?>
+        </th>
+        <th>
+            <?= _("Utilisateur") ?>
+        </th>
+        <th>
+
+            <?= _("Date transfert") ?>
+        </th>
+        <th><?=_("opération")?></th>
+        <th>
+
+        </th>
+    </tr>
+    <?php
+    foreach ($a_operation as $operation) {
+        $aUrl['operation_exercice_id'] = $operation['oe_id'];
+        $aUrl['sa'] = $operation['oe_type'];
+        $url = NOALYSS_URL . "/do.php?" . http_build_query($aUrl);
+        $checkbox->value=$operation['oe_id'];
+        $detail="";
+        if ( ! empty ($operation['jr_internal'])) {
+            $jr_id=$cn->get_value("select jr_id from jrn where jr_internal 
=$1",[$operation['jr_internal']]);
+            if (!empty($jr_id))
+                
$detail=\HtmlInput::detail_op($jr_id,$operation['jr_internal']);
+        }
+        ?>
+<tr>
+    <td class=""><?=$operation['draft_date']?></td>
+    <td class=""><?=$operation['str_date']?></td>
+    <td class=""><?=$operation['oe_text']?></td>
+    <td class=""><?=$operation['tech_user']?></td>
+    <td class=""><?=$operation['str_transfer_date']?></td>
+    <td class=""><?=$detail?></td>
+    <td class=""><?=\Icon_Action::detail_anchor(uniqid(), $url)?></td>
+    <td><?=$checkbox->input()?></td>
+</tr>
+        <?php
+    }
+
+    ?>
+</table>
+    <?=\HtmlInput::submit("remove",_("Efface la sélection"))?>
+</form>
+<?php
+echo ICheckBox::javascript_set_range("operation_range");
+
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 15c9ce17e..03abdc0a2 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -72,6 +72,8 @@ create table operation_exercice
     oe_text text ,
     oe_dossier_id int not null,
     oe_exercice int not null,
+    jr_internal text,
+    oe_transfer_date timestamp,
     tech_user text,
     tech_date timestamp default  now()
 );



reply via email to

[Prev in Thread] Current Thread [Next in Thread]