From aabfb86adb5703f1d9bb896cb3cd68f1435739ca Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Thu, 31 May 2018 16:56:22 +0200 Subject: [PATCH] hotline #73599 Pergame: fix hold date not set on transactions for hold cancelation --- VERSIONS_HOTLINE/73599 | 1 + library/Class/Systeme/PergameService.php | 20 ----- library/Class/Transaction.php | 13 +++- .../Class/WebService/SIGB/Pergame/Service.php | 15 +++- .../Class/WebService/SIGB/PergameTest.php | 76 ++++++++++++++++++- 5 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 VERSIONS_HOTLINE/73599 diff --git a/VERSIONS_HOTLINE/73599 b/VERSIONS_HOTLINE/73599 new file mode 100644 index 00000000000..822265bd055 --- /dev/null +++ b/VERSIONS_HOTLINE/73599 @@ -0,0 +1 @@ + - ticket #73599 : SIGB Pergame: correction du fichier de transactions pour l'annulation des réservations \ No newline at end of file diff --git a/library/Class/Systeme/PergameService.php b/library/Class/Systeme/PergameService.php index 475956d82cf..7929f6a2f7f 100644 --- a/library/Class/Systeme/PergameService.php +++ b/library/Class/Systeme/PergameService.php @@ -244,23 +244,6 @@ class Class_Systeme_PergameService { } - public function supprimerReservation($id_reservation) { - $resa = fetchEnreg("select * from reservations where ID_RESA=$id_reservation"); - if(!$resa) - return false; - sqlExecute("delete from reservations where ID_RESA=$id_reservation"); - - // On cree la transaction - $id_abon=$this->user->IDABON; - $ordre_abon=$this->user->ORDREABON; - $id_origine=$resa["ID_NOTICE_ORIGINE"]; - $date=$resa["DATE_RESA"]; - $id_site=$resa["ID_SITE"]; - - $this->ecrireTransaction(7, array($id_abon,$ordre_abon,$date,$id_origine,$id_site)); - } - - public function prolongerPret($id_pret) { $pret = fetchEnreg("select * from prets where id_pret=$id_pret"); $dateJour = date("Y-m-d"); @@ -325,9 +308,6 @@ class Class_Systeme_PergameService { public function getReglesReservation($id_bib) { - - - if (!$id_bib) return false; diff --git a/library/Class/Transaction.php b/library/Class/Transaction.php index 94470e3f2f2..24e3037bf41 100644 --- a/library/Class/Transaction.php +++ b/library/Class/Transaction.php @@ -16,12 +16,21 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Transaction extends Storm_Model_Abstract { + const CANCEL_HOLD = 7; + protected $_table_name = 'transactions'; - protected $_table_primary = 'id_mvt'; + protected $_table_primary = 'id_mvt'; + + + public function setData($string_or_array) { + return is_array($string_or_array) + ? parent::_set('data', implode('|', $string_or_array) . '|') + : parent::_set('data', $string_or_array); + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Pergame/Service.php b/library/Class/WebService/SIGB/Pergame/Service.php index bf07d415e02..2ab21393823 100644 --- a/library/Class/WebService/SIGB/Pergame/Service.php +++ b/library/Class/WebService/SIGB/Pergame/Service.php @@ -129,7 +129,20 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra public function supprimerReservation($user, $reservation_id) { - return $this->getLegacyService()->supprimerReservation($reservation_id); + if (!$hold = Class_Reservation::find($reservation_id)) + return $this->_error($this->_('Réservation non trouvée')); + + (new Class_Transaction()) + ->setTypeMvt(Class_Transaction::CANCEL_HOLD) + ->setData([$hold->getIdabon(), + $hold->getOrdreabon(), + substr($hold->getDateResa(), 0, 10), + $hold->getIdNoticeOrigine(), + $hold->getIdSite()]) + ->save(); + + $hold->delete(); + return $this->_success(); } diff --git a/tests/library/Class/WebService/SIGB/PergameTest.php b/tests/library/Class/WebService/SIGB/PergameTest.php index 8ef8abd3dd1..ec569f17a4b 100644 --- a/tests/library/Class/WebService/SIGB/PergameTest.php +++ b/tests/library/Class/WebService/SIGB/PergameTest.php @@ -19,7 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -abstract class PergameTestCase extends Storm_Test_ModelTestCase { +abstract class PergameTestCase extends ModelTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { parent::setUp(); @@ -398,6 +401,77 @@ class PergameServiceGetExemplairePotterTest extends PergameTestCase { +class PergameServiceCancelHoldTest extends PergameTestCase { + protected $_cancel_result; + + + public function setUp() { + parent::setUp(); + $this->fixture('Class_Reservation', + ['id' => 1234, + 'id_site' => 1, + 'idabon' => 23, + 'ordreabon' => 2, + 'date_resa' => '2018-05-22 16:53:17', + 'support' => 1, + 'id_notice_origine' => 876]); + $this->_cancel_result = $this->_service_cran->supprimerReservation(Class_Users::getIdentity(), + 1234); + } + + + /** @test */ + public function resultShouldBeSuccess() { + $this->assertEquals(['statut' => true, + 'erreur' => ''], + $this->_cancel_result); + } + + + /** @test */ + public function hold1234ShouldBeDeleted() { + $this->assertNull(Class_Reservation::find(1234)); + } + + + /** @test */ + public function transactionShouldBeCreatedForPergame() { + $transaction = Class_Transaction::find(1); + $this->assertNotNull($transaction); + return $transaction; + } + + + /** + * @test + * @depends transactionShouldBeCreatedForPergame + */ + public function transactionTypeMvtShouldBe7($transaction) { + $this->assertEquals(7, $transaction->getTypeMvt()); + } + + + /** + * @test + * @depends transactionShouldBeCreatedForPergame + */ + public function transactionDataShouldContainsIdAbonOrdreAbonDateIdOrigineIdSite($transaction) { + $this->assertEquals('23|2|2018-05-22|876|1|', + $transaction->getData()); + } + + + /** @test */ + public function deleteUnknownHoldShouldReturnError() { + $this->assertEquals(['statut' => false, + 'erreur' => 'Réservation non trouvée'], + $this->_service_cran->supprimerReservation(Class_Users::getIdentity(), + 666)); + } +} + + + class PergameServiceDelegateLegacyTest extends PergameTestCase { public function setUp() { -- GitLab