<?php 
if(!isset($_GET['month']))
{?>

<script type="text/javascript">
  $( document ).ready(function() {
  $('#exampleModal').modal({backdrop: 'static', keyboard: false}, 'show');
});
  
</script>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Select Month & Year</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form method="GET" action="">
        <div class="modal-body">
          <div class="form-group">
            <label class="" for="from_date">Month &nbsp;&nbsp;&nbsp; <span class="text-danger">*</span></label>
            <select required="" type="date" name="month" class="form-control datepicker" id="from_date">
              <option <?php if(date('m') == '01'){echo 'selected';}?> value="01">January</option>
              <option <?php if(date('m') == '02'){echo 'selected';}?> value="02">February</option>
              <option <?php if(date('m') == '03'){echo 'selected';}?> value="03">March</option>
              <option <?php if(date('m') == '04'){echo 'selected';}?> value="04">April</option>
              <option <?php if(date('m') == '05'){echo 'selected';}?> value="05">May</option>
              <option <?php if(date('m') == '06'){echo 'selected';}?> value="06">June</option>
              <option <?php if(date('m') == '07'){echo 'selected';}?> value="07">July</option>
              <option <?php if(date('m') == '08'){echo 'selected';}?> value="08">August</option>
              <option <?php if(date('m') == '09'){echo 'selected';}?> value="09">September</option>
              <option <?php if(date('m') == '10'){echo 'selected';}?> value="10">October</option>
              <option <?php if(date('m') == '11'){echo 'selected';}?> value="11">November</option>
              <option <?php if(date('m') == '12'){echo 'selected';}?> value="12">December</option>
            </select>
          </div>
          <div class="form-group end_date">
              <label class="" for="to_date">Year &nbsp;&nbsp;&nbsp;</label>
              <select required=""  type="date" name="year" class="form-control datepicker" id="to_date" >
                <option value="2023">2023</option>
              </select>
          </div>
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-primary">Search</button>
        </div>
      </form>
    </div>
  </div>
</div>
<?php }
?>

 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">All Expense</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item"><a href="#">Expense Management</a></li>
              <li class="breadcrumb-item active">All Expense</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="card card-default">
          <div class="card-header">
            <div class="container">
              <div class="row">
                <div class="col-sm-6">
                  <form method="GET" action="">
                    <div class="row">
                      <div class="col-sm-5">
                         <div class="form-group">
                          <label class="" for="from_date">Month &nbsp;&nbsp;&nbsp;</label>
                          <select required="" type="date" name="month" class="form-control datepicker" id="from_date">
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '01'){echo 'selected';}}?> value="01">January</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '02'){echo 'selected';}}?> value="02">February</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '03'){echo 'selected';}}?> value="03">March</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '04'){echo 'selected';}}?> value="04">April</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '05'){echo 'selected';}}?> value="05">May</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '06'){echo 'selected';}}?> value="06">June</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '07'){echo 'selected';}}?> value="07">July</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '08'){echo 'selected';}}?> value="08">August</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '09'){echo 'selected';}}?> value="09">September</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '10'){echo 'selected';}}?> value="10">October</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '11'){echo 'selected';}}?> value="11">November</option>
                            <option <?php if(isset($_GET['month'])){if($_GET['month'] == '12'){echo 'selected';}}?> value="12">December</option>
                          </select>
                        </div>
                      </div> 
                      <div class="col-sm-5">
                        <div class="form-group end_date">
                            <label class="" for="to_date">Year &nbsp;&nbsp;&nbsp;</label>
                            <select required=""  type="date" name="year" class="form-control datepicker" id="to_date" >
                              <option value="2023">2023</option>
                            </select>
                        </div>
                      </div>
                      <div class="col-sm-2" style="float: left;">
                        <label style="color: #fff;">s</label>
                        <div class="form-group">
                            <button style="float: left;" type="submit" class="btn btn-success">Search</button>
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
              </div>
            </div>  
          </div>
        </div>
    </section>
    <section class="content">
      <div class="container-fluid">
        <div class="card card-default">
          <div class="card-header">
            <h3 class="card-title">View All Expense</h3>
            <div class="card-tools">
              <a href="javascript:void(0)" data-toggle="modal" data-target="#exampleModal_2" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add New Expense</a>
            </div>
          </div>
            <!-- /.card-header -->
            <div class="card-body">
              
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>ID</th>
                  <th>Expense Note</th>
                  <th>Expense Date</th>
                  <th>Expense Amount</th>
                  <!-- <th></th> -->
                </tr>
                </thead>
                <tbody>
                <?php $i=1;
                $ttl_exp = 0; 
                foreach ($all_expense as $expense):

                ?>
                <tr>
                  <td><?php echo $i ?></td>
                  <td><?php echo $expense->expense_note ?></td>
                  <td><?php echo date('d-m-Y', strtotime($expense->expense_date))?></td>
                  <td><b>&#8377; <?php echo $expense->expense_amount ?></b></td>
                </tr>
                <?php $ttl_exp += $expense->expense_amount; ?>
                <?php $i++; ?>
                <?php endforeach; ?>
                
                </tbody>
                <tr>
                  <td></td>
                  <td></td>
                  <td><b>Total</b></td>
                  <td><b>&#8377;<?php echo $ttl_exp; ?></b></td>
                </tr>
              </table>
            </div>
          </div>
      </div>
    </section>
  </div>


<div class="modal fade" id="exampleModal_2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add New Expense</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <?php echo form_open(base_url().'/admin/expense/add_new_expense'); ?>
        <div class="modal-body">
          <div class="form-group">
          
            <label for="message-sss" class="col-form-label">Amount <span class="text-danger">*</span></label>
            <input type="number" class="form-control" min="1" max="100000000" id="message-sss" name="expense_amount" required placeholder="Enter Expense Amount"/>
          </div>
          <div class="form-group">
            <label for="message-date" class="col-form-label">Date  <span class="text-danger">*</span></label>
            <input class="form-control" id="message-date" type="date" <?php if(isset($_GET['month'])){ echo 'value="'.date($_GET['year'].'-'.$_GET['month'].'-01').'"';}?> name="expense_date" required placeholder="Enter Expense Amount"/>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Note  <span class="text-danger">*</span></label>
            <textarea class="form-control" id="message-text" name="expense_note" placeholder="Enter Any Note" required></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-primary">Save</button>
        </div>
      <?php echo form_close(); ?>
    </div>
  </div>
</div>

<style>
  select.form-controls {
    display: inline;
    width: 200px;
    margin-left: 25px;
  }
</style>