<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[150]->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="salesreportbillsvat.php" method="post" id="salesreportbills-form">
                    <!--div class="form-group">
                        <label class="sr-only">العملاء</label>
                        <select class="select2 "  name="clientid" id="clientid" >
                            <option value="-1">اختر عميل</option>
                            <option value="0">كل العملاء</option>
                            {foreach $clients as $data}
                            <option value="{$data->clientid}">{$data->clientname}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">التسلسل</label>
                        <input type="text" class="form-control" name="billid" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">رقم الفاتورة</label>
                        <input type="text" class="form-control" name="billserial" >
                    </div>
                    <div style="clear: both"></div>
                    <br />
                    {if $user->userstoreid == 0}
                    <div class="form-group">
                        <label class="sr-only">المخزن</label>
                        <select class="select2 "  name="storeId" id="storeId" >
                            <option value="-1">اختر مخزن</option>
                            <option value="0">كل المخازن</option>
                            {foreach $storeData as $store}
                            <option value="{$store->storeId}">{$store->storeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    {if $user->branchId == 0}
                    <div class="form-group">
                        <label class="sr-only">الفرع</label>
                        <select class="select2 "  name="branchId" id="branchId" >
                            <option value="-1">اختر الفرع</option>
                            <option value="0">كل الفروع</option>
                            {foreach $branchData as $branch}
                            <option value="{$branch->branchId}">{$branch->branchName}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}-->
                    <!--div class="form-group">
                        <label class="sr-only">{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</label>
                        <select class="select2 "  name="sellerid" id="sellerid" >
                            <option value="-1">اختر {if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</option>
                            <option value="0">كل {if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}ين</option>
                            {foreach $sellerData as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">المستخدم</label>
                        <select class="select2 "  name="userid" id="userid" >
                            <option value="-1">اختر المستخدم</option>
                            <option value="0">كل المستخدمين</option>
                            {foreach $userData as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">نوع الفاتورة</label>
                        <select class="select2 "  name="billtype" id="billtype" >
                            <option value="-1">اختر النوع</option>
                            <option value="1">مبيعات فقط</option>
                            <option value="2">مرتجعات فقط</option>
                            <option value="3">مبيعات و مرتجعات</option>
                    <!--option value="4">مبيعات بصريات</option>
                    <option value="5">مرتجعات بصريات</option-->
                    <!--/select>
                </div>
                <div style="clear: both"></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="datefrom" >
                    </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="dateto" >
                    </div>
                    <div class="form-group">
                        <div><label class="sr-only">مجمل يوم</label></div>
                        <div class="radio-inline">
                            <input value="1" name="searchtype"  type="checkbox"/>
                        </div>
                    </div>

                    <div style="clear: both"></div>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</button>

                    <input type="hidden" name="storeIdS" value="{$storeIdS}"/>
                    <input type="hidden" name="branchIdS" value="{$branchIdS}"/>
                    <input type="hidden" name="selleridS" value="{$selleridS}"/>
                    <input type="hidden" name="useridS" value="{$useridS}"/>
                    <input type="hidden" name="clientidS" value="{$clientidS}"/>
                    <input type="hidden" name="billidS" value="{$billidS}"/>
                    <input type="hidden" name="billserialS" value="{$billserialS}"/>
                    <input type="hidden" name="billtypeS" value="{$billtypeS}"/>
                    <input type="hidden" name="day" id="day" value=""/>
                </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($allDataArr) > 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>
                    {if $searchtype == "0"}
                    <h3>فواتير المبيعات</h3>
                    <br/>

                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th><center>رقم الفاتورة</center></th>
                        <th><center>تاريخ الفاتورة ووقتها</center></th>
                        <th><center>اجمالى الفاتورة</center></th>
                        <th><center>  نوع الفاتورة</center></th>
                        <th><center>ضريبة القيمة المضافة</center></th>
                        <th class="hidden-print"><center>تفاصيل الفاتورة</center></th>
                        </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=total_vat_sell value=0}
                            {foreach $allDataArr as $data}
                            <tr>
                                <td>{$i}</td>
                                <td><center>{$data->billserial}</center></td>
                        <td><center>{$data->datetime}</center></td>
                        <td><center>{$data->totalbill}</center></td>
                        <td><center>{$data->billtype}</center></td>
                        <td><center>{$data->vatMoney}</center></td>
                        <td class="hidden-print"><center> <a href="{$data->billURL}" type="button" class="btn btn-default btn-lg notesicon"></a> </center></td>
                        </tr>
                        {assign var=total_vat_sell value=$total_vat_sell+$data->vatMoney}
                        {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">إجمالي القيمة المضافة مبيعات  {$total_vat_sell}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>



                    <h3>فواتير المشتريات</h3>
                    <br/>
                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th><center>رقم الفاتورة</center></th>
                        <th><center>تاريخ الفاتورة ووقتها</center></th>
                        <th><center>اجمالى الفاتورة</center></th>
                        <th><center>  نوع الفاتورة</center></th>
                        <th><center>ضريبة القيمة المضافة</center></th>
                        <th class="hidden-print"><center>تفاصيل الفاتورة</center></th>
                        </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=total_vat_buy value=0}
                            {foreach $allDataArr_buy as $data}
                            <tr>
                                <td>{$i}</td>
                                <td><center>{$data->billserial}</center></td>
                        <td><center>{$data->datetime}</center></td>
                        <td><center>{$data->totalbill}</center></td>
                        <td><center>{$data->billtype}</center></td>
                        <td><center>{$data->vatMoney}</center></td>
                        <td class="hidden-print"><center> <a href="{$data->billURL}" type="button" class="btn btn-default btn-lg notesicon"></a> </center></td>
                        </tr>
                        {assign var=total_vat_buy value=$total_vat_buy+$data->vatMoney}
                        {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_buy->totalbill}</td>
                            <td></td>
                            <td>{$totalsObj_buy->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">إجمالي القيمة المضافة مشتريات  {$total_vat_buy}</h4>
                        </div>
                    </div>



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



                    <h3>دفعات القيمة المضافة</h3>
                    <br/>
                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th><center>التاريخ</center></th>
                        <th><center>القيمة</center></th>
                        <th><center>المستخدم</center></th>
                        <th><center>الخزنة</center></th>
                        </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=total_vat_payed value=0}
                            {foreach $vatPaymentData as $data}
                            <tr>
                                <td>{$i}</td>
                                <td><center>{$data->sysdate}</center></td>
                        <td><center>{$data->amount}</center></td>
                        <td><center>{$data->username}</center></td>
                        <td><center>{$data->savename}</center></td>
                        </tr>
                        {assign var=total_vat_payed value=$total_vat_payed+$data->amount}
                        {assign var=i value=$i+1}
                        {/foreach}
                        <tr>
                            <td><span style="display: none">z</span></td>
                            <th style="text-align: center;">الاجمالى</th>
                            <td>{$total_vat_payed}</td>
                            <td></td>
                            <td></td>
                        </tr>


                        </tbody>

                    </table>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي الدفعات  {$total_vat_payed}</h4>
                        </div>
                    </div>
                    {assign var=reqPayAmount value=$total_vat_sell-$total_vat_buy-$total_vat_payed}
                    <input type="hidden" id="reqPayAmount" value="{$reqPayAmount}"/>




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

                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي القيمة المضافة مبيعات  {$total_vat_sell}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي القيمة المضافة مشتريات  {$total_vat_buy}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي الدفعات  {$total_vat_payed}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">المطلوب دفعه  {$total_vat_sell-$total_vat_buy-$total_vat_payed}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    {if $reqPayAmount > .01}
                    <button type="button" class="btn btn-success pull-left" id="payVat">دفع</button>
                    {/if}
                    <div class="clearfix"></div>



                    {else}




                    <h3>فواتير المبيعات</h3>
                    <br/>
                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th>تاريخ الفاتورة ووقتها</th>
                                <th>اجمالى الفواتير</th>
                                <th>ضريبة القيمة المضافة</th>
                                <th class="hidden-print">تفاصيل الفاتورة</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=total_vat_sell value=0}
                            {foreach $allDataArr as $data}
                            <tr>
                                <td>{$i}</td>
                                <td>{$data->datetime}</td>
                                <td>{$data->totalbill}</td>
                                <td>{$data->vatMoney}</td>
                                <td class="hidden-print"><a data-day="{$data->datetime}" style="color: blue;" class="daydetail">التفاصيل</a></td>
                            </tr>
                            {assign var=total_vat_sell value=$total_vat_sell+$data->vatMoney}
                            {assign var=i value=$i+1}
                            {/foreach}
                            <tr>
                                <td><span style="display: none">z</span></td>
                                <th style="text-align: center;">الاجمالى</th>
                                <td>{$totalsObj->totalbill}</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">إجمالي القيمة المضافة مبيعات  {$total_vat_sell}</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>
                                <th class="hidden-print">تفاصيل الفاتورة</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=total_vat_buy value=0}
                            {foreach $allDataArr_buy as $data}
                            <tr>
                                <td>{$i}</td>
                                <td>{$data->datetime}</td>
                                <td>{$data->totalbill}</td>
                                <td>{$data->vatMoney}</td>
                                <td class="hidden-print"><a data-day="{$data->datetime}" style="color: blue;" class="daydetail">التفاصيل</a></td>
                            </tr>
                            {assign var=total_vat_buy value=$total_vat_buy+$data->vatMoney}
                            {assign var=i value=$i+1}
                            {/foreach}
                            <tr>
                                <td><span style="display: none">z</span></td>
                                <th style="text-align: center;">الاجمالى</th>
                                <td>{$totalsObj_buy->totalbill}</td>
                                <td>{$totalsObj_buy->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">إجمالي القيمة المضافة مشتريات  {$total_vat_buy}</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 class="hidden-print">التفاصيل </th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=total_vat_payed value=0}
                            {foreach $vatPaymentData as $data}
                            <tr>
                                <td>{$i}</td>
                                <td><center>{$data->sysdate}</center></td>
                        <td><center>{$data->amount}</center></td>
                        <td class="hidden-print"><a data-day="{$data->datetime}" style="color: blue;" class="daydetail">التفاصيل</a></td>
                        </tr>
                        {assign var=total_vat_payed value=$total_vat_payed+$data->amount}
                        {assign var=i value=$i+1}
                        {/foreach}
                        <tr>
                            <td><span style="display: none">z</span></td>
                            <th style="text-align: center;">الاجمالى</th>
                            <td>{$total_vat_payed}</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">إجمالي الدفعات  {$total_vat_payed}</h4>
                        </div>
                    </div>
                    {assign var=reqPayAmount value=$total_vat_sell-$total_vat_buy-$total_vat_payed}
                    <input type="hidden" id="reqPayAmount" value="{$reqPayAmount}"/>







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

                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي القيمة المضافة مبيعات  {$total_vat_sell}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي القيمة المضافة مشتريات  {$total_vat_buy}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">إجمالي الدفعات  {$total_vat_payed}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-offset-8 col-lg-4 ">
                        <div class="well well-sm">
                            <h4 class="text-center">المطلوب دفعه  {$reqPayAmount|string_format:"%.2f"}</h4>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    {if $reqPayAmount > .01}
                    <button type="button" class="btn btn-success pull-left" id="payVat">دفع</button>
                    {/if}
                    <div class="clearfix"></div>

                    {/if}

                    <!--div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm">
                            <h4 class="text-center">صافى الربح {$totalsObj->billProfit} {$currency}</h4>
                        </div>
                    </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="salesreportbillsvat.php?do=payVat" method="post" class="form-horizontal">
                    <!-- =================================================   -->
                    <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"/>
                        </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 () {
        $('.daydetail').on('click', function () {
            var day = $(this).attr('data-day');
            $('#day').val(day);
            $('#salesreportbills-form').attr("target", "_blank");
            $('#salesreportbills-form').submit();
            $('#day').val("");
            $('#salesreportbills-form').removeAttr("target");
        });
        $('#payVat').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}
