<?php
$delete_id = $link->hrefquery();

if($delete_id['0']=='delete_id'){
	$delete_inventory =$db->delete('inventory',array('id'=>$delete_id['1']));
	if($delete_inventory){
		$session->redirect('home',Admin);
	}
}



$query = $db->get_col ( users, array ('email' => $uemail ), 'id' );

$mainid = $query [0];

// Payments
$expense = $db->get_all ( 'payment', array ('payment' => 'expense' ), 'amount' );
$blank = '';
foreach ( $expense as $find ) {
	$t_exp = $blank + $find ['amount'];
	$blank = $t_exp;

}
$null = '';
$income = $db->get_all ( 'payment', array ('payment' => 'income' ), 'amount' );
foreach ( $income as $find ) {
	$t_inc = $null + $find ['amount'];
	$null = $t_inc;

}

// ----finish payment------//

// Employee

$active = $db->get_count ( 'employees', array ('status' => '0' ) );

$non_active = $db->get_count ( 'employees', array ('status' => '1' ) );

// ----finish employees----//

// Departments
$departments = $db->get_count ( 'departments' );

// ----departments----//

?>
<div class="page-content">
	<div class="page-header position-relative">
		<h1>
			overview <small> &amp; stats </small>
		</h1>
	</div>
	<!--/.page-header-->
     <?php $get_inventory = $db->get_all('inventory');
    
     ?>
	<div class="row-fluid">
		<div class="span12">
			<!--PAGE CONTENT BEGINS-->
					
				<?php
				    if(is_array($get_inventory)){
				    	$i=1;
					$total_instalment = "";
					foreach ( $get_inventory as $inventory ) {
					if($inventory['installment']=='1'){
						
						$installment_amount = unserialize($inventory['payment_amount']);
						$installment_date = unserialize($inventory['payment_date']);
						$total_install_amount="";
						foreach($installment_amount as $amount){
							$total_install_amount = $total_install_amount+$amount;
						}
						
						if($inventory['item_amount']!=$total_install_amount){
							
							foreach($installment_date as $date){
								
								 $d1 =  time();		
								 $d2 =  strtotime($date);
								 $days_diff = $d2-$d1;
							     $days_difference = ceil($days_diff/3600/24);
								 
							}	
						if($days_difference<=7){	
							
				?>	
							
					<div class="row-fluid">
		<div class="span12" style="overflow: scroll;">
			<!--PAGE CONTENT BEGINS-->
			
			<table id="sample-table-2"
				class="table table-striped table-bordered table-hover no-margin-bottom no-border-top">
				<thead>
					<tr>
						<th>S.No.</th>
						<th>Item Name</th>
						<th>Item Code</th>
						<th>Purchased Date</th>
						<th>Location</th>
						<th>Item Amount</th>
						<th>Installment</th>
						<th>Payment Amount</th>
						<th>Payment Date</th>
						<th>Installment Due</th>
						<th></th>
					</tr>
				</thead>

				<tbody>
				
					<tr>
						<td><?php echo $i;?></td>
						<td> <?php echo $inventory['item_name']; ?> </td>
						<td> <?php echo $inventory['item_code']; ?></td>
						<td><?php echo $inventory['purchase_date'];?></td>
						<td> <?php echo $inventory['location']; ?> </td>
						<td> <?php echo $inventory['item_amount']; ?> </td>
						<td> <?php if($inventory['installment']=='1') echo "Yes"; else echo "No"; ?> </td>
						<td>
						<?php
						foreach($installment_amount as $amount){
							echo '<span class="label label-info tooltip-info" data-original-title="Installment Amount" data-rel="tooltip" data-placement="top" style="cursor:pointer;">'.$amount.'</span><br>';
						}
						?>
						</td>
						<td>
						<?php
						
						
						foreach($installment_date as $date){
							echo '<span class="label label-info tooltip-info" data-original-title="Installment Date" data-rel="tooltip" data-placement="top" style="cursor:pointer;">'.$date.'</span><br>';
						}
						
						?>
						</td>
						<td>
						<?php 
						echo '<span class="label label-important">Installment Due</span>';
						?>
						</td>
						<td class="td-actions">
						<a href="<?php echo $link->link('add_inventory',Admin,'?edit_id='.$inventory['id']);?>" class="green"><i class="icon-edit bigger-130 tooltip-success" data-original-title="Edit" data-rel="tooltip" data-placement="top"></i></a>
						<a href="<?php echo $link->link('home',Admin,'?delete_id='.$inventory['id']);?>" class="red"><i class="icon-trash bigger-130 tooltip-error" data-original-title="Delete" data-rel="tooltip" data-placement="top"></i></a>
						<i class="icon-plus bigger-130 tooltip-info" title="Add Installment" data-rel="popover" data-placement="left" data-content="<form method='post' action=''><input type='hidden' name='inventory_id' value='<?php echo $inventory['id'];?>'>
						<input type='text' name='add_installment' placeholder='payment amount'><br><br>
						<input type='text' id='datepicker' name='installment_date' placeholder='payment date(dd-mm-yyyy)'><br><br>
						<button type='submit' name='installment_submit' class='btn btn-info'>Save</button></form>"></i>
						</td>
					</tr>
				       
										</tbody>
			</table>
			
			<!--PAGE CONTENT ENDS-->
		</div>
		<!--/.span-->
	</div>
	<?php $i++; } } } } } ?>						
							
							
							<?php
							$absenttable = $db->run ( "select * from attendence where t_leave !=''" )->fetchAll ();
							$employee = $db->get_all ( 'employees' );
							
							?>
	
							<div class="row-fluid">
				<div class="span12">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="smaller">Attendence</h4>
						</div>
										<?php
										$attendencefirst = $db->get_count ( "attendence" );
										if ($attendencefirst != 0) {
											?>
										<script type="text/javascript">
											$(function () {
										        $('#container3').highcharts({
										            title: {
										                text: 'Monthly Average Performance',
										                x: -20 //center
										            },
										            subtitle: {
										                text: 'Source: Phpscriptsonline.com',
										                x: -20
										            },
										            xAxis: {
										                categories: [
														               <?php
											$getfiscaldate123 = date ( "Y-m-01" );
											$count = 1;
											while ( $count <= 13 ) {
												$fiscalmonth = date ( 'F', strtotime ( $getfiscaldate123 ) );
												$year = strtotime ( $getfiscaldate123 . '-1 year' );
												$year = substr ( date ( "Y", $year ), 2 );
												
												$month1 = substr ( $fiscalmonth, 0, 3 );
												$month .= "'$month1($year)'" . ',';
												// echo $getfiscaldate;
												$getfiscaldate123 = date ( "Y-m-d", strtotime ( "+1 month", strtotime ( $getfiscaldate123 ) ) );
												$count ++;
											}
											
											// echo $month;
											echo rtrim ( $month, ',' );
											?> 
														            ]
										            },
										            yAxis: {
										                title: {
										                    text: 'Performance'
										                },
										                plotLines: [{
										                    value: 0,
										                    width: 1,
										                    color: '#808080'
										                }]
										            },
										            legend: {
										                layout: 'vertical',
										                align: 'right',
										                verticalAlign: 'middle',
										                borderWidth: 0
										            },
										            series: [
<?php
											$arrval = 0;
											
											foreach ( $employee as $rowemployee ) {
												$a = '';
												$getfiscaldate123 = date ( "Y-m-01" );
												echo "{";
												echo " name: '$rowemployee[e_name]',";
												$count = 1;
												// $a= array();
												while ( $count <= 12 ) {
													$fiscalmonth = date ( 'F', strtotime ( $getfiscaldate123 ) );
													$year1 = strtotime ( $getfiscaldate123 . '-1 year' );
													$year = substr ( date ( "Y", $year1 ), 2 );
													
													$changedate1 = date ( "Y", $year1 ) . '-' . $fiscalmonth . '-01';
													// $d=cal_days_in_month(CAL_GREGORIAN,,1965);
													
													$date1 = date ( "Y-m-d", strtotime ( $changedate1 ) );
													
													$numericmonth = explode ( "-", $date1 );
													$d = cal_days_in_month ( CAL_GREGORIAN, $numericmonth [1], $numericmonth [0] );
													$changedate2 = date ( "Y", $year1 ) . '-' . $numericmonth [1] . '-' . $d;
													
													$date2 = date ( "Y-m-d", strtotime ( $changedate2 ) );
													
													$value = $db->run ( "SELECT COUNT( t_leave) as counting FROM attendence WHERE date between '$date1' and '$date2' and e_id=$rowemployee[e_id] and t_leave=''" )->fetch ();
													
													$a .= $value ['counting'] . ',';
													
													$month1 = substr ( $fiscalmonth, 0, 3 );
													$month .= "'$month1($year)'" . ',';
													// echo $getfiscaldate;
													$getfiscaldate123 = date ( "Y-m-d", strtotime ( "+1 month", strtotime ( $getfiscaldate123 ) ) );
													$count ++;
												}
												
												echo "data: [$a]";
												echo "},";
											
											}
											
											?>
													   ]
										        });
										    });
									    </script>
									    <?php }?>

										<div class="widget-body">
							<div class="widget-main">
											<?php
											$attendencefirst = $db->get_count ( "attendence" );
											if ($attendencefirst != 0) {
												?>
												<div id="container3"
									style="min-width: 310px; height: 400px; margin: 0 auto"></div>
											<?php
											} else {
												?>
													<div class="alert alert-warning">
									<button type="button" class="close" data-dismiss="alert">
										<i class="icon-remove"></i>
									</button>
									<strong>Oh Snap!</strong> No Data Display... <br>
								</div>
												<?php
											
											}
											?>	
											</div>
						</div>
					</div>
				</div>
				<!--/span-->
			</div>
			<!-- rowfluid -->
			<!-- <div class="row-fluid">
				<div class="span6">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="smaller">Payments</h4>
						</div>
										<?php
										/*
										 * $paymentcheck = $db->get_count (
										 * "payment" ); $settingcheck =
										 * $db->get_col ( "setting", array ("id"
										 * => 1 ), 'currency' ); if
										 * ($paymentcheck != 0) {
										 */
										?>
										<script type="text/javascript">
										$(function () {
									    	
									    	// Radialize the colors
											Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
											    return {
											        radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
											        stops: [
											            [0, color],
											            [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
											        ]
											    };
											});
											
											// Build the chart
									        $('#container').highcharts({
									            chart: {
									                plotBackgroundColor: null,
									                plotBorderWidth: null,
									                plotShadow: false
									            },
									            title: {
									                text: 'Total Payment In Income And Expense'
									            },
									            
									           
									            series: [{
									                type: 'pie',
									                name: 'Payment Details In <?php /* if($settingcheck[0] != '') echo CURRENCY; */?>',
									                data: [
									                    
									                    {
									                        name: 'Total Income',
									                        y: <?php /* if($null != ''){echo $null; }else {echo 0;} */?>,
									                        sliced: true,
									                        selected: true
									                    },
									                    
									                    ['Total Expense', <?php /* if($blank !=''){echo $blank;} else {echo 0;} */?>]
									                ]
									            }]
									        });
									    });
											</script>
											<?php //}?>

										<div class="widget-body">
							<div class="widget-main">
											<?php
											/*
											 * $paymentcheck = $db->get_count (
											 * "payment" ); if ($paymentcheck !=
											 * 0) {
											 */
											?>
												<div id="container"
									style="min-width: 310px; height: 400px; margin: 0 auto"></div>
											<?php
											/*
											 * } else {
											 */
											?>
													<div class="alert alert-error">
									<button type="button" class="close" data-dismiss="alert">
										<i class="icon-remove"></i>
									</button>

									<strong> <i class="icon-remove"></i> Oh snap!
									</strong> No Data Display.. <br>
								</div>
												<?php
												
												// }
												?>	
											</div>
						</div>
					</div>
				</div>
				<!--/span-->

			<!-- <div class="span6">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="smaller">Clients</h4>
						</div>
										<?php
										/*
										 * $clientcheck = $db->get_count (
										 * "clients" ); if ($clientcheck != 0) {
										 * $totalclient = $db->run ( "select
										 * distinct sec_status from clients" );
										 */
										?>
											
										<script type="text/javascript">
											$(function () {
												Highcharts.setOptions({
												     colors: [ '#24CBE5', '#64E572', '#FF9655']
												    });
											    $('#container1').highcharts({
											        chart: {
											            plotBackgroundColor: null,
											            plotBorderWidth: 0,
											            plotShadow: false
											        },
											        title: {
											            text: 'Clients<br>Details',
											            align: 'center',
											            verticalAlign: 'middle',
											            y: 50
											        },
											        
											        plotOptions: {
											            pie: {
											                dataLabels: {
											                    enabled: true,
											                    distance: -50,
											                    style: {
											                        fontWeight: 'bold',
											                        color: 'white',
											                        textShadow: '0px 1px 2px black'
											                    }
											                },
											                startAngle: -90,
											                endAngle: 90,
											                center: ['50%', '75%']
											            }
											        },
											        series: [{
											            type: 'pie',
											            name: 'Total',
											            innerSize: '50%',
											            data: 
											           // [[ 'Qualified Lead',2],[ 'prospective',1],[ 'status1',1],[ 'status3',1]]
											           <?php
																						/*
																						 *
																						 * echo
																						 * "[";
																						 * foreach
																						 * (
																						 * $totalclient
																						 * as
																						 * $row
																						 * )
																						 * {
																						 * $findnumber
																						 * =
																						 * $db->get_count
																						 * (
																						 * "clients",
																						 * array
																						 * ("sec_status"
																						 * =>
																						 * $row
																						 * ['sec_status']
																						 * )
																						 * );
																						 * $aclients
																						 * .=
																						 * "[
																						 * '$row[sec_status]',$findnumber],";
																						 * }
																						 * echo
																						 * rtrim
																						 * (
																						 * $aclients,
																						 * ','
																						 * );
																						 * echo
																						 * "]";
																						 */
																						?> 	 
											        }]
											    });
											});
										</script>
										<?php //}?>
										<div class="widget-body">
							<div class="widget-main">
												<?php
												/*
												 * $clientcheck = $db->get_count
												 * ( "clients" ); if
												 * ($clientcheck != 0) {
												 */
												?>
														<div id="container1"
									style="min-width: 310px; height: 400px; margin: 0 auto"></div>
												<?php
												/*
												 * } else {
												 */
												?>
														<div class="alert alert-info">
									<button type="button" class="close" data-dismiss="alert">
										<i class="icon-remove"></i>
									</button>
									<strong>Oh Snap!</strong> No Data Display <br>
								</div>
													<?php
													
													// }
													?>		
											</div>
						</div>
					</div>
				</div>
				<!--/span-->
			<!-- </div>-->
			<!--/row-->
			<br> <br>
			<div class="row-fluid">
				<div class="span12">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="smaller">Awards</h4>
						</div>
										<?php
										$awardscheck = $db->get_count ( "earlier_award" );
										if ($awardscheck != 0) {
											?>
										<script type="text/javascript">
										$(function () {
											
									        $('#last').highcharts({
									            chart: {
									                type: 'column',
									                margin: [ 50, 50, 100, 80]
									            },
									            plotOptions: {
									                column: {
									                    colorByPoint: true
									                }
									            },
									            colors: [
									            
									                '#ff0000',
									                '#00ff00',
									                '#0000ff',
									                '#2f7ed8', 
									                '#0d233a', 
									                '#8bbc21', 
									                '#910000', 
									                '#1aadce', 
									                '#492970',
									                '#f28f43', 
									                '#77a1e5', 
									                '#c42525', 
									                '#a6c96a',
									                '#4572A7', 
									                '#AA4643', 
									                '#89A54E', 
									                '#80699B', 
									                '#3D96AE', 
									                '#DB843D', 
									                '#92A8CD', 
									                '#A47D7C', 
									                '#B5CA92'
									            ],
									            title: {
									                text: 'Monthly Awards'
									            },
									            xAxis: {
									                categories: [
									                    <?php
											$employee = $db->get_all ( 'employees' );
											$name = '';
											foreach ( $employee as $row ) {
												$name .= "'$row[e_name]'" . ',';
											}
											
											echo rtrim ( $name, ',' );
											?>
									                ],
									                labels: {
									                    rotation: -45,
									                    align: 'right',
									                    style: {
									                        fontSize: '13px',
									                        fontFamily: 'Verdana, sans-serif'
									                    }
									                }
									            },
									            yAxis: {
									                min: 0,
									                title: {
									                    text: 'Total Number Of Awards'
									                }
									            },
									            legend: {
									                enabled: false
									            },
									            tooltip: {
									                pointFormat: 'Total Number Of Awards: <b>{point.y:f} </b>',
									            },
									            
									            series: [{
									                name: 'Population',
									                data: [
											                <?php
											$awards = $db->get_all ( 'earlier_award' );
											$employee = $db->get_all ( 'employees' );
											
											foreach ( $employee as $row ) {
												$total = $db->get_count ( "earlier_award", array ('e_id' => $row ['e_id'] ) );
												$total1 .= $total . ',';
											}
											
											echo rtrim ( $total1, ',' );
											?>
											              ],
									                dataLabels: {
									                    enabled: true,
									                    rotation: -90,
									                    color: '#FFFFFF',
									                    align: 'right',
									                    x: 4,
									                    y: 10,
									                    style: { 
									                        fontSize: '23px',
									                        fontFamily: 'Verdana, sans-serif',
									                        textShadow: '0 0 3px black'
									                    }
									                }
									            }]
									        });
									    });


										
										</script>
										<?php }?>

										<div class="widget-body">
							<div class="widget-main">
												<?php
												$awardscheck = $db->get_count ( "earlier_award" );
												if ($awardscheck != 0) {
													?>
													<div id="last"
									style="min-width: 500px; height: 400px; margin: 0 auto"></div>
												<?php
												} else {
													?>
														<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="icon-remove"></i>
									</button>
									<strong>Oh Snaps!</strong> No Data Display... <br>
								</div>
													<?php
												
												}
												?>
											</div>
						</div>
					</div>
				</div>
				<!--/span-->
			</div>
			<!-- rowfluid -->

			<!--PAGE CONTENT ENDS-->
		</div>
		<!--/.span-->
	</div>
	<!--/.row-fluid-->
</div>
<!--/.page-content-->


</div>
<!--/.main-content-->