diff --git a/src/Payutc/Bom/Reversement.php b/src/Payutc/Bom/Reversement.php index b6b650f..2d18fa5 100644 --- a/src/Payutc/Bom/Reversement.php +++ b/src/Payutc/Bom/Reversement.php @@ -152,6 +152,19 @@ public static function getById($revId, $funId=null) { return self::getByQb($qb); } + public static function getAll($funId=null, $step='V') { + $qb = self::getQbBase() + ->where("rev.rev_step = :step") + ->setParameter('step', $step) + ->orderBy('rev.rev_date_updated', 'DESC'); + + if($funId) { + $qb->andWhere('rev.fun_id = :fun_id') + ->setParameter('fun_id', $funId); + } + return self::getByQb($qb); + } + protected static function getQbBase(){ return Dbal::createQueryBuilder() ->select('*') @@ -161,14 +174,24 @@ protected static function getQbBase(){ protected static function getByQb($qb){ $query = $qb->execute(); + $count = $query->rowCount(); // Check that the transaction exists - if ($query->rowCount() == 0) { + if ($count == 0) { throw new ReversementNotFound("Le reversement n'existe pas"); + } else if($count == 1) { + // Get remaining data from the database + $don = $query->fetch(); + return self::fromArray($don); + } else { + $ret = array(); + while($don = $query->fetch()) { + $ret[] = self::fromArray($don); + } + return $ret; } - - // Get remaining data from the database - $don = $query->fetch(); - + } + + protected static function fromArray($don){ $reversement = new Reversement(); $reversement->id = $don['rev_id']; $reversement->funId = $don['fun_id']; diff --git a/src/Payutc/Service/TRESO.php b/src/Payutc/Service/TRESO.php index c23081f..f2f0b36 100644 --- a/src/Payutc/Service/TRESO.php +++ b/src/Payutc/Service/TRESO.php @@ -51,6 +51,7 @@ public function getDetails($fun_id = null) { "account_total" => User::getSumCredit(), // Montant total présent sur les comptes "reversement_total" => Reversement::getTotal(), // Montant total reversé "reversement_wait" => Reversement::getWait(), // Montant total en attente + "reversements" => Reversement::getAll(), // Tout les reversements "fundations" => $fundations ); } else { @@ -58,7 +59,8 @@ public function getDetails($fun_id = null) { "amount_total" => Purchase::getRevenue($fun_id), // Montant total encaissé par la fundation "reversement_total" => Reversement::getTotal($fun_id), // Montant total déjà reversé "reversement_wait" => Reversement::getLast($fun_id, 'W'), // Montant total en attente - "reversement_last" => Reversement::getLast($fun_id) // Date et montant du dernier reversement + "reversement_last" => Reversement::getLast($fun_id), // Date et montant du dernier reversement + "reversements" => Reversement::getAll($fun_id) ); } }