#0000179 Finaliser supprimer une operation reccurente
authorroot <root@n3150.home>
Fri, 27 Jan 2023 10:28:16 +0000 (11:28 +0100)
committerroot <root@n3150.home>
Fri, 27 Jan 2023 10:28:16 +0000 (11:28 +0100)
app/compta/api/recurrent.php
app/compta/controlers/recurrent.php
app/compta/models/recurrent.php

index d0f6ba10b0e7b86c1d197555c8413d6dcda99021..a663a242545603679ef294c0af94dc52f003ca8e 100644 (file)
@@ -124,7 +124,6 @@ _EOF;
             return Array('');
         }
         $r_id = $r['r_id'];
-        error_log("Recurrent::update ".$r_id." update add entries ".$r['r_next']."\n");
         foreach($entries as $entry)
         {
             $this->insertEntry($r_id,$entry);
@@ -150,7 +149,7 @@ _EOF;
     }
 
     /**
-     * \brief, return the list of loans
+     * \brief, return the info for the given recurrent id.
      * TODO: Not sure if it's the right place
      */
     function get($rid)
@@ -165,6 +164,26 @@ _EOF;
       }
       return $res['records'][0];
     }
+
+    /**
+     * Delete the recurrent operation and its' entries
+     * :
+     * @param  the recurrent  id
+     * @return
+     */
+    function remove($rid)
+    {
+      $q =<<<_EOF
+DELETE from `RecurrentEntry`  WHERE re_rec_id = {$rid};
+DELETE from `Recurrent`  WHERE r_id = {$rid};
+_EOF;
+      try {
+        $res = $this->doQueryI($q);
+      } catch (Exception $e) {
+        error_log("Recurrent::remove ".$id." Failed ".$e->getMessage());
+      }
+      return $res['records'];
+    }
     /**
      *
      * TODO: Not sure if it's the right place
index ffb586b40bb7ab7c54e55bf706117a58ec73d61a..8412c94602031d84cb607ec5cf91d79919e1f88b 100644 (file)
@@ -112,9 +112,13 @@ class Recurrent
         $this->_model->get($_id);
         if (\AEB::$REQUEST['confirm'] == 'yes')
         {
-          return new \compta\views\recurrent\Remove($this->_model);
-        } else;
-          return new \compta\views\recurrent\Remove($this->_model);
+            return new \compta\views\recurrent\Remove($this->_model);
+        } else
+        {
+            $this->_model->remove($_id);
+            require_once(controler::$basedir."/views/recurrent_index.php");
+            return new \compta\views\recurrent\Index();
+        }
     }
     /**
      * Get the details of the supplier account.
index de8798754702e9b69fafbd9245ee299fa936ccbb..0ad116740fd09906dbe05ef780345b4987e32afd 100644 (file)
@@ -345,6 +345,21 @@ class Model implements \JsonSerializable
         }
         return [ 'des' => $this->des, 'lst' => $this->lst];
     }
+    /**
+     * @brief remove recurrent and it's entries 
+     *
+     */
+    public function remove($id)
+    {
+        $_cfg = $this->_auth_cfg;
+        $rec  = new \Recurrent( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $this->id  = $id;
+        $this->des = $rec->remove($id);
+        return [  'id' => $id];
+    }
+
 
     /**
      * Required by JsonSerializable