MVC improvements. Upload ofx now creates entries in the DB.
authorwww-data <www-data@n3150.home>
Sat, 2 Apr 2022 23:16:37 +0000 (01:16 +0200)
committerwww-data <www-data@n3150.home>
Sat, 2 Apr 2022 23:16:37 +0000 (01:16 +0200)
19 files changed:
app/compta/api/bank.php
app/compta/api/recurrent.php [new file with mode: 0644]
app/compta/api_recurrent.php [deleted file]
app/compta/controlers/recurrent.php
app/compta/controlers/supplier.php
app/compta/models/anah.php [new file with mode: 0644]
app/compta/models/bank.php
app/compta/models/loan.php
app/compta/models/owner.php
app/compta/models/recurrent.php
app/compta/views/bank_index.php
app/compta/views/recurrent_detail.php
app/compta/views/recurrent_index.php
app/compta/views/recurrent_nouveau.php
app/compta/views/recurrent_payer.php
app/compta/views/recurrent_remove.php [new file with mode: 0644]
app/compta/views/recurrent_update.php
app/compta/views/supplier_bill.php
app/compta/views/supplier_billpay.php [new file with mode: 0644]

index 9a50292dda64fbc1afb5b691a5a29a4da32d0366..ba9a55d120ae27b587992c2ede2ebf4ca0d454f3 100644 (file)
@@ -50,6 +50,52 @@ class Bank extends Api {
         }
         return $res['records'];
     }
+
+    /**
+     * \brief lookup for bank account id defined by the parameter.
+     * if not found return 0.
+     *
+     */
+    public function lookupBank($codeBanque,$codeGuichet,$codeCompte)
+    {
+        $period = $this->getCurrentExercice();
+        $q =<<<_EOF
+SELECT ba_id FROM BankAccounts
+WHERE ba_code_bank = {$codeBanque} and ba_code_branch = "{$codeGuichet}" and ba_num_account= "{$codeCompte}";
+_EOF;
+        try 
+        {
+            $res = $this->doQueryI($q);
+        } catch (Exception $e)
+        {
+         error_log("Bank::lookup Failed ".$period." ".$e->getMessage());       
+        }
+        if (is_array($res['records']))
+        {
+            return $res['records'][0][0];
+        } else
+            return 0;
+    }
+
+    /**
+     *
+     */
+    public function bookMvmt($bank_id,$type,$date,$montant,$mvmt_id,$libelle,$info)
+    {
+        $q=<<<_EOF
+INSERT IGNORE INTO BankMvmts (bm_bank_id,bm_type,bm_date,bm_amount,bm_mvmt_id,bm_name,bm_info)
+VALUES({$bank_id},"{$type}","${date}",{$montant},"${mvmt_id}","{$libelle}","{$info}");
+_EOF;
+        try 
+        {
+            $res = $this->doQueryI($q);
+        } catch (Exception $e)
+        {
+         error_log("Bank::bookMvmt Failed ".$period." ".$e->getMessage());       
+        }
+        return $res['records'];
+    }
+
 }
 
 ?>
diff --git a/app/compta/api/recurrent.php b/app/compta/api/recurrent.php
new file mode 100644 (file)
index 0000000..8b27042
--- /dev/null
@@ -0,0 +1,240 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4 list: */
+/**
+ * This file contains the Pret API for the general ledger system.
+ * It shall provide all function for the ledger system
+ * - create a recurrent operation
+ * - list all recurrent transaction
+ * - loan summary (monthly payment, payment du date, left interest, left capital, 6 next )
+ * - updating a Transaction previously retrieved by the retrieve api.
+ *
+ * @author Andre Ebersold <andre.ebersold@free.fr>
+ * @version 1.0
+ * @package Compta
+ */
+
+require_once(dirname(__FILE__)."/../../common.php");
+require_once(dirname(__FILE__)."/../api_base.php");
+
+/**
+ * Api to retrieve information from the ledger books
+ * @package Compta
+ * @subpackage class
+ */
+class Recurrent extends Api {
+    private $precision = 2;
+    /**
+     * Default constructor
+     * @param Session $_session 
+     * @param Array   $_auth_cfg  Authentication parameter required to connect to the database
+     * @param string  $_db        Name of the database 
+     *
+     */
+    function __construct($_session,$auth_cfg,$db) {
+      parent::__construct($_session,$auth_cfg,$db);
+    }
+
+    /**
+     * Insert or update a recurrent Entry.
+     * When id is -1 create a new entry or else perform an update.
+     *
+     */
+    private function insertEntry($rec_id,$e)
+    {
+         $tplt=<<<_EOF
+INSERT INTO RecurrentEntry (re_id,re_rec_id,re_entry_type,re_acc,re_debit_credit,re_amount)
+ VALUES({$e['id']},{$rec_id},"{$e['entry_type']}","{$e['acc_id']}","{$e['dc']}",{$e['amount']})
+ON DUPLICATE KEY UPDATE 
+       re_entry_type = "{$e['entry_type']}"
+      , re_acc       = "{$e['acc_id']}"
+      , re_amount    = {$e['amount']}
+      , re_debit_credit = "{$e['dc']}"
+;
+_EOF;
+        if ($e['id'] == -1 ) 
+        {
+         $tplt=<<<_EOF
+INSERT INTO RecurrentEntry (re_rec_id,re_enty_type,re_acc,re_debit_credit,re_amount)
+ VALUES({$rec_id},{$e['entry_type']},{$e['acc_id']},{$e['dc']},{$e['amount']}) ;
+_EOF;
+        }
+        try {
+            $res = $this->doQueryI($tplt);
+        } catch (Exception $e) {
+            error_log("Recurrent::insertEntry ".$id." Failed ".$e->getMessage());
+        }
+        return $res['records'];
+    }
+
+    /**
+     * Create a new recurrent entry
+     * Proceed in two steps. First create the summary of the transaction,
+     * Then create the entries belonging to the recurreny transaction
+     * $r_id        = -1;
+     * $r_date      = "";
+     * $r_amount    = 0.0;
+     * $r_desc      = "";
+     * $r_next      = "";
+     * $r_end       = "";
+     */
+    public function create($r,$entries)
+    {
+        $tplt=<<<_EOF
+INSERT INTO Recurrent (r_date,r_amount,r_desc,r_next,r_amount,r_end)
+ VALUES({$r['r_date']},{$r['r_amount']},{$r['r_desc']},{$r['r_next']},{$r['r_amount']},{$r['r_end']})
+; SELECT LAST_INSERT_ID() ; 
+_EOF;
+        try {
+            $res = $this->doQueryI($q);
+        } catch (Exception $e) {
+            error_log("Recurrent::create ".$id." Failed ".$e->getMessage());
+            return Array('');
+        }
+        $r_id = $res['records'][0];
+        error_log("Recurrent::create ".$id." created add entries");
+        foreach($entries as $entry)
+        {
+            $this->insertEntry($r_id,$entry);
+        }
+    }
+    /**
+     * @brief Update recurrent entry
+     */
+    public function update($r,$entries)
+    {
+        $tplt=<<<_EOF
+UPDATE Recurrent 
+SET 
+r_date ="{$r['r_date']}"
+,r_amount ={$r['r_amount']}
+,r_desc ="{$r['r_desc']}"
+,r_next ="{$r['r_next']}"
+,r_amount ={$r['r_amount']}
+,r_end ="{$r['r_end']}"
+WHERE r_id = {$r['r_id']};
+_EOF;
+        try {
+            $res = $this->doQueryI($tplt);
+            error_log("Recurrent::update ".$tplt."\n");
+        } catch (Exception $e) {
+            error_log("Recurrent::update ".$r['r_id']." Failed ".$e->getMessage());
+            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);
+        }
+    }
+
+
+    /**
+     * \brief, return the list of loans
+     * TODO: Not sure if it's the right place
+     */
+    public function getList()
+    {
+      $q =<<<_EOF
+SELECT r_id,r_date,r_amount,r_desc,r_next,r_end from `Recurrent` as l
+_EOF;
+      try {
+        $res = $this->doQueryI($q);
+      } catch (Exception $e) {
+        error_log("Recurrent::getList ".$id." Failed ".$e->getMessage());
+      }
+      return $res['records'];
+    }
+
+    /**
+     * \brief, return the list of loans
+     * TODO: Not sure if it's the right place
+     */
+    function get($rid)
+    {
+      $q =<<<_EOF
+SELECT r_id,r_date,r_amount,r_desc,r_next,r_end from `Recurrent` as l WHERE r_id = {$rid}
+_EOF;
+      try {
+        $res = $this->doQueryI($q);
+      } catch (Exception $e) {
+        error_log("Recurrent::get ".$id." Failed ".$e->getMessage());
+      }
+      return $res['records'][0];
+    }
+    /**
+     *
+     * TODO: Not sure if it's the right place
+     * @return Array(date,amount,rate
+     *               ,duration,description,total interest
+     *               ,interest left,month left,next payment
+     *               ,capital)
+     */
+    function getSummary($recId)
+    {
+      // Get the loan general info
+      $q =<<<_EOF
+SELECT  re_id
+      , re.re_entry_type
+      , re.re_acc
+      , re.re_amount
+      , re.re_debit_credit
+      , a.acc_name
+FROM `RecurrentEntry`  AS re
+JOIN Account as a ON re.re_acc = a.acc_id
+WHERE re_rec_id = {$recId};
+_EOF;
+      try {
+        $res = $this->doQueryI($q);
+      } catch (Exception $e) {
+        error_log("Recurrent::getSummary ".$id." Failed ".$e->getMessage());
+      }
+      return $res['records'];
+    }
+
+    /**
+     * mark the loan entry as booked eg payed.
+     *
+     * @return TODO
+     */
+    function markBooked($recId)
+    {
+        $q =<<<_EOF
+UPDATE Recurrent SET r_next = DATE_ADD(r_next,INTERVAL r_period MONTH ) WHERE r_id = {$recId} ;
+_EOF;
+        try {
+            $res = $this->doQueryI($q);
+        } catch (Exception $e) {
+            error_log("Recurrent::markBooked ".$id." Failed ".$e->getMessage());
+        }
+    }
+
+    /**
+     * retrieve the next non payed entry for the loan.
+     *
+     */
+    function getNextPayement($recId)
+    {
+      $q =<<<_EOF
+SELECT r.r_date as d
+      ,r.r_next as next
+      ,r.r_desc 
+      ,re.re_entry_type
+      ,re.re_debit_credit
+      ,re.re_acc
+      ,re.re_amount
+FROM `Recurrent`  AS r
+JOIN RecurrentEntry AS re ON r.r_id = re.re_rec_id
+WHERE r.r_id = {$recId};
+_EOF;
+      try {
+        $res = $this->doQueryI($q);
+      } catch (Exception $e) {
+        error_log("Recurrent::getNextPayement ".$id." Failed ".$e->getMessage());
+      }
+      return $res['records'];
+
+    }
+}
+
+?>
diff --git a/app/compta/api_recurrent.php b/app/compta/api_recurrent.php
deleted file mode 100644 (file)
index 481588e..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-/* vim: set expandtab sw=4 ts=4 sts=4 list: */
-/**
- * This file contains the Pret API for the general ledger system.
- * It shall provide all function for the ledger system
- * - create a loan
- * - list all loans
- * - loan summary (monthly payment, payment du date, left interest, left capital, 6 next )
- * - updating a Transaction previously retrieved by the retrieve api.
- *
- * @author Andre Ebersold <andre.ebersold@free.fr>
- * @version 1.0
- * @package Compta
- */
-
-require_once(dirname(__FILE__)."/../common.php");
-require_once(dirname(__FILE__)."/api_base.php");
-
-/**
- * Api to retrieve information from the ledger books
- * @package Compta
- * @subpackage class
- */
-class Recurrent extends Api {
-    private $precision = 2;
-    /**
-     * Default constructor
-     * @param Session $_session 
-     * @param Array   $_auth_cfg  Authentication parameter required to connect to the database
-     * @param string  $_db        Name of the database 
-     *
-     */
-    function __construct($_session,$auth_cfg,$db) {
-      parent::__construct($_session,$auth_cfg,$db);
-    }
-
-    /**
-     * \brief, return the list of loans
-     * TODO: Not sure if it's the right place
-     */
-    function getList()
-    {
-      $q =<<<_EOF
-SELECT r_id,r_date,r_amount,r_desc,r_next,r_end from `Recurrent` as l
-_EOF;
-      try {
-        $res = $this->doQueryI($q);
-      } catch (Exception $e) {
-        error_log("Recurrent::getList ".$id." Failed ".$e->getMessage());
-      }
-      return $res['records'];
-    }
-
-    /**
-     * \brief, return the list of loans
-     * TODO: Not sure if it's the right place
-     */
-    function get($rid)
-    {
-      $q =<<<_EOF
-SELECT r_id,r_date,r_amount,r_desc,r_next,r_end from `Recurrent` as l WHERE r_id = {$rid}
-_EOF;
-      try {
-        $res = $this->doQueryI($q);
-      } catch (Exception $e) {
-        error_log("Recurrent::get ".$id." Failed ".$e->getMessage());
-      }
-      return $res['records'][0];
-    }
-    /**
-     *
-     * TODO: Not sure if it's the right place
-     * @return Array(date,amount,rate
-     *               ,duration,description,total interest
-     *               ,interest left,month left,next payment
-     *               ,capital)
-     */
-    function getSummary($recId)
-    {
-      // Get the loan general info
-      $q =<<<_EOF
-SELECT  re_id
-      , re.re_entry_type
-      , re.re_acc
-      , re.re_amount
-      , re.re_debit_credit
-      , a.acc_name
-FROM `RecurrentEntry`  AS re
-JOIN Account as a ON re.re_acc = a.acc_id
-WHERE re_rec_id = {$recId};
-_EOF;
-      try {
-        $res = $this->doQueryI($q);
-      } catch (Exception $e) {
-        error_log("Recurrent::getSummary ".$id." Failed ".$e->getMessage());
-      }
-      return $res['records'];
-    }
-
-    /**
-     * mark the loan entry as booked eg payed.
-     *
-     * @return TODO
-     */
-    function markBooked($recId)
-    {
-        $q =<<<_EOF
-UPDATE Recurrent SET r_next = DATE_ADD(r_next,INTERVAL r_period MONTH ) WHERE r_id = {$recId} ;
-_EOF;
-        try {
-            $res = $this->doQueryI($q);
-        } catch (Exception $e) {
-            error_log("Recurrent::markBooked ".$id." Failed ".$e->getMessage());
-        }
-    }
-
-    /**
-     * retrieve the next non payed entry for the loan.
-     *
-     */
-    function getNextPayement($recId)
-    {
-      $q =<<<_EOF
-SELECT r.r_date as d
-      ,r.r_next as next
-      ,r.r_desc 
-      ,re.re_entry_type
-      ,re.re_debit_credit
-      ,re.re_acc
-      ,re.re_amount
-FROM `Recurrent`  AS r
-JOIN RecurrentEntry AS re ON r.r_id = re.re_rec_id
-WHERE r.r_id = {$recId};
-_EOF;
-      try {
-        $res = $this->doQueryI($q);
-      } catch (Exception $e) {
-        error_log("Recurrent::getNextPayement ".$id." Failed ".$e->getMessage());
-      }
-      return $res['records'];
-
-    }
-}
-
-?>
index 06d54e4d7ea96bca13a422549ac67c3f6be67f7b..228998312f8edf9392989dda75e1767b0e18e05e 100644 (file)
@@ -70,6 +70,27 @@ class Recurrent
         $page = new \compta\views\recurrent\Update($this->_model);
         return $page;
     }
+    /**
+     * Handle post of update recurrent operation
+     * @param string $_accout_id 
+     */
+    public function updatePost() : \IActionResult
+    {
+        $page = null;
+        $model = $this->_model;
+        require_once(controler::$basedir."/views/recurrent_update.php");
+        if ($this->_model->isFormValid() == true)
+        {
+            // Here I should commit the changes of the operation
+            $model->update();
+            // Alright read back and display
+            return $this->detail($model->id);
+        } else
+        {
+            $page = new \compta\views\recurrent\Update($this->_model);
+        }
+        return $page;
+    }
     /**
      * Get the details of the supplier account.
      * @param string $_accout_id  the supplier account
@@ -81,6 +102,20 @@ class Recurrent
         $page = new \compta\views\recurrent\Payer($this->_model);
         return $page;
     }
+    /**
+     * @brief Remove a recurrent record and its entries
+     * @param string $_id  the recurrent entry to remove
+     */
+    public function remove($_id) : \IActionResult
+    {
+        require_once(controler::$basedir."/views/recurrent_remove.php");
+        $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);
+    }
     /**
      * Get the details of the supplier account.
      * @param string $_accout_id  the supplier account
@@ -88,7 +123,7 @@ class Recurrent
     public function nouveau() : \IActionResult
     {
         require_once(controler::$basedir."/views/recurrent_nouveau.php");
-        $page = new \compta\views\recurrent\Nouveau();
+        $page = new \compta\views\recurrent\Nouveau($this->_model);
         return $page;
     }
     /**
@@ -98,7 +133,7 @@ class Recurrent
     public function nouveauPost() : \IActionResult
     {
         require_once(controler::$basedir."/views/recurrent_nouveau.php");
-        $page = new \compta\views\recurrent\Nouveau();
+        $page = new \compta\views\recurrent\Nouveau($this->_model);
         return $page;
     }
 }
index c986129fab40643c721cb6306be625438c4c343a..e8855d76a02e92e0c9d75bb6de07908215e5f8dd 100644 (file)
@@ -82,6 +82,15 @@ class Supplier extends controler
         return $page;
     }
 
+    public function billpay($_id) : \IActionResult
+    {
+        require_once(controler::$viewdir."/supplier_billpay.php");
+        $this->_model->getDetails($_id);
+        $this->_model->getAccount($_id);
+        $page = new \compta\views\supplier\Billpay($this->_model);
+        return $page;
+    }
+
     public function billPost() : \IActionResult
     {
         $model = $this->_model;
diff --git a/app/compta/models/anah.php b/app/compta/models/anah.php
new file mode 100644 (file)
index 0000000..dc4c963
--- /dev/null
@@ -0,0 +1,292 @@
+<?php
+
+namespace compta\models\anah;
+
+require_once(dirname(__FILE__)."/../api_exercice.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
+require_once(dirname(__FILE__)."/../api_booking.php");
+
+require_once(dirname(__FILE__)."/../../../phplib/class.validator.php");
+
+
+
+class Identification implements \JSonSerializable
+{
+    public $numImmatriculationCopropriete     = ""; // String(9)  Optionnel
+    public $nomCopropriete                    = ""; // String(50) Mandatory
+    public $dateReglementCopropriete          = ""; // String(10) Mandatory format DD/MM/AAAA
+    public $Siret                             = ""; // String(14) Optionnel
+    public $addressPrincipale                 = null;    // Object Address
+    public $addressSecondaire                 = Array(); // Tableau Object Address
+    public $parcelle                          = Array(); // Tableau Object Parcelle Optionnel
+    public $residenceService                  = false;   // Mandatory
+    public $syndicCooperatif                  = false;   // Optionnel
+    public $syndicPrincipal                   = true;    // Mandatory
+    public $numImmatriculationCopropritePrincipale = ""; // Optionnel Format AANNNNNNN
+    public $nbAsl                                  = 0;  // Nombre d'ASL
+    public $nbAful                                 = 0;  // Mandatory
+    public $nbUnionsSyndicats                      = 0;  // Numbre d'Unions de syndicas Mandatory
+    public $nbLots                                 = 0;  // Nombre total de lots. min 2..99999
+    public $nbLotsHabBurCom                        = 4;  // Nombre total de lots a usage habitation.. Mandatory
+    public $nbLotsHab                              = 4;  // Nombre de lots à ussage d'habitation
+    public $nbLotsStationnement                    = 0;  // Nombre de lots a ussage d'habitation
+
+    public function __construct($c = null)
+    {
+        if ($c != null)
+        {
+            $i = 0;
+            foreach( get_object_vars($this) as $k => $v)
+            { $this->{$k} = $c[$i++]; }
+        }
+    }
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [
+          'numImmatriculationCopropriete' => $this->numImmatriculationCopropriete
+        , 'nomCopropriete'                => $this->nomCopropriete
+        , 'dateReglementCopropriete'      => $this->dateReglementCopropriete
+        , 'Siret'                         => $this->Siret
+        , 'addressPrincipale' => $this->addressPrincipale
+        , 'addressSecondaire' => $this->addressSecondaire
+        , 'parcelle' => $this->parcelle
+        , 'residenceService' => $this->residenceService
+        , 'syndicCooperatif' => $this->syndicCooperatif
+        , 'syndicPrincipal' => $this->syndicPrincipal
+        , 'numImmatriculationCopropritePrincipale' => $this->numImmatriculationCopropritePrincipale
+        , 'nbAsl' => $this->nbAsl
+        , 'nbAful' => $this->nbAful
+        , 'nbUnionsSyndicats' => $this->nbUnionsSyndicats
+        , 'nbLots' => $this->nbLots
+        , 'nbLotsHabBurCom' => $this->nbLotsHabBurCom
+        , 'nbLotsHab' => $this->nbLotsHab
+        , 'nbLotsStationnement' => $this->nbLotsStationnement
+        ]
+    }
+}
+
+
+class Procedures implements \JSonSerializable
+{
+    public $Arrete        = Array(); // Tableau d'objet
+    public $Type          = ""; // [INSALUBRITE_PARTIES_COM,PERIL_PARTIES_COM,EQUIPEMENTS_COM]
+    public $dateArrete    ="";
+    public $dateMainLevee ="";
+    public $mandatAdHoc   ="";
+    public $dateNomination    ="";
+    public $dateFinMission    ="";
+    public $ordonnanceCarence = null; // Objet
+    public $dateOrdonnance    = "";
+
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+
+/**
+ *
+ */
+class DonneesTechniques implements \JSonSerializable
+{
+    public $classementEnergetique = Array(); // Tableau d'objets
+    public $etiquetteEnergetique  = "";      // String ETIQ_[A-G,NOM_DETERMINE]
+    public $nbBatiments           = 1;
+    public $periodeConstruction   = ""; // Enum [AVANT_1949,DE_1949_A_1960, .. NON_CONNUE]
+    public $anneeConstruction     = 0;  // 0 - 9999
+    public $typeChauffage         = ""; // Enum [COLLECTIF,INDIVIDUEL,MIXTE,SANS_CHAUFFAGE]
+    public $chauffageCollectifUrbain          = false;
+    public $energieChauffageCollectifNonUrbain = ""; // Enum [BOIS_DE_CHAUFFAGE,GAZ_NATUEL,GAZ_PROPANE_BUTANE
+                                                     // CHARBON, ELECTRICITE,AUTRE]
+    public $nbAscenseurs          = 0;
+
+
+
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+/**
+ *
+ */
+class DonneesFinancieres implements \JSonSerializable
+{
+    public $premierExerciceComptable  = false; // Boolean
+    public $dateDebutExerciceComtable = "";    // Format DD/MM/AAAA
+    public $dateClotureComtpes        = "";    // Format DD/MM/AAAA
+    public $dateAg                    = "";
+    public $chargesOperationsCourantes       = 0.0;
+    public $chargesOperationsExceptionnelles = 0.0;
+    public $montantImpayesCoproprietaires    = 0.0
+    public $presenceEmployes                 = false;
+    public $nbCoproprietairesImpayes         = 0;
+    public $montantDettes                    = 0.0;
+    public $montantFondTravaux               = 0.0;
+    public $dateReference                    = ""; // Format DD/MM/AAAA
+    public $comptesNomApprouves              = false;
+
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+/**
+ *
+ */
+class Address implements \JSonSerializable
+{
+    public $voie       = ""; 
+    public $lieuDit    = ""; 
+    public $codePostal = ""; 
+    public $commun     = ""; 
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+
+/**
+ *
+ */
+class Parcelle implements \JSonSerializable
+{
+    public $codeInsee     = ""; // String Mandatory 5 chiffres
+    public $Prefixe       = ""; // Optionnel
+    public $section       = ""; //
+    public $numParcelle   = ""; 
+
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+
+/**
+ *
+ */
+class Attestation implements \JSonSerializable
+{
+    public $Type           = ""; // String Mandatory [IMMATRICULATION,MISE_A_JOUR_STANDARD,MISE_A_JOUR_ANNUELLE]
+    public $nomFichier     = ""; // String Mandatory
+    public $pdfAttestation = ""; // String Mandatory base64 encoded
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+
+/**
+ *
+ */
+class FicheSynthetique implements \JSonSerializable
+{
+    public $nomFichier          = ""; // String Mandatory
+    public $pdfFicheSynthetique = ""; // String Mandatory
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+
+/**
+ *
+ */
+class InfoRattachement implements \JSonSerializable
+{
+    public $adminProvisoire        = ""; // String Mandatory
+    public $typeJustifMandat       = ""; // String Mandatory [CONTRAT_SYNDIC,PV_AG,ORDO_NOMINATION]
+    public $nomFichierJustifMandat = "";
+    public $justifMandat           = "";
+    public $dateDebutMandat        = ""; // DD/MM/AAAA
+    public $dateFinMandat          = ""; // DD/MM/AAAA
+
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+
+/**
+ * @brief
+ *
+ * TODO figure out why we have two time numTeledeclarant
+ */
+class InfoSuccesseur implements \JSonSerializable
+{
+    public $numTeledeclarant              = false; // Boolean  Mandatory
+    public $typeTeledeclarant              = ""; // String (13) [PROFESSIONNEL / BENEVOLE] Mandatory
+    public $siret        = ""; // String Mandatory
+    public $pdfFicheSynthetique = ""; // String Mandatory
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
+/**
+ *
+ */
+class InfosUtilisateur implements \JSonSerializable
+{
+    public $numTeledeclarant              = ""; // String (12)  Mandatory
+    public $adresseEmailUtilisateur       = ""; // String (320) Mandatory
+    public $numImmatriculationCopropriete = ""; // String (9)   Mandatory
+
+    public function __construct($c = null)
+    {
+    }
+    public function jsonSerialize()
+    {
+        return [
+        ];
+    }
+}
+
index 7727c8ea0f4eda2af4822f742c2265b4f18c3000..6ea0ede6b6efab388e65977cc919c6997e688743 100644 (file)
@@ -5,6 +5,7 @@ namespace compta\models\bank;
 require_once(dirname(__FILE__)."/../api_exercice.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 require_once(dirname(__FILE__)."/../api_pcmn.php");
+require_once(dirname(__FILE__)."/../api/bank.php");
 require_once(dirname(__FILE__)."/../../../phplib/class.ofx.php");
 
 /**
@@ -15,8 +16,12 @@ class Model extends \Ofx implements \JsonSerializable
     private $_session  = null;
     private $_auth_cfg = null;
 
+    private $bank_id   = 0;    // Bank ID <> 0 when found during ofx parsing
+
+    private $api_bank  = null;
     public  $mouvements = Array();
     public  $id = -1; // current entry. -1 no entry selected
+
     /**
      * Constructor
      */
@@ -25,24 +30,51 @@ class Model extends \Ofx implements \JsonSerializable
         $this->_session  = $_sess;
         $this->_auth_cfg = $_auth;
     }
+    public function onAccount($codeBanque,$codeGuichet,$codeCompte)
+    {
+        $_cfg = $this->_auth_cfg;
+        $api_bank = new \Bank( $this->getSession()
+                 , $_cfg
+                 , $this->getSession()->getDb());
+        if ($api_bank != null)
+        {
+            $this->api_bank = $api_bank;
+        }
+        $this->bank_id = $api_bank->lookupBank($codeBanque,$codeGuichet,$codeCompte);
+        error_log("Got bank_id:".$this->bank_id." for account=".$codeCompte."\n");
+    }
     
-    public function onMouvement($type,$date,$montant,$reste,$libelle,$info)
+    public function onMouvement($type,$date,$montant,$mvmt_id,$libelle,$info)
     {
-       // error_log("Mvment: ".$type." ".$date." ".$montant."\n");
+        $api_bank = $this->api_bank;
+        // error_log("Mvment: ".$type." ".$date." ".$montant."\n");
+        if ($this->bank_id != 0 && $this->api_bank != null)
+        {
+            $api_bank->bookMvmt($this->bank_id,$type,$date,$montant,$mvmt_id,$libelle,$info);
+        } else
+        {
+            error_log("Not Looged :".$montant." for account=".$type."\n");
+        }
     }
+    
+    public function onEnd()
+    {
+        $this->bank_id = 0;
+    }
+
 
     private function getSession()
     {
-       return $this->_session;
+        return $this->_session;
     }
 
     public function getAccounts()
     {
         $_cfg = $this->_auth_cfg;
         $pcmn = new \Pcmn( $this->getSession()
-             , $_cfg
-            , $this->getSession()->getDb());
-       $pcmn->getAccountList("51"); // Get Banks accounts
+                 , $_cfg
+                 , $this->getSession()->getDb());
+        $pcmn->getAccountList("51"); // Get Banks accounts
     }
     /**
      * Required by JsonSerializable
index 16afa35362820bb43c18fbe48e3220d07bd8af3e..70d1aa9a4b339018b07670f59adfb54fb434690e 100644 (file)
@@ -3,7 +3,6 @@
 namespace compta\models\loan;
 
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 require_once(dirname(__FILE__)."/../api_loan.php");
 
index 24806710c5e4c438037e916e410e245cba671e1b..1a2872816edff85f27446664b47447d02fdcf0e7 100644 (file)
@@ -20,9 +20,11 @@ require_once(dirname(__FILE__)."/../../../phplib/class.ofx.php");
  */
 class Model implements \JsonSerializable
 {
-    private $_session  = null;
-    private $_auth_cfg = null;
+    private $_session   = null;
+    private $_auth_cfg  = null;
 
+    private $_summary   = "";
+    private $_decomptes = Array();
     /**
      * Constructor
      */
@@ -37,5 +39,16 @@ class Model implements \JsonSerializable
         return $this->_session;
     }
 
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [
+           'info' =>  $this->_summary
+        ,  'decomptes' => $this->_decomptes];
+    }
+
+
 }
 ?>
index f83d64b5409bcc4c28f99711ce0b96386a25ee9c..1952ab717d109194c16ef7df3e03e1ef4991ce9d 100644 (file)
@@ -3,9 +3,80 @@
 namespace compta\models\recurrent;
 
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
+require_once(dirname(__FILE__)."/../../../phplib/class.validator.php");
+
+
+
+class Recurrent implements \JSonSerializable
+{
+    public $r_id     = -1;
+    public $r_date   = "";
+    public $r_amount = 0.0;
+    public $r_desc   = "";
+    public $r_next   = "";
+    public $r_end    = "";
+
+    public function __construct($c = null)
+    {
+        if ($c != null)
+        {
+            $i = 0;
+            foreach( get_object_vars($this) as $k => $v)
+            { $this->{$k} = $c[$i++]; }
+        }
+    }
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [
+          'r_id'     => $this->r_id
+        , 'r_date'   => $this->r_date
+        , 'r_amount' => $this->r_amount
+        , 'r_desc'   => $this->r_desc
+        , 'r_next'   => $this->r_next
+        , 'r_end'    => $this->r_end];
+    }
+}
+
+class Entry implements \JsonSerializable
+{
+    /* Order is important don't change */
+    public $id         = -1;
+    public $entry_type = "BQ"; // Could be HA, AN, what ever
+    public $acc_id     = -1;
+    public $amount     = 0.0;
+    public $dc         = "d";  // Debit or credit
+    public $acc_name   = "";   // Account name
+
+    public function __construct($c = null)
+    {
+        if ($c != null)
+        {
+            $i = 0;
+            foreach( get_object_vars($this) as $k => $v)
+            { $this->{$k} = $c[$i++]; }
+        }
+    }
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [
+          'id'         => $this->id
+        , 'entry_type' => $this->entry_type
+        , 'acc_id'     => $this->acc_id
+        , 'amount'     => $this->amount
+        , 'dc'         => $this->dc
+        , 'acc_name'   => $this->acc_name];
+    }
+};
+
 /**
  * @brief Data model for a transaction. 
  */
@@ -14,14 +85,25 @@ class Model implements \JsonSerializable
     private $_session  = null;
     private $_auth_cfg = null;
 
-    private $summary;
-    
-    private $_entries;
+    private $FormValid = false;
+    private $summary   = null;  // Recurrent Object filled when validating inputs
+    private $updatePostParams = Array( "id", "rec_date" ,"rec_amount" ,"rec_desc" 
+                                     , "rec_next" ,"rec_end");
+    private $updatePostCheck  = Array( "", "str_date" ,"num_float" ,"str"
+                                     , "str_date","str_date"); 
+    public  $_entries = Array(); // Array of entries
     private $_payer = false;
     public  $id = -1; // current entry. -1 no entry selected
-    public  $des;     // description of recurrent entry
-    public  $lst;     // list of account operations 
+    // TODO update view accordingly
+    public  $des;     // Deprecated description of recurrent entry
+    public  $lst;     // Deprecated list of account operations 
     public  $lp;      // Payed transaction info 
+    /* New  way. Heuuu not sure. summary entry should be the winner */
+    public  $rec_desc      = "";
+    public  $rec_date      = "";
+    public  $rec_next      = "";
+    public  $rec_end       = "";
+    public  $rec_amount    = 0.0;
     /**
      * Constructor
      */
@@ -29,17 +111,138 @@ class Model implements \JsonSerializable
     {
         $this->_session  = $_sess;
         $this->_auth_cfg = $_auth;
+        $this->summary   = new Recurrent();
+        if (\AEB::$REQUEST['btRURecord'] != null)
+        {
+            $this->FormValid = $this->getUpdatePost();
+        }
+        if (\AEB::$REQUEST['btRNRecord'] != null)
+        {
+            $this->FormValid = $this->getUpdatePost();
+        }
     }
 
     private function getSession()
     {
-       return $this->_session;
+        return $this->_session;
     }
 
     public function isPayed()
     {
         return $this->_payer;
     }
+
+    public function isFormValid()
+    {
+        return $this->FormValid;
+    }
+    /**
+     * Retrieve values from billPost request
+     */
+    private function getUpdatePost()
+    {
+        $formValid = true;
+        $count     = 0;
+        $valid     = true;
+        $v         = new \Validator();
+        $this->id  = \AEB::$REQUEST['rec_id'];
+        $this->summary->r_id = $this->id;
+
+        // Check unique parameters
+        $f = reset($this->updatePostParams);
+        foreach ( $this->updatePostParams as $param)
+        {
+            if ($f == $param )
+            {
+                $count++;
+                continue; // skip first element. 
+            }
+            $pv = \AEB::$REQUEST[$param];
+            try 
+            {
+                $ck = $this->updatePostCheck[$count++];
+                if ($ck != "")
+                {
+                    $v->{$ck}($pv,"Not valid ".$param." value=".$pv."\n");
+                }
+                // TODO remove once solved
+                $this->{$param} = $pv;
+                $this->summary->{str_replace("rec_","r_",$param)} = $pv;
+            }
+            catch (\Exception $e)
+            {
+                error_log("Parameter failure ".$e->getMessage());
+                $formValid = false;
+            }
+        }
+        // Get Through post Entries
+        $count = 0;
+        for ( ; $count < 15 ; $count++)
+        {
+            $k = 'entry'.$count.'_id'; // Check if that key exists
+            if ( \AEB::$REQUEST->offsetExists($k) == true)
+            {
+                if ( ! $this->getEntryPost(\AEB::$REQUEST[$k],$count,$v) ) 
+                {
+                        $formValid = false;
+                }
+            }
+            else
+            {
+                break;
+            }
+        }
+        return $formValid;
+    }
+
+    /**
+     * Retrieve the parameters from one line.
+     */
+    private function getEntryPost($id,$line,$v)
+    {
+        $fvalid  = true; // Form entry is valid
+        $k       = "entry".$line.'_'; // Check if that key exists
+        $arr     = Array("acc_id","acc_name","entry_type","amount_debit","amount_credit");
+        $check   = Array("num_int","","","num_float","num_float");
+        $e       = new Entry();
+        $e->id   = $id;
+        $count   = 0;
+        // Check unique parameters
+        foreach ( $arr as $param)
+        {
+            $p = $k.$param;
+            $pv = \AEB::$REQUEST[$p];
+            try {
+                $ck = $check[$count++];
+                if ($ck != "")
+                {
+                    $v->{$ck}($pv,"Not valid ".$param." va=".$pv."\n");
+                } 
+                if ($param == 'amount_debit' and $pv != 0.0 )
+                {
+                  $e->amount = $pv;
+                  $e->dc     = 'd';
+                } else if ($param == 'amount_credit' and $pv != 0.0)
+                {
+                  $e->amount = $pv;
+                  $e->dc     = 'c';
+                } else 
+                  $e->{$param} = $pv;
+            }
+            catch (\Exception $exp)
+            {
+                error_log("Parameter failure:".$exp->getMessage());
+                $fvalid = false;
+            }
+        }
+        // Only add Entries with an amount not equal to à.
+        if ($e->amount != 0.0 and ($e->acc_id != -1))
+        {
+            $this->_entries[] = $e;
+        }
+        return $fvalid;
+    }
+
     /**
      * @brief pay a recurrent entry for this month
      * @return Array('trans_id') in case of success or empty Array() in case of failure
@@ -81,14 +284,31 @@ class Model implements \JsonSerializable
         { // Success book the entry
             $rec->markBooked($id);
             $this->_payer = true;
-           $this->lp = $lp;
-           $this->id = $id;
+            $this->lp = $lp;
+            $this->id = $id;
         } else
         {
           error_log("Failed payer : unknown reason");
         }
     }
 
+    /**
+     * @brief called on updatePost when post 
+     * parameters are all valid
+     *
+     * The model must contain valid parameters or else,
+     * it should fail
+     */
+    public function update()
+    {
+        $_cfg = $this->_auth_cfg;
+        $rec  = new \Recurrent( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $rec->update( $this->summary->jsonSerialize()
+                    , json_decode(json_encode($this->_entries),true));
+    }
+
     /**
      * @brief get the details of a recurrent entry.
      *
@@ -101,7 +321,16 @@ class Model implements \JsonSerializable
              , $this->getSession()->getDb());
         $this->id  = $id;
         $this->des = $rec->get($id);
+        $this->summary = new Recurrent($this->des);
+        $count     = 0;
+        foreach ($this->updatePostParams as $p)
+        {  $this->{$p} = $this->des[$count++];  }
+
         $this->lst = $rec->getSummary($id);
+        foreach($this->lst as $e)
+        {
+            $this->_entries[] = new Entry($e);
+        }
         return [ 'des' => $this->des, 'lst' => $this->lst];
     }
 
@@ -111,8 +340,9 @@ class Model implements \JsonSerializable
     public function jsonSerialize()
     {
         return [
-           'transi' =>  $this->_summary
-        ,  'entries' => $this->_entries];
+           'transi' =>  $this->summary
+           ,  'entries' => $this->_entries
+        ];
     }
 }
 
index 27545659968d1991edfb32eb9c8503ce182ea1ad..e3636651dd228ee71d73ac046e4e36bce6164508 100644 (file)
@@ -6,8 +6,7 @@ require_once(dirname(__FILE__)."/../api_pcmn.php");
 require_once(dirname(__FILE__)."/../api/bank.php");
 require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
 
-global $xmlBankIndex;
-$xmlBankIndex =  <<<XML
+const xmlBankIndex =  <<<XML
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <?xslt-param name='alias' value='/andre/'?>
 <?xml-stylesheet type="text/xsl" href="xsl/gui.xsl?alias='/andre/'"?>
@@ -71,8 +70,7 @@ class Index extends    \PageCompta
     function __construct($model, $b = true)
     {
         $this->_model = $model;
-        global $xmlBankIndex;
-        parent::__construct($xmlBankIndex,$b);
+        parent::__construct(xmlBankIndex,$b);
     }
 
     public function render()
index 8d98a3bc419f6ae1318165fcfea50436c212fe06..6afc306f7282848447a83073e0c42cb41be85d97 100644 (file)
@@ -5,7 +5,7 @@ require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
 
 require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
 
@@ -92,6 +92,7 @@ _EOF;
 <div class="panel" style='padding-bottom:15px;'>
 <a class="button" href="/app/compta/services.php/recurrent/index" style="float:left;"><span>Retour</span></a>
 <a class="button" href="/app/compta/services.php/recurrent/update/{$this->_model->id}" style="float:left;"><span>Modifier</span></a>
+<a class="button" href="/app/compta/services.php/recurrent/remove/{$this->_model->id}" style="float:left;"><span>Supprimer</span></a>
 </div>
 EOF;
     echo $res;
@@ -104,9 +105,11 @@ EOF;
     function main()
     {
         $this->script("/app/compta/services.php/");
-        echo '<div class="content" style="display:flex;flex-wrap:wrap">';
+        echo '<div class="content" style="display:flex;flex-wrap:wrap;margin-bottom:15px;">';
+        echo '<div class="col-11">';
         $this->document();
         echo '</div>';
+        echo '</div>';
     }
 }
 
index 5c01365fedfc5fd6f3398530f59f378676cd91b0..cc31e58cd6143e02033f2cfc63d8f268150a956b 100644 (file)
@@ -5,7 +5,7 @@ require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
 
 require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
 $XmlComptaDocuments =  <<<XML
@@ -115,41 +115,6 @@ _EOF;
         }
     } 
     echo "</table>";
-   /*
-    echo "<h2 style='width:100%;'>Prochaine échéance </h2>";
-    $lp = $rec->getNextPayement($id);
-    $date_apayer = new DateTime($lp[6]);
-    $date_today  = new DateTime("now");
-    $p = "";
-    if ($date_apayer > $date_today) {
-    $p.= "en attente";
-    } else {
-            $p.=<<<EOF
-<form method="post" action="/app/compta/page_ledger_recurrent.php">
-        <input type="hidden" name="li" value="{$id}" />
-        <input type="hidden" name="lei" value="{$lp[5]}" />
-        <input type="submit" name="submit" value="payer" />
-      </form>
-EOF;
-    }
-
-    $res =<<<_EOF
-<tr><th width="20%">Date</th>
-    <th align="right">annuite</th>
-    <th align="right">interet</th>
-    <th align="right">ammorti</th>
-    <th align="center">&nbsp;</th>
-</tr>
-<tr><td widtd="20%">{$lp[6]}</td>
-    <td align="right">{$lp[7]} €</td>
-    <td align="right">{$lp[8]} €</td>
-    <td align="right">{$lp[9]} €</td>
-    <td align="right">{$p}
-    </td>
-</tr>
-_EOF;
-    echo $res;
-     */
   }
 
   /**
@@ -196,6 +161,7 @@ _EOF;
         $rec->markBooked($id);
     }
     echo "<h2 style='width:100%;'>Règlement échéance terminé</h2>";
+    echo "<div class='col-11'>";
     echo "<table style='width:100%;margin-bottom:10px; border: 1px solid #000;' >";
     $res =<<<_EOF
 <tr><th width="20%">Date</th>
@@ -215,6 +181,7 @@ _EOF;
 _EOF;
     echo $res;
     echo "</table>";
+    echo "</div>";
   }
   /**
    * @brief main page that will list all loans
@@ -227,6 +194,7 @@ _EOF;
              , $_cfg
              , $this->getSession()->getDb());
     $lst = $rec->getList();
+    echo "<div class='col-11'>";
     echo "<table class='table' style='width:100%;margin-bottom:10px;'>";
     echo "<thead>";
     echo "<tr><th width='10%'>Date</th><th>Description</th><th>Montant</th><th>Fin</th><th>Prochaine échéance</th></tr>";
@@ -262,6 +230,7 @@ EOF;
     $res.="</tr>";
     echo $res;
     echo "</table>";
+    echo "</div>";
   }
   /**
    *
@@ -298,7 +267,6 @@ EOF;
             $this->script("/app/compta/services.php/");
         } else
         {
-            error_log("to pag_ledger");
             $this->script();
         }
         echo '<div class="content" style="display:flex;flex-wrap:wrap">';
index 7816d02f3e202b1ceb09da2dfdcbd277587fa73d..738f6970bc1305b228f830d4507b3ae41e3a3288 100644 (file)
@@ -5,10 +5,10 @@ require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
 
 require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
-$XmlComptaDocuments =  <<<XML
+const xmlRecurrentNouveau =<<<XML
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <?xslt-param name='alias' value='/andre/'?>
 <?xml-stylesheet type="text/xsl" href="xsl/gui.xsl?alias='/andre/'"?>
@@ -16,24 +16,81 @@ $XmlComptaDocuments =  <<<XML
 <liens/>
 <title langue='fr'>Gestion comptable</title>
 <content>
-  <script data-main="/app/compta/coproBootstrap.js" src="/js/require.js"></script>
-  <menu>
-    <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
-  </menu>
-<!-- Start Main Panel-->
+  <!-- The script does not work. Looks like an order issue-->
+  <script>
+  (function() {
+    console.log("Try to update mh1a");
+    var mh1a = $('mh1').firstChild;
+    mh1a.href = "/fr/app/compta/services.php/";
+  })(); 
+  </script>
+  <script>
+  </script>
 
-<!-- -->
-    <panel class="" style="padding:0px 0px 0px 0px;display:block;min-height:150px;" id="mydocuments">
-    <h3>Chargement ...</h3>
-    </panel>
+<menu>
+</menu>
 
-<!-- End Main Panel -->
-    <script></script>
+  <panel id="pRecurrent" class="col-11 pg-account" style="min-height:150px;">
+    <h2 id="title" style="width:100%">Nouvelle facture fournisseur</h2>
+
+      <form method="post" action="/app/compta/services.php/recurrent/nouveauPost">
+        <group id="group"> 
+          <grouptitle>Mise à jour d'une opération récurrente</grouptitle>
+          <groupcontent>
+            <FieldSet labelWidth="160" style="border:none 0px;">
+              <TextField type="hidden" id="rec_id" asp-for="id" style=""></TextField>
+              <TextField width="253" labelWidth="250" id="rec_desc" asp-for="rec_desc" style="">
+                <Label style="">Intitulé</Label></TextField><br/>
+              <TextField type="date" width="190" labelWidth="150" id="rec_date" asp-for="rec_date" style="">
+                <Label style=""> Date de début</Label></TextField><br/>
+              <TextField type="date" width="190" id="rec_next" asp-for="rec_next" style="">
+                <Label style="">Prochaine échéance</Label></TextField><br/>
+              <TextField type="date" width="190" id="rec_end" asp-for="rec_end" style="">
+                <Label style="">Date de fin</Label></TextField><br/>
+              <TextField width="190" id="rec_amount" asp-for="rec_amount" style="">
+                <Label style="">Montant</Label></TextField><br />
+            </FieldSet>
+          </groupcontent>
+      </group>
+        <h2>Les écritures</h2>
+        <panel resp-width="98%" style="min-height:15px;">
+      <table autoScroll='true' id="rec_entries" height="220"  style="margin:0 10px auto;">
+      <caption>Compte</caption>
+      <thead resp-width="100%" >
+      <tr style="">
+        <th resp-width='10%'>+</th>
+        <th resp-width="20%">Compte</th>
+        <th resp-width="30%" >Désignation</th>
+        <th resp-width="10%" >Jrnx</th>
+        <th resp-width="15%">Débit</th>
+        <th  resp-width="15%">Crédit</th></tr>
+      </thead>
+      <tbody style="overflow:auto;">
+      </tbody>
+      <tfoot>
+         <tr><td id="recSoldeCompte" colspan="3">Solde:</td>
+           <td style="text-align:right;" id="recSoldeDebit"></td>
+           <td style="text-align:right;" id="recSoldeCredit"></td></tr>
+      </tfoot>
+    </table>
+          </panel>
+          <panel resp-width="98%" style="min-height:14px;padding-top:15px;">
+              <!-- 
+               -->
+            <button id='btRNRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+            <button id='btRNCancel' href="#" style="float:left;">Annuler</button>
+          </panel>
+        </form>
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
   </content>
 </gui>
 XML;
 
 
+
+
 /**
  * @brief Update GUI with the list of 
  * documents available. All decomptes
@@ -42,268 +99,92 @@ class Nouveau extends \PageCompta
        implements \IActionResult 
 {
 
-    function __construct($s = "" ,$b = true)
+    function __construct($_m )
     {
-        parent::__construct($s,$b);
+        $this->_model = $_m;
+        parent::__construct(xmlRecurrentNouveau,true);
     }
     public function render()
     {
         $this->show();
     }
 
-  /**
-   * @brief insert a script in the page to update menu link
-   *
-   */
-    private function script($loc = "/app/compta/services.php/")
-    {
-        $s=<<<_EOF
-<script>
-(function() {
-  var mh1a = $('mh1').firstChild;
-  mh1a.href = "{$loc}";
-})();
-</script>
-_EOF;
-    echo $s;
-  }
-  /**
-   * @brief main page that will list all loans
-   *
-   */
-    private function docRecurrentDetails($id)
-    {
-       $tpl =<<<_EOF
-<tr><td widtd='20'>%s</td>
-    <td align='right'>%s €</td>
-    <td align='right'>%s €</td>
-    </td>
-</tr>
-_EOF;
-    $_cfg = $this->_auth_cfg;
-    $rec = new \Recurrent( $this->getSession()
-             , $_cfg
-             , $this->getSession()->getDb());
-    $des = $rec->get($id);
-    $lst = $rec->getSummary($id);
-    echo "<h2 style='width:100%;'>Détail <i>".$des[3]."</i></h2>";
-    echo "<table  style='width:100%;margin-bottom:10px;'>";
-    echo "<tr ><td style='border-bottom: 1px solid #000;' width='20%'>Date de début      : </td><td align='right'>".$des[1]."</td></tr>";
-    echo "<tr><td>Prochaine échéance:</td><td align='right'>".$des[4]."</td></tr>";
-    echo "<tr><td>Montant : </td><td align='right'>".$des[2]."€</td></tr>";
-    echo "</table>";
-    echo "<h2 style='width:100%;'>Ecritures</h2>";
-    /* acc | debit | credit */
-    echo "<table class='table' style='width:100%;margin-bottom:10px; border: 1px solid #000;' >";
-    $res =<<<_EOF
-           <thead>
-<tr><th width="40%">Account</th>
-    <th align="right">Débit</th>
-    <th align="right">Crédit</th>
-</tr>
-</thead>
-_EOF;
-    echo $res;
-    foreach( $lst as $k => $acc)
-    {
-        if ($acc[4] == 'd')
-        {
-            echo sprintf($tpl,$acc[2]." - ".$acc[5],$acc[3],"0.0");
-        } else
-        {
-            echo sprintf($tpl,$acc[2]." - ".$acc[5],"0.0",$acc[3]);
-        }
-    } 
-    echo "</table>";
-   /*
-    echo "<h2 style='width:100%;'>Prochaine échéance </h2>";
-    $lp = $rec->getNextPayement($id);
-    $date_apayer = new DateTime($lp[6]);
-    $date_today  = new DateTime("now");
-    $p = "";
-    if ($date_apayer > $date_today) {
-    $p.= "en attente";
-    } else {
-            $p.=<<<EOF
-<form method="post" action="/app/compta/page_ledger_recurrent.php">
-        <input type="hidden" name="li" value="{$id}" />
-        <input type="hidden" name="lei" value="{$lp[5]}" />
-        <input type="submit" name="submit" value="payer" />
-      </form>
-EOF;
-    }
-
-    $res =<<<_EOF
-<tr><th width="20%">Date</th>
-    <th align="right">annuite</th>
-    <th align="right">interet</th>
-    <th align="right">ammorti</th>
-    <th align="center">&nbsp;</th>
-</tr>
-<tr><td widtd="20%">{$lp[6]}</td>
-    <td align="right">{$lp[7]} €</td>
-    <td align="right">{$lp[8]} €</td>
-    <td align="right">{$lp[9]} €</td>
-    <td align="right">{$p}
-    </td>
-</tr>
-_EOF;
-    echo $res;
+    /**
+     * @brief allow sub classes to modify xml file
      */
-  }
-
-  /**
-   * @brief pay the loan for this month
-   * @return Array('trans_id') in case of success or empty Array() in case of failure
-   */
-    private function pay($id,$lp)
+    protected function _updateXML(&$xml)
     {
-        $_cfg = $this->_auth_cfg;
-        $entries = array();
-        $book = new Booking( $this->getSession()
-             , $_cfg
-             , $this->getSession()->getDb());
-        $trans = Array("trans_label" => "Payement ".$lp[0][2]
-        ,"voucher_date"    => $lp[0][1]
-        ,"act_trans_date"  => $lp[0][1]);
-        foreach($lp as $e )
-        {
-          $entries[] = Array("acc_id" => $e[5] , "entry_type"=> $e[3] ,"amount" => $e[6], "dc" => $e[4], "key_charge" => "1");
-        }
-      try {
-          return $book->postTransaction($trans,$entries);
-      } catch (Exception $e)
-      {
-         error_log("Failed pay:".$e->message());
-          return Array();
-      }
-
-  }
-  /**
-   * @brief main page that will list all loans
-   *
-   */
-  private function docRecurrentPayer($id)
-  {
-    $_cfg = $this->_auth_cfg;
-    $rec = new \Recurrent( $this->getSession()
-             , $_cfg
-             , $this->getSession()->getDb());
-    $lp = $rec->getNextPayement($id);
-    $result = $this->pay($id,$lp);
-    if (isset($result['trans_id']))
-    { // Success book the entry
-        $rec->markBooked($id);
-    }
-    echo "<h2 style='width:100%;'>Règlement échéance terminé</h2>";
-    echo "<table style='width:100%;margin-bottom:10px; border: 1px solid #000;' >";
-    $res =<<<_EOF
-<tr><th width="20%">Date</th>
-    <th align="right">annuite</th>
-    <th align="right">interet</th>
-    <th align="right">ammorti</th>
-    <th align="center">&nbsp;</th>
-</tr>
-<tr><td widtd="20%">{$lp[6]}</td>
-    <td align="right">{$lp[7]} €</td>
-    <td align="right">{$lp[8]} €</td>
-    <td align="right">{$lp[9]} €</td>
-    <td align="right">
-      <a href="/app/compta/page_ledger_recurrent.php">Retour</a>
-    </td>
-</tr>
+        // Update the title
+        $tbody   = $xml->getElementsByTagName("tbody");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillEntries());
+        $tbody->item(0)->appendChild($nel);
+        /* Update menu */
+        $tbody   = $xml->getElementsByTagName('menu');
+        $f       = $tbody->item(0);
+        $items   =<<<_EOF
+  <item id="btRetour" link="/app/compta/services.php/recurrent/detail/%s" class="" title="Retour" />
 _EOF;
-    echo $res;
-    echo "</table>";
-  }
-  /**
-   * @brief main page that will list all loans
-   *
-   */
-  private function docRecurrents()
-  {
-    $_cfg = $this->_auth_cfg;
-    $rec = new \Recurrent( $this->getSession()
-             , $_cfg
-             , $this->getSession()->getDb());
-    $lst = $rec->getList();
-    echo "<table class='table' style='width:100%;margin-bottom:10px;'>";
-    echo "<thead>";
-    echo "<tr><th width='10%'>Date</th><th>Description</th><th>Montant</th><th>Fin</th><th>Prochaine échéance</th></tr>";
-    echo "</thead>";
-    $date_today  = new \DateTime("now");
-    foreach ($lst as $l)
-    {
-      $res="<tr><td>".$l[1]."</td>";
-      $prochaine_echeance = "";
-      $date_apayer = new \DateTime($l[4]);
-      if ($date_apayer < $date_today)
-      {
-          $prochaine_echeance .= "&nbsp;<a href='page_ledger_recurrent.php?regler=\"".$l[0]."\"'>".$l[4]." a régler</a>";
-      } else
-      { 
-          $prochaine_echeance .= $l[4]." en attente";
-      }
-      $res.=<<<EOF
-<td><a href="?id={$l[0]}">{$l[3]}</a></td>
-EOF;
-      $res.="<td align='right'>".$l[2]."</td>"; // Description
-      $res.="<td align='right'>".$l[5]."</td>"; // Find
-      $res.="<td align='right'>".$prochaine_echeance."</td>"; // Prochaine Echéance
-      $res.="</tr>";
-      echo $res;
-    }
-    // Alright, add the last row that will allow you to add a recurrent entry
-    $res="<tr><td>--.--.--</td>";
-    $res.="<td align='center'>&nbsp;<a href='page_ledger_recurrent.php?a=new'>Ajouter une opération récurrente</a></td>"; // Description
-      $res.="<td align='right'>--</td>"; // Find
-      $res.="<td align='right'>--</td>"; // Find
-      $res.="<td align='right'>--</td>"; // Find
-    $res.="</tr>";
-    echo $res;
-    echo "</table>";
-  }
-  /**
-   *
-   *
-   */
-  private function documents()
-  {
-    if (isset($_GET['id']) )
-    {
-      $this->docRecurrentDetails($_GET['id']);
-    } 
-    else if (isset($_GET['regler']) )
-    {
-      $this->docRecurrentPayer($_GET['regler']);
-    }
-    else
-    {
-      echo "<h3 style='width:100%;'>Les opération récurrentes </h3>";
-      $this->docRecurrents();
+        $frag=sprintf($items
+                     ,$this->_model->id);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($frag);
+        $f->appendChild($nel);
+        // Update asp for fields
+        $this->updateAspfor($xml,$this->_model);
     }
-  }
 
-    /**
-     * @brief Display The articles in flex mode
-     * Also revise menu
-     */
-    function main()
+    private function fillEntries()
     {
-      if ( (isset($_POST) && isset($_POST['submit']) ) 
-        || isset($_GET['regler'])
-        || isset($_GET['id']))
+        $model = $this->_model;
+        $count = 0;
+        $frag  = "";
+        $arr   = Array("id","acc_id","acc_name","entry_type","amount_debit","amount_credit");
+        $tplt  =<<<_EOF
+<td><TextField type="%s" id="entry%d_%s" value="%s" style="width: 95%%;"></TextField></td>
+_EOF;
+        // Add some empty entries to fill the gap.
+        $entries = $model->_entries;
+        $count = count($model->_entries);
+        if ($count < 8 ) 
         {
-            error_log("to ledger_recurrent");
-            $this->script("/app/compta/services.php/");
-        } else
+            for ($i = 8 - $count ; $i > 0 ; $i--)
+            { $entries[] = new \compta\models\recurrent\Entry(); }
+
+        }
+        foreach($entries as $e)
         {
-            error_log("to pag_ledger");
-            $this->script();
+            $i  = 0;
+            $fe = "<tr>";
+            foreach($arr as $f)
+            {
+                if ($f == "amount_debit" ) 
+                {
+                    if ($e->dc == 'd')
+                    {
+                        $fe.=sprintf($tplt,"text",$count,$f,$e->amount);
+                    } else {
+                        $fe.=sprintf($tplt,"text",$count,$f,"0.0");
+                    }
+                } else if ($f == "id")
+                {
+                    $fe.=sprintf($tplt,"hidden",$count,$f,$e->{$f});
+                } else if ($f == "amount_credit")
+                {
+                    if ($e->dc == 'c')
+                    {
+                        $fe.=sprintf($tplt,"text",$count,$f,$e->amount);
+                    } else {
+                        $fe.=sprintf($tplt,"text",$count,$f,"0.0");
+                    }
+                } else
+                    $fe.=sprintf($tplt,"text",$count,$f,$e->{$f});
+            }
+        $fe.="</tr>";
+        $frag.=$fe;
+        $count++;
         }
-        echo '<div class="content" style="display:flex;flex-wrap:wrap">';
-        $this->documents();
-        echo '</div>';
+        return $frag;
     }
 }
 
index 9bd54eaf2b56f7cfcfc9068543753bedb3e56d00..eb9141d2dc086ab168f5dd19bb2f67e8fbfb6b9f 100644 (file)
@@ -5,7 +5,7 @@ require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
 
 require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
 require_once(dirname(__FILE__)."/../models/recurrent.php");
diff --git a/app/compta/views/recurrent_remove.php b/app/compta/views/recurrent_remove.php
new file mode 100644 (file)
index 0000000..139779c
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+
+namespace compta\views\recurrent; 
+require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
+
+require_once(dirname(__FILE__)."/../pages.php");
+require_once(dirname(__FILE__)."/../api_exercice.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
+require_once(dirname(__FILE__)."/../api_booking.php");
+
+const xmlRecurrentRemove =<<<XML
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xslt-param name='alias' value='/andre/'?>
+<?xml-stylesheet type="text/xsl" href="xsl/gui.xsl?alias='/andre/'"?>
+<gui langue='fr' style="padding: 0;">
+<liens/>
+<title langue='fr'>Gestion comptable</title>
+<content>
+  <!-- The script does not work. Looks like an order issue -->
+  <script>
+  </script>
+
+<menu>
+</menu>
+
+  <panel id="pRecurrent" class="col-11 pg-account" style="min-height:150px;">
+    <h2 id="title" style="width:100%">Supprimer l'opération recurrente</h2>
+    <group id="group"> 
+        <grouptitle>Supprimer opération récurrente</grouptitle>
+        <groupcontent>
+          <FieldSet labelWidth="160" style="border:none 0px;">
+            <TextField type="hidden" id="rec_id" asp-for="id" style=""></TextField>
+            <TextField width="253" readOnly="true" labelWidth="250" id="rec_desc" asp-for="rec_desc" style="">
+              <Label style="">Intitulé</Label></TextField><br/>
+            <TextField type="date" readOnly="true" width="190" labelWidth="150" id="rec_date" asp-for="rec_date" style="">
+              <Label style=""> Date de début</Label></TextField><br/>
+            <TextField type="date" readOnly="true" width="190" id="rec_next" asp-for="rec_next" style="">
+              <Label style="">Prochaine échéance</Label></TextField><br/>
+            <TextField type="date" readOnly="true" width="190" id="rec_end" asp-for="rec_end" style="">
+              <Label style="">Date de fin</Label></TextField><br/>
+            <TextField width="190" readOnly="true" id="rec_amount" asp-for="rec_amount" style="">
+              <Label style="">Montant</Label></TextField><br />
+          </FieldSet>
+        </groupcontent>
+    </group>
+          <panel resp-width="98%" style="min-height:14px;padding-top:15px;">
+              <!-- 
+               -->
+            <button id='btRRemove' href="" style="float:left;margin-right: 15px;">Confirmer</button>
+            <button id='btRCancel' href="" style="float:left;">Annuler</button>
+          </panel>
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+
+
+
+
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Remove extends \PageCompta
+        implements \IActionResult 
+{
+
+    function __construct($_m )
+    {
+        $this->_model = $_m;
+        parent::__construct(xmlRecurrentRemove,true);
+    }
+    public function render()
+    {
+        $this->show();
+    }
+
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        // Update buttons
+        $bts     = $xml->getElementsByTagName('button');
+        foreach($bts as $bt)
+        {
+            if ($bt->getAttribute("id") == "btRRemove")
+            {
+                $bt->setAttribute("href","/app/compta/services.php/recurrent/remove/".$this->_model->id."?confirm=true");
+            } 
+            if ($bt->getAttribute("id") == "btRCancel")
+            {
+                $bt->setAttribute("href","/app/compta/services.php/recurrent/detail/".$this->_model->id."");
+            } 
+        }
+        /* Update menu */
+        $tbody   = $xml->getElementsByTagName('menu');
+        $f       = $tbody->item(0);
+        $items   =<<<_EOF
+  <item id="btRetour" link="/app/compta/services.php/recurrent/detail/%s" class="" title="Retour" />
+_EOF;
+        $frag=sprintf($items
+                     ,$this->_model->id);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($frag);
+        $f->appendChild($nel);
+        // Update asp for fields
+        $this->updateAspfor($xml,$this->_model);
+    }
+
+}
+
+?>
index f40f4764be9ab2bac0d99eaf3f534b8e880517b2..656f0afb87a37c4b0f8d1175678496a917289053 100644 (file)
@@ -5,9 +5,93 @@ require_once(dirname(__FILE__)."/../../../phplib/iface.ActionResult.php");
 
 require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_exercice.php");
-require_once(dirname(__FILE__)."/../api_recurrent.php");
+require_once(dirname(__FILE__)."/../api/recurrent.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
+const xmlRecurrentUpdate =<<<XML
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xslt-param name='alias' value='/andre/'?>
+<?xml-stylesheet type="text/xsl" href="xsl/gui.xsl?alias='/andre/'"?>
+<gui langue='fr' style="padding: 0;">
+<liens/>
+<title langue='fr'>Gestion comptable</title>
+<content>
+  <!-- The script does not work. Looks like an order issue-->
+  <script>
+  (function() {
+    console.log("Try to update mh1a");
+    var mh1a = $('mh1').firstChild;
+    mh1a.href = "/fr/app/compta/services.php/";
+  })(); 
+  </script>
+  <script>
+  </script>
+
+<menu>
+</menu>
+
+  <panel id="pRecurrent" class="col-11 pg-account" style="min-height:150px;">
+    <h2 id="title" style="width:100%">Mettre à jour une opération récurrente</h2>
+
+      <form method="post" action="/app/compta/services.php/recurrent/updatePost">
+        <group id="group" > 
+          <grouptitle>Opération récurrente</grouptitle>
+          <groupcontent>
+            <FieldSet labelWidth="160" style="border:none 0px;">
+              <TextField type="hidden" id="rec_id" asp-for="id" style=""></TextField>
+              <TextField width="253" labelWidth="250" id="rec_desc" asp-for="rec_desc" style="">
+                <Label style="">Intitulé</Label></TextField><br/>
+              <TextField width="190" labelWidth="150" id="rec_date" asp-for="rec_date" style="">
+                <Label style=""> Date de début</Label></TextField><br/>
+              <TextField type="date" width="190" id="rec_next" asp-for="rec_next" style="">
+                <Label style="">Prochaine échéance</Label></TextField><br/>
+              <TextField type="date" width="190" id="rec_end" asp-for="rec_end" style="">
+                <Label style="">Date de fin</Label></TextField><br/>
+              <TextField width="190" id="rec_amount" asp-for="rec_amount" style="">
+                <Label style="">Montant</Label></TextField><br />
+            </FieldSet>
+          </groupcontent>
+       </group>
+        <h2>Les écritures</h2>
+<!--
+        <panel resp-width="98%" style="min-height:15px;">
+-->
+      <table autoScroll='true' id="rec_entries" height="220"  style="margin: 0px 0px 0px 15px;width: 98%;">
+      <caption>Compte</caption>
+      <thead resp-width="100%" >
+      <tr style="">
+        <th resp-width='5%'>+</th>
+        <th resp-width="25%">Compte</th>
+        <th resp-width="30%" >Désignation</th>
+        <th resp-width='10%'>Jrnx</th>
+        <th resp-width="15%">Débit</th>
+        <th  resp-width="15%">Crédit</th></tr>
+      </thead>
+      <tbody style="overflow:auto;">
+      </tbody>
+      <tfoot>
+         <tr><td id="recSoldeCompte" colspan="3">Solde:</td>
+           <td style="text-align:right;" id="recSoldeDebit"></td>
+           <td style="text-align:right;" id="recSoldeCredit"></td></tr>
+      </tfoot>
+    </table>
+<!--
+          </panel>
+-->
+          <panel resp-width="98%" style="min-height:14px;padding-top:15px;">
+              <!-- 
+               -->
+            <button id='btRURecord' type="submit" style="float:left;margin-right: 15px;">Modifier</button>
+            <button id='btRUCancel' href="#" style="float:left;">Annuler</button>
+          </panel>
+        </form>
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+
 
 /**
  * @brief Update GUI with the list of 
@@ -21,8 +105,9 @@ class Update extends \PageCompta
     function __construct($model)
     {
         $this->_model = $model;
-        parent::__construct("",true);
+        parent::__construct(xmlRecurrentUpdate,true);
     }
+
     public function render()
     {
         $this->show();
@@ -44,75 +129,88 @@ class Update extends \PageCompta
 _EOF;
     echo $s;
   }
-  /**
-   * @brief main page that will list all loans
-   *
-   */
-    private function document()
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
     {
-       $tpl =<<<_EOF
-<tr><td widtd='20'>%s</td>
-    <td align='right'>%s €</td>
-    <td align='right'>%s €</td>
-    </td>
-</tr>
-_EOF;
-    $des = $this->_model->des;
-    $lst = $this->_model->lst;
-    $res=<<<_EOF
-    <h2 style='width:100%;'>Détail <i>{$des[3]}</i></h2>
-    <form action="/app/compta/services.php/recurrent/updatePost" method="POST" style="width:100%;">
-    <table  style='width:100%;margin-bottom:10px;'>
-    <tr ><td style='border-bottom: 1px solid #000;' width='20%'><label for="dt_debut">Date de début      :</label></td>
-    <td align='right'><input type="date" name="dt_debut" value="{$des[1]}"/></td></tr>
-    <tr><td><label for="dt_next">Prochaine échéance:</label></td><td align='right'><input type="date" name="dt_next" value="{$des[4]}"/></td></tr>
-    <tr><td>Montant : </td><td align='right'><input name="total" type="text" value="{$des[2]}"/> €</td></tr>
-    </table>
-    <h2 style='width:100%;'>Ecritures</h2>
-    
-<table class='table' style='width:100%;margin-bottom:10px; border: 1px solid #000;' >
+        // Update the title
+        $tbody   = $xml->getElementsByTagName("tbody");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillEntries());
+        $tbody->item(0)->appendChild($nel);
+        /* Update menu */
+        $tbody   = $xml->getElementsByTagName('menu');
+        $f       = $tbody->item(0);
+        $items   =<<<_EOF
+  <item id="btRetour" link="/app/compta/services.php/recurrent/detail/%s" class="" title="Retour" />
 _EOF;
+        $frag=sprintf($items
+                     ,$this->_model->id);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($frag);
+        $f->appendChild($nel);
+        // Update asp for fields
+        $this->updateAspfor($xml,$this->_model);
+    }
 
-    $res.=<<<_EOF
-<thead>
-<tr><th width="40%">Account</th>
-    <th align="right">Débit</th>
-    <th align="right">Crédit</th>
-</tr>
-</thead>
-_EOF;
-    echo $res;
-    foreach( $lst as $k => $acc)
+    private function fillEntries()
     {
-        if ($acc[4] == 'd')
+        $model = $this->_model;
+        $count = 0;
+        $frag  = "";
+        $arr   = Array("id","acc_id","acc_name","entry_type","amount_debit","amount_credit");
+        $tplt  =<<<_EOF
+<td><TextField type="%s" id="entry%d_%s" value="%s" style="width: 95%%;"></TextField></td>
+_EOF;
+        $tplt_ro  =<<<_EOF
+<td><TextField type="%s" id="entry%d_%s" value="%s" readOnly="1" style="width: 95%%;"></TextField></td>
+_EOF;
+        // Add some empty entries to fill the gap.
+        $entries = $model->_entries;
+        $ce = count($model->_entries);
+        if ($count < 8 ) 
         {
-            echo sprintf($tpl,$acc[2]." - ".$acc[5],$acc[3],"0.0");
-        } else
+            for ($i = 8 - $ce ; $i > 0 ; $i--)
+            { $entries[] = new \compta\models\recurrent\Entry(); }
+
+        }
+        foreach($entries as $e)
         {
-            echo sprintf($tpl,$acc[2]." - ".$acc[5],"0.0",$acc[3]);
+            $i  = 0;
+            $fe = "<tr>";
+            foreach($arr as $f)
+            {
+                if ($f == "amount_debit" ) 
+                {
+                    if ($e->dc == 'd')
+                    {
+                        $fe.=sprintf($tplt,"text",$count,$f,$e->amount);
+                    } else {
+                        $fe.=sprintf($tplt,"text",$count,$f,"0.0");
+                    }
+                } else if ($f == "id")
+                {
+                    $fe.=sprintf($tplt,"hidden",$count,$f,$e->{$f});
+                } else if ($f == "amount_credit")
+                {
+                    if ($e->dc == 'c')
+                    {
+                        $fe.=sprintf($tplt,"text",$count,$f,$e->amount);
+                    } else {
+                        $fe.=sprintf($tplt,"text",$count,$f,"0.0");
+                    }
+                } else if ($f == "acc_name")
+               {
+                    $fe.=sprintf($tplt_ro,"text",$count,$f,$e->{$f});
+               } else
+                    $fe.=sprintf($tplt,"text",$count,$f,$e->{$f});
+            }
+        $fe.="</tr>";
+        $frag.=$fe;
+        $count++;
         }
-    } 
-    echo "</table>";
-    $res=<<<EOF
-</form>
-<div class="panel" style='padding-bottom:15px;'>
-<a class="button" href="/app/compta/services.php/recurrent/index" style="float:left;"><span>Appliquer</span></a>
-<a class="button" href="/app/compta/services.php/recurrent/index" style="float:left;"><span>Annuler</span></a>
-</div>
-EOF;
-    echo $res;
-  }
-
-    /**
-     * @brief Display The articles in flex mode
-     * Also revise menu
-     */
-    function main()
-    {
-        $this->script("/app/compta/services.php/");
-        echo '<div class="content" style="display:flex;flex-wrap:wrap">';
-        $this->document();
-        echo '</div>';
+        return $frag;
     }
 }
 
index 87979216935cebd3d0e17447e62990d88ade4a14..d6a6ee6c8eb739e0adbcec56f194e8e381464404 100644 (file)
@@ -114,9 +114,9 @@ _EOF;
                      ,$this->_model->_id);
         $nel     = $xml->createDocumentFragment();
         $nel->appendXML($frag);
-       $f->appendChild($nel);
-       // Update asp for fields
-       $this->updateAspfor($xml,$this->_model);
+        $f->appendChild($nel);
+        // Update asp for fields
+        $this->updateAspfor($xml,$this->_model);
     }
 
     /**
diff --git a/app/compta/views/supplier_billpay.php b/app/compta/views/supplier_billpay.php
new file mode 100644 (file)
index 0000000..0cf448f
--- /dev/null
@@ -0,0 +1,203 @@
+<?php
+
+namespace compta\views\supplier; 
+
+require_once(dirname(__FILE__)."/../pages.php");
+
+const SupplierBill =<<<XML
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xslt-param name='alias' value='/andre/'?>
+<?xml-stylesheet type="text/xsl" href="xsl/gui.xsl?alias='/andre/'"?>
+<gui langue='fr' style="padding: 0;">
+<liens/>
+<title langue='fr'>Gestion comptable</title>
+<content>
+  <script>
+  (function() {
+    console.log("Try to update mh1a");
+    var mh1a = $('mh1').firstChild;
+    mh1a.href = "/fr/app/compta/services.php/supplier";
+  })(); 
+  </script>
+  <script>
+  </script>
+
+<menu>
+</menu>
+
+  <panel id="pAccount" class="col-11 pg-account" style="min-height:150px;">
+    <h2 id="title" style="width:100%">Nouvelle facture fournisseur</h2>
+
+          <group id="group"> 
+<grouptitle>Nouvelle Facture</grouptitle>
+<groupcontent>
+<form method="post" action="/app/compta/services.php/supplier/billPost">
+          <FieldSet labelWidth="95" style="border:none 0px;">
+             <TextField width="253" id="suppl_desc" asp-for="suppl_desc" style="margin-right:15px;"><Label style="">Intitule</Label></TextField>
+              <ComboBox width="199" id="suppl_bank"    asp-for="suppl_bank" style="margin-right:15px;"><Label>Banque</Label>
+              </ComboBox> 
+<br/>
+              <ComboBox width="259" id="suppl_id"    asp-for="_id" style="margin-right:15px;"><Label>Fournisseur</Label>
+              </ComboBox> 
+              <TextField width="190" id="suppl_date" asp-for="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
+              <ComboBox width="259" id="suppl_charge" asp-for="suppl_charge" style="margin-right:15px;"><Label>Charge</Label>
+              </ComboBox> 
+            <TextField width="190" id="suppl_voucher_date" asp-for="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
+            <TextField width="253" id="suppl_voucher_ref" asp-for="suppl_voucher_ref" style="margin-right:15px;"><Label style="">Référence</Label></TextField>
+            <TextField width="190" id="suppl_amount" asp-for="suppl_amount" style=""><Label style=""> Montant</Label></TextField><br/>
+            <TextField width="253" id="suppl_voucher_file" type="file" style="margin-right:15px;"><Label style="">Fichier</Label></TextField>
+            <ComboBox width="199" id="suppl_charge_key" asp-for="suppl_charge_key" style=""><Label>Clé Charge</Label>
+            </ComboBox> 
+          </FieldSet>
+          <panel resp-width="98%" style="min-height:14px;">
+              <!-- 
+               -->
+            <button id='btFFRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+            <button id='btFFCancel' href="#" style="float:left;">Annuler</button>
+          </panel>
+        </form>
+      </groupcontent>
+    </group>
+
+
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Billpay extends \PageCompta
+             implements \IActionResult 
+{
+    function __construct($model)
+    {
+        $this->_model = $model;
+        parent::__construct(SupplierBill,true);
+    }
+
+    public function render()
+    {
+        $this->show();
+    }
+
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        $tbody   = $this->getElementById($xml,"suppl_charge_key");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillKeys());
+        $tbody->appendChild($nel);
+        // Ok Handle bank
+        $solde = $this->getElementById($xml,"suppl_bank");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillBanque());
+        $solde->appendChild($nel);
+        // Ok Handle Charges
+        $solde = $this->getElementById($xml,"suppl_charge");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillCharge());
+        $solde->appendChild($nel);
+        // Update supplier ID
+        $tbody   = $this->getElementById($xml,"suppl_id");
+        $nel     = $xml->createDocumentFragment();
+        $frag    =<<<_EOF
+<Entry key="{$this->_model->_id} {$this->_model->_account['acc_desc']}" value="{$this->_model->_id}"></Entry>
+_EOF;
+        $nel->appendXML($frag);
+        $tbody->appendChild($nel);
+        /* Update menu */
+        $tbody   = $xml->getElementsByTagName('menu');
+        $f       = $tbody->item(0);
+        $items   =<<<_EOF
+  <item id="btRetour" link="/app/compta/services.php/supplier/account/%s" class="" title="Retour" />
+_EOF;
+        $frag=sprintf($items
+                     ,$this->_model->_id);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($frag);
+        $f->appendChild($nel);
+        // Update asp for fields
+        $this->updateAspfor($xml,$this->_model);
+    }
+
+    /**
+     * @brief Fill key Charge
+     */
+    private function fillKeys()
+    {
+
+        $template=<<<_EOF
+<Entry key="%s - %s" value="%s"></Entry>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->getKeysCharge();
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                        ,$row[1]
+                        ,$row[2],$row[0]);
+        }
+        return $frag;
+
+    }
+
+    /**
+     * @brief Fill key Charge
+     */
+    private function fillBanque()
+    {
+
+        $template=<<<_EOF
+<Entry key="%s - %s" value="%s"></Entry>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->getListAccounts("5");
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                        ,$row['acc_id']
+                        ,$row['acc_desc']
+                        ,$row['acc_id']);
+        }
+        return $frag;
+
+    }
+    /**
+     * @brief Fill key Charge
+     */
+    private function fillCharge()
+    {
+
+        $template=<<<_EOF
+<Entry key="%s - %s" value="%s"></Entry>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->getListAccounts("6");
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                        ,$row['acc_id']
+                        ,$row['acc_desc']
+                        ,$row['acc_id']);
+        }
+        return $frag;
+
+    }
+
+
+
+}
+
+
+
+?>