 
<?php $__env->startSection('content'); ?>
	<div class="row">
		<div class="col-lg-12">
			<h2>Stats: Marketing Edition</h2>
			<h4>Execution Time: <?php echo e($execution_time); ?> seconds</h4>
			<h4>Execution Memory: <?php echo e($execution_memory); ?> megabytes</h4>
		</div>
	</div>

	<div class="row">
		<div class="col-lg-12">
			<br>
			<strong>
				<?php
					$lastMonthDeleted = \App\Order::onlyTrashed()
						->where('created_at','>',date('Y-m-d',strtotime('first day of last month')).' 00:00:00')
						->where('created_at','<',date('Y-m-d',strtotime('first day of this month')).' 00:00:00')
						->where('deleted_at','>',date('Y-m-d',strtotime('first day of this month')).' 00:00:00')
						->select('id')
						->get();

					$totalDeletedReoccuringRevenue = 0.00;
					$totalDeletedOneTimeRevenue = 0.00;

					foreach($lastMonthDeleted as $deletedOrder)
					{
						foreach(\App\Ordered_Service::where('order','=',$deletedOrder->id)->get() as $orderedService)
						{
							$theService = \App\Service::where('id','=',$orderedService->service)->first();
							if($theService && $theService->billing_type == 'monthly')
							{
								$totalDeletedReoccuringRevenue += $theService->price;
							}
							if($theService && $theService->billing_type == 'once')
							{
								$totalDeletedOneTimeRevenue += $theService->price;
							}
						}
					}

				?>
				Previously active orders created in <?php echo e(date('F',strtotime('first day of last month'))); ?> that have been deleted this month: 
				<?php echo e($lastMonthDeleted->count()); ?>

				</strong>
				&nbsp;
				<i>(MRC: $<?php echo e($totalDeletedReoccuringRevenue); ?> | NRC: $<?php echo e($totalDeletedOneTimeRevenue); ?>)</i>
				<br>
		</div>
	</div>

	<div class="row">
		
		<div id="monthly_graph"></div>
		<div id="daily_graph"></div>
		<div id="map_graph"></div>
		<div id="compare_graph"></div>
		<div id="compare_graph_rev"></div>
		<div id="compare_graph_ser"></div>
		<div id="compare_graph_gro"></div>
		<br><br>

		<br><br>
	</div>
<?php $__env->stopSection(); ?>

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

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

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

	<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
	<script>

	var selectorOptionsDaily = {
	    buttons: [{
	        step: 'month',
	        stepmode: 'backward',
	        count: 1,
	        label: '1m'
	    }, {
	        step: 'month',
	        stepmode: 'backward',
	        count: 6,
	        label: '6m'
	    }, {
	        step: 'year',
	        stepmode: 'todate',
	        count: 1,
	        label: 'YTD'
	    }, {
	        step: 'year',
	        stepmode: 'backward',
	        count: 1,
	        label: '1y'
	    }, {
	        step: 'all',
	    }],
	};



	    var dataDaily = prepDataDaily();
	    var layoutDaily = {
	        title: 'Daily Total - Reoccurring',
	        xaxis: {
	            rangeselector: selectorOptionsDaily,
	            rangeslider: {},
	            tickformat: '%b %e %A'
	        },
	        yaxis: {
	            fixedrange: true, hoverformat: '.2f', tickformat: 'd'
	        }
	    };

	    Plotly.plot('daily_graph', dataDaily, layoutDaily);


	function prepDataDaily() {
	    var x = [];
	    var y = [];


			<?php foreach($daily_data as $key => $value): ?>
	        x.push(new Date(<?php echo e($key * 1000); ?>));
	        y.push(<?php echo e($value); ?>);
			<?php endforeach; ?>

	    return [{
	        mode: 'lines',
	        x: x,
	        y: y
	    }];
	}

	var dataMonthly = [
	            {
	              x: [
		              <?php foreach($monthly_data as $key2 => $value2): ?>
						'<?php echo e(date("F Y", $key2)); ?>',
		              <?php endforeach; ?>
		              ],
	              y: [
						<?php foreach($monthly_data as $key2 => $value2): ?>
						'<?php echo e($value2); ?>',
						<?php endforeach; ?>
		              ],
	              type: 'bar'
	            }
	          ];

	var layoutMonthly = 
				{
					title: 'Monthly Total - Reoccuring',
					yaxis:{hoverformat: '.2f', tickformat: 'd'}
				};

	          Plotly.newPlot('monthly_graph', dataMonthly, layoutMonthly);

				var trace1 = {
				  x: ['10MEG', '20MEG', '50MEG', '100MEG'],
				  y: [1, 1, 1, 1],
				  name: 'Santaquin',
				  type: 'scatter'
				};

				var trace2 = {
				  x: ['10MEG', '20MEG', '50MEG', '100MEG'],
				  y: [1, 1, 1, 1],
				  name: 'Richfield',
				  type: 'scatter'
				};

				<?php foreach($ad_media as $k => $type): ?>
					var <?php echo e(str_replace(' ','',$k)); ?> = {
						x: [
							<?php foreach($all_dates as $date): ?>
								'<?php echo e($date); ?>',
							<?php endforeach; ?>
						],
						y: [
							<?php foreach($all_dates as $date): ?>
								<?php if(array_key_exists($date, $type)): ?>
									'<?php echo e($type[$date]); ?>',
								<?php else: ?>
									'0',
								<?php endif; ?>
							<?php endforeach; ?>
						],
						name: '<?php echo e($k); ?>',
						type: 'scatter'

					};
				<?php endforeach; ?>

				var data = [
					<?php foreach($ad_media as $k => $type): ?>
						<?php echo e(str_replace(' ','',$k)); ?>,
					<?php endforeach; ?>
				];

				var layout = {
						
						title: 'Ad Media - Order Totals',
						tickformat: '%b %Y'
							};

				Plotly.newPlot('compare_graph', data, layout);

				<?php foreach($ad_media_rev as $ke => $type): ?>

					var <?php echo e(str_replace(' ','',$ke)); ?>_rev = {
						x: [
							<?php foreach($all_dates_rev as $date): ?>
								'<?php echo e($date); ?>',
							<?php endforeach; ?>
						],
						y: [
							<?php foreach($all_dates_rev as $date): ?>
								<?php if(array_key_exists($date, $type)): ?>
									'<?php echo e($type[$date]); ?>',
								<?php else: ?>
									'0',
								<?php endif; ?>
							<?php endforeach; ?>
						],
						name: '<?php echo e($ke); ?>',
						type: 'scatter'

					};
				<?php endforeach; ?>

				var dataRev = [
					<?php foreach($ad_media_rev as $ke => $type): ?>
						<?php echo e(str_replace(' ','',$ke)); ?>_rev,
					<?php endforeach; ?>
				];

				var layoutRev = {
						
						title: 'Ad Media - Reoccuring Totals',
						tickformat: '%b %Y',

       					 yaxis:{hoverformat: '.2f', tickformat: 'd'}
							};

				Plotly.newPlot('compare_graph_rev', dataRev, layoutRev);

				<?php foreach($services_rev as $kee => $type): ?>

					var s_<?php echo e(str_replace('/','',str_replace(')','',str_replace('(','',str_replace('-','',str_replace(' ','',$kee)))))); ?>_rev = {
						x: [
							<?php foreach($all_dates_rev as $date): ?>
								'<?php echo e($date); ?>',
							<?php endforeach; ?>
						],
						y: [
							<?php foreach($all_dates_rev as $date): ?>
								<?php if(array_key_exists($date, $type)): ?>
									'<?php echo e($type[$date]); ?>',
								<?php else: ?>
									'0',
								<?php endif; ?>
							<?php endforeach; ?>
						],
						name: '<?php echo e($kee); ?>',
						type: 'scatter',
						visible: 'legendonly'

					};
				<?php endforeach; ?>

				var dataSer = [
					<?php foreach($services_rev as $ke => $type): ?>
						s_<?php echo e(str_replace('/','',str_replace(')','',str_replace('(','',str_replace('-','',str_replace(' ','',$ke)))))); ?>_rev,
					<?php endforeach; ?>
				];

				var layoutSer = {
						
						title: 'Services - Reoccuring Totals (select services from legend below)',
						tickformat: '%b %Y',

       					 yaxis:{hoverformat: '.2f', tickformat: 'd'}
							};

				Plotly.newPlot('compare_graph_ser', dataSer, layoutSer);

				<?php foreach($groups_rev as $kee => $type): ?>

					var g_<?php echo e(str_replace('&','',str_replace('/','',str_replace(')','',str_replace('(','',str_replace('-','',str_replace(' ','',$kee))))))); ?>_rev = {
						x: [
							<?php foreach($all_dates_rev as $date): ?>
								'<?php echo e($date); ?>',
							<?php endforeach; ?>
						],
						y: [
							<?php foreach($all_dates_rev as $date): ?>
								<?php if(array_key_exists($date, $type)): ?>
									'<?php echo e($type[$date]); ?>',
								<?php else: ?>
									'0',
								<?php endif; ?>
							<?php endforeach; ?>
						],
						name: '<?php echo e($kee); ?>',
						type: 'scatter'

					};
				<?php endforeach; ?>

				var dataGro = [
					<?php foreach($groups_rev as $ke => $type): ?>
						g_<?php echo e(str_replace('&','',str_replace('/','',str_replace(')','',str_replace('(','',str_replace('-','',str_replace(' ','',$ke))))))); ?>_rev,
					<?php endforeach; ?>
				];

				var layoutGro = {
						
						title: 'Service Groups - Reoccuring Totals',
						tickformat: '%b %Y',

       					 yaxis:{hoverformat: '.2f', tickformat: 'd'}
							};

				Plotly.newPlot('compare_graph_gro', dataGro, layoutGro);


	</script>








<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>