<?php
class ModePayement {
    public static function getModePayementsByNoModeAndNoCaisse($noMode, $noCaisse) {
        $query = "SELECT * FROM modespayements".ID_GARAGE." WHERE NoMode=:nomode AND NoCaisse=:nocaisse";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nomode", $noMode);
        $statement->bindParam(":nocaisse", $noCaisse);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getModePayementsByNoCaisse($noCaisse) {
        $query = "SELECT * FROM modespayements".ID_GARAGE." WHERE NoCaisse=:nocaisse ORDER BY NoMode";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocaisse", $noCaisse);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getVisibleModePayment($noCaisse = null) {
        $query = "SELECT * FROM modespayements".ID_GARAGE." WHERE Visible = 1"; 
        if(!is_null($noCaisse)) {
            $query .= "AND NoCaisse=:nocaisse";
        } 
        $query .= " ORDER BY NoCaisse, NoMode";

        $statement = Connection::getStatement($query);
        if(!is_null($noCaisse)) {
            $statement->bindParam(":nocaisse", $noCaisse);
        } 
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getModePayment() {
        $query = "SELECT * FROM modespayements".ID_GARAGE." ORDER BY NoCaisse, NoMode"; 
        $statement = Connection::getStatement($query);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getModePaymentByNoMode($noMode) {
        $query = "SELECT * FROM modespayements".ID_GARAGE." WHERE NoMode=:mode"; 
        $statement = Connection::getStatement($query);
        $statement->bindParam(":mode", $noMode);
        $statement->execute();
        return $statement->fetch();
    }
}