44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Portal\Http\Controllers\Marketer;
|
|
|
|
use App\Utils\BusinessUtil;
|
|
use App\Utils\TransactionUtil;
|
|
use Carbon\Carbon;
|
|
use Modules\Portal\Http\Controllers\BasePortalController;
|
|
|
|
class DashboardController extends BasePortalController
|
|
{
|
|
public function __construct(
|
|
protected TransactionUtil $transactionUtil,
|
|
protected BusinessUtil $businessUtil
|
|
) {}
|
|
|
|
public function index()
|
|
{
|
|
$business_id = $this->businessId();
|
|
$user_id = auth()->id();
|
|
$start = Carbon::now()->startOfMonth()->toDateString();
|
|
$end = Carbon::now()->endOfMonth()->toDateString();
|
|
|
|
$business_details = $this->businessUtil->getDetails($business_id);
|
|
$pos_settings = empty($business_details->pos_settings)
|
|
? $this->businessUtil->defaultPosSettings()
|
|
: json_decode($business_details->pos_settings, true);
|
|
|
|
$commission_percent = auth()->user()->cmmsn_percent ?? 0;
|
|
$sell_details = $this->transactionUtil->getTotalSellCommission($business_id, $start, $end, null, $user_id);
|
|
$total_commission = ($commission_percent * ($sell_details['total_sales_with_commission'] ?? 0)) / 100;
|
|
|
|
$month_sales = $this->transactionUtil->getUserTotalSales($business_id, $user_id, $start, $end);
|
|
|
|
return view('portal::marketer.dashboard.index', compact(
|
|
'commission_percent',
|
|
'total_commission',
|
|
'sell_details',
|
|
'month_sales',
|
|
'pos_settings'
|
|
));
|
|
}
|
|
}
|