From 09ecfdc42801964425c4f7a8ffeeb4edf0c40cc1 Mon Sep 17 00:00:00 2001 From: www-data Date: Sat, 30 Dec 2023 22:28:19 +0100 Subject: [PATCH] Update JoinIdentityAccount to support multiple accounts per user --- app/compta/api_syndic.php | 6 ++--- app/compta/reports/syndic_annexe_data.php | 30 +++++++++++++++++++++-- app/compta/reports/syndic_compte.php | 29 +++++++++++++++++++--- app/compta/schema_mysql.php | 2 +- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/compta/api_syndic.php b/app/compta/api_syndic.php index 36c46ec..36a25c4 100644 --- a/app/compta/api_syndic.php +++ b/app/compta/api_syndic.php @@ -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 -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); @@ -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 -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 @@ -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 -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; } } diff --git a/app/compta/reports/syndic_annexe_data.php b/app/compta/reports/syndic_annexe_data.php index c58e262..e396f11 100644 --- a/app/compta/reports/syndic_annexe_data.php +++ b/app/compta/reports/syndic_annexe_data.php @@ -247,10 +247,36 @@ EOF; * */ 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]; } + + /** + * \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; + } /** * */ diff --git a/app/compta/reports/syndic_compte.php b/app/compta/reports/syndic_compte.php index db14d2d..f99fbb0 100644 --- a/app/compta/reports/syndic_compte.php +++ b/app/compta/reports/syndic_compte.php @@ -252,10 +252,12 @@ _EOF; // 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); + $this->Avances($period,$compte); } } 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); - //$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 +%s%.2f € +_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 + +{$avance_str} - +
Total avance0.0 €
Total avance{$total} €

_EOF; diff --git a/app/compta/schema_mysql.php b/app/compta/schema_mysql.php index 8f3182f..1639f27 100644 --- a/app/compta/schema_mysql.php +++ b/app/compta/schema_mysql.php @@ -697,7 +697,7 @@ END; END IF; IF tant > 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; -- 2.30.2