Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
Adrià Vilanova Martínez | 5af8651 | 2023-12-02 20:44:16 +0100 | [diff] [blame^] | 2 | /* |
| 3 | * hores |
| 4 | * Copyright (c) 2023 Adrià Vilanova Martínez |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as |
| 8 | * published by the Free Software Foundation, either version 3 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public |
| 17 | * License along with this program. |
| 18 | * If not, see http://www.gnu.org/licenses/. |
| 19 | */ |
| 20 | |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 21 | class export { |
| 22 | const FORMAT_PDF = 1; |
| 23 | const FORMAT_DETAILEDPDF = 2; |
| 24 | const FORMAT_CSV_SCHEDULES = 3; |
| 25 | const FORMAT_CSV_INCIDENTS = 4; |
| 26 | |
| 27 | public static $formats = array( |
| 28 | 1 => "PDF con horario laboral", |
| 29 | 2 => "PDF detallado", |
| 30 | 3 => "CSV con horarios", |
| 31 | 4 => "CSV con incidencias" |
| 32 | ); |
| 33 | public static $workerFormats = [1, 3, 4]; |
| 34 | |
| 35 | public static $schedulesFields = ["id", "worker", "workerid", "dni", "company", "day", "beginswork", "endswork", "beginsbreakfast", "endsbreakfast", "beginslunch", "endslunch", "state"]; |
| 36 | public static $incidentsFields = ["id", "worker", "workerid", "dni", "company", "creator", "updated", "updatedby", "confirmedby", "type", "day", "allday", "begins", "ends", "details", "workerdetails", "verified", "typepresent", "typepaid", "state"]; |
| 37 | |
| 38 | public static function convert($str) { |
| 39 | return iconv('UTF-8', 'windows-1252', $str); |
| 40 | } |
| 41 | |
| 42 | public static function getDays($worker, $begins, $ends, $showvalidated, $shownotvalidated) { |
| 43 | $return = []; |
| 44 | |
| 45 | $records = registry::getRecords($worker, $begins, $ends, false, false, false, 0, 0); |
| 46 | if ($records === false) return false; |
| 47 | foreach ($records as $record) { |
| 48 | if (!$showvalidated && $record["state"] === registry::STATE_VALIDATED_BY_WORKER) continue; |
| 49 | if (!$shownotvalidated && $record["state"] === registry::STATE_REGISTERED) continue; |
| 50 | if (!isset($return[$record["day"]])) $return[$record["day"]] = []; |
| 51 | $return[$record["day"]]["schedule"] = $record; |
| 52 | } |
| 53 | |
| 54 | $incidents = incidents::getAll(false, 0, 0, $worker, $begins, $ends); |
| 55 | if ($incidents === false) return false; |
| 56 | foreach ($incidents as $incident) { |
| 57 | if ($incident["state"] !== incidents::STATE_REGISTERED && $incident["state"] !== incidents::STATE_VALIDATED_BY_WORKER) continue; |
| 58 | if (!$showvalidated && $incident["state"] === incidents::STATE_VALIDATED_BY_WORKER) continue; |
| 59 | if (!$shownotvalidated && $incident["state"] === incidents::STATE_REGISTERED) continue; |
| 60 | if (!isset($return[$incident["day"]])) $return[$incident["day"]] = []; |
| 61 | if (!isset($return[$incident["day"]]["incidents"])) $return[$incident["day"]]["incidents"] = []; |
| 62 | $return[$incident["day"]]["incidents"][] = $incident; |
| 63 | } |
| 64 | |
| 65 | ksort($return); |
| 66 | |
| 67 | return $return; |
| 68 | } |
| 69 | |
| 70 | public static function sec2hours($sec) { |
| 71 | return round((double)$sec/3600, 2)." h"; |
| 72 | } |
| 73 | } |