<?php
class DBCash {
    public static function getDBCashByNoCommande($noCommande) {
        $query = "SELECT * FROM dbcash".ID_GARAGE." WHERE NoFacture = :nocommande ORDER BY Date";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getDBCashByNoFactureAndLesserDate($noCommande, $date) {
        $query = "SELECT * FROM dbcash".ID_GARAGE." WHERE NoFacture=:nocommande AND Date<:date";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->bindParam(":date", $date);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getDBCashByNoCash($noCash) {
        $query = "SELECT * FROM dbcash".ID_GARAGE." WHERE NoCash = :nocash";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocash", $noCash);
        $statement->execute();
        return $statement->fetch();
    }

    public static function getNoCashByNoFactureAndDateAndSommeAndModePaymentAndNoCaisse($noCommande, $date, $somme, $modePayement, $noCaisse) {
        $query = "SELECT NoCash FROM dbcash".ID_GARAGE." WHERE NoFacture=:nocommande AND Date=:date AND Somme=:somme AND ModePayement=:modepayment AND NoCaisse=:nocaisse";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->bindParam(":date", $date);
        $statement->bindParam(":somme", $somme);
        $statement->bindParam(":modepayment", $modePayement);
        $statement->bindParam(":nocaisse", $noCaisse);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function insert($noCommande, $user, $date, $somme, $tva, $modePayement, $noCaisse) {
        $query = "INSERT INTO dbcash".ID_GARAGE." (NoFacture, PersonneEncaissement, Date, Somme, TVA, ModePayement, NoCaisse) VALUES".
        " (:nocommande, :user, :date, :somme, :tva, :modepayement, :nocaisse)";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->bindParam(":user", $user);
        $statement->bindParam(":date", $date);
        $statement->bindParam(":somme", $somme);
        $statement->bindParam(":tva", $tva);
        $statement->bindParam(":modepayement", $modePayement);
        $statement->bindParam(":nocaisse", $noCaisse);
        return $statement->execute();
    }

    public static function getByPeriod($start, $end, $payement = 1) {
        $query = "SELECT * FROM dbcash".ID_GARAGE." WHERE Date>:start AND Date<=:end AND ModePayement=:payment";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":start", $start);
        $statement->bindParam(":end", $end);
        $statement->bindParam(":payment", $payement);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getSumByNoFacture($noCommande) {
        $query = "SELECT SUM(Somme) FROM dbcash".ID_GARAGE." WHERE NoFacture=:nocommande";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->execute();
        return $statement->fetch();
    }

    public static function getByNoFacture($noCommande) {
        $query = "SELECT * FROM dbcash".ID_GARAGE." WHERE NoFacture=:nocommande";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->execute();
        return $statement->fetch();
    }

     
}