<?php

use Slim\Http\Request;
use Slim\Http\Response;

// Routes

$app->get('/[{name}]', function (Request $request, Response $response, array $args) {
    // Sample log message
    $this->logger->info("Slim-Skeleton '/' route");

    // Render index view
    return $this->renderer->render($response, 'index.phtml', $args);
});



$app->get("/rekap_penjualan_harian/", function (Request $request, Response $response){
    $sql = "SELECT * FROM vrkp_jual_harian";
    $stmt = $this->db->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetch();
    return $response->withJson(["status" => "success", "data" => $result], 200);
});

$app->get("/rekap_penjualan_harian2/{dtanggal}", function (Request $request, Response $response, $args){
    //$dtanggal = $args["dtanggal"];
    $dtanggal = $request->getQueryParam("dtanggal");
    $sql = "SELECT * FROM vrkp_jual_harian WHERE jual_tanggalorder = '".$dtanggal."'";
    echo $sql; 
    $stmt = $this->db->prepare($sql);
    $stmt->execute([":dtanggal" => $dtanggal]);
    $result = $stmt->fetch();
    return $response->withJson(["status" => "success", "data" => $result], 200);
});

$app->get("/rekap/jual/", function (Request $request, Response $response, $args){
    $dtanggal = $request->getQueryParam("dtanggal");
    $sql = "SELECT * FROM vrkp_jual_harian WHERE jual_tanggalorder = '$dtanggal'";

    $stmt = $this->db->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll();
    return $response->withJson($result);
});

$app->get("/dokter/", function (Request $request, Response $response){
    $sql = "SELECT dokter_nama FROM mst_dokter";
    $stmt = $this->db->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll();
    return $response->withJson(["status" => "success", "data" => $result], 200);
});

$app->get("/books/{id}", function (Request $request, Response $response, $args){
    $id = $args["id"];
    $sql = "SELECT * FROM books WHERE book_id=:id";
    $stmt = $this->db->prepare($sql);
    $stmt->execute([":id" => $id]);
    $result = $stmt->fetch();
    return $response->withJson(["status" => "success", "data" => $result], 200);
});

$app->get("/sekolah/", function (Request $request, Response $response){
    $sql = "SELECT * FROM mst_sekolah";
    $stmt = $this->db->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll();
    return $response->withJson(["status" => "success", "data" => $result], 200);
});

$app->get("/sekolah/{id}", function (Request $request, Response $response, $args){
    $id = $args["id"];
    $sql = "SELECT * FROM mst_sekolah WHERE sek_id=:id";
    $stmt = $this->db->prepare($sql);
    $stmt->execute([":id" => $id]);
    $result = $stmt->fetch();
    return $response->withJson(["status" => "success", "data" => $result], 200);
});