Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
| 2 | class export { |
| 3 | const FORMAT_PDF = 1; |
| 4 | const FORMAT_DETAILEDPDF = 2; |
| 5 | const FORMAT_CSV_SCHEDULES = 3; |
| 6 | const FORMAT_CSV_INCIDENTS = 4; |
| 7 | |
| 8 | public static $formats = array( |
| 9 | 1 => "PDF con horario laboral", |
| 10 | 2 => "PDF detallado", |
| 11 | 3 => "CSV con horarios", |
| 12 | 4 => "CSV con incidencias" |
| 13 | ); |
| 14 | public static $workerFormats = [1, 3, 4]; |
| 15 | |
| 16 | public static $schedulesFields = ["id", "worker", "workerid", "dni", "company", "day", "beginswork", "endswork", "beginsbreakfast", "endsbreakfast", "beginslunch", "endslunch", "state"]; |
| 17 | public static $incidentsFields = ["id", "worker", "workerid", "dni", "company", "creator", "updated", "updatedby", "confirmedby", "type", "day", "allday", "begins", "ends", "details", "workerdetails", "verified", "typepresent", "typepaid", "state"]; |
| 18 | |
| 19 | public static function convert($str) { |
| 20 | return iconv('UTF-8', 'windows-1252', $str); |
| 21 | } |
| 22 | |
| 23 | public static function getDays($worker, $begins, $ends, $showvalidated, $shownotvalidated) { |
| 24 | $return = []; |
| 25 | |
| 26 | $records = registry::getRecords($worker, $begins, $ends, false, false, false, 0, 0); |
| 27 | if ($records === false) return false; |
| 28 | foreach ($records as $record) { |
| 29 | if (!$showvalidated && $record["state"] === registry::STATE_VALIDATED_BY_WORKER) continue; |
| 30 | if (!$shownotvalidated && $record["state"] === registry::STATE_REGISTERED) continue; |
| 31 | if (!isset($return[$record["day"]])) $return[$record["day"]] = []; |
| 32 | $return[$record["day"]]["schedule"] = $record; |
| 33 | } |
| 34 | |
| 35 | $incidents = incidents::getAll(false, 0, 0, $worker, $begins, $ends); |
| 36 | if ($incidents === false) return false; |
| 37 | foreach ($incidents as $incident) { |
| 38 | if ($incident["state"] !== incidents::STATE_REGISTERED && $incident["state"] !== incidents::STATE_VALIDATED_BY_WORKER) continue; |
| 39 | if (!$showvalidated && $incident["state"] === incidents::STATE_VALIDATED_BY_WORKER) continue; |
| 40 | if (!$shownotvalidated && $incident["state"] === incidents::STATE_REGISTERED) continue; |
| 41 | if (!isset($return[$incident["day"]])) $return[$incident["day"]] = []; |
| 42 | if (!isset($return[$incident["day"]]["incidents"])) $return[$incident["day"]]["incidents"] = []; |
| 43 | $return[$incident["day"]]["incidents"][] = $incident; |
| 44 | } |
| 45 | |
| 46 | ksort($return); |
| 47 | |
| 48 | return $return; |
| 49 | } |
| 50 | |
| 51 | public static function sec2hours($sec) { |
| 52 | return round((double)$sec/3600, 2)." h"; |
| 53 | } |
| 54 | } |