<?php $__env->startSection('content'); ?>
<?php
use App\Models\Sales;
?>
  <title><?php echo e(trans('admin.EmpGoals')); ?></title>


    <main id="js-page-content" role="main" class="page-content">
                    <ol class="breadcrumb page-breadcrumb no-print">
                      <li class="breadcrumb-item"><a href="javascript:void(0);"><?php echo e(trans('admin.Reports')); ?> </a></li>
                        <li class="breadcrumb-item active">  <?php echo e(trans('admin.EmpGoals')); ?>   </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>
                    
           
                    <div class="row ">
                        <div class="col-xl-12">
                            <div id="panel-1" class="panel">
                                <div class="panel-hdr">
                                    <h2>
                                   <?php echo e(trans('admin.EmpGoals')); ?>

                                    </h2>

                                </div>
                                <div class="panel-container show">
                                    <div class="panel-content">
 
                                        <!-- datatable start -->
                                        <table id="X" class="table table-bordered">
                                          <thead>
                                            <tr>
                                              <th><?php echo e(trans('admin.Name')); ?></th>
                                              <th><?php echo e(trans('admin.PreviousMonth')); ?></th>
                                              <th></th>
                                              <th><?php echo e(trans('admin.Sales')); ?></th>
                                              <th><?php echo e(trans('admin.MonthlyTarget')); ?></th>
                                                  <th></th>
                                              <th><?php echo e(trans('admin.Sales')); ?></th>
                                              <th><?php echo e(trans('admin.QuarterTarget')); ?></th>
                                                  <th></th>
                                              <th><?php echo e(trans('admin.Sales')); ?></th>
                                              <th><?php echo e(trans('admin.SemiTarget')); ?></th>
                                                  <th></th>
                                              <th><?php echo e(trans('admin.Sales')); ?></th>
                                              <th><?php echo e(trans('admin.YearlyTarget')); ?></th>
                                                  <th></th>
                                              <th><?php echo e(trans('admin.Sales')); ?></th>
                                            </tr>
                                            </thead>
                                            <tbody class="Data">
                                                <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php
                                                  $d = new DateTime('first day of this month');
   
         $fromP=date('Y-m-d', strtotime(date('Y-m')." -1 month"));      
         $ToP=date('Y-m-t',strtotime('last month')); 
              
              
       $from=$d->format('Y-m-d');    
       $to=date('Y-m-t',strtotime('today'));    
       
                $fromQ=date('Y-m-d', strtotime('first day of january this year'));    
       $toQ=date('Y-m-d', strtotime("+3 months", strtotime($fromQ)));  
              
                $fromS=date('Y-m-d', strtotime('first day of january this year'));    
       $toS=date('Y-m-d', strtotime("+6 months", strtotime($fromS)));  
              
                $fromY=date('Y-m-d', strtotime('first day of january this year'));    
       $toY=date('Y-m-d', strtotime('Dec 31'));  
              
              
              
       $previousMonthT=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromP,$ToP])
           ->get()->sum('Total_Price');
            
               $previousMonthTax=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromP,$ToP])
           ->get()->sum('Total_Taxes');
              
               $previousMonthDisc=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromP,$ToP])
           ->get()->sum('Total_Discount');
              
              $previousMonth=  ($previousMonthT +  $previousMonthTax)  - $previousMonthDisc ;
              
              
                    $CurrentMonthT=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$from,$to])
           ->get()->sum('Total_Price');
            
               $CurrentMonthTax=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$from,$to])
           ->get()->sum('Total_Taxes');
              
               $CurrentMonthDisc=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$from,$to])
           ->get()->sum('Total_Discount');
              
              $CurrentMonth=  ($CurrentMonthT +  $CurrentMonthTax)  - $CurrentMonthDisc ;
              
              
               $QMonthT=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromQ,$toQ])
           ->get()->sum('Total_Price');
            
               $QMonthTax=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromQ,$toQ])
           ->get()->sum('Total_Taxes');
              
               $QMonthDisc=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromQ,$toQ])
           ->get()->sum('Total_Discount');
              
              $QMonth=  ($QMonthT +  $QMonthTax)  - $QMonthDisc ;  
              
              
               $SMonthT=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromS,$toS])
           ->get()->sum('Total_Price');
            
               $SMonthTax=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromS,$toS])
           ->get()->sum('Total_Taxes');
              
               $SMonthDisc=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromS,$toS])
           ->get()->sum('Total_Discount');
              
              $SMonth=  ($SMonthT +  $SMonthTax)  - $SMonthDisc ;  
              
              
              
              
                          $YMonthT=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromY,$toY])
           ->get()->sum('Total_Price');
            
               $YMonthTax=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromY,$toY])
           ->get()->sum('Total_Taxes');
              
               $YMonthDisc=Sales::where('Delegate',$item->id)
           ->whereBetween('Date',[$fromY,$toY])
           ->get()->sum('Total_Discount');
              
              $YMonth=  ($YMonthT +  $YMonthTax)  - $YMonthDisc ;  
                                                ?>
                                                <tr>
                                       <td> <?php echo e(app()->getLocale() == 'ar' ?$item->Name :$item->NameEn); ?></td>
                                                    
                                       <td><?php echo e($item->MonthlyTarget); ?></td>
                                        <td><?php echo e($previousMonth); ?></td>         
                                                    
                                            <?php if($item->MonthlyTarget > 0): ?>
                                                    
                                                      <td> 
                                    <div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: <?php echo e(($previousMonth/$item->MonthlyTarget) * 100); ?>%;" aria-valuenow="<?php echo e(($previousMonth/$item->MonthlyTarget) * 100); ?>" aria-valuemin="0" aria-valuemax="<?php echo e($item->MonthlyTarget / 100); ?>"><?php echo e(($previousMonth/$item->MonthlyTarget) * 100); ?>%</div>
                                                          </div>
                                            </td>   
                                              
                                        <?php else: ?>
                                                    
                                                                <td> 
                                    <div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: <?php echo e(($previousMonth/1) * 100); ?>%;" aria-valuenow="<?php echo e(($previousMonth/1) * 100); ?>" aria-valuemin="0" aria-valuemax="<?php echo e(1 / 100); ?>"><?php echo e(($previousMonth/1) * 100); ?>%</div>
                                                          </div>
                                            </td>                                            
                                    <?php endif; ?>                
                                                    
                                                    
                                              <td><?php echo e($item->MonthlyTarget); ?></td>
                                        <td><?php echo e($CurrentMonth); ?></td>    
                                                    
                                                    
                                                    <?php if($item->MonthlyTarget > 0): ?>            
                                                    <td>
                                                        
                                                        
                                               
                                                        
                                            
                                                                                                <div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: <?php echo e(($CurrentMonth/$item->MonthlyTarget) * 100); ?>%;" aria-valuenow="<?php echo e(($CurrentMonth/$item->MonthlyTarget) * 100); ?>" aria-valuemin="0" aria-valuemax="<?php echo e($item->MonthlyTarget / 100); ?>"><?php echo e(($CurrentMonth/$item->MonthlyTarget) * 100); ?>%</div>
</div>
                                      </td>  
          
                                        <?php endif; ?>            
                                                    
                                                    
                                                  <td><?php echo e($item->QuarterTarget); ?></td>
                                        <td><?php echo e($QMonth); ?></td>  
                                                          <?php if($item->MonthlyTarget > 0): ?>                
                                                       <td> 
                                                                      <div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: <?php echo e(($QMonth/$item->QuarterTarget) * 100); ?>%;" aria-valuenow="<?php echo e(($QMonth/$item->QuarterTarget) * 100); ?>" aria-valuemin="0" aria-valuemax="<?php echo e($item->QuarterTarget / 100); ?>"><?php echo e(($QMonth/$item->QuarterTarget) * 100); ?>%</div>
</div>
                                  </td>      
                                      <?php endif; ?>              
                                                    
                                            <td><?php echo e($item->SemiTarget); ?></td>
                                        <td><?php echo e($SMonth); ?></td>   
                                                          <?php if($item->MonthlyTarget > 0): ?>                
                                                               <td> 
                                                                      <div class="progress">
    <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: <?php echo e(($SMonth/$item->SemiTarget) * 100); ?>%;" aria-valuenow="<?php echo e(($SMonth/$item->SemiTarget) * 100); ?>" aria-valuemin="0" aria-valuemax="<?php echo e($item->SemiTarget / 100); ?>"><?php echo e(($SMonth/$item->SemiTarget) * 100); ?>%</div>
</div>
                                  </td>   
                                        <?php endif; ?>            
                                                    
                                             <td><?php echo e($item->YearlyTarget); ?></td>
                                        <td><?php echo e($YMonth); ?></td>    
                                                          <?php if($item->MonthlyTarget > 0): ?>                
                                                                <td> 
                                                                      <div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: <?php echo e(($YMonth/$item->YearlyTarget) * 100); ?>%;" aria-valuenow="<?php echo e(($YMonth/$item->YearlyTarget) * 100); ?>" aria-valuemin="0" aria-valuemax="<?php echo e($item->YearlyTarget / 100); ?>"><?php echo e(($YMonth/$item->YearlyTarget) * 100); ?>%</div>
</div>
                                  </td>             
                                     <?php endif; ?>               
                                                </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </tbody>
                        
                        
                                        </table>
                                     <?php echo e($items->Links()); ?>

                                        <!-- datatable end -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </main>


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


<?php $__env->startPush('js'); ?>
<!--  Colors -->
<style>
    
    th , td{
        text-align: center;
    }
  


</style>    

 <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/datagrid/datatables/datatables.bundle.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/summernote/summernote.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/select2/select2.bundle.css')); ?>">

    <style>
        th{
            width:135px!important;
        }
    </style>

 <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.export.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.bundle.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/formplugins/summernote/summernote.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/formplugins/select2/select2.bundle.js')); ?>"></script>
    <script>
        //_fnFeatureHtmlLength();
        $(document).ready(function () {
            // Setup - add a text input to each footer cell
            $('#dt-basic-example thead tr').clone(true).appendTo('#dt-basic-example thead');
            $('#dt-basic-example thead tr:eq(1) th').each(function (i) {
                var title = $(this).text();
                $(this).html('<input type="text" class="form-control form-control-sm" placeholder="Search ' + title + '" />');

                $('input', this).on('keyup change', function () {
                    if (table.column(i).search() !== this.value) {
                        table
                            .column(i)
                            .search(this.value)
                            .draw();
                    }
                });
            });
            var table = $('#dt-basic-example').DataTable(
                {
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: true,
                    lengthChange: true,

                    dom: "<'row mb-3'<'col-sm-12 col-md-3 d-flex align-items-center justify-content-start'f><'col-sm-12 col-md-9 d-flex align-items-center justify-content-end'B>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",

                    buttons: [
                        {
                            extend: 'pageLength',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'colvis',
                            text: 'Column Visibility',
                            titleAttr: 'Col visibility',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'PDF',
                            titleAttr: 'Generate PDF',
                            className: 'btn-outline-danger btn-sm mr-1'
                        },
                        {
                            extend: 'excelHtml5',
                            text: 'Excel',
                            titleAttr: 'Generate Excel',
                            className: 'btn-outline-success btn-sm mr-1'
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'CSV',
                            titleAttr: 'Generate CSV',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'copyHtml5',
                            text: 'Copy',
                            titleAttr: 'Copy to clipboard',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });
            $('.js-thead-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example thead').removeClassPrefix('bg-').addClass(theadColor);
            });

            $('.js-tbody-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example').removeClassPrefix('bg-').addClass(theadColor);
            });

        });

    </script>
  
  <script>
    $(document).ready(function()
    {
        $(function()
        {
            $('.select2').select2();

            $(".select2-placeholder-multiple").select2(
            {
                placeholder: "Select State"
            });
            $(".js-hide-search").select2(
            {
                minimumResultsForSearch: 1 / 0
            });
            $(".js-max-length").select2(
            {
                maximumSelectionLength: 2,
                placeholder: "Select maximum 2 items"
            });
            $(".select2-placeholder").select2(
            {
                placeholder: "Select a state",
                allowClear: true
            });

            $(".js-select2-icons").select2(
            {
                minimumResultsForSearch: 1 / 0,
                templateResult: icon,
                templateSelection: icon,
                escapeMarkup: function(elm)
                {
                    return elm
                }
            });

            function icon(elm)
            {
                elm.element;
                return elm.id ? "<i class='" + $(elm.element).data("icon") + " mr-2'></i>" + elm.text : elm.text
            }

            $(".js-data-example-ajax").select2(
            {
                ajax:
                {
                    url: "https://api.github.com/search/repositories",
                    dataType: 'json',
                    delay: 250,
                    data: function(params)
                    {
                        return {
                            q: params.term, // search term
                            page: params.page
                        };
                    },
                    processResults: function(data, params)
                    {
                        // parse the results into the format expected by Select2
                        // since we are using custom formatting functions we do not need to
                        // alter the remote JSON data, except to indicate that infinite
                        // scrolling can be used
                        params.page = params.page || 1;

                        return {
                            results: data.items,
                            pagination:
                            {
                                more: (params.page * 30) < data.total_count
                            }
                        };
                    },
                    cache: true
                },
                placeholder: 'Search for a repository',
                escapeMarkup: function(markup)
                {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 1,
                templateResult: formatRepo,
                templateSelection: formatRepoSelection
            });

            function formatRepo(repo)
            {
                if (repo.loading)
                {
                    return repo.text;
                }

                var markup = "<div class='select2-result-repository clearfix d-flex'>" +
                    "<div class='select2-result-repository__avatar mr-2'><img src='" + repo.owner.avatar_url + "' class='width-2 height-2 mt-1 rounded' /></div>" +
                    "<div class='select2-result-repository__meta'>" +
                    "<div class='select2-result-repository__title fs-lg fw-500'>" + repo.full_name + "</div>";

                if (repo.description)
                {
                    markup += "<div class='select2-result-repository__description fs-xs opacity-80 mb-1'>" + repo.description + "</div>";
                }

                markup += "<div class='select2-result-repository__statistics d-flex fs-sm'>" +
                    "<div class='select2-result-repository__forks mr-2'><i class='fal fa-lightbulb'></i> " + repo.forks_count + " Forks</div>" +
                    "<div class='select2-result-repository__stargazers mr-2'><i class='fal fa-star'></i> " + repo.stargazers_count + " Stars</div>" +
                    "<div class='select2-result-repository__watchers mr-2'><i class='fal fa-eye'></i> " + repo.watchers_count + " Watchers</div>" +
                    "</div>" +
                    "</div></div>";

                return markup;
            }

            function formatRepoSelection(repo)
            {
                return repo.full_name || repo.text;
            }
        });
    });

</script>
<script>
    var autoSave = $('#autoSave');
    var interval;
    var timer = function()
    {
        interval = setInterval(function()
        {
            //start slide...
            if (autoSave.prop('checked'))
                saveToLocal();

            clearInterval(interval);
        }, 3000);
    };

    //save
    var saveToLocal = function()
    {
        localStorage.setItem('summernoteData', $('#saveToLocal').summernote("code"));
        console.log("saved");
    }

    //delete 
    var removeFromLocal = function()
    {
        localStorage.removeItem("summernoteData");
        $('#saveToLocal').summernote('reset');
    }

    $(document).ready(function()
    {
        //init default
        $('.js-summernote').summernote(
        {
            height: 200,
            tabsize: 2,
            placeholder: "Type here...",
            dialogsFade: true,
            toolbar: [
                ['style', ['style']],
                ['font', ['strikethrough', 'superscript', 'subscript']],
                ['font', ['bold', 'italic', 'underline', 'clear']],
                ['fontsize', ['fontsize']],
                ['fontname', ['fontname']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']]
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ],
            callbacks:
            {
                //restore from localStorage
                onInit: function(e)
                {
                    $('.js-summernote').summernote("code", localStorage.getItem("summernoteData"));
                },
                onChange: function(contents, $editable)
                {
                    clearInterval(interval);
                    timer();
                }
            }
        });

        //load emojis
        $.ajax(
        {
            url: 'https://api.github.com/emojis',
            async: false
        }).then(function(data)
        {
            window.emojis = Object.keys(data);
            window.emojiUrls = data;
        });

        //init emoji example
        $(".js-hint2emoji").summernote(
        {
            height: 100,
            toolbar: false,
            placeholder: 'type starting with : and any alphabet',
            hint:
            {
                match: /:([\-+\w]+)$/,
                search: function(keyword, callback)
                {
                    callback($.grep(emojis, function(item)
                    {
                        return item.indexOf(keyword) === 0;
                    }));
                },
                template: function(item)
                {
                    var content = emojiUrls[item];
                    return '<img src="' + content + '" width="20" /> :' + item + ':';
                },
                content: function(item)
                {
                    var url = emojiUrls[item];
                    if (url)
                    {
                        return $('<img />').attr('src', url).css('width', 20)[0];
                    }
                    return '';
                }
            }
        });

        //init mentions example
        $(".js-hint2mention").summernote(
        {
            height: 100,
            toolbar: false,
            placeholder: "type starting with @",
            hint:
            {
                mentions: ['jayden', 'sam', 'alvin', 'david'],
                match: /\B@(\w*)$/,
                search: function(keyword, callback)
                {
                    callback($.grep(this.mentions, function(item)
                    {
                        return item.indexOf(keyword) == 0;
                    }));
                },
                content: function(item)
                {
                    return '@' + item;
                }
            }
        });

    });

</script>
<script type="text/javascript">


    $(".show-table").click(function(){
        $(".hide-table").show();
    });
    
</script>


<!-- Search Selecet -->
 <script>
        $(document).ready(function()
        {
            $(function()
            {
                $('.select2').select2();

                $(".select2-placeholder-multiple").select2(
                {
                    placeholder: "Select State"
                });
                $(".js-hide-search").select2(
                {
                    minimumResultsForSearch: 1 / 0
                });
                $(".js-max-length").select2(
                {
                    maximumSelectionLength: 2,
                    placeholder: "Select maximum 2 items"
                });
                $(".select2-placeholder").select2(
                {
                    placeholder: "Select a state",
                    allowClear: true
                });

                $(".js-select2-icons").select2(
                {
                    minimumResultsForSearch: 1 / 0,
                    templateResult: icon,
                    templateSelection: icon,
                    escapeMarkup: function(elm)
                    {
                        return elm
                    }
                });

                function icon(elm)
                {
                    elm.element;
                    return elm.id ? "<i class='" + $(elm.element).data("icon") + " mr-2'></i>" + elm.text : elm.text
                }

                 
  $('#coin').select2({
    ajax: {
        type: "GET",
        dataType: 'json',
        url: 'AllCoins',
        processResults: function (data) {
          return {
            results: $.map(data, function(obj, index) {
              return { id: index, text: obj };
            })
          };            
        },
        data: function (params) {  
     
          return {json: JSON.stringify( params.term )} 
                               
        }
        }
  });

           
    
$('#coin').on('select2:select', function (e) {
	console.log("select done", e.params.data);
});
              
                

             
            });
        });



    </script>
<script>

   var table = $('#X').DataTable(
                {
                    
                    retrieve: true,
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: false,
                    lengthChange: true,
                     pageLength : 10,
                    dom: 'Bfrtip',
                   
                    buttons: [
                        {
                            extend: 'pageLength',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'colvis',
                            text: 'Column Visibility',
                            titleAttr: 'Col visibility',
                            className: 'btn-outline-default'
                        },
                  
                        {
                            extend: 'excelHtml5',
                            text: 'Excel',
                            titleAttr: 'Generate Excel',
                             exportOptions: {
                modifier: {
                  page: 'all',
                  search: 'none'   
                }
                             },
                            className: 'btn-outline-success btn-sm mr-1'
                        },
                        
           
                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                                       exportOptions: {
                modifier: {
                  page: 'all',
                  search: 'none'   
                },
                             },
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });   
             
       
</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/MAMP/htdocs/laravel/ERP/resources/views/admin/Reports/EmpGoalsFilter.blade.php ENDPATH**/ ?>