Almost Finished supplier ui using mvc model. Data check needs to be completed
authorwww-data <www-data@n3150.home>
Tue, 11 Jan 2022 15:10:40 +0000 (16:10 +0100)
committerwww-data <www-data@n3150.home>
Tue, 11 Jan 2022 15:10:40 +0000 (16:10 +0100)
app/compta/controlers/supplier.php
app/compta/models/supplier.php
app/compta/pages.php
app/compta/services.php
app/compta/views/supplier_bill.php
app/compta/views/supplier_pay.php
app/config/syndic.php
app/xsl
css

index 4d8d681091ac9ed7794a221d4ec458c3d57de2e2..c986129fab40643c721cb6306be625438c4c343a 100644 (file)
@@ -17,6 +17,10 @@ require_once(controler::$basedir."/../../phplib/iface.ActionResult.php");
 require_once(controler::$basedir."/../../phplib/class.ActionResults.php");
 require_once(controler::$modeldir."/supplier.php");
 
+/**
+ *
+ *
+ */
 class Supplier extends controler
 {
 
@@ -39,11 +43,12 @@ class Supplier extends controler
         $page = new \compta\views\supplier\Index($this->_model);
         return $page;
     }
+
     /**
      * Get the details of the supplier account.
      * @param string $_accout_id  the supplier account
      */
-    public function account($_account_id)
+    public function account($_account_id) : \IActionResult
     {
         require_once(controler::$viewdir."/supplier_account.php");
         $this->_model->getDetails($_account_id);
@@ -51,7 +56,7 @@ class Supplier extends controler
         return $page;
     }
     
-    public function details($_supplier_id)
+    public function details($_supplier_id) : \IActionResult
     {
         require_once(controler::$viewdir."/supplier_details.php");
         $this->_model->getDetails($_id);
@@ -59,15 +64,16 @@ class Supplier extends controler
         return $page;
     }
 
-    public function pay($_id)
+    public function pay($_id) : \IActionResult
     {
         require_once(controler::$viewdir."/supplier_pay.php");
         $this->_model->getDetails($_id);
+        $this->_model->getAccount($_id);
         $page = new \compta\views\supplier\Pay($this->_model);
         return $page;
     }
     
-    public function bill($_id)
+    public function bill($_id) : \IActionResult
     {
         require_once(controler::$viewdir."/supplier_bill.php");
         $this->_model->getDetails($_id);
@@ -75,6 +81,34 @@ class Supplier extends controler
         $page = new \compta\views\supplier\Bill($this->_model);
         return $page;
     }
+
+    public function billPost() : \IActionResult
+    {
+        $model = $this->_model;
+        require_once(controler::$viewdir."/supplier_bill.php");
+        $model->getDetails($model->_id);
+        $model->getAccount($model->_id);
+        if ( $model->validePost())
+        {
+            $model->newBill();
+            return $this->account($model->_id);
+        } else
+            return new \compta\views\supplier\Bill($model);
+    }
+
+    public function payPost() : \IActionResult
+    {
+        $model = $this->_model;
+        require_once(controler::$viewdir."/supplier_pay.php");
+        $model->getDetails($model->_id);
+        $model->getAccount($model->_id);
+        if ( $model->validePost())
+        {
+            $model->payBill();
+            return $this->account($model->_id);
+        } else
+            return new \compta\views\supplier\Pay($this->_model);
+    }
 }
 
 ?>
index 88221d223de2f6b8247680431dc34ecf321759e5..09242064d458c9ed42ff60a050ba7c7bf9ef5366 100644 (file)
@@ -8,6 +8,8 @@ require_once(dirname(__FILE__)."/../api_pcmn.php");
 require_once(dirname(__FILE__)."/../api_syndic.php");
 require_once(dirname(__FILE__)."/../api_retrieve.php");
 
+require_once(dirname(__FILE__)."/../../../phplib/class.validator.php");
+
 /**
  * @brief Data model for a transaction. 
  */
@@ -20,13 +22,40 @@ class Model implements \JsonSerializable
     public  $_solde      = 0.0;
     public  $_id = -1; // current entry. -1 no entry selected
     public  $_account = Array();
+   
+    /* Bill parameters */
+    private $bValide           = false; // is Bill from post valide
+    private $billPostParams    = Array("suppl_amount","suppl_date","suppl_voucher_date","suppl_voucher_ref"
+                                      ,"suppl_desc","suppl_charge_key","suppl_charge");
+    private $billPostCheck     = Array("num_float","str_date","str_date","str","str","","");
+    public $suppl_desc         = "";
+    public $suppl_charge       = "";
+    public $suppl_amount       = 0.0;
+    public $suppl_date         = ""; 
+    public $suppl_voucher_date = "";
+    public $suppl_voucher_ref  = "";
+    public $suppl_charge_key   = 1;
+  
+    /* Pay paramater all the same except suppl_charge become suppl_banque*/
+    public $suppl_banque       = "";
+
     /**
      * Constructor
      */
     function __construct($_sess,$_auth)
     {
-        $this->_session  = $_sess;
-        $this->_auth_cfg = $_auth;
+        $this->_session   = $_sess;
+        $this->_auth_cfg  = $_auth;
+        $this->suppl_date = date("Y-m-d");
+        if (\AEB::$REQUEST['btFFRecord'] != null)
+        {
+            $this->getBillPost();
+        } else if (\AEB::$REQUEST['btFPRecord'] != null)
+        {
+            $this->billPostParams[6] = "suppl_banque";
+            // Ok handler pay bill
+            $this->getBillPost();
+        }
     }
 
     private function getSession()
@@ -34,6 +63,41 @@ class Model implements \JsonSerializable
         return $this->_session;
     }
 
+    /**
+     * Retrieve values from billPost request
+     */
+    private function getBillPost()
+    {
+        $count = 0;
+        $valid = true;
+        $v     = new \Validator();
+        $this->_id = \AEB::$REQUEST['suppl_id'];
+        foreach ( $this->billPostParams as $param)
+        {
+            $pv = \AEB::$REQUEST[$param];
+            try {
+                $ck = $this->billPostCheck[$count++];
+                if ($ck != "")
+                {
+                    $v->{$ck}($pv,"Not valid ".$param);
+                } 
+                $this->{$param} = $pv;
+            } catch (Throwable $rte)
+            {
+                $valid = false;
+            } catch (\Exception $e)
+            {
+                $valid = false;
+            }
+        }
+        $this->bValide = $valid;
+    }
+
+    public function validePost()
+    {
+        return $this->bValide;
+    }
+
     public function getDetails($_id)
     {
         $_cfg = $this->_auth_cfg;
@@ -78,13 +142,13 @@ class Model implements \JsonSerializable
     /**
      * Adapter method
      */
-    public function getChargeAccounts()
+    public function getListAccounts($c = "6")
     {
         $_cfg = $this->_auth_cfg;
         $pcmn = new \Pcmn( $this->getSession()
              , $_cfg
              , $this->getSession()->getDb());
-        return $pcmn->getAccountList("6");
+        return $pcmn->getAccountList($c);
     }
 
 
@@ -100,6 +164,48 @@ class Model implements \JsonSerializable
         return $pcmn->getKeysCharge();
 
     }
+
+    /**
+     *
+     */
+    public function newBill()
+    {
+        $transi = Array( 'act_trans_date' => $this->suppl_date
+            , 'voucher_date' => $this->suppl_voucher_date
+            , 'voucher_ref'  => $this->suppl_voucher_ref
+            , 'acc_supplier' => $this->_id
+            , 'acc_charge'   => $this->suppl_charge
+            , 'amount'       => $this->suppl_amount
+            , 'trans_label'  => $this->suppl_desc
+            , 'key_charge'   => $this->suppl_charge_key
+        );
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Booking( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        return $pcmn->newBill($transi,"");
+    }
+
+    /**
+     *
+     */
+    public function payBill()
+    {
+        $transi = Array( 'act_trans_date' => $this->suppl_date
+            , 'voucher_date' => $this->suppl_voucher_date
+            , 'voucher_ref'  => $this->suppl_voucher_ref
+            , 'acc_supplier' => $this->_id
+            , 'acc_banque'   => $this->suppl_banque
+            , 'amount'       => $this->suppl_amount
+            , 'trans_label'  => $this->suppl_desc
+        );
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Booking( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        return $pcmn->payBill($transi,"");
+    }
+
     /**
      * Required by JsonSerializable
      */
index 292d471c92a06e51e36c169b727d7f8ae52f7898..a4206e2c5943ade3bd4e41cfb107b503e64a499b 100644 (file)
@@ -67,7 +67,37 @@ class PageCompta extends AppPage {
       $xpath = new DOMXPath($xml);
       return $xpath->query("//*[@id='$id']")->item(0);
     }
+    /**
+     *
+     */
+    protected function getElementsAspfor($xml)
+    {
+      $xpath = new DOMXPath($xml);
+      return $xpath->query("//*[@asp-for]");
+    }
 
+    protected function updateAspfor($xml,$model)
+    {
+        foreach($this->getElementsAspfor($xml) as $key => $value)
+        {
+            if  ($value->nodeName == "ComboBox")
+            {
+                $afor_value = $model->{$value->getAttribute("asp-for")};
+                // Get and find right selection set selected
+                foreach($value->childNodes as $child)
+                {
+                    if ( ($child->nodeType == XML_ELEMENT_NODE) && 
+                          ($child->nodeName == "Entry")
+                         &&($child->getAttribute("value") == $afor_value) )
+                    {
+                        error_log("Found Entry ".$afor_value."\n");
+                        $child->setAttribute("selected","1");
+                    }
+                }
+            } else
+                $value->setAttribute("value",$model->{$value->getAttribute("asp-for")});
+        }
+    }
     /**
      *
      */
index 59e126a3c0e67a991be90141c26b1c14a114b6d2..b3cd3ada0440b98626ea8e92bda8dde4aecdb07c 100644 (file)
@@ -56,6 +56,8 @@ $r->get('/supplier/details/?:id',"supplier#details")->setRoot($ctrl_dir);
 $r->get('/supplier/account/?:id',"supplier#account")->setRoot($ctrl_dir);
 $r->get('/supplier/bill/?:id',"supplier#bill")->setRoot($ctrl_dir);
 $r->get('/supplier/pay/?:id',"supplier#pay")->setRoot($ctrl_dir);
+$r->post('/supplier/billPost',"supplier#billPost")->setRoot($ctrl_dir);
+$r->post('/supplier/payPost',"supplier#payPost")->setRoot($ctrl_dir);
 
 /* exercice */
 $r->get('/exercice',"exercice#index")->setRoot($ctrl_dir);
index 48db472a54d66cee7dfbb2254c6e22a017b13a4d..87979216935cebd3d0e17447e62990d88ade4a14 100644 (file)
@@ -31,28 +31,30 @@ const SupplierBill =<<<XML
           <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" style=""><Label style="">Intitule</Label></TextField><br/>
-              <ComboBox width="259" id="suppl_id" style="margin-right:10px;"><Label>Fournisseur</Label>
+              <TextField width="253" id="suppl_desc" asp-for="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
+              <ComboBox width="259" id="suppl_id"    asp-for="_id" style="margin-right:15px;"><Label>Fournisseur</Label>
               </ComboBox> 
-              <TextField width="190" id="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
-              <ComboBox width="259" id="suppl_charge" style="margin-right:10px;"><Label>Charge</Label>
+              <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" style=""><Label style=""> Date Facture</Label></TextField><br/>
-            <TextField width="253" id="suppl_voucher_ref" style="margin-right:9px;"><Label style="">Référence</Label></TextField>
-            <TextField width="190" id="suppl_amount" style=""><Label style=""> Montant</Label></TextField><br/>
-            <TextField width="253" id="suppl_voucher_file" type="file" style="margin-right:10px;"><Label style="">Fichier</Label></TextField>
-            <ComboBox width="199" id="suppl_charge_key" style=""><Label>Clé Charge</Label>
+            <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' href="#" style="float:left;">Enregistrer</button>
-        <button id='btFFCancel' style="float:left;" href="#">Annuler</button>
-       </panel>
-</groupcontent>
-</group>
+               -->
+            <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>
@@ -112,7 +114,9 @@ _EOF;
                      ,$this->_model->_id);
         $nel     = $xml->createDocumentFragment();
         $nel->appendXML($frag);
-        $f->appendChild($nel);
+       $f->appendChild($nel);
+       // Update asp for fields
+       $this->updateAspfor($xml,$this->_model);
     }
 
     /**
@@ -148,7 +152,7 @@ _EOF;
 _EOF;
         $frag    = "";
         $count   = 0;
-        $lst     = $this->_model->getChargeAccounts();
+        $lst     = $this->_model->getListAccounts("6");
         foreach( $lst as $row)
         {
             $frag.=sprintf($template
index 17fb5c74fbc4578e162946224c1f8c470fae330a..71dd0e3d2bd8b3774f958c4eb79368145405d54d 100644 (file)
@@ -29,31 +29,31 @@ const SupplierPay =<<<XML
   <panel id="pAccount" class="col-11 pg-account" style="min-height:150px;">
     <h2 id="title" style="width:100%">Payer facture fournisseur</h2>
 
-          <group id="group"> 
-<grouptitle>Payer Facture</grouptitle>
-<groupcontent>
+    <group id="group"> 
+      <grouptitle>Payer Facture</grouptitle>
+      <groupcontent>
+        <form method="post" action="/app/compta/services.php/supplier/payPost">
           <FieldSet labelWidth="95" style="border:none 0px;">
-              <TextField width="243" id="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
-              <ComboBox width="220" id="suppl_id" style="margin-right:10px;"><Label>Fournisseur</Label>
-                  <Entry key="401001-" value="401001"></Entry>
-                  <Entry key="401002-BOLLORE" value="401002"></Entry>
-              </ComboBox> 
-              <TextField width="75" id="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
-              <ComboBox width="220" id="suppl_banque" style="margin-right:10px;"><Label>Banque</Label>
+              <TextField width="243" id="suppl_desc" asp-for="suppl_desc" style=""><Label style="">Intitule</Label></TextField><br/>
+              <ComboBox width="249" id="suppl_id" asp-for="_id" style="margin-right:15px;"><Label>Fournisseur</Label>
+              </ComboBox>
+              <TextField width="75" id="suppl_date" asp-for="suppl_date" style=""><Label style=""> Date Saisie</Label></TextField><br/>
+              <ComboBox width="249" id="suppl_banque" asp-for="suppl_banque"  style="margin-right:15px;"><Label>Banque</Label>
                   <Entry key="512001-Banque postale" value="512001"></Entry>
-              </ComboBox> 
-            <TextField width="75" id="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
-            <TextField width="220" id="suppl_voucher_ref" value="CHEQUE N°" style="margin-right:9px;"><Label style="">Reference</Label></TextField>
-            <TextField width="73" id="suppl_amount" style=""><Label style=""> Montant</Label></TextField>
+              </ComboBox>
+            <TextField width="75" id="suppl_voucher_date" asp-for="suppl_voucher_date" style=""><Label style=""> Date Facture</Label></TextField><br/>
+            <TextField width="243" id="suppl_voucher_ref" asp-for="suppl_voucher_ref" value="CHEQUE N°" style="margin-right:15px;"><Label style="">Reference</Label></TextField>
+            <TextField width="73" id="suppl_amount" asp-for="suppl_amount" style=""><Label style=""> Montant</Label></TextField>
           </FieldSet>
-        <panel class="col-md-10 col-sm-12" style="min-height:14px;">
-          <button id='btFPRecord' href="#" style="float:left;">Enregistrer</button>
-        <button id='btFPCancel' style="float:left;" href="#">Annuler</button>
+          <panel class="col-md-10 col-sm-12" style="min-height:14px;">
+            <button id='btFPRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+            <button id='btFPCancel' style="float:left;" href="">Annuler</button>
           <!--
           -->
-       </panel>       
-</groupcontent>
-</group>
+          </panel>
+        </form>
+      </groupcontent>
+    </group>
 
 
   </panel>
@@ -90,7 +90,7 @@ class Pay extends \PageCompta
         // Ok Handle Charges
         $solde = $this->getElementById($xml,"suppl_banque");
         $nel     = $xml->createDocumentFragment();
-        $nel->appendXML($this->fillCharge());
+        $nel->appendXML($this->fillBanque());
         $solde->appendChild($nel);
         // Update supplier ID
         $tbody   = $this->getElementById($xml,"suppl_id");
@@ -111,12 +111,14 @@ _EOF;
         $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()
+    private function fillBanque()
     {
 
         $template=<<<_EOF
@@ -124,29 +126,7 @@ _EOF;
 _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 fillCharge()
-    {
-
-        $template=<<<_EOF
-<Entry key="%s - %s" value="%s"></Entry>
-_EOF;
-        $frag    = "";
-        $count   = 0;
-        $lst     = $this->_model->getChargeAccounts();
+        $lst     = $this->_model->getListAccounts("5");
         foreach( $lst as $row)
         {
             $frag.=sprintf($template
index 7ecd64a27920ac8aecd0f196b31287aa4b90593b..7f9559c5206ab432e0cb34f1d82e55d77ff559a1 100644 (file)
@@ -412,9 +412,9 @@ EOF;
                    _('Copropriété') => '/'.$alias.$lang.'/app/compta/services.php/org',
                    _('Plan Comptable') => '/'.$alias.$lang.'/app/compta/services.php/chart',
                    _('Exercices') => '/'.$alias.$lang.'/app/compta/services.php/exercice',
-                   _('Fournisseurs') => '/'.$alias.$lang.'/app/compta/page_ledger_fournisseur.php',
+                   _('Fournisseurs') => '/'.$alias.$lang.'/app/compta/services.php/supplier',
                    _('Copropriétaires') => '/'.$alias.$lang.'/app/compta/page_ledger_coproprietaire.php',
-                   _('Décompte Charge') => '/'.$alias.$lang.'/app/compta/page_ledger_mes_documents.php',
+                   _('Décompte Charge') => '/'.$alias.$lang.'/app/compta/services.php/owner/decomptes',
                    _('Journaux') => '/'.$alias.$lang.'/app/compta/services.php/jrnx',
                    _('Bilan') => '/'.$alias.$lang.'/app/compta/services.php/bilan',
                    _('Budget') => '/'.$alias.$lang.'/app/compta/services.php/budget',
diff --git a/app/xsl b/app/xsl
index 01e86fd0b4968b1e2cf37e183f77ff8a7a650837..b1016666f5fd4264ce632b3e00126819a0f02084 160000 (submodule)
--- a/app/xsl
+++ b/app/xsl
@@ -1 +1 @@
-Subproject commit 01e86fd0b4968b1e2cf37e183f77ff8a7a650837
+Subproject commit b1016666f5fd4264ce632b3e00126819a0f02084
diff --git a/css b/css
index 540dc587e4ab3eafb341a0d7d3990bffb35b848e..83819fb21391da8cfbfeba2fe8d16f654f554ffd 160000 (submodule)
--- a/css
+++ b/css
@@ -1 +1 @@
-Subproject commit 540dc587e4ab3eafb341a0d7d3990bffb35b848e
+Subproject commit 83819fb21391da8cfbfeba2fe8d16f654f554ffd