<style>
    .solidgraytop{
        border-top-style:solid;
        border-top-color:#ddd;
    }
    .solidgrayleft{
        border-left:solid;
        border-left-width:3px;
        border-color: #ddd;
    }
    .solidgrayright{
        border-right-style:solid;
        border-right-color:#ddd;
    }
    .solidgraybottom{
        border-top-style:solid;
        border-top-color:#ddd;
    }
    .hidetop{
        border-top:hidden !important;
    }
    .hidebottom{
        border-bottom:hidden !important;
    }
    .fromaccountstyle{
        font-weight:bold;
        font-size:17px;
        color:blue;
    }
    .toaccountstyle
    {
        font-weight:bold;
        font-size:17px;
        color:purple;
    }
    .fromaccountstylesmall{
        font-weight:bold;
        font-size:15px;
        color:blue;
    }
    .toaccountstylesmall
    {
        font-weight:bold;
        font-size:15px;
        color:purple;
    }
    .dangerstyle
    {
        font-weight:bold;
        font-size:15px;
        color:red;
    }
    .mytotal{
        background-color:#ddd;
        font-weight:bold;
    }
    .nodata{
        background-color: #72B4EC;
        color: white;
        border-radius: 13px;
        margin: 14px;
        font-size: 24px;
        text-align: center;
        padding: 5px;
    }
    .showMoreStyle td{
        text-align: center;
        font-size: 12px;
        font-weight: bold;
        color: white !important;
        background-color: #6e6e6e;
        padding: 1px !important;
    }
</style>
{if $shape == 0}
<a href="javascript:;" data-shape="1" data-id="{$entry->id}" class="btn btn-info reShape">عرض بطريقة حرف T</a>
<br/>
<div style="clear:both"></div>
<br/>
<table class="table" id="dailyEntryTable">
    <thead>
        <tr class="mytotal">
            <th class="solidgrayright" style="text-align: center;border-bottom-color: white !important"></th>
            <th colspan="6" style="text-align: center;border-bottom-color: white !important">حـــــــــ/{$entry->customName}</th>
            <th class="solidgrayleft" style="text-align: center;border-bottom-color: white !important"></th>
        </tr>
        <tr class="mytotal">
            <th class="solidgrayright" style="border-top-color: white !important">التاريخ</th>
            <th style="border-top-color: white !important">بيان القيد</th>
            <th style="border-top-color: white !important">البيان</th>
            <th style="border-top-color: white !important">رقم القيد</th>
            <th style="border-top-color: white !important">مدين</th>
            <th style="border-top-color: white !important">دائن</th>
            <th style="border-top-color: white !important">اسم الحساب</th>
            <th class="solidgrayleft" width="8%" style="border-top-color: white !important">الرصيد</th>
        </tr>
    </thead>
    <tbody>
        {assign var=debtorByNature value=0}
        {assign var=cerditorByNature value=0}
        {assign var=lastid value=0}
        {foreach $allDailyEntery as $dailyEntery}
        {if $dailyEntery->id !=""}
        {assign var=lastid value=$dailyEntery->id}

        <!--عكس القيد-->
        {if $dailyEntery->reverseofid != 0 && $dailyEntery->reverseofid != -10}
        <tr class="solidgraytop" style="background-color: #FCE4EC">
            {else}
        <tr class="solidgraytop">
            {/if}




            {else}

            <!--عكس القيد-->
            {if $dailyEntery->reverseofid != 0}
        <tr style="background-color: #FCE4EC">
            {else}
        <tr>
            {/if}



            {/if}

            <td class="solidgrayleft solidgrayright">{$dailyEntery->dDateTime}</td>
            <td class="solidgrayleft solidgrayright">{$dailyEntery->entryComment}</td>
            <td class="solidgrayleft solidgrayright">{$dailyEntery->dComment}</td>
            <td class="solidgrayleft solidgrayright"><a href="dailyentry.php?id={$dailyEntery->id}" target="_blank" style="color:blue;"><u>{$dailyEntery->id}</u></a></td>




            {if $dailyEntery->type eq 0}
            <td class="solidgrayleft solidgrayright">{$dailyEntery->value}</td>
            <td class="solidgrayleft solidgrayright"></td>
            <td class="solidgrayleft solidgrayright">{$dailyEntery->accountstreeName}</td>

            {assign var=debtorByNature value=$debtorByNature + $dailyEntery->value}
            {assign var=cerditorByNature value=$cerditorByNature - $dailyEntery->value}
            {else}
            <td class="solidgrayleft solidgrayright"></td>
            <td class="solidgrayleft solidgrayright">{$dailyEntery->value}</td>
            <td class="solidgrayleft solidgrayright">{$dailyEntery->accountstreeName}</td>
            {assign var=debtorByNature value=$debtorByNature - $dailyEntery->value}
            {assign var=cerditorByNature value=$cerditorByNature + $dailyEntery->value}
            {/if}
            <td class="solidgrayleft">{if $entry->itemtype == "0"||$entry->itemtype == "3"}{$debtorByNature}{else}{$cerditorByNature}{/if}</td>

        </tr>
        {/foreach}

        {if count($allDailyEntery)>0}
        <tr class="showMore showMoreStyle" data-lid="{$lastid}"><td colspan="8"> عـــرض المزيـــد</td></tr>
        {/if}
    </tbody>
    <tfoot>
        <tr class="mytotal">
            <td class="solidgrayright"></td>
            <td class="solidgrayright"></td>
            <td colspan="6" class="solidgrayleft" style="text-align:center;"></td>

        </tr>
        <!--tr class="mytotal">
            <td class="solidgrayright"></td>
            <td class="solidgrayright"></td>
            <td>{$debtorTotal}</td>
            <td>{$creditorTotal}</td>
            <td colspan="3" class="solidgrayleft" style="text-align:center;">الاجــــــــــمــــــــــالــــــى</td>

        </tr-->
    </tfoot>
</table>
{else if $shape == 1}
<a href="javascript:;" data-shape="0" data-id="{$entry->id}" class="btn btn-info reShape">عرض يطريقة الرصيد المتحرك</a>
<br/>
<div style="clear:both"></div>
<br/>
<table class="table" id="dailyEntryTable">
    <thead>
        <tr class="mytotal">
            <th class="solidgrayright" style="text-align: right;border-bottom-color: white !important">مــن</th>
            <th colspan="6" style="text-align: center;border-bottom-color: white !important">حـــــــــ/{$entry->customName}</th>
            <th class="solidgrayleft" style="text-align: left;border-bottom-color: white !important">الــى</th>
        </tr>
        <tr class="mytotal">
            <th class="solidgrayright" style="border-top-color: white !important" width="9%">القيمة</th>
            <th style="border-top-color: white !important" width="23%">اسم الحساب</th>
            <th style="border-top-color: white !important" width="13%">التاريخ</th>
            <th style="border-top-color: white !important" width="5%">رقم القيد</th>
            <th style="border-top-color: white !important" width="9%">القيمة</th>
            <th style="border-top-color: white !important" width="23%">اسم الحساب</th>
            <th style="border-top-color: white !important" width="13%">التاريخ</th>
            <th class="solidgrayleft" style="border-top-color: white !important" width="5%">رقم القيد</th>
        </tr>
    </thead>
    <tbody>
        {assign var=debtorTotal value=0}
        {assign var=cerditorTotal value=0}
        {assign var=lastid value=0}
        {for $foo = 0 to $realCount step=2}
        {if $allDailyEntery[$foo]->accountstreeName =="" && $allDailyEntery[$foo+1]->accountstreeName ==""}
        {else}
        <tr>
            {if $allDailyEntery[$foo]->id > 0 && $allDailyEntery[$foo]->id > $lastid}    {assign var=lastid value=$allDailyEntery[$foo]->id}    {/if}
            {if $allDailyEntery[$foo+1]->id > 0 && $allDailyEntery[$foo+1]->id > $lastid}  {assign var=lastid value=$allDailyEntery[$foo+1]->id}  {/if}

            <td class="solidgrayright">{$allDailyEntery[$foo]->value}</td>
            <th>{if $allDailyEntery[$foo]->accountstreeName != ""}<span class="toaccountstylesmall">الى حــ/ </span>{/if}{$allDailyEntery[$foo]->accountstreeName}</th>
            <td >{$allDailyEntery[$foo]->dDateTime}</td>
            <td class="solidgrayleft"><a href="dailyentry.php?id={$allDailyEntery[$foo]->id}" target="_blank" style="color:blue;"><u>{$allDailyEntery[$foo]->id}</u></a></td>
            <td class="solidgrayright">{$allDailyEntery[$foo+1]->value}</td>
            <th>{if $allDailyEntery[$foo+1]->accountstreeName != ""}<span class="fromaccountstylesmall">من حــ/ </span>{/if}{$allDailyEntery[$foo+1]->accountstreeName}</th>
            <td>{$allDailyEntery[$foo+1]->dDateTime}</td>
            <td class="solidgrayleft"><a href="dailyentry.php?id={$allDailyEntery[$foo+1]->id}" target="_blank" style="color:blue;"><u>{$allDailyEntery[$foo+1]->id}</u></a></td>
        </tr>
        {assign var=debtorTotal value=$debtorTotal + $allDailyEntery[$foo]->value}
        {assign var=cerditorTotal value=$cerditorTotal + $allDailyEntery[$foo+1]->value}
        {/if}
        {/for}

    </tbody>
    <tfoot>
        {if $cerditorTotal-$debtorTotal != 0}
        <tr class="netRow">
            <td class="solidgrayright">{if $cerditorTotal-$debtorTotal>0}<span class="dangerstyle netRight">{$cerditorTotal-$debtorTotal}</span>{/if}</td>
            <th colspan="2">{if $cerditorTotal-$debtorTotal>0}<span class="dangerstyle">رصيد دائن</span>{/if}</th>
            <td class="solidgrayleft"></td>
            <td class="solidgrayright">{if $debtorTotal-$cerditorTotal>0}<span class="dangerstyle netLeft">{$debtorTotal-$cerditorTotal}</span>{/if}</td>
            <th colspan="2">{if $debtorTotal-$cerditorTotal>0}<span class="dangerstyle">رصيد مدين</span>{/if}</th>
            <td class="solidgrayleft"></td>
        </tr>
        {/if}


        <tr class="mytotal mytotalRow">
            <td class="solidgrayright totalRight">{if $cerditorTotal-$debtorTotal>0}{$cerditorTotal}{else}{$debtorTotal}{/if}</td>
            <th colspan="2"></th>
            <td class="solidgrayleft"></td>
            <td class="solidgrayright totalLeft">{if $cerditorTotal-$debtorTotal>0}{$cerditorTotal}{else}{$debtorTotal}{/if}</td>
            <th colspan="2"></th>
            <td class="solidgrayleft"></td>

        </tr>

        {if count($allDailyEntery)>0}
        <tr class="showMore showMoreStyle" data-lid="{$lastid}"><td colspan="8"> عـــرض المزيـــد</td></tr>
        {/if}
    </tfoot>
</table>
{/if}

{literal}
<script>
    $('.showMore').live('click', function () {
        var btn = $(this);
        if (!btn.hasClass('processing...')) {
            btn.addClass('processing...');

            var id = $('.reShape').first().attr('data-id');
            var shape = $('.reShape').first().attr('data-shape');
            if (shape == 0)
                shape = 1;
            else
                shape = 0;
            var lastId = $(this).attr('data-lid');
            $.ajax({
                url: 'accountstreeajax.php?do=getdetaillimited',
                type: "post",
                data: {id: id, shape: shape, lastId: lastId},
                //async: false,
                success: function (data) {
                    $('.showMore').remove();
                    $('#dailyEntryTable tbody').append(data);
                    if (shape == 1) {
                        //////////////////////////////////////////////////////////////////////////////////////////
                        //calc total
                        var totalRight = 0;
                        var totalLeft = 0;

                        $('.totalRight').each(function () {
                            totalRight += Number($(this).html());
                        });
                        $('.totalLeft').each(function () {
                            totalLeft += Number($(this).html());
                        });

                        $('.mytotalRow').remove();
                        let totalrow = '<tr class="mytotal mytotalRow">' +
                                '     <td class="solidgrayright totalRight">' + totalRight + '</td>' +
                                '     <th colspan="2"></th>' +
                                '     <td class="solidgrayleft"></td>' +
                                '     <td class="solidgrayright totalLeft">' + totalLeft + '</td>' +
                                '     <th colspan="2"></th>' +
                                '     <td class="solidgrayleft"></td>' +
                                ' </tr>';
                        $('#dailyEntryTable tfoot').prepend(totalrow);
                        //////////////////////////////////////////////////////////////////////////////////////////
                        // calc net
                        var netRight = 0;
                        var netLeft = 0;

                        $('.netRight').each(function () {
                            netRight += Number($(this).html());
                        });
                        $('.netLeft').each(function () {
                            netLeft += Number($(this).html());
                        });

                        $('.netRow').remove();
                        if (netLeft != netRight) {
                            let netrow = '';
                            if ((netRight - netLeft) > 0)
                                netrow = '<tr class="netRow">' +
                                        '      <td class="solidgrayright"><span class="dangerstyle netRight">' + (netRight - netLeft) + '</span></td>' +
                                        '      <th colspan="2"><span class="dangerstyle">رصيد دائن</span></th>' +
                                        '      <td class="solidgrayleft"></td>' +
                                        '      <td class="solidgrayright"></td>' +
                                        '      <th colspan="2"></th>' +
                                        '      <td class="solidgrayleft"></td>' +
                                        '  </tr>';
                            else
                                netrow = '<tr class="netRow">' +
                                        '      <td class="solidgrayright"></td>' +
                                        '      <th colspan="2"></th>' +
                                        '      <td class="solidgrayleft"></td>' +
                                        '      <td class="solidgrayright"><span class="dangerstyle netLeft">' + (netLeft - netRight) + '</span></td>' +
                                        '      <th colspan="2"><span class="dangerstyle">رصيد مدين</span></th>' +
                                        '      <td class="solidgrayleft"></td>' +
                                        '  </tr>';
                            $('#dailyEntryTable tfoot').prepend(netrow);
                        }
                        //////////////////////////////////////////////////////////////////////////////////////////
                        $('.showMoreStyle').clone().appendTo('#dailyEntryTable tfoot');
                        $('.showMoreStyle').first().remove();
                    }
                }
            });
        }
    });
</script>
{/literal}