31, 2=>28+date('L'), 3=>31, 4=>30, 5=>31, 6=>30, 7=>31, 8=>31, 9=>30, 10=>31, 11=>30, 12=>31); $fin_mois = mktime(23, 59, 59, $num_mois, $dernier_jour[$num_mois], $annee); $bornes = array($debut_mois, $fin_mois); return $bornes; } //Return what A must pay to B function dettes($A, $B, $debut_mois, $fin_mois) { global $bdd; //When A paid and B was here $reqA_B = $bdd->prepare('SELECT id, date, montant, copains, invites FROM depenses WHERE date>'.$debut_mois.' AND date<'.$fin_mois.' AND de=:param1 AND (copains LIKE "%,'.(int) $B.',%" OR copains LIKE "%,'.(int)$B.'" OR copains LIKE "'.(int) $B.',%" OR copains LIKE "'.(int) $B.'")'); $reqA_B->bindvalue(':param1',$A); $reqA_B->execute(); //When B paid and A was here $reqB_A = $bdd->prepare('SELECT id, date, montant, copains, invites FROM depenses WHERE date>'.$debut_mois.' AND date<'.$fin_mois.' AND de=:param1 AND (copains LIKE "%,'.(int) $A.',%" OR copains LIKE "%,'.(int)$A.'" OR copains LIKE "'.(int) $A.',%" OR copains LIKE "'.(int) $A.'")'); $reqB_A->bindvalue(':param1',$B); $reqB_A->execute(); //What A already paid to B for the current month $reqPaiementsA_B = $bdd -> prepare('SELECT paiements.montant AS montant FROM paiements LEFT JOIN depenses ON paiements.id_depense=depenses.id WHERE depenses.date >'.$debut_mois.' AND depenses.date<'.$fin_mois.' AND paiements.de=:de AND paiements.a=:a'); $reqPaiementsA_B->bindvalue(':de',$A); $reqPaiementsA_B->bindvalue(':a',$B); $reqPaiementsA_B->execute(); //Same thing for B to A $reqPaiementsB_A = $bdd -> prepare('SELECT paiements.montant AS montant FROM paiements LEFT JOIN depenses ON paiements.id_depense=depenses.id WHERE depenses.date >'.$debut_mois.' AND depenses.date<'.$fin_mois.' AND paiements.de=:de AND paiements.a=:a'); $reqPaiementsB_A->bindvalue(':de',$B); $reqPaiementsB_A->bindvalue(':a',$A); $reqPaiementsB_A->execute(); //$deltaAB : What A must pay to B $deltaAB = 0; while($donneesA_B = $reqA_B->fetch()) { //We get the price of the meal, divided by the number of people who ate //nbre de virgule + 1 $deltaAB -= $donneesA_B['montant']/(substr_count($donneesA_B['copains'], ',') + 1 + $donneesA_B['invites']); } while($donneesB_A = $reqB_A->fetch()) //idem { $deltaAB += $donneesB_A['montant']/(substr_count($donneesB_A['copains'], ',') + 1 + $donneesB_A['invites']); } while($donneesPaiementsA_B = $reqPaiementsA_B->fetch()) //idem { $deltaAB -= $donneesPaiementsA_B['montant']; } while($donneesPaiementsB_A = $reqPaiementsB_A->fetch()) //idem { $deltaAB += $donneesPaiementsB_A['montant']; } return $deltaAB; } // When we've "de", "a" and "rbmt", we have to remove the matrix block // corresponding to it in "rbmt" if(isset($_GET['de']) && isset($_GET['a']) && isset($_GET['rbmt'])) { // If your are not the one to receive, or not admin, you've no right if($_GET['a'] == $_SESSION['id'] || !empty($_SESSION['admin'])) { // If we have to insert a paiment, we get the matrix and replace the // paiment with 0, then put it back in the database if(isset($_POST['confirm'])) { $req = $bdd->query('SELECT matrix FROM remboursements WHERE id='.$_GET['rbmt']); $retour = $req->fetch(); $matrix = unserialize($retour["matrix"]); $matrix[$_GET['de']][$_GET['a']] = 0; $req = $bdd->prepare('UPDATE remboursements SET matrix=:matrix WHERE id=:id'); $req->bindValue(':matrix', serialize($matrix)); $req->bindValue(':id', $_GET['rbmt']); $req->execute(); header('location: message.php?id=10'); } // We prompt to confirm the operation else { ?> Bouffe@Ulm : remboursements

Remboursements simplifiés

ou retour aux remboursements
Attention, cette opération n'est pas réversible. Une fois le paiement confirmé, il est impossible de revenir en arrière.

Bouffe@Ulm : remboursements

Remboursements simplifiés

Remboursements précédents'; $req = $bdd->prepare('SELECT * FROM remboursements'); $req->execute(); // We create a table string and a links string. The first will contain a // matrix if we want to see one particular rbmt. Links will provide links // to the other rbmt. $table = ''; $links = ''; while($data = $req->fetch()) { // Reset the list of friend to '' $liste = ''; // Extract info from $data // First the date $date = date('j/m', $data['date']); // List of friend $copains = unserialize($data['copains']); foreach($copains as $nom) $liste .= ', ' . $nom; // If we clicked on one particular rbmt if (isset($_GET['id']) && $_GET['id'] == $data['id'] && isset($_GET['action']) && $_GET['action'] == "show") { $table .= "
  • Le {$date}{$liste}"; $matrix = unserialize($data['matrix']); $table.=' '; //Construct the header of the table foreach($copains as $key => $copain) { if($_SESSION['nom'] == $copain) $copain = ''.$copain.''; $table .= ''; } $table .= ''; //For each peer of buddy, print the block in the array foreach($copains as $keyA=>$copainA) { if($_SESSION['nom'] == $copainA) $copainA = ''.$copainA.''; $table .= ''; foreach($copains as $keyB=>$copainB) { if($matrix[$keyA][$keyB] <= 0) $table .= ''; else { if ($keyB == $_SESSION['id'] || !empty($_SESSION['admin'])) $table .= ''; else $table .= ''; } } $table .= ''; } $table .= '
    Doit\À'.$copain.'
    '.$copainA.'-'.$matrix[$keyA][$keyB].''.$matrix[$keyA][$keyB].'
  • '; } // Else, we print a link else $links .= "
  • Le {$date}{$liste}
  • "; } echo '

    '; echo '

    '; echo 'Retour à l\'accueil'; echo '

    '; echo ''; } ?>