feature/cierres #30
@ -82,7 +82,9 @@ class Reservation extends Common\Ideal\Repository
|
||||
$model = parent::load($data_row);
|
||||
|
||||
$this->fetchUnits($model, $data_row);
|
||||
$this->fetchBroker($model, $data_row);
|
||||
try {
|
||||
$this->fetchBroker($model, $data_row);
|
||||
} catch (Common\Implement\Exception\EmptyResult) {}
|
||||
$this->fetchPromotions($model, $data_row);
|
||||
return $model;
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ use Incoviba\Repository;
|
||||
|
||||
class State extends Common\Ideal\Repository
|
||||
{
|
||||
public function __construct(Common\Define\Connection $connection, protected Repository\Venta\Reservation $reservationRepository)
|
||||
public function __construct(Common\Define\Connection $connection,
|
||||
protected Repository\Venta\Reservation $reservationRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
@ -190,6 +190,7 @@ class Reservation extends Ideal\Service\API
|
||||
}
|
||||
protected function addUnits(Model\Venta\Reservation $reservation, array $units): void
|
||||
{
|
||||
//var_dump(__LINE__, $units);
|
||||
foreach ($units as $unit_id => $value) {
|
||||
try {
|
||||
$unit = $this->unitService->getById($unit_id);
|
||||
@ -202,6 +203,7 @@ class Reservation extends Ideal\Service\API
|
||||
}
|
||||
protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void
|
||||
{
|
||||
var_dump(__LINE__, $promotions);
|
||||
foreach ($promotions as $promotion_id) {
|
||||
try {
|
||||
$promotion = $this->promotionService->getById($promotion_id);
|
||||
|
@ -27,13 +27,37 @@ class ReservationTest extends TestCase
|
||||
$projects = $this->container->get(Repository\Proyecto::class)->fetchAll();
|
||||
$project = $faker->randomElement($projects);
|
||||
$unitTypes = $this->container->get(Repository\Proyecto\TipoUnidad::class)->fetchAll();
|
||||
$projectUnitTypeRepository = $this->container->get(Repository\Proyecto\ProyectoTipoUnidad::class);
|
||||
|
||||
$projectUnitTypes = [];
|
||||
foreach ($unitTypes as $unitType) {
|
||||
$ptuCount = $faker->numberBetween(1, 10);
|
||||
|
||||
for ($i = 0; $i < $ptuCount; $i++) {
|
||||
$ptuData = [
|
||||
'tipo' => $unitType->id,
|
||||
'proyecto' => $project->id,
|
||||
'descripcion' => $faker->word,
|
||||
];
|
||||
$ptu = $projectUnitTypeRepository->create($ptuData);
|
||||
$ptu = $projectUnitTypeRepository->save($ptu);
|
||||
$projectUnitTypes[] = $ptu;
|
||||
}
|
||||
}
|
||||
|
||||
$unitsRepository = $this->container->get(Repository\Venta\Unidad::class);
|
||||
|
||||
$units = [];
|
||||
$unitsValue = [];
|
||||
$unitsCount = $faker->numberBetween(1, 3);
|
||||
for ($i = 0; $i < $unitsCount; $i++) {
|
||||
$type = $faker->randomElement($unitTypes);
|
||||
$units[] = $unitsRepository->fetchByProyectoAndTipo($project->id, $type->id);
|
||||
$type = $faker->randomElement($projectUnitTypes);
|
||||
$unitData = [
|
||||
'pt' => $type->id,
|
||||
];
|
||||
$unit = $unitsRepository->create($unitData);
|
||||
$unit = $unitsRepository->save($unit);
|
||||
$units[] = $unit->id;
|
||||
$unitsValue[] = $faker->randomFloat(2, 1000, 10000);
|
||||
}
|
||||
|
||||
@ -68,7 +92,24 @@ class ReservationTest extends TestCase
|
||||
}
|
||||
$contracts = $this->container->get(Repository\Proyecto\Broker\Contract::class)->fetchActiveByProject($project->id);
|
||||
$broker = $faker->boolean(10) ? $faker->randomElement($contracts)->broker : null;
|
||||
$activePromotions = $this->container->get(Repository\Venta\Promotion::class)->fetchActiveByProject($project->id);
|
||||
|
||||
$promotionTypes = Model\Venta\Promotion\Type::cases();
|
||||
$promotionsRepository = $this->container->get(Repository\Venta\Promotion::class);
|
||||
for ($i = 0; $i < 10; $i ++) {
|
||||
$promotionData = [
|
||||
'project_id' => $project->id,
|
||||
'type' => $faker->randomElement($promotionTypes)->value,
|
||||
'state' => Model\Venta\Promotion\State::ACTIVE->value,
|
||||
'start_date' => $faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'),
|
||||
'end_date' => $faker->dateTimeBetween('now', '+2 years')->format('Y-m-d'),
|
||||
'valid_until' => $faker->dateTimeBetween('now', '+2 years')->format('Y-m-d'),
|
||||
'amount' => $faker->randomFloat(2, 0, 1),
|
||||
];
|
||||
$promotion = $promotionsRepository->create($promotionData);
|
||||
$promotionsRepository->save($promotion);
|
||||
}
|
||||
$activePromotions = $promotionsRepository->fetchActiveByProject($project->id);
|
||||
var_dump(__LINE__, $activePromotions);
|
||||
$promotionsCount = $faker->numberBetween(0, 3);
|
||||
$promotions = [];
|
||||
for ($i = 0; $i < $promotionsCount; $i++) {
|
||||
|
@ -58,6 +58,11 @@ class ReservationTest extends TestCase
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->promotionService->method('getById')->willReturnCallback(function($id) {
|
||||
$promotion = new Model\Venta\Promotion();
|
||||
$promotion->id = $id;
|
||||
return $promotion;
|
||||
});
|
||||
$this->unitService = $this->getMockBuilder(Service\Venta\Unidad::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->unitService->method('getById')->willReturnCallback(function($id) {
|
||||
@ -84,7 +89,7 @@ class ReservationTest extends TestCase
|
||||
$digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K';
|
||||
$broker = $faker->boolean(10) ? $faker->randomNumber(8, true) : '';
|
||||
$promotions = [];
|
||||
$promotionsCount = $faker->numberBetween(0, 10);
|
||||
$promotionsCount = $faker->numberBetween(0, 3);
|
||||
for ($i = 0; $i < $promotionsCount; $i++) {
|
||||
$promotions[] = $faker->numberBetween(1, 100);
|
||||
}
|
||||
|
Reference in New Issue
Block a user