<?php $__env->startSection("content"); ?>
<div class="row">
  <div class="col-sm-12">
    <div class="container">
      <div class="top-content">
        <div class="right-content">
          <div class="title" style="width:452px;">
            <h2>Expenses</h2>
          
           
          </div>
          <div class="tasks" style="width:471px;">
            <button class="btn btn-primary" onclick="window.location='<?php echo e(url('expenses/create')); ?>'">Add New Expense</button>
            <div class="dropdown">
              <select class="form-control chosen-select" onchange="change_period($(this).val())">
              <option value="all">Choose Budget Period</option>
              <?php if(count($periods)>0): ?>
              <?php foreach($periods as $row): ?>
              <option value="<?php echo e($row->id); ?>" <?php if($period==$row->id){echo 'selected="selected"';}  /* {{\App\Providers\Common::format_date($row->from)}} to {{\App\Providers\Common::format_date($row->to)}} */ ?>><?php echo e($row->name); ?></option>
              <?php endforeach; ?>
              <?php endif; ?>
            </select>
            </div>
          </div>
        </div>
      </div>
      <div class="main-content">
        <div class="sidebar">
          <nav>
            <ul class="navigations">
              <li <?php if($status=="all") echo 'class="active"'; ?>> <a href="<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=all&period=<?php echo e($period); ?>&page=<?php echo e($page); ?>">All Expenses</a> </li>
              <li <?php if($status=="Pending") echo 'class="active"'; ?>> <a href="<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=Pending&period=<?php echo e($period); ?>&page=<?php echo e($page); ?>">Pending</a> </li>
              <li <?php if($status=="Approved") echo 'class="active"'; ?>> <a href="<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=Approved&period=<?php echo e($period); ?>&page=<?php echo e($page); ?>">Approved</a> </li>
              <li <?php if($status=="Denied") echo 'class="active"'; ?>> <a href="<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=Denied&period=<?php echo e($period); ?>&page=<?php echo e($page); ?>">Denied</a> </li>
              <li <?php if($status=="Overdue") echo 'class="active"'; ?>> <a href="<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=Overdue&period=<?php echo e($period); ?>&page=<?php echo e($page); ?>">Overdue</a> </li>
              <li <?php if($status=="Closed") echo 'class="active"'; ?>> <a href="<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=Closed&period=<?php echo e($period); ?>&page=<?php echo e($page); ?>">Closed</a> </li>
            </ul>
          </nav>
          <div class="departments">
            <select class="form-control chosen-select" data-placeholder="Departments" onchange="change_department($(this).val())">
              <option value="all">All Departments</option>
              <?php if(count($categories)>0): ?>
              <?php foreach($categories as $row): ?>
              <option value="<?php echo e($row->id); ?>" <?php if($department==$row->id) echo 'selected="selected"'; ?>><?php echo e($row->name); ?></option>
              <?php endforeach; ?>
              <?php endif; ?>
            
            </select>
          </div>
          
        </div>
        <div class="main">
          <div class="expense-table tbl-border">
            <table class="table table-bordered">
              <thead>
                <tr>
                  <th Class="tbl-heading"></th>
				  <th Class="tbl-heading">Period</th>
                  <th Class="tbl-heading">Request</th>
                  <th Class="tbl-heading">Category</th>
                  <?php foreach($currency_symbol as $row): ?>
				  <th Class="tbl-heading"><?php echo e($row->symbol); ?></th>
                  <?php endforeach; ?>
				  <th Class="tbl-heading">Approver</th>
                  <th Class="tbl-heading">Details</th>
                </tr>
              </thead>
              <tbody>
              <form role="form" action="<?php echo e(url('expenses/edit')); ?>" method="POST" name="" id="">
              <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
              <?php if(count($expenses)>0): ?>
              <?php $i=0; ?>
              <?php foreach($expenses as $row): ?>
              <?php
                  $color = "purple";
                  if($row->status=="Pending"){ $color = "yellow"; }
                  if($row->status=="Approved"){ $color = "green"; }
                  if($row->status=="Denied"){ $color = "red"; }
				  if($row->status=="Closed"){ $color = "black"; }
                ?>
              <tr class="border-<?php echo e($color); ?>">
                <td class="select"><input type="checkbox" name="expenses[]" value="<?php echo e($row->id); ?>" class="expenses_checkbox" /></td>
                <td class="period"><?php echo e($row->period); ?></td>
				<td class="requests" style="text-align:left">
                <h5>Item: <a href="<?php echo e(URL::asset('/')); ?>expenses/show/<?php echo e($row->id); ?>" style="text-decoration:none; color:inherit !important;"><?php echo e($row->item); ?></a></h5>
               
                
                   
                 
                    
                   <p><h5>Subject:<?php echo e($row->subject); ?></h5></p> 	
                    <p>By: <span><?php echo e($row->user); ?></span></p>				   
				 <?php if($row->comments != ''): ?>
                  	<p><strong>Comments: </strong><?php echo e($row->comments); ?></p>
                  <?php endif; ?>
                  <div style="clear:both;height:5px;"></div>
                  <div class="" id="comments_box_<?php echo e($row->id); ?>" style="display:none;">
                  	<div style="float:left;margin-top:8px;"><strong>Comments: </strong></div> <textarea name="comments[<?php echo e($row->id); ?>]" id="comments_<?php echo e($row->id); ?>" style="width:320px;height:42px;margin-left:10px;"></textarea>
                  </div>
                  
                 </td>
				 <td class="category" style="text-align:left"><h5><?php echo e($row->category); ?></h5> </td>
                <td class="amount"> 
				<p><span><?php echo e(\App\Providers\Common::format_currency($row->price)); ?></span> requested</p>
                  <a href="<?php echo e(URL::asset('/')); ?>expenses/show/<?php echo e($row->id); ?>" style="text-decoration:none; color:inherit !important;"><span class="overdue bg-<?php echo e($color); ?>"><?php echo e($row->status); ?></span></a></td>
                <td class="approvers">
                <?php if($row->approver!=""): ?>
                <div class="group"> <?php if($row->approver_logo==""){?> <p align="center"><img src="<?php echo e(URL::asset('/')); ?>uploads/logo.png" width="20px" /></p> 
				<?php } else {?> <p align="center"><img src="<?php echo e(URL::asset('/')); ?>uploads/<?php echo e($row->approver_logo); ?>" width="20px" /></p>
				<?php }?>
                    <p><?php echo e($row->approver); ?></p>
                </div>
                <?php endif; ?>
                </td>
                <td class="details">
                  
                 
				  <p class="green"><span><?php echo e(\App\Providers\Common::format_currency($row->budget-$row->price)); ?></span> Left</p>
                  <p class="priority"><strong>Priority: </strong><?php echo e($row->priority); ?></p>	  
                </td>
              </tr>
              <?php if($i==count($colors)-1){$i=-1;} $i++; ?>
              <?php endforeach; ?>
              <?php endif; ?>
                </tbody>
              
            </table>
          </div>
          <nav>
            <div class="page-details"> <?php echo $expenses->render(); ?> </div>
            <?php if(Auth::user()->role!=3): ?>
            <div class="status-trigger">
              <div id="com_warnings" style="color:red;margin-bottom:10px;display:none;">Please fill comment box these are required.</div>
			  <div id="acom_warnings" style="color:red;margin-bottom:10px;display:none;">Please Select the Request first.</div>
              <button class="btn btn-danger" name="status" id="deniedsubmitbtn" value="Denied" type="submit" style="visibility:hidden;">Deny</button>
			  <button class="btn btn-success" id="approvestatusbutton" style="background:#000;visibility:hidden;" name="status" value="Approved" type="submit">Approve</button>
              <button class="btn btn-success" id="closestatusbutton" style="background:#000;visibility:hidden;" name="status" value="Closed" type="submit">Close</button>
              
              <button class="btn btn-danger" value="Denied" type="button" onclick="denyexpenses()">Deny</button>
              
              <button class="btn btn-success" style="background:green;" type="button" onclick="approve()">Approve</button>
              
              <button class="btn btn-success" style="background:#000;" type="button" onclick="closeexpenses()">Close</button>
              
            </div>
            <?php endif; ?>
          </nav>
        </div>
        </form>
      </div>
    </div>
  </div>
 
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection("footer"); ?> 
<script>
	function change_department(id){
		var url = '<?php echo e(URL::asset('/')); ?>expenses?department='+id+'&status=<?php echo e($status); ?>&period=<?php echo e($period); ?>&page<?php echo e($page); ?>';
		window.location = url;
	}
	function change_period(id){
		var url = '<?php echo e(URL::asset('/')); ?>expenses?department=<?php echo e($department); ?>&status=<?php echo e($status); ?>&period='+id+'&page<?php echo e($page); ?>';
		
		window.location = url;
	}
	
	function denyexpenses(){
		$(".expenses_checkbox").each(function(index, element) {
            var checking = $(this).is(':checked');
			var checkboxid = $(this).val();
			if(checking === true){ 
				window.scrollTo(0,200); 
				$("#comments_box_"+checkboxid).slideDown('slow');
				$("#comments_"+checkboxid).addClass('validatecommentbox'); 
			}else{
				$("#comments_box_"+checkboxid).slideUp('slow');
				$("#comments_"+checkboxid).removeClass('validatecommentbox');
			}
        });
		
		var commentcounter = 0;
		$(".expenses_checkbox").each(function(index, element) {
            var checking = $(this).is(':checked'); 
			if(checking === true){ 
				commentcounter++; 
			}
        });
		var allemptycommentbox=$(".validatecommentbox").filter(function() {
			return this.value;
		}); 
		if(allemptycommentbox.length == 0){
			$("#com_warnings").show();
		}else if(allemptycommentbox.length == commentcounter){
			$("#com_warnings").hide();	
			$("#deniedsubmitbtn").trigger('click');
		}
	}
	function closeexpenses(){
		var commentcounter = 0;
		$(".expenses_checkbox").each(function(index, element) {
            var checking = $(this).is(':checked'); 
			if(checking === true){ 
				commentcounter++; 
			}
        });
		if(commentcounter>0){
			var confirmation = confirm('Are you sure?');
			if(confirmation === true){
				$("#closestatusbutton").trigger('click');
			}
		}	
	}
	
	function approve(){
		var commentcounter = 0;
		$(".expenses_checkbox").each(function(index, element) {
            var checking = $(this).is(':checked'); 
			if(checking === true){ 
				commentcounter++; 
			}
        });
		if(commentcounter>0){
			var confirmation = confirm('Are you sure?');
			if(confirmation === true){
				$("#approvestatusbutton").trigger('click');
			}
		} else {
			$("#acom_warnings").show();
		}	
	}
	
	
	function changestatussingle(expenseid){
		var commentbox = $("#comment_single_"+expenseid).val();
		var newstatus = $("#expense_status_"+expenseid).val();
		if(newstatus == 'Denied'){
		if(commentbox == ''){
			$("#comments_single_tr_id").slideDown('slow');
		}else{ 
			commentbox = $("#comment_single_"+expenseid).val();
			$.post( "<?php echo e(URL::asset('/')); ?>expenses/updatestatus", {newstatus:newstatus,commentbox:commentbox,expenseid:expenseid,_token:'<?php echo csrf_token(); ?>'}).done(function(data){
				location.reload();
			});
		}
		}else{
			$.post( "<?php echo e(URL::asset('/')); ?>expenses/updatestatus", {newstatus:newstatus,commentbox:commentbox,expenseid:expenseid,_token:'<?php echo csrf_token(); ?>'}).done(function(data){
				location.reload();
			});
		}
	}
</script> 
<?php $__env->stopSection(); ?> 
<?php echo $__env->make("app", array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>