<?php $__env->startSection('content'); ?>
<?php $__env->startSection('title','بيان ارباح فعلى'); ?>
<section class="content-header">
	<h1>
		تقرير الارباح الفعلى
		<small>
			  على ما تم تحصيله من العملاء
		</small>
		<a class="btn print-window pull-right" href="javascript:void(0)" onclick="window.print()" role="button">
			<i class="fa fa-print" aria-hidden="true"></i>
		</a>
	</h1>
</section>
<section class="content">
	<div class="box box-primary">
		<?php echo $__env->make('layouts.partial.filter', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
		<?php echo $__env->make('layouts.partial.printHeader',['showCompanyData'=>true], array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
		<div class="row">
			<div class="col-md-12">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>#</th>
							<th>الإسم</th>
							<th><?php echo app('translator')->getFromJson('front.percentage'); ?></th>
                            <th><?php echo app('translator')->getFromJson('front.total profits'); ?></th>
							<th><?php echo app('translator')->getFromJson('front.general expenses'); ?></th>
                            <th><?php echo app('translator')->getFromJson('front.grand profit'); ?></th>
							<th><?php echo app('translator')->getFromJson('front.parteners expenses'); ?></th>
                            <th><?php echo app('translator')->getFromJson('front.partner profit'); ?></th>
                            <th>صافى ربح الشريك</th>
						</tr>
					</thead>
					<tbody>
						<?php
							$from= request()->fromdate;
							$to= request()->todate;
						?>
						<?php $__currentLoopData = $partners; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $partner): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
							<?php
								$sptialExpenses = $partner->expenses();
								if($from){
									$sptial = $sptialExpenses->whereRaw("DATE(created_at) >= '{$from}'")
									->sum('value');
								}
								if($to){
									$sptial = $sptialExpenses->whereRaw("DATE(created_at) <= '{$to}'")->sum('value');
								}
								if(empty($from) && empty($to)){
									$sptial = $sptialExpenses->sum('value');
								}
                                $percent = optional($partner->firststore)->percent??0;
                                $gExpenses = 0;
                                $totalProfit = $ordersProfit;
								if($settings['subtract_expenses_profit']==1){
                                    $gExpenses = $generalExpenses*($percent/100);
								}else{
                                    $totalProfit -= $generalExpenses;
								}
								$grandP = $ordersProfit-$generalExpenses;
								$partnerProfit = $grandP * ($percent/100);
								$final = $partnerProfit - $sptial;
							?>
							<tr>
								<td><?php echo e($loop->iteration); ?></td>
								<td><?php echo e($partner->name); ?></td>
								<td><?php echo e($percent); ?> %</td>
                                <?php if($loop->iteration==1): ?>
                                    <td class="bg-green rowTd" rowspan="<?php echo e(count($partners)); ?>"><?php echo e(currency(round($ordersProfit,2),currency()->config('default'),currency()->config('default'), true)); ?></td>
                                    <td class="bg-red rowTd" rowspan="<?php echo e(count($partners)); ?>"><?php echo e(currency(round($generalExpenses,2),currency()->config('default'),currency()->config('default'), true)); ?></td>
                                    <td class="bg-primary rowTd" rowspan="<?php echo e(count($partners)); ?>"><?php echo e(currency(round($grandP,2),currency()->config('default'),currency()->config('default'), true)); ?></td>
                                <?php endif; ?>
								<td><?php echo e($sptial); ?></td>
								<td class="warning"><?php echo e(currency($partnerProfit,currency()->config('default'),currency()->config('default'), true)); ?></td>
								<td class="success"><?php echo e(currency($final,currency()->config('default'),currency()->config('default'), true)); ?></td>
							</tr>
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
					</tbody>
				</table>
			</div>
            <div class="col-md-12">
                <?php if($settings['subtract_expenses_profit']==2): ?>
                    <div class="bg-yellow" style="padding: 5px;">
                         المصروفات العامة لا يتم حسابها على حسب نسبة الشركاء بينما يتم طرحها من إجمالى الربح وتوزيع الربح على حسب نسبة الشركاء
                    </div>
                <?php endif; ?>
                <div class="bg-green" style="padding: 5px;margin-top: 10px;font-weight: bold">
                     إجمالى قيمة الربح : <?php echo e(currency(round($ordersProfit,2),currency()->config('default'),currency()->config('default'), true)); ?>

                </div>

            </div>
		</div>
	</div>
</section>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('css'); ?>
    <style>
        .rowTd{
            vertical-align: middle !important;
            text-align: center !important;
            font-size: 15px !important;
        }
        .progress-bar,.badge{
            width: 100%;
        }
        .badge {
            width: 100%;
            padding: 5px;
        }
        table,.badge,td {
            font-size: 14px !important;
            font-weight: bold !important;
        }
        @media  print {
            table,.badge,td,.bg-green,.bg-yellow,.bg-aqua,.bg-yellow,.bg-red {
                font-size: 18px !important;
                color: #0c0c0c!important;
            }

        }
    </style>
<?php $__env->stopPush(); ?>
<?php $__env->startPush('js'); ?>
	<script>
        $('.datepicker').datepicker({
            autoclose: true,
            rtl: true,
            format: 'yyyy-mm-dd',
            language: "<?php echo e(\Session::get('locale')); ?>",
        });
      /*  $(document).on('change','.todate,.fromdate',function(e){
            e.preventDefault();
            alert();
            let todate = $('.todate').val();
            let fromdate = $('.fromdate').val();
		});*/
	</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>