PHP code example of tourze / hotel-agent-bundle

1. Go to this page and download the library: Download tourze/hotel-agent-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / hotel-agent-bundle example snippets


   // config/bundles.php
   return [
       // ... other bundles
       Tourze\HotelAgentBundle\HotelAgentBundle::class => ['all' => true],
   ];
   

use Tourze\HotelAgentBundle\Service\AgentBillService;
use Tourze\HotelAgentBundle\Service\OrderCreationService;

// Inject services via constructor
class YourController
{
    public function __construct(
        private AgentBillService $agentBillService,
        private OrderCreationService $orderCreationService
    ) {}

    public function createOrder(Agent $agent, array $orderData): Order
    {
        return $this->orderCreationService->createFromArray($orderData, $agent);
    }

    public function generateAgentBill(Agent $agent, string $month): AgentBill
    {
        return $this->agentBillService->generateMonthlyBill($agent, $month);
    }
}

// Create an order with validation
$order = $orderCreationService->createFromArray([
    'hotelId' => 1,
    'roomTypeId' => 2,
    'checkInDate' => '2024-01-15',
    'checkOutDate' => '2024-01-17',
    'roomCount' => 2,
    'guestName' => 'John Doe',
    'guestPhone' => '+1234567890'
], $agent);

// Update order status
$orderStatusService->updateStatus($order, OrderStatusEnum::CONFIRMED);

use Tourze\HotelAgentBundle\Service\AgentCodeGenerator;

class CustomAgentCodeGenerator extends AgentCodeGenerator
{
    public function generateCode(): string
    {
        // Custom logic for agent code generation
        return 'AGT' . date('Y') . sprintf('%04d', rand(1, 9999));
    }
}

use Tourze\HotelAgentBundle\Service\BillAuditService;
use Tourze\HotelAgentBundle\Entity\AgentBill;

class CustomBillAuditService extends BillAuditService
{
    public function audit(AgentBill $bill, string $decision, string $comment = ''): bool
    {
        // Custom audit logic
        if ($this->performCustomValidation($bill)) {
            return parent::audit($bill, $decision, $comment);
        }
        
        return false;
    }
    
    private function performCustomValidation(AgentBill $bill): bool
    {
        // Your custom validation logic
        return true;
    }
}

use Tourze\HotelAgentBundle\Service\OrderImportService;

class CustomOrderImportService extends OrderImportService
{
    protected function validateRowData(array $rowData): bool
    {
        // Add custom validation rules
        if (!parent::validateRowData($rowData)) {
            return false;
        }
        
        // Additional custom checks
        return $this->performBusinessRuleValidation($rowData);
    }
}
bash
   php bin/console doctrine:migrations:migrate