<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;
    }
</style>

<div class="row">
    <div class="container {if $lang_code == 'en'} gt4-ltr{/if}">
        <ol class="breadcrumb">
            <li><a href="#">التقارير</a></li>
            <li><a href="cashSaveFlowController.php?do=show">تقرير تدفق النقدية بالخزنة</a></li>
            <li class="active">عرض التقرير</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير تدفق النقدية بالخزنة
                <a href="{$youtubes[118]->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="cashSaveFlowController.php?do=show" method="post">

                    <div class="form-group">
                        <label class="sr-only">الخزنة/البنك</label>
                        <select class="select2 wdt300" name="saveId" id="saveid">
                            <option value="-1">اختر خزنة/بنك</option>
                            {if $searchinonesave eq 0}
                            {foreach $saveData as $save}
                            <a href="show_ltr.html"></a>
                            <option value="save_{$save->saveid}">{$save->savename}</option>
                            {/foreach}
                            {/if}
                            {foreach $allAccounts as $data}
                            <option value="bank_{$data->accountid}">{$data->bankname} -
                                {$data->accountnumber}/{$data->accountname}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div id="dateTimeDiv">
                        <div class="form-group">
                            <label class="sr-only">من التاريخ</label>
                            <div class="input-group date form_datetime col-md-5" data-date=""
                                data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control" size="16" type="text" value="" name="from" id="from"
                                    readonly="">
                                <span class="input-group-addon " style="width: 0%;"><span
                                        class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon" style="width: 0%;"><span
                                        class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <div class="input-group date form_datetime col-md-5" data-date=""
                                data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control" size="16" type="text" value="" name="to" id="to"
                                    readonly="">
                                <span class="input-group-addon " style="width: 0%;"><span
                                        class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon" style="width: 0%;"><span
                                        class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>
                        </div>
                    </div>
                    <div id="dateOnlyDiv">
                        <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" value="">
                        </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" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">بحث بـ</label>
                        <div class="input-group">
                            <label> <input value="dateOnly" name="search" id="searchdateOnly" type="radio" checked
                                    onclick='localStorage.setItem("search", "dateOnly");
                                    window.location.reload();'>
                                تاريخ</label>
                            <label>
                                <input value="dateTime" name="search" id="searchdateTime" type="radio" onclick='localStorage.setItem("search", "dateTime");
                                        window.location.reload();'>
                                تاريخ ووقت</label>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>
            </div>

            <div class="clearfix"></div>
            <hr />
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>

                <div class="panel-body table-responsive">
                    {if count($savedailyData)>0 || count($allMovements)>0}
                    <div class="col-lg-4">
                        <div class="well-sm" style="background-color: cadetblue; color: white;">

                            <h4 class="text-center">الرصيد السابق</h4>

                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <table class="table table-black table-striped">
                        <thead>
                            <tr style="text-align:center">
                                <th>اسم الخزينة/البنك</th>
                                <th>الرصيد</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $savesData as $data}
                            <tr>
                                <td>{$data.savename} </td>
                                <td>
                                    {$data.balance}
                                </td>

                            </tr>
                            {/foreach}
                            {foreach $accountsData as $account}
                            <tr>
                                <td>{$account.accountname} </td>
                                <td>
                                    {$account.balance}
                                </td>

                            </tr>
                            {/foreach}
                        </tbody>

                    </table>

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

                    <div class="col-lg-4">
                        <div class="well-sm" style="background-color: cadetblue; color: white;">
                            <h4 class="text-center">المصروفات</h4>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <table class="table table-black table-striped">
                        <thead>
                            <tr style="text-align:center">
                                <th>#</th>
                                <th>التفاصيل</th>
                                {foreach $savesData as $data}
                                <th>{$data.savename}</th>
                                {/foreach}
                                {foreach $accountsData as $data}
                                <th>{$data.accountname}</th>
                                {/foreach}
                            </tr>
                        </thead>
                        <tbody>
                            {if $allBuy}
                            <tr>
                                <td>1</td>
                                <td>قيمة المشتريات</td>
                                {foreach $savesData as $data}
                                {foreach $allBuy as $buy}
                                {if $data@key eq $buy@key}
                                <td>{$buy->savedailychangeamount}</td>
                                {/if}
                                {/foreach}
                                {/foreach}
                                {foreach $accountsData as $data}
                                <td>0</td>
                                {/foreach}
                            </tr>
                            {/if}
                            {foreach $outData as $out}
                            <tr>
                                <td>{$out@iteration}</td>
                                <td>{$out->processname}
                                    {if ($out->personName <> '0' && $out->personName <> '')
                                            ||$out->savecurrentvalue !=""}
                                            ( {$out->savecurrentvalue} )
                                            {/if}
                                </td>
                                {foreach $savesData as $data}
                                {if $data@key eq $out->saveid}
                                <td>{$out->savedailychangeamount}</td>
                                {else}
                                <td>0</td>
                                {/if}
                                {/foreach}

                                {foreach $accountsData as $data}
                                <td>0</td>
                                {/foreach}
                            </tr>
                            {/foreach}
                            {foreach $outDataAcc as $out}
                            <tr>
                                <td>{$out@iteration}</td>
                                <td>{if $out->tablename eq
                                    "cashTransferController.php"}{$out->processname}{else}{$out->processname}
                                    ({$out->bankname}- {$out->accountname} {if
                                    $out->clientname}/{$out->clientname}{/if}){/if}</td>
                                {foreach $savesData as $data}
                                <td>0</td>
                                {/foreach}
                                {foreach $accountsData as $data}
                                {if $data@key eq $out->accountid}
                                <td>{$out->accountmovementamount}</td>
                                {else}
                                <td>0</td>
                                {/if}
                                {/foreach}
                            </tr>
                            {/foreach}
                        </tbody>
                        <tfoot>
                            <tr style="text-align:center">
                                <th></th>
                                <th>إجمالي المصروفات</th>
                                {foreach $savesData as $data}
                                <th>{$data.outSum}</th>
                                {/foreach}
                                {foreach $accountsData as $acc}
                                <th>{$acc.outSum}</th>
                                {/foreach}
                            </tr>
                        </tfoot>

                    </table>

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

                    <div class="col-lg-4">
                        <div class="well-sm" style="background-color: cadetblue; color: white;">
                            <h4 class="text-center">الإيرادات</h4>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <table class="table table-black table-striped">
                        <thead>
                            <tr style="text-align:center">
                                <th>#</th>
                                <th>التفاصيل</th>
                                {foreach $savesData as $data}
                                <th>{$data.savename}</th>
                                {/foreach}
                                {foreach $accountsData as $data}
                                <th>{$data.accountname}</th>
                                {/foreach}
                            </tr>
                        </thead>
                        <tbody>
                            {if $allSell || $allSellAccount}
                            <tr>
                                <td>1</td>
                                <td>قيمة المبيعات</td>
                                {foreach $savesData as $data}
                                {foreach $allSell as $sell}
                                {if $data@key eq $sell@key}
                                <td>{$sell->savedailychangeamount}</td>
                                {/if}
                                {/foreach}
                                {/foreach}
                                
                                {foreach $accountsData as $data}
                                {foreach $allSellAccount as $sell}
                                {if $data@key eq $sell@key}
                                <td>{$sell->accountmovementamount}</td>
                                {/if}
                                {/foreach}
                                {/foreach}
                            </tr>
                            {/if}
                            {foreach $inData as $in}
                            <tr>
                                <td>{$in@iteration + 1}</td>
                                <td>{$in->processname}
                                    {if ($in->personName <> '0' && $in->personName <> '')
                                            ||$in->savecurrentvalue !=""}
                                            ( {$in->savecurrentvalue} )
                                            {/if}
                                </td>
                                {foreach $savesData as $data}
                                {if $data@key eq $in->saveid}
                                <td>{$in->savedailychangeamount}</td>
                                {else}
                                <td>0</td>
                                {/if}
                                {/foreach}

                                {foreach $accountsData as $data}
                                <td>0</td>
                                {/foreach}
                            </tr>
                            {/foreach}
                            {foreach $inDataAcc as $in}
                            <tr>
                                <td>{$in@iteration}</td>
                                <td>{if $in->tablename eq
                                    "cashTransferController.php"}{$in->processname}{else}{$in->processname}
                                    ({$in->bankname}- {$in->accountname} {if
                                    $in->clientname}/{$in->clientname}{/if}){/if}</td>
                                {foreach $savesData as $data}
                                <td>0</td>
                                {/foreach}
                                {foreach $accountsData as $data}
                                {if $data@key eq $in->accountid}
                                <td>{$in->accountmovementamount}</td>
                                {else}
                                <td>0</td>
                                {/if}
                                {/foreach}
                            </tr>
                            {/foreach}
                        </tbody>
                        <tfoot>
                            <tr style="text-align:center">
                                <th></th>
                                <th>إجمالي الإيرادات</th>
                                {foreach $savesData as $data}
                                <th>{$data.inSum}</th>
                                {/foreach}
                                {foreach $accountsData as $acc}
                                <th>{$acc.inSum}</th>
                                {/foreach}
                            </tr>
                        </tfoot>
                    </table>

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

                    <div class="col-lg-4">
                        <div class="well-sm" style="background-color: cadetblue; color: white;">

                            <h4 class="text-center">صافي الحركة</h4>

                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <table class="table table-black dtr-inline">
                        <thead>
                            <tr style="text-align:center">
                                <th>اسم الخزينة</th>
                                <th>مدين</th>
                                <th>دائن</th>
                                <th>صافي الحركة خلال المدة</th>
                                <th>رصيد أول المدة</th>
                                <th>الرصيد الحالي</th>
                            </tr>
                        </thead>
                        <tbody>
                            {$allDebit= 0}
                            {$allCredit= 0}
                            {$allBalance = 0}
                            {$allcurrentBalance = 0}

                            {foreach $savesData as $data}
                            {$allBalance = $allBalance + $data.balance}
                            {$allcurrentBalance = $allcurrentBalance + $data.currentBalance}

                            {$debitsum= 0}
                            {$creditsum= 0}
                            {if $data.balance >= 0}
                            {$debitsum = $debitsum + $data.balance + $data.inSum}
                            {$creditsum= $creditsum+$data.outSum}
                            {$allCredit = $allCredit + $creditsum}
                            {$allDebit = $allDebit + $debitsum}
                            {else}
                            {$creditsum=$creditsum+ $data.balance + $data.outSum}
                            {$debitsum =$debitsum+ $data.inSum}
                            {$allCredit = $allCredit + $creditsum}
                            {$allDebit = $allDebit + $debitsum}
                            {/if}
                            <tr>
                                <td>{$data.savename}</td>
                                <td>
                                    {$debitsum}
                                </td>
                                <td>
                                    {$creditsum}
                                </td>
                                <td>{$debitsum - $creditsum}</td>
                                <td>{$data.balance}</td>
                                <td>{$data.currentBalance}</td>
                            </tr>
                            {/foreach}

                            {foreach $accountsData as $account}
                            {$allBalance = $allBalance + $account.balance}
                            {$allcurrentBalance = $allcurrentBalance + $account.currentBalance}

                            {$debitsum= 0}
                            {$creditsum= 0}
                            {if $account.balance >= 0}
                            {$debitsum = $debitsum + $account.balance + $account.inSum}
                            {$creditsum= $creditsum+$account.outSum}
                            {$allCredit = $allCredit + $creditsum}
                            {$allDebit = $allDebit + $debitsum}
                            {else}
                            {$creditsum=$creditsum+ $account.balance + $account.outSum}
                            {$debitsum =$debitsum+ $account.inSum}
                            {$allCredit = $allCredit + $creditsum}
                            {$allDebit = $allDebit + $debitsum}
                            {/if}
                            <tr>
                                <td>{$account.accountname} </td>
                                <td>
                                    {$debitsum}
                                </td>
                                <td>
                                    {$creditsum}
                                </td>
                                <td>{$debitsum - $creditsum}</td>
                                <td>{$account.balance}</td>
                                <td>{$account.currentBalance}</td>
                            </tr>
                            {/foreach}
                        </tbody>
                        <tfoot>
                            <tr style="text-align:center">
                                <th>إجمالي سيولة الشركة</th>
                                <th>{$allDebit}</th>
                                <th>{$allCredit}</th>
                                <th>{$allDebit - $allCredit}</th>
                                <th>{$allBalance}</th>
                                <th>{$allcurrentBalance}</th>
                            </tr>
                        </tfoot>
                    </table>

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




                    <hr />
                    <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>
                    {else}
                    <div class="nodata">عفوا لا توجد نتائج</div>
                    {/if}

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






                </div>
            </div>
            <!--<input id="ddrt" name="ddrt" value="">-->
            {literal}
            <script>
                var search = localStorage.getItem("search");
                if (search == "dateTime") {
                    $('#searchdateTime').attr('checked', 'checked');
                    $('#searchdateOnly').removeAttr('checked');
                    //
                    $('#dateTimeDiv').show();
                    $('#dateOnlyDiv').remove();
                } else {
                    $('#searchdateOnly').attr('checked', 'checked');
                    $('#searchdateTime').removeAttr('checked');
                    //
                    $('#dateOnlyDiv').show();
                    $('#dateTimeDiv').remove();
                }
                var db = Number(localStorage.getItem("db"));
                if (db == 1) {
                    $('#db').attr('checked', 'checked');
                } else {
                    $('#db').removeAttr('checked');
                }
                /*
                 //write number at input id=ddrt, mark it with sucess class @ value columns
                 $('#ddrt').on('blur', function () {
                 var val = $(this).val();
                 $('.ddrt td').each(function () {
                 if ($(this).text().trim() == val) {
                 $(this).parent().parent().addClass('success');
                 }
                 })
                 })
                 $('.ddrt').on('click', function () {
                 $(this).addClass('success');
                 })
                 */
            </script>
            {/literal}