
<?php $__env->startSection('title','Daily Action'); ?>
<?php $__env->startPush('styles'); ?>
    <style>
        .action-view{
            height: 402px;
            overflow-y: scroll;
            padding: 0px;
        }
        .card-header{
            background: #EAECF0;
            align-items: center;
            height: 60px;
        }
        table tr td a{
            color: #1C274D;
        }
        table th,table td{
            border-color: #EAECF0;
        }
        .action-view{
            scrollbar-width: auto;
            scrollbar-color: #fff #CCCED2;
        }

        .action-view::-webkit-scrollbar {
            width: 8px;
        }

        .action-view::-webkit-scrollbar-track {
            background: #CCCED2;
        }

        .action-view::-webkit-scrollbar-thumb {
            background-color: #fff;
            border-radius: 5px;
            border: 2px solid #CCCED2;
        }
        .card-body table tr td, .card-body table tr th{
            font-size: 0.8vw;
        }
        .view_details{
            cursor: pointer;
        }
    </style>
<?php $__env->stopPush(); ?>
<?php
    $check_calving = null;
    $check_dry = null;
?>

<?php $__env->startSection('content'); ?>
    <h2 class="mb-3 card-title">Daily Action List - Breeding</h2>
    <div class="card-body">
        <form action="<?php echo e(route('daily-action.breeding.filter')); ?>" method="GET" role="form" id="form1"  enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <div class="row mt-2">
                <div class="col-md-3">
                    <div class="form-group">
                        <label class="form-label" for="farm">Farm Name</label> <span class="text-danger"> *</span>
                        <select class="form-control <?php $__errorArgs = ['farms'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="farm" id="farm">
                            <?php if(count($farms) > 0): ?>
                                <option selected value="">Select Farm</option>
                                <?php $__currentLoopData = $farms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($item->id); ?>" <?php echo e(($farm_id ?? '') === $item->id ? 'selected': ''); ?>><?php echo e($item->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </select>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <label class="form-label" for="herd">Herd Name</label>
                        <select class="form-control <?php $__errorArgs = ['herd'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"  name="herd"  id="herd"></select>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <label class="form-label" for="lot">Lot Name</label>
                        <select class="form-control <?php $__errorArgs = ['lots'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="lot"  id="lot"></select>
                    </div>
                </div>
                <div class="col-md-3 mt-2">
                    <div class="form-group pt-4">
                        <button type="submit" id="get-data-btn" class="btn btn-primary"  disabled="disabled">Get Data</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div class="row mt-4">
        <div class="col-md-4 mt-4 ">
            <div class="card  pb-3">
                <div class="card-header d-flex justify-content-between">
                    <h5 class="title_name">Expected 1st Heat (<?php echo e(config('perameters.expected_first_heat')); ?> Days After Calving)</h5>
                    <button class="btn btn-light border" onclick="printDiv('heatPdf')" type="button"><i class="print-ico"></i></button>
                </div>
                <div class="card-body action-view " id="heatPdf">
                    <table class="table table-bordered w-100">
                        <tr>
                            <th>Cattle Tag ID</th>
                            <th>Expected 1st Heat Date</th>
                        </tr>
                        <?php $__empty_1 = true; $__currentLoopData = $cattleIdsArray; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php if($item && $item['cattle']): ?>
                                <?php
                                    $calving_alert_start_date = \Carbon\Carbon::parse($item['exact_calving_date'])->subDays(3)->format('Y-m-d');
                                    $check_ai = \App\Models\ArtificialInsemination::where([['cattle_id',$item['cattle']->id],['heat_date','>=',$calving_alert_start_date]])->get();
                                    $today = \Carbon\Carbon::now()->format('Y-m-d');
                                ?>
                                <?php if(count($check_ai) === 0 && $today >= $calving_alert_start_date && $calving_alert_start_date <= $item['exact_calving_date']): ?>
                                    <tr>
                                        <td><a data-url="<?php echo e(route('ai.create',["tag"=>$item['cattle']->id])); ?>" class="view_details"><?php echo e(($item['cattle']->disposal_status === 0) ? $item['cattle']->tag->uid : ''); ?></a></td>
                                        <td><?php echo e(\Carbon\Carbon::createFromFormat('Y-m-d', $item['exact_calving_date'])->format('d-m-Y')); ?></td>
                                    </tr>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <?php endif; ?>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-4 mt-4 ">
            <div class="card  pb-3">
                <div class="card-header d-flex justify-content-between">
                    <h5 class="title_name">Check For Heat(Regular <?php echo e(config('perameters.heat_interval')); ?> Days Interval)</h5>
                    <button class="btn btn-light border" onclick="printDiv('regularHeatPdf')" type="button"><i class="print-ico"></i></button>
                </div>
                <div class="card-body action-view" id="regularHeatPdf">
                    <table class="table table-bordered w-100">
                        <tr>
                            <th>Cattle Tag ID</th>
                            <th>Expected Check Heat Date</th>
                        </tr>
                        <?php $__empty_1 = true; $__currentLoopData = $cattleHeatIdsArray; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php if($item && $item['cattle_heat']): ?>
                                <?php
                                    $check_ai_heat = \App\Models\ArtificialInsemination::where([['cattle_id',$item['cattle_heat']->id],['heat_date','>=',$item['exact_heat_date']]])->get();
                                    $today = \Carbon\Carbon::now()->format('Y-m-d');
                                    $alert_start_date = \Carbon\Carbon::parse($item['exact_heat_date'])->subDays(3)->format('Y-m-d');
                                ?>
                                <?php if(count($check_ai_heat) === 0 && $alert_start_date <= $item['exact_heat_date']): ?>
                                    <tr>
                                        <td><a data-url="<?php echo e(route('ai.create',["tag"=>$item['cattle_heat']->id])); ?>" class="view_details"><?php echo e($item['cattle_heat']->tag->uid); ?></a></td>
                                        <td><?php echo e(\Carbon\Carbon::createFromFormat('Y-m-d', $item['exact_heat_date'])->format('d-m-Y')); ?></td>
                                    </tr>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <?php endif; ?>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-4 mt-4 ">
            <div class="card  pb-3">
                <div class="card-header d-flex justify-content-between">
                    <h5 class="title_name"> 1st PD Check After <?php echo e(config('perameters.first_pd_check_period')); ?> Days Of AI</h5>
                    <button class="btn btn-light border" onclick="printDiv('firstPDPdf')" type="button"><i class="print-ico"></i></button>
                </div>
                <div class="card-body action-view" id="firstPDPdf">
                    <table class="table table-bordered w-100">
                        <tr>
                            <th>Cattle Tag ID</th>
                            <th>Expected 1st PD Date</th>
                        </tr>
                        <?php $__empty_1 = true; $__currentLoopData = $cattleFirstPDIdsArray; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php if($item && $item['cattle_first_pd']): ?>
                                <?php
                                    $first_pd_alert_start_date = \Carbon\Carbon::parse($item['exact_first_pd_date'])->subDays(3)->format('Y-m-d');
                                    $check_first_pd = \App\Models\PregnancyDiagnosis::where([['cattle_id',$item['cattle_first_pd']->id],['check_date','>=',$first_pd_alert_start_date]])->get();
                                    $today = \Carbon\Carbon::now()->addDays(2)->format('Y-m-d');
                                ?>
                                <?php if(count($check_first_pd) === 0 && $today >= $first_pd_alert_start_date && $first_pd_alert_start_date <= $item['exact_first_pd_date']): ?>
                                    <tr>
                                        <td><a data-url="<?php echo e(route('pd.create',["tag"=>$item['cattle_first_pd']->id])); ?>" class="view_details"><?php echo e($item['cattle_first_pd']->tag->uid); ?></a></td>
                                        <td><?php echo e(\Carbon\Carbon::createFromFormat('Y-m-d', $item['exact_first_pd_date'])->format('d-m-Y')); ?></td>
                                    </tr>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <?php endif; ?>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-4 mt-4 ">
            <div class="card  pb-3">
                <div class="card-header d-flex justify-content-between">
                    <h5 class="title_name">2ND PD Check After <?php echo e(config('perameters.second_pd_check_period')); ?> Days Of AI</h5>
                    <button class="btn btn-light border" onclick="printDiv('secondPDPdf')" type="button"><i class="print-ico"></i></button>
                </div>
                <div class="card-body action-view" id="secondPDPdf">
                    <table class="table table-bordered w-100">
                        <tr>
                            <th>Cattle Tag ID</th>
                            <th>Expected 2nd PD Date</th>
                        </tr>
                        <?php $__currentLoopData = $cattleSecondPDIdsArray; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if($item && $item['cattle_second_pd']): ?>
                                <?php
                                    $second_pd_alert_start_date = \Carbon\Carbon::parse($item['exact_second_pd_date'])->subDays(3)->format('Y-m-d');
                                    $check_second_pd = \App\Models\PregnancyDiagnosis::where([['cattle_id',$item['cattle_second_pd']->id],['check_date','>=',$second_pd_alert_start_date]])->get();
                                    $today = \Carbon\Carbon::now()->addDays(2)->format('Y-m-d');
                                ?>
                                <?php if(count($check_second_pd) === 0 && $today >= $second_pd_alert_start_date && $second_pd_alert_start_date <= $item['exact_second_pd_date']): ?>
                                    <tr>
                                        <td><a data-url="<?php echo e(route('pd.create',["tag"=>$item['cattle_second_pd']->id])); ?>" class="view_details"><?php echo e($item['cattle_second_pd']->tag->uid); ?></a></td>
                                        <td><?php echo e(\Carbon\Carbon::createFromFormat('Y-m-d', $item['exact_second_pd_date'])->format('d-m-Y')); ?></td>
                                    </tr>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-4 mt-4 ">
            <div class="card  pb-3">
                <div class="card-header d-flex justify-content-between">
                    <h5 class="title_name">Expected Calving After <?php echo e(config('perameters.expected_calving')); ?> Days Of AI</h5>
                    <button class="btn btn-light border" onclick="printDiv('calvingPdf')" type="button"><i class="print-ico"></i></button>
                </div>
                <div class="card-body action-view" id="calvingPdf">
                    <table class="table table-bordered w-100">
                        <tr>
                            <th>Cattle Tag ID</th>
                            <th>Expected Calving Date</th>
                        </tr>
                        <?php $__currentLoopData = $modifiedCattleIds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td>
                                    <a data-url="<?php echo e(route('calving.create',["tag"=>$item->id])); ?>" class="view_details">
                                        <?php echo e($item->tag->uid); ?>

                                    </a>
                                </td>
                                <td>
                                    <?php echo e($item->expected_calving_date); ?>

                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-4 mt-4 ">
            <div class="card  pb-3">
                <div class="card-header d-flex justify-content-between">
                    <h5 class="title_name">Expected Drying Before <?php echo e(config('perameters.preg_dry_period')); ?> Days Of Calving</h5>
                    <button class="btn btn-light border" onclick="printDiv('dryingPdf')" type="button"><i class="print-ico"></i></button>
                </div>
                <div class="card-body action-view" id="dryingPdf">
                    <table class="table table-bordered w-100">
                        <tr>
                            <th>Cattle Tag ID</th>
                            <th>Expected Dry Date</th>
                        </tr>
                        <?php $__currentLoopData = $cattleDryOff; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td>
                                    <a data-url="<?php echo e(route('dryoff.create',["tag"=>$item->id])); ?>" class="view_details">
                                        <?php echo e($item->tag->uid); ?>

                                    </a>
                                </td>
                                <td>
                                    <?php echo e($item->expected_dry_of_date); ?>

                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="breeding_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <div class="modal-body p-0 mt-3 editModal">

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

<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">
        function printDiv(divName) {
            var printContents = document.getElementById(divName).innerHTML;
            var printStyle = '<style>@page {size: auto;margin: 0mm;}</style>';
            var printDiv = '<div id="order-details-wrapper" style="padding: 20px;">' + printStyle + printContents +'</div>';
            document.body.innerHTML = printDiv;
            var originalContents = document.body.innerHTML;
            window.print();
            document.body.innerHTML = originalContents;
            location.reload();
        }

        $(document).ready(function($) {
            $('.select2-multiple').select2();
            $('#farm').change(function(){
                var farm_id = $(this).val();
                if(farm_id){
                    $.ajax({
                        type:"GET",
                        url:"<?php echo e(url('system/statistics/get-herd-list')); ?>?farm_id="+farm_id,
                        success:function(res){
                            if(res){
                                $('#get-data-btn').prop("disabled", false);
                                $("#herd").empty().append('<option>Select Herd</option>');
                                $.each(res,function(key){
                                    $("#herd").append('<option value="'+res[key].id+'">'+res[key].name+'</option>');
                                });
                            }else{
                                $("#herd").empty();
                            }
                        }
                    });
                }else{
                    $("#herd").empty();
                    $("#lot").empty();
                }
            });
            $('#herd').on('change',function(){
                var lot_id = $(this).val();
                if(lot_id){
                    $.ajax({
                        type:"GET",
                        url:"<?php echo e(url('system/statistics/get-lot-list')); ?>?lot_id="+lot_id,
                        success:function(res){
                            if(res){
                                $("#lot").empty().append('<option>Select Lot</option>');
                                $.each(res,function(key,value){
                                    $("#lot").append('<option value="'+res[key].id+'">'+res[key].name+'</option>');
                                });
                            }else{
                                $("#lot").empty();
                            }
                        }
                    });
                }else{
                    $("#lot").empty();
                }
            });

            $('.view_details').click(function () {
                let id = $(this).attr('data-url');
                $('.editModal').empty();
                axios.get(id, {
                }).then(function (response) {
                    $('#breeding_modal').modal('show');
                    $('.editModal').html(response.data);

                }).catch(function (error) {
                    console.log(error);
                });
            });
        });

    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\hr_and_att\resources\views/backend/daily_action/breeding/index.blade.php ENDPATH**/ ?>