Improved Update DB, supplier account, owner mvc
authorwww-data <www-data@n3150.home>
Mon, 6 Nov 2023 22:20:42 +0000 (23:20 +0100)
committerwww-data <www-data@n3150.home>
Mon, 6 Nov 2023 22:20:42 +0000 (23:20 +0100)
app/compta/controlers/admin.php
app/compta/controlers/owner.php
app/compta/models/admin.php [new file with mode: 0644]
app/compta/services.php
app/compta/views/admin_index.php
app/compta/views/admin_update.php [new file with mode: 0644]
app/compta/views/compta_index.php
app/compta/views/owner_index.php [new file with mode: 0644]
app/compta/views/supplier_account.php

index 07ac5782ea2d3b17fed210f2b42e8de8526082f0..504b05a50bd7795438e3b60c5419870630a10526 100644 (file)
@@ -15,28 +15,55 @@ namespace compta\controlers;
 require_once(dirname(__FILE__)."/../controler_base.php");
 require_once(controler::$basedir."/../../phplib/iface.ActionResult.php");
 require_once(controler::$basedir."/../../phplib/class.ActionResults.php");
+require_once(controler::$modeldir."/admin.php");
+
+
 
 /**
  *
  *
  */
-class Admin 
+class Admin extends controler 
 {
 
+    private $_model;
     /**
      * Constructor
      */
     public function __construct()
     {
+        parent::__construct();
+        $this->_model = new \compta\models\admin\Model(
+             $this->getSession(),$this->getAuthConfig());
     }
     /**
-     * Get the details of the supplier account.
-     * @param string $_accout_id  the supplier account
+     * Get the details of the accounting system.
      */
     public function index() : \IActionResult
     {
         require_once(controler::$basedir."/views/admin_index.php");
-        $page = new \compta\views\admin\Index();
+        $page = new \compta\views\admin\Index($this->_model);
+        return $page;
+    }
+
+    /**
+     * Display the Update database view
+     * @param string $_accout_id  the supplier account
+     */
+    public function update() : \IActionResult
+    {
+        require_once(controler::$basedir."/views/admin_update.php");
+        $page = new \compta\views\admin\Update($this->_model);
+        return $page;
+    }
+    /**
+     * Display the Update database view
+     * @param string $_accout_id  the supplier account
+     */
+    public function updateRequest($_entry) : \IActionResult
+    {
+        require_once(controler::$basedir."/views/admin_update.php");
+        $page = new \compta\views\admin\Update($this->_model);
         return $page;
     }
 }
index e3bd348690712d66a9968549e43bc55005976cc6..44da737e0ab3d19f53de171508cf3dcaef57af27 100644 (file)
@@ -38,7 +38,9 @@ class Owner extends controler
              $this->getSession(),$this->getAuthConfig());
     }
     /**
-     * Get the details of the supplier account.
+     * Display the list of owners, there financial situation
+     * If logged in user is not the syndic, the simply display
+     * the owner information not more
      * @param string $_accout_id  the supplier account
      */
     public function index() : \IActionResult
@@ -48,7 +50,28 @@ class Owner extends controler
         return $page;
     }
     /**
-     * Get the details of the supplier account.
+     * Get the details of the owner (address account association etc... )
+     * @param string $_accout_id  the supplier account
+     */
+    public function detail() : \IActionResult
+    {
+        require_once(controler::$basedir."/views/owner_index.php");
+        $page = new \compta\views\Owner\Index();
+        return $page;
+    }
+    /**
+     * Détail du compte de copropriétaire
+     * @param string $_owner_id
+     */
+    public function compte($_ownerid) : \IActionResult
+    {
+        require_once(controler::$basedir."/views/owner_index.php");
+        $page = new \compta\views\Owner\Index();
+        return $page;
+    }
+
+    /**
+     * Return the list of all available reports
      * @param string $_accout_id  the supplier account
      */
     public function decomptes() : \IActionResult
diff --git a/app/compta/models/admin.php b/app/compta/models/admin.php
new file mode 100644 (file)
index 0000000..d918f76
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+
+namespace compta\models\admin;
+
+require_once(dirname(__FILE__)."/../api_syndic.php");
+require_once(dirname(__FILE__)."/../api_booking.php");
+require_once(dirname(__FILE__)."/../api_retrieve.php");
+require_once(dirname(__FILE__)."/../schema_mysql.php");
+
+/**
+ * @brief Data model for a transaction. 
+ */
+class Model implements \JsonSerializable
+{
+    private $_session   = null;
+    private $_auth_cfg  = null;
+    private $_db_schema = null;
+
+    /**
+     * Constructor
+     */
+    function __construct($_sess,$_auth)
+    {
+        $this->_session  = $_sess;
+        $this->_auth_cfg = $_auth;
+        $this->loadDbSchema();
+    }
+
+    private function getSession()
+    {
+        return $this->_session;
+    }
+
+    private function loadDbSchema()
+    {
+        GLOBAL $Xml_Compta_Schema;
+        $this->_db_schema = new \DomDocument();
+        $this->_db_schema->loadXML($Xml_Compta_Schema);
+    }
+
+    private function getStatement($_id)
+    {
+      $xpath = new \DOMXPath($this->_db_schema);
+      return $xpath->query("//statement[@count='$id' and mode='update']")->item(0);
+    }
+
+    private function getStatementCount()
+    {
+      $xpath = new \DOMXPath($this->_db_schema);
+      return $xpath->query("/sql/statement[last() ]/@count")->item(0)->value;
+    }
+
+    /**
+     * Compare the index in schema and the one in the 
+     * data base. If the Schema index is higher than
+     * the one in the database, return true. Otherwise
+     * return false
+     */
+    public function isDbUpdateRequired()
+    {
+        $_cfg = $this->_auth_cfg;
+        $syndic = new \Syndic( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        return $syndic->baseCounter() < $this->getStatementCount() ;
+    }
+
+    public function getStatementsToExecute()
+    {
+        $_cfg = $this->_auth_cfg;
+        $syndic = new \Syndic( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $xpath = new \DOMXPath($this->_db_schema);
+        return $xpath->query("/sql/statement[@count>".$syndic->baseCounter()." and @mode='update']");
+    }
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [ ];
+    }
+}
+?>
index 66a2dbb558a270ed427c28f2fc869c2198bc2a7f..55af739196b433a9b652e7c659f0d9f65aaf7491 100644 (file)
@@ -62,6 +62,13 @@ $r->post('/supplier/billPost',"supplier#billPost")->setRoot($ctrl_dir);
 $r->post('/supplier/billPayPost',"supplier#billPayPost")->setRoot($ctrl_dir);
 $r->post('/supplier/payPost',"supplier#payPost")->setRoot($ctrl_dir);
 
+/* Tax services*/
+$r->get('/tax',"tax#index")->setRoot($ctrl_dir);
+/* Tenant services*/
+$r->get('/tenant',"tenant#index")->setRoot($ctrl_dir);
+/* Income services*/
+$r->get('/income',"income#index")->setRoot($ctrl_dir);
+
 /* exercice */
 $r->get('/exercice',"exercice#index")->setRoot($ctrl_dir);
 $r->get('/exercice/',"exercice#index")->setRoot($ctrl_dir);
@@ -130,6 +137,8 @@ $r->post('/budget/updateEntryPost',"budget#updateEntryPost")->setRoot($ctrl_dir)
 /* Admin services*/
 $r->get('/admin',"admin#index")->setRoot($ctrl_dir);
 $r->get('/admin/index',"admin#index")->setRoot($ctrl_dir);
+$r->get('/admin/update',"admin#update")->setRoot($ctrl_dir);
+$r->get('/admin/updateRequest/?:id',"admin#updateRequest")->setRoot($ctrl_dir);
 
 /* Onwer services*/
 $r->get('/owner',"owner#index")->setRoot($ctrl_dir);
index 586723dca5d7382aa70c7f4d4b23b8f7fcb8af74..d11a44ce688def826fd4c5870f221bfa7b04412e 100644 (file)
@@ -59,11 +59,12 @@ XML;
 class Index extends \PageCompta
             implements \IActionResult 
 {
+    private $_model;
 
-    function __construct()
+    function __construct($model)
     {
         parent::__construct(XmlAdminDocument,true);
-        //$this->_model = $model;
+        $this->_model = $model;
     }
 
     private function script()
@@ -136,7 +137,13 @@ _EOF;
 
         $frag.=sprintf($template,"Server",$_cfg[SQL_SERVER]);
         $frag.=sprintf($template,"Base de donnee",$_cfg[SQL_DB]);
-        $frag.=sprintf($template,"Utilisateur",$_cfg[SQL_USER]);
+       $frag.=sprintf($template,"Utilisateur",$_cfg[SQL_USER]);
+       if ($this->_model->isDbUpdateRequired())
+       {
+            $frag.=<<<_EOF
+<tr><td colspan="2"><link href="/app/compta/services.php/admin/update">Update Required</link></td></tr>
+_EOF;
+       }
         return $frag;
 
     }
diff --git a/app/compta/views/admin_update.php b/app/compta/views/admin_update.php
new file mode 100644 (file)
index 0000000..e0d4909
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+namespace compta\views\admin; 
+
+
+require_once(dirname(__FILE__)."/../pages.php");
+require_once(dirname(__FILE__)."/../api_exercice.php");
+require_once(dirname(__FILE__)."/../api_syndic.php");
+
+const XmlAdminUpdateDocument =  <<<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 Mise a jour de la DB </title>
+<content>
+  <!--
+  <script data-main="/app/compta/coproBootstrap.js" src="/js/require.js"></script>
+  -->
+  <menu>
+    <item id="btRetour" link="/app/compta/services.php/admin" class="" title="Retour" />
+  </menu>
+<!-- Start Main Panel-->
+
+<!-- -->
+    <panel class="" style="padding:0px 60px 15px 15px;display:block;min-height:150px;" id="mydocuments">
+    <h3>Mettre à jour la base de donnée</h3>
+
+    <table id="tStatemens" min-height="400" width="100%" style="margin:15px 30px 15px 15px; " >
+      <caption>ail compte </caption>
+      <thead resp-width="100%">
+        <tr>
+          <th resp-width="60%">Description</th>
+          <th resp-width="50%">Valeur</th></tr>
+      </thead>
+      <tbody style="overflow:auto;">
+      </tbody>
+    </table>
+
+    </panel>
+<!-- End Main Panel -->
+    <script></script>
+  </content>
+</gui>
+XML;
+
+
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Update extends \PageCompta
+            implements \IActionResult 
+{
+    private $_model;
+
+    function __construct($model)
+    {
+        parent::__construct(XmlAdminUpdateDocument,true);
+        $this->_model = $model;
+    }
+
+    private function script()
+    {
+        $s=<<<_EOF
+<script>
+(function() {
+  var mh1a = $('mh1').firstChild;
+  mh1a.href = "/fr/app/compta/services.php/";
+})();
+</script>
+_EOF;
+        echo $s;
+    }
+    public function render()
+    {
+        $this->show();
+    }
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        $tbody = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        // Append database config
+        $nel->appendXML($this->fillDatabase());
+
+        $f->appendChild($nel);
+        // Update return link
+        $retour = $this->getElementById($xml,"btRetour");
+        $retour->removeAttribute('link');
+        $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']);
+    }
+    /**
+     * @brief display Database settings
+     */
+    private function fillDatabase()
+    {
+        $frag =<<<_EOF
+<tr class="odd"><td colspan="2" >Base de Donne</td> </tr>
+_EOF;
+        $template=<<<_EOF
+<tr><td style="text-align: center;"><button style="float:none;" id="update" href="/app/compta/services.php/admin/updateRequest/%s">Update</button></td><td>%s</td></tr>
+_EOF;
+
+        foreach(iterator_to_array($this->_model->getStatementsToExecute()) as $_statement)
+        {
+            $frag.=sprintf($template
+                          , $_statement->attributes->item(0)->value
+                          , $_statement->nodeValue);
+        }
+        return $frag;
+
+    }
+
+}
+
+
+?>
index 742577f5cd26758524fada64781e9d8d3b67a399..bc9dc0565bbc94fa27aba1b7063c9515d3aa7376 100644 (file)
@@ -99,9 +99,10 @@ EOF;
      */
     private function fournisseurs() {
       $_content =<<<EOF
-Gérer vos fournisseurs, <br>
-les factures,<br>
-les règlements.<br>
+Gérer vos <a href="/app/compta/services.php/supplier">fournisseurs</a>,
+les <a href="/app/compta/sercices.php/tenant">locataires</a><br>
+les <a href="/app/compta/services.php/tax">impôts</a>,
+les <a href="/app/compta/sercices.php/income">revenus</a><br>
 EOF;
       $this->article(_("Fournisseurs"),"iu-fournisseur.jpg",$_content);
 
diff --git a/app/compta/views/owner_index.php b/app/compta/views/owner_index.php
new file mode 100644 (file)
index 0000000..62a2de0
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+?>
index 6fc7a1d15a19412d9df8343d1468cc8e2ad170db..0eebca85eef0a823e83ad43427a634a54dadf512 100644 (file)
@@ -22,8 +22,48 @@ const SupplierAccount =<<<XML
 </menu>
 
   <panel id="pAccount" class="col-11 pg-account" style="min-height:150px;">
-    <h2 id="title" style="width:100%">Mes fournisseurs</h2>
+    <h2 id="title" style="width:100%"></h2>
 
+    <table autoScroll='false' id="per_month" height="50"  style="margin:0 10px auto;">
+    <caption>Summary</caption>
+<!--
+    <thead resp-width="100%" >
+      <tr style="">
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Jan</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Fév</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Mars</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Avril</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Mai</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Juin</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Juil</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Aout</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Sept</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Oct</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Nov</link></th>
+        <th resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Déc</link></th>
+      </tr>
+    </thead>
+-->
+    <tbody >
+      <tr style="">
+        <td resp-width='8.3%'></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Jan</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Fév</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Mars</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Avril</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Mai</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Juin</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Juil</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Aout</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Sept</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Oct</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Nov</link></td>
+        <td resp-width='8.3%'><link href="/app/compta/services.php/supplier/month">Déc</link></td>
+      </tr>
+    </tbody>
+    <tfoot>
+    </tfoot>
+    </table>
   <panel  style="margin-top:10px;min-height:15px;" resp-width="100%" >
     <table autoScroll='true' id="supplier_table_account" height="200"  style="margin:0 10px auto;">
     <caption>Compte</caption>
@@ -75,7 +115,7 @@ class Account extends \PageCompta
     {
         $lSoldes = Array('supplierSoldeDebit','supplierSoldeCredit');
         $tbody   = $xml->getElementsByTagName('tbody');
-        $f       = $tbody->item(0);
+        $f       = $tbody->item(1);
         $nel     = $xml->createDocumentFragment();
         $nel->appendXML($this->fillTable());
         $f->appendChild($nel);
@@ -83,6 +123,15 @@ class Account extends \PageCompta
         $solde = $this->getElementById($xml,"supplierSoldeCompte");
         $el    = $xml->createTextNode(" ".$this->_model->_solde[2]);
         $solde->appendChild($el);
+        // Title 
+        $title = $this->getElementById($xml,"title");
+        if ($title != null)
+        {
+            $_acc =$this->_model->getAccount($this->_model->_id);
+            
+            $el    = $xml->createTextNode("Fournisseur ".$_acc['acc_desc']." (".$_acc['acc_id'].")");
+            $title->appendChild($el);
+        }
         $count = 0;
         foreach( $lSoldes as $s)
         {
@@ -114,7 +163,7 @@ _EOF;
     {
 
         $template=<<<_EOF
-<tr class="%s"><td>%s</td><td>%s</td>
+<tr class="%s"><td>%s</td><td><link href="/app/compta/services.php/transaction/detail/%s">%s</link></td>
 <td style="text-align:right">%s</td>
 <td style="text-align:right">%.2f</td>
 <td style="text-align:right;color:%s">%.2f</td></tr>
@@ -125,7 +174,7 @@ _EOF;
         foreach( $lst as $row)
         {
             $frag.=sprintf($template
-                        ,++$count % 2?"odd":"even" ,$row[0],$row[1] ,$row[2]
+                        ,++$count % 2?"odd":"even" ,$row[0],$row[5],$row[1] ,$row[2]
                         ,$row[3]
                         ,$row[2] > $row[3] ? "red" : "black"
                         ,$row[4]);