<?php //print_r($usertype);exit; ?>
    <section class="content-header">
      <h1>
        Swiss(VAT) Card Users
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">List</li>
      </ol>
    </section>

    <section class="content">
      <div class="row">
        <?php echo $this->utility->showMsg();?>
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Management</h3>
              </div>
               
              <div></div>
            <!-- /.box-header -->
            <div class="box-body">
            <form action="" method="post">
              <div class="form-group">
                <div class="row">
                 <div class="col-sm-6">
                    <label class="col-sm-4 control-label">Search By Year</label>
                      <select name="vat_year" class="monthSelect col-sm-4">
                       <option value="">--Select Year--</option>
                      <?php for($i=date('Y');$i>2016;$i--) {
                      ?>
                            <option value="<?php echo $i; ?>" <?php if($this->input->post('vat_year')){ if($this->input->post('vat_year') == $i ){ echo 'selected'; } }elseif(date('Y') == $i){ echo 'selected'; } ?>><?php echo $i; ?></option>
                      <?php 
                          }  
                      ?>
                    </select>
                 </div> 
                 <div class="col-sm-4">
                            <div class="col-sm-4">
                                <input type="submit" class="btn btn-success " value="Search" id="add">
                            </div>
                         </div>
                        </div>
                      </div>
            </form>
              <?php if($this->input->post('vat_year')){ 
                      $req_year = $this->input->post('vat_year'); 
                    }else{ 
                      $req_year = date('Y');
                    }  
              ?>
              <a target="_blank" href="<?php echo base_url().'admin/log/download_vat1/'.$req_year; ?>"><input type="button" class="btn btn-info" value="Download Q1" id="download"></a>
              <a target="_blank" href="<?php echo base_url().'admin/log/download_vat2/'.$req_year; ?>"><input type="button" class="btn btn-info" value="Download Q2" id="download"></a>
              <a target="_blank" href="<?php echo base_url().'admin/log/download_vat3/'.$req_year; ?>"><input type="button" class="btn btn-info" value="Download Q3" id="download"></a>
              <a target="_blank" href="<?php echo base_url().'admin/log/download_vat4/'.$req_year; ?>"><input type="button" class="btn btn-info" value="Download Q4" id="download"></a>
              <h4>Q1 - Mwst Abrechnung <?php if($this->input->post('vat_year')){ echo $this->input->post('vat_year'); }else{ echo date('Y');}  ?></h4> 
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Date</th>
                  <th>Referenz</th>
                  <th>Betrag</th>
                  <th>Herkunft</th>
                </tr>
                </thead>
                 <?php if(count($first_quartar)>0)
                {?>
                <tbody>
                <?php
                $total_first=0;
                foreach ($first_quartar as $key=>$data) 
                {
                  $total_first+=$data['total_sum'];
                ?>
                <tr>
                    <td><?php echo ($key+1);?></td>
                    <td><?php echo date('d-m-Y',$data['created']); ?></td>
                    <td><?php echo $data['order_id_masked']; ?></td>
                    <td><?php echo number_format($data['total_sum']/100, 2,',', '.'); ?></td>
                    <td><?php echo 'CH'; ?></td>
                </tr>
                <?php } } ?>
                <tfoot>
                </tfoot>
              </table>
              <span style="margin-bottom: 100px; display: block; font-weight: bold !important; font-size: 15px;">Q1 total vat amount: <?php echo number_format($total_first/100, 2,',', '.'); ?></span>



              <h4>Q2 - Mwst Abrechnung <?php if($this->input->post('vat_year')){ echo $this->input->post('vat_year'); }else{ echo date('Y');}  ?></h4> 
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Date</th>
                  <th>Referenz</th>
                  <th>Betrag</th>
                  <th>Herkunft</th>
                </tr>
                </thead>
                 <?php if(count($second_quartar)>0)
                {?>
                <tbody>
                <?php
                $total_second=0;
                foreach ($second_quartar as $key=>$data) 
                {
                  $total_second+=$data['total_sum'];
                ?>
                <tr>
                    <td><?php echo ($key+1);?></td>
                    <td><?php echo date('d-m-Y',$data['created']); ?></td>
                    <td><?php echo $data['order_id_masked']; ?></td>
                    <td><?php echo number_format($data['total_sum']/100, 2,',', '.'); ?></td>
                    <td><?php echo 'CH'; ?></td>
                </tr>
                <?php } } ?>
                <tfoot>
                </tfoot>
              </table>
              <span style="margin-bottom: 100px; display: block; font-weight: bold !important; font-size: 15px; ">Q2 total vat amount: <?php echo number_format($total_second/100, 2,',', '.'); ?></span>


              <h4>Q3 - Mwst Abrechnung <?php if($this->input->post('vat_year')){ echo $this->input->post('vat_year'); }else{ echo date('Y');}  ?></h4> 
              <table id="example3" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Date</th>
                  <th>Referenz</th>
                  <th>Betrag</th>
                  <th>Herkunft</th>
                </tr>
                </thead>
                 <?php if(count($third_quartar)>0)
                {?>
                <tbody>
                <?php
                $total_third=0;
                foreach ($third_quartar as $key=>$data) 
                {
                  $total_third+=$data['total_sum'];
                ?>
                <tr>
                    <td><?php echo ($key+1);?></td>
                    <td><?php echo date('d-m-Y',$data['created']); ?></td>
                    <td><?php echo $data['order_id_masked']; ?></td>
                    <td><?php echo number_format($data['total_sum']/100, 2,',', '.'); ?></td>
                    <td><?php echo 'CH'; ?></td>
                </tr>
                <?php } } ?>
                <tfoot>
                </tfoot>
              </table>
              <span style="margin-bottom: 100px; display: block; font-weight: bold !important; font-size: 15px; ">Q3 total vat amount: <?php echo number_format($total_third/100, 2,',', '.'); ?></span>


              <h4>Q4 - Mwst Abrechnung <?php if($this->input->post('vat_year')){ echo $this->input->post('vat_year'); }else{ echo date('Y');}  ?></h4> 
              <table id="example4" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Date</th>
                  <th>Referenz</th>
                  <th>Betrag</th>
                  <th>Herkunft</th>
                </tr>
                </thead>
                 <?php if(count($fourth_quartar)>0)
                {?>
                <tbody>
                <?php
                $total_fourth=0;
                foreach ($fourth_quartar as $key=>$data) 
                {
                  $total_fourth+=$data['total_sum'];
                ?>
                <tr>
                    <td><?php echo ($key+1);?></td>
                    <td><?php echo date('d-m-Y',$data['created']); ?></td>
                    <td><?php echo $data['order_id_masked']; ?></td>
                    <td><?php echo number_format($data['total_sum']/100, 2,',', '.'); ?></td>
                    <td><?php echo 'CH'; ?></td>
                </tr>
                <?php } } ?>
                <tfoot>
                </tfoot>
              </table>
              <span style="margin-bottom: 100px; display: block; font-weight: bold !important; font-size: 15px; ">Q4 total vat amount: <?php echo number_format($total_fourth/100, 2,',', '.'); ?></span>
              
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>



    
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/12.1.6/css/intlTelInput.css">
<script>
  $(function () {
    $("#example1").DataTable();
    $("#example2").DataTable();
    $("#example3").DataTable();
    $("#example4").DataTable();
  });
</script>
