public function totalBonuses($users, $level) { \Log::info("in totalBonuses"); $commission = CommissionLevel::where('sales_level', $level)->first(); $total = 0; foreach ($users as $user) { \Log::info("userId={$user->id}"); $sales = SalesTransactions::where('purchased_by', $user->id)->get(); foreach ($sales as $sale) { $total += $sale->pay_bonus_on_amt * $commission->percentage * 0.01; } \Log::info("total={$total}"); } return number_format($total, 2); }
public function updateSales(Request $request, $approved) { $userId = $request->session()->get('user_id'); $roles = $request->session()->get('userRoles'); $user = Users::find($userId); $shoppingCart = ShoppingCarts::where('user_id', $userId)->first(); $items = $this->processApprovedItems($shoppingCart); $payPrice = $request->session()->get('transactionPayPrice'); $salesTransaction = new SalesTransactions(); $salesTransaction->date = $approved['date']; $salesTransaction->purchased_by = $userId; $salesTransaction->total_items = $request->session()->get('transactionTotalPrice'); $shipping = $request->session()->get('transactionTotalWeightShipping') + $request->session()->get('transactionTotalShipping'); $salesTransaction->total_shipping = $shipping; $salesTransaction->total_order = $request->session()->get('transactionGrandTotal'); $salesTransaction->payment_method = 1; $salesTransaction->pay_bonus_on_amt = $request->session()->get('payPrice'); $salesTransaction->credit_card_id = $approved['credit_card']; $salesTransaction->payment_type = $approved['pay_method']; $salesTransaction->transaction_approval_code = $approved['approval_code']; $salesTransaction->transaction_approval_date = $approved['date']; $salesTransaction->first_id = $user->sponsor_id; $salesTransaction->second_id = $user->second_id; $salesTransaction->third_id = $user->third_id; $salesTransaction->fourth_id = $user->fourth_id; $salesTransaction->fifth_id = $user->fifth_id; $salesTransaction->shipping_id = $request->session()->get('shippingId'); $salesTransaction->save(); $this->updateSalesDetails($salesTransaction, $items, $roles); $this->updateBonuses($salesTransaction, $user, $roles); $items = $this->processPaidItems($shoppingCart); return 1000000 + $salesTransaction->id; }