<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" style="padding:5px 15px 15px">
                <h3 class="panel-title" style="display: inline-block;">عرض الأصول <br />
                    {if $message != ""}
                    {$message}
                    {/if}</h3>
                <a href="{$youtubes[7]->url}" target="_blank" class="hidden-print"><img
                        src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube"
                        style="width: 2%;"></a>
                <a href="assetController.php" class="hidden-print"><input type="button" style="margin-left: 12px"
                        id="submit" class="btn btn-primary pull-left " value="إضافة جديد" /></a>
            </div>

            <div class="panel-body">

                <!---------- start outputString alert ----------->
                <div id="outputString" class="alert alert-block alert-success fade in  hidden-print"
                    style="display:none">
                    <button type="button" class="close pull-left" data-dismiss="alert"
                        aria-hidden="true">&times;</button>
                    <p id="outputStringValue">{$outputString}</p>
                    <div class="clearfix"></div>
                </div>
                <!---------  end outputString alert ------------>

                <form class="form-inline  hidden-print" method="post" action="assetController.php?do=show">
                    <div class="form-group">
                        <label class="sr-only">اسم الاصل</label>
                        <select data-placeholder="اختر اصل" class="select2 wdt100" name="assetId" id="assetId"
                            onChange=" getResult();">
                            <option value="-1"> اختر اصل </option>





                            {foreach $allassetdata as $assetsearch}





                            <option value="{$assetsearch->assetId}">{$assetsearch->assetsName}</option>





                            {/foreach}





                        </select>
                        <input type="hidden" name="usergroupname" id="usergroupname" value="{$usergroupname}" />
                    </div>
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>
                <hr />
                {literal}
                <form id="form1" name="form1" method="post" action="assetController.php?do=executeOperation" onsubmit="if (Spry.Widget.Form.validate(this)) {
                            return countChoosenProducts('assetController');
                        } else {
                            return false;
                        }
                      " enctype="multipart/form-data">
                    {/literal}
                    <!-- Table -->
                    <table class="table">
                        <thead>
                            <tr>
                                <th class="hidden-print">
                                    <label>
                                        <input type="checkbox" name="checkAll" id="checkAll" />
                                    </label>
                                </th>
                                <th>اسم الاصل</th>
                                <th>سعر الاصل</th>
                                <th>النوع</th>
                                <th class="hidden-print">تعديل</th>
                                <th class="hidden-print">بيع</th>
                                <th class="hidden-print">الغاء</th>
                                <th class="hidden-print">طباعة</th>
                                <th class="hidden-print">قيد اليومية</th>
                            </tr>
                        </thead>
                        <tbody>

                            {foreach $assetData as $asset}
                            {if {$asset->conditions} eq 1}
                            <tr class="danger"> {elseif {$asset->conditions} eq 0}

                            <tr> {/if}
                                <td class="hidden-print">
                                    <label>
                                        <input type="checkbox" name="choosedItem[]" id="checked{$i}" class="choosenItem"
                                            value="{$asset->assetId}" />
                                    </label>
                                </td>
                                <td>{$asset->assetsName}</td>
                                <td id="assetsValue0{$asset->assetId}">{$asset->assetsValue}</td>
                                <td>
                                    {if $asset->type eq 1}
                                        {if {$asset->paytype} eq 0}
                                        اصل جديد خزينه
                                        {elseif {$asset->paytype} eq 1}
                                        اصل جديد شيك
                                        {elseif {$asset->paytype} eq 2}
                                        اصل جديد مورد
                                        {/if}
                                    {else}
                                    اصل قديم
                                    {/if} </td>
                                <td class="hidden-print"><a
                                        href="assetController.php?do=edit&assetId={$asset->assetId}&type={$asset->type}"
                                        type="button" class="btn btn-default btn-lg editicon"> </a></td>

                                <td>
                                    {if $asset->assetssaleid < 1} <button type="button"
                                        class="btn btn-primary exampleModals" data-toggle="modal"
                                        data-target="#exampleModal" id="bottommodel{$asset->assetId}"
                                        data-id="{$asset->assetId}"> البيع</button>
                                        {else}
                                        <button type="button" class="btn btn-primary exampleModals" data-toggle="modal"
                                            data-target="#exampleModal" id="bottommodel{$asset->assetId}"
                                            data-id="{$asset->assetId}" style="background-color: red;"> تفاصيل</button>
                                        {/if}

                                </td>
                                <td class="hidden-print"> {if {$asset->conditions} eq 0} <a href="javascript:;"
                                        data-go="assetController.php?do=delete&assetId={$asset->assetId}&type={$asset->type}&action={$asset->dailyentryid}"
                                        type="button" class="btn btn-default btn-lg removeicon delthis"> </a> {else}
                                    تم الغاءه من قبل
                                    {/if}
                                    <!--a onclick="getValue({$assetId->assetId},{$asset->type})" name="dd" class="deletefinal button with_icon16_notext"-->
                                </td>
                                <td class="hidden-print"><a
                                        href="assetController.php?do=editprint&id={$asset->assetId}&type={$asset->type}"
                                        type="button" class="btn btn-default btn-lg printicon"> </a></td>
                                <td class="hidden-print"><a href="dailyentry.php?id={$asset->dailyentryid}"
                                        target="_blank" type="button" class="btn btn-default btn-lg editicon"> </a></td>
                            </tr>
                            {/foreach}

                        </tbody>

                    </table>
                    <div class="clearfix"></div>
                    <hr />
                    <div class="hidden-print">
                        <div class="col-lg-12">
                            <div class="well well-sm">
                                <div class="form-group">
                                    <div class="col-lg-4">
                                        <label for="operation"></label>
                                        <span id="spryselect1">
                                            <select name="operation" id="operation" data-placeholder="اختر العملية"
                                                class="select2 wdt100">
                                                <option value="-1"></option>
                                                <option value="1">الغاء</option>
                                            </select>
                                            <span class="selectRequiredMsg">اختر العملية</span></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-4">
                                        <input name="" class="hidden-print btn btn-primary" type="submit"
                                            value="تنفيذ" />
                                    </div>
                                </div>

                                <!-----------  start noElementsError alert ------------->
                                <div class="clearfix"></div>
                                <div id="noElementsError" class="alert alert-danger fade in  hidden-print"
                                    style="display:none;">
                                    <button type="button" class="close pull-left" data-dismiss="alert"
                                        aria-hidden="true">×</button>
                                    <p>يجب اختيار العناصر أولاً</p>
                                    <div class="clearfix"></div>
                                </div>
                                <!----------  end noElementsError alert -------------->

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

                        <!-- <div class="col-lg-offset-8 col-lg-4">
                            <div class="well well-sm"><h4 class="text-center">اجمالى الاصول:  {$sumValue}</h4></div>
                    </div>
                        -->
                        <div class="clearfix"></div>
                    </div>
                </form>
                <div class="hidden-print">
                    <div class="dataTables_info" id="datatable_2_info"> هناك
                        &nbsp;[{$paginate.first}-{$paginate.last}]&nbsp; عنصر من &nbsp; &nbsp; [{$paginate.total}]</div>
                    <div class="dataTables_paginate paging_full_numbers" id="datatable_2_paginate"> {if {paginate_prev}
                        eq ""}
                        {else} <span class="next paginate_button" id="datatable_2_next">{paginate_prev}</span> {/if}
                        <span> {if {paginate_middle} eq ""}
                            {else} <span class="paginate_button">{paginate_middle format="page"}</span> {/if} </span>
                        {if {paginate_next} eq ""}
                        {else} <span class="last paginate_button" id="datatable_2_last">{paginate_next}</span> {/if}
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="hidden-print">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <div class="col-lg-4">
                                <button type="button" onclick="print_Custom('mycustomheader');"
                                    class="btn btn-success pull-right">طباعة</button>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">اضافه بيع</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"
                    style="margin-top: -18px; float:left">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="post" id="submitForm">
                <div class="modal-body">
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label">العميل</label>
                        <div class="col-lg-8">
                            <select class="select2 wdt100 clientstore" name="assetssaleclient" id="clientid">
                                {foreach $clientdata as $client}
                                <option value="{$client->clientid}">{$client->clientname}</option>

                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label">الخزنة</label>
                        <div class="col-lg-8">
                            <select class="select2 wdt100 clientstore" name="assetssalesave" id="saveid">
                                {foreach $savedata as $save}
                                <option value="{$save->saveid}">{$save->savename}</option>

                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label"> التاريخ </label>
                        <div class="col-lg-8">
                            <input type="text" class="form-control awdatepicker " data-date-format="yyyy-mm-dd"
                                id="searchDateFrom" name="assetssaledate">
                        </div>
                    </div>
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label">المبلغ</label>
                        <div class="col-lg-8">
                            <input type="number" class="form-control" name="assetssaleval" id="assetssaleval">
                        </div>
                    </div>
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label">التعليق</label>
                        <div class="col-lg-8">
                            <textarea class="form-control" name="assetssalecomment" rows="2"
                                id="assetssalecomment"></textarea>
                        </div>
                    </div>
                    <input type="hidden" class="form-control" name="assetsidm" id="assetidm">
                    <input type="hidden" class="form-control" name="assetssaleoldid" id="assetssaleoldid">

                </div>
                <div style="clear:both"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">اغلاق</button>
                    <button type="submit" class="btn btn-primary" id="assetsalesave">حفظ</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="hidden-print">
    <div class="modal fade " id="confirmThis" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close pull-left" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                    <div class="modal-title">تأكيد حذف العنصر</div>
                </div>
                <div class="modal-body"> هل تريد حذف هذا العنصر؟ </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">لا</button>
                    <button type="button" class="btn btn-primary" id="delThisBtn" data-go="">نعم</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</div>
<!-- /.modal -->
{literal}
<script type="text/javascript">
    $(document).ready(function () {
        $("body").on("click", ".exampleModals", function () {
            var assetsid = Number($(this).attr("data-id"));
            $.post("ajaxnew.php?do=assetsalecheck", { assetsid: assetsid }, function (result) {
                data = JSON.parse(result);
                if (data != null) {
                    $("#clientid").val(data.assetssaleclient).trigger("change");
                    $("#saveid").val(data.assetssalesave).trigger("change");
                    $("#searchDateFrom").val(data.assetssaledate);
                    $('#assetssaleval').val(data.assetssaleval);
                    $('#assetssalecomment').val(data.assetssalecomment);
                    $('#assetsValue0' + assetsid).text('0.00');
                    $('#bottommodel' + assetsid).text("تفاصيل");
                    $('#bottommodel' + assetsid).css("background-color", "red");
                    $('#assetsalesave').remove();

                } else {
                    $("#clientid").val(0).trigger("change");
                    $("#saveid").val(0).trigger("change");
                    $("#searchDateFrom").val('');
                    $('#assetssaleval').val('');
                    $('#assetssalecomment').val('');
                }

            });
            $('#assetidm').val(assetsid);
        });
        $('form#submitForm').submit(function (e) {
            var assetsid = $('#assetidm').val();
            e.preventDefault();
            var formData = new FormData(this);
            $.ajax({
                url: 'assetController.php?do=assetsaleadd',
                type: 'POST',
                data: formData,
                success: function (data) {
                    $("#submitForm")[0].reset()
                    $('#exampleModal').modal('toggle');
                    $('#assetsValue0' + assetsid).text('0.00');
                    $('#bottommodel' + assetsid).text("تفاصيل");
                    $('#bottommodel' + assetsid).css("background-color", "red");


                },
                cache: false,
                contentType: false,
                processData: false
            });

        });
    });
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", { invalidValue: "-1" });
</script>
{/literal}