<ol class="breadcrumb">
    <li><a href="accSetupController.php">نظام المحاسبة</a></li>
    <li class="active">دفتر الأستاذ العام</li>
</ol>

<div class="panel panel-default panel-m">
    <div class="panel-heading">
        <h3 class="panel-title">دفتر الأستاذ العام</h3>
    </div>
    <div class="panel-body">

        <div class="row noprint" style="margin-bottom:15px;">
            <form method="get" action="accLedgerReportController.php" class="form-inline">
                <input type="hidden" name="do" value="report">
                <div class="form-group">
                    <label>الحساب</label>
                    <select name="account_id" class="select2 wdt100" data-placeholder="اختر الحساب" style="width:250px;">
                        <option value=""></option>
                        {foreach $accounts as $acc}
                        <option value="{$acc.id}" {if $acc.id == $account_id}selected{/if}>{$acc.code} - {$acc.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="form-group">
                    <label>السنة المالية</label>
                    <select name="fiscal_year_id" class="form-control">
                        {foreach $fiscalYears as $fy}
                        <option value="{$fy.id}" {if $fy.id == $fiscal_year_id}selected{/if}>{$fy.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="form-group">
                    <label>من</label>
                    <input type="text" name="date_from" class="form-control datepicker" value="{$date_from}">
                </div>
                <div class="form-group">
                    <label>إلى</label>
                    <input type="text" name="date_to" class="form-control datepicker" value="{$date_to}">
                </div>
                <button type="submit" class="btn btn-success">بحث</button>
            </form>
        </div>

        <div class="noprint" style="margin-bottom:10px;">
            <button onclick="window.print();" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-print"></i> طباعة</button>
            <a href="accLedgerReportController.php?do=exportExcel&account_id={$account_id}&fiscal_year_id={$fiscal_year_id}&date_from={$date_from}&date_to={$date_to}" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-download"></i> Excel</a>
            <button onclick="window.print();" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-file"></i> PDF</button>
        </div>

        {if $account_id}
        <h4>حساب: {$account.code} - {$account.name}</h4>
        <table class="table table-striped table-bordered table-hover dataTableClass">
            <thead>
                <tr>
                    <th>التاريخ</th>
                    <th>رقم القيد</th>
                    <th>البيان</th>
                    <th>مدين</th>
                    <th>دائن</th>
                    <th>الرصيد</th>
                </tr>
            </thead>
            <tbody>
                <tr class="info">
                    <td colspan="3"><strong>رصيد أول المدة</strong></td>
                    <td></td>
                    <td></td>
                    <td><strong>{$openingBalance}</strong></td>
                </tr>
                {foreach $journalLines as $row}
                <tr>
                    <td>{$row.entry_date}</td>
                    <td><a href="accJournalController.php?do=view&id={$row.journal_entry_id}">{$row.entry_no}</a></td>
                    <td>{$row.journal_description}</td>
                    <td>{$row.debit}</td>
                    <td>{$row.credit}</td>
                    <td>{$row.running_balance}</td>
                </tr>
                {/foreach}
            </tbody>
        </table>
        {/if}

    </div>
</div>
