
<?php $__env->startSection('title'); ?> Invoice Terms | Beauty Parlour <?php $__env->stopSection(); ?>
<?php $__env->startSection('branch'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('invoice-terms.index'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('styles'); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content_section'); ?>
<div class="row py-3 ps-2">
    <div class="heading d-flex justify-content-start align-items-center">
        <h3 class="mb-0"><span> Invoice Terms List</span></h3>
    </div>
</div>

<div class="table_wrapper py-1 card">
    <div class="row my-2 aggregate-section-div">
        <div class="px-3 ">
            <div class=" d-flex justify-content-between align-items-center aggregate-section border">
                <div class="d-flex align-items-center">
                    <p class="mb-0"><a href="<?php echo e(route('invoice-terms.index')); ?>"
                            class="text-primary py-2 px-3 active">All(<?php echo e($allInvoiceTermCount); ?>)</a>
                    </p>

                    <p class="mb-0"><a href="<?php echo e(route('active-invoice-terms-list')); ?>"
                    class="text-primary py-2 px-3">Active(<?php echo e($activeInvoiceTermCount); ?>)</a></p>
                    <p class="mb-0"><a href="<?php echo e(route('inactive-invoice-terms-list')); ?>"
                            class="text-primary py-2 px-3">Inactive(<?php echo e($inactiveInvoiceTermCount); ?>)</a></p>
                </div>
                <div class="d-none d-sm-block">
                    <?php if(Auth::user()->can('invoice-terms-create')): ?>
                    <a href="javascript:void(0)"
                        class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0" data-bs-toggle="modal"
                        data-bs-target="#addInvoiceTerms"><span class="">New Terms</span></a>
                    <?php endif; ?>
                </div>
            </div>

            <?php if(Auth::user()->can('invoice-terms-create')): ?>
            <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none" data-bs-toggle="modal"
                data-bs-target="#addInvoiceTerms">
                New Terms</div>
            <?php endif; ?>
        </div>
    </div>



    <div class="row px-3">
        <div class="table-container table-responsive">
            <table id="" class="table table-bordered">
                <thead class="text-uppercase">
                    <tr class="me-3">
                        <th class="text-center" scope="col"><span>Invoice Title</span></th>
                        <th class="text-center" scope="col"><span>Invoice Terms</span></th>
                        <th class="text-center" scope="col"><span>Status</span></th>
                    </tr>
                </thead>
                <tbody class="text-center">

                    <?php $__currentLoopData = $invoiceTermData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php if(isset($item) && $item != null): ?>
                    <tr class="">

                        <td class="text-start">
                            <div class="row_title">
                                <span class="text-normal fw-bolder"><?php echo e($item->invoice_title); ?></span>
                            </div>
                            <div class="row-actions mt-2">

                                <?php if(Auth::user()->can('invoice-terms-edit')): ?>
                                <span><button class="text-primary border-0 bg-transparent fw-bolder" value="<?php echo e($item->id); ?>"
                                        onclick="updateInvoiceTerms(<?php echo e($item->id); ?>)"> Edit </button></span>
                                

                                <?php if($item->status == true): ?>
                                <span> | <a class="text-warning fw-bolder"
                                        href="<?php echo e(route('invoice-terms-inactive', $item->id)); ?>">Inactive</a></span>
                                <?php else: ?>
                                <span> | <a class="text-success fw-bolder"
                                        href="<?php echo e(route('invoice-terms-active', $item->id)); ?>">Active</a>
                                </span>
                                <?php endif; ?>

                                <?php if($item->status == true): ?>
                                <?php if($item->is_default == false): ?>
                                <span> | <a class="text-info fw-bolder" href="<?php echo e(route('invoice-terms-default', $item->id)); ?>">Make Default</a></span>
                                <?php else: ?>
                                <span> | <a class="text-success fw-bolder" href="#">Default</a>
                                </span>
                                <?php endif; ?>
                                <?php endif; ?>

                                <?php endif; ?>
                                <?php if(Auth::user()->can('invoice-terms-delete')): ?>
                                
                                <?php endif; ?>
                            </div>
                        </td>
                        <?php
                        // Convert the description to plain text (remove HTML tags)
                        $description = strip_tags($item->invoice_terms);
                        
                        // Split the description into words
                        $description_words = preg_split('/\s+/', $description, -1, PREG_SPLIT_NO_EMPTY);
                        
                        // Get the first 50 words
                        $limited_description = implode(' ', array_slice($description_words, 0, 20));
                        ?>

                        <td><?php echo $limited_description; ?>...</td>

                        <td>
                            <?php if($item->status == true): ?>
                            <span class="badge bg-success">Active</span>
                            <?php else: ?>
                            <span class="badge bg-danger">Inactive</span>
                            <?php endif; ?>
                        </td>

                    </tr>

                    
                    <div class="modal fade" id="updateInvoiceTerms<?php echo e($item->id); ?>" tabindex="-1"
                        aria-labelledby="oneInputModalLabel" aria-hidden="true" data-bs-backdrop='static'>
                        <div class="modal-dialog modal-dialog-centered max-width-900px">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h1 class="modal-title fs-5" id="oneInputModalLabel">Update Invoice Terms</h1>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                                        aria-label="Close"></button>
                                </div>
                                <form action="<?php echo e(route('invoice-terms.update', $item->id)); ?>" method="post"
                                    enctype="multipart/form-data">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('put'); ?>
                                    <div class="modal-body p-0">
                                        <div class="row px-4 my-4">

                                            <div class="col-md-12 mb-3">
                                                <div class="form-group">
                                                    <label for="invoice_title">Invoice Title<span class="text-danger">(required)</span>
                                                    </label>
                                                    <input type="text" name="invoice_title" required class="form-control form-control-solid" 
                                                        value="<?php echo e($item->invoice_title); ?>" placeholder="Title">
                                                </div>
                                            
                                                <?php $__errorArgs = ['invoice_title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <span class=text-danger><?php echo e($message); ?></span>
                                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                            </div>
                                            
                                            <div class="col-md-12 mb-3">
                                                <div class="form-group">
                                                    <label for="invoice_terms">Invoice Terms<span class="text-danger">(required)</span>
                                                    </label>
                                                    <textarea type="text" name="invoice_terms" id="invoice_terms<?php echo e($item->id); ?>" class="form-control form-control-solid" value=""
                                                        placeholder="Invoice Terms" rows="2" cols="2"><?php echo $item->invoice_terms; ?></textarea>
                                                </div>

                                                <span id="warnTextDesc1<?php echo e($item->id); ?>" class="text-danger warn d-none">Invoice Terms is required</span>
                                            
                                                <?php $__errorArgs = ['invoice_terms'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <span class=text-danger><?php echo e($message); ?></span>
                                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-success" onclick="return validateFU(<?php echo e($item->id); ?>)">Update</button>
                                        <button type="button" class="btn btn-danger"
                                            data-bs-dismiss="modal">Cancel</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                </tbody>
            </table>
        </div>

        <?php if(isset($allInvoiceTermCount) && $allInvoiceTermCount > 10): ?>
        <div class="clearfix d-flex">
            <div class="float-left">
                <p class="text-muted">
                    <?php echo e(__('Showing')); ?>

                    <span class="font-weight-bold"><?php echo e($invoiceTermData->firstItem()); ?></span>
                    <?php echo e(__('to')); ?>

                    <span class="font-weight-bold"><?php echo e($invoiceTermData->lastItem()); ?></span>
                    <?php echo e(__('of')); ?>

                    <span class="font-weight-bold"><?php echo e($invoiceTermData->total()); ?></span>
                    <?php echo e(__('results')); ?>

                </p>
            </div>

            <div class="float-right custom-table-pagination">
                <?php echo $invoiceTermData->links('pagination::bootstrap-4'); ?>

            </div>
        </div>
        <?php endif; ?>
    </div>
</div>



<div class="modal fade" id="addInvoiceTerms" tabindex="-1" aria-labelledby="oneInputModalLabel" aria-hidden="true" data-bs-backdrop='static'>
    <div class="modal-dialog modal-dialog-centered max-width-900px">
        <div class="modal-content">
            <div class="modal-header">
                <h1 class="modal-title fs-5" id="oneInputModalLabel">New Invoice Terms</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-header">
                <p class="fs-5 text-center mb-0" id="oneInputModalLabel">ইনভয়েস নীতি একবার তৈরী হয়ে গেলে Delete করা সম্ভব না , প্রয়োজনে edit বা inactive করতে পারবেন। তাই অপ্রয়োজনীয় ইনভয়েস নীতি তৈরী থেকে বিরত
                থাকুন।</p>
            </div>
            <form action="<?php echo e(route('invoice-terms.store')); ?>" method="post" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <div class="modal-body p-0">
                    <div class="row px-4 my-4">
                        <div class="col-md-12 mb-3">
                            <div class="form-group">
                                <label for="invoice_title">Invoice Title<span class="text-danger">(required)</span>
                                </label>
                                <input type="text" name="invoice_title" required class="form-control form-control-solid" value=""
                                    placeholder="Title">
                            </div>
                        
                            <?php $__errorArgs = ['invoice_title'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class=text-danger><?php echo e($message); ?></span>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <div class="col-md-12 mb-3">
                            <div class="form-group">
                                <label for="invoice_terms">Invoice Terms<span class="text-danger">(required)</span>
                                </label>
                                <textarea type="text" name="invoice_terms" id="invoice_terms" class="form-control form-control-solid" value=""
                                    placeholder="Invoice Terms" rows="2" cols="2"></textarea>
                            </div>

                            <span id="warnTextDesc1" class="text-danger warn d-none">Invoice Terms is required</span>
                        
                            <?php $__errorArgs = ['invoice_terms'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class=text-danger><?php echo e($message); ?></span>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success" onclick="return validate()">Save</button>
                    <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                </div>
            </form>
        </div>
    </div>
</div>

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

<?php $__env->startSection('scripts'); ?>
<?php echo $__env->make('admin.invoiceTerms.partial.tinymce', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>

    function validate(){
        if ((tinymce.EditorManager.get('invoice_terms').getContent()) == ''){
            event.preventDefault();
            document.getElementById('warnTextDesc1').classList.add('active')
            return false;
        }
    };
    
    function validateFU(id){
        if ((tinymce.EditorManager.get('invoice_terms'+id).getContent()) == ''){
            event.preventDefault();
            document.getElementById('warnTextDesc1'+id).classList.add('active')
            return false;
        }
    };

    //To show update modal...
    function updateInvoiceTerms(id) {
        //For package description...
        tinymce.init({
        selector: '#invoice_terms'+id,
        plugins: [
            "advlist autolink lists link image charmap print preview hr anchor pagebreak",
            "searchreplace wordcount visualblocks visualchars code fullscreen",
            "insertdatetime media nonbreaking save table contextmenu directionality",
            "emoticons template paste textcolor colorpicker textpattern textcolor"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | image | forecolor backcolor",
        images_upload_url: '/upload-image-for-package',  // Server endpoint for image uploads

        images_upload_handler: function (blobInfo, success, failure) {
            const formData = new FormData();
            formData.append('file', blobInfo.blob(), blobInfo.filename());

            fetch('/upload-image-for-package', {
            method: 'POST',
            body: formData,
            headers: {
                'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'  // Include the CSRF token
            }
            })
            .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
            })
            .then(data => success(data.location))
            .catch(error => failure('Image upload failed: ' + error));
        }

        });

        $("#updateInvoiceTerms"+id).modal('show');
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\Project\Personal-Project\Office-Project\update\skin-care\resources\views/admin/invoiceTerms/index.blade.php ENDPATH**/ ?>