51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?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];
|
|
}
|
|
} |