Update JoinIdentityAccount to support multiple accounts per user master
authorwww-data <www-data@n3150.home>
Sat, 30 Dec 2023 21:28:19 +0000 (22:28 +0100)
committerwww-data <www-data@n3150.home>
Sat, 30 Dec 2023 21:28:19 +0000 (22:28 +0100)
app/compta/api_syndic.php
app/compta/reports/syndic_annexe_data.php
app/compta/reports/syndic_compte.php
app/compta/schema_mysql.php

index 36c46ecbdfd6cbe28e9f37f511222a5143c876fc..36a25c427e3207527344c34a203c26269dc5eb21 100644 (file)
@@ -215,7 +215,7 @@ SELECT ident_id,ident_name,ident_firstname,ident_address,`ident_postalcode`
       , ident_mobile, ident_email1
       , case when joa.jia_acc != 'NULL' then joa.jia_acc else 0 end as compte
 FROM Owners as o
       , ident_mobile, ident_email1
       , case when joa.jia_acc != 'NULL' then joa.jia_acc else 0 end as compte
 FROM Owners as o
-LEFT JOIN JoinIdentityAccount as joa on joa.jia_ident = o.ident_id where o.ident_id = {$this->session->id()};
+LEFT JOIN JoinIdentityAccount as joa on joa.jia_ident = o.ident_id and joa.jia_actu = 1 where o.ident_id = {$this->session->id()};
 __EOF;
       } else {
         //error_log("Syndic::getCorproprietaires syndic ".$_uid);
 __EOF;
       } else {
         //error_log("Syndic::getCorproprietaires syndic ".$_uid);
@@ -228,7 +228,7 @@ SELECT ident_id, ident_name, ident_firstname, ident_address, `ident_postalcode`
       , ident_mobile, ident_email1
       , case when joa.jia_acc != 'NULL' then joa.jia_acc else 0 end as compte
 FROM Owners as o
       , ident_mobile, ident_email1
       , case when joa.jia_acc != 'NULL' then joa.jia_acc else 0 end as compte
 FROM Owners as o
-LEFT JOIN JoinIdentityAccount as joa on joa.jia_ident = o.ident_id where o.ident_id = {$_uid};
+LEFT JOIN JoinIdentityAccount as joa on joa.jia_ident = o.ident_id and joa.jia_actu = 1 where o.ident_id = {$_uid};
 __EOF;
         } else {
           $q =<<<__EOF
 __EOF;
         } else {
           $q =<<<__EOF
@@ -237,7 +237,7 @@ SELECT ident_id, ident_name, ident_firstname, ident_address, ident_postalcode
       , ident_mobile, ident_email1
       , case when joa.jia_acc != 'NULL' then joa.jia_acc else 0 end as compte
 FROM   Owners as o
       , ident_mobile, ident_email1
       , case when joa.jia_acc != 'NULL' then joa.jia_acc else 0 end as compte
 FROM   Owners as o
-LEFT JOIN JoinIdentityAccount as joa on joa.jia_ident = o.ident_id;
+LEFT JOIN JoinIdentityAccount as joa on joa.jia_ident = o.ident_id and joa.jia_actu = 1;
 __EOF;
         }
       }
 __EOF;
         }
       }
index c58e262cbc314d8d7dc1e156d0c939b345948b5c..e396f11a2c27285d63b4cf23742dbeb7a709d323 100644 (file)
@@ -247,10 +247,36 @@ EOF;
      *
      */
     function getUserIdFromAccount($account) {
      *
      */
     function getUserIdFromAccount($account) {
-       $q      = "select jia_ident from JoinIdentityAccount WHERE jia_acc = ".$account.";";
-       $res    = $this->doQueryImpr($q);
+       $q    = "select jia_ident from JoinIdentityAccount WHERE jia_acc = ".$account.";";
+       $res  = $this->doQueryI($q);
+       error_log("For ".$account." Got= ".$res['records'][0][0]." ");
        return   $res['records'][0][0];
     }
        return   $res['records'][0][0];
     }
+
+    /**
+     * \brief get the accounts except the CHRG account.
+     */
+    public function getAvances($period,$account,&$total)
+    {
+        $uid  = $this->getUserIdFromAccount($account);
+        $q =<<<_EOF
+SELECT jia_acc,act.actu_abrevation,act.actu_title from JoinIdentityAccount
+ JOIN AccountTypeUser as act on jia_actu = act.actu_id 
+WHERE jia_ident = {$uid} AND jia_acc != "{$account}";
+_EOF;
+        $res   = $this->doQueryI($q);
+        // Put account list in an array
+        $result = Array();
+        foreach ($res['records'] as $entry)
+        {
+           $compte = $entry[0];
+           $q = "call solde_compte_where('".$period."','t.acc_id like \"".$compte."%\"');";
+           $res = $this->doQueryI($q);
+           $result[$compte] = array($entry[1],$entry[2],$res['records'][0][2]);
+           $total += ($result[$compte][2]);
+        }
+        return $result;
+    }
     /**
      *
      */
     /**
      *
      */
index db14d2db4c6fa3bacc230d04562f4b878311f1bf..f99fbb01996782f9c6d0be241bc894a3966a6452 100644 (file)
@@ -252,10 +252,12 @@ _EOF;
             // Exercice Clos
             if ($exercice[1] == 0) {
                   $this->Detail($period,$compte);
             // Exercice Clos
             if ($exercice[1] == 0) {
                   $this->Detail($period,$compte);
+                  $this->Avances($period,$compte);
             } else {
                 $pdf->Cell(50,5,"Exercice Clos.");
                 $pdf->Ln();
                 $this->Detail($period,$compte);
             } else {
                 $pdf->Cell(50,5,"Exercice Clos.");
                 $pdf->Ln();
                 $this->Detail($period,$compte);
+                $this->Avances($period,$compte);
             }
         } catch (Exception $e) {
             $pdf->Cell(50,5,"Failed :".$e->getMessage());
             }
         } catch (Exception $e) {
             $pdf->Cell(50,5,"Failed :".$e->getMessage());
@@ -302,19 +304,40 @@ _EOF;
 _EOF;
         $pdf->writeHTMLCell($w=0, $h=0, $x='', $y= '', $tcharge, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);
        
 _EOF;
         $pdf->writeHTMLCell($w=0, $h=0, $x='', $y= '', $tcharge, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);
        
-        //$this->Titre("Total appels de fonds ".$result['total_appel']." €");
-        $this->Titre("Vos avances");
+       //$this->Titre("Total appels de fonds ".$result['total_appel']." €");
+    }
+    /**
+     * \brief compute avance for user
+     */
+    private function Avances($period,$compte) {
+       $fragment =<<<_EOF
+<tr><td class="title">%s</td><td class="result">%.2f €</td></tr>
+_EOF;
+        $pdf = $this->pdf;
+        $total = 0.0;
+       error_log("Before enter getAvances");
+        $avances= $this->data->getAvances($period,$compte,$total);
+       $this->Titre("Vos avances");
+       $avance_str="";
+       foreach($avances as $entry)
+       {
+            $avance_str.=sprintf($fragment,$entry[1],$entry[2]);
+       }
+       error_log("".$avance_str);
         $avance =<<<_EOF
 <style>
 .title {width:212px;}
 .result { width:100px;text-align:right;}
 </style>            
 <table>
         $avance =<<<_EOF
 <style>
 .title {width:212px;}
 .result { width:100px;text-align:right;}
 </style>            
 <table>
+<!--
 <tr><td class="title">Avance de trésorerie</td><td class="result">0.00 €</td></tr>
 <tr><td class="title">Avance de travaux art 14.2</td><td class="result">0.00 €</td></tr>
 <tr><td class="title">Avance fond de travaux</td><td class="result">0.00 €</td></tr>
 <tr><td class="title">Avance de trésorerie</td><td class="result">0.00 €</td></tr>
 <tr><td class="title">Avance de travaux art 14.2</td><td class="result">0.00 €</td></tr>
 <tr><td class="title">Avance fond de travaux</td><td class="result">0.00 €</td></tr>
+-->
+{$avance_str}
 <tr>
 <tr>
-<td style="width:212px;"><b>Total avance</b></td><td style="width:100px;text-align:right;"><b>0.0 €</b></td></tr>
+<td style="width:212px;"><b>Total avance</b></td><td style="width:100px;text-align:right;"><b>{$total} €</b></td></tr>
 </table>
 <br/>
 _EOF;
 </table>
 <br/>
 _EOF;
index 8f3182f669cf9fe06d56d01e1004f9e3cefa1f38..1639f2746afab62a9702ebc281e6a35014938ed5 100644 (file)
@@ -697,7 +697,7 @@ END;
         END IF;
           IF tant &gt; 0  THEN
         INSERT INTO TransactionEntry (trans_id,entry_type,entry_date,voucher_ref,acc_id,amount,debit_credit,description) VALUES 
         END IF;
           IF tant &gt; 0  THEN
         INSERT INTO TransactionEntry (trans_id,entry_type,entry_date,voucher_ref,acc_id,amount,debit_credit,description) VALUES 
-           (@last_id,"OD",ed,vouch,a,am*tant,'c',des);
+           (@last_id,"OD",ed,vouch,a,ROUND(am*tant),'c',des);
           END IF;
         END LOOP;
 
           END IF;
         END LOOP;