<?php $running_year = $this->db->get_where('settings' , array('type' => 'running_year'))->row()->description; ?>
<div class="content-w">
		  <div class="os-tabs-w menu-shad">
			<div class="os-tabs-controls">
			  <ul class="nav nav-tabs upper">
				<li class="nav-item">
				  <a class="nav-link" href="<?php echo base_url();?>admin/payments/"><i class="os-icon picons-thin-icon-thin-0409_wallet_credit_card_money_payment"></i><span><?php echo get_phrase('New Invoice');?></span></a>
				</li>
				<li class="nav-item">
				  <a class="nav-link active" href="<?php echo base_url();?>admin/jobsheets_payments/"><i class="os-icon picons-thin-icon-thin-0426_money_payment_dollars_coins_cash"></i><span><?php echo get_phrase('payments');?></span></a>
				</li>
			  </ul>
			</div>
		  </div>
  <div class="content-i">
    <div class="content-box">
	<div class="element-wrapper">
		 <div class="tab-content">
		<div class="tab-pane active" id="invoices">
          <div class="element-box lined-primary shadow">
		  <div class="table-responsive">
			<table id="dataTable1" width="100%" class="table table-striped table-lightfont">
			<thead>
				<tr>
    				<th><?php echo get_phrase('client');?></th>
					<th><?php echo get_phrase('date');?></th>
					<th><?php echo get_phrase('total hours');?></th>
					<th><?php echo get_phrase('total sheets');?></th>
					<th><?php echo get_phrase('total amount');?></th>
					<th><?php echo get_phrase('balance ');?></th>
					<th><?php echo get_phrase('status');?></th>
					<th class="text-center"><?php echo get_phrase('options');?></th>
				</tr>
			</thead>
			<tbody>
			<?php
                $count = 1;
              //  $this->db->where('year' , $running_year);
              //  $this->db->order_by('creation_timestamp' , 'desc');
                $invoices = $this->db->get('invoice')->result_array();
                foreach($invoices as $row): 
                    $client_id=$row['client_id'];
                    $invDate = $row['due'];
                   $newDate = date("d-m-Y", strtotime($invDate));
                   $amount=$row['amount'];
                ?>
				<tr>
					<td><?php echo $this->db->get_where('client' , array('client_id'=>$client_id))->row()->client_name; ?></td>
					<td><a class="btn nc btn-rounded btn-sm btn-primary" style="color:white"><?php echo $newDate;?></a></td>
					<td><?php echo $row['total_hours'];?></td>
						<td><?php echo $row['total_jobs'];?></td>
						<td><?php echo number_format($row['amount'],2);?></td>
						<?php $balance= number_format(($row['amount_paid']-$row['amount']),2) ?>
						<td><?php echo $balance ?></td>

					<td>
					<?php if($row['status'] == 'paid' && ($balance==0.00)):?>
					
			    		<a class="btn nc btn-rounded btn-sm btn-success" style="color:white"><?php echo Paid;?></a>
					<?php endif;?>
					<?php if($row['status'] == 'unpaid' && ($balance < 0.00)):?>
						
						<a class="btn nc btn-rounded btn-sm btn-danger" style="color:white"><?php echo Unpaid;?></a>
					<?php endif;?>
					</td>
					
					<td class="row-actions" nowrap>
						<a href="<?php echo base_url();?>admin/invoice_details/<?php echo $row['invoice_id'];?>"><i class="picons-thin-icon-thin-0424_money_payment_dollar_cash"></i></a> 
						<?php if($row['status'] == 'unpaid' && ($balance < 0.00)):?>
							<a href="#" onclick="showAjaxModal('<?php echo base_url();?>modal/popup/modal_invoice/<?php echo $row['invoice_id'];?>');"><i class="picons-thin-icon-thin-0001_compose_write_pencil_new"></i></a>

					    <?php endif;?>
						
						<a class="danger" href="<?php echo base_url();?>admin/invoice/delete/<?php echo $row['invoice_id'];?>" onClick="return confirm('<?php echo get_phrase('confirm_delete');?>')"><i class="picons-thin-icon-thin-0056_bin_trash_recycle_delete_garbage_empty"></i></a>
					</td>
				</tr>
			<?php endforeach;?>
			</tbody>
			</table>
		  </div>
		</div>
          </div>
		  
          </div>
        </div>
      </div>
    </div>
</div>