Skip to content

Commit

Permalink
Work work work!
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 22, 2024
1 parent 3bf4e5f commit 86a7fbc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
8 changes: 1 addition & 7 deletions lib/GaletteObjectsLend/Entity/LendObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions lib/GaletteObjectsLend/Entity/LendRent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion tests/GaletteObjectsLend/Entity/tests/units/LendObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 86a7fbc

Please sign in to comment.