[PHP]Funzione di calcolo prezzo di una camera in un range di date

in questo modo salti il ciclo while e l'aggiornamento della tabella con i valori custom,
it's ok !

verifica tutto,
le ottimizzazioni (mezzo microsecondo guadagnato… ) le vedremo alla fine se proprio vorrai
 
Ciao Marino51, sto cercando di inserire la variabile rebate quando cambio il prezzo per una determinata data sul calendario.
Ho creato il campo input name rebate e modificato l'insert nel file che gestisce l'insert custom price.
Ci sto da giorni e non riesco a comprendere perché non mi funziona. Ho creato un file php per l'inserimento del prezzo custom del rebate e funziona ma volevo utilizzare lo stessa classe di aggiornamento prezzo custom per inserire anche lo sconto rebate.
Hai qualche suggerimento? Grazie!
 
Questo è il file modificato ( RoomCustomPriceDomain )
PHP:
namespace Domain;

class RoomCustomPriceDomain extends RootDomain
{
    private $id;
    private $roomId;
    private $createdDate;
    private $certainDate;
    private $price;
    private $rebate;

    public function __construct(
        $id,
        $roomId,
        $createdDate,
        $certainDate,
        $price,
        $rebate
    ){
        $this->id = $id;
        $this->roomId = $roomId;
        $this->createdDate = $createdDate;
        $this->certainDate = $certainDate;
        $this->price = $price;
        $this->rebate = $rebate;

    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function getId()
    {
        return $this->id;
    }

    public function setRoomId($roomId)
    {
        $this->roomId = $roomId;
    }

    public function getRoomId()
    {
        return $this->roomId;
    }

    public function setCreatedDate($createdDate)
    {
        $this->createdDate = $createdDate;
    }

    public function getCreatedDate()
    {
        return $this->createdDate;
    }

    public function setCertainDate($certainDate)
    {
        $this->certainDate = $certainDate;
    }

    public function getCertainDate()
    {
        return $this->certainDate;
    }

    public function setPrice($price)
    {
        $this->price = $price;
    }

    public function getPrice()
    {
        return $this->price;
    }
  
   public function setRebate($rebate)
    {
        $this->rebate = $rebate;
    }

    public function getRebate()
    {
        return $this->rebate;
    }
  
  
}

mentre il file modificato (RoomCustomPriceDataSource)

PHP:
namespace DataSource;
use DateTime;
use Driver\MySQLi;
use Domain\RoomCustomPriceDomain;

class RoomCustomPriceDataSource extends RootDataSource
{
    public function instantiateRoomCustomPriceDomain(array $row)
    {
        $row['created_date'] = $this->getDateObject($row['created_date']);
        $row['certain_date'] = $this->getDateObject($row['certain_date']);
        $roomCustomPriceDomain = new RoomCustomPriceDomain(
            $row['id'],
            $row['room_id'],
            $row['created_date'],
            $row['certain_date'],
            $row['price'],
            $row['rebate']
        );

        return $roomCustomPriceDomain;
    }
    public function insert(array $roomCustomPriceDomainArray)
    {
        $statement = $this->mysqli->buildStatement('
            DELETE FROM  
                room_custom_price
            WHERE
                certain_date = :certainDate AND
                room_id = :roomId
        ');
        foreach ($roomCustomPriceDomainArray as $roomCustomPriceDomain) {
            $statement->execute(array(
                ':roomId' => $roomCustomPriceDomain->getRoomId(),
                ':certainDate' => $roomCustomPriceDomain->getCertainDate()->format('Y-m-d')
            ));
        }
        $statement->close();
      
        $statement = $this->mysqli->buildStatement('
            INSERT INTO
                room_custom_price
            VALUES(
                :id,
                :roomId,
                :createdDate,
                :certainDate,
                :price,
                :rebate
            )
        ');
        foreach ($roomCustomPriceDomainArray as $roomCustomPriceDomain) {
            $statement->execute(array(
                ':id' => $roomCustomPriceDomain->getId(),
                ':roomId' => $roomCustomPriceDomain->getRoomId(),
                ':createdDate' => $roomCustomPriceDomain->getCreatedDate()->format('Y-m-d H:i:s'),
                ':certainDate' => $roomCustomPriceDomain->getCertainDate()->format('Y-m-d'),
                ':price' => $roomCustomPriceDomain->getPrice(),
                ':rebate' => $roomCustomPriceDomain->getRebate()
            ));
        }
        $statement->close();
        return true;
    }

    public function delete(array $dataArray)
    {
        $statement = $this->mysqli->buildStatement('
            DELETE FROM
                room_custom_price
            WHERE
                room_id = :roomId AND
                certain_date = :certainDate
        ');
        foreach ($dataArray as $data) {
            $statement->execute(array(
                ':roomId' => $data['roomId'],
                ':certainDate' => $data['certainDate']
            ));
        }
        $statement->close();
    }
    public function getAllByRoomId($roomId, $now)
    {
        $certainDate = new DateTime($now->format('Y-m-d'));
        $startDate = $certainDate->modify('-1 month')->format('Y-m-17');
        $endDate = $certainDate->modify('+2 months')->format('Y-m-13');

        $statement = $this->mysqli->buildStatement('
            SELECT
                DATE_FORMAT(certain_date, \'%m-%d-%Y\') AS certain_date,
                price
            FROM
                room_custom_price
            WHERE
                room_id = :roomId AND
                (certain_date BETWEEN :startDate AND :endDate)
        ');
        $statement->execute(array(
            ':roomId' => $roomId,
            ':startDate' => $startDate,
            ':endDate' => $endDate
        ));
        $rows = $statement->fetchAllAssociative();
        $statement->close();

        return $rows;
    }
}

Quando provo ad aggiornare la pagina rimane in caricamento e non mi fornisce errori.
 

Discussioni simili