Skip to content

Instantly share code, notes, and snippets.

@makamo
Created November 25, 2015 22:14
Show Gist options
  • Save makamo/b23413c3b1993d5ce5b9 to your computer and use it in GitHub Desktop.
Save makamo/b23413c3b1993d5ce5b9 to your computer and use it in GitHub Desktop.
<?php
namespace App\Model\Entity;
use App\Utility\Overtime;
use App\Utility\Periode;
use Cake\Collection\Collection;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
/**
* Paie Entity.
*/
class Paie extends Entity
{
public $periode_Fin;
public $periode_debut;
public $heureTotalSup;
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible = [
'*' => true,
];
/**
*
*/
public function __construct(array $properties = [], array $options = []){
parent::__construct($properties, $options);
if(isset($this->contrat)){
$this->setHeureTotalSup(new Overtime($this->contrat->surtemps));
}
}
/**
* @param Overtime $heureTotalSup
*/
public function setHeureTotalSup($heureTotalSup)
{
$this->heureTotalSup = $heureTotalSup;
}
protected function _setDate()
{
$date = $this->_setPeriode();
return $date["debut"];
}
protected function _getDate()
{
$p = Periode::getStartAndEndDate($this->week, $this->year);
$this->periode_debut = $p["debut"];
$this->periode_Fin = $p["fin"];
return $p["debut"]->toDateString();
}
/**
* Déclare la date de debut et de fin d'une période
*/
protected function _setPeriode()
{
$p = Periode::getStartAndEndDate($this->week, $this->year);
$this->periode_debut = $p["debut"];
$this->periode_Fin = $p["fin"];
return $p;
}
public function _getNbHeurePayable(){
$total=0;
foreach($this->paie_heures as $heures){
$total+=$heures->h_payable;
}
return $total;
}
public function _getNbHeureTotal(){
$total=0;
foreach($this->paie_heures as $heures){
$total+=$heures->h_total;
}
return $total;
}
public function _getNbHeureReg(){
$total=0;
foreach($this->paie_heures as $heures){
$total+=$heures->h_reg;
}
return $total;
}
public function _getNbHeureSup(){
$total=0;
foreach($this->paie_heures as $heures){
$total+=$heures->h_sup;
}
return $total;
}
public function _getMontantHeure(){
$total=0;
foreach($this->paie_heures as $heures){
$total+=$heures->montant;
}
return $total;
}
public function _getNbMetrage(){
$total=0;
foreach($this->paie_metrages as $metrages){
$total+=$metrages->metrage;
}
return $total;
}
public function _getMontantMetrage(){
$total=0;
foreach($this->paie_metrages as $metrages){
$total+=$metrages->montant;
}
return $total;
}
public function _getMontantAjustement(){
$total=0;
foreach($this->paie_ajustements as $ajustement){
$total+=$ajustement->montant;
}
return $total;
}
public function _getSousTotal(){
return $this->montant_heure + $this->montant_metrage + $this->montant_ajustement;
}
public function _getTotal(){
/* debug([$this->sous_total,
$this->paie_autre->deplacement_aller,
$this->paie_autre->deplacement_retour,
$this->nb_jour_travail*$this->paie_autre->hebergement,
$this->paie_autre->montant_ferie,
$this->paie_autre->vacance_montant]);die();*/
return
$this->sous_total+
$this->paie_autre->deplacement_aller+
$this->paie_autre->deplacement_retour+
$this->nb_jour_travail*$this->paie_autre->hebergement+
$this->paie_autre->ferie+
$this->paie_autre->vacance_montant;
}
public function _getTauxMoyen(){
return
$this->sous_total / $this->nb_heure_total;
}
public function _getMontantHeureTotal(){
$reg=0;
$sup=0;
foreach($this->paie_heures as $heures){
$this->heureTotalSup->add($heures->h_total,$heures->date);
$reg += $this->heureTotalSup->getReg() *$heures->taux_reg;
$sup += $this->heureTotalSup->getSup() *$heures->taux_sup;
}
return $reg+$sup;
}
public function _getOver(){
return ($this->montant_heure + $this->montant_metrage) - $this->montant_heure_total ;
}
public function _getNbJourTravail(){
$dates=[];
foreach($this->paie_heures as $heures){
$dates[] = $heures->date;
}
return count(array_unique($dates));
}
public function _getEmployee(){
$employees = TableRegistry::get('Employees');
return $employees->get($this->employee_id);
}
public function _getPaieHeures(){
$paie_heures = TableRegistry::get('PaieHeures');
return $paie_heures->find()->contain(['Fonctions'])->where(['paie_id'=>$this->id])->toArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment