Added InvoiceJob

This commit is contained in:
Frank Schubert
2024-08-29 14:51:37 +02:00
parent 248013423d
commit 1ed2dddb97
13 changed files with 1051 additions and 30 deletions

View File

@@ -0,0 +1,51 @@
<?php
class InvoiceJobController extends mfBaseController {
protected function init() {
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function apiAction() {
if(!$this->me->is(["Admin"])) {
$this->redirect("Dashboard");
}
$do = $this->request->do;
$data = [];
switch($do) {
case "getActiveJobs":
$return = $this->getActiveJobsApi();
break;
default:
$return = false;
}
if(!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
private function getActiveJobsApi() {
$now = new DateTime("now");
$jobs = [];
foreach(InvoiceJobModel::search(["to_date>=" => $now->format("Y-m-d")]) as $job) {
$j = $job->data;
$j->id = $job->id;
$jobs[] = $j;
}
return ["jobs" => $jobs];
}
}