Skip to content

Instantly share code, notes, and snippets.

@makamo
Created November 25, 2015 22:13
Show Gist options
  • Save makamo/23441ef8d9d36415d165 to your computer and use it in GitHub Desktop.
Save makamo/23441ef8d9d36415d165 to your computer and use it in GitHub Desktop.
public function index($week = null, $year = null)
{
// Si variable non défini choisi semaine courante
if (!$year) {
$year = date("Y");
}
if (!$week) {
$week = date("W") - 1;
}
// Range de date
$periodeDate = Periode::getStartAndEndDate($week, $year);
$employees = TableRegistry::get('ContratsEmployees');
//trouve tout les employees
$tous_employees = $employees->find('list', [
'keyField' => 'id',
'valueField' => '_matchingData.Employees.inverse_name'
])->matching('Employees', function ($q) {
return $q->where(['Employees.activated =' => true]);
})->order(['Employees.last_name'])->toArray();
$contrats = TableRegistry::get('Contrats')->find('list')->where('actif');
$dropdownDate = new Time("$year-01-01");
$dropdownDate->addWeeks($week - 1)->modify('last sunday');
$paies = $this->Paies->find()->contain([
'Contrats.Entreprises.Pays',
'Contrats.Entreprises.Provinces',
'PaieHeures' => function (Query $q) {
return $q->select([
'paie_id',
'date',
'h_payable' => $q->func()->sum('h_payable'),
'h_total' => $q->func()->sum('h_total'),
'h_reg' => $q->func()->sum('h_reg'),
'h_sup' => $q->func()->sum('h_sup'),
'fonction_id',
'task_id',
'taux_reg',
'Fonctions.name',
'Tasks.name',
'Equipements.name',
])->group(['date', 'taux_reg', 'rapport_journalier_id', 'timesheet_id'])->contain([
'Fonctions',
'Equipements',
'Tasks'
])->order('date');
},
'PaieMetrages' => function (Query $q) {
return $q->order(['date', 'debut']);
},
'PaieAutres',
'PaieAjustements',
'Employees'
])->where(['week' => $week, 'year' => $year])->order("Employees.last_name");
$this->set(compact('contrats', 'periodeDate', 'tous_employees', 'dropdownDate', 'paies'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment