Started Transaction MVC. Detail of transaction
authorwww-data <www-data@n3150.home>
Tue, 30 May 2023 14:39:31 +0000 (16:39 +0200)
committerwww-data <www-data@n3150.home>
Tue, 30 May 2023 14:39:31 +0000 (16:39 +0200)
app/compta/api_retrieve.php
app/compta/controlers/transaction.php
app/compta/models/transaction.php
app/compta/services.php
app/compta/views/account_detail.php
app/compta/views/transaction_detail.php [new file with mode: 0644]

index b9cad96183aa95d60f9bc96597c978679e16d183..7cd524d61c1e96eb19f416a471133d2c1ca6b019 100644 (file)
@@ -74,6 +74,8 @@ _EOF;
       debit_credit     enum  ('d','c'),
       description      VARCHAR(255),
       voucher_ref      VARCHAR(255)
+      @return Array( transaction : Array(transId,voucher_ref,voucher_date,act_transdate,trans_label)
+        entries : Array(tras_ent_id,entry_date,acc_id,acc_name_,debit_credit,amount,te_type)
       */
     function getTransaction($id) {
       $period = $this->getCurrentExercice();
@@ -84,7 +86,7 @@ SELECT trans_id,voucher_ref,voucher_date,act_trans_date,trans_label
 _EOF;
       $transaction = $this->doQueryI($q);
       $q =<<<_EOF
-SELECT trans_entry_id,entry_date,te.acc_id,acc.acc_name,debit_credit,amount 
+SELECT trans_entry_id,entry_date,te.acc_id,acc.acc_name,debit_credit,amount,te.entry_type 
   FROM TransactionEntry AS te 
   JOIN Account          AS acc ON  acc.acc_id = te.acc_id 
   WHERE trans_id ='{$id};'
@@ -235,12 +237,15 @@ EOF;
     /**
      *
      * @param array $opt    Option array like limit, offset
+     *
+     * @return Array( entries : Array(Date,Ref,Designation,Debit,Credit,TransId) , solde : Array())
+     *      
      */
     function getEntriesByAccount($period,$acc,$opt) {
       $q = 'call detail_compte_sans_solde("'.$period.'",'.$acc.');';
       $res = $this->doQueryI($q);
       if ($res['total_matches'] == 0) {
-            return array('entries'=> array(array(0,0,0,0,0)),'solde' =>array(0,0,0));
+            return array('entries'=> array(array(0,0,0,0,0,0)),'solde' =>array(0,0,0));
       } 
       // return $res['records'];
       $q = 'CALL solde_compte("'.$period.'","'.$acc.'");';
index 689e8c8f809bdfad419c3e40e004c7cb2fc30840..eb39a658d58c3fdc387866d309079b3a432f6728 100644 (file)
@@ -3,37 +3,61 @@
 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::$basedir."/session.php");
+require_once(controler::$basedir."/models/transaction.php");
+
+
 /**
  * @brief Transaction controler. 
  *  I'm missing the Transaction Model
  */
 class Transaction 
 {
+    private $_model    = null;
+    private $_session  = null;
+    private $_auth_cfg = null;
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        GLOBAL $conf;
+        $conf_auth       = $conf['auth']['mysql'];
+        $this->_session  = new \SessionCompta($conf_auth,$conf_auth['req_file']);
+        $this->_auth_cfg = $conf['auth']['mysql'];
+        $this->_model    = new \compta\models\transaction\Model($this->_session,$this->_auth_cfg);
+    }
     /**
      * method post add transaction.
      * The post method is actually a json encoded request.
      * I might need to review 
      *
      */
-    public add()
+    public function add()
     {
     }
 
-    public remove()
+    public function remove()
     {
     }
 
-    public detail()
+    public function detail($_id) : \IActionResult
     {
+        require_once(controler::$basedir."/views/transaction_detail.php");
+        $this->_model->get($_id);
+        $page = new \compta\views\transaction\Detail($this->_model);
+        return $page;
     
     
     }
 
-    public summary()
+    public function summary()
     {
     }
 
-    public update()
+    public function update()
     {
     }
 }
index 34cfcec69a453cea8bf4c17d4c433b257bd0dc28..3a8bbbb1e6ea7a0552010f2d5e4af6f5c6690bf7 100644 (file)
@@ -1,6 +1,11 @@
 <?php
 
-namespace compta/model/transaction ;
+namespace compta\models\transaction ;
+
+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_retrieve.php");
 
 /**
  * @brief Data model for a transaction. 
@@ -15,10 +20,30 @@ class Model implements \JsonSerializable
     /**
      * Constructor
      */
-    function __construct()
+    function __construct($_sess,$_auth)
     {
+        $this->_session  = $_sess;
+        $this->_auth_cfg = $_auth;
     }
 
+    private function getSession()
+    {
+        return $this->_session;
+    }
+    /**
+     * Get Transaction data from Database
+     */
+    public function get($_id)
+    {
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Retrieve( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $r    = $pcmn->getTransaction( $_id); // Get Transaction
+        $this->_id         = $_id;
+        $this->_mouvements = $r['entries'];
+        $this->_summary    = $r['transaction'];
+    }
     /**
      * Required by JsonSerializable
      */
index 4bc243a307e8f66ffb76b27a2d54b48107e46fae..4c45db36ce9e23c18295975bd5006d70229b0c6b 100644 (file)
@@ -102,7 +102,7 @@ $r->get('/jrnx/detailMonth/?:id',"jrnx#detailMonth")->setRoot($ctrl_dir);
 $r->get('/transaction',"transaction#index")->setRoot($ctrl_dir);
 $r->get('/transaction/',"transaction#index")->setRoot($ctrl_dir);
 $r->get('/transaction/nouveau',"transaction#nouveau")->setRoot($ctrl_dir);
-$r->get('/transaction/detail',"transaction#detail")->setRoot($ctrl_dir);
+$r->get('/transaction/detail/?:id',"transaction#detail")->setRoot($ctrl_dir);
 $r->get('/transaction/update/?:id',"transaction#update")->setRoot($ctrl_dir);
 $r->post('/transaction/updatePost',"transaction#updatePost")->setRoot($ctrl_dir);
 
index e56945df0275baa73adb8b6f790e57a39ee36139..752d2608c974a8ca81c4c7ed6fccd193210d5098 100644 (file)
@@ -126,8 +126,10 @@ _EOF;
     private function fillTable()
     {
         $template=<<<_EOF
-<tr class="%s"><td>%s</td><td>%s</td>
-<td style="text-align:right">%s</td>
+<tr class="%s">
+<td style="text-align:left">%s</td>
+<td style="text-align:right"><link href="/app/compta/services.php/transaction/detail/%s">%s</link></td>
+<td>%s</td>
 <td style="text-align:right">%s</td>
 <td style="text-align:right;color:%s">%s</td></tr>
 _EOF;
@@ -139,7 +141,7 @@ _EOF;
             $debit   = sprintf("%.2f",$row[3]);
             $credit  = sprintf("%.2f",$row[4]);
             $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] == 0.0 ? "" : $debit
                         ,$row[2] > $row[3] ? "red" : "black"
                         ,$row[4] == 0.0? "" : $credit);
diff --git a/app/compta/views/transaction_detail.php b/app/compta/views/transaction_detail.php
new file mode 100644 (file)
index 0000000..7bbddb1
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+
+namespace compta\views\transaction; 
+
+require_once(dirname(__FILE__)."/../pages.php");
+
+const XmlAccount =<<<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>
+  </script>
+  <script>
+  </script>
+
+<menu>
+  <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
+</menu>
+
+  <panel id="pAccount" class="col-12 pg-account" style="min-height:150px;">
+    <h2 id="title" style="width:100%">Transaction</h2>
+    <p id="date" style="width:100%" >Date de Saisie   : </p>
+    <p id="voucher_date" style="width:100%">Date Facture     : </p>
+    <p id="voucher_ref" style="width:100%" >Réference Facture: </p>
+    <table id="tAccount" autoScroll='true' height="200" style="margin:15px 30px 15px 0px; padding:15px 0px 0px 0px;" >
+      <caption>Détail Transaction</caption>
+      <thead resp-width="100%">
+        <tr>
+          <th resp-width="10%">Date</th>
+          <th resp-width="50%">Account</th>
+          <th resp-width="10%">Type</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="accSoldeCompte" colspan="3">Solde:</td>
+            <td id="accSoldeDebit"  style="text-align:right;" >0.0</td>
+            <td id="accSoldeCredit" style="text-align:right;" >0.0</td>
+        </tr>
+      </tfoot>
+    </table>
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Detail extends \PageCompta
+             implements \IActionResult 
+{
+    function __construct($model)
+    {
+        $this->_model = $model;
+        parent::__construct(XmlAccount,true);
+    }
+
+    public function render()
+    {
+        $this->show();
+    }
+
+  /**
+   * @brief insert a script in the page to update menu link
+   *
+   */
+    private function script()
+    {
+        $s=<<<_EOF
+<script>
+(function() {
+  var mh1a = $('mh1').firstChild;
+  mh1a.href = "page_ledger.php";
+})();
+(function() {
+  var h, a, f;
+  a = document.getElementsByTagName('link');
+  for (h = 0; h < a.length; h++) {
+    f = a[h];
+    if (f.rel.toLowerCase().match(/stylesheet/) && f.href) {
+      var g = f.href.replace(/(&|\?)rnd=\d+/, '');
+      f.href = g + (g.match(/\?/) ? '&' : '?');
+      f.href += 'rnd=' + (new Date().valueOf());
+    }
+  } // for
+})()
+
+</script>
+_EOF;
+    echo $s;
+  }
+
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        $sum   = $this->_model->_summary;
+        $fields= Array('title','date','voucher_ref','voucher_date');
+        $values= Array($sum[4],$sum[3],$sum[1],$sum[2]);
+        $tbody = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        /* Fill Table with entries */
+        $nel->appendXML($this->fillTable());
+        $f->appendChild($nel);
+        /* Update title from xml template */
+        foreach (array_keys($fields) as $key)
+        {
+            $title = $this->getElementById($xml,$fields[$key]);
+            $el    = $xml->createTextNode(" ".$values[$key]);
+            $title->appendChild($el);
+        }
+        // Update return link
+        $retour = $this->getElementById($xml,"btRetour");
+        $retour->removeAttribute('link');
+        $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']);
+        // Ok Handle solde
+        //$solde = $this->getElementById($xml,"accSoldeCompte");
+        //$el    = $xml->createTextNode("compte ".$this->_model->_solde[2]);
+        //$solde->appendChild($el);
+    }
+
+    /**
+     * @brief Fill bilan table
+     */
+    private function fillTable()
+    {
+        $template=<<<_EOF
+<tr class="%s">
+<td style="text-align:left">%s</td>
+<td style="text-align:right"><link href="/app/compta/services.php/transaction/detail/%s">%s</link></td>
+<td>%s</td>
+<td style="text-align:right">%s</td>
+<td style="text-align:right;color:%s">%s</td></tr>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->_mouvements;
+        foreach( $lst as $row)
+        {
+            $debit   = $row[4] == 'd'?sprintf("%.2f",$row[5]):0.0;
+            $credit  = $row[4] == 'c'?sprintf("%.2f",$row[5]):0.0;
+            $frag.=sprintf($template
+                        , ++$count % 2?"odd":"even" ,$row[1]
+                        , $row[2] ,$row[3],$row[6]
+                        , $debit == 0.0 ? "" : $debit
+                        , $debit > $credit ? "red" : "black"
+                        , $credit == 0.0? "" : $credit);
+        }
+        return $frag;
+    }
+
+}
+
+?>