<script type="text/javascript">

	var over_due_table     = $('.cls_datatable_overdue');
  var reminder_due_table = $('.cls_datatable_reminder');
  var booking_due_table  = $('.cls_datatable_booking_overdue');

	showBbranchWiseDashboard();

	function showBbranchWiseDashboard()
	{
    
		getBookingStats('Approved','green','Approve','#approve_stats');

		getBookingStats('Cancelled','blue','Cancel','#cancel_stats');

		getBookingStats('Unapproved','dark','Unapprove','#unapprove_stats');

		getOtherBookingStats('Hot','dark','Hot Booking','#hot_stats');

		getOtherBookingStats('Blocked','dark','Blocked Booking','#block_stats');

		getOtherBookingStats('Re-Sale','dark','Resale Booking','#resale_stats');

		getInventoryProgress('chart-donut');

		getSalesPersonProgress('#chart-combination');

    showBranchWiseTableDate(over_due_table,'totaloverdue','#total_over_due');

    showBranchWiseTableDate(reminder_due_table,'reminderoverdue','#five_day_reminder');

    showBranchWiseTableDate(booking_due_table,'bookingwiseoverdue','#bookingwise_overdue');

	}




	function getBookingStats(title,color,status,bind_element)
	{
		var branch   = $('select[name=branch]').val();

		var route    = "<?php echo e(route('bookingstats')); ?>";

		var data_set = {_token:token,status:status,title:title,color:color,branch:branch};
           
   		$.post(route,data_set,function(data){

   			if(data.status == "true")
   			{
   				$(bind_element).html(data.view);
   			}
   		});
	}

	function getOtherBookingStats(title,color,type_of_booking,bind_element)
	{
		var branch   = $('select[name=branch]').val();

		var route    = "<?php echo e(route('otherbookingstats')); ?>";

		var data_set = {_token:token,type_of_booking:type_of_booking,title:title,color:color,branch:branch};
           
   		$.post(route,data_set,function(data){

   			if(data.status == "true")
   			{
   				$(bind_element).html(data.view);
   			}
   		});
	}

	function getInventoryProgress(bind_element)
	{
		$('#'+bind_element).html('');
		
		var branch   = $('select[name=branch]').val();

		var route    = "<?php echo e(route('inventoryprogress')); ?>";

		var data_set = {_token:token,branch:branch};
           
   		$.post(route,data_set,function(data){

   			if(data.status == "true")
   			{
   				var inventory_progress = data.view;

	            var  inventory_dataset = [];

	            for(i = 0; i<inventory_progress.length; i++)
	            {
	                inventory_dataset.push({label: inventory_progress[i].block_name, value: inventory_progress[i].count});
	            }

	            Morris.Donut({
	                element: bind_element,
	                data:inventory_dataset,
	                colors: ['blue', 'green','pink','red','gray','red','orange'],
	                resize: true,
	            });

   			}
   		});
	}

	function getSalesPersonProgress(bind_element)
	{
		var branch   = $('select[name=branch]').val();

		var route    = "<?php echo e(route('salespersonprogress')); ?>";

		var data_set = {_token:token,branch:branch};
           
   		$.post(route,data_set,function(result){

   			if(result.status == "true")
   			{
   				require(['c3', 'jquery'], function(c3, $) {
                    $(document).ready(function(){
                      var chart = c3.generate({
                        bindto: bind_element, // id of chart wrapper
                        data: {
                          columns: [
                              // each columns data
                           result.view.sales
                            
                          ],
                          type: 'bar', // default type of chart
                          types: {
                            'data2': "line",
                            'data3': "spline",
                          },
                          groups: [
                            [ 'data1', 'data4']
                          ],
                          colors: {
                            'data1': tabler.colors["green"],
                            'data2': tabler.colors["pink"],
                            'data3': tabler.colors["green"],
                            'data4': tabler.colors["blue"]
                          },
                          names: {
                              // name of each serie
                            'data1': 'Total Sales',
                            'data2': 'Marketing',
                            'data3': 'Sales',
                            'data4': 'Sales'
                          }
                        },
                        axis: {
                          x: {
                            type: 'category',
                            // name of each category
                            categories: result.view.sales_list
                          },
                        },
                        bar: {
                          width: 16
                        },
                        legend: {
                                  show: false, //hide legend
                        },
                        padding: {
                          bottom: 0,
                          top: 0
                        },
                      });
                    });
                  });

   			}
   		});
	}

  function showBranchWiseTableDate(datatable_element,route,bind_element)
  {

      var branch = $('select[name=branch]').val();

      route = route;

      var data_set = {_token:token,branch:branch};

      resetDataTable(datatable_element);

             
      $.post(route,data_set,function(data){

          if(data.status == "true")
          {
             $(bind_element).html(data.view);

               reiniDataTable(datatable_element);

          }
          else
          {
              $(bind_element).html(data.view);

              reiniDataTable(datatable_element);
              
          }
      });
  }

</script><?php /**PATH /home/ubuntu/rebmgisplus/skylite/resources/views/scripts/component.blade.php ENDPATH**/ ?>