create(); DB::table('orders')->insert([ 'id' => '018e4567-e89b-72d3-a456-426614174000', 'shop_id' => $shop->id, 'reference' => UuidHelper::v7()->toString(), 'employee' => json_encode([ 'matricule' => '1234567', 'firstname' => 'Jean', 'lastname' => 'Dupont', 'facility' => 'Main Facility', 'site' => 'HQ', 'service' => 'IT', ]), 'delivery_address' => '{}', 'pickup_day' => '2023-01-05', 'status' => OrderStatus::VALIDATED->value, 'total' => 1500, // 15.00 EUR ]); $service = new EloquentEmployeeStatisticsService(); $start = CarbonImmutable::parse('2023-01-01'); $end = CarbonImmutable::parse('2023-01-07'); // WHEN $result = $service->getWeeklyTotalForEmployee(new Matricule('1234567'), $start, $end); // THEN expect($result->getAmount())->toBe('1500') ->and($result->getCurrency()->getCode())->toBe('EUR'); }); it('includes VALIDATED and PENDING orders and excludes WAITING, FAILED, and CANCELED orders in weekly total', function (): void { // GIVEN $shop = Shop::factory()->create(); $baseRow = [ 'shop_id' => $shop->id, 'employee' => json_encode([ 'matricule' => '1234567', 'firstname' => 'Jean', 'lastname' => 'Dupont', 'facility' => 'Main Facility', 'site' => 'HQ', 'service' => 'IT', ]), 'delivery_address' => '{}', 'pickup_day' => '2023-01-05', ]; DB::table('orders')->insert([ array_merge($baseRow, [ 'id' => UuidHelper::v7()->toString(), 'reference' => UuidHelper::v7()->toString(), 'status' => OrderStatus::VALIDATED->value, 'total' => 1000, ]), array_merge($baseRow, [ 'id' => UuidHelper::v7()->toString(), 'reference' => UuidHelper::v7()->toString(), 'status' => OrderStatus::PENDING->value, 'total' => 2500, ]), array_merge($baseRow, [ 'id' => UuidHelper::v7()->toString(), 'reference' => UuidHelper::v7()->toString(), 'status' => OrderStatus::WAITING->value, 'total' => 4000, ]), array_merge($baseRow, [ 'id' => UuidHelper::v7()->toString(), 'reference' => UuidHelper::v7()->toString(), 'status' => OrderStatus::FAILED->value, 'total' => 5000, ]), array_merge($baseRow, [ 'id' => UuidHelper::v7()->toString(), 'reference' => UuidHelper::v7()->toString(), 'status' => OrderStatus::CANCELED->value, 'total' => 9000, ]), ]); $service = new EloquentEmployeeStatisticsService(); // WHEN $result = $service->getWeeklyTotalForEmployee( new Matricule('1234567'), CarbonImmutable::parse('2023-01-01'), CarbonImmutable::parse('2023-01-07') ); // THEN expect($result->getAmount())->toBe('3500'); }); });