
<style type="text/css">
    #InventoryPurchaseTable thead tr th {
        color:#555;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }
    #InventoryPurchaseTable tbody tr td input{
        width:100%;
        margin:0;
        border: 1px solid rgba(0,0,0,0.02);
        background-color:#e5e5e5;
    }
    #InventoryPurchaseTable tbody tr td {
        border:0;
        padding:3px 1px;
        position:relative;
    }
    #InventoryPurchaseTable tbody tr:first-child td{
        padding-top:10px;
    }
    #InvoiceDiscountInput{
        display: inline-block;
        width: 40px;
        padding: 3px;
        line-height: 20px;
        background: rgb(250, 250, 250);
        min-height: 12px;
        text-align: center;
        height: 25px;
        font-size: 12px;
        top: -2px;
        position: relative;
        margin: 0 3px;


    }
    #InvoiceVAT{
        display: inline-block;
        width: 92px;
        padding: 3px;
        line-height: 20px;
        background: rgb(250, 250, 250);
        min-height: 12px;
        text-align: center;
        height: 25px;
        font-size: 12px;
        top: -2px;
        position: relative;
        margin: 0 3px;
        margin-left: 23px;

    }
    #InventoryPurchaseTable .Hint{
        position: absolute;
        font-size: 10px;
        font-weight: bold;
        height: 20px;
        line-height: 20px;
        bottom: 2px;
        right: 4px;
        color: rgb(153, 153, 153);
    }
    #InventoryPurchaseTable .TotalTD{
        width: auto;
        display: inline-block;
        text-align: center;
        font-size: 20px;
        font-weight: bold;
    }

    #InventoryPurchaseTable input.wrong{
        border: 1px solid rgba(255, 0, 0, 0.2);
        background: rgba(255, 0, 0, 0.05);
        /*        width:100%;*/
    }
    .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;
    }
    .datepicker thead tr .dow {
        color:#4c0870!important;
    }
    .datepicker table tr td.day:hover {
        background: #4c0870!important;
        color:#fff;
    }
    .datepicker table tr td.active {
        background-color: #4c0870!important;
color:#ed9421 !important;    }
    .datepicker thead tr .datepicker-switch {
        color: #4c0870 !important;
        font-size: 13px;
    }
    .datepicker table tr td span.active {
        background-color: #4c0870!important;
color:#ed9421 !important;    }
    .datepicker table tr td span:hover {
        background-color: #4c0870!important;
color:#ed9421 !important;        color:#fff;
    }
    datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870!important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    .datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870!important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    .select2-container > .select2-choice{
        background-color: #e5e5e5;
        width: 150px;
    }
    #InvoicePaymentSetup .nav.nav-tabs a {
        padding: 7px 14px;
        font-size: 11px;
    }
    .InputSpinner{
        width: 60px;
    }
    .InputSpinner > .form-control{
        border-color: rgb(221, 221, 221);
        height:36px;
        margin:0;
        padding:0;
        text-align: center;
        /*
        -webkit-border-radius: 3px 0px 0px 3px !important;
        -moz-border-radius: 3px 0px 0px 3px !important;
        border-radius: 3px 0px 0px 3px !important;
        */
    }
    .InputSpinner > .input-group-btn-vertical {
        position: relative;
        white-space: nowrap;
        width: 25px;
        vertical-align: middle;
        display: table-cell;
    }
    .InputSpinner > .input-group-btn-vertical > .btn {
        height:19px;
        display: block;
        float: none;
        width: 100%;
        max-width: 100%;
        padding: 8px;
        margin-left: -1px;
        position: relative;
        border-radius: 0;
    }
    .InputSpinner > .input-group-btn-vertical > .btn:first-child {
        border-top-right-radius: 4px;
    }
    .InputSpinner > .input-group-btn-vertical > .btn:last-child {
        margin-top: -2px;
        border-bottom-right-radius: 4px;
    }
    .InputSpinner > .input-group-btn-vertical i{
        position: absolute;
        top: 50%;
        left: 6px;
        margin-top:-9px;
        font-size: 18px;
    }
    .InputSpinner .input-group-btn-vertical .btn.btn-default{
        font-size: 10px;
        padding: 6px 10px;
    }
    #InvoicePaymentSetup .table tbody > tr:last-child > td{
        border:0;
    }
    .hideme{

        display:none;
    }
    .select2-container > .select2-choice {

        width: 100%;

    }
    .supInv{
        display:inline-flex;
    }
    .Account_Code{
        margin-left:10px;
    }

</style>
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>

    <div id="PurchaseDisabler" style="position:absolute;left:0;right:0;top:0px;height:100%;background:rgba(255,255,255,0.9);z-index:2099;display:none"><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>
    <form method="POST" action="" onsubmit="return false" id="InvoiceForm">
        <div class="container-fluid container-fixed-lg">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="PurchaseSuccess" class="hidden"></div>
                    <div class="invoice padding-50 sm-padding-10">
                        <div class="container-sm-height">
                            <div class="row-sm-height">
                                <div class="col-md-9 col-sm-height sm-no-padding">
                                    <h2 class="font-montserrat all-caps hint-text"><?php echo CommonLanguage::getMessage('purchase_invoice'); ?> </h2>
                                    <div>
                                        <div class="input-group  col-md-4 center-margin pull-left" >

                                            <select  name="search_supplier" id="search_supplier"  class="full-width Account_Code " data-init-plugin="select2" value="<?php echo $order_details[0]['Supplier_ID'] ?>">

                                                <option value="0"> <?php print CommonLanguage::getMessage('choose_supplier'); ?></option> 
                                                <?php foreach ($suppliers as $supp): ?>
                                                    <option value="<?php echo $supp['Supplier_ID']; ?>"><?php echo $supp['Supplier_Name']; ?></option>
                                                <?php endforeach; ?>

                                            </select>

                                                                                <!--                                        <input type="text" id="search_supplier" class="form-control" placeholder="Enter < ?php echo $IsSales ? 'Customer' :'Supplier Company';?>" >-->
                                        </div>
                                        <div class="Account_Code col-md-4">
                                            <select  name="Account_Code" id="Account_Code"  class="full-width Account_Code " data-init-plugin="select2">
                                                <option value="0"> <?php print CommonLanguage::getMessage('choose_account'); ?></option> 

                                                <?php foreach ($purAcc as $pur): ?>
                                                    <option value="<?php echo $pur['Account_Code']; ?>"><?php echo $pur['Account_Name'] . ' - ' . $pur['Account_Code']; ?></option>
                                                <?php endforeach; ?>


                                            </select>
                                            <!--                                        <input type = "text" id="Account_Code" class="form-control" placeholder="Account Code">-->
                                        </div>

                                        <div class="clearfix"></div>
                                    </div>
                                    <br>
                                    <div id="SupplierInfo">
                                        <input type="hidden" name="Supplier_ID" required id="Supplier_ID" value="<?php echo $order_details[0]['Supplier_ID'] ?>" />
                                        <div id="SupplierInfoContent">
                                            <strong><span class='Name'><?php echo $order_details[0]['Supplier_Name'] ?></span></strong>
                                        </div>
                                        <div id="SupplierAccInfo">
                                        </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="sm-m-t-20">
                                        <h4><?php print CommonLanguage::getMessage('purchase_voucher'); ?> #
                                            <?php if (empty($InvoiceNumber)) {
                                                echo 1;
                                            } else {
                                                echo $InvoiceNumber + 1;
                                            } ?></h4>
                                    </div>
                                    <div  class="form-group supInv" id="SupplierInv" style="">
                                        <h4> <?php print CommonLanguage::getMessage('supplier_invoice'); ?>#</h4>
                                        <input id="Supplier_Invoice" name="Supplier_Invoice" class="form-control" value="" style="    width: 35%;
                                               margin-top: 11px;
                                               margin-left: 15px" />

                                    </div>
                                    <div  class="form-group form-group-default input-group">
                                        <label><?php print CommonLanguage::getMessage('Date'); ?></label>
                                        <input id="PurchaseInvoiceDate" name="PurchaseInvoiceDate" class="form-control" value="<?php echo ($today); ?>" />
                                        <span class="input-group-addon primary"><i class="fa fa-calendar"></i></span>
                                    </div>
                                    <div  class="form-group form-group-default input-group  ">
                                        <label><?php print CommonLanguage::getMessage('due_date'); ?></label>
                                        <input id="PurchaseInvoiceDueDate" name="PurchaseInvoiceDueDate" class="form-control" required>
                                        <span class="input-group-addon primary"><i class="fa fa-calendar-o"></i></span>
                                    </div>

                                    <div  id="depot" class="form-group " >

                                        <div class="input-group m-b" >
                                            <label><?php print CommonLanguage::getMessage('Depot'); ?></label>
                                            <div class="input-group" style="    width: 311px;">
                                                <span class="input-group-btn">
                                                    <button type="button" class="btn btn-primary"><i class="fa fa-certificate"></i> </button> </span>
                                                <select required id="Depot_Loc" name="Depot_Loc" class="full-width Depot_Loc" data-init-plugin="select2">
<?php foreach ($all_depots as $Depot): ?>
                                                        <option value="<?php echo $Depot['Depot_ID']; ?>"><?php echo $Depot['Depot_Name']; ?></option>
<?php endforeach; ?>

                                                </select>
                                            </div>
                                        </div>

                                    </div>
<?php echo Forms::CurrencyDropDown(1, 'primary'); ?>

                                    <br>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="clearfix"></div>
                        </div>
                        <div class="table-responsive">
                            <div id="ProdLoader" class="text-center alert hidden" style="height:100%;background-color:#E2DEEF"> <h3 ></h3> </div>
                            <table class="table m-t-50 " id='InventoryPurchaseTable'>
                                <thead>
                                    <tr>
                                        <th class="text-center" style="width:15%"><?php print CommonLanguage::getMessage('Type'); ?></th>
                                        <th class="text-center"style="width:15%"><?php print CommonLanguage::getMessage('Code'); ?></th>
                                        <th class="text-center" style="width:20%"><?php print CommonLanguage::getMessage('product_name'); ?></th>
                                        <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('Quantity'); ?></th>
                                        <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('unit_cost'); ?></th>
                                        <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('discount_percent'); ?></th>
                                        <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('vat'); ?></th>
                                        <th class="text-center"style="width:10%"><?php print CommonLanguage::getMessage('total'); ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                                <?php for ($i = 0; $i < count($order_details); $i++) { ?>
                                        <tr data-vat="<?php echo $order_details[$i]['VAT'] ?>" data-id="<?php echo $order_details[$i]['Item_ID'] ?>" data-qty="<?php echo $order_details[$i]['Stock_Qty'];?>">
                                            <td>
                                                <select required name="Material_Category_ID"  class="full-width Material_Category_ID " data-init-plugin="select2" value="<?php echo $order_details[$i]['Material_Category_ID'] ?>">
    <?php foreach ($all_categories as $Cat): ?>
                                                        <option value="<?php echo $Cat['Material_Category_ID']; ?>"><?php echo $Cat['Material_Category_Name']; ?></option>
    <?php endforeach; ?>
                                                </select>
                                            </td>
                                            <td><input type="text" class="form-control AutoComplete CODE" value="<?php echo $order_details[$i]['Code'] ?>"></td>
                                            <td><input type="text" class="form-control AutoComplete ProductName" value="<?php echo $order_details[$i]['Name'] ?>"></td>
                                            <td><span class="Hint"><?php echo CommonLanguage::getMessage('last_cost').' '.$order_details[$i]['last_cost']?> </span><input type="text" class="form-control Quantity isnumber" value="<?php echo $order_details[$i]['Product_Delivery_Quantity'] ?>"></td>
                                            <td><span class="Hint"><?php echo $order_details[$i]['Stock_Qty'].' '.CommonLanguage::getMessage('in_stock')?></span><input type="text" class="form-control UnitPrice isnumber"></td>
                                            <td><input type="text" class="form-control Disc" value=""></td>
                                            <td><input type="text" class="form-control VATPerItem " disabled value=""></td>
                                            <td class="TotalTD"><span class="CurrencyIndicator"></span>&nbsp;<span class="Total">0</span></td>
                                            <td class="ExpiryDate"><span class="fa fa-plus-circle" style="color:#4c0870;margin-top:10px"></span></td>
                                        </tr>
<?php } ?>
                                </tbody>
                            </table>
                        </div>
                        <br>
                        <div class="container-sm-height" >
                            <div class="row row-sm-height b-a b-grey">
                                <div class="col-sm-6 col-sm-height col-middle  clearfix" style="border-left: 1px solid #eee;padding-left: 6px;border-right: 1px solid #eee;padding-right:0">
                                    <h5 class="font-montserrat all-caps small no-margin hint-text bold"><?php print CommonLanguage::getMessage('payment'); ?></h5>
                                    <div id="InvoicePaymentSetup" class="no-print">
                                        <div class="Body">
                                            <div class="">
                                                <ul class="nav nav-tabs">
                                                    <li class="active"><a data-toggle="tab" href="#SetPaidFormTab_1"><i class="fa fa-money"></i>&nbsp;&nbsp;<?php print CommonLanguage::getMessage('cash'); ?></a></li>
                                                    <li><a data-toggle="tab" href="#SetPaidFormTab_2"><i class="fa fa-file-text-o"></i>&nbsp;&nbsp;<?php print CommonLanguage::getMessage('check'); ?></a></li>
                                                    <li><a data-toggle="tab" href="#SetPaidFormTab_3"><i class="fa fa-cc-visa"></i>&nbsp;&nbsp;<?php print CommonLanguage::getMessage('credit_card'); ?></a></li>
                                                </ul>
                                                <div class="tab-content" style="padding:0;overflow:visible">
                                                    <div id="SetPaidFormTab_1" class="tab-pane fade in active">
                                                        <table class="table" cellpadding="0" cellspacing="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="width: 65%;"><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('amount'); ?></span></td>
                                                                    <td>
                                                                        <div class="input-group InputSpinner" style="width:120px">
                                                                            <input type="text" class="form-control" value="0" onblur="InputMustBeAtleastN(this, 0);" />
                                                                            <div class="input-group-btn-vertical">
                                                                                <button class="btn btn-default more"><i class="fa fa-caret-up"></i></button>
                                                                                <button class="btn btn-default"><i class="fa fa-caret-down"></i></button>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('Type'); ?></span></td>
                                                                    <td style="text-align:center">
                                                                        <div class="input-group-btn DropDownForForms Closable">
                                                                            <button type="button" class="btn btn-default btn-block dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                                <span><?php print CommonLanguage::getMessage('select'); ?></span>
                                                                                <input type="hidden" value="" class="form-control" onkeyup="return false" onkeydown="return false"/>
                                                                            </button>
                                                                            <ul class="dropdown-menu">
<?php for ($x = 0; $x < count($Cashes); $x++) { ?>
                                                                                    <li value="<?php echo $Cashes[$x]["Payment_Type_ID"]; ?>"><a><?php echo $Cashes[$x]["Payment_Type_Name"]; ?></a></li>
<?php } ?>
                                                                            </ul>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <div id="SetPaidFormTab_2" class="tab-pane fade in">
                                                        <table class="table" cellpadding="0" cellspacing="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="width: 65%;"><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('amount'); ?></span></td>
                                                                    <td>
                                                                        <div class="input-group InputSpinner" style="width:120px">
                                                                            <input type="text" class="form-control" value="0" onblur="InputMustBeAtleastN(this, 0);" />
                                                                            <div class="input-group-btn-vertical">
                                                                                <button class="btn btn-default more"><i class="fa fa-caret-up"></i></button>
                                                                                <button class="btn btn-default"><i class="fa fa-caret-down"></i></button>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('Type'); ?></span></td>
                                                                    <td style="text-align:center">
                                                                        <div class="input-group-btn DropDownForForms Closable">
                                                                            <button type="button" class="btn btn-default btn-block dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                                <span><?php print CommonLanguage::getMessage('select'); ?></span>
                                                                                <input type="hidden" value="" class="form-control" onkeyup="return false" onkeydown="return false"/>
                                                                            </button>
                                                                            <ul class="dropdown-menu">
<?php for ($x = 0; $x < count($Checks); $x++) { ?>
                                                                                    <li value="<?php echo $Checks[$x]["Payment_Type_ID"]; ?>"><a><?php echo $Checks[$x]["Payment_Type_Name"]; ?></a></li>
<?php } ?>
                                                                            </ul>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><span class="SpanInTableInPayment"> <?php print CommonLanguage::getMessage('check'); ?>#</span></td>
                                                                    <td style="text-align:center"><input type="text" class="form-control CheckNumValue" /></td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <div id="SetPaidFormTab_3" class="tab-pane fade in">
                                                        <table class="table" cellpadding="0" cellspacing="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="width: 65%;"><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('amount'); ?></span></td>
                                                                    <td>
                                                                        <div class="input-group InputSpinner" style="width:120px">
                                                                            <input type="text" class="form-control" value="0" onblur="InputMustBeAtleastN(this, 0);" />
                                                                            <div class="input-group-btn-vertical">
                                                                                <button class="btn btn-default more"><i class="fa fa-caret-up"></i></button>
                                                                                <button class="btn btn-default"><i class="fa fa-caret-down"></i></button>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('Type'); ?></span></td>
                                                                    <td style="text-align:center">
                                                                        <div class="input-group-btn DropDownForForms Closable">
                                                                            <button type="button" class="btn btn-default btn-block dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                                                <span><?php print CommonLanguage::getMessage('select'); ?></span>
                                                                                <input type="hidden" value="" class="form-control" onkeyup="return false" onkeydown="return false"/>
                                                                            </button>
                                                                            <ul class="dropdown-menu">
<?php for ($x = 0; $x < count($CreditCards); $x++) { ?>
                                                                                    <li value="<?php echo $CreditCards[$x]["Payment_Type_ID"]; ?>"><a><?php echo $CreditCards[$x]["Payment_Type_Name"]; ?></a></li>
<?php } ?>
                                                                            </ul>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td><span class="SpanInTableInPayment"><?php print CommonLanguage::getMessage('approval_code'); ?></span></td>
                                                                    <td style="text-align:center"><input type="text" class="form-control CardApproval" /></td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-3 col-sm-height col-middle clearfix sm-p-b-15" style="text-align:center">
                                    <div style="text-align: left;display: inline-block;">
                                        <h5 class="font-montserrat all-caps small no-margin hint-text bold" ><?php print CommonLanguage::getMessage('vat_ten'); ?><span class="form-control ignore" id="InvoiceVAT"></span> </h5>
                                        <h5 class="font-montserrat all-caps small no-margin hint-text bold" > <?php print CommonLanguage::getMessage('invoice_discount'); ?><input type="text" class="form-control ignore" id="InvoiceDiscountInput" /> %</h5>
                                        <h3 class="no-margin"><span class="CurrencyIndicator"></span>&nbsp;<span id="InvoiceTotalAfterDiscount">0</span></h3>
                                        <h5 class="font-montserrat all-caps small no-margin hint-text bold" ><?php print CommonLanguage::getMessage('item_discount'); ?></h5>
                                        <h3 class="no-margin"><span class="CurrencyIndicator"></span>&nbsp;<span id="DiscountVal">0</span></h3>
                                    </div>
                                </div>
                                <div class="col-sm-3 text-right bg-menu col-sm-height padding-15" style="text-align:left !important">
                                    <div style="text-align: left;display: inline-block;">
                                        <h5 class="font-montserrat all-caps small no-margin hint-text text-white bold"><?php print CommonLanguage::getMessage('total'); ?></h5>
                                        <h1 class="no-margin text-white Total"><span class="CurrencyIndicator"></span>&nbsp;<span id="PurchaseInvoiceTotalDetails">0</span></h1>
                                        <h5 class="font-montserrat all-caps small no-margin hint-text text-white bold"><?php print CommonLanguage::getMessage('total_paid'); ?></h5>
                                        <h1 class="no-margin text-white Total"><span class="CurrencyIndicator"></span>&nbsp;<span id="PurchaseInvoiceTotalPaid">0</span></h1>
                                        <h5 class="font-montserrat all-caps small no-margin hint-text text-white bold"><?php print CommonLanguage::getMessage('taxable_amount'); ?></h5>
                                        <h1 class="no-margin text-white Total"><span class="CurrencyIndicator"></span>&nbsp;<span id="PurchaseTaxableAmount">0</span></h1>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="container-sm-height" >
                            <button class=" btn btn-primary btn-cons m-b-10 pull-right" id="InvoiceSubmitButton" style="padding-top: 10px;top: 20px;min-width:253px;" type="button"><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('Save'); ?></span></button>
                        </div>
                        <hr>
                        <div>
                            <span class="m-l-20 text-black sm-pull-right"><?php echo $org_details[0]['Organization_Legal_Name']; ?></span>
                            <span class="m-l-20 text-black sm-pull-right"><?php echo $org_details[0]['Organization_Province']; ?> <?php echo $org_details[0]['Organization_Country']; ?> - <?php echo $org_details[0]['Organization_City']; ?></span>
                            <span class="m-l-20 text-black sm-pull-right">CR: <?php echo $org_details[0]['Organization_Commercial_Registry']; ?></span>
                            <span class="m-l-20 text-black sm-pull-right"><?php print CommonLanguage::getMessage('Phone'); ?>: <?php echo $org_details[0]['Organization_Phone']; ?></span>
                            <span class="m-l-40 text-black sm-pull-right"><?php print CommonLanguage::getMessage('Email'); ?>: <?php echo $org_details[0]['Organization_Email']; ?></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="role-mode" id="add_Expiry" aria-hidden="true" style="display: none;     width: 50%;
     margin: 0 auto;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel"> <?php print CommonLanguage::getMessage('Add_Expiry_Date'); ?></h4>
                <div id="ExpirySuccess" class="hidden"></div>

                <br>
            </div>
            <div class="modal-body" id="Add">
                <input type="hidden" name="Product_ID"  id="Product_ID" class="form-control input-rounded" required>
                <input type="hidden" name="Category_ID"  id="Category_ID" class="form-control input-rounded" required>
                <input type="hidden" name="Unit_Price"  id="Unit_Price" class="form-control input-rounded" required>
                <div class="form-group col-md-12 AddRow">
                    <div  class=" col-md-6">
                        <input type="text" name="Product_Quantity"  id="Product_Quantity" placeholder=" <?php print CommonLanguage::getMessage('Quantity'); ?>" class="form-control input-rounded Product_Quantity" required>
                    </div>
                    <div  class=" col-md-5">
                        <input type="text" name="Product_ExpiryDate"  id="Product_ExpiryDate" placeholder="<?php print CommonLanguage::getMessage('Expiry_Date'); ?>" class="form-control input-rounded Product_ExpiryDate" required>
                    </div>
                    <span class="fa fa-plus-circle" style="color:#8a7dbe;margin-top:10px"></span>
                    <span class="fa fa-minus-circle" style="color:#ed9421;margin-top:10px;display:none"></span>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" id="Closemodal" ><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button type="submit" class="btn btn-primary" id="SubmitExpiry"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
        </div>
    </div>
</div>








<script>
    var Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            CompanyLang = <?php echo json_encode(CommonLanguage::getMessage('company')); ?>,
            EmailLang = <?php echo json_encode(CommonLanguage::getMessage('Email')); ?>,
            PhoneLang = <?php echo json_encode(CommonLanguage::getMessage('Phone')); ?>,
            AddressLang = <?php echo json_encode(CommonLanguage::getMessage('address')); ?>,
            CountryLang = <?php echo json_encode(CommonLanguage::getMessage('country')); ?>,
            FinancialNbLang = <?php echo json_encode(CommonLanguage::getMessage('financial_nb')); ?>,
            accountCodeLang = <?php echo json_encode(CommonLanguage::getMessage('account_code')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            account_firstLang = <?php echo json_encode(CommonLanguage::getMessage('choose_account_first')); ?>,
            supplier_firstLang = <?php echo json_encode(CommonLanguage::getMessage('choose_supplier_first')); ?>,
            customer_firstLang = <?php echo json_encode(CommonLanguage::getMessage('choose_customer_first')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>;
    var CurrencyRate = <?php echo json_encode($Extable) ?>

    var TotalInvoice = 0,
            TotalDiscount = 0,
            TotalInvoiceWithoutDiscount = 0;



    $(function () {




        $("#Product_ExpiryDate").datepicker({autoclose: true}).on("changeDate", function () {})

        $("#InventoryPurchaseTable tbody").on("click", "tr > .ExpiryDate > span.fa-plus-circle", function () {
            var me = $(this).parents("tr");

            $("#add_Expiry").modal('show')
            $("#Product_ID").val(me.attr('data-id'))
            var SEL = $("select.Material_Category_ID", me).val();
            $("#Category_ID").val(SEL)
            $("#Unit_Price").val(me.attr('Unit_Price'))
        })






        $("#Add").on("click", ".AddRow > .fa-plus-circle", function (e) {
            $(".AddRow > .fa-minus-circle").css("display", "")
            var Parent = $(this).parents("#Add").find(".AddRow:eq(0)"), NewItem = Parent.clone().insertAfter(Parent);

            NewItem.find("input").val('');
            NewItem.find("#Product_ExpiryDate").datepicker({autoclose: true})
        })
        $("#Add").on("click", ".AddRow > .fa-minus-circle", function (e) {
            $(this).closest(".AddRow").empty().remove();
            $("#Add").each(function () {
                $(".AddRow > .fa-minus-circle", $(this).parent()).css({"display": $(".AddRow", $(this).parent()).length <= 1 ? "none" : "inline-block"})
            })
        })















        $("#InvoicePaymentSetup .InputSpinner .btn").on('click', function (e) {
            e.preventDefault();
            var Input = $("input", $(this).parent().parent()), V = parseInt(Input.val())
            Input.val($(this).hasClass("more") ? V + 1 : V == 0 ? 0 : V - 1)
            UpdatePurchaseInvoiceTotalPaid()
        })
        $("#InvoicePaymentSetup").find("input.form-control").on("keyup", function () {
            UpdatePurchaseInvoiceTotalPaid()
        })
        $("#search_supplier").on("change", function () {
            if ($(this).val() == 0) {
                $("#ProdLoader > h3").empty().html(supplier_firstLang)
                $("#ProdLoader").removeClass("hideme")
                $("#InventoryPurchaseTable").addClass("hideme")
            } else
            if ($("#Account_Code").val() == 0) {
                $("#ProdLoader > h3").empty().html(account_firstLang)
            }
            //            else
            //                    if($("#Supplier_Invoice").val() == 0 && !IsSalesMode){
            //                        $("#ProdLoader > h3").empty().html("Please enter supplier invoice number.")
            //                    }
            else {
                $("#ProdLoader").addClass("hideme")
                $("#InventoryPurchaseTable").removeClass("hideme")
            }
            var Data = {
                id: $(this).val(),
                mode: 0
            }

            $.ajax({
                url: "InventoryAjax/addPurchaseAjax",
                data: Data,
                dataType: 'json',
                complete: function (v1, v2) {
                    if (v2 == "success") {
                        var Data = (v1.responseJSON);
                        console.log(Data)

                        $("#SupplierInfoContent").empty();
                        var Content = "";
                        Content += "<strong><span class='Name'>" + Data[0]['Supplier_Name'] + "</span></strong>";
                        Content += "<div><strong>" + CompanyLang + ": </strong><span class='Company'>" + Data[0]['Supplier_Company'] + "</span></div>";
                        Content += "<div><strong>" + EmailLang + ": </strong><span class='Email'>" + Data[0]['Supplier_Email'] + "</span></div>";
                        Content += "<div><strong>" + PhoneLang + ": </strong><span class='Phone'>" + Data[0]['Supplier_Phone'] + "</span></div>";
                        Content += "<div><strong>" + AddressLang + ": </strong><span class='Address'>" + Data[0]['Supplier_Address'] + "</span></div>";
                        Content += "<div><strong>" + CountryLang + ": </strong>" + Data[0]['Country_Name'] + "</div>";
                        Content += "<div><strong>" + FinancialNbLang + ": </strong>" + Data[0]['Account_Code'] + "</div>";
                        $("#SupplierInfoContent").html(Content)
                        $("#Supplier_ID-error").remove()
                        $("#Supplier_ID").removeClass("error").val(Data[0]['Supplier_ID']);


                    }
                }
            })

        })
        $("#CurrencyDropDown .dropdown-menu > li").on("click", function () {
            setTimeout(function () {
                UpdateTable()
            }, 300)
//                UpdateTable()
        })

        //        $("#Supplier_Invoice").on("keyup",function(){
        //            if($(this).val() == 0){
        //                $("#ProdLoader > h3").empty().html("Please enter supplier invoice number.")
        //                $("#ProdLoader").removeClass("hideme")
        //                $("#InventoryPurchaseTable").addClass("hideme")
        //            }else
        //                if($("#search_supplier").val() == 0){
        //                    $("#ProdLoader > h3").empty().html("Please Choose A "+(IsSalesMode ? 'Customer' : 'Supplier ')+"First.")
        //                }
        //            else{
        //                $("#ProdLoader").addClass("hideme")
        //                $("#InventoryPurchaseTable").removeClass("hideme")
        //            }
        //
        //        })

        $("#Account_Code").on("change", function () {
            var accName = $("#s2id_Account_Code a span:eq(0)").html().split('-')[0];

            $('#Account_CodeDiv').remove()
            var Content = "";
            if ($(this).val() != 0) {
                Content += "<div id='Account_CodeDiv' value='" + $(this).val() + "'><strong>" + accountCodeLang + ": </strong>" + accName + "</div>";
                $("#SupplierAccInfo").append(Content)
            }
            if ($(this).val() == 0) {
                $("#ProdLoader > h3").empty().html(account_firstLang)
                $("#ProdLoader").removeClass("hideme")
                $("#InventoryPurchaseTable").addClass("hideme")
            } else
            if ($("#search_supplier").val() == 0) {
                $("#ProdLoader > h3").empty().html(supplier_firstLang)
            }
            //            else
            //                    if($("#Supplier_Invoice").val() == 0 && !IsSalesMode){
            //                        $("#ProdLoader > h3").empty().html("Please enter supplier invoice number.")
            //                    }
            else {
                $("#ProdLoader").addClass("hideme")
                $("#InventoryPurchaseTable").removeClass("hideme")
            }

        })



        EnableAutoComplete($("#InventoryPurchaseTable .AutoComplete.CODE"));
        EnableAutoComplete($("#InventoryPurchaseTable .AutoComplete.ProductName"));
        $("#PurchaseInvoiceDueDate,#PurchaseInvoiceDate").datepicker({autoclose: true}).on("changeDate", function (e) {
            $(this).keyup();
        })
        $("#InventoryPurchaseTable").delegate(".Quantity,.UnitPrice,.Disc", "blur keyup", function (e) {
            var me = $(this), TR = me.parents("tr");
            setTimeout("UpdateTable()", 100);
            if (e.which == 13) {
                if (me.hasClass("Quantity")) {
                    TR.find(".UnitPrice").focus()
                } else if (me.hasClass("UnitPrice")) {
                    TR.find(".Disc").focus()
                } else {
                    TR.next().find(".CODE").focus()
                }
            }
            if (TR.index() < $("#InventoryPurchaseTable tbody").children().length - 1) {
                if ($.trim(me.val()).match(/^\s*?([\d]+(\.\d+)?|\.\d{1,2})\s*$/) == null) {
                    me.addClass("wrong")
                } else {
                    me.removeClass("wrong")
                }
            }

        });

        $("#InvoiceDiscountInput").on("blur keyup", function () {
            setTimeout("UpdateTable()", 100)
        })
        $("#InventoryPurchaseTable tbody").delegate("> tr input", "keydown", function (e) {
            var me = $(this)
            if (e.which == 8) {
                if (me.val() == "" && !me.hasClass("CODE")) {
                    me.parents("td").prev().find("input").focus()
                } else if (me.val() == "" && me.hasClass("CODE")) {
                    if (me.parents("tr").prev()) {
                        me.parents("tr").prev().find(".Disc").focus()
                    }
                }
            }
        })
        $("#InventoryPurchaseTable tbody").delegate("> tr input", "keyup", function (e) {
            var me = $(this), Parent = me.parents("tbody"), IsLastOneEmpty = true;
            $("tr", Parent).each(function (e) {
                if ($("tr", Parent).length > 1) {
                    var IsEmpty = true;
                    $(this).find("input").each(function () {
                        if ($(this).val() != "")
                            IsEmpty = false;
                    })
                    if (IsEmpty == true) {
                        if ($(this).index() <= $("#InventoryPurchaseTable tbody tr").length - 2) {
                            me.parents("tr").prev().find(".Disc").focus()
                            $(this).remove();
                        }
                    }
                }
            })
            $("tr:last-child input", Parent).each(function (e) {
                if ($(this).val() != "")
                    IsLastOneEmpty = false;
            })
            if (IsLastOneEmpty == false) {
                var ClonedRow = $("tr:first-child", Parent).clone()
                ClonedRow.find("input").val("")
                Parent.append(ClonedRow);
                EnableAutoComplete($(".AutoComplete.CODE", ClonedRow).removeClass("AutoAdded"));
                EnableAutoComplete($(".AutoComplete.ProductName", ClonedRow).removeClass("AutoAdded"));
                $(".Hint,.Total", ClonedRow).html("")
                $("input", ClonedRow).removeClass("wrong")
                $(".select2-container", ClonedRow).empty().remove()
                $(".Material_Category_ID", ClonedRow).show().select2()
                //ClonedSelect.find('select.Material_Category_ID option:selected').removeAttr('selected');
                //ClonedSelect.find('select.Material_Category_ID option:first').attr('selected','selected');
                //ClonedSelect.find('select.Material_Category_ID').trigger('change');
                /* ClonedRow HERE | Reset The select tag here hahah */
                UpdateTable()
                //				setTimeout("openmodal()",800)
            }
        })
        $("#CurrencyDropDown li").click(function () {
            $(".CurrencyIndicator").html($(this).attr("MySymbol"))
            setTimeout("UpdateSubmitButtonStatus()", 100)
        })
        var Def = $("#CurrencyDropDown li").filter(function () {
            return $(this).attr("value") == $("#CurrencyDropDown input").val()
        })
        if (Def.length > 0) {
            $(".CurrencyIndicator").html(Def.attr("MySymbol"))
            $("> button > span", $("#CurrencyDropDown")).html(Def.text())
        }
        $("#InvoiceForm").validate({
            ignore: ".ignore",
            rules: {
                PurchaseInvoiceDate: {required: true, date: true},
                PurchaseInvoiceDueDate: {date: true}
            }
        })
        $("#InvoiceSubmitButton").on("click", ApplyPostMethod);
        UpdateSubmitButtonStatus()
    })
    function UpdateTable() {
        var vatVal = 0, totalvat = 0, taxAmount = 0;
        TotalInvoice = TotalDiscount = TotalInvoiceWithoutDiscount = 0
        $("#InventoryPurchaseTable tr").each(function () {
            UpdateTotalForRow($(this))
        })
        var InvoiceDiscountInput = parseFloat($("#InvoiceDiscountInput").val()) || 0;
        var TotalInvoiceDisounted = TotalInvoice - (TotalInvoice * (InvoiceDiscountInput / 100))
        var SubTotalVal = TotalInvoiceWithoutDiscount * (1 - TotalDiscount / 100);
        $("#DiscountVal").html(AddCommas((TotalInvoiceWithoutDiscount - TotalInvoice).toFixed(3)))
        $("#InvoiceTotalAfterDiscount").text(AddCommas((TotalInvoiceWithoutDiscount * (InvoiceDiscountInput / 100)).toFixed(3)))
        setTimeout("UpdateSubmitButtonStatus()", 100)
        $("#InventoryPurchaseTable tbody tr").each(function () {
            var TRvalue = parseFloat($(".TotalTD .Total", $(this)).attr('myval'));
            if (TRvalue != 0) {
                //alert(TRvalue)
                if ($(this).attr('data-vat') == 1) {
                    vatVal = TRvalue * 0.1;
                    totalvat += vatVal;
                    taxAmount += TRvalue;
                    //alert(totalvat)
                    $(this).find('.VATPerItem').val(vatVal)
                    $('#PurchaseTaxableAmount').html(AddCommas(taxAmount))
                    $("#InvoiceVAT").html(AddCommas(totalvat.toFixed(3)))
                }

            }
            $("#PurchaseInvoiceTotalDetails").attr({"MyValueNotDiscounted": TotalInvoice, "MyValueDiscounted": (TotalInvoiceDisounted + totalvat)}).text(AddCommas((TotalInvoiceDisounted + totalvat).toFixed(3)))

        })
    }

    function EnableAutoComplete(who) {

        if (!who.hasClass("AutoAdded")) {
            who.autocomplete({
                source: function (request, response) {
                    var SEL = $("select.Material_Category_ID", this.element.parents("tr")).val();
                    $.getJSON('xhr/ajaxVendor?cmd=' + (who.hasClass("CODE") ? "1" : "2") + "&type=" + SEL, request, function (s, status, xhr) {
                        response(s);
                    });
                },
                minLength: 2,
                select: function (event, ui) {
                    var TR = $(this).parents("tr");
                    TR.attr("data-id", ui.item.Product_ID ? ui.item.Product_ID : ui.item.Material_ID)
                    TR.attr("data-vat", ui.item.Product_VAT ? ui.item.Product_VAT : ui.item.Material_VAT)
                    TR.attr("data-qty", ui.item.Product_Quantity ? ui.item.Product_Quantity : ui.item.Material_Quantity)
                    TR.find("input.CODE").val(ui.item.Product_Code ? ui.item.Product_Code : ui.item.Material_Code)
                    TR.find("input.ProductName").val(ui.item.Product_Name ? ui.item.Product_Name : ui.item.Material_Name)
                    //TR.find("input.UnitPrice").val(IsSalesMode ? (ui.item.Product_Price ? ui.item.Product_Price : ui.item.Material_Price ) : "")
                    TR.find("input.UnitPrice").prev().text("last cost: " + (!ui.item.LAST_COST ? "0" : ui.item.LAST_COST));
                    TR.find("input.Quantity").focus().prev().text((ui.item.Product_Quantity ? ui.item.Product_Quantity : ui.item.Material_Quantity) + " in stock")
                    return false;
                }
            }).autocomplete("instance")._resizeMenu = function (ul, items) {
                this.menu.element.outerWidth((who.width() * (this.element.hasClass("CODE") ? 1 : 2.3)) + parseFloat(who.css("padding-left")) + parseFloat(who.css("padding-right")) + 2);
            }
            who.autocomplete("instance")._renderItem = function (ul, item) {
                var MyType = this.element.hasClass("CODE") ? (item.Product_Code ? item.Product_Code : item.Material_Code) : (item.Product_Name ? item.Product_Name : item.Material_Name);
                return $("<li>").html("<table cellspacing='0' cellpadding='0'><tr><td class='OnlyText'>" + MyType + "</td></tr></table>").appendTo(ul)
            }
            who.addClass("AutoAdded")
        }
        $(document).keydown(function (e) {
            if (e.which == 8 && e.target.tagName.toLowerCase() != "input") {
                e.preventDefault()
            }
        })

    }
    function ApplyPostMethod() {
        $("#PurchaseSuccess").attr("class", "hidden");
        if ($("#InvoiceForm").valid()) {
            var IsValidated = true,
                    Data = {
                        Cash_Amount: $("#SetPaidFormTab_1 .InputSpinner > input").eq(0).val(),
                        Cash_ID: $("#SetPaidFormTab_1 .DropDownForForms > button > input").eq(0).val(),
                        Check_Amount: $("#SetPaidFormTab_2 .InputSpinner > input").eq(0).val(),
                        Check_ID: $("#SetPaidFormTab_2 .DropDownForForms > button > input").eq(0).val(),
                        Check_Num: $("#SetPaidFormTab_2 .CheckNumValue").eq(0).val(),
                        Card_Amount: $("#SetPaidFormTab_3 .InputSpinner > input").eq(0).val(),
                        Card_ID: $("#SetPaidFormTab_3 .DropDownForForms > button > input").eq(0).val(),
                        Card_Code: $("#SetPaidFormTab_3 .CardApproval").eq(0).val(),
                        Products: []

                    };



            Data.Depot_ID = $("select.Depot_Loc").val();
            Data.Supplier_Invoice_ID = $("#Supplier_Invoice").val();
            Data.Supplier_ID = $("#Supplier_ID").val();
            Data.Purchase_Date = $("#PurchaseInvoiceDate").val();
            Data.Purchase_Due_Date = $("#PurchaseInvoiceDueDate").val() ? $("#PurchaseInvoiceDueDate").val() : $("#PurchaseInvoiceDate").val();
            Data.Currency_ID = $("#CurrencyDropDown input").val();
            Data.Purchase_Discount = $("#InvoiceDiscountInput").val();
            Data.Purchase_Net_Total = $("#PurchaseInvoiceTotalDetails").attr("MyValueDiscounted");
            Data.Purchase_Sub_Total = $("#PurchaseInvoiceTotalDetails").attr("MyValueNotDiscounted");
            Data.Purchase_Paid_Amount = $("#AdvanceValue").val();
            Data.Invoice_VAT = $("#InvoiceVAT").html().replace(",", "");
            Data.Account_Code = $('#Account_CodeDiv').attr('value');




            $("#InventoryPurchaseTable tbody tr").each(function (e) {
                var me = $(this);
                if (e < $(this).parent().children().length - 1) {


                    Data.Products.push({
                        Material_Category_ID: me.find("select.Material_Category_ID").val(),
                        Product_Code: me.find(".CODE").val(),
                        Product_Name: me.find(".ProductName").val(),
                        Item_Quantity: me.find(".Quantity").val(),
                        Item_Price: me.find(".UnitPrice").val(),
                        Currency_ID: $("#CurrencyDropDown input").val(),
                        Item_Discount: me.find(".Disc").val(),
                        Product_Total_Price: me.find(".TotalTD > .Total").attr("myval")
                    });



                    me.find(".CODE,.ProductName,.Quantity,.UnitPrice").each(function () {
                        if ($.trim($(this).val()) == "" || ($(this).hasClass("isnumber") && $.trim($(this).val()).match(/^\s*?([\d]+(\.\d+)?|\.\d{1,2})\s*$/) == null)) {
                            $(this).addClass("wrong")
                            IsValidated = false;
                        } else {
                            $(this).removeClass("wrong")
                        }
                    })
                }
            })
            if (!IsValidated)
                return;
            $("#PurchaseDisabler").show();
            $.ajax({
                url: "InventoryAjax/addPurchaseAjax",
                method: "POST",
                data: Data,
                complete: function (v1, v2) {
                    if (v2 == "success") {
                        $("#PurchaseSuccess").attr("class", "alert alert-success").html(Submitted_Successfully)
                        $("#InvoiceSubmitButton").addClass("disabled", "disabled")
                    } else {
                        $("#PurchaseSuccess").attr("class", "alert alert-danger").html(Failed_Submit)
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                    $("#PurchaseDisabler").hide();
                }
            })
        } else {
            $(document.body).animate({scrollTop: 0}, 800)
        }
    }
    function UpdateTotalForRow(who) {
        var Single_Price = parseFloat(who.find(".UnitPrice").val()) || 0,
                Qty = parseFloat(who.find(".Quantity").val()) || 0,
                Total = Single_Price * Qty,
//			final_Total           = Single_Price * Qty,
                Discount = parseFloat(who.find(".Disc").val()) || 0,
                Net_Total = (Total * (1 - Discount / 100)) || 0;
//         console.log(Total)
//                       var Net_Total = ConvertCurrency2(final_row_total,$("#Class_Currency").text(),$("#CurrencyDropDown input").val());
        TotalInvoiceWithoutDiscount += Total;
        TotalDiscount += Discount
        TotalInvoice += Net_Total
        who.find(".Total").attr("MyVal", Net_Total.toFixed(3)).text(AddCommas(Net_Total.toFixed(3)))
        who.attr('Unit_Price', Single_Price)
    }
    function UpdateSubmitButtonStatus() {
        var Rows = $("#InventoryPurchaseTable tbody tr"), DoDisable = false
        if (Rows.length > 0) {
            if (Rows.length == 1) {
                if ($.trim($("input.CODE", Rows).val()) != "" && $.trim($("input.ProductName", Rows).val()) != "" && $.trim($("input.Quantity", Rows).val()) != "" && $.trim($("input.UnitPrice", Rows).val()) != "") {
                    DoDisable = false;
                } else {
                    DoDisable = true;
                }
            } else {
                DoDisable = false;
            }
        } else {
            DoDisable = true;
        }
        if ($.trim($("#CurrencyDropDown > button > input").val()) == "")
            DoDisable = true;
        if (parseFloat($("#PurchaseInvoiceTotalPaid").html().replace(",", "")) > parseFloat($("#PurchaseInvoiceTotalDetails").html().replace(",", "")))
            DoDisable = true;

        // document.title = Rows.length
        if (DoDisable) {
            $("#InvoiceSubmitButton").addClass("disabled")
        } else {
            $("#InvoiceSubmitButton").removeClass("disabled")
        }
    }
    function InputMustBeAtleastN(who, N) {
        if (parseInt(who.value) < N || !parseInt(who.value))
            who.value = N;
        UpdatePurchaseInvoiceTotalPaid();
    }
    function UpdatePurchaseInvoiceTotalPaid() {
        var A1 = parseFloat($("#SetPaidFormTab_1 .InputSpinner > input").eq(0).val()) || 0,
                A2 = parseFloat($("#SetPaidFormTab_2 .InputSpinner > input").eq(0).val()) || 0,
                A3 = parseFloat($("#SetPaidFormTab_3 .InputSpinner > input").eq(0).val()) || 0;
        $("#PurchaseInvoiceTotalPaid").text(AddCommas(A1 + A2 + A3));
        UpdateSubmitButtonStatus();
        console.log(A1 + A2 + A3)
        console.log(parseFloat($("#PurchaseInvoiceTotalDetails").attr("myvaluediscounted")))
        if ((A1 + A2 + A3) >= parseFloat($("#PurchaseInvoiceTotalDetails").attr("myvaluediscounted")))
            $("#PurchaseInvoiceDueDate").removeAttr("required")
        else
            $("#PurchaseInvoiceDueDate").attr("required", "required")

    }







    $("#SubmitExpiry").on("click", function () {


        var Data = {
            Product_ID: $("#Product_ID").val(),
            type: 1,
            Unit_Cost: $("#Unit_Price").val(),
            Depot_ID: $("select.Depot_Loc").val(),
            Category_ID: $("#Category_ID").val(),
            Currency_ID: $("#CurrencyDropDown input").val(),
            Expiry: []
        }

        $("#Add > .AddRow").each(function () {
            var me = $(this);
            Data.Expiry.push({
                Expiry_Date: me.find(".Product_ExpiryDate").val(),
                Product_Quantity: me.find(".Product_Quantity").val()

            })


        })

        $.ajax({
            url: "InventoryAjax/addPurchaseAjax",
            method: "POST",
            data: Data,
            complete: function (v1, v2) {
                if (v2 == "success" && v1.responseText == "OK") {


                    $("#ExpirySuccess").attr("class", "alert alert-success").html(Submitted_Successfully)

                    setTimeout(function () {
                        $("#add_Expiry").modal('hide')
                        $("#ExpirySuccess").addClass('hidden')
                        $('.AddRow').not('div:first').remove()
                        $('.AddRow > .fa-minus-circle').not('div:first').css("display", "none")
                    }, 800)


                } else {
                    $("#ExpirySuccess").attr("class", "alert alert-danger").html(Failed_Submit)
                }

            }
        })
        $('#Add  input').val('')



    })


    $("#Closemodal").on("click", function () {
        $('#add_Expiry').modal('hide')
        $('.AddRow').not('div:first').remove()
        $('.AddRow > .fa-minus-circle').not('div:first').css("display", "none")
        $('#Add  input').val('')



    })




</script>


