<?php

class Compta
{
	var $annee;
	var $trimestre;

	function Compta($annee, $trimestre)
	{
		$this->annee = $annee;
		$this->trimestre = $trimestre;
	}

	function getConsu()
	{
		$q = "SELECT c.*, u.user_nom, u.user_prenom, p.pat_nom, p.pat_prenom, p.pat_datenaiss FROM consultation c LEFT JOIN situpat s ON (s.id_consult = c.id_consult) LEFT JOIN module m ON (m.id_mod = s.id_mod) LEFT JOIN utilisateur u ON (u.id_user = c.id_user) LEFT JOIN patient p ON (p.id_pat = c.id_pat) WHERE YEAR(c.date_saisie) = '" . $this->annee . "' && QUARTER(c.date_saisie) = '" . $this->trimestre . "' && c.consu_type != 1 ORDER BY c.date_saisie ASC";
		$listConsu = queryList($q);

		return $listConsu;
	}

	function getModule()
	{
		$q = "SELECT p.*, pat.pat_nom, pat.pat_prenom, pat.pat_datenaiss, m.mod_nom FROM proposition p LEFT JOIN module m ON (m.id_mod = p.id_mod) LEFT JOIN patient pat ON (pat.id_pat = p.id_pat) WHERE p.prop_contrat != '0000-00-00' && YEAR(p.date_saisie) = '" . $this->annee . "' && QUARTER(p.date_saisie) = '" . $this->trimestre . "' ORDER BY p.date_saisie ASC";
		$listModule = queryList($q);

		return $listModule;
	}

	function getFirstContrat()
	{
		$q = "SELECT p.*, u.user_nom, u.user_prenom FROM patient p LEFT JOIN utilisateur u ON (u.id_user = p.id_user) WHERE YEAR(p.date_saisie) = '" . $this->annee . "' && QUARTER(p.date_saisie) = '" . $this->trimestre . "' && p.pat_contrat != '0000-00-00' ORDER BY p.date_saisie ASC";
		$listContrat = queryList($q);

		return $listContrat;
	}

	function getLastModule($id_pat, $id_mod, $consu_date)
	{
		$q = "SELECT * FROM proposition p WHERE p.id_pat = '" . $id_pat . "' && p.id_mod = '" . $id_mod . "' && p.prop_contrat <= '" . $consu_date . "' ORDER BY p.id_prop DESC LIMIT 1";
		$lastModule = queryOne($q);

		return $lastModule;
	}
}

?>