<style>
.table-checkable tr > td:first-child, .table-checkable tr > th:first-child {
  max-width: unset;
}
.table td, .table th, .card .table td, .card .table th, .card .dataTable td, .card .dataTable th {
  padding: 4px;  
}
/* 
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
@media only screen and (max-width: 560px), (min-device-width: 568px) and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
	display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
	position: absolute;
	top: -9999px;
	left: -9999px;
}
tr {
	border: 0px solid #ccc;
}
td {
	/* Behave  like a "row" */
	border: none;
	/*border-bottom: 1px solid #eee; */
	position: relative;
	padding-left: 50%;
}
td:before {
	/* Now like a table header */
	position: unset; /*absolute causing issues*/
	/* Top/left values mimic padding */
	top: 6px;
	left: 6px;
	width: 45%;
	padding-right: 10px;
	white-space: nowrap;
}
/*
Label the data
*/
td:nth-of-type(1):before {content: "Date";}
td:nth-of-type(2):before {content: "Amount";}
td:nth-of-type(3):before {content: "Description";}
td:nth-of-type(4):before {content: "Added By";}
td:nth-of-type(5):before {content: "Actions";}
.table-checkable tr > td:first-child, .table-checkable tr > th:first-child {
  max-width: 20%;  
}
}
@media only screen and (max-width: 480px), (min-device-width: 300px) and (max-device-width: 480px) {
	.table-checkable tr > td:first-child, .table-checkable tr > th:first-child {
	  max-width: 100%;  
	}
	td:nth-of-type(1)::before {
	  content: "";
	}
}

</style>
<div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-bar">
                        <div class="page-title-breadcrumb">
                            <div class=" pull-left">
                                <div class="page-title">Profit/Loss of <?php echo getProjectName($projectId);?></div>
                            </div>
                            <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.php?page=home">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                <a class="parent-item" href="index.php?page=view_project&id=<?php echo $projectId;?>">Project</a>&nbsp;</li>
                                <li><i class="fa fa-angle-right"></i></li><li class="active">Profit/Loss</li>
                            </ol>
                        </div>
                    </div>
                    
                    
                    <div class="row col-12 pl-0 pr-0 mt-2 mb-2 text-center">
                    	<div class="col-12 row">
                    		<div class="col-6">
                    			<?php if(isset($_REQUEST['show_type']) && $_REQUEST['show_type']=='accounts'){ ?>
	                    			<a class="label label-sm label-info" href="index.php?page=project_profit_loss&id=<?php echo $_REQUEST['id']; ?>&show_type=normal">Normal View</a>
	                    		<?php } else { ?>
	                    			<span class="label label-sm">Normal View</span>
	                    		<?php } ?>
	                    	</div>
	                    	<div class="col-6">
	                    		<?php if(!isset($_REQUEST['show_type']) || (isset($_REQUEST['show_type']) && $_REQUEST['show_type']=='normal')){ ?>
	                    			<a class="label label-sm label-info" href="index.php?page=project_profit_loss&id=<?php echo $_REQUEST['id']; ?>&show_type=accounts">Accounts View</a>
	                    		<?php } else { ?>
	                    			<span class="label label-sm">Accounts View</span>
	                    		<?php } ?>
	                    	</div>
                    	</div>
                    </div>
                    
                    
                    
                   <?php if(!isset($_REQUEST['show_type']) || (isset($_REQUEST['show_type']) && $_REQUEST['show_type']=='normal')){ ?>
                                       
		 				<div  class="row col-12">
		 					<div class="col-md-12">
	                            <div class="card card-topline-red">
	                                <div class="card-head">
	                                    <header>Expenses</header>
	                                    <div class="tools">                                        
		                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
		                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
	                                    </div>
	                                </div>
	                                <div class="card-body ">
	                                    <div class="row p-b-20">
	                                        <div class="col-md-12 col-sm-12 col-12">
	                                            <div class="btn-group">
	                                                <button onclick="location.href = 'index.php?page=project_add_expense&project_id=<?php echo $projectId; ?>';" id="addRow1" class="btn btn-info">
	                                                    Add Expense <i class="fa fa-plus"></i>
	                                                </button>
	                                            </div>
	                                        </div>                                        
	                                    </div>
	                                    <?php if(isset($_REQUEST['success1'])){ ?><div class="alert alert-success"><?php echo urldecode($_REQUEST['success1']); ?></div></div><?php } ?>
	                                    <?php if(isset($expenseRs) && mysqli_num_rows($expenseRs)>0) { ?>
	                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
	                                        <thead>
	                                            <tr>                                                
	                                                <th> Date </th>
	                                                <th> Amount </th>
	                                                <th> Description </th>                                                                                             
	                                            </tr>
	                                        </thead>
	                                        <tbody>
	                                        	<?php                   	
													while($resDetails = mysqli_fetch_array($expenseRs)) { ?>
		                                            <tr class="odd gradeX">        
		                                                <td><?php getFormattedDate($resDetails['date']); ?></td>
		                                                <td><?php echo 'Rs. '.money_format('%!i', $resDetails['amount']); ?></td>
		                                                <td><?php echo $resDetails['description']; ?></td>   
		                                            </tr>
	                                            <?php $totalExpense+= $resDetails['amount']; } ?> 
	                                            <tr class="odd gradeX">        
	                                                <td colspan="2"><b>Total Expense</b></td>
	                                                <td><b><?php echo 'Rs. '.money_format('%!i', $totalExpense); ?></b></td>                                                  
	                                            </tr>                                           
	                                        </tbody>
	                                    </table>  
	                                                                      
	                                    <?php } else { ?>
	                                    	<div class="alert alert-danger">Sorry! No Results Found.</div>					        		
						        		<?php }	?> 
	                                </div>
	                            </div>
	                            
	                        </div>
	                       
                        
	                        <div class="row col-12">
	                        	<div class="col-md-12">
	                            <div class="card card-topline-red">
	                                <div class="card-head">
	                                    <header>Payments</header>
	                                    <div class="tools">                                        
		                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
		                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
	                                    </div>
	                                </div>
	                                <div class="card-body ">
	                                    <div class="row p-b-20">
	                                        <div class="col-md-12 col-sm-12 col-12">
	                                            <div class="btn-group">
	                                                <button onclick="location.href = 'index.php?page=project_add_income&project_id=<?php echo $projectId; ?>';" id="addRow1" class="btn btn-info">
	                                                    Add Payment <i class="fa fa-plus"></i>
	                                                </button>
	                                            </div>
	                                        </div>                                        
	                                    </div>
	                                    <?php if(isset($_REQUEST['success2'])){ ?><div class="alert alert-success"><?php echo urldecode($_REQUEST['success2']); ?></div></div><?php } ?>
	                                    <?php if(isset($paymentsRs) && mysqli_num_rows($paymentsRs)>0) { ?>
	                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
	                                        <thead>
	                                            <tr>                                                
	                                                <th> Date </th>
	                                                <th> Amount </th>
	                                                <th> Description </th>                   
	                                            </tr>
	                                        </thead>
	                                        <tbody>
	                                        	<?php                                        	
													while($resPayments = mysqli_fetch_array($paymentsRs)) {	?>
	                                            <tr class="odd gradeX">        
	                                                <td><?php getFormattedDate($resPayments['date']); ?></td>
	                                                <td><?php echo 'Rs. '.money_format('%!i', $resPayments['amount']); ?></td>
	                                                <td><?php echo $resPayments['description']; ?></td>   
	                                            </tr>
	                                            <?php 
	                                            	$totalProfit+= $resPayments['amount']; 
													$totalExpense+= $resDetails['amount'];													
												} 
												$totalProfit = number_format((float)$totalProfit, 2, '.', '');
												$totalExpense = number_format((float)$totalExpense, 2, '.', ''); ?> 
	                                            <tr class="odd gradeX">        
	                                                <td colspan="2"><b>Total Expense</b></td>
	                                                <td><b><?php echo 'Rs. '.money_format('%!i', $totalExpense); ?></b></td>                                                  
	                                            </tr>
	                                            <tr class="odd gradeX">        
	                                                <td colspan="2"><b>Total Payment</b></td>
	                                                <td><b><?php echo 'Rs. '.money_format('%!i', $totalProfit); ?></b></td>                                                  
	                                            </tr>                                            
	                                        </tbody>
	                                    </table>                                    
	                                    <?php } else { ?>
	                                    	<div class="alert alert-danger">Sorry! No Results Found.</div>					        		
						        		<?php }	?> 
	                                </div>
	                            </div>
	                        
	                        </div>
	                        
	                        
	                        <div class="row col-12">
                        	<div class="col-md-12">
                            <div class="card card-topline-red">
                                <div class="card-head">
                                    <header></header>                                    
                                </div>
                                <div class="card-body ">
                                    <div class="row p-b-20">
                                        <div class="col-md-12 col-sm-12 col-12 text-center">
                                        	<?php $profitLoss = $totalProfit-$totalExpense;
                                        	$profitLoss = number_format((float)$profitLoss, 2, '.', ''); ?>
                                        	<?php if($projStatus!='completed'){                                        		
                                        		if($profitLoss>0){ ?>
                                        			<h3 style="color: green;"><b>Balance Cash : <?php echo 'Rs. '.money_format('%!i', $profitLoss); ?></b></h3>
                                        		<?php } else { ?>
                                            		<h3 style="color: red;"><b>Over Expense : <?php echo 'Rs. '.money_format('%!i', $profitLoss); ?></b></h3>
                                            	<?php } 
											} else { 
                                            	if($profitLoss>0){ ?>
                                        			<h3 style="color: green;"><b>Profit : <?php echo 'Rs. '.money_format('%!i', $profitLoss); ?></b></h3>
                                        		<?php } else { ?>
                                            		<h3 style="color: red;"><b>Loss : <?php echo 'Rs. '.money_format('%!i', $profitLoss); ?></b></h3>
                                            	<?php }
                                            } ?>
                                        </div>                                        
                                    </div>                                        
                                </div>
                            </div>
                        
                        </div>
                        
                    </div>
	                    
                        <?php } ?>
                        
                        <?php if(isset($_REQUEST['show_type']) && $_REQUEST['show_type']=='accounts'){
                        	
                        	 //if($_SERVER['REMOTE_ADDR']=='202.88.237.77'){
                        	     
	                                        	$cc=0;                              	
													while($resDetails1 = mysqli_fetch_array($expenseRs1)) {	
														$accountsArray[$cc]['date'] = $resDetails1['date'];
														$accountsArray[$cc]['amount'] = $resDetails1['amount'];
														$accountsArray[$cc]['type'] = 'expense';
														$accountsArray[$cc]['description'] = $resDetails1['description'];
														$cc++;
													}
													
												while($resPayments1 = mysqli_fetch_array($paymentsRs1)) {	
														$accountsArray[$cc]['date'] = $resPayments1['date'];
														$accountsArray[$cc]['amount'] = $resPayments1['amount'];
														$accountsArray[$cc]['type'] = 'income';
														$accountsArray[$cc]['description'] = $resPayments1['description'];
														$cc++;
												}
														 
                        	asort($accountsArray); 
							$totalExpense1 = $totalProfit1 = 0;
                        	//print_r($accountsArray);?>
                        	
                        	<div class="row col-12">
	                        	<div class="col-md-12">
	                            <div class="card card-topline-red">
	                                <div class="card-head">
	                                    <header>Accounts</header>
	                                    <div class="tools">                                        
		                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
		                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
	                                    </div>
	                                </div>
	                                <div class="card-body ">	                                    
	                                    
	                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
	                                        <thead>
	                                            <tr>                                                
	                                                <th> Date </th>	                                                
	                                                <th> Credit </th>
	                                                <th> Debit </th>	 
	                                                <th> Description </th>                                                                    
	                                            </tr>
	                                        </thead>
	                                        <tbody>
	                                        	<?php foreach ($accountsArray as $account) { ?>
	                                            <tr class="odd gradeX">        
	                                                <td style="width: 10%;"><?php echo getFormattedDate($account['date']); ?></td>	                                                
	                                                <td class="text-right pr-3" style="width: 15%;">
	                                                	<?php if($account['type']=='income'){
	                                                		 echo money_format('%!i', $account['amount']); 
															 $totalProfit1+= $account['amount'];
														} ?>
	                                                </td>
	                                                <td class="text-right pr-3" style="width: 15%;">
	                                                	<?php if($account['type']!='income'){
	                                                		 echo money_format('%!i', $account['amount']); 
															 $totalExpense1+= $account['amount'];	
														}?>
	                                                </td>
	                                                <td style="width: 50%;"><?php echo $account['description']; ?></td>
	                                            </tr>
	                                            <?php } ?>	                                                                                        
	                                        </tbody>
	                                    </table>                                   
	                                     
	                                </div>
	                            </div>
	                        
	                        </div>
                        	
                        </div>
                        
                        
                        <div class="row col-12">
                        	<div class="col-md-12">
                            <div class="card card-topline-red">
                                <div class="card-head">
                                    <header></header>                                    
                                </div>
                                <div class="card-body ">
                                    <div class="row p-b-20">
                                        <div class="col-md-12 col-sm-12 col-12 text-center">
                                        	<?php $profitLoss1 = $totalProfit1-$totalExpense1;
                                        	$profitLoss1 = number_format((float)$profitLoss1, 2, '.', ''); ?>
                                        	<?php if($projStatus!='completed'){                                        		
                                        		if($profitLoss1>0){ ?>
                                        			<h3 style="color: green;"><b>Balance Cash : <?php echo 'Rs. '.money_format('%!i', $profitLoss1); ?></b></h3>
                                        		<?php } else { ?>
                                            		<h3 style="color: red;"><b>Over Expense : <?php echo 'Rs. '.money_format('%!i', $profitLoss1); ?></b></h3>
                                            	<?php } 
											} else { 
                                            	if($profitLoss1>0){ ?>
                                        			<h3 style="color: green;"><b>Profit : <?php echo 'Rs. '.money_format('%!i', $profitLoss1); ?></b></h3>
                                        		<?php } else { ?>
                                            		<h3 style="color: red;"><b>Loss : <?php echo 'Rs. '.money_format('%!i', $profitLoss1); ?></b></h3>
                                            	<?php }
                                            } ?>
                                        </div>                                        
                                    </div>                                        
                                </div>
                            </div>
                        
                        </div>
                        
                    </div>
                        
                        <?php } ?>
                        
                        
                    

</div>
</div>
