

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')
    <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
</head>
<body>
<div class="row" id="x" style="display: none;">
    <div class="col-12">
      <span class="d-flex align-items-center purchase-popup">
        <i class="typcn typcn-delete-outline" id="bannerClose"></i>
      </span>
    </div>
</div>
<div class="container-scroller">
@include('layout.navbar')
<!-- partial -->
    @include('layout.breadscrum')
    <div class="container-fluid page-body-wrapper">

    @include('layout.sidebar')

    <!-- partial -->
        <div class="main-panel">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-md-12 grid-margin stretch-card">
                        <div class="card" style="min-height: 80vh;">
                            <div class="card-body">
                                <h4 class="card-title"><i class="mdi mdi-dots-vertical menu-icon"></i> {{__('laboratory.info')}}
                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_laboratory_information']))
                                    <button class="btn btn-sm btn-inverse-success waves-effect px-3 ml-2 rounded-25 float-right" type="button" data-action="new" data-toggle="modal" data-target="#modal-laboratory" data-backdrop="static"><i class="typcn typcn-pencil"></i> {{__('laboratory.form_edit_tittle')}}</button>
                                    @endif
                                </h4>

                                <div class="row px-3">
                                    <div class="col-lg-12 pr-4 border rounded-lg pt-3 pl-4 mt-2  bg-light">
                                        <h6 class="text-info">{{__('laboratory.info')}}</h6>
                                        <div class="py-2">
                                            <div class="row font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.table_name_kh')}}</span>
                                                <span class="text-muted col-sm-10">{{$info->name_kh}}</span>
                                            </div>
                                            <div class="row  font-14  py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.table_name_en')}}</span>
                                                <span class="text-muted col-sm-10">{{$info->name_en}}</span>
                                            </div>
                                            <div class="row  font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('lab_profile.short_name')}}</span>
                                                <span class=" text-muted col-sm-10">{{$info->short_name}}</span>
                                            </div>
                                            <div class="row  font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.phone')}}</span>
                                                <span class=" text-muted col-sm-10">{{$info->phone}}</span>
                                            </div>
                                            <div class="row  font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('lab_profile.emial')}}</span>
                                                <span class=" text-muted col-sm-10">{{$info->email}}</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 pr-4 border rounded-lg pt-3 pl-4 mt-3 bg-light">
                                        <h6 class="text-info">{{__('lab_profile.address')}}</h6>
                                        <div class="py-2">
                                            <div class="row font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.form_address_kh')}}</span>
                                                <span class="text-muted col-sm-10">{{$info->address_kh}}</span>
                                            </div>
                                            <div class="row  font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.form_address_en')}}</span>
                                                <span class="text-muted col-sm-10">{{$info->address_en}}</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 pr-4 border rounded-lg pt-3 pl-4 mt-3 bg-light">
                                        <h6 class="text-info">{{__('laboratory.license')}}</h6>
                                        <div class="py-2">
                                            <div class="row font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.start_date')}}</span>
                                                <span class="text-muted col-sm-10">{{date('l, F j, Y g:i A', strtotime($info->start_date))}}</span>
                                            </div>
                                            <div class="row  font-14 py-1">
                                                <span class="float-left col-sm-2">{{__('laboratory.expiry_date')}}</span>
                                                <span class="text-muted col-sm-10">{{date('l, F j, Y g:i A', strtotime($info->end_date))}}</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                        </div>
                    </div>

                </div>
            </div>

            </div>

            <div class="modal mt-5 fade modal-primary" id="modal-laboratory">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title">{{__('laboratory.form_edit_tittle')}}</h6>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="mdi mdi-close"></span></button>
                        </div>

                        <div class="modal-body">
                            <form method="post" action="{{url('laboratory-profile/update')}}" id="form" onkeydown="return event.key != 'Enter';">
                                @csrf
                                <input type="hidden" class="form-control" name="lab_id" id="lab-id" value="0" />
                                <div class="form-vertical">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <div class="form-group mb-1">
                                                <label for="lab-name-kh">{{__('laboratory.table_name_kh')}} <span class="text-danger">*</span> </label>
                                                <input type="text" class="form-control form-control-sm" name="name_kh" id="lab-name-kh" value="{{$info->name_kh}}" placeholder="{{__('laboratory.table_name_kh')}}"/>
                                            </div>
                                            <div class="form-group mb-1">
                                                <label for="lab-name-en">{{__('laboratory.table_name_en')}} <span class="text-danger">*</span></label>

                                                <div class="input-group" id="testItem">
                                                    <div class="form-group" style="flex:1 !important;">
                                                        <input type="text" class="form-control form-control-sm rounded-right-0" name="name_en" id="lab-name-en" value="{{$info->name_en}}" placeholder="{{__('laboratory.table_name_en')}}">
                                                    </div>
                                                    <div class="input-group-append">
                                                        <input type="text" class="form-control form-control-sm rounded-left-0" style="width: 100px !important;" name="short_name" id="lab-code" value="{{$info->short_name}}" maxlength="3" placeholder="{{__('lab_profile.short_name')}}">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-sm-6">

                                            <div class="form-group mb-1">
                                                <label for="lab-name-kh">{{__('patient.table_phon')}} </label>
                                                <input type="text" class="form-control form-control-sm" name="phone_number" id="phone-number" value="{{$info->phone_number}}" placeholder="{{__('patient.table_phon')}}"/>
                                            </div>

                                            <div class="form-group mb-1">
                                                <label for="lab-name-kh">{{__('lab_profile.emial')}} </label>
                                                <input type="email" class="form-control form-control-sm" name="email" id="email" value="{{$info->email}}" placeholder="{{__('lab_profile.emial')}}"/>
                                            </div>

                                        </div>

                                        <div class="col-sm-12">

                                            <div class="row form-group mb-1">
                                                <div class="col-sm-12">
                                                    <label for="address-kh" class="control-label">{{__('laboratory.form_address_kh')}}</label>
                                                    <input type="text" class="form-control form-control-sm" name="address_kh" id="address-kh" value="{{$info->address_kh}}" placeholder="{{__('laboratory.form_address_kh')}}">
                                                </div>
                                            </div>

                                            <div class="form-group mb-1">
                                                <label for="address-en">{{__('laboratory.form_address_en')}}</label>
                                                <input type="text" class="form-control form-control-sm" name="address_en" id="address-en" value="{{$info->address_en}}" placeholder="{{__('laboratory.form_address_en')}}">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <button type="submit" class="d-none" id="submit-data"></button>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-info rounded-25" onclick="$('#submit-data').click()" id="btnSave"><i class="fa fa-floppy-o"></i>&nbsp;&nbsp;<span class="save">{{__('lang.save')}}</span><span class="update" style="display: none">{{__('lang.update')}}</span></button>
                            <button type="button" class="btn btn-secondary rounded-25 mx-3" data-dismiss='modal'>{{__('lang.cancel')}}</button>
                        </div>
                    </div>
                </div>
            </div>

            @include('layout.footer')
        </div>
    </div>
</div>

@include('layout.common_script')

</body>

<script src="{{url(env("APP_URL").'storage/assets/vendors/js/org.vendor.bundle.base.js')}}"></script>

<script>

    let base_url = "{{url('laboratory-profile')}}";

    let sample_number = "{{$info->sample_number}}";
    let patient_code = "{{$info->patient_code}}";
    let technician_label = "{{$info->technician_label}}";
    let discount_type = "{{$info->discount_type}}";
    let phone_number = "{{$info->phone_number}}";
    let email = "{{$info->email}}";

    let currency = "{{$info->currency}}";

    let exchange_rate = "{{$info->exchange_rate}}";
    let abnormal_text_color = "{{$info->abnormal_text_color}}";
    let show_result_footer = "{{$info->show_result_footer}}";
    let abnormal_result_font_weight = "{{$info->abnormal_result_font_weight}}";
    let result_header_id = "{{$info->result_header_id}}";
    let invoice_template_id = "{{$info->invoice_template_id}}";

    function generateSlug(text) {
        return text
            .trim()
            .split(/\s+/)
            .slice(0, 3)
            .map(word => word[0])
            .join('')
            .toUpperCase().padEnd(3, 'X');
    }

    document.getElementById('lab-name-en').addEventListener('input', function () {
        document.getElementById('lab-code').value = generateSlug(this.value);
    });

    function showPreview(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("file-ip-1-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#image-upload-form').submit();
        }
    }


    /* alternative logo start */

    function showAlternativeLogo(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("file-ip-2-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#alternative-logo-upload-form').submit();
        }
    }


    $('#alternative-logo-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/alternative-logo/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#btn-remove-alternative-logo').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/alternative-logo/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#file-ip-2-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });
    /* alterntive logo end */

    /* default_footer start */

    function showDefaultFooter(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("file-ip-4-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#default-footer-upload-form').submit();
        }
    }


    $('#default-footer-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/default-footer/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#btn-remove-default-footer').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/default-footer/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#file-ip-4-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });

    /* default_footer end */

    /* alternative footer start */

     function showAlternativeFooter(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("file-ip-3-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#alternative-footer-upload-form').submit();
        }
    }

    $('#alternative-footer-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/alternative-footer/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#btn-remove-alternative-footer').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/alternative-footer/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#file-ip-3-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });

    /* alternative footer end */


    function showPreviewAlterVerifyImage(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("alter-verify-image-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#alter-verify-image-upload-form').submit();
        }
    }

    $('#alter-verify-image-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/alter-verify-sign/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#btn-remove-alter-verify-label').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/alter-verify-sign/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#alter-verify-image-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });


   function showPreviewAlterLabtechImage(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("alter-labtech-image-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#alter-labtech-image-upload-form').submit();
        }
    }

    $('#alter-labtech-image-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/alter-labtech-sign/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#btn-remove-alter-labtech-label').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/alter-labtech-sign/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#alter-labtech-image-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#image-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/avatar/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    $('#btn-remove-lab-logo').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/avatar/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#file-ip-1-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });

    function postLabConfigure(attr_code, attr_value) {
        let url = base_url + '/configure/save';
        $.ajax({
            url: url,
            type:"POST",
            data :{
                "_token": csrf_token,
                attribute_code : attr_code,
                attribute_value: attr_value
            },
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    }


    function postLabSettingSetter() {
        let url = base_url + '/save';

        technician_label = $('#technician-label').val()
        sample_number = $("input[name='sample_number']:checked").attr('data-id')
        patient_code = $("input[name='patient_number']:checked").attr('data-id')
        discount_type = $("input[name='discount_type']:checked").attr('data-id')
        exchange_rate = $('#exchange-rate').val()
        abnormal_text_color = $('#abnormal-text-color').val()
        show_result_footer = $('input[name="show_result_footer"]:checked').attr('data-id')
        abnormal_result_font_weight = $('input[name="abnormal_result_font_weight"]:checked').attr('data-id')
        result_header_id = $('input[name="result_header_id"]:checked').attr('data-id')
        invoice_template_id = $('input[name="invoice_template_id"]:checked').attr('data-id')

        if($('#phone-number').val()!='') phone_number = $('#phone-number').val()
        if($('#email').val()!='') email = $('#email').val()

        currency = $("input[name='currency']:checked").attr('data-id')

        $.ajax({
            url: url,
            type:"POST",
            data :{
                "_token": csrf_token,
                sample_number : sample_number,
                patient_code: patient_code,
                discount_type: discount_type,
                technician_label: technician_label,
                phone_number: phone_number,
                email: email,
                exchange_rate: exchange_rate,
                abnormal_text_color: abnormal_text_color,
                show_result_footer: show_result_footer,
                abnormal_result_font_weight: abnormal_result_font_weight,
                result_header_id: result_header_id,
                currency:currency,
                invoice_template_id: invoice_template_id
            },
            success:function(res){
                if(res.success){
                    $('.sample-number-mode-getter label').text(res.data.sample_number == 0 ? 'Manual' : 'Auto-generate')
                    $('.patient-number-mode-getter label').text(res.data.patient_code == 0 ? 'Manual' : 'Auto-generate')
                    $('.discount-type-getter label').text(res.data.discount_type == 1 ? '(%) Percentage' : '($) Price')
                    $('.verify-label-getter label').text(res.data.verify_label)
                    $('.technician-label-getter label').text(res.data.technician_label)
                    $('.phone-getter span').text(res.data.phone_number)
                    $('.email-getter span').text(res.data.email)
                    $('.base-currency-mode-getter label').text(res.data.currency == 0 ? 'USD ($)' :'Riel (៛)')
                    $('.invoice-template-mode-getter label').text(res.data.invoice_template_id == 1 ? '{{__('laboratory-profile.invoice_detail')}}' : '{{__('laboratory-profile.invoice_summary')}}')
                }
                handleMessage(res.success, res.message)
            }
        });
    }

    /** verify label image */

    $('#verify-image-upload-form').submit(function(e) {
        e.preventDefault();
        var formData = new FormData(this);
        $.ajax({
            url: '{{'laboratory-profile/verifies/upload'}}',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success:function(res){
                handleMessage(res.success, res.message)
            }
        });
    });

    function showPreviewVerifyImage(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("verify-image-preview");
            preview.src = src;
            preview.style.display = "block";
            $('#verify-image-upload-form').submit();
        }
    }

    $('#btn-remove-verify-label').click(function(e) {
        $.ajax({
            url: '{{'laboratory-profile/verifies/remove'}}',
            type: 'POST',
            data: {"_token": "{{ csrf_token() }}"},
            success:function(res){
                $('#verify-image-preview').attr('src',"")
                handleMessage(res.success, res.message)
            }
        });
    });

</script>

</html>

