<section class="content-header">
    <div class="container-fluid">
        <div id="flash" data-flash="<?= $this->session->flashdata('success'); ?>"></div>
        <div class="row ">
            <div class="col-sm-12">
                <h1>LAP.KEUANGAN - Rugi / Laba </h1>
            </div>
        </div>
    </div>
</section>

<div id="flash" data-flash="<?= $this->session->flashdata('success'); ?>"></div>

<section class="content">

    <!-- start pencarian -->
    <div class="container-fluid">
        <form action="" method="get">
            <div class="row mb-3 ">
                <div class="col-12">
                    <?php if (isset($_GET['tgl'])) {
                        $tgl = $_GET['tgl'];
                    } else {
                        $tgl = null;
                    } ?>
                    <div class="input-group align-center">
                        <div class="input-group-prepend">
                            <span class="input-group-text"><i class="fas fa-warehouse"></i></span>
                        </div>
                        <input id="datepickerbulan" placeholder="Pilih Tanggal Arsip" name="tgl" type="text" class="form-control " value="<?= $tgl = $tgl ? $tgl : date('m / Y') ?>" autocomplete="off">

                        <div style="width: 100px" class="input-group-prepend">
                            <button type="submit" class="btn btn-outline-secondary w-100">Pilih</button>
                        </div>
                    </div>
                </div>
        </form>
    </div>
    <!-- ending pencarian -->

    <div class="row">
        <div class="col-12 col-md-12 col-sm-12">
            <div class="input-group align-center">
                <div class="input-group-prepend">
                    <span class="input-group-text mb-2">Invoice</span>
                </div>
                <input name="inov_lbbc" readonly="on" value="<?= $invoice_rlcab ?>" class=" mb-2 form-control form-control-lg" type="text">
            </div>
        </div>

        <div class="col-12 col-md-12 col-sm-12">
            <div class="card border-left-primary ">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Pendapatan (&nbsp;<?= $tgl ?>&nbsp;)</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?= indo_currency($totpenga) ?>
                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-coins fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-12 col-sm-12">
            <div class="card border-left-primary ">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Gaji Karyawan (&nbsp;<?= $tgl ?>&nbsp;)</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?= indo_currency($totgaji) ?>
                            </div>

                            <span class=" float-right mt-2 badge badge-primary p-1"> Gaji Karyawan </span>
                            <table class='table table-sm mt-4'>
                                <?php $i = 1; ?>
                                <?php foreach ($perlcabgaji->result() as $am => $data) : ?>
                                    <tbody>
                                        <tr>
                                            <td scope="row"><?= $i; ?>.</td>
                                            <td><?= $data->nama ?></td>
                                            <td><?= $data->pekerjaan ?></td>
                                            <td><?= $data->gaji ?></td>
                                        </tr>
                                    </tbody>
                                    <?php $i++; ?>

                                <?php endforeach ?>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-12 col-sm-12">
            <div class="card border-left-primary ">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <button class="btn btn-secondary float-right  mb-2 " data-toggle="modal" data-target="#pengeluaranrlcab"><i class="fas fa-plus fa-1x text-gray-300"></i></button>

                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Operasional (&nbsp;<?= $tgl ?>&nbsp;)</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?= indo_currency($totpengrl) ?>
                            </div>

                            <span class=" float-right mt-2 badge badge-primary p-1"> Operasial Tempat </span>
                            <table class='table table-sm mt-4'>
                                <?php $i = 1; ?>
                                <?php foreach ($perlcab->result() as $am => $data) : ?>
                                    <tbody>
                                        <tr>
                                            <td scope="row"><?= $i; ?>.</td>
                                            <td><a id="btn-hapus" href="<?= site_url('lapkeucabrl/delpenrlcab/' . $data->id_pengrlcab) ?>">
                                                    [ <i class="fas fa-trash-alt"></i>
                                                </a> ]</td>

                                            <td><?= $data->inov_pengrlcab ?></td>
                                            <td><?= $data->peng_rlcab ?></td>
                                            <td><?= $data->harga_rlcab ?></td>
                                        </tr>
                                    </tbody>
                                    <?php $i++; ?>

                                <?php endforeach ?>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-12 col-sm-12">
            <div class="card border-left-primary ">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Total Pendapatan Bersih(&nbsp;<?= $tgl ?>&nbsp;)</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?= indo_currency($totpenga - ($totpengrl + $totgaji)) ?>
                            </div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-coins fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-12 col-sm-12 mb-3">
            <form action="<?= base_url('lapkeucabrl/addpengnercab'); ?>" method="post">

                <?php $tot = $totpenga - ($totpengrl + $totgaji) ?>
                <input readonly="on" type='hidden' class='form-control' value='<?= $invoice_rlcab ?>' name="invoice_inv">
                <input readonly="on" type='hidden' class='form-control' value='<?= $totpenga ?>' name="inv_omset">
                <input readonly="on" type='hidden' class='form-control' value='<?= $totpengrl ?>' name="inv_peng">
                <input readonly="on" type='hidden' class='form-control' value='<?= $totgaji ?>' name="inv_gaji">

                <input readonly="on" type='hidden' class='form-control' value='<?= $tot ?>' name="inv_tot">
                <input readonly="on" type='hidden' class='form-control' value='<?= date('m / Y') ?>' name="inv_bln">
                <input readonly="on" type='hidden' class='form-control' value='<?= date('Y') ?>' name="inv_th">
                <?= $tgl > 0 ? '
                <button class="btn btn-lg btn-primary w-100  mt-2" type="submit">Simpan Laporan Rugi Laba</button>
                '
                    :
                    null
                ?>
            </form>

        </div>




    </div>





    <!-- Modal Pengeluaran R/L Cabang-->

    <form action="<?= base_url('lapkeucabrl/addpengrlcab'); ?>" method="post">
        <div class="modal fade bd-example-modal-lg" id="pengeluaranrlcab" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered " role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterTitle">Foam Pengeluaran R/L Cabang</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class='row'>

                            <div class='col-lg-6 ' style="font-size: 13px">
                                <label class=" text-black-100 mt-2"><i class="fas fa-keyboard"></i>&nbsp; Tanggal </label>
                                <div class='input-group'>
                                    <input readonly="on" type='text' class='form-control' value='<?php echo date('m / Y') ?>' name="bln_pengrlcab" autocomplete="off" required>
                                </div>
                            </div>

                            <div class='col-lg-6 ' style="font-size: 13px">
                                <label class=" text-black-100 mt-2"><i class="fas fa-keyboard"></i>&nbsp; Inovoice Pengeluaran R/L </label>
                                <div class='input-group'>
                                    <input readonly="on" type='text' class='form-control' value='<?= $pengrlcab ?>' name="inov_pengrlcab">
                                </div>
                            </div>

                            <div class='col-lg-12 ' style="font-size: 13px">
                                <label class=" text-black-100 mt-2"><i class="fas fa-keyboard"></i>&nbsp; Nama Pengeluaran </label>
                                <div class='input-group'>
                                    <select name="peng_rlcab" required class="form-control">
                                        <option value="">- Pilih Pengeluaran -</option>
                                        <option value="Biaya Listrik">Biaya Listrik</option>
                                        <option value="Biaya Internet">Biaya Internet</option>
                                        <option value="Biaya Iuran Sampah">Biaya Iuran Sampah</option>
                                        <option value="Sewa Server">Sewa Server</option>
                                    </select>
                                </div>
                            </div>
                            <div class='col-lg-12 ' style="font-size: 13px">
                                <label class=" text-black-100 mt-2"><i class="fas fa-keyboard"></i>&nbsp; Biaya </label>
                                <div class='input-group'>
                                    <input type='text' class='form-control' value='' name="harga_rlcab" autocomplete="off" required>
                                </div>
                            </div>
                            <div class='col-lg-12 ' style="font-size: 13px">
                                <label class=" text-black-100 mt-2"><i class="fas fa-keyboard"></i>&nbsp; Reverensi Note </label>
                                <div class='input-group'>
                                    <input type='text' class='form-control' value='' name="note_rlcab" autocomplete="off" required>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-secondary w-100">Tambah Biaya Pengeluaran</button>
    </form>

</section>