<?php
require_once($_SERVER['DOCUMENT_ROOT']."/erm/base/sales.php");
require_once($_SERVER['DOCUMENT_ROOT']."/erm/config/config.php");
session_start();
//$_SESSION['scdoc'] = 0;
if(isset($_POST['add'])){
    if(!isset($_SESSION['scdoc'])){
        $docID= docID();
    }
    
    $userID = 1;
    salesCart($_POST['productID'],$_POST['quantity'], $_POST['rate'],$_POST['customerID'], $_POST['vat'], $_POST['discount'], $docID, $userID);
   

    $_SESSION['scdoc'] = $docID;
    $_SESSION['Ccustomer'] = $_POST['customerID'];
}


?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <link href="img/logo/logo.png" rel="icon">
  <title>RuangAdmin - Simple Tables</title>
  <link href="/erm/views/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="/erm/views/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
  <link href="/erm/views/css/ruang-admin.min.css" rel="stylesheet">
  <!-- Select2 -->
  <link href="/erm/views/vendor/select2/dist/css/select2.min.css" rel="stylesheet" type="text/css">
  <!-- Bootstrap DatePicker -->  
  <link href="/erm/views/vendor/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" >
  <!-- Bootstrap Touchspin -->
  <link href="/erm/views/vendor/bootstrap-touchspin/css/jquery.bootstrap-touchspin.css" rel="stylesheet" >
  <!-- ClockPicker -->
  <link href="/erm/views/vendor/clock-picker/clockpicker.css" rel="stylesheet">
  <!-- RuangAdmin CSS -->
</head>

<body id="page-top">
  <div id="wrapper">
    <!-- Sidebar -->
    <?php include('sidebar.php'); ?>
    <!-- Sidebar -->
    <div id="content-wrapper" class="d-flex flex-column">
      <div id="content">
        <!-- TopBar -->
        <?php include('topbar.php'); ?>
        <!-- Topbar -->
        <!-- Container Fluid-->
        <div class="container-fluid" id="container-wrapper">
          <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h3 mb-0 text-gray-800">Invoices</h1>
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="./">Home</a></li>
              <li class="breadcrumb-item">Tables</li>
              <li class="breadcrumb-item active" aria-current="page">Simple Tables</li>
            </ol>
          </div>

          <div class="row">
            <div class="col-lg-12 mb-4">
                <!-- page start  -->
            <div class="card">
            <div class="d-flex justify-content-end" >
            <h1 class="h3 primary" styke="font-family:times; font-weight:400">INVOICES NO <?php echo "IN001"?></h1>
            </div>

            <form class="" action="" method="post">
            
            <div class="form-group col-lg-3 mb-4 ">
                    <label for="select2SinglePlaceholder">Customers</label>
                    <select class="select2-single-placeholder form-control " name="customerID" id="select2Single" <?php if(isset($_SESSION['Ccustomer'])){echo('value='.$_SESSION['Ccustomer']);} ?>>
                    <option value="">Select</option>
                    <option value="Aceh">Aceh</option>
                    <option value="Sumatra Utara">Sumatra Utara</option>
                    <option value="Sumatra Barat">Sumatra Barat</option>
                    <option value="Riau">Riau</option>
                    <option value="Kepulauan Riau">Kepulauan Riau</option>
                    <option value="Jambi">Jambi</option>
                    <option value="Bengkulu">Bengkulu</option>
                    <option value="Sumatra Selatan">Sumatra Selatan</option>
                    <option value="Kepulauan Bangka Belitung">Kepulauan Bangka Belitung</option>
                    <option value="Lampung">Lampung</option>
                    <option value="Banten">Banten</option>
                    <option value="Jawa Barat">Jawa Barat</option>
                    <option value="Jakarta">Jakarta</option>
                    <option value="Jawa Tengah">Jawa Tengah</option>
                    <option value="Yogyakarta">Yogyakarta</option>
                    <option value="Jawa TImur">Jawa Timur</option>
                    <option value="Bali">Bali</option>
                    
                    </select>
                </div >

                <div class="form-group col-lg-3 mb-4" id="simple-date2">
                    <label for="oneYearView">INVOICES DATE</label>
                      <div class="input-group date">
                        <div class="input-group-prepend">
                          <span class="input-group-text"><i class="fas fa-calendar"></i></span>
                        </div>
                        <input type="text" class="form-control" value="<?php echo date("d-m-Y");?>" id="oneYearView" name="invoiceDate">
                      </div>
                  </div>
           
            <!-- selection rows -->
        <div class="d-flex justify-content-start" >
            <div class="form-group col-lg-3 mb-4 ">
                    <label for="select2SinglePlaceholder">Products</label>
                    <select class="select2-single-placeholder form-control " name="productID" id="select2SinglePlaceholder" style="height: 150px;">
                      <option value="">Select</option>
                      <option value="Aceh">Aceh</option>
                      <option value="Sumatra Utara">Sumatra Utara</option>
                      <option value="Sumatra Barat">Sumatra Barat</option>
                      <option value="Riau">Riau</option>
                      <option value="Kepulauan Riau">Kepulauan Riau</option>
                      <option value="Jambi">Jambi</option>
                      <option value="Bengkulu">Bengkulu</option>
                      <option value="Sumatra Selatan">Sumatra Selatan</option>
                      <option value="Kepulauan Bangka Belitung">Kepulauan Bangka Belitung</option>
                      <option value="Lampung">Lampung</option>
                      <option value="Banten">Banten</option>
                      <option value="Jawa Barat">Jawa Barat</option>
                      <option value="Jakarta">Jakarta</option>
                      <option value="Jawa Tengah">Jawa Tengah</option>
                      <option value="Yogyakarta">Yogyakarta</option>
                      <option value="Jawa TImur">Jawa Timur</option>
                      <option value="Bali">Bali</option>
                      
                    </select>
                  </div >
                  
                  <div class="form-group col-lg-2 mb-4">
                  <label for="exampleInputEmail1">Quantity</label>
                      <input type="text" class="form-control1" id="exampleInputEmail1" aria-describedby="emailHelp"
                        placeholder="" name="quantity">
                  </div>

                  <div class="form-group col-lg-2 mb-4">
                  <label for="exampleInputEmail1">Rate</label>
                      <input type="text" class="form-control1" id="exampleInputEmail1" aria-describedby="emailHelp"
                        placeholder="" name="rate">
                  </div>

                  <div class="form-group col-lg-2 mb-4">
                  <label for="exampleInputEmail1">Vat</label>
                      <input type="text" class="form-control1" id="exampleInputEmail1" aria-describedby="emailHelp"
                        placeholder="" value="16%" name="vat">
                  </div>
                  <div class="form-group col-lg-2 mb-4">
                  <label for="exampleInputEmail1">Discount</label>
                      <input type="text" class="form-control1" id="exampleInputEmail1" aria-describedby="emailHelp"
                        placeholder="" value="0%" name="discount">
                  </div>
                  <div class="form-group col-lg-1 mb-4">
                  <label for="exampleInputEmail1"> Add</label>
                 <button type="submit"class="btn-primary" name="add">ADD</button>
                  </div>
            </div>
            </form>
                <!-- end of card -->
            </div>

            <div>

            <hr>
                <!-- empty div class -->
            </div>
              <!-- Simple Tables -->
              <div class="card">
                <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                  <h6 class="m-0 font-weight-bold text-primary">Items</h6>
                </div>
                <div class="table-responsive">
                  <table class="table align-items-center table-flush">
                    <thead class="thead-light">
                      <tr>
                        <th>Product</th>
                        <th>Quantity</th>
                        <th>Rate</th>
                        <th>Vat</th>
                        <th>Discount</th>
                        <th>Total</th>
                      </tr>
                    </thead>
                    <tbody>
                      <?php
                        $doc = $_SESSION['scdoc'];
                        $items= getDocSC($doc);
                        foreach($items as $item){
                            print " <tr> ";
                            print "<td>" . $item['ProductID'] . "</td>";
                            print "<td>" . $item['quantity'] . "</td>";
                            print "<td>" . $item['rate']. "</td>";
                            print "<td>" . $item['vatRate']. "</td>";
                            print "<td>" . $item['discount']. "</td>";
                            print "<td>" . $item['Amount']. "</td>"; 
                            print("<td>");
                            print('<a class="btn btn-success" href="/crm/main/tBoard.php?tiketNo='.$item['salesID'].'"><i class="fa fa-info"></i></a>');
                            print("</td>");
                            print " </tr> ";
                        }
                      ?>
                    </tbody>
                  </table>
                </div>
                <div class="card-footer"></div>
              </div>
            </div>
          </div>
          <!--Row-->

          <!-- Modal Logout -->
          <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelLogout"
            aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabelLogout">Ohh No!</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  <p>Are you sure you want to logout?</p>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-outline-primary" data-dismiss="modal">Cancel</button>
                  <a href="login.html" class="btn btn-primary">Logout</a>
                </div>
              </div>
            </div>
          </div>

        </div>
        <!---Container Fluid-->
      </div>
      <!-- Footer -->
      <footer class="sticky-footer bg-white">
        <div class="container my-auto">
          <div class="copyright text-center my-auto">
            <span>copyright &copy; <script> document.write(new Date().getFullYear()); </script> - developed by
              <b><a href="https://indrijunanda.gitlab.io/" target="_blank">indrijunanda</a></b>
            </span>
          </div>
        </div>
      </footer>
      <!-- Footer -->
    </div>
  </div>

  <!-- Scroll to top -->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <script src="/erm/views/vendor/jquery/jquery.min.js"></script>
  <script src="/erm/views/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="/erm/views/vendor/jquery-easing/jquery.easing.min.js"></script>
  <!-- Select2 -->
  <script src="/erm/views/vendor/select2/dist/js/select2.min.js"></script>
  <!-- Bootstrap Datepicker -->
  <script src="/erm/views/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
  <!-- Bootstrap Touchspin -->
  <script src="/erm/views/vendor/bootstrap-touchspin/js/jquery.bootstrap-touchspin.js"></script>
  <!-- ClockPicker -->
  <script src="/erm/views/vendor/clock-picker/clockpicker.js"></script>
  <script src="/erm/views/js/ruang-admin.min.js"></script>

  <!javavascript for this page -->
  <script>
    $(document).ready(function () {


      $('.select2-single').select2();

      // Select2 Single  with Placeholder
      $('.select2-single-placeholder').select2({
        placeholder: "Select",
        allowClear: true
      });      

      // Select2 Multiple
      $('.select2-multiple').select2();

      // Bootstrap Date Picker
      $('#simple-date1 .input-group.date').datepicker({
        format: 'dd/mm/yyyy',
        todayBtn: 'linked',
        todayHighlight: true,
        autoclose: true,        
      });

      $('#simple-date2 .input-group.date').datepicker({
        startView: 1,
        format: 'dd/mm/yyyy',        
        autoclose: true,     
        todayHighlight: true,   
        todayBtn: 'linked',
      });

      $('#simple-date3 .input-group.date').datepicker({
        startView: 2,
        format: 'dd/mm/yyyy',        
        autoclose: true,     
        todayHighlight: true,   
        todayBtn: 'linked',
      });

      $('#simple-date4 .input-daterange').datepicker({        
        format: 'dd/mm/yyyy',        
        autoclose: true,     
        todayHighlight: true,   
        todayBtn: 'linked',
      });    

      // TouchSpin

      $('#touchSpin1').TouchSpin({
        min: 0,
        max: 100,                
        boostat: 5,
        maxboostedstep: 10,        
        initval: 0
      });

      $('#touchSpin2').TouchSpin({
        min:0,
        max: 100,
        decimals: 2,
        step: 0.1,
        postfix: '%',
        initval: 0,
        boostat: 5,
        maxboostedstep: 10
      });

      $('#touchSpin3').TouchSpin({
        min: 0,
        max: 100,
        initval: 0,
        boostat: 5,
        maxboostedstep: 10,
        verticalbuttons: true,
      });

      $('#clockPicker1').clockpicker({
        donetext: 'Done'
      });

      $('#clockPicker2').clockpicker({
        autoclose: true
      });

      let input = $('#clockPicker3').clockpicker({
        autoclose: true,
        'default': 'now',
        placement: 'top',
        align: 'left',
      });

      $('#check-minutes').click(function(e){        
        e.stopPropagation();
        input.clockpicker('show').clockpicker('toggleView', 'minutes');
      });

    });
  </script>

</body>

</html>