<?php
if (isset($_POST['mode']) && $_POST['mode'] == 'get_num_2_word') {
    include(__DIR__ . "/libs/Common/NumToWords.php");
    $ar_number = NumToWords::convert('ar', floatval($_POST['value']), ($_POST['curr_id'] == 1 ? "دولار أميركي" : "ليرة لبنانية"), ($_POST['curr_id'] == 1 ? "سنت" : "قرش"));
    echo $ar_number . ' فقط لا غير';
//            //the dollar is Masculine in ar
//            $ar_number = new convert_ar('1013212', "male");
//            echo $ar_number->convert_number() . ' دولار أميركي فقط لا غير';
//            echo "<br/>";
//            //the LP (ليرة لبنانية) is Feminin in ar
//            $ar_number = new convert_ar('99998712302', "female");
//            echo $ar_number->convert_number() . ' ليرة لبنانية فقط لا غير';
    exit;
}
?><!DOCTYPE html>
<html lang="ar">

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width initial-scale=1.0">
        <title>Check</title>

        <link href="Theme/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css"/>

        <link href="Theme/plugins/boostrapv3/css/bootstrap.min.css" rel="stylesheet"> 
        <link href="Theme/plugins/bootstrap-select2/select2.css" rel="stylesheet" type="text/css" media="screen"/>
        <link href="Theme/plugins/switchery/css/switchery.min.css" rel="stylesheet" type="text/css" media="screen"/>
        <link href="Theme/plugins/nvd3/nv.d3.min.css" rel="stylesheet" type="text/css" media="screen"/>
        <link href="Theme/plugins/mapplic/css/mapplic.css" rel="stylesheet" type="text/css"/>
        <link href="Theme/plugins/rickshaw/rickshaw.min.css" rel="stylesheet" type="text/css"/>
        <link href="Theme/plugins/uniform/css/uniform.default.min.css" rel="stylesheet" type="text/css"/>
        <link href="Theme/plugins/bootstrap-datepicker/css/datepicker3.css"  rel="stylesheet" type="text/css"/>  
        <link href="Theme/plugins/jquery-metrojs/MetroJs.css" rel="stylesheet" type="text/css" media="screen"/>
        <link href="Theme/css/pages-icons.css" rel="stylesheet" type="text/css">
        <link href="Theme/css/pages.css"  rel="stylesheet" type="text/css"/>
        <link href="Theme/plugins/bootstrap-datepicker/css/datepicker3.css"  rel="stylesheet" type="text/css"/>



        <style>
            .form-control{
                margin-top:10px;
            }
        </style>
        <script src="Theme/plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>
        <script src="Theme/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
        <script src="Theme/plugins/boostrapv3/js/bootstrap.min.js" type="text/javascript"></script>
        <script src="Theme/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>
        <script src="Views/files/towords.js"></script>
    </head>
    <body style="background-color:#fff ">

        <form onsubmit="return false;">
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-2">
                        <h4>No 000311</h4>
                    </div>
                    <div class="col-md-2" style="border:1px solid #000;width: 60px;height: 40px;">logo</div>
                    <div class="col-md-4 text-center">3 Logo</div>
                    <div class="col-md-1" style="border:1px solid #000;width: 100px;height: 40px;">
                        <select class="full-width" id="currency_id">
                            <option value="1">USD</option>
                            <option value="2">LBP</option>
                        </select>
                    </div>
                    <div class="col-md-2"><input type="text" placeholder="enter amount" class="form-control" id="amount_value"/></div>
                </div>

            </div>
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-2 pull-left">
                        <h4>Pay against this cheque</h4>
                    </div>
                    <div class="col-md-2 pull-right">
                        <h4>إدفعوا بموجب هذا الشك</h4>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2">
                        <h4>To the order of</h4>
                    </div>
                    <div class="col-md-8">
                        <input class="form-control text-right" id="supplier_name" type="text" autocomplete="on"/>
                    </div>
                    <div class="col-md-2">
                        <h4>لأمر</h4>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2">
                        <h4>The sum of</h4>
                    </div>
                    <div class="col-md-8">
                        <input class="form-control text-right" id="amount_desc" type="text" autocomplete="off"/>
                    </div>
                    <div class="col-md-2">
                        <h4>مبلغ</h4>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-2">
                        <h4>Payable at / يدفع في</h4>
                        <h4>Saida Branch</h4>
                    </div>
                    <div class="col-md-2">
                        <input type="text" id="check_date" class="form-control text-right" value="<?php echo date('Y-m-d'); ?>" /><span>place</span>
                        <h4>100000075234<br/>CHARIFCO CHICKEN</h4>
                    </div>
                    <div class="col-md-1">
                        <h4>في <br/>Date</h4>
                    </div>
                    <div class="col-md-2">
                        <input type="text" class="form-control text-right" id="check_loc" autocomplete="on" /> <span>مكان الإصدار</span>
                    </div>
                    <div class="col-md-1">
                        <h4>Signature </h4>
                    </div>
                    <div class="col-md-2">
                    </div>

                    <div class="col-md-1">
                        <h4>الإمضاء</h4>
                    </div>


                </div>
            </div>
            <button class="btn btn-success" id="print_check" type="submit" ><i class="fa fa-print"></i> print</button>
        </form>
        <div id="form_check">



        </div>


        <script>




            function ucWords(str) {
                return str.replace(/([^\W_]+[^\s-]*) */g, function (txt) {
                    return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
                });
            }

            $(function () {
                $("#check_date").datepicker({});

                $('#currency_id,#amount_value').on('change', function () {
                    $('#print_check').attr('disabled', 'disabled');
                    $.ajax({
                        url: '',
                        data: {'mode': 'get_num_2_word', 'value': $("#amount_value").val(), 'curr_id': $('#currency_id').val()},
                        type: 'POST',
                        complete: function (v, v2) {
                            if (v2 == 'success') {
                                $("#amount_desc").val(v.responseText);
                                $('#print_check').removeAttr('disabled');
                            }
                        }
                    })
                });
                //
                $('#print_check').on('click', function () {
                    var row = '<div style="position:relative;"><div style="position:absolute;top:15px;left:490px;width:130px;text-align:center;"> # ' + $("#amount_value").val() + ' #</div>';
                    row += '<div style="position:absolute;top:70px;left:90px;width:520px;text-align:right;"> ' + $("#supplier_name").val() + '</div>';
                    row += '<div style="position:absolute;top:100px;left:70px;width:540px;text-align:right;"> ' + $("#amount_desc").val() + '</div>';
                    row += '<div style="position:absolute;top:155px;left:220px;">' + $("#check_date").val() + '</div>';
                    row += '<div style="position:absolute;top:155px;left:380px;">' + $("#check_loc").val() + '</div>';
                    row += '</div>';
                    $('#form_check').html($(row));
                    PrintElem($('#form_check'));

                });
            });
            function PrintElem(elem) {
                var mywindow = window.open('', 'PRINT', 'height=600,width=800');
                mywindow.document.write('<html><head><style>.header,.page-sidebar,.breadcrumb{display:none;}</style>');
                mywindow.document.write('</head><body style="direction:ltr;">');
                mywindow.document.write(elem.html());
                mywindow.document.write('</body></html>');
                mywindow.document.close(); // necessary for IE >= 10
                mywindow.focus(); // necessary for IE >= 10*/
                mywindow.print();
                mywindow.close();
                return true;
            }
        </script>
    </body>

</html>