<style>
    .borderleft{
        border-left: 2px solid #ddd;
    }
</style>
<div class="row">
    <div class="container">
        <!--show-------------------------------------------------------------------------------------------->
        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <h3 class="panel-title"><strong> ميزان المراجعة الشهرى</strong></h3>
                <a href="{$youtubes[222]->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="monthlytrialbalance.php?do=monitor" method="post">
                    <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>

                    <button type="submit" class="btn btn-primary">بحث</button>

                </form>
                <p>{$msg}</p>
                <hr/>

                <div class="form-group">
                    <input type="checkbox" name="bure" id="bure" checked="checked" value="1">
                    <label class="sr-only"> اخفاء الاجمالى صفر</label>

                    <input type="checkbox" name="hidemonths" id="hidemonths" value="1">
                    <label class="sr-only"> اخفاء نتائج الشهور</label>
                </div>
                <div id="dailyEntryTable" style="overflow-x: scroll">

                    <table class="table table-black">
                        <thead>
                            <tr class="mytotal">
                                <th rowspan="2" class="solidgrayright">#</th>
                                <th rowspan="2">الكود</th>
                                <th rowspan="2" style="min-width: 250px">الحساب</th>

                                <th colspan="2" style="min-width:150px;text-align: center" class="borderleft months">رصيد اول المدة</th>
                                {foreach $months as $month}
                                <th class="months borderleft" colspan="2" style="min-width:150px;text-align: center">{$month}</th>
                                {/foreach}
                                <th colspan="2" style="min-width:150px;text-align: center" class="borderleft months">الاجمالى</th>
                                <th colspan="2" style="min-width:150px;text-align: center" class="borderleft">قيم ميزان المراجعه</th>
                                <th colspan="2" style="min-width:150px;text-align: center" class="borderleft">رصيد الشجره</th>
                                <th style="min-width:150px;text-align: center" class="borderleft">قيم البرنامج</th>
                            </tr>
                            <tr class="mytotal">
                                <th class="months">مدين</th>
                                <th class="borderleft months">دائن</th>
                                {foreach $months as $month}
                                <th class="months">مدين</th>
                                <th class="months borderleft">دائن</th>
                                {/foreach}
                                <th class="months">مدين</th>
                                <th class="borderleft months">دائن</th>
                                <th>مدين</th>
                                <th class="borderleft">دائن</th>
                                <th>مدين</th>
                                <th class="borderleft">دائن</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=netDebt value=0}
                            {assign var=netCredit value=0}
                            {assign var=sumDebt2 value=0}
                            {assign var=sumCredit2 value=0}
                            {assign var=i value=1}
                            {foreach $balanceArray as $data}
                            <tr>
                                <td>{$i}</td>
                                <td>{$data->layingOrder}</td>
                                <td>{$data->customName}</td>

                                <th class="months">{$data->firstPeriodDebtor}</th>
                                <th class="borderleft months">{$data->firstPeriodCreditor}</th>
                                {assign var=totMonthsDebt value=$data->firstPeriodDebtor}
                                {assign var=totMonthsCredit value=$data->firstPeriodCreditor}
                                {assign var=m value=1}
                                {foreach $months as $month}
                                <th class="months">{$data->theValue2[$month]['debt']}</th>
                                <th class="months borderleft">{$data->theValue2[$month]['credit']}</th>
                                {assign var=m value=$m+1}
                                {assign var=totMonthsDebt value=$totMonthsDebt+$data->theValue2[$month]['debt']}
                                {assign var=totMonthsCredit value=$totMonthsCredit+$data->theValue2[$month]['credit']}
                                {/foreach}

                                <th class="months">{$totMonthsDebt}</th>
                                <th class="borderleft months">
                                    {$totMonthsCredit}
                                    <input type="hidden" id="iszero{$i}" class="iszeroClass" data-itr="{$i}" value="{if $totMonthsDebt == 0 && $totMonthsCredit == 0}1{else}0{/if}">
                                </th>
                                {assign var=calcBalance value=0}
                                <th>
                                    {if $totMonthsDebt > $totMonthsCredit}
                                    {$totMonthsDebt-$totMonthsCredit}

                                    {if  $data->islastLeaf == 1}
                                    {assign var=netDebt value=$netDebt + ($totMonthsDebt-$totMonthsCredit)}{assign var=calcBalance value=$totMonthsDebt-$totMonthsCredit}
                                    {/if}
                                    {if (($showClientsAtTree == 0 && ($data->id == 58 || $data->id == 60)) || ($showSuppliersAtTree == 0 && ($data->id == 81 || $data->id == 87))) }
                                    {assign var=netDebt value=$netDebt + ($totMonthsDebt-$totMonthsCredit)}
                                    {assign var=calcBalance value=$totMonthsDebt-$totMonthsCredit}
                                    {/if}


                                    {/if}


                                </th>
                                <th class="borderleft">
                                    {if $totMonthsCredit > $totMonthsDebt}
                                    {$totMonthsCredit-$totMonthsDebt}

                                    {if  $data->islastLeaf == 1}{assign var=netCredit value=$netCredit + ($totMonthsCredit-$totMonthsDebt)}{assign var=calcBalance value=$totMonthsCredit-$totMonthsDebt}{/if}
                                    {if (($showClientsAtTree == 0 && ($data->id == 58 || $data->id == 60)) || ($showSuppliersAtTree == 0 && ($data->id == 81 || $data->id == 87))) }
                                    {assign var=netCredit value=$netCredit + ($totMonthsCredit-$totMonthsDebt)}
                                    {assign var=calcBalance value=$totMonthsCredit-$totMonthsDebt}
                                    {/if}


                                    {/if}
                                </th>
                                <th {if $calcBalance != abs($data->theValue) || ($data->accountNature == 0 && $data->theValue > 0 && $totMonthsCredit > $totMonthsDebt) ||
                                    ($data->accountNature == 1 && $data->theValue > 0 && $totMonthsCredit < $totMonthsDebt)
                                    }style="color:red"{/if}>
                                    {if $data->islastLeaf == 1 }
                                    {if $data->accountNature == 0 && $data->theValue >= 0 || $data->accountNature == 1 && $data->theValue <= 0}{abs($data->theValue)}
                                    {assign var=sumDebt2 value=$sumDebt2+abs($data->theValue)}
                                    {/if}
                                    {/if}
                                    <!-- as it is not leaf but has to be summed is clients are hidden or suppliers are hidden -->
                                    {if (($showClientsAtTree == 0 && ($data->id == 58 || $data->id == 60)) || ($showSuppliersAtTree == 0 && ($data->id == 81 || $data->id == 87))) }
                                    {if $data->accountNature == 0 && $data->theValue >= 0 || $data->accountNature == 1 && $data->theValue <= 0}{abs($data->theValue)}
                                    {assign var=sumDebt2 value=$sumDebt2+abs($data->theValue)}
                                    {/if}
                                    {/if}
                                </th>



                                <th {if $calcBalance != abs($data->theValue) || ($data->accountNature == 0 && $data->theValue > 0 && $totMonthsCredit > $totMonthsDebt) ||
                                    ($data->accountNature == 1 && $data->theValue > 0 && $totMonthsCredit < $totMonthsDebt)
                                    }style="color:red"{/if} class="borderleft">
                                    {if $data->islastLeaf == 1 }
                                    {if $data->accountNature == 1 && $data->theValue > 0 || $data->accountNature == 0 && $data->theValue < 0}{abs($data->theValue)}
                                    {assign var=sumCredit2 value=$sumCredit2+abs($data->theValue)}
                                    {/if}
                                    {/if}

                                    <!-- as it is not leaf but has to be summed is clients are hidden or suppliers are hidden -->
                                    {if (($showClientsAtTree == 0 && ($data->id == 58 || $data->id == 60)) || ($showSuppliersAtTree == 0 && ($data->id == 81 || $data->id == 87))) }
                                    {if $data->accountNature == 1 && $data->theValue > 0 || $data->accountNature == 0 && $data->theValue < 0}{abs($data->theValue)}
                                    {assign var=sumCredit2 value=$sumCredit2+abs($data->theValue)}
                                    {/if}
                                    {/if}
                                </th>

                                <th class="borderleft">
                                    {$data->theValue3}
                                </th>
                            </tr>
                            {assign var=i value=$i+1}
                            {/foreach}
                            <tr style="background-color: gray">
                                <td colspan="3" style="text-align: center">الاجــمــالــى</td>

                                <td class="months">{$totalsArr['firstPeriodDebtor']}</td>
                                <td class="months">{$totalsArr['firstPeriodCreditor']}</td>

                                {assign var=allDebtTot value=$totalsArr['firstPeriodDebtor']}
                                {assign var=allCreditTot value=$totalsArr['firstPeriodCreditor']}
                                {assign var=m value=1}
                                {foreach $months as $month}
                                <td class="months">{$totalsArr[{$month}]['debt']}</td>
                                <td class="months">{$totalsArr[{$month}]['credit']}</td>

                                {assign var=allDebtTot value=$allDebtTot + {$totalsArr[{$month}]['debt']}}
                                {assign var=allCreditTot value=$allCreditTot + {$totalsArr[{$month}]['credit']}}

                                {assign var=m value=$m+1}
                                {/foreach}

                                <td class="months">{$allDebtTot}</td>
                                <td class="months">{$allCreditTot}</td>
                                <td>{$netDebt}</td>
                                <td>{$netCredit}</td>
                                <td>{$sumDebt2}</td>
                                <td>{$sumCredit2}</td>
                                <td>{$sumProgram}</td>


                            </tr>
                        </tbody>
                    </table>

                </div>
                </br>
            </div>
        </div>
    </div>
</div>






{literal}
<script>
    $(function () {

        $('#bure').live('change', function () {
            $('.iszeroClass').each(function () {
                var itr = $(this).data('itr');
                if ($('#bure').is(':checked') && $(this).val() == 1) {
                    $('#iszero' + itr).parent().parent().hide();
                } else {
                    $('#iszero' + itr).parent().parent().show();
                }
            })
        });
        $('#bure').change();
        $('#hidemonths').live('change', function () {
            if ($('#hidemonths').is(':checked')) {
                $('.months').addClass('hidden');
            } else {
                $('.months').removeClass('hidden');
            }
        });


    });

</script>
{/literal}