diff --git a/VERSIONS_HOTLINE/73599 b/VERSIONS_HOTLINE/73599 new file mode 100644 index 0000000000000000000000000000000000000000..822265bd0558e5a6e3d07bd6430b7d1eced2ae2e --- /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 475956d82cf6ef117e0456f264a447a26c937ce4..7929f6a2f7f035701f96dc748033ae100c4173ef 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 94470e3f2f2515ce34130841715ea77ddbea9c89..24e3037bf412af711910478875eedf06d2afb563 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 bf07d415e0233ac7a027ce1a4305b27f7490a081..2ab21393823acb735f75718b6ca0b37d03b15dbe 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 8ef8abd3dd1e0d15ea13bb68adf0220a7095fd6e..ec569f17a4b6e217c6998fcea0e2bc129d07e90c 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() {