forked from jefyokta/kamela2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bfd3394
Showing
127 changed files
with
14,179 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/vendor | ||
/node_modules | ||
.env | ||
./public/models/*.glb | ||
./public/models/*.gltf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
POST http://localhost:8000/login HTTP/1.1 | ||
|
||
{ | ||
"username":"jefyokta", | ||
"password":"123" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# kamela2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
use Swoole\Coroutine; | ||
|
||
class Command | ||
{ | ||
public function handle(array $argument) | ||
{ | ||
|
||
switch ($argument[1]) { | ||
case 'start': | ||
|
||
require_once __DIR__ . "/../../index.php"; | ||
break; | ||
|
||
case 'make': | ||
Coroutine::run(function () use ($argument) { | ||
$this->make($argument[2], $argument[3]); | ||
}); | ||
break; | ||
case "test": | ||
$test = require __DIR__ . "/../Test/Test.php"; | ||
$test->run(); | ||
break; | ||
default: | ||
# code... | ||
break; | ||
} | ||
} | ||
|
||
public function make(string $kind, string $name = null) | ||
{ | ||
|
||
switch ($kind) { | ||
case 'controller': | ||
$data = | ||
"<?php | ||
namespace Kamela\\Controller; | ||
use Oktaax\\Http\\Request; | ||
use Oktaax\\Http\\Response; | ||
class {$name}Controller | ||
{ | ||
public function index(Request \$req, Response \$res) | ||
{ | ||
\$res->end(\"Hello World \"); | ||
} | ||
}"; | ||
Coroutine::writeFile(__DIR__ . "/../Controllers/{$name}Controller.php", $data); | ||
break; | ||
|
||
default: | ||
# code... | ||
break; | ||
} | ||
} | ||
|
||
private function handleEmptyMake($kind) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<?php | ||
|
||
namespace Kamela\Controller; | ||
|
||
use Kamela\Models\Guest; | ||
use Kamela\Models\House; | ||
use Oktaax\Console; | ||
use Oktaax\Http\Request; | ||
use Oktaax\Http\Response; | ||
use Swoole\Coroutine; | ||
use Swoole\Coroutine\Channel; | ||
|
||
class AdminController | ||
{ | ||
public function index(Request $req, Response $res) | ||
{ | ||
$monthly = $this->monthly(); | ||
$type36 = (object) $this->soldAndUnsold("type36"); | ||
$type45 = (object) $this->soldAndUnsold("type45"); | ||
$type66 = (object) $this->soldAndUnsold("type66"); | ||
$allhouses = (object) $this->soldAndUnsold(); | ||
$method = $this->mothlymethod(); | ||
|
||
$lastMonth = Guest::raw( | ||
"SELECT * FROM tamu | ||
WHERE MONTH(created_at) = MONTH(CURDATE() - INTERVAL 1 MONTH) | ||
AND YEAR(created_at) = YEAR(CURDATE() - INTERVAL 1 MONTH);" | ||
)->run(true) ?? 0; | ||
|
||
$increment = $this->increment($monthly, $lastMonth); | ||
|
||
$request = $req; | ||
|
||
$res->render("admin.pages.index", compact("request", "monthly", "type36", "type45", "type66", "allhouses", "method", "increment")); | ||
} | ||
|
||
public function guest(Request $req, Response $res) | ||
{ | ||
$guest = Guest::select("*"); | ||
|
||
if ($req->get['filter'] == null) { | ||
$guest = $guest; | ||
} else { | ||
if ($req->get['filter'] ?? false) { | ||
$data['guest'] = $guest->where("status", '=', $req->get['filter']); | ||
$data['checked'] = $req->get['filter']; | ||
} elseif (!$req->get['filter'] ?? false && $req->queryHas('q')) { | ||
$guest->where("name", "LIKE", $req->get['q']); | ||
$req->get['filter'] ?? null; | ||
} elseif ($req->get['filter'] ?? false && $req->queryHas('q')) { | ||
$data['guest'] = $guest->where("status", '=', $req->get['filter'])->andWhere("", "LIKE", $req->get['q']); | ||
$data['checked'] = $req->get['filter']; | ||
} else { | ||
$data['checked'] = $req->get['filter'] ?? null; | ||
$guest = $guest; | ||
} | ||
} | ||
|
||
$data['guest'] = $guest->get(); | ||
$request = $req; | ||
$res->render("admin.pages.guest", compact("data", "request")); | ||
} | ||
|
||
public function house(Request $req, Response $res) | ||
{ | ||
$request = $req; | ||
$get = $req->get; | ||
$houses = House::select("rumah.* , (type.price + rumah.kelebihan * type.kelebihanfee + | ||
CASE WHEN rumah.kelebihan != 0 THEN 1000000 ELSE 0 END) AS price")->join("type", "type.id = rumah.type"); | ||
if (empty($get['search'])) { | ||
if (!empty($get['type']) && empty($get['filter'])) { | ||
$houses = $houses->where('type', '=', $get['type']); | ||
} elseif (empty($get['type']) && !empty($get['filter'])) { | ||
$houses = $houses->where('status', '=', $get['filter']); | ||
} elseif (!empty($get['type']) && !empty($get['filter'])) { | ||
$houses = $houses->where("type", '=', $get['type'])->andWhere("status", "=", $get['filter']); | ||
} else { | ||
$houses = $houses; | ||
} | ||
} else { | ||
$houses = $houses->where("blok", "LIKE", "%" . $get['search'] . "%"); | ||
} | ||
$houses = $houses->get(); | ||
|
||
$search = $get['search'] ?? ""; | ||
$res->render("admin.pages.house", compact("houses", "request", "search")); | ||
} | ||
|
||
public function document(Request $request, Response $response) | ||
{ | ||
|
||
|
||
$doc = $request->get['f']; | ||
|
||
if (!file_exists(storagePath("/private/docs/$doc"))) { | ||
return $response->status(404)->end("Document $doc not found!"); | ||
} else { | ||
$response->sendfile(storagePath("/private/docs/$doc")); | ||
} | ||
} | ||
private function monthly() | ||
{ | ||
return Guest::raw("SELECT * FROM tamu WHERE MONTH(created_at) = MONTH(CURDATE()) AND YEAR(created_at) = YEAR(CURDATE());")->run(true) ?? 0; | ||
} | ||
|
||
private function mothlymethod() | ||
{ | ||
return Guest::raw("SELECT * FROM tamu WHERE metode = 1 AND MONTH(created_at) = MONTH(CURDATE()) AND YEAR(created_at) = YEAR(CURDATE());")->run(true) ?? 0; | ||
} | ||
|
||
private function soldAndUnsold($type = null): array | ||
{ | ||
|
||
if (is_null($type)) { | ||
$unsold = House::select("*")->where("status", '!=', 400)->run(true) ?? 0; | ||
$sold = House::select("*")->where("status", '=', 400)->run(true) ?? 0; | ||
$booked = House::select("*")->where("status", '=', 300)->run(true) ?? 0; | ||
return ["sold" => $sold, "unsold" => $unsold, "booked" => $booked]; | ||
|
||
|
||
// Coroutine::run(function () { | ||
// $chan = new Channel(3); | ||
|
||
// go(function () use ($chan) { | ||
// $unsold = House::select("*")->where("status", '!=', 400)->run(true) ?? 0; | ||
// $chan->push(['unsold' => $unsold]); | ||
// }); | ||
|
||
// go(function () use ($chan) { | ||
// $sold = House::select("*")->where("status", '=', 400)->run(true) ?? 0; | ||
// $chan->push(['sold' => $sold]); | ||
// }); | ||
|
||
// go(function () use ($chan) { | ||
// $booked = House::select("*")->where("status", '=', 300)->run(true) ?? 0; | ||
// $chan->push(['booked' => $booked]); | ||
// }); | ||
|
||
// $results = []; | ||
// for ($i = 0; $i < 3; $i++) { | ||
// $results[] = $chan->pop(); | ||
// } | ||
|
||
// $chan->close(); | ||
|
||
// $finalResults = []; | ||
// foreach ($results as $result) { | ||
// $finalResults = array_merge($finalResults, $result); | ||
// } | ||
|
||
// return $finalResults; // Mengembalikan hasil akhir | ||
// }); | ||
} else { | ||
|
||
$unsold = House::select("*")->where("type", '=', $type)->andWhere("status", '!=', 400)->run(true) ?? 0; | ||
$sold = House::select("*")->where("type", '=', $type)->andWhere("status", '=', 400)->run(true) ?? 0; | ||
$booked = House::select("*")->where("type", '=', $type)->andWhere("status", '=', 300)->run(true) ?? 0; | ||
|
||
return ["sold" => $sold, "unsold" => $unsold, "booked" => $booked]; | ||
} | ||
} | ||
|
||
private function increment($cur, $lastMonth) | ||
{ | ||
Console::log("Current: " . $cur . " (type: " . gettype($cur) . ")"); | ||
Console::log("Last Month: " . $lastMonth . " (type: " . gettype($lastMonth) . ")"); | ||
try { | ||
if ($cur === 0) { | ||
Console::log("Current is zero, returning -100%"); | ||
return -100; | ||
} else if (empty($lastMonth) || !is_numeric($lastMonth) || $lastMonth == 0) { | ||
return 0; | ||
} elseif ($cur !== 0 && $lastMonth !== 0) { | ||
$result = (($cur - $lastMonth) / $lastMonth) * 100; | ||
return $result; | ||
} else { | ||
return 0; | ||
} | ||
} catch (\Throwable $th) { | ||
//throw $th; | ||
Console::log($th->getMessage() . " " . $th->getLine()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Kamela\Controller; | ||
|
||
use Oktaax\Http\Request; | ||
use Oktaax\Http\Response; | ||
use Swoole\Coroutine; | ||
|
||
class DownloaderController | ||
{ | ||
public function index(Request $req, Response $res) | ||
{ | ||
if ($req->request->get["f"] ?? false) { | ||
$fileName = $req->request->get["f"]; | ||
$file = file_exists(storagePath("docs/" . $fileName)); | ||
if (!$file) { | ||
$res->status(404)->end("requested file's not found"); | ||
} else { | ||
$res->sendfile(storagePath("docs/" . $fileName)); | ||
} | ||
} else { | ||
$res->status(400)->end('file name is required'); | ||
} | ||
} | ||
} |
Oops, something went wrong.