
<?php $__env->startSection('title','Deworming'); ?>
<?php $__env->startPush('styles'); ?>
    <style>
        .cm_grid {
            display: flex;
        }

        label {
            color: #1C274D;
            font-family: Mulish, sans-serif;
            font-size: 16px;
            font-style: normal;
            font-weight: 600;
            line-height: normal;
        }

        .cattle_info {
            max-height: 135px;
            overflow-y: scroll;
        }

        .farm_info span {
            color: #0050C9;
            font-size: 14px;
            font-style: normal;
            font-weight: 500;
            line-height: normal;
        }

        .farm_info strong {
            color: #1C274D;
            font-size: 14px;
            font-style: normal;
            font-weight: 500;
            line-height: normal;
        }

        .cattle_uid {
            color: #6E7796;
            font-size: 14px;
            font-style: normal;
            font-weight: 600;
            line-height: 24px;
        }
    </style>

<?php $__env->stopPush(); ?>
<?php
    $c_id = request()->get('tag');
    $f_date = request()->get('followup_date');
    $worm = request()->get('worm');
    $type = request()->get('type');
?>

<?php $__env->startSection('content'); ?>
    <h2 class="ms-2 mb-3 card-title">Deworming List</h2>
    <div class="card mt-3 m-lg-2">
        <div class="card-body table_card mt-2">
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.create')): ?>
                <div class="add-new-button-hidden">
                    <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#dewarming_add_modal"
                            ><i class="plus-ico"></i> Add Deworming
                    </button>
                    <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#deworming_bulk_modal"
                            ><i class="plus-ico"></i> Bulk Entry
                    </button>
                </div>
            <?php endif; ?>
            <table id="myTable" class="table table-bordered dt-responsive nowrap w-100">
                <thead>
                <tr>
                    <th><?php echo e(__('messages.sl')); ?></th>
                    <th>Tag ID</th>
                    <th>Dewormer Name</th>
                    <th>Worm</th>
                    <th>Type</th>
                    <th>Dewormer Date</th>
                    <th><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $dewormings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e(($item->cattle_id) ? $item->cattle->tag->uid : 'N/A'); ?></td>
                        <td><?php echo e(($item->dewormer_id) ? $item->dewormer->name : 'N/A'); ?></td>
                        <td>
                            <span
                                class="badge badge-pill badge-soft-<?php echo e(($item->worm === 'active') ? 'primary' : 'info'); ?> mr-1"><?php echo e(($item->worm === 'acdodarm') ? 'Acdodarm' : 'Andodarm'); ?></span>
                        </td>
                        <td style="text-transform: capitalize"><?php echo e(($item->type) ?? 'N/A'); ?></td>
                        <td><?php echo e(($item->date) ? \Carbon\Carbon::createFromFormat('Y-m-d', $item->date)->format('d-m-Y') : 'N/A'); ?></td>
                        <td class="center">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.list')): ?>
                                <a view-id="<?php echo e($item->id); ?>"
                                   class="btn view-btn" data-bs-toggle="offcanvas"
                                   data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
                                    <i class="eye-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.edit')): ?>
                                <a class="btn edit-btn" edit-id="<?php echo e($item->id); ?>" data-bs-toggle="modal"
                                   data-bs-target="#dewarming_edit_modal"><i class="edit-ico"></i></a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.delete')): ?>
                                <a href="#" class="btn"
                                   onclick="deletePost(<?php echo e($item->id); ?>)">
                                    <i class="delete-ico"></i>
                                    <form id="delete-form-<?php echo e($item->id); ?>"
                                          action="<?php echo e(route('deworming.destroy', $item->id)); ?>" method="POST"
                                          style="display: none;">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                    </form>
                                </a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight"
         aria-labelledby="offcanvasRightLabel">
        <div class="offcanvas-header">
            <button type="button" class="me-4" data-bs-dismiss="offcanvas" aria-label="Close"
                    style=" border: none;">
                <svg xmlns="http://www.w3.org/2000/svg" width="24"
                     height="24" viewBox="0 0 24 24" fill="none">
                    <path d="M20 11H7.83L13.42 5.41L12 4L4 12L12 20L13.41 18.59L7.83 13H20V11Z"
                          fill="black"/>
                </svg>
            </button>
            <h5 class="offcanvas-title" id="offcanvasRightLabel">Vaccination Details</h5>
        </div>
        <div class="offcanvas-body me-2 offcanva_data_view" style="width: 27rem;"></div>
    </div>
    
    <div class="modal fade" id="dewarming_add_modal" tabindex="-1" aria-labelledby="exampleModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title">Add Dewarming Information</h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('deworming.store')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data" autocomplete="off">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <label class="form-label" for="cattle_id">Tag ID <span class="text-danger">*</span></label>
                                <select class="form-control add-modal <?php $__errorArgs = ['cattle_id'];
$__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_id" id="cattle_id" required>
                                    <option value="">Select Tag Id</option>
                                    <?php $__currentLoopData = $cattles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option
                                            value="<?php echo e($item->id); ?>" <?php echo e((($c_id) && ($c_id === $item->id)) ? 'selected' : ''); ?>><?php echo e($item->tag->uid); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="type">Type <span class="text-danger">*</span></label>
                                <select class="form-control type  <?php $__errorArgs = ['type'];
$__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="type"
                                        id="type" required>
                                    <option value="">Select Type</option>
                                    <option value="regular" <?php echo e((($type === 'regular')) ? 'selected' : ''); ?>>
                                        Regular
                                    </option>
                                    <option value="custom" <?php echo e((($type === 'custom')) ? 'selected' : ''); ?>>
                                        Custom
                                    </option>
                                </select>
                            </div>
                        </div>

                        <div class="row mt-2">
                            <div class="col-md-6">
                                <label class="form-label" for="worm">Worm Type <span class="text-danger">*</span></label>
                                <select class="form-control worm <?php $__errorArgs = ['worm'];
$__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="worm"
                                        id="worm" required>
                                    <option value="">Select Worm Type</option>
                                    <option value="acdodarm" <?php echo e((($worm === 'acdodarm')) ? 'selected' : ''); ?>>
                                        Acdodarm
                                    </option>
                                    <option value="andodarm" <?php echo e((($worm === 'andodarm')) ? 'selected' : ''); ?>>
                                        Andodarm
                                    </option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="dewormer_id">Dewormer <?php echo e(__('messages.name')); ?> <span class="text-danger">*</span></label>
                                <select
                                    class="form-control dewormer_id select2-multiple <?php $__errorArgs = ['dewormer_id'];
$__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="dewormer_id" id="dewormer_id" disabled="disabled" required>
                                    <option value="">Select Dewormer</option>
                                    <?php $__currentLoopData = $dewormers; $__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(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="row mt-2">
                            <div class="col-md-6">
                                <label class="form-label" for="date_create">Deworming Date <span class="text-danger">*</span></label>
                                <input type="text"
                                       class="form-control piker-date <?php $__errorArgs = ['date'];
$__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="date" id="date_create" value="<?php echo e(old('date')); ?>" placeholder="Pick deworming date" required/>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="cost_create">Cost</label>
                                <input type="text" class="form-control" name="cost" id="cost_create" value="<?php echo e(old('cost')); ?>"
                                       placeholder="Enter cost"/>
                            </div>
                        </div>
                        <div class="row mt-2">
                            <div class="col-md-6">
                                <label class="form-label" for="route_create">Route/Method</label>
                                <select class="form-control" name="route" id="route_create">
                                    <option value="">Select Route</option>
                                    <option value="Subcutaneous">Subcutaneous</option>
                                    <option value="Intramuscular">Intramuscular</option>
                                    <option value="Oral">Oral</option>
                                    <option value="IV">IV</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="dose_create">Dose</label>
                                <input type="text" class="form-control" name="dose" id="dose_create" value="<?php echo e(old('dose')); ?>"
                                       placeholder="Enter dose number"/>
                            </div>
                        </div>

                        <div class="row mt-2 follow_date <?php echo e(($f_date) ? '' : 'd-none'); ?>">
                            <div class="col-md-6">
                                <label class="form-label" for="followup_date_create">Followup Date </label>
                                <input type="text" class="form-control piker-date" name="followup_date" id="followup_date_create"
                                       placeholder="Pick followup date"
                                       value="<?php echo e(($f_date) ?? old('followup_date')); ?>"/>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label" for="deworming_by_create">Deworming By</label>
                                <select class="form-control" name="deworming_by" id="deworming_by_create">
                                    <option value="">Select Deworming By</option>
                                    <?php $__currentLoopData = $inseminators; $__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(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="mt-5 d-flex justify-content-end ">
                            <button type="button" class="btn  me-2" data-bs-dismiss="modal"
                                    style="background: #EAECF0;">
                                <?php echo e(__('messages.close')); ?>

                            </button>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.create')): ?>
                                <button type="submit" class="btn btn-primary" >
                                    Save
                                </button>
                            <?php endif; ?>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    
    
    <div class="modal fade" id="dewarming_edit_modal" tabindex="-1" aria-labelledby="exampleModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title">Add Dewarming Information</h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('new.update.deworming')); ?>" method="POST" autocomplete="off">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <input type="hidden" id="item_id" name="item_id">
                                <label class="form-label" for="cattle_id_edit">Tag ID <span class="text-danger">*</span></label>
                                <select class="form-control add-modal-edit <?php $__errorArgs = ['cattle_id'];
$__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_id" id="cattle_id_edit">
                                </select>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label" for="type-edit">Type <span class="text-danger">*</span></label>
                                <select class="form-control type  <?php $__errorArgs = ['type'];
$__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="type"
                                        id="type-edit">
                                    <option value="">Select Type</option>
                                    <option value="regular"> Regular</option>
                                    <option value="custom"> Custom</option>
                                </select>
                            </div>
                        </div>
                        <div class="row mt-2">
                            <div class="col-md-6">
                                <label class="form-label" for="worm-edit">Worm Type <span class="text-danger">*</span></label>
                                <select class="form-control worm <?php $__errorArgs = ['worm'];
$__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="worm"
                                        id="worm-edit">
                                    <option value="">Select Worm Type</option>

                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="dewormer_id">Dewormer <?php echo e(__('messages.name')); ?> <span class="text-danger">*</span></label>
                                <select
                                    class="form-control dewormer_id select2-multiple <?php $__errorArgs = ['dewormer_id'];
$__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="dewormer_id" id="dewormer_id" disabled="disabled">
                                </select>
                            </div>
                        </div>
                        <div class="row mt-2">
                            <div class="col-md-6">
                                <label class="form-label" for="date">Deworming Date <span class="text-danger">*</span></label>
                                <input type="text"
                                       class="form-control  piker-date <?php $__errorArgs = ['date'];
$__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="date" id="date" value="<?php echo e(old('date')); ?>" placeholder="Pick deworming date"/>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="cost">Cost</label>
                                <input type="text" class="form-control" name="cost" id="cost" value="<?php echo e(old('cost')); ?>"
                                       placeholder="Enter cost"/>
                            </div>
                        </div>
                        <div class="row mt-2">
                            <div class="col-md-6">
                                <label class="form-label" for="route">Route/Method</label>
                                <select class="form-control" name="route" id="route"></select>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label" for="dose">Dose</label>
                                <input type="text" class="form-control" name="dose" id="dose" value="<?php echo e(old('dose')); ?>"
                                       placeholder="Enter dose number"/>
                            </div>
                        </div>
                        <div class="row mt-2 follow_date <?php echo e(($f_date) ? '' : 'd-none'); ?>">
                            <div class="col-md-6">
                                <label class="form-label" for="followup_date">Followup Date </label>
                                <input type="text" class="form-control piker-date" name="followup_date"
                                       id="followup_date" placeholder="Pick followup date"
                                       value="<?php echo e(($f_date) ?? old('followup_date')); ?>"/>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="deworming_by">Deworming By</label>
                                <select class="form-control" name="deworming_by" id="deworming_by"></select>
                            </div>
                        </div>
                        <div class="mt-5 d-flex justify-content-end ">
                            <button type="button" class="btn  me-2" data-bs-dismiss="modal"
                                    style="background: #EAECF0;">
                                <?php echo e(__('messages.close')); ?>

                            </button>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.create')): ?>
                                <button type="submit" class="btn btn-primary" >Update
                                </button>
                            <?php endif; ?>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    

    
    <div class="modal fade" id="deworming_bulk_modal" tabindex="-1" aria-labelledby="exampleModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-xl modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title">Bulk Entry - Deworming Information</h4>
                <div class="modal-body p-0 mt-3">
                    <div class="cm_row mt-2">
                        <div class="">
                            <div class="form-group">
                                <label class="form-label" for="farm">Farm Name</label>
                                <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($item->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                </select>
                            </div>
                        </div>
                        <div class="">
                            <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="">
                            <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="">
                            <div class="form-group pt-4" style="margin-top: 6px;">
                                <button type="button" id="get-data-btn"
                                        class="btn btn-primary" disabled="disabled" style="background-color: #009A75; color: #fff">Get Data
                                </button>
                            </div>
                        </div>
                    </div>
                    <form action="<?php echo e(route('dewormings-bulk-store')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data" autocomplete="off">
                        <?php echo csrf_field(); ?>
                        <div class="no_data mt-5 w-100 text-center" hidden>
                            <h6>No Data Found</h6>
                        </div>
                        <div class="row mt-4" id="bulk_entry_field" hidden>
                            <div class="col-md-12">
                                <div class="cm_grid">
                                    <div>
                                        <h6 style="font-size: 14px; color: #6E7796;font-weight: 600;">Showing data for
                                            -</h6>
                                    </div>
                                    <div class="farm_info"></div>
                                </div>
                            </div>
                            <div class="col-md-12 mb-3">
                                <label class="form-label">Tag ID <span class="text-danger">*</span></label>
                                <div class="form-check">
                                    <label class="cattle_uid">
                                        <input type="checkbox" class="form-check-input" id="checkAll"> Select All
                                    </label>
                                </div>
                                <div class="row cattle_info" id="cattle_info"></div>
                            </div>

                            <div class="col-md-4">
                                <label class="form-label" for="type_bulk">Type <span class="text-danger">*</span></label>
                                <select class="form-control type  <?php $__errorArgs = ['type'];
$__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="type"
                                        id="type_bulk" required>
                                    <option value="">Select Type</option>
                                    <option value="regular" <?php echo e((($type === 'regular')) ? 'selected' : ''); ?>>
                                        Regular
                                    </option>
                                    <option value="custom" <?php echo e((($type === 'custom')) ? 'selected' : ''); ?>>
                                        Custom
                                    </option>
                                </select>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label" for="worm_bulk">Worm Type <span class="text-danger">*</span></label>
                                <select class="form-control worm  <?php $__errorArgs = ['worm'];
$__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="worm"
                                        id="worm_bulk" required>
                                    <option value="">Select Worm Type</option>
                                    <option value="acdodarm" <?php echo e((($worm === 'acdodarm')) ? 'selected' : ''); ?>>
                                        Acdodarm
                                    </option>
                                    <option value="andodarm" <?php echo e((($worm === 'andodarm')) ? 'selected' : ''); ?>>
                                        Andodarm
                                    </option>
                                </select>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label" for="dewormer_id_bulk">Dewormer <?php echo e(__('messages.name')); ?> <span class="text-danger">*</span></label>
                                <select
                                    class="form-control select2-multiple dewormer_id <?php $__errorArgs = ['dewormer_id'];
$__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="dewormer_id" id="dewormer_id_bulk" disabled="disabled" required>
                                    <option value="">Select Dewormer</option>
                                    <?php $__currentLoopData = $dewormers; $__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(); ?>
                                </select>
                            </div>
                            <div class="col-md-4 mt-2">
                                <label class="form-label" for="date_bulk">Deworming Date <span class="text-danger">*</span></label>
                                <input type="text" class="form-control piker-date  <?php $__errorArgs = ['date'];
$__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="date" id="date_bulk" value="<?php echo e(old('date')); ?>" placeholder="Pick deworming date"
                                       required/>
                            </div>
                            <div class="col-md-4 mt-2">
                                <label class="form-label" for="cost_bulk">Cost</label>
                                <input type="text" class="form-control" name="cost" id="cost_bulk" value="<?php echo e(old('cost')); ?>"
                                       placeholder="Enter cost"/>
                            </div>
                            <div class="col-md-4 mt-2">
                                <label class="form-label" for="route_bulk">Route/Method</label>
                                <select class="form-control" name="route" id="route_bulk">
                                    <option value="">Select Route</option>
                                    <option value="Subcutaneous">Subcutaneous</option>
                                    <option value="Intramuscular">Intramuscular</option>
                                    <option value="Oral">Oral</option>
                                    <option value="IV">IV</option>
                                </select>
                            </div>
                            <div class="col-md-4 mt-2">
                                <label class="form-label" for="dose_bulk">Dose</label>
                                <input type="text" class="form-control" name="dose" id="dose_bulk" value="<?php echo e(old('dose')); ?>"
                                       placeholder="Enter dose number"/>
                            </div>
                            <div class="col-md-4 mt-2 follow_date <?php echo e(($f_date) ? '' : 'd-none'); ?>">
                                <label class="form-label" for="followup_date_bulk">Followup Date </label>
                                <input type="text" class="form-control piker-date" name="followup_date_bulk"
                                       id="followup_date" placeholder="Pick followup date"
                                       value="<?php echo e(($f_date) ?? old('followup_date')); ?>"/>
                            </div>
                            <div class="col-md-4 mt-2">
                                <div class="form-group">
                                    <label class="form-label" for="deworming_by_bulk">Deworming By</label>
                                    <select class="form-control" name="deworming_by" id="deworming_by_bulk">
                                        <option value="">Select Deworming By</option>
                                        <?php $__currentLoopData = $inseminators; $__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(); ?>
                                    </select>
                                </div>
                            </div>
                            <div class="mt-5 d-flex justify-content-end ">
                                <button type="button" class="btn  me-2" data-bs-dismiss="modal"
                                        style="background: #EAECF0;">Close
                                </button>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Deworming.create')): ?>
                                    <button type="submit" class="btn btn-primary" >
                                        Save
                                    </button>
                                <?php endif; ?>
                            </div>
                        </div>
                    </form>
                </div>

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

<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">
        $('.add-modal').select2({
            dropdownParent: $('#dewarming_add_modal'),
            width: 'resolve',
        });
        $(".piker-date").datepicker({
            autoHide: true,
            format: 'dd-mm-yyyy',
        });
        $('.modal').on('hidden.bs.modal', function (e) {
            $(this).find("input,textarea,select").val('').end().find("input[type=checkbox], input[type=radio]").prop("checked", "").end();
            // $('select').val("").trigger('change');
            $('#bulk_entry_field').prop('hidden', true);
            $('.no_data').prop('hidden', false);

        });
        $(document).on('click', '.view-btn', function () {
            let id = $(this).attr('view-id');
            $('.offcanva_data_view').empty();
            $.ajax({
                type: "GET",
                url: "<?php echo e(url('system/deworming')); ?>/" + id,
                success: function (res) {
                    $('.offcanva_data_view').append('<table class="table table-borderless w-100" style="border: none;">' +
                        ' <tr><th style="width: 40%;">Tag ID</th><td>' + res.cattle + '</td></tr>' +
                        ' <tr><th style="width: 40%;">Animal Name</th><td></td></tr>' +
                        ' <tr><th style="width: 40%;">Dewormer Name</th><td>' + res.name + '</td></tr>' +
                        ' <tr><th style="width: 40%;">Worm Type</th><td>' + res.deworm.type + '</td></tr>' +
                        ' <tr><th style="width: 40%;">Deworming Date</th><td>' + res.date + '</td></tr>' +
                        ' <tr><th style="width: 40%;">Cost</th><td>' + res.deworm.cost + '</td></tr>' +
                        '<tr><th style="width: 40%;">Route/Method</th><td>' + res.deworm.route + '</td></tr>' +
                        '<tr><th style="width: 40%;">Dose</th><td>' + res.deworm.dose + '</td></tr>' +
                        '<tr><th style="width: 40%;">Deworming By</th><td>' + (res.doctor === undefined ? 'null' : res.doctor) + '</td></tr>' +
                        '</table>')
                },
                error: function (response) {
                    console.log(response);
                }
            });
        });

        $('.type').change(function () {
            var type = $(this).val();
            if (type === 'custom') {
                $('.follow_date').removeClass('d-none');
            } else {
                $('.follow_date').addClass('d-none');
            }
        });

        $('.worm').change(function () {
            var worm = $(this).val();
            $.get("<?php echo e(url('system/worm/get-dewormer-list')); ?>?worm=" + worm, function (result) {
                $('.dewormer_id').prop("disabled", false);
                if (result) {
                    $(".dewormer_id").empty().append('<option>Select Dewormer</option>');
                    $.each(result, function (key, value) {
                        $(".dewormer_id").append('<option value="' + result[key].id + '">' + result[key].name + '</option>');
                    });
                } else {
                    toastr.error("Something Wrong");
                }
            });
        });

        $(document).on('click', '.edit-btn', function () {
            let id = $(this).attr('edit-id');
            $('#cattle_id_edit').empty();
            $('#worm-edit').empty();
            $('#type-edit').empty();
            $('#dewormer_id').empty();
            $('#route').empty();
            $('#vaccinated_by').empty();
            $.ajax({
                type: "GET",
                url: "<?php echo e(url('system/deworming')); ?>/" + id + "/edit",
                success: function (res) {

                    $.each(res.cattles, function (index, value) {
                        $('#cattle_id_edit').append('<option value="' + value.id + '" ' + (value.id === res.deworm.cattle_id ? 'selected' : '') + '>' + value.uid + '</option>');
                    });
                    $('#worm-edit').html('<option value="acdodarm"' + ("acdodarm" === res.deworm.worm ? 'selected' : '') + '>Acdodarm</option>' +
                        '<option value="andodarm" ' + ("andodarm" === res.deworm.worm ? 'selected' : '') + ' >Andodarm</option>');

                    var worm = res.deworm.worm;
                    $.get("<?php echo e(url('system/worm/get-dewormer-list')); ?>?worm=" + worm, function (result) {
                        $('.dewormer_id').prop("disabled", false);
                        if (result) {
                            $(".dewormer_id").empty().append('<option>Select Dewormer</option>');
                            $.each(result, function (key, value) {
                                $(".dewormer_id").append('<option value="' + result[key].id + '" ' + ( result[key].id === res.deworm.dewormer_id ? 'selected' : '') + '>' + result[key].name + '</option>');
                            });
                        } else {
                            toastr.error("Something Wrong");
                        }
                    });
                    $('#type-edit').append('<option value="regular" ' + ("regular" === res.deworm.type ? 'selected' : '') + '>Regular</option>' +
                        '<option value="custom" ' + ("custom" === res.deworm.type ? 'selected' : '') + '>Custom</option>');

                    if (res.deworm.type === 'custom') {
                        $('.follow_date').removeClass('d-none');
                    } else {
                        $('.follow_date').addClass('d-none');
                    }
                    $('#date').val(res.date);
                    $('#cost').val(res.deworm.cost);
                    $('#route').append('<option value="" selected disabled>Select Route</option>' +
                        '<option value="Subcutaneous" ' + ("Subcutaneous" === res.deworm.route ? 'selected' : '') + '>Subcutaneous</option>' +
                        '<option value="Intramuscular" ' + ("Intramuscular" === res.deworm.route ? 'selected' : '') + '>Intramuscular</option>' +
                        ' <option value="Oral" ' + ("Oral" === res.deworm.route ? 'selected' : '') + '>Oral</option>' +
                        '<option value="IV" ' + ("IV" === res.deworm.route ? 'selected' : '') + '>IV</option>');
                    $('#dose').append('<option value="">Select Type</option>' +
                        '<option value="First Dose" ' + ("First Dose" === res.deworm.dose ? 'selected' : '') + '>First Dose</option>' +
                        '<option value="Booster Dose"' + ("Booster Dose" === res.deworm.dose ? 'selected' : '') + '>Booster Dose</option>' +
                        ' <option value="Regular Dose"' + ("Regular Dose" === res.deworm.dose ? 'selected' : '') + '>Regular Dose</option>')
                    $.each(res.inseminators, function (index, value) {
                        $('#vaccinated_by').append('<option value="' + value.id + '" ' + (value.id === res.deworm.deworming_by ? 'selected' : '') + '>' + value.name + '</option>');
                    });
                    $('#dose').val(res.deworm.dose);
                    $('#followup_date').val(res.followup_date);
                    $('#item_id').val(res.deworm.id);
                },
                error: function (response) {
                    console.log(response);
                }
            });
        });
        //bulk entry
        $("#checkAll").click(function () {
            $(".check").prop('checked', $(this).prop('checked'));
        });

        $('#farm').change(function () {
            var farm_id = $(this).val();
            if (farm_id) {
                $.ajax({
                    type: "GET",
                    url: "<?php echo e(url('system/milk-production/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/milk-production/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();
            }
        });
        // get data method
        $('.no_data').prop('hidden', false);
        $('#get-data-btn').on('click', function () {
            let farm = $('#farm').val();
            let herd = $('#herd').val();
            let lot = $('#lot').val();
            $('.farm_info').empty();
            $('#cattle_info').empty();
            if (lot) {
                $.ajax({
                    type: "GET",
                    url: "<?php echo e(route('dewormings-get-data')); ?>",
                    data: {
                        farm: farm,
                        herd: herd,
                        lot: lot,
                    },
                    success: function (res) {
                        $('.farm_info').append('<p><strong>Farm Name : </strong><span>' + res.farm_info.name + '</span> <br>' +
                            '<strong>Hard Name : </strong><span>' + res.herd_info.name + '</span> <br>' +
                            '<strong>Lot Name : </strong><span>' + res.lot_info.name + '</span> </p>');
                        if (res.cattles.length > 0) {
                            $('.no_data').prop('hidden', true);
                            $('#bulk_entry_field').prop('hidden', false);
                            $.each(chunkArray(res.cattles, 5), function (index, value) {
                                $.each(value, function (index, item) {
                                    $('#cattle_info').append(
                                        '<div class="col-md-3">' +
                                        '<div class="form-check"><label class="cattle_uid"><input type="checkbox" class="form-check-input check" name="cattle_id[]" id="cattle_id_bulk" value="' + item.id + '"> ' + item.uid + '</label></div>' +
                                        '</div>'
                                    );
                                })

                            });
                        } else {
                            $('#bulk_entry_field').prop('hidden', true);
                            $('.no_data').prop('hidden', false);
                        }
                    }
                });
            } else {
                $("#lot").empty();
            }
        });

        function chunkArray(array, size) {
            var result = [];
            for (var i = 0; i < array.length; i += size) {
                result.push(array.slice(i, i + size));
            }
            return result;
        }
    </script>

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

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