public function save() { $data = $this->getData(['base1', 'base2', 'start', 'end', 'date', 'user_id']); $base1 = \Arr::get($data, 'base1'); $base2 = \Arr::get($data, 'base2'); $base1 = intval($base1 / 100); $base2 = intval($base2 / 100); $date = \Arr::get($data, 'date'); $start = \Arr::get($data, 'start'); $end = \Arr::get($data, 'end'); $periodmonth = Calendar::getPeriodMonth($date); $count = date('t', strtotime($date)); $start = strtotime($start) > strtotime($periodmonth['start']) ? $start : $periodmonth['start']; $end = strtotime($end) > strtotime($periodmonth['end']) ? $periodmonth['end'] : $end; $s = new \DateTime($start); $e = new \DateTime($end); $interval1 = $s->diff($e); $em = new \DateTime($periodmonth['end']); $interval2 = $e->diff($em); $coun1 = $interval1->days; $coun2 = $interval2->days; $percent1 = $coun1 / $count; $percent2 = $coun2 / $count; $html = $base1 . '*' . $coun1 . '/' . $count . ' + ' . $base2 . '*' . $coun2 . '/' . $count; $result = $base1 * $percent1 + $base2 * $percent2; return ['result' => round($result), 'html' => $html]; }
public static function prepare(array $sheet) { $sheet['lang'] = []; foreach (range(1, 6) as $day) { $sheet['lang'][$day] = ['day' => $day, 'lang' => Calendar::weekdays($day), 'start' => \Arr::get($sheet, 's' . $day, NULL), 'end' => \Arr::get($sheet, 'e' . $day, NULL)]; } $sheet['lang']['0'] = ['day' => 0, 'lang' => Calendar::weekdays(0), 'start' => \Arr::get($sheet, 's0', NULL), 'end' => \Arr::get($sheet, 'e0', NULL)]; return $sheet; }
public function getByFact($date) { if (!$date) { $date = date($this->format_date); } $period = Calendar::getPeriodMonth($date); $select = "\n DATE_FORMAT(b.datetime,'%Y-%m') month\n "; $params = ['since' => $period['start'] . ' 00:00:00', 'till' => $period['end'] . ' 23:59:59']; $group = "DATE_FORMAT(b.datetime,'%Y-%m-01')"; $all = \Model::admin('Balance')->buildOrderStatistics(compact("select", "params", "group")); if (!empty($all)) { return array_pop($all); } return 0; }
/** * @param integer $id * * @Method (AJAX) */ public function viewAction($id) { $form = $this->form('BonusEdit'); $valiebles = ['Опоздание' => -1, 'Не отработано' => -1, 'Недостача' => -1, 'Экспедиторский бонус' => 1]; $filter = $this->form('BonusFilter'); $filter->setData('user_id', $id); if ($this->request->is('POST')) { $filter->handle($this->request->post); if ($filter->validate()) { $query = $filter->buildQuery(); $this->redirect('/admin/employee/bonus/view/' . $id . $query); } } $filter->setData($this->request->query->all()); $data = $filter->getSafeData(); $bonuses = $this->model('Bonus')->getByList($data); array_walk($bonuses, function (&$bonus) { $bonus['approved'] = Bonus::is_approved($bonus); }); $month = $filter->getData('month', date('m')); $year = $filter->getData('year', date('Y')); $bonus_mount = $year . '-' . $month; if ($bonus_mount == date('Y-m')) { $bonus_mount = date('Y-m-d'); } else { $bonus_mount = $bonus_mount . '-' . date('d'); } $form->setData('date', $bonus_mount); $form->setData('manager_id', $id); // оклад $oklad = $this->model('EmployeeSalary')->getByOkladUserId($id); $start = date('Y-m-d', strtotime($bonus_mount)); $_date = new \DateTime($start); $_date->add(new \DateInterval('P1M')); $_date->sub(new \DateInterval('P1D')); $end = $_date->format('Y-m-d'); $coun_word_day = Calendar::GetWorkingDayCount($start, $end); // кол-во рабочих дней if ($coun_word_day) { $price_hour = $oklad / ($coun_word_day * 8); } else { $price_hour = 0; } return $this->renderPartial('bonus/view', ['filter' => $filter->createBuilder(), 'bonuses' => $bonuses, 'user_id' => $id, 'auth_user' => $this->user->id, 'is_rule' => $this->is_allow, 'form' => $form->createBuilder(), 'valiebles' => $valiebles, 'auth_user' => $this->user->id, 'price_hour' => $price_hour]); }
public function save() { $data = $this->getData(['date', 'hour', 'minute', 'user_id']); $user_id = \Arr::get($data, 'user_id', 0); $_date = date('Y-m', strtotime($data['date'])); $period_month = Calendar::getPeriodMonth($_date . '-01'); $oklad = $this->model('EmployeeSalary')->getByOkladUserId($user_id, $period_month); $price_hour = intval($oklad / (25 * 8)); $bonus = $this->model('Bonus')->plus($data, $price_hour); return $bonus; /* $id = $this->model('Bonus')->insert($data); $bonus = $this->model('Bonus')->getById($id); if(null != $bonus){ $bonus['date'] = date('d.m.Y',strtotime($bonus['date'])); } return $bonus;*/ }
public function init($sheets = NULL) { $m = $this->getData('month', date('m')); $y = $this->getData('year', date('Y')); $p = Calendar::getPeriodMonth($y . '-' . $m . '-01'); $this->setData('start', $p['start']); $this->setData('end', $p['end']); if ($sheets) { foreach ($sheets as $sheet) { $key = ''; $_id = \Arr::get($sheet, 'id', 0); // id sheet $plan_id = \Arr::get($sheet, 'plan_id', NULL); // Plan_id $user_id = \Arr::get($sheet, 'manager_id', NULL); // user_id $department_id = \Arr::get($sheet, 'department_id', NULL); // department_id $ammount = \Arr::get($sheet, 'plan_amount', NULL); // ammount if ($user_id) { $key = $user_id . '_' . $plan_id; // user_id _ plan_id $this->_user[$key] = 0 < $ammount ? $ammount : ''; $this->_ids['user_' . $key] = $_id; } else { $key = ($department_id ? $department_id . '_' : '') . $plan_id; $this->_common[$key] = 0 < $ammount ? $ammount : ''; $this->_ids['common_' . $key] = $_id; } } $this->setData('common', $this->_common); $this->setData('user', $this->_user); $this->setData('ids', $this->_ids); } return $this; }
/** * @param integer $id * * @Method (AJAX) */ public function editAction($id) { $form = $this->form('TimeManagerEdit'); $tmanager = $this->model('ManagerTimeSheet')->getById($id); if ($tmanager) { $form->setData($tmanager); } else { $form->setData('user_id', $id); } if ($this->request->is('POST')) { $form->handle($this->request->post); if (!$form->validate()) { return ['errors' => $form->getErrors()]; } if ($form->isSubmitted()) { $tmanager = $form->save(); $tmanager_progress = $this->model('ManagerTimeSheet')->progress($tmanager); return ['tmanager' => $tmanager, 'progress' => $tmanager_progress]; } } else { $days = []; foreach (range(0, 6) as $_d) { $days[$_d] = Calendar::weekdays($_d); } unset($days[0]); $days['0'] = Calendar::weekdays(0); $tmanager_progress = $this->model('ManagerTimeSheet')->progress($tmanager); return $this->renderPartial('tmanager/edit', ['form' => $form->createBuilder(), 'tmanager' => $tmanager, 'days' => $days, 'tmanager_progress' => $tmanager_progress, 'is_rule' => $this->is_allow]); } }
public function getByList(array $filter) { $params = []; $where = []; if (!empty($filter['month']) and !empty($filter['year'])) { $period = Calendar::getPeriodMonth($filter['year'] . '-' . $filter['month'] . '-01'); $criteria[] = "b.date >= :start:"; $criteria[] = "b.date <= :end:"; $params['start'] = $period['start']; $params['end'] = $period['end']; } if (!empty($filter['date'])) { if (is_array($filter['date']) and count($filter['date']) > 0) { if (count($filter['date']) == 1) { $filter['date'] = array_pop($filter['date']); } } if (is_array($filter['date'])) { list($start, $end) = $filter['date']; $start = date($this->format, strtotime($start)); $end = date($this->format, strtotime($end)); $criteria[] = "b.date >= :start:"; $criteria[] = "b.date <= :end:"; $params['start'] = $start; $params['end'] = $end; } else { $date = date($this->format, strtotime($filter['date'])); $criteria[] = "b.date = :date:"; $params['date'] = $date; } } if (isset($filter['user_id'])) { if (is_array($filter['user_id'])) { $criteria['user_id'] = "b.manager_id IN (:user_ids:)"; $params['user_ids'] = $filter['user_id']; } else { $criteria['user_id'] = "b.manager_id = :user_id:"; $params['user_id'] = $filter['user_id']; } } if (isset($filter['creator_id'])) { if (is_array($filter['creator_id'])) { $criteria['creator_id'] = "b.creator_id IN (:creator_ids:)"; $params['creator_ids'] = $filter['creator_id']; } else { $criteria['creator_id'] = "b.creator_id = :creator_id:"; $params['creator_id'] = $filter['creator_id']; } } if (isset($filter['is_approved'])) { if (is_array($filter['is_approved'])) { $criteria['is_approved'] = "b.is_approved IN (:is_approveds:)"; $params['is_approveds'] = $filter['is_approved']; } else { $criteria['is_approved'] = "b.is_approved = :is_approved:"; $params['is_approved'] = $filter['is_approved']; } } $where = !empty($criteria) ? "WHERE " . implode(' AND ', $criteria) : ''; $query = $this->db->newStatement("\n SELECT\n b.*,\n u.id as user_id,\n TRIM(CONCAT_WS(' ', u.lastname, u.firstname, u.secondname)) name,\n TRIM(CONCAT_WS(' ', c.lastname, c.firstname, c.secondname)) creater_name,\n TRIM(CONCAT_WS(' ', a.lastname, a.firstname, a.secondname)) approved_name\n FROM bonus b\n INNER JOIN user u ON b.manager_id = u.id\n LEFT OUTER JOIN user c ON b.creator_id = c.id\n LEFT OUTER JOIN user a ON b.approved_id = a.id\n {$where}\n ORDER BY b.date asc\n "); $query->bind($params); return $query->getAllRecords(); }
/** * update bonuses */ public function updateBonus($id = NULL) { $salary = $this->getById($id); if (null !== $salary) { $mBonus = new Bonus($this->db, $this->user); $stamp = strtotime($salary['date']); $filter = Calendar::getMonthYear($salary['date']); $filter['user_id'] = $salary['user_id']; $bonuses = $mBonus->getByList($filter); $plus = 0; $total_bonus = 0; foreach ($bonuses as $bonus) { if (Bonus::is_approved($bonus)) { if ($bonus['amount'] < 0) { $total_bonus += $bonus['amount']; // все депремирования } else { $plus += $bonus['amount']; } } } $total_bonus = round($total_bonus, -2); //ROUND до рублей $plus = round($plus, -2); //ROUND до рублей $_total = $salary['total'] + $salary['bonus'] - $salary['plus']; //чисто без Демотиваторов ! bonus в БД лежат плюсом $total = $_total + $total_bonus + $plus; //ROUND до рублей $total = round($total, -2); //ROUND до рублей $balance = $salary['balance'] + ($total - $salary['total']); $data = ['id' => $salary['id'], 'total' => $total, 'balance' => $balance, 'bonus' => -$total_bonus, 'plus' => $plus]; $this->upsert($data); } }
/** * @param integer $id * * @Method (AJAX) */ public function editorAction($id) { $employee = $this->model('EmployeeData')->getById($id); $form0 = $this->form('EmployeeEdit'); $form0->setData($employee); //Doc $doc = $this->model('EmployeeDoc')->getById($id); $docs = $this->model('EmployeeDoc')->getDocs(); $_docmap = $this->model('EmployeeDocMap')->getByUserId($id); $docmap = $this->model('EmployeeDocMap')->getMapUser($_docmap); $doc_progress = $this->model('EmployeeDoc')->progress($doc, $docmap); $form1 = $this->form('Employee\\Doc'); if (null != $doc) { $form1->setData($doc); } else { $form1->setData('user_id', $id); } //Contact $contacts = $this->model('EmployeeContact')->getGroupContacts(); $econtacts = $this->model('EmployeeContact')->getById($id); $_cmap = $this->model('EmployeeContactMap')->getByUserId($id); $cmap = $this->model('EmployeeContactMap')->getMapUser($_cmap); $contact_progress = $this->model('EmployeeContact')->progress($econtacts, $cmap); $form2 = $this->form('Employee\\Contact'); $form2->setData($employee); //department $form3 = $this->form('Employee\\Department'); $form3->setData($employee); $departments = []; $edepartments = []; foreach ($this->model('Department')->getList() as $d) { $departments[] = ['id' => $d['id'], 'name' => str_repeat(' - ', $d['level'] - 1) . $d['number'] . '. ' . $d['name']]; $edepartments[$d['id']] = $d; } //Rule $form4 = $this->form('Employee\\Codex'); $form4->setData($employee); $userrule = $this->model('Codex')->getByUser($id); $userrule = $this->model('Codex')->asArrayGroup($userrule); $disallow = [3 => 'USER_CLIENT', 17 => 'USER_WHOLESALER', 18 => 'USER_FRANCHISER']; if (isset($disallow[$employee['role_id']])) { unset($disallow[$employee['role_id']]); } $disallow = array_flip($disallow); $roles = $this->model('Codex')->getByAllowList($disallow); // Grafik $form5 = $this->form('TimeManagerEdit'); $tmanager = $this->model('ManagerTimeSheet')->getByUserId($id); $tmanager_progress = $this->model('ManagerTimeSheet')->progress($tmanager); if ($tmanager) { $form5->setData($tmanager); } else { $form5->setData('user_id', $id); } $days = []; foreach (range(1, 6) as $_d) { $days[$_d] = Calendar::weekdays($_d); } $days['0'] = Calendar::weekdays(0); $form6 = $this->form('EmployeePlanEdit'); $form6->setData('user_id', $id); $f = Calendar::getPeriodMonth(date('Y-m') . '-01'); $eplans = $this->model('EmployeePlan')->getByUserId($id, $f); $plans = $this->model('Plan')->getByGroups(); $form7 = $this->form('ESalaryAdd'); $esalary = $this->model('EmployeeSalary')->getByUserId($id); if (null != $esalary) { $form7->setData($esalary); } else { $form7->setData('user_id', $id); } return $this->renderPartial('employee/editor/base', ['employee' => $employee, 'form0' => $form0->createBuilder(), 'form1' => $form1->createBuilder(), 'doc' => $doc, 'docmap' => $docmap, 'docs' => $docs, 'doc_progress' => $doc_progress, 'form2' => $form2->createBuilder(), 'contacts' => $contacts, 'econtacts' => $econtacts, 'cmap' => $cmap, 'contact_progress' => $contact_progress, 'form3' => $form3->createBuilder(), 'departments' => $departments, 'form4' => $form4->createBuilder(), 'userrule' => $userrule, 'roles' => $roles, 'form5' => $form5->createBuilder(), 'days' => $days, 'tmanager' => $tmanager, 'tmanager_progress' => $tmanager_progress, 'form6' => $form6->createBuilder(), 'edepartments' => $edepartments, 'plans' => $plans, 'eplans' => $eplans, 'form7' => $form7->createBuilder(), 'esalary' => $esalary, 'is_rule' => 1, 'user_id' => $id]); }
public static function cluiningTime($tmanager, $timesheet = [], $workdays = [], $end_mount = NULL) { $times = []; //weekdays foreach ($tmanager as $_tmanager) { $period_start = strtotime($_tmanager['since']); $period_end = strtotime(\Arr::get($_tmanager, 'till', $end_mount . ' 23:59:59')); foreach ($workdays as $_wodrk_day) { $notclose = false; $recast = 0; if (strtotime($_wodrk_day) < time()) { $sheet = \Arr::get($timesheet, $_wodrk_day, NULL); if ($sheet) { $stamp = strtotime($sheet['start']); $stamp_end = strtotime($sheet['finish']); $w = date('w', $stamp); $time = strtotime(date('H:i:s', $stamp)); $finish_day = date('Y-m-d', $stamp_end); if ($finish_day != $_wodrk_day) { $d = strtotime($finish_day) - strtotime($_wodrk_day); // //$time = null; //$finish = null; if ($d > 0) { $notclose = true; } } else { $finish = strtotime(date('H:i:s', $stamp)); } $time_work = $finish - $time; $hour = $time_work / 3600; $hour = ceil($hour / 0.5) * 0.5; $timetable_start = \Arr::get($_tmanager, 's' . $w, 0); $timetable_end = \Arr::get($_tmanager, 'e' . $w, 0); if (!empty($timetable_start) and !empty($timetable_end)) { if ($stamp > $period_start and $stamp < $period_end) { //входит в отрезок //recast if ($time > 0) { $recast_before = strtotime($timetable_start) - $time; if ($recast_before > 0) { $recast += floor($recast_before / 3600); } } if ($finish > 0) { $recast_after = $finish - strtotime($timetable_end); if ($recast_after > 0) { $recast += floor($recast_after / 3600); } } $times[$_wodrk_day] = ['day' => $w, 'lang' => Calendar::weekdays($w), 'date' => $_wodrk_day, 'start' => $sheet['start'], 'finish' => $sheet['finish'], 's' => $timetable_start, 'e' => $timetable_end, 'hour' => $hour, 'notclose' => $notclose, 'recast' => $recast]; unset($timesheet[$_wodrk_day]); } } } else { $stamp = strtotime($_wodrk_day); $w = date('w', $stamp); $timetable_start = \Arr::get($_tmanager, 's' . $w, NULL); $timetable_end = \Arr::get($_tmanager, 'e' . $w, NULL); if ($timetable_start) { if ($stamp > $period_start and $stamp < $period_end) { //входит в отрезок $times[$_wodrk_day] = ['day' => $w, 'lang' => Calendar::weekdays($w), 'date' => $_wodrk_day, 'late' => $timetable_start, 'start' => 0, 'finish' => 0, 's' => $timetable_start, 'e' => $timetable_end]; } } } } else { } } } /** обработаем выходные дни */ if (!empty($timesheet)) { foreach ($tmanager as $_tmanager) { $period_start = strtotime($_tmanager['since']); $period_end = strtotime(\Arr::get($tmanager, 'till', $end_mount . ' 23:59:59')); foreach ($timesheet as $sheet) { if ($sheet) { $stamp = strtotime($sheet['start']); $stamp_end = strtotime($sheet['finish']); $w = date('w', $stamp); $time = strtotime(date('H:i:s', $stamp)); $finish = strtotime(date('H:i:s', $stamp_end)); $timetable_start = \Arr::get($_tmanager, 's' . $w, NULL); $timetable_end = \Arr::get($_tmanager, 'e' . $w, NULL); if ($stamp > $period_start and $stamp < $period_end) { //входит в отрезок $_wodrk_day = date('Y-m-d', $stamp); $time_work = $finish - $time; $hour = $time_work / 3600; $hour = ceil($hour / 0.5) * 0.5; $times[$_wodrk_day] = ['day' => $w, 'lang' => Calendar::weekdays($w), 'date' => $_wodrk_day, 'start' => $sheet['start'], 'finish' => $sheet['finish'], 's' => $timetable_start, 'e' => $timetable_end, 'hour' => $hour]; } } } } } ksort($times); return $times; }
/** * @acesss (SALARY_SHEET) * @Method (!AJAX) */ public function generateAction() { $content = ''; $query = $this->request->query->all(); $year = \Arr::get($query, 'year', 2015); $month = \Arr::get($query, 'month', 0); $month = intval($month); $months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; if ($month) { $index = array_search($month, $months); if (false !== $index) { $index++; $next = \Arr::get($months, $index, 0); if ($next) { $ids = []; $filter = Calendar::getPeriodMonth($year . '-' . $month . '-01'); foreach ($this->model('Employee')->getByListFull($filter) as $employee) { $ids[$employee['user_id']] = $employee['user_id']; } $calculate = $this->model('Calculate')->init($month, $year, NULL, $ids, true); $update = $calculate->updateFact(); $content .= '<p>Обновлены фактические значения за ' . $month . '-' . $year . '</p>'; $content .= '<a href="/admin/employee/plansheet/generate?month=' . $next . '">Сгенерировать следующий месяц</a>'; } else { $content .= 'Обновлены фактические показватели все заданные месяцы 2015'; } } } return $this->render('generate', ['content' => $content]); }