diff --git a/lib/GaletteObjectsLend/Entity/LendObject.php b/lib/GaletteObjectsLend/Entity/LendObject.php index 995f33e..cc660d2 100644 --- a/lib/GaletteObjectsLend/Entity/LendObject.php +++ b/lib/GaletteObjectsLend/Entity/LendObject.php @@ -285,11 +285,7 @@ private function loadFromRS(ArrayObject $r): void } if ($this->object_id && $this->deps['rents'] === true) { - $only_last = false; - if ($this->deps['rents'] === false && $this->deps['last_rent'] === true) { - $only_last = true; - } - $this->rents = LendRent::getRentsForObjectId($this->object_id, $only_last); + $this->rents = LendRent::getRentsForObjectId($this->object_id); } if ($this->deps['picture'] === true) { @@ -387,8 +383,6 @@ public function __get(string $name): mixed return number_format($this->$name, 2, ',', ' '); case 'value_rent_price': return $this->rent_price; - case 'weight_bulk': - return $this->weight; case 'weight': return number_format($this->weight, 3, ',', ' '); default: diff --git a/lib/GaletteObjectsLend/Entity/LendRent.php b/lib/GaletteObjectsLend/Entity/LendRent.php index f9c6e6d..2dece46 100644 --- a/lib/GaletteObjectsLend/Entity/LendRent.php +++ b/lib/GaletteObjectsLend/Entity/LendRent.php @@ -123,13 +123,13 @@ public function __construct(int|ArrayObject $args = null) */ private function loadFromRS(ArrayObject $r): void { - $this->rent_id = $r->rent_id; - $this->object_id = $r->object_id; + $this->rent_id = (int)$r->rent_id; + $this->object_id = (int)$r->object_id; $this->date_begin = $r->date_begin; $this->date_forecast = $r->date_forecast; $this->date_end = $r->date_end; - $this->status_id = $r->status_id; - $this->adherent_id = $r->adherent_id; + $this->status_id = (int)$r->status_id; + $this->adherent_id = (int)$r->adherent_id; $this->comments = $r->comments; } @@ -236,8 +236,8 @@ public static function getRentsForObjectId(int $object_id, bool $only_last = fal foreach ($rows as $r) { $rt = new LendRent($r); $rt->status_text = $r->status_text; - $rt->status_id = $r->status_id; - $rt->in_stock = $r->in_stock == '1' ? true : false; + $rt->status_id = (int)$r->status_id; + $rt->in_stock = $r->in_stock == '1'; $rt->prenom_adh = $r->prenom_adh; $rt->nom_adh = $r->nom_adh; $rt->pseudo_adh = $r->pseudo_adh; diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php b/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php index 9cfa1ee..8d5f2bf 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php @@ -120,6 +120,10 @@ public function testCrud(): void $object->name = 'An object'; $object->category_id = $this->active_category_id; $object->is_active = true; + $object->price = 1500.00; + $object->rent_price = 10.00; + $object->price_per_day = true; + $object->weight = 186.00; $this->assertTrue($object->store()); $oid = $object->getId(); @@ -137,7 +141,16 @@ public function testCrud(): void $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps); $this->assertTrue($object->isActive()); + $this->assertSame(1500.00, $object->getPrice()); + $this->assertSame('1 500,00', $object->price); + $this->assertSame(10.00, $object->getRentPrice()); + $this->assertSame('10,00', $object->rent_price); + $this->assertSame(10.00, $object->value_rent_price); + $this->assertSame(186.00, $object->getWeight()); + $this->assertSame('186,000', $object->weight); + $this->assertSame('2024-05-22', $object->getDateBegin()); + $this->assertSame('2024-05-22', $object->date_begin); $object->name = 'An object (edited)'; $object->description = 'An object description'; $object->serial_number = 'SE-aBc-RI@L'; @@ -165,9 +178,12 @@ public function testCrud(): void //edit category to inactive one $object->category_id = $this->inactive_category_id; + $this->assertNull($object->member); + $this->assertNull($object->rents); $this->assertTrue($object->store()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps + ['member' => true, 'rents' => true]); $this->assertFalse($object->isActive()); + $this->assertInstanceOf(\Galette\Entity\Adherent::class, $object->member); //removing category $rm_category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins);