Add mvc supplier (pay|bill). Still missing apply and cancel feature.
authorwww-data <www-data@n3150.home>
Sun, 9 Jan 2022 21:27:42 +0000 (22:27 +0100)
committerwww-data <www-data@n3150.home>
Sun, 9 Jan 2022 21:27:42 +0000 (22:27 +0100)
app/compta/api_pcmn.php
app/compta/controlers/supplier.php
app/compta/models/supplier.php
app/compta/services.php
app/compta/views/supplier_account.php [new file with mode: 0644]
app/compta/views/supplier_bill.php [new file with mode: 0644]
app/compta/views/supplier_index.php
app/compta/views/supplier_pay.php [new file with mode: 0644]

index b2950d9158e58826f26cf635e85c0afcef527051..b9385a40e11ba419d2408075eef46334c1e80eae 100644 (file)
@@ -77,15 +77,17 @@ __EOF;
 
   }
   /**
-   *
+   * return account details based on account number.
+   *  acc_desc, and others to be defined
    */
-  function getAccount() {
-    error_log("Pcmn::getAccount TODO needs to be coded");
-      return array(
-          'acc_id' => '401001',
-          'acc_desc'   => 'test',
-          'acc_type'     => 'Charge',
-    );
+  function getAccount($_id) {
+      $q =<<<_EOF
+SELECT acc_id, acc_name FROM Account WHERE acc_id ="{$_id}";
+_EOF;
+    $this->logTransaction("Pcmn getAccount ",$q);
+    $res    = $this->doQueryI($q);
+    $ident = $res['records'][0];
+    return  array('acc_id' => $_id,'acc_desc' => $ident[1]);
   }
   /**
    * @brief only delete an account that's closed !! and that's not used
index 73db5cf3b9bd1e4488fec181597c8052ad4142d6..4d8d681091ac9ed7794a221d4ec458c3d57de2e2 100644 (file)
@@ -45,8 +45,8 @@ class Supplier extends controler
      */
     public function account($_account_id)
     {
-        require_once(controler::$viewdir."/supplier_accout.php");
-        $this->_model->getDetails($_id);
+        require_once(controler::$viewdir."/supplier_account.php");
+        $this->_model->getDetails($_account_id);
         $page = new \compta\views\supplier\Account($this->_model);
         return $page;
     }
@@ -59,7 +59,7 @@ class Supplier extends controler
         return $page;
     }
 
-    public function pay()
+    public function pay($_id)
     {
         require_once(controler::$viewdir."/supplier_pay.php");
         $this->_model->getDetails($_id);
@@ -67,10 +67,11 @@ class Supplier extends controler
         return $page;
     }
     
-    public function bill()
+    public function bill($_id)
     {
         require_once(controler::$viewdir."/supplier_bill.php");
         $this->_model->getDetails($_id);
+        $this->_model->getAccount($_id);
         $page = new \compta\views\supplier\Bill($this->_model);
         return $page;
     }
index 6ff61a695797a63d46ab184272c53ac860df6108..88221d223de2f6b8247680431dc34ecf321759e5 100644 (file)
@@ -5,6 +5,7 @@ namespace compta\models\supplier;
 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_syndic.php");
 require_once(dirname(__FILE__)."/../api_retrieve.php");
 
 /**
@@ -18,6 +19,7 @@ class Model implements \JsonSerializable
     public  $_mouvements = Array();
     public  $_solde      = 0.0;
     public  $_id = -1; // current entry. -1 no entry selected
+    public  $_account = Array();
     /**
      * Constructor
      */
@@ -31,6 +33,7 @@ class Model implements \JsonSerializable
     {
         return $this->_session;
     }
+
     public function getDetails($_id)
     {
         $_cfg = $this->_auth_cfg;
@@ -46,15 +49,57 @@ class Model implements \JsonSerializable
         $this->_solde      = $r['solde'];
     }
 
+    /**
+     * Adapter method
+     */
     public function getSuppliers()
     {
         $_cfg = $this->_auth_cfg;
         $pcmn = new \Pcmn( $this->getSession()
              , $_cfg
-            , $this->getSession()->getDb());
-       return $pcmn->getFournisseur("");
+             , $this->getSession()->getDb());
+        return $pcmn->getFournisseur("");
+    }
+    
+    /**
+     * Adapter method
+     */
+    public function getAccount($_id)
+    {
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Pcmn( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $this->_account= $pcmn->getAccount($_id);
+        return $this->_account;
     }
 
+
+    /**
+     * Adapter method
+     */
+    public function getChargeAccounts()
+    {
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Pcmn( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        return $pcmn->getAccountList("6");
+    }
+
+
+    /**
+     * Adapter method
+     */
+    public function getKeysCharge()
+    {
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Syndic( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        return $pcmn->getKeysCharge();
+
+    }
     /**
      * Required by JsonSerializable
      */
index 1fee6d305586f3d888e2d295400b592d9a7898c9..59e126a3c0e67a991be90141c26b1c14a114b6d2 100644 (file)
@@ -52,7 +52,10 @@ $r->get('/account/detail/?:id',"account#detail")->setRoot($ctrl_dir);
 
 /* Supplier services*/
 $r->get('/supplier',"supplier#index")->setRoot($ctrl_dir);
-$r->get('/supplier/detail/?:id',"supplier#detail")->setRoot($ctrl_dir);
+$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);
 
 /* exercice */
 $r->get('/exercice',"exercice#index")->setRoot($ctrl_dir);
diff --git a/app/compta/views/supplier_account.php b/app/compta/views/supplier_account.php
new file mode 100644 (file)
index 0000000..00bb97f
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+
+namespace compta\views\supplier; 
+
+require_once(dirname(__FILE__)."/../pages.php");
+
+const SupplierAccount =<<<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/supplier" class="" title="Retour" />
+</menu>
+
+  <panel id="pAccount" class="col-11 pg-account" style="min-height:150px;">
+    <h2 id="title" style="width:100%">Mes fournisseurs</h2>
+
+  <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>
+    <thead resp-width="100%" >
+    <tr style="">
+        <th resp-width='10%'>Date</th>
+        <th resp-width="30%">Réf</th>
+        <th resp-width="30%" >Désignation</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="supplierSoldeCompte" colspan="3">Solde:</td><td style="text-align:right;" id="supplierSoldeDebit"></td><td style="text-align:right;" id="supplierSoldeCredit"></td></tr>
+ </tfoot>
+    </table>
+</panel>
+
+
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Account extends \PageCompta
+             implements \IActionResult 
+{
+    function __construct($model)
+    {
+        $this->_model = $model;
+        parent::__construct(SupplierAccount,true);
+    }
+
+    public function render()
+    {
+        $this->show();
+    }
+
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        $lSoldes = Array('supplierSoldeDebit','supplierSoldeCredit');
+        $tbody   = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillTable());
+        $f->appendChild($nel);
+        // Ok Handle soldes
+        $solde = $this->getElementById($xml,"supplierSoldeCompte");
+        $el    = $xml->createTextNode(" ".$this->_model->_solde[2]);
+        $solde->appendChild($el);
+        $count = 0;
+        foreach( $lSoldes as $s)
+        {
+          $solde = $this->getElementById($xml,$s);
+          $el    = $xml->createTextNode(" ".$this->_model->_solde[$count++]);
+          $solde->appendChild($el);
+        }
+        /* Update menu */
+        $tbody   = $xml->getElementsByTagName('menu');
+        $f       = $tbody->item(0);
+        $items   =<<<_EOF
+  <item id="btFacture" link="/app/compta/services.php/supplier/bill/%s" fa-icon="fa-file-invoice" title="Facture" />
+  <item id="btPayer" link="/app/compta/services.php/supplier/pay/%s" fa-icon="fa-coins" title="Payer" />
+_EOF;
+        $frag=sprintf($items
+                     ,$this->_model->_id
+                     ,$this->_model->_id);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($frag);
+        $f->appendChild($nel);
+    }
+
+    /**
+     * @brief Fill bilan table
+     */
+    private function fillTable()
+    {
+
+        $template=<<<_EOF
+<tr class="%s"><td>%s</td><td>%s</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>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->_mouvements;
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                        ,++$count % 2?"odd":"even" ,$row[0],$row[1] ,$row[2]
+                        ,$row[3]
+                        ,$row[2] > $row[3] ? "red" : "black"
+                        ,$row[4]);
+        }
+        return $frag;
+
+    }
+
+}
+
+
+?>
diff --git a/app/compta/views/supplier_bill.php b/app/compta/views/supplier_bill.php
new file mode 100644 (file)
index 0000000..48db472
--- /dev/null
@@ -0,0 +1,169 @@
+<?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>
+          <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>
+              </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>
+              </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>
+            </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>
+
+
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Bill 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 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);
+    }
+
+    /**
+     * @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 fillCharge()
+    {
+
+        $template=<<<_EOF
+<Entry key="%s - %s" value="%s"></Entry>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->getChargeAccounts();
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                        ,$row['acc_id']
+                        ,$row['acc_desc']
+                        ,$row['acc_id']);
+        }
+        return $frag;
+
+    }
+
+
+
+}
+
+
+
+?>
index aa815c78409771c79073570fb4f6fb4e1a647ba4..c57e83bf5d0aa16f7a3d9f86ee79ae507b1f58c2 100644 (file)
@@ -21,7 +21,7 @@ const SupplierIndex =<<<XML
   <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
 </menu>
 
-  <panel id="pAccount" class="col-12 pg-account" style="min-height:150px;">
+  <panel id="pAccount" class="col-11 pg-account" style="min-height:150px;">
     <h2 id="title" style="width:100%">Mes fournisseurs</h2>
     <div id="supplier-list" style="width:98%;" class="panel dcol-container">
      <div id="supplier-list-c1" class="panel dcol">
@@ -54,36 +54,6 @@ class Index extends \PageCompta
         $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
      */
@@ -110,7 +80,7 @@ _EOF;
         $template=<<<_EOF
 <span class="user-card" >
 <p>
-<link href="/app/compta/services.php/supplier/details/%s">%s %s</link>
+<link href="/app/compta/services.php/supplier/account/%s">%s %s</link>
 <span style="float: right; padding-right: 10x;">
 Solde <b>%.2f</b>
 </span>
diff --git a/app/compta/views/supplier_pay.php b/app/compta/views/supplier_pay.php
new file mode 100644 (file)
index 0000000..17fb5c7
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+
+namespace compta\views\supplier; 
+
+require_once(dirname(__FILE__)."/../pages.php");
+
+
+const SupplierPay =<<<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%">Payer facture fournisseur</h2>
+
+          <group id="group"> 
+<grouptitle>Payer Facture</grouptitle>
+<groupcontent>
+          <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>
+                  <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>
+          </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>       
+</groupcontent>
+</group>
+
+
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+
+
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Pay extends \PageCompta
+             implements \IActionResult 
+{
+    function __construct($model)
+    {
+        $this->_model = $model;
+        parent::__construct(SupplierPay,true);
+    }
+
+    public function render()
+    {
+        $this->show();
+    }
+
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        // Ok Handle Charges
+        $solde = $this->getElementById($xml,"suppl_banque");
+        $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);
+    }
+
+    /**
+     * @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 fillCharge()
+    {
+
+        $template=<<<_EOF
+<Entry key="%s - %s" value="%s"></Entry>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = $this->_model->getChargeAccounts();
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                        ,$row['acc_id']
+                        ,$row['acc_desc']
+                        ,$row['acc_id']);
+        }
+        return $frag;
+
+    }
+
+
+
+}
+
+
+?>