[MVC] Update Transaction entry
authorwww-data <www-data@n3150.home>
Mon, 18 Sep 2023 20:39:06 +0000 (22:39 +0200)
committerwww-data <www-data@n3150.home>
Mon, 18 Sep 2023 20:39:06 +0000 (22:39 +0200)
app/compta/api_booking.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
app/compta/views/transaction_entry.php [new file with mode: 0644]
app/compta/views/transaction_update.php

index f23635e035e511782f19f5527826e3dba4312c72..8d1ce70e54d0cb114c8f9b1354e07031ee6065c4 100644 (file)
@@ -134,7 +134,7 @@ _EOF;
     /**
      *
      */
-    private function updateEntry($trans_id,$entry)
+    public function updateEntry($trans_id,$entry)
     {
       $entry_id = $entry['entry_id'];
       if ( isset($entry['key_charge']) ) 
index 90c1bcb2206f0655433361c2c2f5b9be85427d04..ffb460a2f9debe7ea9dfc315e8d9600304357b3c 100644 (file)
@@ -65,13 +65,49 @@ class Transaction
         return $page;
     }
     
-    public function updatePost($_id)
+    public function updatePost()
     {
-        require_once(controler::$basedir."/views/transaction_update.php");
-        $this->_model->get($_id);
-        $page = new \compta\views\transaction\Update($this->_model);
+        require_once(controler::$basedir."/views/transaction_detail.php");
+        //$this->_model->get($_id);
+        $page = new \compta\views\transaction\Detail($this->_model);
+        return $page;
+    }
+    /**
+     * If successfull update, show detail, or else
+     * show entry with Field on Error. For instance
+     *  - account not leaf or does not exists
+     *  - amount in debit and credit
+     *  - amount is zero in debit and credit
+     */
+    public function updateEntryPost()
+    {
+        require_once(controler::$basedir."/views/transaction_detail.php");
+       //$this->_model->get($_id);
+       // TODO: Get entry check result from model
+        $page = new \compta\views\transaction\Detail($this->_model);
         return $page;
     }
+
+    /**
+     * Display a transaction entry
+     */
+    public function entry($_tid,$_eid)
+    {
+        $model = $this->_model;
+        require_once(controler::$basedir."/views/transaction_entry.php");
+        $model->get($_tid);
+        $model->setEditEntry($_eid);
+        $page = new \compta\views\transaction\Entry($this->_model);
+        return $page;
+    }
+
+    public function search()
+    {
+    }
+
+    public function searchPost()
+    {
+    }
 }
 
 ?>
index f85cad803f7bbe5d780b27300add08376c4980a5..37f24652ecfd132f5e29945ef871e2929a1f23aa 100644 (file)
@@ -27,6 +27,9 @@ class Transaction implements \JsonSerializable
             $i = 0;
             foreach( get_object_vars($this) as $k => $v)
             { $this->{$k} = $c[$i++]; }
+        } else 
+        {
+            $this->id = -1;
         }
     }
     /**
@@ -71,12 +74,12 @@ class Entry implements \JsonSerializable
         }
     }
     /**
-     * Required by JsonSerializable
+     * Required by JsonSerializable. Aligned with api_booking update_Entry
      */
     public function jsonSerialize()
     {
         return [
-          'id'         => $this->id
+          'entry_id'   => $this->id
         , 'entry_date' => $this->entry_date
         , 'entry_type' => $this->entry_type
         , 'acc_id'     => $this->acc_id
@@ -93,11 +96,23 @@ class Model implements \JsonSerializable
 {
 
     private $summary;
-    
-    private $_entries;
 
+    private $editEntry = 0;
+
+    private $formValid = false;
+    
     public  $_id;
     public  $_mouvements;
+    
+    private $updatePostParams = Array( "id", "rec_trans_date" ,"rec_voucher_date" ,"rec_voucher_ref" 
+                                     , "rec_trans_label" );
+    private $updatePostCheck  = Array( "", "str_date" ,"str_date" ,"str"
+                                     , "str"); 
+    private $updateEntryPostParams = Array( "id", "rec_trans_date" ,"rec_voucher_date" ,"rec_voucher_ref" 
+                                     , "rec_trans_label" );
+    private $updateEntryPostCheck  = Array( "", "str_date" ,"str_date" ,"str"
+                                     , "str"); 
+    public  $_entries = Array(); // Array of entries
     /**
      * Constructor
      */
@@ -105,12 +120,76 @@ class Model implements \JsonSerializable
     {
         $this->_session  = $_sess;
         $this->_auth_cfg = $_auth;
+        $this->_summary    = new Transaction();
+        if (\AEB::$REQUEST['btRURecord'] != null)
+        {
+            $this->FormValid = $this->getUpdatePost();
+        }
+        if (\AEB::$REQUEST['btRNRecord'] != null)
+        {
+            $this->FormValid = $this->getUpdatePost();
+        }
+        /* view entry */
+        if (\AEB::$REQUEST['editEntry'] != null)
+        {
+            try 
+            {
+              $this->setEditEntry ( \AEB::$REQUEST['editEntry'] );
+            } catch (Exception $e)
+            {
+            }
+        }
+        /* updateEntry */
+        if (\AEB::$REQUEST['btUpdateEntry'] != null)
+        {
+            $e = null;
+            try 
+            {
+                list($this->formValid,$e) = $this->getUpdateEntryPost ( );
+                if ($this->formValid == true ) 
+                {
+                    $this->updateEntry($this->_id,$e);
+
+                    $this->get($this->_id);
+                } else 
+                {
+                  $this->get($this->_id);
+                }
+            } catch (Exception $e)
+            {
+                $this->get($this->_id);
+            }
+        }
     }
 
+
     private function getSession()
     {
         return $this->_session;
     }
+
+    /**
+     * \brief Verify that $e is a number. Throw an Exception if it's not the case
+     *
+     */
+    public function setEditEntry($e)
+    {
+      $v    = new \Validator();
+      $v->num_int($e,"Failed edit_entry  not int");
+      $this->editEntry = $e;
+    }
+
+    /**
+     * \brief Return true if the given Entry matches the one to be edited.
+     */
+    public function isEntryEdit($e)
+    {
+      if ( ( $e->id == $this->editEntry ) && ( $this->editEntry != 0 ) )
+      {
+        return true;
+      }
+      return false;
+    }
     /**
      * Get Transaction data from Database
      */
@@ -129,11 +208,202 @@ class Model implements \JsonSerializable
         }
         $this->_summary    = new Transaction($r['transaction']);
     }
+    
+    /**
+     * Get Transaction data from Database
+     */
+    private function updateEntry($trans_id,$e)
+    {
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Booking( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $r    = $pcmn->updateEntry($trans_id,$e->jsonSerialize()); // Get Transaction
+    }
 
     public function getEntries()
     {
         return $this->_entries;
     }
+    /**
+     * Get Form Parameters in case of post Transaction
+     */
+    private function getUpdateEntryPost()
+    {
+        $formValid = true;
+        $count     = 0;
+        $valid     = true;
+        $v         = new \Validator();
+        $this->_id = \AEB::$REQUEST["entry_trans_id"];
+
+        $k       = "entry_"; // Check if that key exists
+        $arr     = Array("id","acc_id","entry_type","amount_debit","amount_credit");
+        $check   = Array("num_int","num_int","","num_float","num_float");
+        $e       = new Entry();
+
+        // Check unique parameters
+        foreach ( $arr as $param)
+        {
+            $p = $k.$param;
+            $pv = \AEB::$REQUEST[$p];
+            try {
+                $ck = $check[$count++];
+                if ($ck != "" and $pv != "")
+                {
+                    if ($ck == "num_float" and $pv!= "")
+                    {
+                        $pv = number_format(floatval($pv),3,'.',',');
+                    }
+                    $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()."\n");
+                $formValid = false;
+            }
+        }
+        // Only add Entries with an amount not equal to 0.
+        if ($e->amount == 0.0 or ($e->acc_id == -1))
+        {
+            $formValid = false;
+        }
+        return array($formValid,$e);
+
+    }
+    /**
+     * Get Form Parameters in case of post Transaction
+     */
+    private function getUpdatePost()
+    {
+        $formValid = true;
+        $count     = 0;
+        $valid     = true;
+        $v         = new \Validator();
+        $this->id  = \AEB::$REQUEST['rec_id'];
+        $this->summary->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_","",$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;
+            }
+        }
+    }
+    /**
+     * 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;
+       if ($line == -1)
+       {
+          $k = "entry_";
+       }
+        // 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 0.
+        if ($e->amount != 0.0 and ($e->acc_id != -1))
+        {
+            $this->_entries[] = $e;
+        }
+        return $fvalid;
+    }
+
+    /**
+     * Adapter method Return entry account type
+     * Eg: BQ, VT, AO, AN
+     */
+    public function getEntryTypes()
+    {
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Retrieve( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $r    = $pcmn->getEntryTypes( ); // Get Transaction
+        return $r;
+    }
+
+    /**
     /**
      * Required by JsonSerializable
      */
@@ -141,7 +411,8 @@ class Model implements \JsonSerializable
     {
         return [
            'transi' =>  $this->_summary
-        ,  'entries' => $this->_entries];
+           ,  'entries' => $this->_entries
+        ];
     }
 }
 
index 31978b5599e77310e5997d3f8ecdc5f6ed2ba76f..66a2dbb558a270ed427c28f2fc869c2198bc2a7f 100644 (file)
@@ -103,9 +103,12 @@ $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/?:id',"transaction#detail")->setRoot($ctrl_dir);
+$r->get('/transaction/entry/?:id/?:eid',"transaction#entry")->setRoot($ctrl_dir);
 $r->get('/transaction/remove/?:id',"transaction#remove")->setRoot($ctrl_dir);
+$r->get('/transaction/removeEntry/?:id/?:eid',"transaction#removeEntry")->setRoot($ctrl_dir);
 $r->get('/transaction/update/?:id',"transaction#update")->setRoot($ctrl_dir);
 $r->post('/transaction/updatePost',"transaction#updatePost")->setRoot($ctrl_dir);
+$r->post('/transaction/updateEntryPost',"transaction#updateEntryPost")->setRoot($ctrl_dir);
 
 /* Bilan services*/
 $r->get('/bilan',"bilan#index")->setRoot($ctrl_dir);
index 752d2608c974a8ca81c4c7ed6fccd193210d5098..aeac199ecbeaa99570d3dd9bad428f4e13cc4139 100644 (file)
@@ -37,8 +37,8 @@ const XmlAccount =<<<XML
       </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>
+            <td id="accSoldeDebit"  style="text-align:right;" ></td>
+            <td id="accSoldeCredit" style="text-align:right;" ></td>
         </tr>
       </tfoot>
     </table>
@@ -116,8 +116,14 @@ _EOF;
         $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']);
        // Ok Handle solde
         $solde = $this->getElementById($xml,"accSoldeCompte");
+        $solde_debit  = $this->getElementById($xml,"accSoldeDebit");
+        $solde_credit = $this->getElementById($xml,"accSoldeCredit");
         $el    = $xml->createTextNode("compte ".$this->_model->_solde[2]);
         $solde->appendChild($el);
+        $el    = $xml->createTextNode("".$this->_model->_solde[0]);
+        $solde_debit->appendChild($el);
+        $el    = $xml->createTextNode("".$this->_model->_solde[1]);
+        $solde_credit->appendChild($el);
     }
 
     /**
@@ -128,20 +134,24 @@ _EOF;
         $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 style="text-align:right"><link href="/app/compta/services.php/transaction/detail/%s?b=%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;
+        $back    = \AEB::$REQUEST['b'].":/account/detail/".$this->_model->_id;
         $lst     = $this->_model->_mouvements;
         foreach( $lst as $row)
         {
             $debit   = sprintf("%.2f",$row[3]);
             $credit  = sprintf("%.2f",$row[4]);
             $frag.=sprintf($template
-                        ,++$count % 2?"odd":"even" ,$row[0],$row[5] ,$row[1],$row[2]
+                ,++$count % 2?"odd":"even" 
+                ,$row[0]
+                ,$row[5] ,$back,$row[1]
+                ,$row[2]
                         ,$row[3] == 0.0 ? "" : $debit
                         ,$row[2] > $row[3] ? "red" : "black"
                         ,$row[4] == 0.0? "" : $credit);
index 9cdd649721bbddaaf30d2529ad07f5a6d0181334..64fd48618a37eeb40bf1a2a44105f9f7e46e4f06 100644 (file)
@@ -132,7 +132,19 @@ _EOF;
         // Update return link
         $retour = $this->getElementById($xml,"btRetour");
         $retour->removeAttribute('link');
-        $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']);
+        $back_array = explode(':',\AEB::$REQUEST['b']);
+        $depth = count($back_array);
+        if ($depth> 1)
+        {
+            $current_back = $back_array[$depth - 1];
+            unset( $back_array[$depth - 1] );
+
+            $b = "?b=".implode(':',$back_array);
+            $retour->setAttribute('link',"/app/compta/services.php/".$current_back.$b);
+        }else
+        {
+            $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']);
+        }
         // Ok Handle buttons 
         $panelButtons= $this->getElementById($xml,"pButtons");
         $nel     = $xml->createDocumentFragment();
@@ -148,21 +160,25 @@ _EOF;
         $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 style="text-align:right"><link href="/app/compta/services.php/transaction/entry/%s/%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;
+        $model   = $this->_model;
         $lst     = $this->_model->_mouvements;
+        //$lst     = $this->_model->_entries;
         foreach( $lst as $row)
         {
+            //$row     = $row_entry->jsonSerialize();
             $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]
+                        , $model->_id,$row[0] ,$row[3]
+                        , $row[6] /* Type */
                         , $debit == 0.0 ? "" : $debit
                         , $debit > $credit ? "red" : "black"
                         , $credit == 0.0? "" : $credit);
diff --git a/app/compta/views/transaction_entry.php b/app/compta/views/transaction_entry.php
new file mode 100644 (file)
index 0000000..a316441
--- /dev/null
@@ -0,0 +1,253 @@
+<?php
+
+namespace compta\views\transaction; 
+
+require_once(dirname(__FILE__)."/../pages.php");
+
+require_once(dirname(__FILE__)."/../api_pcmn.php");
+require_once(dirname(__FILE__)."/../api_retrieve.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>
+
+<form method="POST" action="/app/compta/services.php/transaction/updateEntryPost">
+  <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="20%">Account</th>
+          <th resp-width="30%">Account name</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>
+  <panel id="pButtons" resp-width="98%" class="col-12" style="min-height:14px;">
+  <!-- -->
+  </panel>
+  </form>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Entry extends \PageCompta
+             implements \IActionResult 
+{
+    /* To fill combo with right selection */
+    private $selected_type = 'BQ';
+
+    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)
+    {
+        $buttons=<<<_EOF
+    <button id='btTrBack' href="/app/compta/services.php/transaction/detail/{$this->_model->_id}" style="float:left;">Retour</button>
+    <button id='btUpdateEntry' type="submit" style="float:left;margin-right: 15px;">Modifier</button>
+    <button id='btTrErase' style="float:left;" href="/app/compta/services.php/transaction/removeEntry/{$this->_model->_id}">Supprimer</button>
+_EOF;
+        $sum   = $this->_model->_summary->jsonSerialize();
+        $fields= Array('title','date','voucher_ref','voucher_date');
+        $values= Array($sum['trans_label'],$sum['trans_date'],$sum['voucher_ref'],$sum['voucher_date']);
+        $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 buttons 
+        $panelButtons= $this->getElementById($xml,"pButtons");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($buttons);
+        $panelButtons->appendChild($nel);
+    }
+
+    /**
+     * @brief Fill bilan table
+     */
+    private function fillTable()
+    {
+        $template=<<<_EOF
+<tr class="%s">
+<td style="text-align:left">%s</td>
+<td style="text-align:left">%s</td>
+<td style="text-align:right"><link href="/app/compta/services.php/transaction/entry/%s/%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;
+        $templateEdit=<<<_EOF
+<tr class="%s">
+<TextField type="hidden" id="entry_trans_id"  style="" value="%s"></TextField>
+<TextField type="hidden" id="entry_id"  style="" value="%s"></TextField>
+<td style="text-align:left">%s</td>
+<td style="text-align:left">
+<TextField  width="120" id="entry_acc_id" style="" value="%s"></TextField>
+</td>
+<td style="text-align:right">%s</td>
+<td>
+    <ComboBox width="100" id="entry_entry_type" style="">
+      %s
+    </ComboBox> 
+</td>
+<td style="text-align:right">
+<TextField  width="120" id="entry_amount_debit" style="" value="%01.2f"></TextField>
+</td>
+<td style="text-align:right;color:%s">
+<TextField width="120" id="entry_amount_credit" style="" value="%01.2f"></TextField>
+</td>
+</tr>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $model   = $this->_model;
+        //$lst     = $this->_model->_mouvements;
+        $lst     = $this->_model->_entries;
+/**
+    public $id         = -1;
+    public $entry_date = "2022-01-01"; // Could be HA, AN, what ever
+    public $acc_id     = -1;
+    public $acc_name   = "";   // Account name
+    public $dc         = "d";  // Debit or credit
+    public $amount     = 0.0;
+    public $entry_type = "BQ"; // Could be HA, AN, what ever
+ */
+        foreach( $lst as $row)
+        {
+            $debit   = $row->dc == 'd'?sprintf("%.2f",$row->amount):0.0;
+            $credit  = $row->dc == 'c'?sprintf("%.2f",$row->amount):0.0;
+            if ($model->isEntryEdit($row)) 
+            {
+              $entryS0=<<<_EOF
+<Entry key="%s" value="%s"></Entry>
+_EOF;
+              $entryS1=<<<_EOF
+<Entry key="%s" value="%s" selected="" ></Entry>
+_EOF;
+              $types = $model->getEntryTypes();
+              $selected = "";
+              foreach ($types as $t)
+              {
+                  if ($t[0] == $row->entry_type)
+                  {
+                      $selected.=sprintf($entryS1,$t[1],$t[0]);
+                  } else
+                  {
+                      $selected.=sprintf($entryS0,$t[1],$t[0]);
+                  }
+              }
+              $frag.=sprintf($templateEdit
+                  , ++$count % 2?"odd":"even" 
+                  , $model->_id
+                  , $row->id
+                  , $row->entry_date
+                        , $row->acc_id /* Account ID */
+                        , $row->acc_name
+                        , $selected /* Type */
+                        , $debit == 0.0 ? "" : $debit
+                        , $debit > $credit ? "red" : "black"
+                        , $credit == 0.0? "" : $credit);
+            } else
+            {
+              $frag.=sprintf($template
+                        , ++$count % 2?"odd":"even" ,$row->entry_date
+                        , $row->acc_id /* Account ID */
+                        , $model->_id,$row->id ,$row->acc_name
+                        , $row->entry_type /* Type */
+                        , $debit == 0.0 ? "" : $debit
+                        , $debit > $credit ? "red" : "black"
+                        , $credit == 0.0? "" : $credit);
+            }
+        }
+        return $frag;
+    }
+
+}
+
+?>
index bd92184f30d19cada16ae39ce38dafb17532730d..8f51cc96b817312c53b329655eb15da50bf5b5a1 100644 (file)
@@ -39,13 +39,13 @@ const xmlTransactionUpdate =<<<XML
           <groupcontent>
             <FieldSet labelWidth="160" style="border:none 0px;">
               <TextField type="hidden" id="rec_id" asp-for="_id" style=""></TextField>
-              <TextField width="300" labelWidth="250" id="rec_desc" asp-for="_summary.trans_label" style="">
+              <TextField width="300" labelWidth="250" id="rec_trans_label" asp-for="_summary.trans_label" style="">
                 <Label style="">Intitulé</Label></TextField><br/>
-              <TextField type="date" width="190" id="rec_next" asp-for="_summary.trans_date" style="">
+              <TextField type="date" width="190" id="rec_trans_date" asp-for="_summary.trans_date" style="">
                 <Label style="">Date enregistrement</Label></TextField><br/>
-              <TextField type="date" width="190" id="rec_end" asp-for="_summary.voucher_date" style="">
+              <TextField type="date" width="190" id="rec_voucher_date" asp-for="_summary.voucher_date" style="">
                 <Label style="">Date Facture</Label></TextField><br/>
-              <TextField width="300" id="rec_amount" asp-for="_summary.voucher_ref" style="">
+              <TextField width="300" id="rec_voucher_ref" asp-for="_summary.voucher_ref" style="">
                 <Label style="">Rérérence</Label></TextField><br />
             </FieldSet>
           </groupcontent>
@@ -74,7 +74,7 @@ const xmlTransactionUpdate =<<<XML
               <!-- 
                -->
             <button id='btRURecord' type="submit" style="float:left;margin-right: 15px;">Modifier</button>
-            <button id='btRUCancel' href="#" style="float:left;">Annuler</button>
+            <button id='btRCCancel' href="#" style="float:left;">Annuler</button>
           </panel>
         </form>
   </panel>