



<?php $__env->startSection('title', 'Daily Sales Reports'); ?>


<?php $__env->startSection('internal-js'); ?>
    <script>
        $(document).ready(function () {
            $('#insurers1').DataTable( {
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons'},
                ],
                footerCallback: function ( row, data, start, end, display ) {
                    var api = this.api(), data;
                    var numberRenderer = $.fn.dataTable.render.number(',', '.', 2).display;

                    // Remove the formatting to get integer data for summation
                    var intVal = function ( i ) {
                        return typeof i === 'string' ? i.replace(/[\.]/g, '.').replace(/[\,]/g, '') * 1 : typeof i === 'number' ? i : 0;
                    };

                    //Comm Amount
                    totalSalesCount = api.column( 3 ).data().reduce( function (a, b) { return intVal(a) + intVal(b)}, 0 );
                    currentSalesCount = api.column( 3, { page: 'current'} ).data().reduce( function (a, b) { return intVal(a) + intVal(b)}, 0 );
                    // Update Footer - Sale Amount
                    $( api.column( 3 ).footer() ).html(currentSalesCount +'<br>('+ totalSalesCount +')').css('color', 'blue');

                    //Comm Amount
                    totalSalesAmount = api.column( 4 ).data().reduce( function (a, b) { return intVal(a) + intVal(b)}, 0 );
                    currentSalesAmount = api.column( 4, { page: 'current'} ).data().reduce( function (a, b) { return intVal(a) + intVal(b)}, 0 );
                    // Update Footer - Sale Amount
                    $( api.column( 4 ).footer() ).html(numberRenderer(currentSalesAmount) +'<br>('+ numberRenderer(totalSalesAmount) +')').css('color', 'blue');

                    <?php if(auth()->user()->admin == 1): ?>
                    //PROFIT SECTION
                    totalProfitAmount = api.column( 6 ).data().reduce( function (a, b) { return intVal(a) + intVal(b)}, 0 );
                    currentProfitAmount = api.column( 6, { page: 'current'} ).data().reduce( function (a, b) { return intVal(a) + intVal(b)}, 0 );
                    // Update Footer - Sale Amount
                    $( api.column( 6 ).footer() ).html(numberRenderer(currentProfitAmount) +'<br>('+ numberRenderer(totalProfitAmount) +')').css('color', 'blue');
                    <?php endif; ?>
                },
            } );


            $('#date-from').on('change', function (){
                $('#date-to').attr('required', true);
            });
            $('#date-to').on('change', function (){
                $('#date-from').attr('required', true);
            });
        });
        
        function viewSoldItems(id){
            var route_link = '/view-sold-items-on-receipt/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
                .load(encodeURI(route_link))
                .dialog({
                    modal: true,
                    width: 600,
                    title: "View Sold items on the Selected  Receipt",
                    open: function() {
                        $(this).parent().css({'top': 50});
                    }
                });
        }
    </script>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('internal-css'); ?>
    <style>
        #insurers1 tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        #insurers1 th, td {
            text-align: left;
            padding: 5px;
        }
        #insurers1 tr:hover {background-color: #d8d9e1;}
    </style>

<?php $__env->stopSection(); ?>


<?php $__env->startSection('headers'); ?>
    <?php echo $__env->make('headers.inventory-header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('heading', 'Daily Sales Report'); ?>
<?php $__env->startSection('done-by', ''); ?>


<?php $__env->startSection('content'); ?>
    <div class="inputDivider" style="margin-top: 10px; text-align: left; background-color: lightcyan">
        <?php echo Form::open(['action'=>['Modules\InventoryDashboardController@showSalesReport'], 'method'=>'POST', 'id'=>'filter-sales-report', 'class'=>'fields-small']); ?>

        <div class="guestDetails_input_right">
            <div class="guestDetails_inputLabel">
                &nbsp;
            </div>
            <div class="guestDetails_input_right">
                <button type="submit" name="search" style="cursor: pointer"><i class="fa fa-search" aria-hidden="true"></i></button>
            </div>
        </div>
        <div class="guestDetails_input_right">
            <div class="guestDetails_inputLabel">
                Date Added To:<span class="error">*</span>
            </div>
            <div class="guestDetails_input_right">
                <input type="datetime-local" id="date-to" name="to"  class="input-text-height" value="<?php echo e($search['to'] ?? date('Y-m-d H:i')); ?>">
            </div>
        </div>
        <div class="guestDetails_input_right">
            <div class="guestDetails_inputLabel">
                Date Added From:<span class="error">*</span>
            </div>
            <div class="guestDetails_input_right">
                <input type="datetime-local" id="date-from" name="from"  class="input-text-height" value="<?php echo e($search['from'] ?? date('Y-m-d H:i')); ?>">
            </div>
        </div>
        <div class="guestDetails_inputDividerNone" style="height: 0"></div>
        <?php echo Form::close(); ?>

    </div>
    <div class="guestDetails_inputDivider"></div>
    <!--View and Setup your Insurers-->
    <div>
        <!--Export Links/Buttons-->
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <table id="insurers1" style="width: 100%; border-collapse: collapse; ">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Item Name.</th>
                <th>Unit Sell Price</th>
                <th>Quantity</th>
                <th>Total Amount Paid</th>
                <?php if(auth()->user()->admin == 1): ?>
                    <th>Unit Buy Price</th>
                    <th>Profit Made</th>
                <?php endif; ?>
                <th>Mode</th>
                <th>REF</th>
                <th>Date Sold</th>
                <th>User</th>
                <th>View Receipt</th>
            </tr>
            </thead>
            <tbody>
            <?php $__currentLoopData = $list; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if($row->item): ?>
                    <tr>
                        <td class="ar"></td>
                        <td><b class="error"><?php echo strtoupper($row->item->name); ?></b></td>
                        <td><?php echo number_format($row->unit_price_sell,2); ?></td>
                        <td style="font-weight: bold" class="error"><?php echo e(abs($row->quantity)); ?></td>
                        <td style="font-weight: bold"><?php echo number_format($row->total_price_sell,2); ?></td>
                        <?php if(auth()->user()->admin == 1): ?>
                            <td><?php echo number_format($row->unit_price_buy,2); ?></td>
                            <td style="font-weight: bold" class="success"><?php echo number_format($row->profit,2); ?></td>
                        <?php endif; ?>
                        <?php if($row->receipt): ?>
                            <td><?php if($row->receipt->modeOfPayment != null): ?>
                                    <?php echo $row->receipt->modeOfPayment->name; ?>

                                    <?php if($row->receipt->subModeOfPayment != null): ?>
                                        - <?php echo $row->receipt->subModeOfPayment->name; ?>

                                    <?php endif; ?>
                                <?php endif; ?></td>
                            <td><?php echo $row->receipt->ref; ?></td>
                        <?php else: ?>
                            <td></td>
                            <td></td>
                        <?php endif; ?>
                        <td><?php echo date('d/m/Y H:i:s a', strtotime($row->created_at)); ?></td>
                        <td>
                            <?php if($row->user): ?>
                                <?php echo $row->user->firstName." ".$row->user->lastName; ?>

                            <?php endif; ?>
                        </td>
                        <td><i class="fa fa-eye error" onclick="viewSoldItems('<?php echo e($row->invoice_id); ?>')" style="cursor: pointer; font-size: 14px" title="Click to View Receipt"></i></td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Item Name.</th>
                <th>Unit Sell Price</th>
                <th>Quantity</th>
                <th>Total Amount Paid</th>
                <?php if(auth()->user()->admin == 1): ?>
                    <th>Unit Buy Price</th>
                    <th>Profit Made</th>
                <?php endif; ?>
                <th>Mode</th>
                <th>REF</th>
                <th>Date Sold</th>
                <th>User</th>
                <th>View Receipt</th>
            </tr>
            </tfoot>
        </table>

    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('modal_heading'); ?>
    <h1>Sales Report</h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <ol><b>
            <li>View Sales per a Specified Period</li>
            <li>Filter through available Sales Reports</li>
            <li>Export Sales Report</li>
        </b>
    </ol>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/zedarroot/public_html/edwulp/resources/views/inventory/daily-sales.blade.php ENDPATH**/ ?>