
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="policyController.php?do=show">بوليصة الشحن</a></li>
            <li class="active">عرض بواليص الشحن</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- 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[4]->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="policyController.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">
                <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>
                <form class="form-inline hidden-print" action="policyController.php?do=show" method="post">
                    <div class="form-group">
                        <label class="sr-only">شركة الشحن</label>
                        <select class="select2 wdt100"  name="companyId" id="companyId">
                            <option value="-1">اختر شركة</option>


                            {foreach $shippercompaniesData as $shippercompanies}


                            <option value="{$shippercompanies->companyId}">{$shippercompanies->companyName}</option>


                            {/foreach}


                        </select>
                    </div>

                    <div class="form-group">
                        <label for="type" class="col-lg-2 control-label">النوع</label>
                        <div class="col-lg-10">
                            <div class="radio-inline">
                                <label>
                                    <input type="radio" name="type"  value="1">
                                    عملاء
                                </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input type="radio" name="type"  value="2">
                                    موردين
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="submit" class="btn btn-primary" value="عرض"/>
                    </div>
                </form>
            </div>
            <hr/>

            <!-- Table -->
            {literal}
            <form method="post" action="policyController.php?do=executeOperation" onsubmit="if (Spry.Widget.Form.validate(this)) {
                        return countChoosenProducts('policyController');
                    } else {
                        return false;
                    }">
                {/literal}
                <table class="table table-black dataTableClass">
                    <thead>
                        <tr>
                            <th class="hidden-print">
                                <input type="checkbox" name="checkAll" id="checkAll"/>
                            </th>
                            <th>رقم الفاتوره  </th>
                            <th>عدد الطرود </th>
                            <th>رقم البوليصة</th>
                            <th>السعر</th>
                            <th>شركة الشحن</th>
                            <th>التاريخ</th>
                            <th>نوع البوليصة</th>
                            <th>النوع</th>
                            <th>اسم العميل/ المورد</th>
                            <th>تحصيل/ دفعة</th>
                            <th class="hidden-print">تعديل</th>
                            <th class="hidden-print">حذف</th>
                        </tr>
                    </thead>
                    <tbody>

                        {foreach $policyData as $policy}
                        {if {$policy->tempdele} eq 1}
                        <tr class="danger"> {elseif {$policy->tempdele} eq 0}

                        <tr> {/if}
                            <td class="hidden-print">
                                <input type="checkbox" name="choosedItem[]" id="checked{$i}" class="choosenItem" value="{$policy->policyId}" />
                            </td>
                            <td>{$policy->invoicenumber}</td>
                            <td>{$policy->policyName}</td>
                            <td>{$policy->policyNum}</td>
                            <td>{$policy->policyCost}</td>
                            <td>{$policy->companyName}</td>
                            <td>{$policy->policyDate}</td>
                            {if $policy->policyType eq 1}
                            <td>ذهاب</td>
                            {else}
                            <td>عودة</td>
                            {/if}
                            <td>{if $policy->senderType eq 1}عملاء{else}موردين{/if}</td>
                            <td>{$policy->senderName}</td>
                            <td>
                                {if $policy->affectSave eq 1}
                                <select class="select2 policySave" data-id="{$policy->policyId}" data-itr="{$i}" id="save{$i}">
                                    <option></option>
                                    {foreach $allSave as $data}
                                    <option value="{$data->saveid}">{$data->savename}</option>
                                    {/foreach}
                                </select>
                                {/if}
                            </td>
                            <td class="hidden-print"> <a href="policyController.php?do=edit&policyId={$policy->policyId}" type="button" class="btn btn-default btn-lg editicon"></a> </td>
                            <td class="hidden-print"> <a href="#" name="dd" type="button" class="btn btn-default btn-lg deleteicon conformdel1" data-position="policyController.php?do=delete&policyId={$policy->policyId}" ></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="3">حذف</option>
                                        </select>
                                        <span class="selectInvalidMsg">*</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>
                            <div class="clearfix"></div>
                            <div id="noElementsError" class="alert alert-danger fade in" style="display:none;">
                                <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">×</button>
                                <p>يجب اختيار العناصر أولاً</p>
                                <div class="clearfix"></div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </form>

            <div class="clearfix"></div>
        </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>
        <!-- Modal -->
        <div class="modal fade hidden-print" id="myModal1" 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>
                        <h4 class="modal-title">تأكيد حذف البوليصة</h4>
                    </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 savemodel1">نعم</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->

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

    $('.policySave').live('change', function () {
        if (!$(this).hasClass('processing...')) {
            $(this).addClass('processing...');
            var thisIs = $(this);

            $.ajax({
                type: "POST",
                url: 'policyAjaxController.php?do=dopay',
                data: {policy: thisIs.data('id'), save: thisIs.val()},
                async: false,
                success: function (data) {
                    console.log(data);
                    data = Number(data);
                    console.log(data);
                    if (data > 0) {
                        thisIs.parent().html('تمت العملية بنجاح')
                    } else {
                        thisIs.removeClass('processing...');
                    }
                }
            });


        }

    });
</script>
{/literal}