Current File : /home/karenpetzb/application/models/PromoUser.php |
<?php
class PromoUser extends Zend_Db_Table
{
protected $_name = 'promo_user';
protected $_primary = 'ID';
/*
* Remise selon la marque et l'user
*/
public function getRemiseByMarque($idbrend, $iduser) { try {
return $this->select()->where("USERIDBREND = ?", $iduser)->where("USERBRENDID = ?", $idbrend)->query()->fetch();
} catch (Zend_Exception $e) { return array(); }
}
public function getRemiseByMarqueFull($iduser) { try {
$sql = "SELECT u.NOM NOM,u.ID IDUSER, u.PRENOM PRENOM,
pu.ID ID, pu.REMISEEURO REMISEEURO, pu.REMISEPOUR REMISEPOUR, pu.USERIDBREND USERIDBREND, pu.USERBRENDID USERBRENDID, sb.BREND BREND, sb.IDSUPPLIER IDSUPPLIER
FROM promo_user AS pu
LEFT JOIN user AS u ON u.ID = pu.USERIDBREND
LEFT JOIN supplier_brend AS sb ON sb.ID = pu.USERBRENDID
WHERE pu.USERIDBREND IS NOT NULL
AND pu.USERBRENDID IS NOT NULL
AND u.ID = ".$iduser."
ORDER BY u.NOM, u.PRENOM ASC";
return $this->getAdapter()->fetchAll($sql);
} catch (Zend_Exception $e) { return array(); }
}
/*
* Remise selon la marque et le code intern
*/
public function getRemiseByCodeInternMarque($idbrend, $codeintern) { try {
return $this->select()->where("CINTERNIDBREND = ?", $codeintern)->where("CINTERNBRENDID = ?", $idbrend)->query()->fetch();
} catch (Zend_Exception $e) { return array(); }
}
public function getRemiseByCodeInternMarqueFull($codeintern) { try {
$sql = "SELECT pu.ID ID, pu.REMISEEURO REMISEEURO, pu.REMISEPOUR REMISEPOUR, uci.LABEL LABELINTERN, uci.CODE CODEINTERN,
pu.CINTERNIDBREND CINTERNIDBREND, sb.BREND BREND, pu.CINTERNBRENDID CINTERNBRENDID, sb.IDSUPPLIER IDSUPPLIER, u.ID IDUSER
FROM promo_user AS pu
LEFT JOIN user_cintern AS uci ON uci.ID = pu.CINTERNIDBREND
LEFT JOIN user AS u ON u.CODEINTERN = pu.CINTERNIDBREND
LEFT JOIN supplier_brend AS sb ON sb.ID = pu.CINTERNBRENDID
WHERE pu.CINTERNIDBREND IS NOT NULL
AND pu.CINTERNBRENDID IS NOT NULL
AND pu.CINTERNIDBREND = '".$codeintern."'
ORDER BY uci.CODE,sb.BREND ASC";
return $this->getAdapter()->fetchAll($sql);
} catch (Zend_Exception $e) { return array(); }
}
/*
* Remise selon la date d'inscription
*/
public function getRemiseByDateInscription() { try {
return $this->select()->where('isDATEINSCR IS NOT NULL AND isDATEINSCR = 0')->query()->fetch();
} catch (Zend_Exception $e) { return array(); }
}
/*
* Remise selon l'id de l'user
*/
public function getRemiseByUserID($id) { try {
return $this->select()->where('IDUSER IS NOT NULL AND IDUSER = ?', $id)->query()->fetch();
} catch (Zend_Exception $e) { return array(); }
}
public function getRemiseByUserIDFull($id) { try {
$sql = "SELECT u.NOM NOM,u.ID IDUSER, u.PRENOM PRENOM,
pu.ID ID, pu.REMISEEURO REMISEEURO, pu.REMISEPOUR REMISEPOUR
FROM promo_user AS pu
LEFT JOIN user AS u ON pu.IDUSER = u.ID
WHERE pu.IDUSER IS NOT NULL
AND u.ID = ".$id;
return $this->getAdapter()->fetchRow($sql);
} catch (Zend_Exception $e) { return array(); }
}
/*
* Remise pour la premiere commande
*/
public function getRemiseByIsFirstCommand() { try {
return $this->select()->where('isFIRSTCMD IS NOT NULL AND isFIRSTCMD = 0')->query()->fetch();
} catch (Zend_Exception $e) { return array(); }
}
}
?>