<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="#">الأصول</a></li>
            <li class="active">تعديل أصل</li>
        </ol>
        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <h3 class="panel-title">تعديل أصل</h3>
            </div>
            <div class="panel-body"> {literal}
                <form id="spform" class="nameToBeChecked form-horizontal" action="assetController.php?do=update"
                    method="post">
                    <!--validate the form before checking name-->
                    {/literal}
                    <div class="form-group">
                        <label class="col-lg-2 control-label">إسم الأصل</label>
                        <div class="col-lg-4">
                            <input type="text" name="assetname" id="assetname" class="form-control"
                                value="{$loadData->assetsName}" />

                            <!----------- start nameError alert -------------->
                            <div id="nameError" style="display:none">

                            </div>
                            <!----------- end nameError alert ------------->

                        </div>
                    </div>

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


                    <div class="form-group">
                        <label class="col-lg-2 control-label">تصنيع </label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="1" class="radioR" name="manufacture" {if {$loadData->manufacture} eq
                                    1} checked="checked" {/if} type="radio" />

                                    نعم </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="0" class="noradioR" name="manufacture" {if {$loadData->manufacture} eq
                                    0} checked="checked" {/if} type="radio" />
                                    لا </label>
                            </div>

                        </div>
                    </div>


                    <!--==============================-->
                    <input type="hidden" name="assetId" id="assetId" value="{$loadData->assetId}" />
                    <input type="hidden" name="type" value="{$loadData->type}" />
                    <input type="hidden" name="today" value="{$loadData->currentdate}" />
                    <div class="form-group">
                        <label class="col-lg-2 control-label">نوع الأصل</label>
                        <div class="col-lg-4"> <span id="spryselect2">
                                <select id="assetscatid" name="assetscatid" data-placeholder="اختر"
                                    class="select2 wdt100">
                                    <option value="-1"></option>



                                    {foreach $allctadata as $mycat}



                                    <option {if {$loadData->assetscatid} eq {$mycat->assetscatid}}selected="selected"
                                        {/if} value="{$mycat->assetscatid}">{$mycat->cattitel}</option>



                                    {/foreach}




                                </select>
                                <span class="selectRequiredMsg">اختر نوع.</span><span class="selectInvalidMsg">اختر نوع
                                    الاصل.</span></span> </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">سعر الأصل</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <span id="sprytextfield1">
                                    <input type="text" readonly="readonly" name="assetprice"
                                        value="{$loadData->assetsValue}" class="form-control numberinput" />
                                    <span class="textfieldRequiredMsg">ادخل السعر</span><span
                                        class="textfieldInvalidFormatMsg">ادخل القيمة صحيحة</span></span>

                                <span class="input-group-addon">{$currency}</span>
                            </div>
                        </div>

                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">نسبة الإهلاك</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <span id="sprytextfield3">
                                    <input type="text" name="assetsDepreciation" value="{$loadData->assetsDepreciation}"
                                        class="positivefloat form-control" />
                                    <span class="textfieldRequiredMsg">***.</span><span
                                        class="textfieldInvalidFormatMsg">ادخل رقم مناسب.</span><span
                                        class="textfieldMaxValueMsg"> ادخل رقم من 0 الى 100</span><span
                                        class="textfieldMinValueMsg"> ادخل رقم من 0 الى 100</span></span>
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">مجمع الإهلاك</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <span id="sprytextfield4">
                                    <input type="text" name="depreciation" value="{$loadData->depreciation}"
                                        class="form-control positivefloat" />
                                    <span class="textfieldRequiredMsg">ادخل القيمه.</span><span
                                        class="textfieldInvalidFormatMsg">من فضلك ادخل قيمه صحيحه.</span></span>
                                <span class="input-group-addon">{$currency}</span>
                            </div>

                        </div>
                    </div>

                    <!--==============================-->
                    <div class="form-group">
                        <label class="col-lg-2 control-label"> سعر الساعة </label>
                        <div class="col-lg-4">
                            <div class="input-group"> <span id="sprytextfield6">
                                    <input type="text" name="Hourlyrate" class="positivefloat form-control"
                                        value="{$loadData->Hourlyrate}" />
                                    <span class="textfieldRequiredMsg">ادخل القيمه.</span><span
                                        class="textfieldInvalidFormatMsg">من فضلك ادخل قيمه صحيحه.</span></span> <span
                                    class="input-group-addon">{$currency}</span> </div>
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">وصف الأصل</label>
                        <div class="col-lg-4">
                            <textarea name="assetsDescription" cols="45" rows="5"
                                class="form-control">{$loadData->assetsDescription}</textarea>
                        </div>
                    </div>

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

                    <input type="hidden" value="{$loadData->dailyentryid}" name="dailyentryid" />

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

                    {if {$type} eq "1"}
                    <div class="form-group" id="checkdata2">
                        <label class="col-lg-2 control-label">الخزنة</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100 clientstore" name="saveid" id="saveid">

                                {foreach $savedata as $save}
                                <option value="{$save->saveid}" {if $save->saveid eq $loadData->saveid} selected
                                    {/if}>{$save->savename} / {$save->savecurrentvalue}</option>

                                {/foreach}
                            </select>
                        </div>
                    </div>


                    {elseif $type eq 2}
                    <div class="form-group">
                        <label class="col-lg-2 control-label">إسم البنك</label>
                        <div class="col-lg-4">
                            <div id="bankdiv">
                                <input name="checkwithdrawalid" type="hidden" value="{$showData->checkwithdrawalid}" />
                                <input type="text" name="ddlBank" id="ddlBank" disabled value="{$showData->bankname}"
                                    class=" form-control ">
                                <input type="hidden" id="bankid" value="{$showData->bankid}" />
                                <input type="hidden" id="bankname" value="{$showData->bankname}" />
                            </div>
                        </div>
                    </div>
                    <!--==============================-->

                    <div class="form-group">
                        <label class="col-lg-2 control-label">إسم الحساب </label>
                        <div class="col-lg-4">
                            <input type="text" name="ddlAccount" id="ddlAccount" disabled
                                value="{$showData->accountname} " class=" form-control ">
                            <input type="hidden" id="accountid" value="{$showData->accountid}" />
                            <input type="hidden" id="accountname" value="{$showData->accountname}" />
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">رقم الحساب</label>
                        <div class="col-lg-4"> <span id="sprytextfield1">

                                <input type="text" name="txtAccountNum" id="txtAccountNum" disabled
                                    value="{$showData->accountnumber} " class="positiveNo form-control ">
                                <input type="hidden" id="accountnumber" value="{$showData->accountnumber}" />
                                <span class="textfieldRequiredMsg">*</span></span> </div>
                    </div>

                    <!--==============================-->
                    <div class="form-group">
                        <label class="col-lg-2 control-label">رصيد سابق</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <span id="sprytextfield2">

                                    <input type="text" name="txtPreviousAccount" id="txtPreviousAccount"
                                        value="{$showData->accountbeforevalue}" disabled class="form-control ">
                                    <input type="hidden" id="accountbeginingbalance"
                                        value="{$showData->accountbeginingbalance}" />
                                    <span class="textfieldRequiredMsg">*</span><span
                                        class="textfieldInvalidFormatMsg">يرجى إدخال قيمة صحيحة</span></span>

                                <span class="input-group-addon">{$currency}</span>
                            </div>
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">رقم الشيك</label>
                        <div class="col-lg-4">

                            <input type="text" name="txtcheckNum" id="txtcheckNum"
                                value="{$showData->checkwithdrawalnumber}" disabled class="form-control ">
                            <input type="hidden" id="checkwithdrawalnumber"
                                value="{$showData->checkwithdrawalnumber}" />


                        </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">إسم المستفيد</label>
                        <div class="col-lg-4">
                            <input type="text" name="txtUser" id="txtUser" class="form-control "
                                value="{$showData->checkwithdrawaluser}">
                        </div>
                    </div>
                    <!--==============================-->

                    <div class="form-group">
                        <label class="col-lg-2 control-label">المبلغ المدفوع</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <span id="sprytextfield4">
                                    <input type="text" name="text1" id="text1"
                                        value="{$showData->checkwithdrawalamount}" disabled class="form-control " />
                                    <input type="hidden" id="checkwithdrawalamount"
                                        value="{$showData->checkwithdrawalamount}" />
                                    <span class="textfieldRequiredMsg">*</span><span
                                        class="textfieldInvalidFormatMsg">يرجى إدخال قيمة صحيحة</span></span>

                                <span class="input-group-addon">{$currency}</span>
                            </div>

                        </div>
                    </div>

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

                    <div class="form-group">
                        <label class="col-lg-2 control-label">تفاصيل أخرى</label>
                        <div class="col-lg-4">
                            <textarea name="textNote" id="textNote" cols="45" rows="5"
                                class="form-control ">{$showData ->checkwithdrawalnote}</textarea>
                        </div>
                    </div>

                    <!--==============================-->
                    {elseif $type eq 3}
                    <!--====================Start supllier div==========================-->
                    <div class="form-group" id="checkdata3">
                        <label class="col-lg-2 control-label">المورد</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100 clientstore" name="supplierid" id="supplierid">
                                <option value="-1">اختر مورد</option>
                                {foreach $allSuppliers as $data}
                                <option value="{$data->supplierid}" data-val="{$data->suppliercurrentDebt}" 
                                    {if $loadData->saveid eq $data->supplierid} selected {/if}>
                                    {$data->suppliername} / {$data->suppliercurrentDebt}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <!--====================End supllier div==========================-->
                    {/if}
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="reset" class="btn btn-danger pull-left">إلغاء</button>
                            <button type="button" id="spbutton" class="btn btn-primary pull-left">تعديل</button>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </form>
            </div>


        </div>


    </div>
    <!--panel-body-->
</div>
<!--panel-->

<!--container-->

<!--row-->
{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "real");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "integer", { isRequired: false, invalidValue: "-1", minValue: "0", maxValue: "100" });




    $('#spbutton').live('click', function (e) {
        //ckeck name
        var tableName = 'assets';
        var inputName = 'assetname';
        var name = $("#" + inputName).val();
        var id = $("#assetId").val();
        $.ajax({
            url: 'checkRedundantNames.php?do=checkNameWithId&name=' + name + '&id=' + id + '&tablename=' + tableName,
            success: function (data) {
                //alert(data);
                if (data == '0') {
                    $("#nameError").css("display", "none");
                    var myForm = document.getElementById("spform");
                    var SS = Spry.Widget.Form.validate(myForm);
                    if (SS == true) {
                        if (!$('#spbutton').hasClass("processing")) {
                            $('#spbutton').addClass("processing");
                            myForm.submit();
                            //$('#spbutton').unbind('click');
                        }
                    }

                }
                else if (data == '1') {
                    $("#" + inputName).val("");
                    $("#" + inputName).focus();
                    $("#nameError").css("display", "block");
                    return false;
                }
            }
        });

    });
</script>
{/literal}