<?php 
    session_start();
    include "../modules/Class/autoload.php";   
?>

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>РБДА</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="РБДА" name="description" />
    <meta content="Themesdesign" name="author" />
    <!-- App favicon -->
    <link rel="shortcut icon" href="../assets/images/nerufavicon.png">
    <!-- Bootstrap Css -->
    <link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- Icons Css -->
    <link href="../assets/css/icons.min.css" rel="stylesheet" type="text/css" />
    <!-- App Css-->
    <link href="../assets/css/app.min.css" rel="stylesheet" type="text/css" />

</head>

<body data-sidebar="dark">

    <!-- Begin page -->
    <div id="layout-wrapper">        
        <?php include "header.php";?>
        <!-- ========== Left Sidebar Start ========== -->
        <?php include "menu.php"?>
        <!-- Left Sidebar End -->

        <!-- ============================================================== -->
        <!-- Start right Content here -->
        <!-- ============================================================== -->
        <div class="main-content">
            <div class="page-content">
                <div class="container-fluid">
                    <!-- start page title -->
                    <div class="row">
                        <div class="col-12">
                            <div class="page-title-box d-flex align-items-center justify-content-between">
                                <h4 class="mb-0 font-size-18">Поиск штрафов</h4>
                            </div>
                        </div>
                    </div>
                    <!-- end page title -->
                    <div class="card">
                        <div class="card-body">
                            <div class="p-lg-3">
                                <div class="col-md-3">
                                <form method="post"  action="searchfiness.php">

                                    <div class="form-group">
                                        <label for="my-input">Введите номер автомобиля</label>
                                        <?php if (isset($_REQUEST['plate'])){$startplate = $_REQUEST['plate']; }else{$startplate='';}?>
                                        <input value="<?=strtoupper($startplate)?>" id="my-input" required class="form-control" type="text" name="plate" pattern="\d{3,4}[A-z]{2}\d{2}|\d{2}[A-z]{1}\d{4}[A-z]{1}|[A-z]{1}\d{3}[A-z]{2}\d{3}|\d{2}[A-z]{2}\d{4}|\d{4}[A-z]{2}\d{2}|\d{3}[A-z]{2}\d{2}|\d{3}[A-z]{1}\d{2}|\d{3}[A-z]{1}|\d{2}[A-z]{2}\d{4}|\d{3}[A-z]{1}\d{2}|[A-z]{1}\d{6}|\d{3}[A-z]{3}\d{1}|\d{3}[A-z]{1}\d{3}|\d{3}[A-z]{1}\d{2}|[A-z]{1}\d{5}|\d{3}[A-z]{2}\d{3}\d{2}[A-z]{1}\d{4}[A-z]{1}" title="0000XX01 || 000XX01">
                                    </div>
                                    <div class="form-group">
                                        <button name="srchfines" class="btn btn-primary" type="submit">Поиск</button>
                                    </div>
                                </form> 
                                </div>
                                             
                            </div>
                        <!--end card body-->
                    </div> <!-- end card-->
                </div> <!-- container-fluid -->
                <?php 
                
                    if(isset($_REQUEST['srchfines'])){

                        $url = '217.11.177.108:9907/Fines/api/rbdaapi/index.php';
                        $secret = 'shohinnewkey';
                        $inputdate = date('ymdHis');
                        $plate = filterdb($_REQUEST['plate']);
                        $data = [
                            "action"=>"fines",
                            "inputdate"=>$inputdate,
                            "plate"=>$plate,
                            "sign"=>md5('fines'.$plate.$inputdate.$secret)
                        ];
                        $jsondata = json_encode($data);
                        //echo $jsondata;
                        $sendcurl = sendcurl($jsondata,$url);
                        $arraydata = customjsondecode($sendcurl);     
                        // dd($arraydata);                      
                        if(@$arraydata['code']=='103'){
                            echo '
                            <div class="alert alert-primary" role="alert">
                                У автомобиля <u>'.strtoupper($plate).'</u> не обнаружены нарушения.<br> <a target="_blank" href="qrcode.php?plate='.$plate.'&sign='.md5('myandbdasecrettoday'.$plate).'">Напечатать справку</a>
                            </div>
                            ';
                            return;
                        }
                ?>
                
                <div class="card">
                        <div class="card-body">
                            <div class="p-lg-3">
                                <div class="col-md-3">
                                    <div class="alert alert-primary" role="alert">
                                        Номер автомобиля: <u> <?=strtoupper($plate)?></u><br>
                                        Кол-во штрафов: <u> <?=$arraydata[0]['totalkol']?></u><br>
                                        Общая сумма: <u> <?=$arraydata[0]['totalsumma']?> смн</u> <br>
                                        <form method="post" target="_blank" action="qrforpaytest.php">
                                            <input type="hidden" name="summa" value="<?=$arraydata[0]['totalsumma']?>">
                                            <input type="hidden" name="plate" value="<?=$plate?>">
                                            <button style="margin-top: 2px;" class="btn btn-success" type="submit">Оплатить все штрафы на  <?=$arraydata[0]['totalsumma']?> смн</button> 
                                        </form>
                                        
                                    </div>
                                    <hr>
                                    
                                </div>
                                <div class="col" style="overflow-x:auto ;">
                                <table class="table table-light">
                                        <thead class="thead-light">
                                            <tr>
                                                <th>№</th>
                                                <th>Ордер штрафа</th>
                                                <th>Номер автомобиля</th>
                                                <th>Дата</th>
                                                <th>Штраф</th>
                                                <th>Сумма</th>
                                                <th>Фото 1</th>
                                                <th>Фото 2</th>
                                                <th>Доп фото</th>
                                                <th>Видео</th>
                                                <th>Оплата</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $i=1; foreach ($arraydata as $value) { ?>
                                                <tr>
                                                    <td><?=$i ?></td>
                                                    <td><?=$value['orderid'] ?></td>
                                                    <td><?=strtoupper($plate)?></td>
                                                    <td><?=$value['finedate']?></td>
                                                    <td><?=$value['finename']?></td>
                                                    <td><?=$value['summa']?> смн</td>
                                                    <td> <a target="_blank" href="<?=$value['photo']?>" ><span class="badge badge-primary">Посмотреть</span></a></td>
                                                    <td><a target="_blank" href="<?=$value['metaPlate']?>"><span class="badge badge-primary">Посмотреть</span></a></td>
                                                    <td><a target="_blank" href="<?=$value['additionalPhoto']?>"><span class="badge badge-primary">Посмотреть</span></a></td>
                                                    <td><a target="_blank" href="<?=$value['video']?>"><span class="badge badge-primary">Посмотреть</span></a></td>
                                                    <td>
                                                        <form method="post" target="_blank"   action="qrforpaytest.php">
                                                            <input type="hidden" name="summa" value="<?=$value['summa']?>">
                                                            <input type="hidden" name="plate" value="<?=$value['orderid']?>">
                                                            <button style="margin-top: 2px;" class="btn btn-success" type="submit">Оплатить <?=$arraydata[0]['totalsumma']?> смн</button> 
                                                        </form>
                                                    </td>
                                                </tr>
                                            <?php $i++; } ?>
                                        </tbody>
                                       
                                    </table>
                                </div>
                                
                                    
                                                                             
                            </div>
                        <!--end card body-->
                    </div> <!-- end card-->
                </div> <!-- container-fluid -->
                <?php } ?>


            </div>
            <!-- End Page-content -->
        </div>
        <!-- end main content-->

    </div>
    <!-- END layout-wrapper -->

    <!-- JAVASCRIPT -->
    <script src="../assets/libs/jquery/jquery.min.js"></script>
    <script src="../assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="../assets/libs/metismenu/metisMenu.min.js"></script>
    <script src="../assets/libs/simplebar/simplebar.min.js"></script>
    <script src="../assets/libs/node-waves/waves.min.js"></script>

    <script src="../assets/js/app.js"></script>
    <script src="../assets/js/myjs.js"></script>

</body>

</html>