
<?php $__env->startSection('title','Life Time History'); ?>
<?php $__env->startSection('content'); ?>
    <h2 class="ms-2 card-title"><?php echo e(__('messages.cattle_list')); ?></h2>
    <form action="<?php echo e(route('cattles.lifetime-history.index')); ?>" method="GET" role="form" id="form1"
          enctype="multipart/form-data">
        <div class="d-flex w-100 justify-content-between mb-5">
            <div class="row mx-0 row-get-data-5 d-flex justify-content-between">
                <div class="row-18 px-0">
                    <div class="form-group">
                        <label class="form-label" for="farm"><?php echo e(__('messages.farm_name')); ?></label>
                        <select class="form-select <?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"
                                onChange="getHerd();">
                            <?php if(count($farms) > 0): ?>
                                <option 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($item->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </select>
                    </div>
                </div>
                <div class="row-18 px-0">
                    <div class="form-group">
                        <label class="form-label" for="herd"><?php echo e(__('messages.herd_name')); ?></label>
                        <select class="form-select <?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"
                                onChange="getLot();">
                        </select>
                    </div>
                </div>
                <div class="row-18 px-0">
                    <div class="form-group">
                        <label class="form-label" for="lot"><?php echo e(__('messages.lot_name')); ?></label>
                        <select class="form-select <?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="row-18 px-0">
                    <div class="form-group">
                        <label class="form-label" for="cattle_sex"><?php echo e(__('messages.cattle_sex')); ?></label>
                        <select class="form-select <?php $__errorArgs = ['sex'];
$__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="cattle_sex"
                                id="cattle_sex">
                            <option value="">Select Cattle Sex</option>
                            <option value="male">Male</option>
                            <option value="female">Female</option>
                        </select>
                    </div>
                </div>
                <div class="row-18 px-0">
                    <div class="form-group">
                        <label class="form-label" for="cattle_type"><?php echo e(__('messages.cattle_status')); ?></label>
                        <select class="form-select <?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="cattle_type"
                                id="cattle_type">
                            <option value="none">Select Cattle Status</option>
                            <option value="calf">Calf</option>
                            <option value="heifer">Heifer</option>
                            <option value="bull">Bull</option>
                            <option value="reproduction_stage">Reproduction Stage</option>
                            <option value="open_unbred">Open Unbred</option>
                            <option value="open_bred">Open Bred</option>
                            <option value="pregnant">Pregnant</option>
                            <option value="milking">Milking</option>
                            <option value="dry">Dry</option>
                            <option value="pregnant_milking">Pregnant Milking</option>
                            <option value="pregnant_dry">Pregnant Dry</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="row mx-0 row-get-data-1 d-flex justify-content-end mt-4">
                <div class="form-group pt-2 d-flex justify-content-end px-0">
                    <button type="submit" class="btn btn-primary">Search</button>
                </div>
            </div>
        </div>
    </form>
    <div class="card mt-3 m-lg-2">
        <div class="card-body mt-2 table_card">
            <table id="datatable-buttons" class="table table-bordered dt-responsive nowrap w-100"
                   data-table="dataTables">
                <thead>
                <tr>
                    <th><?php echo e(__('messages.sl')); ?></th>
                    <th><?php echo e(__('messages.lot_name')); ?></th>
                    <th><?php echo e(__('messages.tag_id')); ?></th>
                    <th><?php echo e(__('messages.animal_name')); ?></th>
                    <th><?php echo e(__('messages.birth_date')); ?></th>
                    <th><?php echo e(__('messages.status')); ?></th>
                    <th><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $cattles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e(($item->lot_id) ? $item->lot->name : 'N/A'); ?></td>
                        <td><?php echo e(($item->tag_id) ? $item->tag->uid : 'N/A'); ?></td>
                        <td><?php echo e(($item->animal_name) ?? 'N/A'); ?></td>
                        <td><?php echo e(($item->birth_date) ? Carbon\Carbon::createFromFormat('Y-m-d', $item->birth_date)->format('d-m-Y') : 'N/A'); ?></td>
                        <td style="text-transform: capitalize">
                            <span
                                class="badge badge-pill badge-soft-<?php echo e(($item->status) ? 'success' : 'danger'); ?> font-size-11"><?php echo e(($item->status) ?? 'None'); ?></span>
                        </td>
                        <td>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('cattle.show')): ?>
                                <a role="button" data-bs-toggle="offcanvas" data-id="<?php echo e($item->id); ?>"
                                   data-bs-target="#offcanvasRight" aria-controls="offcanvasRight"
                                   class="btn btn-sm cattle-info-show"><i class="eye-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('cattle.show')): ?>
                                <a role="button" data-id="<?php echo e($item->id); ?>"
                                   class="btn btn-sm cattle-summary-show" data-bs-toggle="offcanvas"
                                   data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
                                    <i class="list-ico"></i>
                                </a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight"
         aria-labelledby="offcanvasRightLabel">
        <div class="offcanvas-header d-flex justify-content-around">
            <div class="d-flex justify-content-start w-50 align-items-center">
                <button type="button" class="me-4" data-bs-dismiss="offcanvas" aria-label="Close"
                        style=" border: none;">
                    <i class="arrow-back-ico"></i>
                </button>
                <h5 class="offcanvas-title" id="offcanvasRightLabel"></h5>
            </div>
            <div class="d-flex justify-content-end w-50 align-items-center">
            </div>
        </div>
        <div class="offcanvas-body offcanva_data_view " style="width: 70vw;"></div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">
        function getHerd() {
            var str = '';
            var val = $('#farm').val();

            for (i = 0; i < val.length; i++) {
                if (val[i]) {
                    str += val[i] + ',';
                }
            }
            var str = str.slice(0, str.length - 1);
            $.ajax({
                type: "GET",
                url: "<?php echo e(url('system/users/get-herd-list')); ?>",
                data: 'farm_id=' + str,
                success: function (res) {
                    if (res) {
                        $("#herd").empty().html(res);

                    } else {
                        $("#herd").empty();
                    }
                }
            });
        }

        function getLot() {
            var str = '';
            var val = $('#herd').val();

            for (i = 0; i < val.length; i++) {
                if (val[i]) {
                    str += val[i] + ',';
                }
            }
            var str = str.slice(0, str.length - 1);

            $.ajax({
                type: "GET",
                url: "<?php echo e(url('system/users/get-lot-list')); ?>",
                data: 'herd_id=' + str,
                success: function (res) {
                    if (res) {
                        $("#lot").empty().html(res);
                    } else {
                        $("#lot").empty();
                    }
                }
            });
        }

        $('#cattle_sex').change(function () {
            var sex = $(this).val();
            if (sex === 'male') {
                $('#cattle_type option').removeAttr('selected').filter('[value=none]').attr('selected', true);
                $("#cattle_type option[value='heifer']").hide();
                $("#cattle_type option[value='bull']").show();
                $("#cattle_type option[value='open_unbred']").hide();
                $("#cattle_type option[value='open_bred']").hide();
                $("#cattle_type option[value='pregnant']").hide();
                $("#cattle_type option[value='milking']").hide();
                $("#cattle_type option[value='pregnant_milking']").hide();
                $("#cattle_type option[value='pregnant_dry']").hide();
                $("#cattle_type option[value='dry']").hide();
                $("#cattle_type option[value='reproduction_stage']").show();
            } else {
                $('#cattle_type option').removeAttr('selected').filter('[value=none]').attr('selected', true);
                $("#cattle_type option[value='bull']").hide();
                $("#cattle_type option[value='heifer']").show();
                $("#cattle_type option[value='reproduction_stage']").hide();
                $("#cattle_type option[value='open_unbred']").show();
                $("#cattle_type option[value='open_bred']").show();
                $("#cattle_type option[value='pregnant']").show();
                $("#cattle_type option[value='milking']").show();
                $("#cattle_type option[value='pregnant_milking']").show();
                $("#cattle_type option[value='pregnant_dry']").show();
                $("#cattle_type option[value='dry']").show();
            }
        });
        $(document).on('click', '.cattle-info-show', function () {
            let id = $(this).data('id');
            axios.get("<?php echo e(url('system/cattles/lifetime-history/')); ?>/" + id).then(function (response) {
                $('.offcanva_data_view').html(response.data);
                $('#offcanvasRightLabel').text("<?php echo e(__('messages.cattle_lifetime_history')); ?>");
            }).catch(function (error) {
                console.log(error)
            })
        })
        $(document).on('click', '.cattle-summary-show', function () {
            let id = $(this).data('id');
            axios.get("<?php echo e(url('system/cattles/summary/')); ?>/" + id).then(function (response) {
                $('.offcanva_data_view').html(response.data);
                $('#offcanvasRightLabel').text("<?php echo e(__('messages.cattle_summary')); ?>");
            }).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/cattle/lifetime_history.blade.php ENDPATH**/ ?>