<!--
<style type="text/css">
    #addStockCardTable thead tr th {
        color: #FFF;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }
    #addStockCardTable tbody tr td input {
        width: 100%;
        margin: 0;
        border: 1px solid rgba(0,0,0,0.02);
        background-color: #f0f0f0;
    }
    #addStockCardTable tbody tr td {
        border: 0;
        padding: 3px 1px;
        position: relative;
    }
    #addStockCardTable tbody tr:first-child td {
        padding-top: 10px;
    }
    #addStockCardTable .Hint {
        position: absolute;
        font-size: 10px;
        font-weight: bold;
        height: 20px;
        line-height: 20px;
        bottom: 2px;
        right: 4px;
        color: rgb(153, 153, 153);
    }
    #addStockCardTable .TotalTD {
        width: auto;
        display: inline-block;
        text-align: center;
        font-size: 20px;
        text-indent: 10px;
        font-weight: bold;
    }
    #addStockCardTable .Disc {
        width: 50px;
    }
    #addStockCardTable input.wrong {
        border: 1px solid rgba(255, 0, 0, 0.2);
        background: rgba(255, 0, 0, 0.05);
    }
    .DropDownForForms > .dropdown-menu {
        width: 100%;
        height: auto;
        max-height: 200px;
        cursor: pointer;
        overflow-y: auto;
        z-index: 999999;
    }
    .DropDownForForms > .dropdown-menu > li:hover {
        background: #eee;
    }
    .DropDownForForms > button {
        color:#FFF;
        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;
    }




    .DropDownForForms > button strong {
        width: 288px;
        text-overflow: ellipsis;
        overflow: hidden;
        display: block;
    }
    .hideMe {
        display:none;
    }
    .costW {
        width: 250;
    }

    .DepotDiv {
        padding-top: 37px;
    }


</style>
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade stick-up" data-backdrop="static"  id="add_StockCard" tabindex="-1" role="dialog" aria-hidden="true" style="overflow:auto">
    <div class="modal-dialog" style="width:50%">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" data- aria-hidden="true"><i class="pg-close fs-14"></i></button>
                <h5><?php print CommonLanguage::getMessage('Add_To_Stock_Card'); ?></h5>
            </div>
            <div class="col-m-12">
                <div id="AddExpirySuccess" class="hidden"></div>
            </div>
            <div class="modal-body">

                <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" style="float: left;">
                                        <h2 class="font-montserrat all-caps hint-text"><?php print CommonLanguage::getMessage('Transactions'); ?></h2>
                                        <div>
                                            <select id ="transaction_id" class="full-width Transaction" data-init-plugin="select2" >
                                                <option value="0"><?php print CommonLanguage::getMessage('Select_Transaction_Type'); ?></option>
                                                <?php foreach ($Trans_Type as $Type): ?>
                                                    <option value="<?php echo $Type['Transaction_Type_ID'] ?>"><?php echo $Type['Transaction_Type'] ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                        <br>
                                        <div class="hideMe" id="CostDiv">
                                            <div  Default-Currency="<?php echo $Currency_Default; ?>" class="input-group-btn DropDownForForms Closable" id="CurrencyDropDown">
                                                <button type="button" class="btn bg-complete-darker btn-block dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                    <span><strong><?php print CommonLanguage::getMessage('Select_Currency'); ?></strong></span>
                                                    <input type="hidden" value="" class="form-control ignore" name="Currency_ID" id="Currency_ID" onkeyup="return false" onkeydown="return false" required/>
                                                </button>
                                                <ul class="dropdown-menu">
                                                    <?php echo($currency); ?>
                                                    <li class="divider"></li>
                                                    <li><a class="LoadMore"><?php print CommonLanguage::getMessage('More'); ?>..</a></li>
                                                </ul>
                                            </div>
                                            <div>
                                                <label><?php print CommonLanguage::getMessage('Cost'); ?></label>
                                                <input type="number" class="form-control Cost" id="Unit_Cost">
                                            </div>
                                        </div>

                                        <div class="clearfix"></div>
                                    </div>
                                </div>

                                <div class="DepotDiv">
                                    <div class="input-group  col-md-4 center-margin"  style="float: right;">
                                        <div >
                                            <label><?php print CommonLanguage::getMessage('Depot'); ?></label>
                                            <select id ="DepotID" class="full-width Transaction" data-init-plugin="select2" >
                                                <option value="0"><?php print CommonLanguage::getMessage('Select_Depot'); ?></option>
                                                <?php foreach ($All_Depot as $depot): ?>
                                                    <option value="<?php echo $depot['Depot_ID'] ?>"><?php echo $depot['Depot_Name'] ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                        <div id="DepotFromDiv" class="hideMe">
                                            <label><?php print CommonLanguage::getMessage('From'); ?></label>
                                            <select id ="DepotIDFrom" class="full-width Transaction" data-init-plugin="select2" >
                                                <option value="0"><?php print CommonLanguage::getMessage('Select_Depot'); ?></option>
                                                <?php foreach ($All_Depot as $depot): ?>
                                                    <option value="<?php echo $depot['Depot_ID'] ?>"><?php echo $depot['Depot_Name'] ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                            </div>



                        </div>
                    </div>
                    <div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="table-responsive">
                        <form method="POST" action="" onsubmit="return false" id="InvoiceForm">
                            <table class="table m-t-50" id='addStockCardTable'>
                                <thead>
                                    <tr>
                                        <th class="text-center digits" ><?php print CommonLanguage::getMessage('Quantity'); ?></th>
                                        <th class="text-center" ><?php print CommonLanguage::getMessage('Expiry_Date'); ?></th>
                                        <th class="text-center DamageTH hideMe " ><?php print CommonLanguage::getMessage('Damage_Reason'); ?></th>

                                    </tr>
                                </thead>
                                <tbody id= "ExpiryQuantities">
                                    <tr class="TableItem">
                                        <td><input type="text" class="form-control Quantity digits" required></td>
                                        <td><input type="text" class="form-control ExpiryDate" value="<?php echo $today ?>"></td>
                                        <td><input type="text" class="form-control DamageReason hideMe"></td>
                                        <td><span class="fa fa-plus-circle plus_circle" style="color: #4c0870;margin-left: 10px;cursor: pointer;font-size: 16px;"></span><span class="fa fa-minus-circle hideMe minus_circle" style="color: #ed9421;margin-left: 5px;cursor: pointer;font-size: 16px;"></span></td>
                                    </tr>
                                </tbody>
                            </table>
                        </form>
                    </div>
                    <br>
                    <div class="container-sm-height" >
                        <button class=" btn bg-complete-darker btn-cons m-b-10 pull-right  "  id="SubmitToStockCard" style="padding-top: 10px;top: 20px;min-width:253px; color:#FFF;" type="button"><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('Save'); ?></span></button>
                    </div>
                </div>
                </form>
            </div>
        </div>

    </div>

</div>

<script>
    var today = <?php echo json_encode($today) ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>;
    $(function () {
        $(".ExpiryDate").datepicker({autoclose: true})
        $("#transaction_id").on("change", function () {
            var type = $(this).val();

            if (type == 1 || type == 10) {
                $("#CostDiv").removeClass("hideMe")
                $(".DamageReason,.DamageTH,#DepotFromDiv").addClass("hideMe")
            } else if (type == 4) {
                $("#DepotFromDiv").removeClass("hideMe")
                $(".DamageReason,.DamageTH,#CostDiv").addClass("hideMe")
            } else if (type == 7) {
                $(".DamageReason,.DamageTH").removeClass("hideMe")
                $("#DepotFromDiv,#CostDiv").addClass("hideMe")
            } else {
                $("#CostDiv,#DepotFromDiv,.DamageReason,.DamageTH").addClass("hideMe")
            }


        })

        $("#addStockCardTable tbody").on("click", "tr .minus_circle", function () {
            if ($('#addStockCardTable tbody tr').length > 1)
                $(this).parents("tr").remove();
            if ($('#addStockCardTable tbody tr').length = 2)
                $('#addStockCardTable tbody tr:eq(0) .minus_circle').addClass("hideMe");



        })

        $("#addStockCardTable tbody").on("click", " tr  .plus_circle", function () {
            var tr = $(this).parents("tr").clone();
            $(".minus_circle:eq(0)").removeClass("hideMe");
            tr.find("input").val("")
            tr.find(".ExpiryDate").datepicker({autoclose: true})
            tr.find(".minus_circle").removeClass("hideMe")
            $("#addStockCardTable tbody").append(tr)
        })

        $("#SubmitToStockCard").on("click", function () {
            $("#InvoiceForm").validate()
            console.log($("#InvoiceForm").valid())
            var transT = $("#transaction_id").val(),
                    dep = $("#DepotID").val(),
                    unit = $("#Unit_Cost").val(),
                    depF = $("#DepotIDFrom").val();
            $("#AddExpirySuccess").addClass("hideMe")
            if (transT == 0 || dep == 0 || ((transT == 1 || transT == 10) && unit == "") || (transT == 4 && depF == 0)) {
                $("#AddExpirySuccess").attr("class", "alert alert-danger").html("Please enter all required values.")

                return
            }
            if (!$("#InvoiceForm").valid()) {
                $("#AddExpirySuccess").attr("class", "alert alert-danger").html(Required_Fields)
                return
            }
            var mainArray = {
                "Product_ID": $("select.Product_ID").val(),
                "Category_ID": $("select.Material_Category_ID").val(),
                "Type_ID": $("#transaction_id").val(),
                "Depot_ID": $("#DepotID").val(),
                "Depot_ID_To": $("#DepotIDFrom").val(),
                "Unit_Cost": $("#Unit_Cost").val(),
                "Currency_ID": $("#Currency_ID").val(),
                "FromDate": window.startDate ? window.startDate : year + '-01-01',
                "ToDate": window.endDate ? window.endDate : year + '-12-31',
                "TypeTrans": $("#TypeTrans").val(),
                Expiry: []
            }
            $("#addStockCardTable tbody tr").each(function () {
                mainArray.Expiry.push({
                    Product_Quantity: $(this).find(".Quantity").val(),
                    Expiry_Date: $(this).find(".ExpiryDate").val(),
                    Damaged_Reason: $(this).find(".DamageReason").val()
                })

            })

            $.ajax({
                url: "StockAjax/addStockCardAjax",
                method: "POST",
                data: mainArray,
                dataType: "json",
                complete: function (v1, v2) {
                    if (v2 == 'success') {
                        var Data = v1.responseJSON,
                                l = Object.keys(Data).length;
//                    console.log(Object.keys(Data).length)

//                    $('.Profile').attr("src",img);
                        $('#tableWithSearch').DataTable().destroy();
                        $("#tableWithSearch tbody").empty();
                        for (var i = 0; i < l - 3; i++) {
//                        alert()

                            $(".product").empty().html(Data['General']['CODE'] + ' - ' + Data['General']['NAME']);
                            $(".qunatity").empty().html(FixNumber(Data['General']['Total_Quantity']));
                            $(".stock").empty().html(FixNumber(Data['Amount_Per_Stock']));
                            $(".Cost").empty().html(' ' + FixNumber(Data['Cost']));


                            var TR = $('<tr data-id=' + Data[i]['Transaction_ID'] + '><td class="text-center">' + Data[i]['Transaction_Date'] + '</td>' +
                                    '<td class="text-center">' + Data[i]['Transaction_Type'] + '</td>' +
                                    '<td class="text-center">' + FixNumber(Data[i]['Unit_Cost']) + ' ' + Data[i]['Currency_Symbol'] + '</td>' +
                                    '<td class="text-center">' + FixNumber(Data[i]['Product_Quantity']) + '</td>' +
                                    '<td class="text-center">' + FixNumber(Data[i]['Balance']) + ' ' + currencySymbol + '</td>' +
                                    '<td class="text-center">' + Data[i]['Depot_Name'] + '</td>' +
                                    '<td class="text-center">' + Data[i]['Employee_Name'] + '</td>' +
                                    '<td class="text-center "><span class="ExpiryDate">' + Data[i]['Expiry_Date'] + '</span></td>' +
                                    '<td class="text-center"><button class="text-center btn bg-complete-darker" style ="color:#FFF" id="editTrans">Edit</button></td>' +
                                    '</tr>');
                            $("#tableWithSearch").append(TR)
                        }
                        $('#tableWithSearch').DataTable()
//                    RebuildTable()
                        ReloadScroll()


                        $("#AddExpirySuccess").show();
                        $("#AddExpirySuccess").attr("class", "alert alert-success").html(Submitted_Successfully)
                        setTimeout(function () {
                            $("#add_StockCard").modal("hide")
                            $("#AddExpirySuccess").hide();
                        }, 1000)
//                    setTimeout({$("#add_StockCard").hide()',1000);
                    } else {
                        $("#AddExpirySuccess").attr("class", "alert alert-danger").html(Failed_Submit)
                    }

                }

            })
        })



    })

</script>


-->