<script>
    
    function createNewAccount(){
        var route_link = '/add-company-chart-of-account';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(route_link))
            .dialog({
            modal: true,
            width: 600,
            title: "Create a New Account for the Company",

            buttons: [
                {
                    text: "Create Account",
                    icon: "ui-icon-check",
                    id: "my-button-1",
                    click: function(e) {
                        if(confirm('Are you sure to Save Entered Details?')){
                            e.preventDefault();
                            $("#my-button-1").attr('disabled', true).text('Please Wait....');
                            var datas = $('#add-company-chart-of-accounts').serializeArray();

                            $.ajax({
                                method: "POST",
                                url: route_link,
                                data: datas,
                                success: function (res){
                                    if(res == 'empty type'){
                                        alert('Please Select the Type of Ledger you want to create');
                                        $("#my-button-1").attr('disabled', true).text('Create Account');
                                    }else if(res == 'empty currency'){
                                        alert('Please Select a Currency for the Bank Account to be Created');
                                        $("#my-button-1").attr('disabled', true).text('Create Account');
                                    }else if(res == 'empty name' ){
                                        alert('Please Provide the Ledger Name for this Account to proceed');
                                        $("#my-button-1").attr('disabled', true).text('Create Account');
                                    }else if(res == 'empty number' ){
                                        alert('Please Provide the Ledger Number for this Account to Proceed');
                                        $("#my-button-1").attr('disabled', true).text('Create Account');
                                    }else if(res == 'account exists' ){
                                        alert('Provided Account Name already Exists');
                                        $("#my-button-1").attr('disabled', true).text('Create Account');
                                    }else if(res == 'number exists' ){
                                        alert('Provided Ledger Number already Exists');
                                        $("#my-button-1").attr('disabled', true).text('Create Account');
                                    }else if(res == 'error' ){
                                        alert('An Error occurred and System is unable to perform the requested action. Try again');
                                        location.reload();
                                    }else if(res.indexOf('general-ledger-account') != -1){
                                        window.location = res;
                                    }else{
                                        alert('System Encountered an Error. Please Contact System Admin');
                                        location.reload();
                                    }
                                }
                            });
                        }
                        return false;
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }
    
    function searchClientFinance(){
        var url_link = '/search-client-finance';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
        .load(encodeURI(url_link))
        .dialog({
            modal: true,
            width: 600,
            title: "Search Client and Policy",
            buttons: [
                {
                    text: "Open Policy File ",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        e.preventDefault();
                        var type = $('input[name="search-parameter"]:checked').val();

                        var selected,details;
                        selected = $('#policy-details').val();
                        details = "Please Select a Client to Search";

                        if(selected == "" ||  null){
                            alert(details);
                        }else{
                            $(location).attr('href','/policy-finance/'+selected+'?type=summary');
                        }

                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 20});
            }
        });
    }

    //SEARCH POLICY
    function searchPolicyFinance(){
        var url_link = '/search-policy-finance';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(url_link))
            .dialog({
            modal: true,
            width: 750,
            title: "Search Policy File",
            buttons: [
                {
                    text: "Open Policy File ",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        e.preventDefault();
                        //$('#submit-button').text("Please wait...").attr('disabled', true).css('backgroundColor', 'gray');
                        var type = $('input[name="search-parameter"]:checked').val();

                        var selected,details;
                        if(type == 1){
                            selected = $('#select-list').val();
                            details = "Please Select a Debit Note to Search";
                        }else if(type == 2) {
                            selected = $('#credit-notes').val();
                            details = "Please Select Credit Note Number to perform the Search";
                        }

                        if(selected == "" ||  null){
                            alert(details);
                        }else{
                            if(type == 1){
                                $(location).attr('href','/policy-finance/'+selected+'?type=summary');
                            }else if(type == 2){
                                $(location).attr('href','/credit-note/'+selected+'/finance?type=summary');
                            }
                        }
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 70});
            }
        });
    }

    
    function searchPremiumDirectPV(){
        var url_link = '/search-direct-payment-voucher';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(url_link))
            .dialog({
            modal: true,
            width: 600,
            title: "Search Direct Premium Payment Voucher",
            buttons: [
                {
                    text: "Continue & View",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        e.preventDefault();

                        var selected = $('#select-list').val();
                        if(selected == "" ||  null){
                            alert('Please Select a Direct Payment Voucher to Search');
                        }else{
                            $(location).attr('href','/direct-payment-voucher/'+selected+'/finance?type=summary');
                        }
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }

    
    function searchReceipt(){
        var url_link = '/search-receipt';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(url_link))
            .dialog({
            modal: true,
            width: 600,
            title: "Search a Receipt",
            buttons: [
                {
                    text: "Continue & View",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        e.preventDefault();

                        var selected = $('#select-list').val();
                        if(selected == "" ||  null){
                            alert('Please Select a Receipt to Search');
                        }else{
                            $(location).attr('href','/receipt/'+selected+'/finance?type=summary');
                        }
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }

    
    function searchCompanyLedger(){
        var url_link = '/search-general-ledger';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(url_link))
            .dialog({
            modal: true,
            width: 600,
            title: "Search a General Ledger Account",
            buttons: [
                {
                    text: "Continue & View",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        e.preventDefault();
                        var selected = $('#select-list').val();
                        if(selected == "" ||  null){
                            alert('Please Select a Receipt to Search');
                        }else{
                            $(location).attr('href','/general-ledger-account/'+selected);
                        }
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }
    function addNewReceipt(){
        alert('Coming Soon');
    }

    /**JV Section**/
    function clientToClientJv(){
        var url_link = '/client-client-jv';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
        .load(encodeURI(url_link))
        .dialog({
            modal: true,
            width: 600,
            title: "Create a Client to Client JV",
            buttons: [
                {
                    text: "Continue & Save",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        if(confirm('Are you sure to Create a Client - Client JV?')){
                            e.preventDefault();
                            $("#my-button-1").attr('disabled', true).text('Please Wait....');
                            var datas = $('#add-client-client-jv').serializeArray();
                            $.ajax({
                                method: "POST",
                                url: url_link,
                                data: datas,
                                success: function (res){
                                    if(res == 'empty cr'){
                                        alert('Please Select the Account to be Credited');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'empty dr'){
                                        alert('Please Select the Account to be Debited');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'empty amount' ){
                                        alert('Please Enter Amount you want to create a Journal with');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'empty date' ){
                                        alert('Please Provide the Date of Journal Entry to Proceed');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'dr greater than zero' ){
                                        alert('Policy to be Debited has a balance greater than Zero.');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'cr less than zero' ){
                                        alert('Policy to be Credited has a balance less than Zero.');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'more amount' ){
                                        alert('The Entered JV Amount is greater than available Amount to be used');
                                        $("#my-button-1").attr('disabled', true).text('Continue & Save');
                                    }else if(res == 'error' ){
                                        alert('An Error occurred and System is unable to perform the requested action. Try again');
                                        location.reload();
                                    }else if($.isNumeric(res)){
                                        /**Redirect to JVs Page for Approval**/
                                        window.location = '/journal-voucher/'+res;
                                    }else{
                                        alert('System Encountered an Error. Please Contact System Admin');
                                        location.reload();
                                    }
                                }
                            });
                        }
                        return false;
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }
</script>
<?php /**PATH C:\xampp\htdocs\finewood\resources\views/finance/js/finance-functions.blade.php ENDPATH**/ ?>