Last active
April 27, 2016 13:08
-
-
Save gaetanm/e38a7bf39b63d8bbab85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function approve() | |
{ | |
$id = $this->request->getData('post', 'id'); | |
$ar = AR::select('WHERE id = ?', $id); | |
$this->updateMemberAbsences($ar); | |
$ar->approvedBy = $this->member->id; | |
$ar->approvalDate = date('Y-m-d'); | |
$ar->update(); | |
$abs = AbsenceModel::selectAll('WHERE request = ?', $ar->id); | |
foreach ($abs as $ab) | |
{ | |
$from = $ab->startDate; | |
$to = $ab->endDate; | |
$monthFrom = date('m', strtotime($from)); | |
$monthTo = date('m', strtotime($to)); | |
$yearFrom = date('Y', strtotime($from)); | |
$yearTo = date('Y', strtotime($to)); | |
$days = array(); | |
$days2 = array(); | |
if ($monthTo == $monthFrom) | |
{ | |
for ($i=date('j', strtotime($from)); $i <= date('j', strtotime($to)); $i++) | |
{ | |
if (date('l', strtotime($yearTo.'-'.$monthTo.'-'.$i)) != 'Saturday' | |
and date('l', strtotime($yearTo.'-'.$monthTo.'-'.$i)) != 'Sunday') | |
{ | |
$days[] = $i; | |
} | |
} | |
$this->insertAbsenceSumary($days, $monthFrom, $yearTo, $ab->type); | |
} | |
else | |
{ | |
for ($i=date("j", strtotime($from)); $i <= date("t", strtotime($from)); $i++) | |
{ | |
if (date('l', strtotime($yearFrom.'-'.$monthFrom.'-'.$i)) != 'Saturday' | |
and date('l', strtotime($yearFrom.'-'.$monthFrom.'-'.$i)) != 'Sunday') | |
{ | |
$days[] = $i; | |
} | |
} | |
$this->insertAbsenceSumary($days, $monthFrom, $yearFrom, $ab->type); | |
$forTheDate = date('Y', strtotime($to)).'-'.date('m', strtotime($to)).'-1'; | |
$daysNumber = round(((strtotime($to) - strtotime($forTheDate))/86400)+1); | |
for ($i=1; $i <= $daysNumber; $i++) | |
{ | |
if (date('l', strtotime($yearTo.'-'.$monthTo.'-'.$i)) != 'Saturday' | |
and date('l', strtotime($yearTo.'-'.$monthTo.'-'.$i)) != 'Sunday') | |
{ | |
$days2[] = $i; | |
} | |
} | |
$this->insertAbsenceSumary($days2, $monthTo, $yearTo, $ab->type); | |
} | |
} | |
foreach ($this->totalAS as $key => $value) | |
{ | |
$data = (explode('-', $key)); | |
$as = new ASU; | |
if (!ASU::exists('WHERE member = ? AND year = ? AND month = ?', array($ar->member->id, $data[1], $data[0]))) | |
{ | |
$as->member = $ar->member; | |
$as->month = $data[0]; | |
$as->year = $data[1]; | |
$as->paidVacationDayRTT = implode(' ', $value['paidVacationDayRTT']); | |
$as->sickLeave = implode(' ', $value['sickLeave']); | |
$as->recuperation = implode(' ', $value['recuperation']); | |
$as->other = implode(' ', $value['other']); | |
$as->insert(); | |
} | |
else | |
{ | |
$as = ASU::select('WHERE member = ? AND year = ? AND month = ?', array($ar->member->id, $data[1], $data[0])); | |
$as->paidVacationDayRTT = implode(' ', array_merge($as->paidVacationDayRTT, $value['paidVacationDayRTT'])); | |
$as->sickLeave = implode(' ', array_merge($as->sickLeave, $value['sickLeave'])); | |
$as->recuperation = implode(' ', array_merge($as->recuperation, $value['recuperation'])); | |
$as->other = implode(' ', array_merge($as->other, $value['other'])); | |
$as->update(); | |
} | |
} | |
echo 'success'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment