
<style type="text/css">
    #ContraTable thead tr th {
        color:#555;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }
    #ContraTable tbody tr td input{
        width:100%;
        margin:0;
        border: 1px solid rgba(0,0,0,0.02);
        background-color:#f0f0f0;
    }
    #ContraTable tbody tr td {
        border:0;
        padding:3px 1px;
        position:relative;
    }
    #ContraTable tbody tr:first-child td{
        padding-top:10px;
    }
    #ContraTable .Hint{
        position: absolute;
        font-size: 10px;
        font-weight: bold;
        height: 20px;
        line-height: 20px;
        bottom: 2px;
        right: 4px;
        color: rgb(153, 153, 153);
    }
    #ContraTable .TotalTD{
        width: auto;
        display: inline-block;
        text-align: center;
        font-size: 20px;
        text-indent:10px;
        font-weight: bold;
    }
    #ContraTable .Disc{
        width:50px;
    }
    #ContraTable input.wrong{
        border: 1px solid rgba(255, 0, 0, 0.2);
        background: rgba(255, 0, 0, 0.05);
    }
    .DropDownForForms > .dropdown-menu{
        width:100%;
        height:200px;
        max-height:200px;
        overflow-y:scroll;
    }
    .DropDownForForms > .dropdown-menu{
        height:auto;
        cursor: pointer;
        overflow-y:auto;
    }
    .DropDownForForms > button{
        position:relative;
        z-index:999;
    }
    .DropDownForForms > button > input{
        position: absolute;
        left:5;
        top: 0;
        width:90%;
        cursor: pointer;
        -webkit-user-select:none;
        -moz-user-select:none;
        user-select:none;
        padding: 0;
        border: 0;
        background: transparent;
    }
    .Disabled{
        cursor:default;
        opacity:0.5;
    }
    #AdvanceValue{
        width: 102px;
        display: inline-block;
    }
    .select2-container {
        min-width: 200px;
    }
    .datepicker table tr td.new {
        color: #000 !important;
    }
    .datepicker thead tr .datepicker-switch {
        color: #4c0870;
    }
    .datepicker table tr td.day:hover {
        background: #4c0870;
        color: #fff !important;
    }
</style>
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<link href="<?php echo THEME_PATH; ?>/plugins/summernote/css/summernote.css" rel="stylesheet" type="text/css" media="screen">
<script src="<?php echo THEME_PATH; ?>/plugins/summernote/js/summernote.min.js" type="text/javascript"></script>
<div class="modal fade"  data-backdrop="static" id="add_contra" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <?php echo Forms::ModalLoader('ContraIsBusy')?>
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-14"></i></button>
                <h5><?php print CommonLanguage::getMessage('add_contra'); ?></h5>
            </div>
            <div class="modal-body">
                <div id="ContraValidationAlert" ></div>
                <form method="POST" action="" onsubmit="return false" id="ContraForm">
                    <div class="">
                        <div class="">
                            <div class="">
                                <div class="invoice">
                                    <div class="container-sm-height">
                                        <div class="row-sm-height">
                                            <div class="col-md-9 col-sm-height sm-no-padding">
                                                <div>
                                                    <div class="input-group  col-md-4 center-margin pull-left" >
                                                        <div class="sm-m-t-20">
                                                            <h2 class="font-montserrat all-caps hint-text"><?php print CommonLanguage::getMessage('contra'); ?></h2>
                                                        </div>
                                                    </div>
                                                    <div class="clearfix"></div>
                                                </div>
                                                <br>
                                                <div id="SupplierInfo">
                                                    <input type="hidden" name="Supplier_ID" required id="Supplier_ID" />
                                                    <div id="SupplierInfoContent">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-4 col-sm-height col-bottom sm-no-padding sm-p-b-20" style="vertical-align: top;">

                                                <div class="form-group form-group-default input-group">
                                                    <label class=""><?php print CommonLanguage::getMessage('Date'); ?></label>
                                                    <input id="Contra_Date" name="Contra_Date" class="form-control" value="<?php echo($today); ?>" >
                                                    <span class="input-group-addon complete"><i class="fa fa-calendar"></i></span>
                                                </div>
                                                <!--
<div Default-Currency="< ?php echo $currency->getDefaultCurrency(); ?>" class="input-group-btn DropDownForForms Closable" id="CurrencyDropDown">
<button type="button" class="btn btn-complete btn-block dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span><strong>Select Currency</strong></span>
<input type="hidden" id="Add_Contra_Currency_ID" value="< ?php echo $DefaultCurrencyID; ?>" class="form-control ignore" onkeyup="return false" onkeydown="return false" required/>
</button>
<ul class="dropdown-menu">
< ?php echo($currency->GetLIListCurrency()); ?>
<li class="divider"></li>
<li><a class="LoadMore">More..</a></li>
</ul>
</div>
                                                -->
                                                <br>
                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <div class=""></div>
                                    </div>
                                    <div class="table-responsive">
                                        <table class="table m-t-50" id='ContraTable'>
                                            <thead>
                                                <tr>
                                                    <th class="text-center" style="width:5%"></th>
                                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('account'); ?><span class="fa fa-plus-circle m-l-5 openFrame" data-src="ACC/viewlibrary/1?is_pop=1" style="color:#4c0870;cursor:pointer"></span></th>
                                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('Currency'); ?></th>
                                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('amount'); ?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td  class="text-center">
                                                        <?php print CommonLanguage::getMessage('transfer_from'); ?>: 
                                                    </td>
                                                    <td>
                                                        <div class="form-group BootstrapDropDown">
                                                                <input class="AccountCode full-width" id="Transfer_From" type="hidden"  />

<!--                                                            <select id="Transfer_From" class="full-width AccountCode" data-init-plugin="select2">
                                                                <?php // foreach ($contra_acocunts as $type): ?>
                                                                    <option value="<?php // echo $type['Account_Code']; ?>"><?php // echo $type['Account_Name'] . " - " . $type['Account_Code']; ?></option>
                                                                <?php // endforeach; ?>
                                                            </select>-->
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group BootstrapDropDown">
                                                            <select id="From_Currency" class="full-width " data-init-plugin="select2">
                                                                <?php foreach ($currency_list as $currency): ?>
                                                                    <option mysymbol="<?php echo $currency['Currency_Symbol']; ?>" value="<?php echo $currency['Currency_ID']; ?>"><?php echo $currency['Currency_Name'] . " - " . $currency['Currency_Code']; ?></option>
                                                                <?php endforeach; ?>
                                                            </select>
                                                        </div>
                                                    </td>

                                                    <!--

                                                    -->
                                                    <td><input id="Transfer_Amount" type="text"  class="form-control Transfer_Amount"></td>
                                                </tr>
                                                <tr>
                                                    <td  class="text-center">
                                                        <?php print CommonLanguage::getMessage('transfer_to'); ?>: 
                                                    </td>
                                                    <td>
                                                        <div class="form-group BootstrapDropDown">
                                                                <input class="AccountCode full-width" id="Transfer_To" type="hidden"  />

<!--                                                            <select id="Transfer_To" class="full-width AccountCode" data-init-plugin="select2">
                                                                <?php foreach ($contra_acocunts as $type): ?>
                                                                    <option value="<?php echo $type['Account_Code']; ?>"><?php echo $type['Account_Name'] . " - " . $type['Account_Code']; ?></option>
                                                                <?php endforeach; ?>
                                                            </select>-->
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group BootstrapDropDown">
                                                            <select id="To_Currency" class="full-width " data-init-plugin="select2">
                                                                <?php foreach ($currency_list as $currency): ?>
                                                                    <option mysymbol="<?php echo $currency['Currency_Symbol']; ?>" value="<?php echo $currency['Currency_ID']; ?>"><?php echo $currency['Currency_Name'] . " - " . $currency['Currency_Code']; ?></option>
                                                                <?php endforeach; ?>
                                                            </select>
                                                        </div>
                                                    </td>


                                                    <td><input id="Transfered_Amount" type="text"  class="form-control Transfer_Amount"></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <br>
                                    <div class="container-sm-height" >
                                        <div class="row row-sm-height b-a b-grey">
                                            <div class="col-sm-8 col-sm-height col-middle clearfix sm-p-b-15">
                                                <textarea id="Contra_Note" name="Contra_Note" class="form-control NoteTextArea" placeholder="<?php print CommonLanguage::getMessage('enter_note'); ?>"></textarea>
                                            </div>
                                            <div class="col-sm-4 text-right bg-menu col-sm-height padding-15">
                                                <h5 class="font-montserrat all-caps small no-margin hint-text text-white bold"><?php print CommonLanguage::getMessage('From'); ?> </h5>
                                                <h1 class="no-margin text-white Total"><span class="CurrencyIndicatorFrom"><?php echo $CurrSymbol ?></span>&nbsp;<span id="ContraTotalDetailsFrom">0</span></h1>


                                                <h5 class="font-montserrat all-caps small no-margin hint-text text-white bold"><?php print CommonLanguage::getMessage('To'); ?> </h5>
                                                <h1 class="no-margin text-white Total"><span class="CurrencyIndicatorTo"><?php echo $CurrSymbol ?></span>&nbsp;<span id="ContraTotalDetailsTo">0</span></h1>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="container-sm-height" >
                                        <button class=" btn btn-complete btn-cons m-b-10 pull-right disabled" name="ContraSubmitButton" id="ContraSubmitButton" style="padding-top: 10px;top: 20px;min-width:253px;" type="button"><i class="pg-form"></i> <span class="bold">Submit</span></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<script>
    var Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            eq_total = <?php echo json_encode(CommonLanguage::getMessage('eq_total')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>;

    $("body").addClass("NoSearch")


    $(function () {
        
        build_select2($(".AccountCode"),"xhr/accIDSearch?type=contra")
//        $("#add_contra").on("show.bs.modal", function () {
//            $("#ContraValidationAlert").remove();

//        });
        $("#Contra_Date").datepicker({autoclose: true})


    })
    $("#From_Currency,#To_Currency").on("change", function () {
        var Fromsymbol = $("#From_Currency option:selected").attr('mysymbol'),
                Tosymbol = $("#To_Currency option:selected").attr('mysymbol')
        $(".CurrencyIndicatorFrom").html(Fromsymbol)
        $(".CurrencyIndicatorTo").html(Tosymbol)
        setTimeout("ContraUpdateSubmitButtonStatus()", 100);

    })
    var Def = $("#From_Currency").filter(function () {
        return $(this).attr("value") == $("#From_Currency input").val();
    })
    if (Def.length > 0) {
        $(".CurrencyIndicatorFrom").html(Def.attr("mysymbol"))
        $("> button > span", $("#From_Currency")).html(Def.text());
    }


    $("#ContraSubmitButton").on("click", function () {
        var from_a = parseFloat($("#Transfer_Amount").val()),
                to_a = parseFloat($("#Transfered_Amount").val());
            if(from_a != to_a){
                $("#ContraValidationAlert").attr("class", "alert alert-danger").empty().html(eq_total);
                     $("#add_contra").scrollTop(0)
                return
            }
            var IsValidated = true;
//        $("#ContraValidationAlert").remove();
//        var AlertBox = $('<div id="ContraValidationAlert" class="WizardValidationAlert alert"></div>'), 
//        AlertBox.insertAfter($("#add_contra").find(".modal-dialog .modal-header").find("h5"))
        //if($("#InvoiceForm").valid()){
        if (!IsValidated)
            return;
        $("#ContraIsBusy").removeClass('hidden')
//        $("#add_contra").append('<div id="ContraIsBusy" style="position:absolute;left:0;right:0;top:0px;height:100%;background:rgba(255,255,255,0.9);z-index:9999;opacity:0"><img class="image-responsive-height demo-mw-50" src="img/demo/progress.svg" alt="Progress" style="position: absolute;left: 50%;top: 50%;margin: -25px 0 0 -25px;" /></div>');
//        $("#ContraIsBusy").animate({opacity: 1});
        var Data = {
            Contra_Date: $("#Contra_Date").val(),
            From_Currency: $("#From_Currency").val(),
            To_Currency: $("#To_Currency").val(),
            Transfer_From: $("#Transfer_From").val(),
            Transfer_To: $("#Transfer_To").val(),
            Transfer_Amount: $("#Transfer_Amount").val(),
            Transfered_Amount: $("#Transfered_Amount").val(),
            Contra_Note: $("#Contra_Note").val()
        };
        $.ajax({
            url: "ACCAjax/addContra",
            method: "POST",
            data: Data,
            complete: function (v1, v2) {
                if (v2 == 'success') {
                    if (v1.responseText == 'success') {
//                        $("#ContraIsBusy").remove()
                        $("#ContraValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                        ChangeTable()
                        setTimeout(function() {
                            $("#add_contra").modal('toggle')
                            $("#ContraValidationAlert").addClass("hidden")
                        }, 1500)
                    }else{
                        $("#ContraValidationAlert").attr("class", "alert alert-danger").empty().html(v1.responseText);
                    }
                } else {
                    $("#ContraValidationAlert").attr("class", "alert alert-danger").empty().html(Failed_Submit);
                }
                $("#ContraIsBusy").addClass('hidden')

//                $("#ContraTotalDetailsFrom,#ContraTotalDetailsTo").html("0");
            }
        })
    });
    $("#ContraTable").on("keyup", "input.Transfer_Amount", function () {
        ContraUpdateSubmitButtonStatus()
    })
    function ContraUpdateSubmitButtonStatus() {
        var IsValidated = true;
        if ($("#Transfer_Amount").val() == "" || ($("#Transfer_Amount").hasClass("Transfer_Amount") && ($("#Transfer_Amount").val()).match(/^\s*?([\d]+(\.\d+)?|\.\d{1,2})\s*$/) == null)) {
            IsValidated = false;
        }
        if ($("#Transfered_Amount").val() == "" || ($("#Transfered_Amount").hasClass("Transfer_Amount") && ($("#Transfered_Amount").val()).match(/^\s*?([\d]+(\.\d+)?|\.\d{1,2})\s*$/) == null)) {
            IsValidated = false;
        }
        if (!IsValidated) {
            $("#ContraSubmitButton").addClass("disabled")
        } else {
            $("#ContraSubmitButton").removeClass("disabled")
        }
        var Transfer_Amount = parseFloat($("#Transfer_Amount").val()) || 0;
        var Transfered_Amount = parseFloat($("#Transfered_Amount").val()) || 0;
        $("#ContraTotalDetailsFrom").attr({"MyValue": Transfer_Amount}).text(AddCommas(public_round_number(Transfer_Amount)))
        $("#ContraTotalDetailsTo").attr({"MyValue": Transfered_Amount}).text(AddCommas(public_round_number(Transfered_Amount)))
    }
</script>
