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 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; }
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; }
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(); }
/** * @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]); }
/** * @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]); }