예제 #1
0
        if ($qte >= 0 && is_int($qte)) {
            $this->qte = $qte;
        }
    }
    public function getVATValue()
    {
        return $this->qte * $this->prix * $this->tva;
    }
    public function getTTC()
    {
        return $this->qte * $this->prix + $this->getVATValue();
    }
    public function printResult()
    {
        $totalHT = $this->qte * $this->prix;
        $totalTTC = $totalHT + $totalHT * $this->tva;
        echo "Référence : " . $this->ref . " Nom : " . $this->nom . " Prix Unitaire : " . $this->prix . "€ TVA : " . $this->tva * 100 . "%" . PHP_EOL . "Qte : " . $this->qte . " Prix total HT : " . $totalHT . "€ Prix TTC : " . $totalTTC . "€";
    }
    public function __toString()
    {
        return "Référence : " . $this->ref . " Nom : " . $this->nom . " Prix Unitaire : " . $this->prix . "€ TVA : " . $this->tva * 100 . "%" . PHP_EOL . "Qte : " . $this->qte . " Prix total HT : " . $this->qte * $this->prix . "€ Prix TTC : " . number_format($this->{$this}->getTTC(), 2) . "€";
    }
}
try {
    $p = new Panier("Xc0012", "RedBull", 2.0, 0.2);
    $p->setQte(113);
} catch (Exception $e) {
    echo $e->getMessage();
}
$p->printResult();
echo $p;