<style>

</style>
<div id="addproduct" style="display:none"> {foreach $productData as $product}
    <option value="{$product->productid}">{$product->productName}</option>
    {/foreach}
</div>
<div id="imageClose" style="display:none"> <img alt="" src="{$path}/images/close.png" /> </div>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">المخازن</a></li>
            <li><a href="storemovementController.php?do=show">التحويل بين المخازن</a></li>
            <li class="active">اضافة تحويل</li>
        </ol>
        <h3>اضافة تحويل بين المخازن</h3>
        <hr />
        <form class="form-horizontal " role="form" action="storemovementController.php?do=add" method="post"
            id="sellbillForm">
            <div class="row">
                <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsettingdata->searchvalue}" />
                <!---onChange="loadStoreTo(this.value);"-->

                <div class="{if $Programsettingdata->storeserial eq 0} hidden {/if}">
                    <label style="margin-right: -17;" class="col-lg-2 "> رقم ايصال التحويل</label> <span
                        style="margin-right: 23px;">
                        <input style="margin-bottom: 7px;" class="positiveNo" type="text" name="operationnum"
                            id="operationnum" value="{$nextId}" {if $Programsettingdata->operationnumEdit ==
                        1}readonly{/if}/></span>
                </div>
                <div id="opNoError" style="display:none;"></div>
                <!-- =================================================   -->
                <!--                <div class="form-group" style="display: none;">
                                    <label class="col-lg-2 control-label">الرقم التسلسلي</label>
                                    <div class="col-lg-3">
                                        <input type="text" disabled class="form-control wdt300" value="{$nextId}"/>
                                    </div>
                                </div>-->

                <!-- =================================================   -->

                {if $searchinonestore neq 0}
                <div class="form-group">
                    <label class="col-lg-2 control-label">من المخزن</label>
                    <div class="col-lg-8"> <span id="spryselect1">
                            <input type="hidden" name="storeidfrom" id="storeidfrom" value="{$manyParcodesstoreidfrom}">
                            {$store->storeName}
                    </div>
                </div>
                {else}

                <div class="form-group">
                    <label class="col-lg-2 control-label">من المخزن</label>
                    <div class="col-lg-8"> <span id="spryselect1">
                            <select class="select2 wdt300" name="storeidfrom" id="storeidfrom"
                                onChange="loadStoreTo(this.value);">
                                <option value="-1">اختر مخزن</option>
                                {foreach $stores as $store}
                                <option value="{$store->storeId}" {if ($manyParcodes==1 &&
                                    $manyParcodesstoreidfrom==$store->storeId) || ( $manyParcodes !=1 && $userDefStore ==
                                    $store->storeId)}
                                    selected="selected" {/if}>{$store->storeName}</option>
                                {/foreach}
                            </select>
                            <span class="selectInvalidMsg">*</span></span>
                    </div>
                </div>
                {/if}
                <div class="form-group storeTo">
                    <label class="col-lg-2 control-label">إلى المخزن</label>
                    <div class="col-lg-8">
                        <select class="select2 wdt300" name="storeidto" id="storeidto">
                            <option value="-1">اختر مخزن</option>
                            {*if $manyParcodes == 1*}
                            {foreach $storeData as $store}


                            {if ($manyParcodes == 1 && $manyParcodesstoreidfrom != $store->storeId) || $userDefStore !=
                            $store->storeId}
                            <option value="{$store->storeId}" {if $manyParcodesstoreidto==$store->storeId}
                                selected="selected" {/if}>{$store->storeName}</option>
                            {/if}



                            {/foreach}
                            {*/if*}
                        </select>
                    </div>
                </div>
                <div class="form-group {if $usergroupdata->storeSupervisorShow == 0} hidden {/if}">
                    <label class="col-lg-2 control-label">التحويل </label>
                    <div class="col-lg-8">
                        <div class="radio-inline">
                            <label>
                                <input value="0" class="radioR" name="recieveType" type="radio" {if
                                    $Programsettingdata->storeRecieveType == 0}checked="checked"{/if}>
                                مباشر </label>
                        </div>
                        <div class="radio-inline">
                            <label>
                                <input value="1" class="radioR" name="recieveType" type="radio" {if
                                    $Programsettingdata->storeRecieveType == 1}checked="checked"{/if}>
                                عن طريق مخزن وسيط </label>
                        </div>
                    </div>
                </div>
                {if $Programsettingdata->workerbetweenstores == 0}
                <div class="form-group">
                    <label class="col-lg-2 control-label">السائق</label>
                    <div class="col-lg-8">
                        <select class="select2 wdt300 checkme" id="driver" name="driver">
                            <option value="-1"></option>
                            {foreach $drivers as $data}
                            <option value="{$data->userid}">{$data->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">مدة انجاز السائق بالساعة</label>
                    <div class="col-lg-8">
                        <input type="text" class="form-control positiveNo checkme" name="drivertimeout"
                            id="drivertimeout" value="{$Programsettingdata->drivertimeout}">
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    {$whatPrice}
                    <label class="col-lg-2 control-label">اظهر سعر </label>
                    <div class="col-lg-8">
                        <div class="radio-inline">
                            <label>
                                <input value="hide" class="radioR whatPrice" name="whatPrice" id="whatPrice0"
                                    type="radio" {if $manyParcodes==1 && $manyParcodeswhatPrice=="hide" }
                                    checked="checked" {elseif $manyParcodes !=1} checked="checked" {/if}>
                                بدون </label>
                        </div>
                        {if $usergroupdata->showBuyPrice eq 0}
                        <div class="radio-inline">
                            <label>
                                <input value="productBuyPrice" class="radioR whatPrice" name="whatPrice" id="whatPrice1"
                                    type="radio" {if $manyParcodes==1 && $manyParcodeswhatPrice=="productBuyPrice" }
                                    checked="checked" {/if}>
                                الشراء </label>
                        </div>
                        {/if}
                        {if $usergroupdata->showSellAllPrice eq 0}
                        <div class="radio-inline">
                            <label>
                                <input value="productSellAllPrice" class="radioR whatPrice" name="whatPrice"
                                    id="whatPrice2" type="radio" {if $manyParcodes==1 &&
                                    $manyParcodeswhatPrice=="productSellAllPrice" } checked="checked" {/if}>
                                جملة </label>
                        </div>
                        {/if}
                        {if $usergroupdata->showSellHalfPrice eq 0}
                        <div class="radio-inline">
                            <label>
                                <input value="productSellHalfPrice" class="radioR whatPrice" name="whatPrice"
                                    id="whatPrice3" type="radio" {if $manyParcodes==1 &&
                                    $manyParcodeswhatPrice=="productSellHalfPrice" } checked="checked" {/if}>
                                نص جملة </label>
                        </div>
                        {/if}
                        {if $usergroupdata->showSellUnitPrice eq 0}
                        <div class="radio-inline">
                            <label>
                                <input value="productSellUnitPrice" class="radioR whatPrice" name="whatPrice"
                                    id="whatPrice4" type="radio" {if $manyParcodes==1 &&
                                    $manyParcodeswhatPrice=="productSellUnitPrice" } checked="checked" {/if}>
                                قطاعى </label>
                        </div>
                        {/if}

                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-lg-2 control-label">تعليق</label>
                    <div class="col-lg-4">
                        <textarea name="comment" id="comment" rows="3" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            <!-- end of frist row-->
            <input name="storenegative" type="hidden" value="{$storenegative}" id="storenegative" />
            <div class="row">
                <div class="row">
                    <hr />
                    <div class="col-lg-6">
                        <h4>المنتجات</h4>
                    </div>
                    <div class="col-lg-6  hidden-print">
                        <button type="button" name="addpro" id="addpro" class="btn btn-primary pull-left ft-nor"> اضافة
                            جديد</button>
                        {if $manyParcodes != 1}
                        <button type="button" name="addManyParcodes" id="addManyParcodes"
                            class="btn btn-success pull-left ft-nor" style="margin-left:3px;"> اضافة بالباركود
                            المجمع</button>
                        {/if}
                    </div>
                </div>
                <!-- end of title row-->
                <div class="table-responsive">
                    <table class="table billtable table-bordered table-black " id="containerpros">
                        <thead>
                            <tr>
                                <th class="wdt200">رقم</th>
                                <th class="wdt120 check_tr {if {$Programsettingdata->parcode} eq 1} hidden {/if}">
                                    الباركود</th>
                                <th class="wdt400">اسم المنتج</th>
                                <th class="wdt200">الكمية الحالية</th>
                                <th class="wdt200">الكمية المحولة</th>
                                <th class="wdt200 pricesClass" {if ($manyParcodes==1&&$manyParcodeswhatPrice=="hide"
                                    )||$manyParcodes!=1}style="display:none" {/if}>السعر</th>
                                <th class="wdt200 pricesClass" {if ($manyParcodes==1&&$manyParcodeswhatPrice=="hide"
                                    )||$manyParcodes!=1}style="display:none" {/if}>السعر الاجمالي</th>
                                <th
                                    class="wdt200 ck_expireDate {if {$Programsettingdata->expiredate} eq 1}  hidden {/if}">
                                    ت الصلاحية</th>
                                <th class="wdt200 ck_comment">تعليق</th>
                                <th class="hidden-print">حذف</th>
                            </tr>
                        </thead>
                        <tbody>
                            {if $manyParcodes == 1 && $products_ordered}

                            {assign var=total_quantity value=0}
                            {assign var=total_Price value=0}
                            {assign var=i value=1}
                            {foreach $products_ordered as $pro}
                            <tr>
                                <td>{$i}</td>
                                <td class=" check_tr {if {$Programsettingdata->parcode} eq 1} hidden {/if}">
                                    <input type="text" name="parcode{$i}" id="parcode{$i}" class="form-control parcode"
                                        value="{$pro->parcode}" />
                                </td>
                                <td>
                                    <div id="myproductselect">
                                        <input type="hidden" class="select2product wdt400 myproduct" data-itr="{$i}"
                                            name="product{$i}" id="product{$i}" data-placeholder="اختر منتج" />
                                        <input type="hidden" name="oldproductname{$i}" id="oldproductname{$i}"
                                            value="{$pro->productName}" />
                                        <input type="hidden" name="oldproductid{$i}" id="oldproductid{$i}"
                                            value="{$pro->productId}" />
                                    </div>
                                    <!--
                                        <select class="select2 wdt100" id="productid1" name="productid1" tabindex="7" onchange="getProductQuantity(this.value,1);" onblur="anotherProduct(this.value,1);" >


                                       </select>
                                    -->

                                </td>
                                <td>
                                    <div id="quantity1">
                                        <input type="text" name="currentquantity{$i}" id="currentquantity{$i}"
                                            class="form-control getprototal  positiveNo txt-nonraduis"
                                            value="{$pro->currentQuantity}" tabindex="7" readonly />
                                    </div>
                                </td>
                                <td>
                                    <input type="text" name="productamount{$i}" onkeyup="checkdata({$i})"
                                        id="productamount{$i}"
                                        class="form-control getprototal  positivefloat txt-nonraduis"
                                        value="{$pro->quantityMovement}" tabindex="7" />
                                </td>
                                <td class="pricesClass" {if ($manyParcodes==1&&$manyParcodeswhatPrice=="hide"
                                    )||$manyParcodes!=1}style="display:none" {/if}>
                                    <input type="text" name="pricePro{$i}" id="pricePro{$i}"
                                        class="form-control txt-nonraduis" value="{$pro->choosenPrice}" tabindex="7"
                                        readonly />
                                </td>
                                <td class="pricesClass" {if ($manyParcodes==1&&$manyParcodeswhatPrice=="hide"
                                    )||$manyParcodes!=1}style="display:none" {/if}>
                                    <input type="text" name="price{$i}" id="price{$i}"
                                        class="form-control txt-nonraduis getPriceTotal" value="{$pro->choosenPrice}"
                                        tabindex="7" readonly />
                                    <input type="hidden" name="productBuyPrice{$i}" id="productBuyPrice{$i}"
                                        value="{$pro->productBuyPrice}" />
                                    <input type="hidden" name="productSellAllPrice{$i}" id="productSellAllPrice{$i}"
                                        value="{$pro->productSellAllPrice}" />
                                    <input type="hidden" name="productSellHalfPrice{$i}" id="productSellHalfPrice{$i}"
                                        value="{$pro->productSellHalfPrice}" />
                                    <input type="hidden" name="productSellUnitPrice{$i}" id="productSellUnitPrice{$i}"
                                        value="{$pro->productSellUnitPrice}" />
                                </td>

                                <!-- onkeyup="checkquantity(1);"-->
                                <td class="{if {$Programsettingdata->expiredate} eq 1}  hidden {/if}">
                                    <input type="hidden" name="proSerials{$i}" id="proSerials{$i}" data-itr="{$i}"
                                        value="">
                                </td>
                                <td class="{if {$Programsettingdata->expiredate} eq 1}  hidden {/if}">
                                    <input type="hidden" name="proSerials{$i}" id="proSerials{$i}" data-itr="{$i}"
                                        value="">
                                </td>
                                <td>
                                    <textarea name="comment{$i}" id="comment{$i}" class="form-control"
                                        style="height: 25px;">{$pro->productDescription}</textarea>
                                </td>
                                <td id="{$i}" class="hidden-print">
                                    <button id="remove{$i}" type="button"
                                        class="close flt-none removeicon removeproduct"
                                        aria-hidden="true">&times;</button>
                                </td>
                            </tr>
                            {assign var=total_quantity value=$total_quantity+$pro->quantityMovement}
                            {assign var=total_Price value=$total_Price+$pro->choosenPrice}
                            {assign var=i value=$i+1}
                            {/foreach}

                            <input type="hidden" name="productitr" id="productitr" value="{$i}" />

                            {else}


                            <tr>
                                <td>1</td>
                                <td class=" check_tr {if {$Programsettingdata->parcode} eq 1} hidden {/if}">
                                    <input type="text" name="parcode1" id="parcode1" class="form-control parcode"
                                        value="" />
                                </td>
                                <td>
                                    <div id="myproductselect">
                                        <input type="hidden" class="select2product wdt400 myproduct" data-itr="1"
                                            name="product1" id="product1" data-placeholder="اختر منتج" />
                                    </div>
                                    <!--
                                    <select class="select2 wdt100" id="productid1" name="productid1" tabindex="7" onchange="getProductQuantity(this.value,1);" onblur="anotherProduct(this.value,1);" >


                                   </select>
                                -->

                                </td>
                                <td>
                                    <div id="quantity1">
                                        <input type="text" name="currentquantity1" id="currentquantity1"
                                            class="form-control getprototal  positiveNo txt-nonraduis" value="0"
                                            tabindex="7" readonly />
                                    </div>
                                </td>
                                <td>
                                    <input type="text" name="productamount1" onkeyup="checkdata(1)" id="productamount1"
                                        class="form-control getprototal  positivefloat txt-nonraduis" value="0"
                                        tabindex="7" />
                                </td>
                                <td class="pricesClass" style="display:none">
                                    <input type="text" name="pricePro1" id="pricePro1"
                                        class="form-control txt-nonraduis" value="0" tabindex="7" readonly />
                                </td>
                                <td class="pricesClass" style="display:none">
                                    <input type="text" name="price1" id="price1"
                                        class="form-control txt-nonraduis getPriceTotal" value="0" tabindex="7"
                                        readonly />
                                    <input type="hidden" name="productBuyPrice1" id="productBuyPrice1" value="0" />
                                    <input type="hidden" name="productSellAllPrice1" id="productSellAllPrice1"
                                        value="0" />
                                    <input type="hidden" name="productSellHalfPrice1" id="productSellHalfPrice1"
                                        value="0" />
                                    <input type="hidden" name="productSellUnitPrice1" id="productSellUnitPrice1"
                                        value="0" />
                                </td>

                                <!-- onkeyup="checkquantity(1);"-->
                                <td class="{if {$Programsettingdata->expiredate} eq 1}  hidden {/if}">
                                    <input type="hidden" name="proSerials1" id="proSerials1" data-itr="1" value="">
                                </td>
                                <td>
                                    <textarea name="comment1" id="comment1" class="form-control"
                                        style="height: 25px;"></textarea>
                                </td>
                                <td id="1" class="hidden-print">
                                    <button id="remove1" type="button" class="close flt-none removeicon removeproduct"
                                        aria-hidden="true">&times;</button>
                                </td>
                            </tr>
                            <input type="hidden" name="productitr" id="productitr" value="1" />
                            {/if}

                        </tbody>
                    </table>
                    <button type="button" class="btn btn-primary pull-left ft-nor">
                        اجمالى الكمية المحولة <span class="badge wht-clo">
                            <div id="totalQuantityMove">{if $manyParcodes == 1}{$total_quantity}{else}0{/if}</div>
                        </span>
                    </button>
                    <button type="button" class="btn btn-primary pull-left ft-nor pricesClass" {if
                        ($manyParcodes==1&&$manyParcodeswhatPrice=="hide"
                        )||$manyParcodes!=1}style="display:none;margin-left: 3px;" {else}style="margin-left: 3px;"
                        {/if}>
                        اجمالى السعر<span class="badge wht-clo">
                            <div id="totalQuantityMovePrice">{if $manyParcodes == 1}{$total_Price}{else}0{/if}</div>
                        </span>
                    </button>
                </div>
            </div>

            <!-- end of second row-->
            <input type="hidden" name="add_print" id="add_print" value="0" />

            <br />
            <div class="row  hidden-print">
                <button type="button" id="saveBtn" class="btn btn-primary">حفظ</button>
                <button type="button" id="add_print_btn" class="btn btn-success">حفظ وطباعة بإذن</button>
                <button type="button" id="add_print_btn2" class="btn btn-success">حفظ وطباعة </button>
                <button type="button" id="saveBtn_allStoreProducts" class="btn btn-danger" style="float: left">تحويل
                    جميع منتجات المخزن</button>
            </div>
            <!-- end of fifth row-->

        </form>
    </div>
    <!-- end of container-->
</div>

<input type="hidden" name="sumSameProductForStore" id="sumSameProductForStore"
    value="{$Programsettingdata->sumSameProductForStore}" />
<input type="hidden" name="showStoreToDetail" id="showStoreToDetail" value="{$Programsettingdata->showStoreToDetail}" />



<!------------------------Client Model----------------------------->
<!-- Modal -->
<div class="modal fade" id="myModalManyParcodes" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-modal">
            <div class="modal-header">
                <button type="button" class="close pull-left savemodel2" data-dismiss="modal"
                    aria-hidden="true">&times;</button>
                <h4 class="modal-title">اضافة منتجات بالباركود المجمع</h4>
            </div>
            <div class="modal-body">
                <form id="manyParcodesForm" action="storemovementController.php?do=addManyParcodes" method="post"
                    class="form-horizontal">
                    <div class="form-group">
                        <label for="debtLimit" class="col-lg-3 control-label">الباركودات مجمعة</label>
                        <div class="col-lg-9">
                            <textarea name="manyParcodes" class="form-control" style="background: url(http://i.imgur.com/2cOaJ.png);
                                      background-attachment: local;
                                      background-repeat: no-repeat;
                                      padding-left: 35px;
                                      padding-top: 10px;
                                      text-align: left !important;
                                      border-color:#ccc;
                                      direction: ltr;" id="manyParcodes" rows="5"></textarea>

                        </div>
                        <div id='hazemc'>1</div>
                    </div>
                    <input type="hidden" name="manyParcodesstoreidfrom" id="manyParcodesstoreidfrom" value="" />
                    <input type="hidden" name="manyParcodesstoreidto" id="manyParcodesstoreidto" value="" />
                    <input type="hidden" name="manyParcodeswhatPrice" id="manyParcodeswhatPrice" value="" />
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default savemodel2" data-dismiss="modal">الغاء</button>
                <button type="button" class="btn btn-primary" id="doAddManyParcodes">تم</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->



<!------------------------Client Model----------------------------->
<!-- Modal -->
<div class="modal fade" id="storeDescriptionMoal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-modal">
            <div class="modal-header">
                <button type="button" class="close pull-left savemodel2" data-dismiss="modal"
                    aria-hidden="true">&times;</button>
                <h4 class="modal-title"> مخزن الى</h4>
            </div>
            <div class="modal-body">
                <form id="manyParcodesForm" action="" method="post" class="form-horizontal">
                    <div class="form-group">
                        <label for="debtLimit" class="col-lg-3 control-label">وصف المخزن</label>
                        <div class="col-lg-9">
                            <textarea class="form-control" rows="5" id="storeDescriptionMoalText" readonly></textarea>

                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default savemodel2" data-dismiss="modal">اغلاق</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

{literal}
<script type="text/javascript">
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", { isRequired: false, invalidValue: "-1" });
    $(document).on('click', "#addManyParcodes", function () {
        if ($('#storeidfrom').val() == "-1" || $('#storeidto').val() == "-1") {
            alert('اختر المخازن اولا');
        } else {
            $('#myModalManyParcodes').modal('show');
            setTimeout(function () {
                $('#manyParcodes').focus();
            }, 800);
        }
    });
    $(document).on('click', "#doAddManyParcodes", function () {
        if ($('#manyParcodes').val() != '') {
            $('#manyParcodesstoreidfrom').val($('#storeidfrom').val());
            $('#manyParcodesstoreidto').val($('#storeidto').val());
            $('#manyParcodeswhatPrice').val($("input[name=whatPrice]:checked").val());
            $('#manyParcodesForm').submit();
        } else {
            alert('عفوا لم تدخل اى باركود');
        }

    });
    $(document).on('change', "#storeidto", function () {
        var showStoreToDetail = $('#showStoreToDetail').val();
        if (Number($(this).val()) > 0 && showStoreToDetail == 1) {
            $('#storeDescriptionMoalText').html($("#storeidto option:selected").data('description'));
            $('#storeDescriptionMoal').modal('show');
        }
    });
</script>
{/literal}