<?php $__env->startSection('content'); ?>

						<?php if(session('status')): ?>
							<div class="alert alert-success">
								<?php echo e(session('status')); ?>

							</div>
						<?php endif; ?>
			
						<?php if(count($errors) > 0): ?>
							<div class="alert alert-danger">
								<strong>Whoops!</strong> There were some problems with your input.<br><br>
								<ul>
									<?php foreach($errors->all() as $error): ?>
										<li><?php echo e($error); ?></li>
									<?php endforeach; ?>
								</ul>
							</div>
						<?php endif; ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header" style="text-align: center;">Dashboard: Projects<i class="fa fa-refresh hidden-xs" style="float: right; cursor: pointer;" onclick="location.reload()"></i></h1>
    	</div>
    </div>
    <div class="row">
    	
    	<div class="col-md-12">
    		<div class="panel panel-default">
                        <div class="panel-heading">
                            Active Projects: Status
                        </div>
                        <div class="panel-body">
                            <div id="active_projects_status"></div>
                        </div>
            </div>
    	</div>

    	
    </div>
    <?php if(true): ?>

    
    <?php 
    	$currentWeek = strtotime('today 3:00 am') == strtotime('Sunday 3:00 am') ? strtotime('today 3:00 am') : strtotime('last Sunday 3:00 am') ; 
    	$weekStart = $currentWeek - 7257600;
    	$monthStart = $weekStart;
    	$projectStart = $weekStart;
    	$months = array();

    	for($i=1;$i<=26;$i++)
    	{
    		if(!array_key_exists(date('M', $monthStart), $months))
    		{
    			$months[date('M', $monthStart)] = 1;
    		}
    		else 
    		{
    			$months[date('M', $monthStart)]++;
    		}
    		
    		$monthStart += 604800;
    	}
    ?>
    
    
    <div class="row">
    	<div class="col-md-12">
    		<div class="panel panel-default">
                        <div class="panel-heading">
                            Active Projects: Timeline
                        </div>
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-gantt" >
                                    <thead>
                                        <tr>
                                            
                                            <th colspan="4">&nbsp;</th>
											
                                            <?php foreach($months as $month => $weeks): ?>
                                            <th colspan="<?php echo e($weeks); ?>"><?php echo e($month); ?></th>	
                                            <?php endforeach; ?>
                                            

                                        </tr>
                                        <tr>
                                        	<th>Company</th>
                                            <th>City</th>
                                            <th>Sold</th>
                                            <th>Due</th>
                                            <?php for($i=1;$i<=26;$i++): ?>
                                            <?php if($weekStart == $currentWeek): ?>
                                            <th style="border-right: 1px solid gray;">
                                            <?php else: ?>
                                            <th>
                                            <?php endif; ?>
                                            
                                            	<?php echo e(date('d', $weekStart)); ?>

                                            </th>
                                            <?php $weekStart += 604800; ?>
                                            <?php endfor; ?>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php $count = 0;  ?>
                                    <?php foreach($all_active as $project): ?>
                                    <?php if($project->desired_due_date != '' && strtotime($project->desired_due_date) != 0): ?>
                                    <?php $count++; ?>
                                    <?php if($count % 2 == 1): ?>
                                        <tr class="odd" title="Status: <?php echo e($team_object->find($project->status)->name); ?>">
                                    <?php else: ?>
                                    	<tr class="even" title="Status: <?php echo e($team_object->find($project->status)->name); ?>">
                                    <?php endif; ?>
                                            <td><a href="<?php echo e(url('uadmin/projects/report/'.$project->id)); ?>" target="_blank"><?php echo e($project->company_name); ?></a></td>
                                            <td><?php echo e($project->service_city); ?></td>
                                            <td><i style="display: none;"><?php echo e($project->date_sold); ?> </i><?php echo e($project->date_sold != '' && strtotime($project->date_sold) != 0 ? date('M d', strtotime($project->date_sold)) : ''); ?></td>
                                            <td><i style="display: none;"><?php echo e($project->desired_due_date); ?></i><?php echo e($project->desired_due_date != '' && strtotime($project->desired_due_date) != 0 ? date('M d', strtotime($project->desired_due_date)) : ''); ?></td> 
                                            
                                            <?php $projectWeeks = $projectStart; 
                                            
                                            		$soldWeek = strtotime(date('Y-m-d', strtotime($project->date_sold)).' 3:00 am') == strtotime('Sunday 3:00 am', strtotime(date('Y-m-d', strtotime($project->date_sold)).' 3:00 am')) 
                                            					? strtotime(date('Y-m-d', strtotime($project->date_sold)).' 3:00 am') : strtotime('last Sunday 3:00 am', strtotime(date('Y-m-d', strtotime($project->date_sold)).' 3:00 am')) ; 
                                            		
                                            		$dueWeek = strtotime(date('Y-m-d', strtotime($project->desired_due_date)).' 3:00 am') == strtotime('Sunday 3:00 am', strtotime(date('Y-m-d', strtotime($project->desired_due_date)).' 3:00 am')) 
                                            					? strtotime(date('Y-m-d', strtotime($project->desired_due_date)).' 3:00 am') : strtotime('last Sunday 3:00 am', strtotime(date('Y-m-d', strtotime($project->desired_due_date)).' 3:00 am')) ; 
                                            		
                                            		$lastClass = '';
                                            		$nextWeek = false;
                                            ?>
                                            
                                            <?php for($i=1;$i<=26;$i++): ?>
                                            	
                                            	<?php 
                                            		$class = '';
                                            		if($projectWeeks > $soldWeek && $projectWeeks < $dueWeek) $class = 'mid';
                                            		if(date('Y-m-d', $projectWeeks) == date('Y-m-d', $soldWeek)) $class = 'start';
                                            		if(date('Y-m-d', $projectWeeks) == date('Y-m-d', $dueWeek)) $class = 'end';
                                            		if($projectWeeks > $dueWeek && $dueWeek < $currentWeek && $projectWeeks <= $currentWeek) $class = 'overdue';
                                            		if($i == 26 && $projectWeeks > $soldWeek && $projectWeeks < $dueWeek) $class = 'leaving';
                                            		if($i == 1 && $projectWeeks > $soldWeek && $projectWeeks < $dueWeek) $class = 'entering';
                                            		
                                            	?>
                                            	<?php if($projectWeeks == $currentWeek): ?>
                                            	<td style="padding: 0; border: 0px; border-right: 1px solid gray;"><div class="<?php echo e($class); ?>">&nbsp;</div></td>
                                            	<?php else: ?>
                                            	<td style="padding: 0; border: 0px;"><div class="<?php echo e($class); ?>">&nbsp;
                                            		
                                            	</div>
                                            	<?php if($nextWeek): ?>
                                            		<div class="currentStatus" style="
                                            		<?php if($class == '' || $class == "end"): ?>
                                            			color: #317aba;
                                            		<?php endif; ?>
                                            		<?php if($class == "end"): ?>
                                            			
														margin-top: -10px; 
                                            		<?php endif; ?>
                                            		"><?php echo e($team_object->find($project->status)->name); ?></div>
                                            		<?php $nextWeek = false; ?>
                                            	<?php endif; ?>
                                            	</td>
                                            	<?php endif; ?>
                                            	<?php if($projectWeeks == $currentWeek): ?>
                                            	
                                            	<?php $nextWeek = true; ?>
                                            	<?php endif; ?>
                                            	<?php $projectWeeks += 604800; 
                                            		  $lastClass = $class;
                                            		  
                                            	?>
                                            <?php endfor; ?>
                                        </tr>
                                        <?php endif; ?>
                                    <?php endforeach; ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
            </div>
                <div class="panel panel-default">
                      <div class="panel-heading">
                            Archived Projects
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example2">
                                    <thead>
                                        <tr>
                                            <th>Company</th>
                                            <th>City</th>
                                            <th>Date Sold</th>
                                            <th>Project Created</th>
                                            <th>Completed</th>
                                            <th>Action</th>
                                            <th>Keywords</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php $count = 0; ?>
                                    <?php foreach($archives as $archive): ?>
                                    <?php $count++; ?>
                                    <?php if($count % 2 == 1): ?>
                                        <tr class="odd">
                                    <?php else: ?>
                                    	<tr class="even">
                                    <?php endif; ?>
                                            <td><?php echo e($archive->company_name); ?></td>
                                            <td><?php echo e($archive->service_city); ?></td>
                                            <td><?php echo e($archive->date_sold != '' && strtotime($archive->date_sold) != 0 ? date('Y-m-d', strtotime($archive->date_sold)) : ''); ?></td>
                                            <td><?php echo e($archive->created_at != '' && strtotime($archive->created_at) != 0 ? date('Y-m-d', strtotime($archive->created_at)) : ''); ?></td>
                                            <td><?php echo e($archive->done != '' && strtotime($archive->done) != 0 ? date('Y-m-d', strtotime($archive->done)) : ''); ?></td>
                                            <td style="text-align: center;">
                                            <!--
                                            <a href="<?php echo e(url('uadmin/projects/view/'.$archive->id)); ?>" target="_blank">
                                             
                                            		<i class="fa fa-file-text-o fa-fw" style="text-align: left;"></i>
                                            	</a>
                                            	 
                                            	&nbsp &nbsp  --> 
                                            	<a href="<?php echo e(url('uadmin/projects/report/'.$archive->id)); ?>" target="_blank"><i class="fa fa-file-pdf-o"></i></a>
                                            	
                                            	
                                            </td>
                                            <td>
                                            	<?php echo e($archive->order_type); ?> &nbsp;
                                            	<?php echo e($archive->customer_type); ?> &nbsp;
                                            	<?php echo e($archive->sales_exec); ?> &nbsp;
                                            	<?php echo e($archive->client_primary_contact); ?> &nbsp;
                                            	<?php echo e($archive->billing_attention); ?> &nbsp;
                                            	<?php echo e($archive->technical_contact); ?> &nbsp;
												<?php echo e($archive->service_city); ?> &nbsp;
                                            	<?php echo e($archive->service_zip); ?> &nbsp;
                                            	<?php echo e($archive->account_num); ?> &nbsp;
                                            	<?php echo e($archive->contact_primary_email); ?> &nbsp;
                                            	<?php echo e($archive->technical_email); ?> &nbsp;
                                            </td>
                                        </tr>
                                  	<?php endforeach; ?>
                                       </tbody>
                                	</table>
                                </div>
                             </div>
                         </div>
    	</div>
    </div>
    <?php endif; ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.css"/>
	<style>
		.pagination {
			float: right;
			margin-top: 0;
			margin-bottom: 0;
		}
		th {
			text-align: center;
		}
		
		.mid {
			width:100%; text-align:center; border-bottom: 14px solid #000; line-height:.75em; margin:0 0 0; border-color: #317aba; overflow: visible;
		}
		.start { 
			width:100%; text-align:center; border-bottom: 10px solid transparent; line-height:1em; margin:0 0 0; border-top: 10px solid transparent; border-right: 20px solid #31b953; height: 100%; border-top-right-radius: 20%; border-bottom-right-radius: 20%; overflow: visible;
		}
		.end {
			width:100%; text-align:center; border-bottom: 10px solid transparent; line-height:1em; margin:0 0 0; border-top: 10px solid transparent; border-left: 20px solid #b93131; height: 100%; border-top-left-radius: 20%; border-bottom-left-radius: 20%;overflow: visible; 
		}
		.overdue {
			width:100%; text-align:center; border-bottom: 14px ridge #000; line-height:.75em; margin:0 0 0; border-color: red; overflow: visible;
		}
		.entering {
			width:100%; text-align:center; border-bottom: 14px solid #000; line-height:.75em; margin:0 0 0; border-color: #317aba; border-bottom-left-radius: 100%; overflow: visible;
		}
		.leaving {
			width:100%; text-align:center; border-bottom: 14px solid #000; line-height:.75em; margin:0 0 0; border-color: rgba(48, 122, 190, .5); overflow: visible;
		}
		.currentStatus {
			max-width: 10px; overflow: visible; color: white; position: relative; bottom: 15px; font-size: 10px; white-space: nowrap; padding-left: 2.5em;
		}
	</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>
	<script src="<?php echo e(asset('uad/js/plugins/morris/morris.js')); ?>"></script>
	<script src="<?php echo e(asset('uad/js/plugins/morris/raphael.min.js')); ?>"></script>
	<script type="text/javascript" src="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.js"></script>
	<script>


	Morris.Bar({
		  element: 'active_projects_status',
		  data: [
            { y: 'Entry', a: <?php echo e($statuses[1]); ?> },
            { y: 'NNI', a: <?php echo e($statuses[2]); ?> },
            { y: 'Mapping', a: <?php echo e($statuses[3]); ?> },
            { y: 'Permits', a: <?php echo e($statuses[4]); ?> },
            { y: 'Constr.', a: <?php echo e($statuses[5]); ?> },
            { y: 'Splicing', a: <?php echo e($statuses[6]); ?> },
            { y: 'DC', a: <?php echo e($statuses[7]); ?> },
            { y: 'CPE', a: <?php echo e($statuses[8]); ?> },
            { y: 'SP/NA', a: <?php echo e($statuses[9]); ?> },
            { y: 'HV/CT', a: <?php echo e($statuses[10]); ?> },
            { y: 'NP', a: <?php echo e($statuses[11]); ?> },
            { y: 'Billing', a: <?php echo e($statuses[12]); ?> },
		  ],
		  xkey: 'y',
		  ykeys: ['a'],
		  labels: ['Projects'],
		  resize: true,
		});

    $(document).ready(function() {
        var table1 =    $('#dataTables-my_actives').dataTable( {
    					"pageLength": 4,
    					"stateSave" : false,
    					"searching" : false,
    					"lengthChange" : false,
    					"order" : [0, "asc"],
    					"pagingType" : "simple"
    					
            } );  


        });
    $(document).ready(function() {
        var table2 =    $('#dataTables-my_upcomings').dataTable( {
    					"pageLength": 4,
    					"stateSave" : false,
    					"searching" : false,
    					"lengthChange" : false,
    					"order" : [1, "desc"],
    					"pagingType" : "simple"
    					
            } );  


        });
    $(document).ready(function() {
        var table3 =    $('#dataTables-gantt').dataTable( {
    					"stateSave" : false,
    					"searching" : false,
    					"lengthChange" : false,
    					"order" : [3, "asc"],
    					"paging" : false,
    					"scrollX" : window.innerWidth < 1500 ? true : false,
    					"columnDefs": [
    			    				   <?php for($i=4;$i<30;$i++): ?>
    					               { "orderable": false, "targets": <?php echo e($i); ?> },
    					               <?php endfor; ?>
    					             ]
    					
    					
            } );  


        });

    $(document).ready(function() {
        var table4 =    $('#dataTables-example2').dataTable( {

    					"pageLength": 25,
    					"order": [ 4, 'desc' ],
    					"scrollX" : window.innerWidth < 800 ? true : false,
    					"columnDefs": [
    					               {
    					                   "targets": [ 6 ],
    					                   "visible": false,
    					                   "searchable": true
    					               },
    					           ]

            } );  


        });

        
        
        if ( typeof $.fn.dataTable == "function" && typeof $.fn.dataTableExt.fnVersionCheck == "function" && $.fn.dataTableExt.fnVersionCheck('1.9.2')/*older versions should work too*/ )
        {
            $.fn.dataTableExt.oApi.clearSearch = function ( oSettings )
            {
         
                var table = this;
                 
                //any browser, must include your own file
                //var clearSearch = $('<img src="/images/delete.png" style="vertical-align:text-bottom;cursor:pointer;" alt="Delete" title="Delete"/>');
                 
                //no image file needed, css embedding must be supported by browser
                var clearSearch = $('<i class="fa fa-times-circle-o fa-fw" style="vertical-align:text-bottom;cursor:pointer;color: gray;"></i>');
                $(clearSearch).click( function ()
                        {
                              table.fnFilter('');
                        });
                $(oSettings.nTableWrapper).find('div.dataTables_filter').append(clearSearch);
                $(oSettings.nTableWrapper).find('div.dataTables_filter label').css('margin-right', '-16px');//16px the image width
                $(oSettings.nTableWrapper).find('div.dataTables_filter input').css('padding-right', '16px');
            }
         
            //auto-execute, no code needs to be added
            $.fn.dataTable.models.oSettings['aoInitComplete'].push( {
                "fn": $.fn.dataTableExt.oApi.clearSearch,
                "sName": 'whatever'
            } );
        }
    
	</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>