Improved controler views
authorwww-data <www-data@n3150.home>
Fri, 29 Jul 2022 21:28:38 +0000 (23:28 +0200)
committerwww-data <www-data@n3150.home>
Fri, 29 Jul 2022 21:28:38 +0000 (23:28 +0200)
29 files changed:
app/compta/api/recurrent.php
app/compta/api_booking.php
app/compta/api_budget.php
app/compta/controlers/account.php
app/compta/controlers/bilan.php
app/compta/controlers/budget.php
app/compta/controlers/recurrent.php
app/compta/controlers/supplier.php
app/compta/models/bilan.php [new file with mode: 0644]
app/compta/models/budget.php
app/compta/models/recurrent.php
app/compta/models/supplier.php
app/compta/pages.php
app/compta/services.php
app/compta/views/account_categorie.php [new file with mode: 0644]
app/compta/views/account_detail.php
app/compta/views/account_index.php [new file with mode: 0644]
app/compta/views/admin_index.php
app/compta/views/bilan_charges.php [new file with mode: 0644]
app/compta/views/bilan_index.php
app/compta/views/budget_detail.php
app/compta/views/budget_index.php
app/compta/views/budget_list.php [new file with mode: 0644]
app/compta/views/budget_updateEntry.php [new file with mode: 0644]
app/compta/views/recurrent_nouveau.php
app/compta/views/supplier_account.php
app/compta/views/supplier_billpay.php
app/xsl
css

index 8b2704298a2a6b98903108361dde0ac30c3350e8..d0f6ba10b0e7b86c1d197555c8413d6dcda99021 100644 (file)
@@ -41,6 +41,15 @@ class Recurrent extends Api {
      */
     private function insertEntry($rec_id,$e)
     {
+        $tplt = "";
+        if ($e['id'] == -1 ) 
+        {
+         $tplt=<<<_EOF
+INSERT INTO RecurrentEntry (re_rec_id,re_entry_type,re_acc,re_debit_credit,re_amount)
+ VALUES({$rec_id},"{$e['entry_type']}",{$e['acc_id']},"{$e['dc']}",{$e['amount']}) ;
+_EOF;
+        } else
+        {
          $tplt=<<<_EOF
 INSERT INTO RecurrentEntry (re_id,re_rec_id,re_entry_type,re_acc,re_debit_credit,re_amount)
  VALUES({$e['id']},{$rec_id},"{$e['entry_type']}","{$e['acc_id']}","{$e['dc']}",{$e['amount']})
@@ -50,12 +59,6 @@ ON DUPLICATE KEY UPDATE
       , re_amount    = {$e['amount']}
       , re_debit_credit = "{$e['dc']}"
 ;
-_EOF;
-        if ($e['id'] == -1 ) 
-        {
-         $tplt=<<<_EOF
-INSERT INTO RecurrentEntry (re_rec_id,re_enty_type,re_acc,re_debit_credit,re_amount)
- VALUES({$rec_id},{$e['entry_type']},{$e['acc_id']},{$e['dc']},{$e['amount']}) ;
 _EOF;
         }
         try {
@@ -80,17 +83,17 @@ _EOF;
     public function create($r,$entries)
     {
         $tplt=<<<_EOF
-INSERT INTO Recurrent (r_date,r_amount,r_desc,r_next,r_amount,r_end)
- VALUES({$r['r_date']},{$r['r_amount']},{$r['r_desc']},{$r['r_next']},{$r['r_amount']},{$r['r_end']})
+INSERT INTO Recurrent (r_date,r_amount,r_desc,r_next,r_end)
+ VALUES("{$r['r_date']}",{$r['r_amount']},"{$r['r_desc']}","{$r['r_next']}","{$r['r_end']}")
 ; SELECT LAST_INSERT_ID() ; 
 _EOF;
         try {
-            $res = $this->doQueryI($q);
+            $res = $this->doQueryI($tplt);
         } catch (Exception $e) {
             error_log("Recurrent::create ".$id." Failed ".$e->getMessage());
             return Array('');
         }
-        $r_id = $res['records'][0];
+        $r_id = $res['records'][0][0];
         error_log("Recurrent::create ".$id." created add entries");
         foreach($entries as $entry)
         {
index a715c0c758bb150ba4f0bedb7a7e856432262c45..2474d47a4a2c8c04a65e58ad07beb437d91ee79c 100644 (file)
@@ -174,14 +174,14 @@ _EOF;
     {
            $q =<<<_EOF
 SET sql_mode="NO_ENGINE_SUBSTITUTION";
-INSERT INTO Transactions (voucher_date,act_trans_date,trans_label) 
-VALUES ('{$transi['voucher_date']}','{$transi['act_trans_date']}','{$transi['trans_label']}');
+INSERT INTO Transactions (voucher_date,voucher_ref,act_trans_date,trans_label) 
+VALUES ('{$transi['voucher_date']}','{$transi['voucher_ref']}','{$transi['act_trans_date']}','{$transi['trans_label']}');
 _EOF;
       $this->logTransaction("New Transaction ",$q);
       $res = $this->doQueryI($q);
       $qlid= "select LAST_INSERT_ID();";
       $res = $this->doQueryI($qlid);
-      $trans_id = $res['records'][0]['0'];
+      $trans_id = $res['records'][0][0];
 
       foreach($entries as  $entry) {
         $this->newEntry($trans_id,$entry,$transi['act_trans_date']);
@@ -203,6 +203,7 @@ UPDATE Transactions
 SET voucher_date='{$transi['voucher_date']}'
    ,act_trans_date='{$transi['act_trans_date']}'
    ,trans_label= '{$transi['trans_label']}'
+   ,voucher_ref= '{$transi['voucher_ref']}'
 WHERE  trans_id= {$transi['trans_id']} ;
 _EOF;
       $this->logTransaction("Update Transaction ",$q);
index e09f1a618727d17db6b89c7d46227795acf9be54..821ffd568291b1e172148764a2d6849cad597f3f 100644 (file)
@@ -12,63 +12,102 @@ class Budget extends Api {
 
     /**
      * @brief 
-     */
-    function getAllAccounts($transInfo,$entries) {
-    }
-
-    /**
-     * @brief 
+     * return an array of array (bu_id,period,budget_desc)
      */
     function getBudgets() {
       $q =<<<__EOF
-    select bu_id, p.per_string, bu_desc from  Budget as b JOIN Period as p on b.bu_period_id = p.per_id order by p.per_string;
+SELECT bu_id, p.per_string, bu_desc,COALESCE(SUM(be.buet_amount),0.0) from  Budget as b 
+   JOIN Period AS p ON b.bu_period_id = p.per_id 
+   LEFT JOIN BudgetEntry as be ON  b.bu_id  = be.buet_budget_id or be.buet_budget_id IS NULL
+WHERE be.buet_acc_id LIKE ('6%') or be.buet_acc_id IS NULL
+GROUP BY p.per_string
+ORDER by p.per_string
+;
 __EOF;
       $res = $this->doQueryI($q);
       return $res['records'];
     }
-/**
-  trans_id             INTEGER AUTO_INCREMENT PRIMARY KEY,
-  voucher_ref          VARCHAR(255),
-  voucher_date         DATE,
-  act_trans_date       DATE,
-  per_id               INTEGER
 
-Transaction Entry
-  trans_entry_id       INTEGER AUTO_INCREMENT PRIMARY KEY,
-  trans_id             INTEGER,
-  entry_date           DATE,
-  entry_type           VARCHAR(2),
-  acc_id               VARCHAR(32),
-  orig_amount          REAL,
-  amount               DOUBLE PRECISION,
-  debit_credit         enum  ('d','c'),
-  description          VARCHAR(255),
-  voucher_ref          VARCHAR(255)
-  */
-    function getTransaction($id) {
-       $q ='select trans_id,voucher_ref,voucher_date from  Transaction where trans_id ='.$id.';';
-       $transaction = $this->doQueryI($q);
-       $q ='select trans_entry_id,acc_id,voucher_ref,description,debit_credit,amount from  TransactionEntry where trans_id ='.$id.';';
-       $entries = $this->doQueryI($q);
-        return array( 'transaction' => $transaction['records'], 'entries' => $entries['records']);
+    /**
+     * @brief Get the budget entry from the database. If the entry does not yey
+     * exists, return an initialized array with the necessary parameter
+     *
+     *
+     * @param IN $bu_id   The budget identifier
+     * @param IN $acc_nbr String identifing the account number.
+     * @return an array (buet_id,buet_budget_id,buet_acc_id,buet_amount,buet_pc_ic)
+     *
+    public $budget_id  = -1;
+    public $entry_id   = -1;
+    public $acc_id     = -1;
+    public $amount     = 0.0;
+    public $dc         = "c";  // Debit or credit
+    public $pc         = 1;  // Post charge
+     */
+    function getBudgetEntry($bu_id,$acc_nbr) {
+      $q =<<<__EOF
+SELECT 
+     buet_budget_id as budget_id
+   , COALESCE(buet_id,0) as entry_id
+   , buet_acc_id
+   , COALESCE(buet_amount,0.0) as amount
+   , buet_debit_credit
+   , buet_pc_id as pc
+FROM  BudgetEntry as b 
+WHERE buet_acc_id = "{$acc_nbr}" and buet_budget_id = {$bu_id}
+;
+__EOF;
+        $res = $this->doQueryI($q);
+        //if (sizeof($res['records'][0]) < 5)
+        if (! isset($res['records'][0]) )
+        {
+            return Array($bu_id,-1,$acc_nbr,0.0,'c',1);
+        }
+        return $res['records'][0];
     }
 
 
-
     /**
      * @brief 
      */
-    function getBudgetEntries($cls,$anne) {
+    function getBudgetEntries($cls,$anne,$bu_id = -1) {
         $q=<<<EOF
 SELECT c.acc_id ,c.acc_name,COALESCE(be.buet_amount,0) as amount,
-            p.per_string,COALESCE(be.buet_pc_id,1), COALESCE(be.buet_id,0) FROM Account as c
+            p.per_string
+  ,COALESCE(be.buet_pc_id,1)
+  , COALESCE(be.buet_id,0) 
+  , COALESCE(SUM(te.amount),0)
+  , c.acc_right = c.acc_left + 1 as isLeaf
+FROM Account as c
             LEFT JOIN Period as p on (p.per_string = '{$anne}' )
+            LEFT JOIN Period as pn1 on (p.per_id - 1 = pn1.per_id )
             LEFT JOIN Budget as b on b.bu_period_id = p.per_id
             LEFT JOIN BudgetEntry as be on c.acc_id = be.buet_acc_id and be.buet_budget_id = b.bu_id
+            LEFT JOIN TransactionEntry as te on c.acc_id = te.acc_id and te.entry_date BETWEEN pn1.per_begin AND pn1.per_end 
             WHERE c.acc_id like '{$cls}%' 
             GROUP BY c.acc_id
             ;
 EOF;
+        if ($bu_id > 0)
+        {
+            $q=<<<EOF
+SELECT c.acc_id ,c.acc_name,COALESCE(be.buet_amount,0) as amount,
+   p.per_string
+  ,COALESCE(be.buet_pc_id,1)
+  , COALESCE(be.buet_id,0)
+  , COALESCE(SUM(te.amount),0)
+  , c.acc_right = c.acc_left + 1 as isLeaf
+ FROM Account as c
+            LEFT JOIN Budget as b on b.bu_id = {$bu_id}
+            LEFT JOIN Period as p on (p.per_id = b.bu_period_id )
+            LEFT JOIN Period as pn1 on (p.per_id - 1 = pn1.per_id )
+            LEFT JOIN BudgetEntry as be on c.acc_id = be.buet_acc_id and be.buet_budget_id = b.bu_id
+            LEFT JOIN TransactionEntry as te on c.acc_id = te.acc_id and te.entry_date BETWEEN pn1.per_begin AND pn1.per_end 
+            WHERE b.bu_id = {$bu_id} AND c.acc_id like '{$cls}%' 
+            GROUP BY c.acc_id
+            ;
+EOF;
+        }
         $res = $this->doQueryI($q);
         
         return $res['records'];
@@ -79,7 +118,7 @@ EOF;
     /**
      * @brief 
      */
-    function getEntriesByAccount($period,$acc) {
+    private function getEntriesByAccount($period,$acc) {
         $q = 'call detail_compte_sans_solde("'.$period.'",'.$acc.');';
         $res = $this->doQueryI($q);
         if ($res['total_matches'] == 0) {
@@ -94,7 +133,7 @@ EOF;
     /**
      * @brief 
      */
-    function getSoldeAccount($period,$acc) {
+    private function getSoldeAccount($period,$acc) {
        $q = 'CALL solde_compte("'.$period.'","'.$acc.'");';
        $res = $this->doQueryI($q);
        return $res['records'][0];
@@ -112,9 +151,9 @@ EOF;
       error_log("Buget::addBudget ".$anne." desc=".$desc);
         $q = 'select per_id from Period where per_string = "'.$anne.'";';
         $res = $this->doQueryI($q);
-        error_log("addBudget ".$anne." Called res= ".$res["records"][0][0]);
-        if ($res['records'][0][0] > 0) {
-            $pid   = $res['records'][0][0];
+        error_log("addBudget ".$anne." Called res= ".$res["records"][0][0]."\n");
+        if ($res["records"][0][0] > 0) {
+            $pid   = $res["records"][0][0];
             $q     = 'INSERT INTO  Budget (bu_period_id,bu_desc) VALUES('.$pid.',"'.$desc.'");';
             $res   = $this->doQueryI($q);
             $this->logTransaction("Budget Create",$q);
@@ -141,15 +180,49 @@ EOF;
     /**
      * @brief 
      */
-    function addBudgetEntry($buet_id,$bu_id,$acc,$amount,$chrg) {
-      if (!$this->in_groupe(COMPTA_SYNDIC)) {
-          throw new Exception(_("Only Syndic can add or replace a Budget entry"));
-      }
+    function addBudgetEntry($buet_id,$bu_id,$acc,$amount,$chrg)
+    {
+        if (!$this->in_groupe(COMPTA_SYNDIC)) {
+            throw new Exception(_("Only Syndic can add or replace a Budget entry"));
+        }
         $q = "REPLACE INTO BudgetEntry (buet_id,buet_budget_id,buet_acc_id,buet_amount,buet_pc_id) VALUES (".$buet_id.",".$bu_id.",'".$acc."',".$amount.",".$chrg.");";
+        if ($buet_id == -1)
+        { // New entry
+            $q = "INSERT INTO BudgetEntry (buet_budget_id,buet_acc_id,buet_amount,buet_pc_id) VALUES (".$bu_id.",'".$acc."',".$amount.",".$chrg.");";
+        }
         $res = $this->doQueryI($q);
         $this->logTransaction("Budget Add Entry",$q);
         return array("");
     }
+
+    /**
+     * @brief get Budget for all user account or a specific user account
+     * if given as parameter
+     */
+    function getBudgetPerUser($bu_id,$user_acc = null)
+    {
+        $q =<<<_EOF
+SELECT acc_id, acc_name,tant,tc,ROUND(tc * tant / 1000,2) as annuelle,ROUND(tc * tant / 1000 / 4,2) as trimestre, ROUND(tc*tant/1000 / 12,2) as mensuelle FROM 
+ ( SELECT acc_id
+         , acc_name
+         , (SELECT sum(buet_amount) 
+            FROM BudgetEntry as be 
+            JOIN Budget as b on be.buet_budget_id = b.bu_id 
+            JOIN Period as p on p.per_id = b.bu_period_id 
+            WHERE be.buet_acc_id like '6%' AND p.per_string = "2022"
+           ) as tc
+         ,FctTantieme(acc_id,1) as tant 
+    FROM `Account`
+    WHERE acc_id like '45%' and acc_right = acc_left + 1
+ ) as n
+WHERE tant != 0;
+_EOF;
+
+        $res = $this->doQueryI($q);
+        $this->logTransaction("getBudgetPerUser",$q);
+        return $res['records'];
+
+    }
 }
 
 
index 0f8848a3d02bf82690c75a84fdbdb6e422c76835..4c629732ba5fe8750218fdd2d70b335ba0c22774 100644 (file)
@@ -40,10 +40,10 @@ class Account extends controler
      */
     public function index() : \IActionResult
     {
-        //require_once(controler::$basedir."/view_bank_index.php");
-        //$page = new \compta\views\account\Index();
-        return new \HtmlResult("Account to be coded");
-        //return $page;
+        require_once(controler::$viewdir."/account_index.php");
+        $page = new \compta\views\account\Index($this->_model);
+        //return new \HtmlResult("Account to be coded");
+        return $page;
     }
 
     /**
@@ -70,6 +70,19 @@ class Account extends controler
         return $page;
         // return new \HtmlResult("Account  ".$_id);
     }
+    /**
+     * @brief display a short list of all account
+     * categories 1 to 8
+     *
+     */
+    public function categorie($_id)
+    {
+        require_once(controler::$viewdir."/account_categorie.php");
+        $this->_model->getDetails($_id);
+        $page = new \compta\views\account\Categorie($this->_model);
+        return $page;
+        // return new \HtmlResult("Account  ".$_id);
+    }
 
 }
 
index 499eea62ea3626d856b9c21e5d64dd25aabdad8d..5207145cba2e54c00e0b998099a5e8c89e0220a5 100644 (file)
@@ -15,12 +15,13 @@ 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."/bilan.php");
 
 /**
  *
  *
  */
-class Bilan
+class Bilan extends controler
 {
 
     /**
@@ -28,6 +29,9 @@ class Bilan
      */
     public function __construct()
     {
+        parent::__construct();
+        $this->_model = new \compta\models\bilan\Model(
+             $this->getSession(),$this->getAuthConfig());
     }
     /**
      * Get the details of the supplier account.
@@ -39,6 +43,16 @@ class Bilan
        $page = new \compta\views\bilan\Index();
         return $page;
     }
+    /**
+     * Get the details of the supplier account.
+     * @param string $_accout_id  the supplier account
+     */
+    public function charges() : \IActionResult
+    {
+       require_once(controler::$basedir."/views/bilan_charges.php");
+       $page = new \compta\views\bilan\Charges($this->_model);
+        return $page;
+    }
 }
 
 ?>
index 0399c02d00f45ff43edcc99955de3dea2bb9eb18..29e9d018e8f86225260028ad85d01f8cdcc022d9 100644 (file)
@@ -49,14 +49,25 @@ class Budget
         $page = new \compta\views\budget\Index();
         return $page;
     }
+    /**
+     * Get default budget main page.
+     */
+    public function list() : \IActionResult
+    {
+        require_once(controler::$basedir."/views/budget_list.php");
+        $page = new \compta\views\budget\BList($this->_model);
+        return $page;
+    }
     /**
      * Get the details of the supplier account.
      * @param string $_accout_id  the supplier account
      */
     public function detail($_id) : \IActionResult
     {
+       $model = $this->_model;
+       $model->current_budget_id = $_id;
         require_once(controler::$basedir."/views/budget_detail.php");
-        $page = new \compta\views\budget\Index();
+        $page = new \compta\views\budget\Detail($this->_model);
         return $page;
     }
     /**
@@ -69,6 +80,54 @@ class Budget
         $page = new \compta\views\budget\Nouveau();
         return $page;
     }
+    /**
+     * Get the details of the supplier account.
+     * @param string $_accout_id  the supplier account
+     */
+    public function update() : \IActionResult
+    {
+        require_once(controler::$basedir."/views/budget_update.php");
+        $page = new \compta\views\budget\Update();
+        return $page;
+    }
+    /**
+     * Get the details of the supplier account.
+     * TODO validate input parameters
+     * @param string $_accout_id  the supplier account
+     */
+    public function updateEntry($bu_id,$acc) : \IActionResult
+    {
+        $model = $this->_model;
+        require_once(controler::$basedir."/views/budget_updateEntry.php");
+        $model->getBudgetEntry($bu_id,$acc);
+        $page = new \compta\views\budget\UpdateEntry($this->_model);
+        return $page;
+    }
+    /**
+     * Get the details of the supplier account.
+     * @param string $_accout_id  the supplier account
+     */
+    public function updatePost() : \IActionResult
+    {
+        $model = $this->_model;
+        require_once(controler::$basedir."/views/budget_nouveau.php");
+        $page = new \compta\views\budget\Nouveau();
+        return $page;
+    }
+    /**
+     * Get the details of the supplier account.
+     * @param string $_accout_id  the supplier account
+     */
+    public function updateEntryPost() : \IActionResult
+    {
+        $model = $this->_model;
+        if ($model->isFormValid())
+        {
+            $model->setBudgetEntry();
+            return $this->detail($model->entry->budget_id);
+        }
+        return $this->updateEntry($model->entry->budget_id,$model->entry->acc_id);
+    }
 }
 
 ?>
index 228998312f8edf9392989dda75e1767b0e18e05e..ffb586b40bb7ab7c54e55bf706117a58ec73d61a 100644 (file)
@@ -132,8 +132,18 @@ class Recurrent
      */
     public function nouveauPost() : \IActionResult
     {
-        require_once(controler::$basedir."/views/recurrent_nouveau.php");
-        $page = new \compta\views\recurrent\Nouveau($this->_model);
+        $page = null;
+        $model = $this->_model;
+        if ($model->isFormValid())
+        {// Create the entries and every
+            require_once(controler::$basedir."/views/recurrent_index.php");
+            $model->create();
+            $page = new \compta\views\recurrent\Index();
+        } else
+        {
+            require_once(controler::$basedir."/views/recurrent_nouveau.php");
+            $page = new \compta\views\recurrent\Nouveau($this->_model);
+        }
         return $page;
     }
 }
index e8855d76a02e92e0c9d75bb6de07908215e5f8dd..b02954e6409d90d1fa51d1952b8ed4e6be3222ba 100644 (file)
@@ -105,6 +105,21 @@ class Supplier extends controler
             return new \compta\views\supplier\Bill($model);
     }
 
+    public function billPayPost() : \IActionResult
+    {
+        $model = $this->_model;
+        require_once(controler::$viewdir."/supplier_billpay.php");
+        $model->getDetails($model->_id);
+        $model->getAccount($model->_id);
+        if ( $model->validePost())
+        {
+            $model->newBillPay();
+            return $this->account($model->_id);
+        } else
+            return new \compta\views\supplier\Billpay($model);
+    }
+
+
     public function payPost() : \IActionResult
     {
         $model = $this->_model;
diff --git a/app/compta/models/bilan.php b/app/compta/models/bilan.php
new file mode 100644 (file)
index 0000000..0484109
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+
+namespace compta\models\bilan;
+
+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");
+
+require_once(dirname(__FILE__)."/../../../phplib/class.validator.php");
+
+/**
+ * @brief Data model for a transaction. 
+ */
+class Model implements \JsonSerializable
+{
+    private $_session  = null;
+    private $_auth_cfg = null;
+
+    /**
+     * Constructor
+     */
+    function __construct($_sess,$_auth)
+    {
+        $this->_session   = $_sess;
+        $this->_auth_cfg  = $_auth;
+        $this->suppl_date = date("Y-m-d");
+    }
+
+    private function getSession()
+    {
+        return $this->_session;
+    }
+
+    /**
+     *
+     *
+     */
+    public function syntheseCharges()
+    {
+        $ex = $this->getSession()->getCurrentExercice();
+
+        $q=<<<_EOF
+SELECT  a.acc_id 
+       ,a.acc_name
+       ,sum(COALESCE(amount,0)) 
+       , 
+  (SELECT count(p.acc_id) as level FROM Account as ap
+        JOIN Account as p on p.acc_left < ap.acc_left and p.acc_right > ap.acc_right 
+        WHERE ap.acc_id = a.acc_id) as l 
+
+ FROM Account as a
+JOIN   Period as p on per_string = "{$ex}"
+JOIN   Account as son on a.acc_left <= son.acc_left and a.acc_right >= son.acc_right
+LEFT JOIN TransactionEntry as te on son.acc_id = te.acc_id and te.debit_credit = 'd'
+          and te.entry_date BETWEEN p.per_begin AND p.per_end
+LEFT JOIN PosteCharge as pc on te.tret_key_id = pc.pc_id
+WHERE a.acc_id REGEXP ('^6.*')  AND a.acc_left <= a.acc_right - 1
+GROUP BY a.acc_id
+_EOF;
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Retrieve( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $r = $pcmn->doQueryI($q);
+        return $r['records'];
+    }
+
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [
+           'account' =>  $this->_summary
+           ,  'charges' => $this->syntheseCharges()
+        ];
+    }
+
+
+}
index 5063599a311579a08f1b92ec9a141d4d5860a245..7714d374fcff4e7467c2472007baf4265151f6f7 100644 (file)
@@ -6,6 +6,46 @@ require_once(dirname(__FILE__)."/../api_exercice.php");
 require_once(dirname(__FILE__)."/../api_budget.php");
 require_once(dirname(__FILE__)."/../api_booking.php");
 
+
+class Entry implements \JsonSerializable
+{
+    /* Order is important don't change */
+    public $budget_id  = -1;
+    public $entry_id   = -1;
+    public $acc_id     = -1;
+    public $amount     = 0.0;
+    public $dc         = "c";  // Debit or credit
+    public $pc         = 1;  // Post charge
+
+    public function __construct($c = null)
+    {
+        if ($c != null)
+        {
+            $i = 0;
+            foreach( get_object_vars($this) as $k => $v)
+            {
+                //error_log("Entry::ctor ".$k." (pos ".$i.") set to :".$c[$i]."\n"); 
+                $this->{$k} = $c[$i++];
+            }
+        }
+    }
+    /**
+     * Required by JsonSerializable
+     */
+    public function jsonSerialize()
+    {
+        return [
+          'budget_id' => $this->budget_id
+        , 'entry_id'  => $this->entry_id
+        , 'acc_id'    => $this->acc_id
+        , 'amount'    => $this->amount
+        , 'dc'        => $this->dc
+        , 'pc'        => $this->pc];
+    }
+};
+
+
+
 /**
  * @brief Data model for a transaction. 
  */
@@ -13,14 +53,19 @@ class Model implements \JsonSerializable
 {
     private $_session  = null;
     private $_auth_cfg = null;
+    private $budget_db = null;
+
+    private $updatePostParams = Array( "be_budget_id", "be_entry_id" ,"be_acc_id" ,"be_pc" 
+                                     ,"be_amount");
+    private $updatePostCheck  = Array( "num_int", "num_int" ,"num_int" ,"num_int"
+                                     , "num_float",""); 
 
     private $summary;
     
     private $_entries;
-
-    public  $id = -1; // current entry. -1 no entry selected
-    public  $des;     // description of recurrent entry
-    public  $lst;     // list of account operations 
+    public  $FormValid = false;
+    public  $current_budget_id;
+    public  $entry     = null; // Current Budget entry
     /**
      * Constructor
      */
@@ -28,12 +73,110 @@ class Model implements \JsonSerializable
     {
         $this->_session  = $_sess;
         $this->_auth_cfg = $_auth;
+        $this->budget_db = new \Budget( $this->getSession()
+                 , $this->_auth_cfg
+                 , $this->getSession()->getDb());
+        if (\AEB::$REQUEST['btBERecord'] != null)
+        {
+            $this->entry = new Entry();
+            $this->FormValid = $this->getUpdatePost();
+        }
     }
 
     private function getSession()
     {
        return $this->_session;
     }
+
+    /**
+     * @brief retrieve budget list from Database
+     *
+     */
+    public function getBudgets()
+    {
+        $_cfg = $this->_auth_cfg;
+        $b    = new \Budget( $this->getSession()
+                 , $_cfg
+             , $this->getSession()->getDb());
+        return $b->getBudgets();
+    }
+
+    /**
+     * @brief retrieve budger entry from database
+     *
+     */
+    public function getBudgetEntry($bu_id,$acc_nbr)
+    {
+        $b     = $this->budget_db;
+        $this->entry = new Entry($b->getBudgetEntry($bu_id,$acc_nbr));
+        return $this->entry;
+    }
+
+    /**
+     * @brief update/create budget entry in database
+     *
+     */
+    public function setBudgetEntry()
+    {
+        $b = $this->budget_db;
+        $e = $this->entry;
+        //function addBudgetEntry($buet_id,$bu_id,$acc,$amount,$chrg) {
+        error_log("add Entry:".$e->entry_id." bu_id ".$e->budget_id." ".$e->acc_id." ".$e->amount);
+        $b->addBudgetEntry($e->entry_id,$e->budget_id,$e->acc_id,$e->amount,$e->pc);
+        return ;
+    }
+
+    /**
+     *
+     *
+     */
+    public function getBudgetEntries($bu_id,$categorie)
+    {
+        $b     = $this->budget_db;
+        return $b->getBudgetEntries($categorie,"",$bu_id);
+    }
+    /**
+     *
+     */
+    public function isFormValid()
+    {
+        return $this->FormValid;
+    }
+    /**
+     * Retrieve values from billPost request
+     */
+    private function getUpdatePost()
+    {
+        $formValid = true;
+        $count     = 0;
+        $valid     = true;
+        $v         = new \Validator();
+
+        // Check unique parameters
+        $f = reset($this->updatePostParams);
+        foreach ( $this->updatePostParams as $param)
+        {
+            $pv = \AEB::$REQUEST[$param];
+            try 
+            {
+                $ck = $this->updatePostCheck[$count++];
+                if ($ck != "")
+                {
+                    $v->{$ck}($pv,"Not valid ".$param." value=".$pv."\n");
+                }
+                // TODO remove once solved
+                if ($this->entry != null)
+                  $this->entry->{str_replace("be_","",$param)} = $pv;
+            }
+            catch (\Exception $e)
+            {
+                error_log("Parameter failure ".$e->getMessage());
+                $formValid = false;
+            }
+        }
+        return $formValid;
+    }
+
     /**
      * Required by JsonSerializable
      */
index 1952ab717d109194c16ef7df3e03e1ef4991ce9d..de8798754702e9b69fafbd9245ee299fa936ccbb 100644 (file)
@@ -256,6 +256,7 @@ class Model implements \JsonSerializable
              , $this->getSession()->getDb());
         $trans = Array("trans_label" => "Payement ".$lp[0][2]
         ,"voucher_date"    => $lp[0][1]
+        ,"voucher_ref"    =>   $lp[0][2]." ".$lp[0].[1] 
         ,"act_trans_date"  => $lp[0][1]);
         foreach($lp as $e )
         {
@@ -309,6 +310,17 @@ class Model implements \JsonSerializable
                     , json_decode(json_encode($this->_entries),true));
     }
 
+
+    public function create()
+    {
+        $_cfg = $this->_auth_cfg;
+        $rec  = new \Recurrent( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        $rec->create( $this->summary->jsonSerialize()
+                    , json_decode(json_encode($this->_entries),true));
+    }
+
     /**
      * @brief get the details of a recurrent entry.
      *
index 09242064d458c9ed42ff60a050ba7c7bf9ef5366..b79fe7063891cc224affc9836e3143b147176892 100644 (file)
@@ -26,8 +26,8 @@ class Model implements \JsonSerializable
     /* 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","","");
+                                      ,"suppl_desc","suppl_charge_key","suppl_charge","suppl_charge");
+    private $billPostCheck     = Array("num_float","str_date","str_date","str","str","","","");
     public $suppl_desc         = "";
     public $suppl_charge       = "";
     public $suppl_amount       = 0.0;
@@ -50,6 +50,11 @@ class Model implements \JsonSerializable
         if (\AEB::$REQUEST['btFFRecord'] != null)
         {
             $this->getBillPost();
+        } else if (\AEB::$REQUEST['btFFPRecord'] != null)
+        {
+            $this->billPostParams[7] = "suppl_banque";
+            // Ok handler pay bill
+            $this->getBillPost();
         } else if (\AEB::$REQUEST['btFPRecord'] != null)
         {
             $this->billPostParams[6] = "suppl_banque";
@@ -165,6 +170,34 @@ class Model implements \JsonSerializable
 
     }
 
+    /**
+     *
+     */
+    public function newBillPay()
+    {
+        $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
+       );
+       $_amount = $this->suppl_amount;
+       $_charge = $this->suppl_charge;
+       $entries = Array(
+           Array("acc_id" => $this->_id, "entry_type"=> "HA" ,"amount" => $_amount, "dc" => 'c', "key_charge" => "1")
+           ,Array("acc_id" => $_charge , "entry_type"=> "HA" ,"amount" => $_amount, "dc" => 'd', "key_charge" => "1")
+           ,Array("acc_id" => $this->_id , "entry_type"=> "BQ" ,"amount" => $_amount, "dc" => 'd', "key_charge" => "1")
+           ,Array("acc_id" => $this->suppl_banque , "entry_type"=> "BQ" ,"amount" => $_amount, "dc" => 'c', "key_charge" => "1")
+       );
+        $_cfg = $this->_auth_cfg;
+        $pcmn = new \Booking( $this->getSession()
+             , $_cfg
+             , $this->getSession()->getDb());
+        return $pcmn->postTransaction($transi,$entries);
+    }
     /**
      *
      */
@@ -186,6 +219,7 @@ class Model implements \JsonSerializable
         return $pcmn->newBill($transi,"");
     }
 
+
     /**
      *
      */
index a4206e2c5943ade3bd4e41cfb107b503e64a499b..1644fe2c1c2d7eaff4ce1e78c9a27e58d2c6dcc9 100644 (file)
@@ -82,7 +82,8 @@ class PageCompta extends AppPage {
         {
             if  ($value->nodeName == "ComboBox")
             {
-                $afor_value = $model->{$value->getAttribute("asp-for")};
+                //$afor_value = $model->{$value->getAttribute("asp-for")};
+                $afor_value = $this->getAspAttributeFromModel($value,$model);
                 // Get and find right selection set selected
                 foreach($value->childNodes as $child)
                 {
@@ -90,12 +91,33 @@ class PageCompta extends AppPage {
                           ($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")});
+                $value->setAttribute("value"
+                                    ,$this->getAspAttributeFromModel($value,$model));
+        }
+    }
+
+    /**
+     * @brief getting the attribute from model based on asp entry seems to
+     * be more complicated I thought
+     */
+    private function getAspAttributeFromModel($value,$model)
+    {
+        $asp = $value->getAttribute("asp-for");
+        $pos = strpos($asp,'.');
+        if ($pos !== false)
+        { // Get child object to retrieve the parameter
+            $child = strstr($asp,".",1);
+            $entry = substr(strstr($asp,"."),1);
+            $mv    = get_object_vars($model);
+            return $mv[$child]->{$entry};
+
+        } else
+        { // Get attribute directly from object model
+            return $model->{$value->getAttribute("asp-for")};
         }
     }
     /**
index b3cd3ada0440b98626ea8e92bda8dde4aecdb07c..4bc243a307e8f66ffb76b27a2d54b48107e46fae 100644 (file)
@@ -49,6 +49,7 @@ $r->get('/chart/acount/?:id',"chart#account")->setRoot($ctrl_dir);
 /* Account services*/
 $r->get('/account',"account#index")->setRoot($ctrl_dir);
 $r->get('/account/detail/?:id',"account#detail")->setRoot($ctrl_dir);
+$r->get('/account/categorie/?:id',"account#categorie")->setRoot($ctrl_dir);
 
 /* Supplier services*/
 $r->get('/supplier',"supplier#index")->setRoot($ctrl_dir);
@@ -56,7 +57,9 @@ $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->get('/supplier/billpay/?:id',"supplier#billpay")->setRoot($ctrl_dir);
 $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);
 
 /* exercice */
@@ -86,6 +89,7 @@ $r->post('/recurrent/updatePost',"recurrent#updatePost" ) ->setRoot($ctrl_dir);
 $r->get('/recurrent/payer/?:id',"recurrent#payer")->setRoot($ctrl_dir);
 $r->get('/recurrent/nouveau',"recurrent#nouveau")->setRoot($ctrl_dir);
 $r->post('/recurrent/nouveauPost',"recurrent#nouveauPost" ) ->setRoot($ctrl_dir);
+$r->get('/recurrent/remove/?:id',"recurrent#remove" ) ->setRoot($ctrl_dir);
 
 /* journal  */
 $r->get('/jrnx',"jrnx#index")->setRoot($ctrl_dir);
@@ -106,14 +110,18 @@ $r->post('/transaction/updatePost',"transaction#updatePost")->setRoot($ctrl_dir)
 $r->get('/bilan',"bilan#index")->setRoot($ctrl_dir);
 $r->get('/bilan/index',"bilan#index")->setRoot($ctrl_dir);
 $r->get('/bilan/synthese',"bilan#synthese")->setRoot($ctrl_dir);
+$r->get('/bilan/charges',"bilan#charges")->setRoot($ctrl_dir);
 
 /* Budget services*/
 $r->get('/budget',"budget#index")->setRoot($ctrl_dir);
 $r->get('/budget/index',"budget#index")->setRoot($ctrl_dir);
+$r->get('/budget/list',"budget#list")->setRoot($ctrl_dir);
 $r->get('/budget/detail/?:id',"budget#detail")->setRoot($ctrl_dir);
 $r->get('/budget/nouveau',"budget#nouveau")->setRoot($ctrl_dir);
 $r->get('/budget/update',"budget#update")->setRoot($ctrl_dir);
+$r->get('/budget/updateEntry/?:id/?:acc',"budget#updateEntry")->setRoot($ctrl_dir);
 $r->post('/budget/updatePost',"budget#updatePost")->setRoot($ctrl_dir);
+$r->post('/budget/updateEntryPost',"budget#updateEntryPost")->setRoot($ctrl_dir);
 
 /* Admin services*/
 $r->get('/admin',"admin#index")->setRoot($ctrl_dir);
diff --git a/app/compta/views/account_categorie.php b/app/compta/views/account_categorie.php
new file mode 100644 (file)
index 0000000..6ff3558
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+
+namespace compta\views\account; 
+
+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%">Détail </h2>
+    <table id="tAccount" autoScroll='true' height="200" style="margin:15px 30px 15px 0px; padding:15px 0px 0px 0px;" >
+      <caption>Détail compte </caption>
+      <thead resp-width="100%">
+        <tr>
+          <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="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)
+    {
+        $tbody = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillTable());
+        $f->appendChild($nel);
+        /* Update title from xml template */
+        $title = $this->getElementById($xml,"title");
+        $el    = $xml->createTextNode("compte ".$this->_model->_id);
+        $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>%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;
+    }
+
+}
+
+?>
index eea239b4f125bcaf428a0a540ac06a5e05a58bb8..e56945df0275baa73adb8b6f790e57a39ee36139 100644 (file)
@@ -128,20 +128,22 @@ _EOF;
         $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>
+<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   = sprintf("%.2f",$row[3]);
+            $credit  = sprintf("%.2f",$row[4]);
             $frag.=sprintf($template
                         ,++$count % 2?"odd":"even" ,$row[0],$row[1] ,$row[2]
-                        ,$row[3]
+                        ,$row[3] == 0.0 ? "" : $debit
                         ,$row[2] > $row[3] ? "red" : "black"
-                        ,$row[4]);
-       }
+                        ,$row[4] == 0.0? "" : $credit);
+        }
         return $frag;
     }
 
diff --git a/app/compta/views/account_index.php b/app/compta/views/account_index.php
new file mode 100644 (file)
index 0000000..ff6f755
--- /dev/null
@@ -0,0 +1,152 @@
+<?php
+
+namespace compta\views\account; 
+
+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%">Détail </h2>
+    <table id="tAccount" autoScroll='true' height="200" style="margin:15px 30px 15px 0px; padding:15px 0px 0px 0px;" >
+      <caption>Détail compte </caption>
+      <thead resp-width="100%">
+        <tr>
+          <th resp-width="20%">Catégorie</th>
+          <th resp-width="80%">Titre</th>
+        </tr>
+      </thead>
+      <tbody style="overflow:auto;">
+      </tbody>
+      <tfoot>
+        <tr><td id="accSoldeCompte" colspan="2">Selectionner la catégorie</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 Index 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)
+    {
+        $tbody = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillTable());
+        $f->appendChild($nel);
+        /* Update title from xml template */
+        //$title = $this->getElementById($xml,"title");
+        //$el    = $xml->createTextNode("compte ".$this->_model->_id);
+        //$title->appendChild($el);
+        // Update return link
+        $retour = $this->getElementById($xml,"btRetour");
+        $retour->removeAttribute('link');
+        $retour->setAttribute('link',"/app/compta/services.php/".\AEB::$REQUEST['b']);
+    }
+
+    /**
+     * @brief Fill bilan table
+     */
+    private function fillTable()
+    {
+        $template=<<<_EOF
+<tr class="%s"><td>%d</td><td><link href="/app/compta/services.php/account/categorie/%d?b=/account" >%s </link> </td>
+</tr>
+_EOF;
+        $frag    = "";
+        $count   = 0;
+        $lst     = [1,2,3,4,5,6,7,8];
+       $str     = [ "-"
+                  ,"DE CAPITAUX"
+                  , "IMMOBILISATIONS"
+                  , "D'IMMOBILISATIONS"
+                  , "DE TIERS"
+                  , "FINANCIERS"
+                  , "DE CHARGES"
+                  , "DE PROVISION"
+                  , "SPECIAUX"
+       ];
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template
+                   ,++$count % 2?"odd":"even" 
+                   ,$row
+                   ,$row
+                   ,$str[$row]
+                        );
+       }
+        return $frag;
+    }
+
+}
+
+?>
+
index e41cb4585e6c898c07adf17f88b2ef0e3722dfb5..586723dca5d7382aa70c7f4d4b23b8f7fcb8af74 100644 (file)
@@ -7,26 +7,44 @@ require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_exercice.php");
 require_once(dirname(__FILE__)."/../api_syndic.php");
 
-global $xmlAdminDocument;
-$XmlAdminDocument =  <<<XML
+const XmlAdminDocument =  <<<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>
+<title langue='fr'>Administrate Gestion comptable</title>
 <content>
+  <!--
   <script data-main="/app/compta/coproBootstrap.js" src="/js/require.js"></script>
+  -->
   <menu>
     <item id="btRetour" link="page_ledger.php" class="" title="Retour" />
   </menu>
 <!-- Start Main Panel-->
 
 <!-- -->
-    <panel class="" style="padding:0px 0px 0px 0px;display:block;min-height:150px;" id="mydocuments">
-    <h3>Chargement ...</h3>
-    </panel>
+    <panel class="" style="padding:0px 60px 15px 15px;display:block;min-height:150px;" id="mydocuments">
+    <h3>Aperçu de la configuration</h3>
+
+    <table id="tAdmin" 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>
+      <tfoot>
+<!--
+        <tr><td id="accSoldeCompte" colspan="2"></td>
+        </tr>
+-->
+      </tfoot>
+    </table>
 
+    </panel>
 <!-- End Main Panel -->
     <script></script>
   </content>
@@ -42,10 +60,10 @@ class Index extends \PageCompta
             implements \IActionResult 
 {
 
-    function __construct($b=true)
+    function __construct()
     {
-        global $xmlAdminDocument;
-        parent::__construct($XmlAdminDocument,$b);
+        parent::__construct(XmlAdminDocument,true);
+        //$this->_model = $model;
     }
 
     private function script()
@@ -64,36 +82,65 @@ _EOF;
     {
         $this->show();
     }
-    private function documents()
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        $tbody = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillAccounting());
+        // 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']);
+    }
+
+    private function fillAccounting()
     {
+        $frag = "";
+        $template=<<<_EOF
+<tr><td>%s</td><td>%s</td></tr>
+_EOF;
         $_cfg = $this->_auth_cfg;
         $syndic = new \Syndic( $this->getSession()
              , $_cfg
              , $this->getSession()->getDb());
         $accounting = $syndic->baseType();
-        echo "<table class='table' style='width:100%;margin-bottom:10px;'>";
-        echo "<thead>";
-        echo "<tr><th width='50%'>Description</th><th>Valeur</th></tr>";
-        echo "</thead>";
-        echo "<tr><td width='50%'>Type de compatbilite</td><td>".$accounting."</td></tr>";
-        $accounting = $syndic->baseVersion();
-        echo "<tr><td>Version</td><td>".$accounting."</td></tr>";
-        $accounting = $syndic->baseCounter();
-        echo "<tr><td>Compteur</td><td>".$accounting."</td></tr>";
-        echo "</table>";
-    }
+        $fields = ["Type de compatibilite","Version","Compteur"];
+        $fdata  = [$accounting, $syndic->baseVersion(),$syndic->baseCounter()];
 
+        for ($i = 0 ; $i < 3 ;$i++ )
+        {
+           $frag.=sprintf($template,$fields[$i],$fdata[$i]);
+        }
+        return $frag;
+    }
     /**
-     * @brief Display The articles in flex mode
-     * Also revise menu
+     * @brief display Database settings
      */
-    function main() {
-        $this->script();
-        echo '<div class="content" style="display:flex;flex-wrap:wrap">';
-        echo "<h3 style='width:100%;'>Aperçu de la configuration</h3>";
-        $this->documents();
-        echo '</div>';
+    private function fillDatabase()
+    {
+        $frag =<<<_EOF
+<tr class="odd"><td colspan="2" >Base de Donne</td> </tr>
+_EOF;
+        $template=<<<_EOF
+<tr><td>%s</td><td>%s</td></tr>
+_EOF;
+        $_cfg = $this->_auth_cfg;
+
+        $frag.=sprintf($template,"Server",$_cfg[SQL_SERVER]);
+        $frag.=sprintf($template,"Base de donnee",$_cfg[SQL_DB]);
+        $frag.=sprintf($template,"Utilisateur",$_cfg[SQL_USER]);
+        return $frag;
+
     }
+
 }
 
 
diff --git a/app/compta/views/bilan_charges.php b/app/compta/views/bilan_charges.php
new file mode 100644 (file)
index 0000000..6173536
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+namespace compta\views\bilan; 
+require_once(dirname(__FILE__)."/../pages.php");
+require_once(dirname(__FILE__)."/../api_pcmn.php");
+
+global $XmlComptaBudget;
+$XmlComptaBudget =  <<<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>
+    function download_() {
+            window.open("/app/compta/reports/syndic_builder_annexe.php?period="+gState.Exercice);
+    }
+  </script>
+<!--
+  <script data-main="/app/compta/bilanBootstrap.js" src="/js/require.js"></script>
+-->
+
+<menu>
+  <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
+</menu>
+
+  <panel id="pBilan" class="col-10 offset-1" style="min-height:150px;padding:15px 0 15px 0px;">
+  <h3>Bilan des charges </h3>
+  <table id="bilan" resp-width="100%" style="margin:10px 0px 0px 0px;padding:15px 0px 0px 0px;" >
+      <caption>Bilan de L'exercice</caption>
+      <thead>
+        <tr>
+          <th resp-width="15%">Compte</th>
+          <th resp-width="75%">Libelle</th>
+          <th resp-width="10%">Solde</th></tr>
+      </thead>
+      <tbody>
+          <!-- <tr><td>10</td><td>Immoblisation</td><td>0</td><td>0</td><td>0</td></tr> -->
+      </tbody>
+  </table>
+  </panel>
+  <div class="clearfix"></div>
+    <!-- Script Section -->
+  </content>
+</gui>
+XML;
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class Charges extends \PageCompta
+       implements \IActionResult 
+{
+
+  function __construct($model)
+  {
+        //$page = new PageBilan($XmlComptaBudget,true);
+        global $XmlComptaBudget;
+       parent::__construct($XmlComptaBudget,true);
+       $this->_model = $model;
+  }
+
+  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)
+    {
+        $tbody = $xml->getElementsByTagName('tbody');
+        $f       = $tbody->item(0);
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillTable());
+        $f->appendChild($nel);
+    }
+    /**
+     * @brief Fill bilan table
+     */
+    private function fillTable()
+    {
+           $template=<<<_EOF
+<tr class="%s"><td>%s</td>
+<td><link href="/app/compta/services.php/account/detail/%s?b=/bilan/charges"> %s</link> </td>
+<td style="text-align:right;color:%s">%.2f</td></tr>
+_EOF;
+$frag    = "";
+        $lst = $this->_model->syntheseCharges();
+        $count = 0;
+        foreach( $lst as $row)
+        {
+            $frag.=sprintf($template,++$count % 2?"odd":"even"
+                            ,$row[0]
+                            ,$row[0]
+                            ,str_repeat("-",$row[3])." ".$row[1]
+                            , "red"
+                            ,$row[2]);
+        }
+        return $frag;
+    }
+
+}
+
index 5ca86ff19563defc1d358d0811bd77e5b2cbf990..646ca673a75d2f82e04cddb8b836ba51640f0035 100644 (file)
@@ -25,6 +25,7 @@ $XmlComptaBudget =  <<<XML
 
 <menu>
   <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
+  <item id="btCharges" link="/app/compta/services.php/bilan/charges?b=/bilan" class="" title="Charges" />
 </menu>
 
   <panel id="pBilan" class="col-10 offset-1" style="min-height:150px;padding:15px 0 15px 0px;">
@@ -126,7 +127,8 @@ _EOF;
     private function fillTable()
     {
            $template=<<<_EOF
-<tr class="%s"><td>%s</td><td>%s</td>
+<tr class="%s"><td>%s</td>
+<td><link href="/app/compta/services.php/account/detail/%s?b=/bilan"> %s</link> </td>
 <td style="text-align:right">%.2f</td>
 <td style="text-align:right">%.2f</td>
 <td style="text-align:right;color:%s">%.2f</td></tr>
@@ -135,18 +137,21 @@ $frag    = "";
         $_cfg = $this->_auth_cfg;
         $pcmn = new \Pcmn( $this->getSession()
                  , $_cfg
-         , $this->getSession()->getDb());
-       $lst = $pcmn->getBilan(
-               $this->getSession()->getCurrentExercice()
+                 , $this->getSession()->getDb());
+        $lst = $pcmn->getBilan(
+        $this->getSession()->getCurrentExercice()
        );
-       $count = 0;
+        $count = 0;
         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]);
+            $frag.=sprintf($template,++$count % 2?"odd":"even"
+                            ,$row[0]
+                            ,$row[0]
+                            ,$row[1]
+                            ,$row[2]
+                            ,$row[3]
+                            ,$row[2] > $row[3] ? "red" : "black"
+                            ,$row[4]);
         }
         return $frag;
     }
index de9252984430694c2fede02a06bf922b5218f08f..e46bbff141d597b8d46427da66b7bca04cab2bcd 100644 (file)
@@ -3,8 +3,7 @@ namespace compta\views\budget;
 require_once(dirname(__FILE__)."/../pages.php");
 require_once(dirname(__FILE__)."/../api_pcmn.php");
 
-global $XmlComptaBudget;
-$XmlComptaBudget =  <<<XML
+const XmlComptaBudgetDetail =<<<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/'"?>
@@ -14,67 +13,29 @@ $XmlComptaBudget =  <<<XML
 <content>
   <script>
 /* 
-  AEBW.require('xgui_dialogbox');
-  try {
-    AEBW.require('xgui_wizard');
-    AEBW.require('xgui_json');
-  } catch (e) {
-    alert("Failed Load File");
-  }
 */
   </script>
-  <script data-main="/app/compta/budgetBootstrap.js" src="/js/require.js"></script>
 
 
 <menu>
-<item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
-<item id="btBudget" link="#" class="" title="Liste" />
-<item id="btBudgetNew" link="#" class="" title="Nouveau" />
+<item id="btRetour" link="/app/compta/services.php/budget/list" class="" title="Retour" />
+<item id="btResume" link="/app/compta/services.php/budget/detail" class="" title="Résumé" />
 </menu>
-<panel>
-  <panel id="budget" style='width:100%;height:500px;float:left;border:1px;'>
-    <group id='group-budget' >
-      <grouptitle>Nouveau</grouptitle>
-      <groupcontent>
-        <FieldSet  labelWidth="100" style="border:none 0px;">
-          <TextField class="col-md-9" id="budget_anne" style="margin-right:10px;"><Label class="col-md-5" style="">Année:</Label></TextField>
-          <TextField id="budget_desc" class="col-md-9"><Label class="col-md-6">Désignation:</Label></TextField>
-        </FieldSet>
-
-      <panel style="height:14px;">
-<div style="float:left;width:100%;height:14px;"/>
-<button id='btBuApply' href="#" style="float:left;width:80px;">Nouveau</button>
-<button id='btBuCancel' style="float:left;width:80px;" href="#">Annuler</button>
-</panel>
-</groupcontent>
-</group>
-<panel id="panel-budgets" >
-<table id="table_budgets" autoScroll="yes" height="280" resp-width="95%" style="margin-left:10px;">
-<thead>
-  <tr>
-    <th resp-width='5%'></th>
-    <th resp-width="15%">Année</th>
-    <th resp-width="80%">Libellé</th>
-      </tr>
-    </thead>
-    <tbody>
-       <tr></tr>
-    </tbody>
-    <tfoot>
-    </tfoot>
-  </table>
-
+<panel class="" style="padding: 10px 15px 10px 15px;">
+  <panel id="budget" style='width:100%;min-height:300px;float:left;border:1px;'>
+    <h3>Détail des comptes pour le Budget</h3>
+    <panel id="panel-budgets" >
 <!-- -->
 
           <!-- Add The table with the exinting Losts -->
-          <table id="table_budget_edit" height="250" autoScroll="true" style="display:none;margin-left:10px;">
+          <table id="table_budget_edit" height="250" width="100%" autoScroll="true" style="margin:10px 0px 30px 0px;">
             <thead>
               <tr>
-                <th width="50"></th>
-                <th width="90">Compte</th>
-                <th width="290">Libellé</th>
-                <th width="90">N-1</th>
-                <th width="90">N</th></tr>
+                <th resp-width="10%"></th>
+                <th resp-width="20%">Compte</th>
+                <th resp-width="50%">Libellé</th>
+                <th resp-width="10%">N-1</th>
+                <th resp-width="10%">N</th></tr>
          </thead>
          <tbody >
              <tr></tr>
@@ -82,11 +43,12 @@ $XmlComptaBudget =  <<<XML
          <tfoot>
              <!--
              -->
-             <tr><td colspan="3">Total:</td><td style="text-align:right;" id="beTotalN1">0.0</td><td style="text-align:right;" id="beTotalN">0.0</td></tr>
+             <tr><td colspan="3">Total:</td><td style="text-align:right;" id="beTotalN1">0.0</td><td style="text-align:right;" id="beTotalN"></td></tr>
          </tfoot>
     </table>
-</panel>
-</panel>
+
+    </panel>
+  </panel>
 </panel>
 <!--
 -->
@@ -103,13 +65,14 @@ $_default_file = "ledger_syndic.xml";
  * documents available. All decomptes
  */
 class Detail extends \PageCompta
-       implements \IActionResult 
+            implements \IActionResult 
 {
+    private $total = 0.0;
 
-    function __construct($b = true)
+    function __construct($model)
     {
-        global $XmlComptaBudget;
-        parent::__construct($XmlComptaBudget,$b);
+        $this->_model = $model;
+        parent::__construct(XmlComptaBudgetDetail,true);
     }
 
     public function render()
@@ -117,6 +80,85 @@ class Detail extends \PageCompta
         $this->show();
     }
 
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        // Update the title
+        $tbody   = $xml->getElementsByTagName("tbody");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillBudgetEntries());
+        $tbody->item(0)->appendChild($nel);
+        // Update total as well
+        $total = $this->getElementById($xml,"beTotalN");
+        $el    = $xml->createTextNode(" ".$this->total);
+        $total->appendChild($el);
+        // Update Menu
+        $this->updateMenu($xml);
+    }
+
+    private function updateMenu(&$xml)
+    {
+        $str    = "";
+        $ids    = Array('btBCharge','btBProduit','btBCapitaux');
+        $labels = Array('Charges','Produit','Capitaux');
+        $cat    = Array(6,7,1);
+        $tplt   =<<<_EOF
+<item id="%s" link="/app/compta/services.php/budget/%s/%s" class="" title="%s" />
+_EOF;
+        $items  =<<<_EOF
+<item id="btResume" link="/app/compta/services.php/budget/detail" class="" title="Résumé" />
+_EOF;
+        $menu   = $xml->getElementsByTagName("menu");
+        $frag   = $xml->createDocumentFragment();
+        for( $i = 0 ; $i < 3 ; ++$i)
+        {
+            $str.=sprintf($tplt
+                ,$ids[$i]
+                ,$this->_model->current_budget_id
+                ,$cat[$i]
+                ,$labels[$i]
+            );
+        }
+        $frag->appendXML($str);
+        $menu->item(0)->appendChild($frag);
+    }
+
+    private function fillBudgetEntries()
+    {
+        $count = 0;
+        $total = 0.0;
+        $ret   = "";
+        $tplt  =<<<_EOF
+<tr class="%s">
+  <td>%s</td>
+  <td><link href="/app/compta/services.php/budget/detail/%s">%s</link></td>
+  <td><link href="/app/compta/services.php/budget/updateEntry/%s/%s">%s</link></td>
+  <td>%s</td>
+  <td style="text-align:right;">%s</td>
+</tr>
+_EOF;
+        $entries = $this->_model->getBudgetEntries($this->_model->current_budget_id,"6");
+        foreach ($entries as $e)
+        {
+            $ret.=sprintf($tplt
+                ,++$count % 2?"odd":"even" 
+                ,""
+                ,$e[0] // Compte
+                ,$e[0]
+                ,$this->_model->current_budget_id // Libelle bu_id 
+                ,$e[0] // Libelle account
+                ,$e[1] // Libelle message
+                ,$e[6] // N - 1
+                ,$e[2] // N
+            );
+            $total += $e[2];
+        }
+        $this->total = $total;
+        return $ret;
+    }
+
 }
 
 /**
index e48a5593eb0aa0e934fe8c3b3bee3dc9cdad3af6..565cc87f59921de408a50530b03209f7b7aae488 100644 (file)
@@ -19,7 +19,7 @@ $XmlComptaBudget =  <<<XML
 
 <menu>
 <item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
-<item id="btBudget" link="/app/compta/services.php/budget/" class="" title="Liste" />
+<item id="btBudget" link="/app/compta/services.php/budget/list" class="" title="Liste" />
 <item id="btBudgetNew" link="/app/compta/services.php/budget/nouveau" class="" title="Nouveau" />
 </menu>
 <panel>
diff --git a/app/compta/views/budget_list.php b/app/compta/views/budget_list.php
new file mode 100644 (file)
index 0000000..171a8f1
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+namespace compta\views\budget; 
+require_once(dirname(__FILE__)."/../pages.php");
+require_once(dirname(__FILE__)."/../api_pcmn.php");
+
+const XmlComptaBudgetList =<<<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>
+
+<menu>
+<item id="btRetour" link="/app/compta/services.php/" class="" title="Retour" />
+<item id="btBudget" link="/app/compta/services.php/budget/list" class="" title="Liste" />
+<item id="btBudgetNew" link="/app/compta/services.php/budget/nouveau" class="" title="Nouveau" />
+</menu>
+<panel>
+  <panel id="budget" style='width:100%;height:500px;float:left;border:1px;'>
+
+  <panel id="panel-budgets" >
+    <table id="table_budgets" autoScroll="yes" height="280" resp-width="95%" style="margin-left:10px;">
+      <thead>
+        <tr>
+          <th resp-width="10%">Année</th>
+          <th resp-width="80%">Libellé</th>
+          <th resp-width='10%'>Montant</th>
+        </tr>
+      </thead>
+      <tbody>
+      </tbody>
+      <tfoot>
+      </tfoot>
+    </table>
+
+<!-- -->
+
+</panel>
+</panel>
+</panel>
+<!--
+-->
+<script>
+</script>
+</content>
+</gui>
+XML;
+
+
+$_default_file = "ledger_syndic.xml";
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class BList extends \PageCompta
+       implements \IActionResult 
+{
+
+    function __construct($model)
+    {
+        parent::__construct(XmlComptaBudgetList,true);
+        $this->_model = $model;
+    }
+
+    public function render()
+    {
+        $this->show();
+    }
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        // Update the title
+        $tbody   = $xml->getElementsByTagName("tbody");
+        $nel     = $xml->createDocumentFragment();
+        $nel->appendXML($this->fillBudgets());
+        $tbody->item(0)->appendChild($nel);
+    }
+
+    /**
+     * @brief complete the table with all available budgets
+     */
+    private function fillBudgets()
+    {
+        $count=0;
+        $ret  = "";
+        $tplt =<<<_EOF
+<tr class="%s">
+  <td>%s</td><td><link href="/app/compta/services.php/budget/detail/%s">%s</link></td>
+  <td style="text-align:right;">%s</td>
+</tr>
+_EOF;
+        $budgets = $this->_model->getBudgets();
+        foreach ($budgets as $budget)
+        {
+            $ret.=sprintf($tplt
+                ,++$count % 2?"odd":"even" 
+                ,$budget[1]
+                ,$budget[0]
+                ,$budget[2]
+                ,$budget[3]
+            );
+        }
+        return $ret;
+    }
+
+}
+
+/**
+ * Should I make the checks here ? I wonder 
+ * if this is required
+ */
+
+?>
diff --git a/app/compta/views/budget_updateEntry.php b/app/compta/views/budget_updateEntry.php
new file mode 100644 (file)
index 0000000..5d8f99f
--- /dev/null
@@ -0,0 +1,168 @@
+<?php
+namespace compta\views\budget; 
+require_once(dirname(__FILE__)."/../pages.php");
+require_once(dirname(__FILE__)."/../api_pcmn.php");
+
+const XmlComptaBudgetUpdateEntry =<<<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>
+
+
+<menu>
+<item id="btRetour" link="/app/compta/services.php/budget/list" class="" title="Retour" />
+<item id="btResume" link="/app/compta/services.php/budget/detail" class="" title="Résumé" />
+</menu>
+<!--
+  <panel id="pBilan" class="col-10 offset-1" style="min-height:150px;padding:15px 0 15px 0px;">
+-->
+<panel class="" style="padding: 10px 15px 30px 15px;">
+  <panel id="budget" style='width:100%;min-height:300px;float:left;border:1px;margin: 0px 15px 30px 15px;'>
+    <h3>Détail des comptes pour le Budget</h3>
+
+    <group id="group"> 
+      <grouptitle>Mettre à jour l'entrée du budget</grouptitle>
+      <groupcontent>
+        <form method="post" action="/app/compta/services.php/budget/updateEntryPost">
+          <FieldSet labelWidth="130" style="border:none 0px;">
+              <TextField width="243" id="be_acc_id" asp-for="entry.acc_id" style=""><Label style="">Compte</Label></TextField><br/>
+              <ComboBox width="249" id="be_pc" asp-for="entry.pc"  style="margin-right:15px;"><Label>Poste Charge</Label>
+                  <Entry key="512001-Banque postale" value="1"></Entry>
+                  <Entry key="512001- Chauffe" value="4"></Entry>
+                  <Entry key="512001- Eay" value="5"></Entry>
+              </ComboBox><br/>
+            <TextField width="243" id="be_amount" asp-for="entry.amount" style=""><Label style=""> Montant</Label></TextField>
+            <TextField type="hidden" id="be_budget_id" asp-for="entry.budget_id" style=""></TextField>
+            <TextField type="hidden" id="be_entry_id" asp-for="entry.entry_id" style=""></TextField>
+          </FieldSet>
+          <panel class="col-md-10 col-sm-12" style="min-height:14px;">
+            <button id='btBERecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+            <button id='btBECancel' style="float:left;" href="">Annuler</button>
+          <!--
+          -->
+          </panel>
+        </form>
+      </groupcontent>
+    </group>
+
+  </panel>
+</panel>
+<!--
+-->
+<script>
+</script>
+</content>
+</gui>
+XML;
+
+
+$_default_file = "ledger_syndic.xml";
+/**
+ * @brief Update GUI with the list of 
+ * documents available. All decomptes
+ */
+class UpdateEntry extends \PageCompta
+            implements \IActionResult 
+{
+    private $total = 0.0;
+
+    function __construct($model)
+    {
+        $this->_model = $model;
+        parent::__construct(XmlComptaBudgetUpdateEntry,true);
+    }
+
+    public function render()
+    {
+        $this->show();
+    }
+
+    /**
+     * @brief allow sub classes to modify xml file
+     */
+    protected function _updateXML(&$xml)
+    {
+        // Update the title
+        // Update total as well
+        // Update Menu
+        //$this->updateMenu($xml);
+        $this->updateAspfor($xml,$this->_model);
+    }
+
+    private function updateMenu(&$xml)
+    {
+        $str    = "";
+        $ids    = Array('btBCharge','btBProduit','btBCapitaux');
+        $labels = Array('Charges','Produit','Capitaux');
+        $cat    = Array(6,7,1);
+        $tplt   =<<<_EOF
+<item id="%s" link="/app/compta/services.php/budget/%s/%s" class="" title="%s" />
+_EOF;
+        $items  =<<<_EOF
+<item id="btResume" link="/app/compta/services.php/budget/detail" class="" title="Résumé" />
+_EOF;
+        $menu   = $xml->getElementsByTagName("menu");
+        $frag   = $xml->createDocumentFragment();
+        for( $i = 0 ; $i < 3 ; ++$i)
+        {
+            $str.=sprintf($tplt
+                ,$ids[$i]
+                ,$this->_model->current_budget_id
+                ,$cat[$i]
+                ,$labels[$i]
+            );
+        }
+        $frag->appendXML($str);
+        $menu->item(0)->appendChild($frag);
+    }
+
+    private function fillBudgetEntries()
+    {
+        $count = 0;
+        $total = 0.0;
+        $ret   = "";
+        $tplt  =<<<_EOF
+<tr class="%s">
+  <td>%s</td>
+  <td><link href="/app/compta/services.php/budget/detail/%s">%s</link></td>
+  <td><link href="/app/compta/services.php/budget/updateEntry/%s/%s">%s</link></td>
+  <td>%s</td>
+  <td style="text-align:right;">%s</td>
+</tr>
+_EOF;
+        $entries = $this->_model->getBudgetEntries($this->_model->current_budget_id,"6");
+        foreach ($entries as $e)
+        {
+            $ret.=sprintf($tplt
+                ,++$count % 2?"odd":"even" 
+                ,""
+                ,$e[0] // Compte
+                ,$e[0]
+                ,$this->_model->current_budget_id // Libelle bu_id 
+                ,$e[0] // Libelle account
+                ,$e[1] // Libelle message
+                ,$e[4] // N - 1
+                ,$e[2] // N
+            );
+            $total += $e[2];
+        }
+        $this->total = $total;
+        return $ret;
+    }
+
+}
+
+/**
+ * Should I make the checks here ? I wonder 
+ * if this is required
+ */
+
+?>
index 738f6970bc1305b228f830d4507b3ae41e3a3288..c3181aca95bbad6a1ca382b976c7e1cc9f041f10 100644 (file)
@@ -181,6 +181,7 @@ _EOF;
                     $fe.=sprintf($tplt,"text",$count,$f,$e->{$f});
             }
         $fe.="</tr>";
+        error_log($fe."\n");
         $frag.=$fe;
         $count++;
         }
index 00bb97f3a2811f3f2832129343786c563a8c688d..6fc7a1d15a19412d9df8343d1468cc8e2ad170db 100644 (file)
@@ -95,9 +95,11 @@ class Account extends \PageCompta
         $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="btFacturePay" link="/app/compta/services.php/supplier/billpay/%s" fa-icon="fa-coins" title="Facture  Payer" />
   <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
                      ,$this->_model->_id);
         $nel     = $xml->createDocumentFragment();
index 0cf448f73867c33e0254c0520df4ac84b6a79e24..6a15e026c6e2a9f5442a8186a74d5e5ced1b6d37 100644 (file)
@@ -31,10 +31,10 @@ const SupplierBill =<<<XML
           <group id="group"> 
 <grouptitle>Nouvelle Facture</grouptitle>
 <groupcontent>
-<form method="post" action="/app/compta/services.php/supplier/billPost">
+<form method="post" action="/app/compta/services.php/supplier/billPayPost">
           <FieldSet labelWidth="95" style="border:none 0px;">
              <TextField width="253" id="suppl_desc" asp-for="suppl_desc" style="margin-right:15px;"><Label style="">Intitule</Label></TextField>
-              <ComboBox width="199" id="suppl_bank"    asp-for="suppl_bank" style="margin-right:15px;"><Label>Banque</Label>
+              <ComboBox width="199" id="suppl_banque"    asp-for="suppl_banque" style="margin-right:15px;"><Label>Banque</Label>
               </ComboBox> 
 <br/>
               <ComboBox width="259" id="suppl_id"    asp-for="_id" style="margin-right:15px;"><Label>Fournisseur</Label>
@@ -52,8 +52,8 @@ const SupplierBill =<<<XML
           <panel resp-width="98%" style="min-height:14px;">
               <!-- 
                -->
-            <button id='btFFRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
-            <button id='btFFCancel' href="#" style="float:left;">Annuler</button>
+            <button id='btFFPRecord' type="submit" style="float:left;margin-right: 15px;">Enregistrer</button>
+            <button id='btFFPCancel' href="#" style="float:left;">Annuler</button>
           </panel>
         </form>
       </groupcontent>
@@ -95,7 +95,7 @@ class Billpay extends \PageCompta
         $nel->appendXML($this->fillKeys());
         $tbody->appendChild($nel);
         // Ok Handle bank
-        $solde = $this->getElementById($xml,"suppl_bank");
+        $solde = $this->getElementById($xml,"suppl_banque");
         $nel     = $xml->createDocumentFragment();
         $nel->appendXML($this->fillBanque());
         $solde->appendChild($nel);
diff --git a/app/xsl b/app/xsl
index b1016666f5fd4264ce632b3e00126819a0f02084..84bbba5f0d444985b1b467a8677f370bc27e6927 160000 (submodule)
--- a/app/xsl
+++ b/app/xsl
@@ -1 +1 @@
-Subproject commit b1016666f5fd4264ce632b3e00126819a0f02084
+Subproject commit 84bbba5f0d444985b1b467a8677f370bc27e6927
diff --git a/css b/css
index 83819fb21391da8cfbfeba2fe8d16f654f554ffd..61a97d1412591363baddfbbc591825765c79c4eb 160000 (submodule)
--- a/css
+++ b/css
@@ -1 +1 @@
-Subproject commit 83819fb21391da8cfbfeba2fe8d16f654f554ffd
+Subproject commit 61a97d1412591363baddfbbc591825765c79c4eb