diff --git a/src/components/history/HistoryDetail.php b/src/components/history/HistoryDetail.php index 29a28ea1e393016b813e68b6ec4887d328d62a94..b64632f2c87b5789e2b50b2a599f28c298b8fb4e 100644 --- a/src/components/history/HistoryDetail.php +++ b/src/components/history/HistoryDetail.php @@ -17,24 +17,28 @@ <div class="container"> <?php // TODO : fetch from REST - $history = ['courierName' => "jamal", 'shippingCost' => 2, 'rating' => 0, 'historyId' => 1]; - $productDetails = [ - ["productName" => "pisau cukur", "quantity" => 69], - ["productName" => "ivan gunawan", "quantity" => 420], - ["productName" => "pisau cukur 2", "quantity" => 692], - ["productName" => "ivan gunawan 2", "quantity" => 4202], - ]; + // var_dump($this->data); + $history = $this->data['history']; + $productDetails = $this->data['details']; + $kurir = $this->data['kurir']; ?> <label>Nama Kurir : </label> - <p><?=$history['courierName']?></p> + <p><?=$kurir['name']?></p> <label>Biaya ongkir : </label> - <p><?=$history['shippingCost']?></p> + <p><?=$history['biaya_pengiriman']?></p> <label>Rating : </label> <p><?=($history['rating'] === 0) ? 'belum memberi rating' : $history['rating']?></p> <?php if($history['rating'] === 0) { - // TODO : giving rating + $id = $history['id'] ; + $temp = ' + <form action="/HistoryDetail" method="POST"> + <input type="number" name="rating" min="1" max="5"> + <input type="hidden" name="idPesanan" value=' . $id . '> + <input type="submit" value="Submit"> + </form>'; + echo $temp; } ?> @@ -46,7 +50,7 @@ </tr> <?php foreach ($productDetails as $product) { ?> <tr> - <td><?php echo $product['productName']; ?></td> + <td><?php echo $product['product_name']; ?></td> <td><?php echo $product['quantity']; ?></td> </tr> <?php } ?> diff --git a/src/controller/history/HistoryDetailController.php b/src/controller/history/HistoryDetailController.php index 4689df31d5eedceb1854a1b00e0ca2327b0dd0f5..6cc7b0e88bb364b8a1d836f7a734930ae681493c 100644 --- a/src/controller/history/HistoryDetailController.php +++ b/src/controller/history/HistoryDetailController.php @@ -1,7 +1,58 @@ <?php +require_once __DIR__ . '/../../rest/Rest.php'; class HistoryDetailController extends Controller{ public function index($id = 0) { - $this->render(); + Rest::setEndpoint('history/detail/'.$id); + Rest::setOption('GET', null); + + $detail = Rest::call(); + + + Rest::setEndpoint('history/history/'.$id); + Rest::setOption('GET', null); + + $history = Rest::call(); + + + $detail = json_decode($detail, true); + $history = json_decode($history, true); + + Rest::setEndpoint('user/user-details/id/'.$history['user_id']); + Rest::setOption('GET', null); + + $kurir = Rest::call(); + // var_dump($kurir); + + $kurir = json_decode($kurir, true); + $data =[ + 'history' => $history, + 'details' => $detail, + 'kurir'=> $kurir + ]; + + $this->render($data); + } + + public function post(){ + $id = $_POST['idPesanan']; + $rating = $_POST['rating']; + + Rest::setEndpoint('history/rating/'.$id); + + $data = [ + 'rating' => intval($rating) + ]; + + Rest::setOption('PUT', $data); + + $result = json_decode(Rest::call(), true); + + if($result == "success"){ + header("Location: /History"); + }else{ + echo $result; + } + } } \ No newline at end of file