<script>

    function payIt() {
        var amount = Number($('#amount').val());
        if (amount <= 0) {
            $('#amount').css('background-color', 'yellow');
        } else {
            $('#amount').css('background-color', 'white');
            $('#payInfo').submit();
        }
    }
</script>
<style>
    .myresult {
        -webkit-print-color-adjust: exact;
    }
    .nodata{
        background-color: #72B4EC;
        color: white;
        border-radius: 13px;
        margin: 14px;
        font-size: 24px;
        text-align: center;
        padding: 5px;
    }
    table.dataTable thead .sorting:after, table.dataTable thead .sorting_asc:after, table.dataTable thead .sorting_desc:after, table.dataTable thead .sorting_asc_disabled:after, table.dataTable thead .sorting_desc_disabled:after{
        display: none;
    }
    @media print {
        p,h4,h3,h2,h1,span,label,td,th,div.dataTables_info,a,.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
        div.dataTables_wrapper div.dataTables_info, tr.odd td.sorting_1{
            color:#000!important
        }
        .table thead>tr>th, .table tbody>tr>th, .table tfoot>tr>th, .table thead>tr>td, .table tbody>tr>td, .table tfoot>tr>td{
            text-align: center
        }
    }

</style>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">التقارير</a></li>
            <li class="active">تقرير نسبة المناديب على التحصيلات</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير نسبة المناديب على التحصيلات
                <a href="{$youtubes[161]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
            </div>
            <div class="panel-body">
                <form class="form-inline hidden-print" action="clientPayedDeptController.php?do=mandobreport" method="post" id="salesreportbills-form">
                    <div class="form-group">
                        <label class="sr-only">المندوب</label>
                        <select class="select2"  name="mandob" id="mandob" >
                            <option value="-1">اختر المندوب</option>
                            {foreach $sellers as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <br />
                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="from" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="to" >
                    </div>
                    <div style="clear: both"></div>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>

            </div>
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>
                <div class="panel-body"><!-- style="overflow-x: auto;" -->
                    {if count($mandobCollectData) > 0 || count($allDataArr_buy) > 0|| count($vatPaymentData) > 0}
                    <hr/>
                    <!--div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm">
                            <h4 class="text-center">صافى الربح {$totalsObj->billProfit} {$currency}</h4>
                        </div>
                    </div-->
                    <style>
                        @media print {
                            @page {
                                size: landscape;
                                margin: 0;
                            }
                            .willprint ,.willprint td,.willprint th {
                                padding:  0px !important;
                                font-family: arial;
                                font-size: 10px;
                                border-collapse: collapse;
                                border: 1px solid #333 !important;
                            }
                            /* .willprint th{
                                background: #aaa !important;
                            } */
                            .willprint tr:even-child td{
                                background: #333 !important;
                                color: #fff !important;
                            }
                        }
                    </style>


                    <h3>التحصيلات</h3>
                    <br/>

                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th>العميل</th>
                                <th>المبلغ المحصل</th>
                                <th>النسبة</th>
                                <th>قيمة النسبة المستحقة</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=totalMandob value=0}
                            {foreach $mandobCollectData as $data}
                            {assign var=mandobPercentageMoney value=(($data->mandobCollectRatio/100) * $data->clientdebtchangeamount)}
                            {assign var=totalMandobMoney value=$totalMandobMoney+$mandobPercentageMoney}
                            <tr>
                                <td>{$i}</td>
                                <td>{$data->clientname}</td>
                                <td>{$data->clientdebtchangeamount}</td>
                                <td>{$data->mandobCollectRatio}</td>
                                <td>{$mandobPercentageMoney}</td>
                            </tr>

                            {assign var=i value=$i+1}
                            {/foreach}
                            <!--                            <tr>
                                                            <td><span style="display: none">z</span></td>
                                                            <td></td>
                                                            <th style="text-align: center;">الاجمالى</th>
                                                            <td>{$totalsObj->totalbill}</td>
                                                            <td></td>
                                                            <td>{$totalsObj->vatMoney}</td>
                                                            <td class="hidden-print"></td>
                                                        </tr>-->
                        </tbody>

                    </table>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي مستحقات المندوب  {$totalMandobMoney}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>



                    <h3>مقبوضات المندوب</h3>
                    <br/>
                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th>المبلغ</th>
                                <th>التاريخ</th>
                                <th>النوع</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=mandobTakenMoney value=0}
                            {foreach $mandobTakenMoneyArr as $data}
                            {assign var=mandobTakenMoney value=$mandobTakenMoney+$data->value}
                            <tr>
                                <td>{$i}</td>
                                <td>{$data->value}</td>
                                <td>{$data->date}</td>
                                <td>{if $data->type == 1}مصروف{elseif $data->type == 2}مكافاة تحصيل{/if}</td>
                            </tr>
                            {assign var=mandobTakenMoney value=$mandobTakenMoney+$data->vatMoney}
                            {assign var=i value=$i+1}
                            {/foreach}
                        </tbody>

                    </table>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي المقبوضات  {$mandobTakenMoney}</h4>
                        </div>
                    </div>
                    {assign var=reqPayAmount value=($totalMandobMoney - $mandobTakenMoney)}
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">صافى المستحق  {$reqPayAmount}</h4>
                        </div>
                    </div>

                    <input type="hidden" id="reqPayAmount" value="{$reqPayAmount}"/>

                    <div class="clearfix"></div>
                    {if $reqPayAmount > .01}
                    <button type="button" class="btn btn-success pull-left" id="payMandob">{if $userGroupData->mandobMethod == 0}اضافة نسبة المندوب كمصروف{else if $userGroupData->mandobMethod == 1}اضافة نسبة المندوب  للراتب {/if}</button>
                    {/if}
                    <div class="clearfix"></div>



                    <div class="clearfix"></div>
                    <hr />
                    <!--div  class="noprint">
                        <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 hidden-print">طباعة</button>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div-->
                    {else}
                    <div class="nodata">عفوا لا توجد نتائج</div>
                    {/if}

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
















<!------------------------Client Model----------------------------->
<!-- Modal -->
<div class="modal fade" id="myModal1" 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="payInfo" action="clientPayedDeptController.php?do=paymandob" method="post">
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="amount" class="col-lg-2 control-label">المبلغ</label>
                        <div class="col-lg-4"> <!--<span id="sprytextfield3">-->
                            <input class="form-control positivefloat" placeholder="المبلغ" id="amount" name="amount" type="text" required="required"/>
                            <input type="hidden" name="mandobMethod" value="{$userGroupData->mandobMethod}"/>
                            <input type="hidden" name="choosenMandob" value="{$choosenMandob}"/>
                        </div>
                    </div>
                    <!-- =================================================   -->
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">الغاء</button>
                <button type="button" class="btn btn-primary" onClick="payIt();">دفع</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<!------------------------Client Model----------------------------->




{literal}
<script>
    $(document).ready(function () {
        $('#payMandob').on('click', function () {
            $('#myModal1').modal('show');
        });
        $('#amount').on('keyup', function () {
            var amount = Number($(this).val());
            var req = Number($('#reqPayAmount').val());
            req = Math.round(req * 100) / 100;
            if (amount > req) {
                $(this).val(req);
            }
            if (amount <= 0) {
                $('#amount').css('background-color', 'yellow');
            } else {
                $('#amount').css('background-color', 'white');
            }
        });
    });

</script>
{/literal}
