Example #1
0
 public function postNewRollover(NewRolloverRequest $request, Rollover $rollover, Payment $payment)
 {
     if ($request->input('from_thc') == $request->input('to_thc')) {
         flash()->error('You can not rollover to the same Customer!');
     } else {
         $customer_from_id = thcToCustomerId($request->input('from_thc'));
         $customer_to_id = thcToCustomerId($request->input('to_thc'));
         $from_balance = $payment->where('customer_id', $customer_from_id)->first(['account_balance']);
         //            $rollover_amount = (int) $request->input('rollover_amount');
         if ($from_balance->account_balance > 0) {
             $this->rollovers = $rollover->create(['rollover_amount' => $from_balance->account_balance, 'rollover_from_user' => $customer_from_id, 'rollover_to_user' => $customer_to_id]);
             // Rollover remaining amount
             $payment->where('customer_id', $customer_from_id)->decrement('account_balance', $from_balance->account_balance);
             $payment->where('customer_id', $customer_to_id)->increment('account_balance', $from_balance->account_balance);
             if ($this->rollovers->id) {
                 // Should we delete / deactivate account?
                 flash()->success(nairaFormater($from_balance->account_balance) . ' was rolled over from ' . customerFullname($customer_from_id) . ' to ' . customerFullname($customer_to_id) . '!');
             } else {
                 flash()->error('An error occurred, try rolling over again!');
             }
         } else {
             flash()->error('You can not rollover (' . nairaFormater($from_balance->account_balance) . ') to another Customer!');
         }
     }
     return redirect()->route('rollover.list');
 }
Example #2
0
 public function postNewOrder(NewOrderRequest $request, Order $order, Payment $payment)
 {
     $customer_id = thcToCustomerId($request->input('thc'));
     $balance = $payment->where('customer_id', $customer_id)->first(['account_balance']);
     $order_amount = (int) $request->input('order_amount');
     if ($balance->account_balance >= $order_amount) {
         $this->orders = $order->create(['order_amount' => $order_amount, 'order_category_id' => $request->input('order_category'), 'customer_id' => $customer_id]);
         // Deduct order amount from balance
         $payment->where('customer_id', $customer_id)->update(['account_balance' => $balance->account_balance - $order_amount]);
         if ($this->orders->id) {
             $order->whereId($this->orders->id)->update(['receipt_number' => thcReceiptNoGenerator($this->orders->id)]);
             flash()->success('Order Completed Successfully!');
         } else {
             flash()->error('An error occurred, try placing the Order again!');
         }
     } else {
         flash()->error('Account Balance (' . nairaFormater($balance->account_balance) . ') is too low to complete this Order!');
     }
     return redirect()->route('order.new');
 }
Example #3
0
 public function postNewTopUp(NewTopUpRequest $request, Payment $payment)
 {
     $customer_id = thcToCustomerId($request->input('customer_thc'));
     $topup_amount = (int) $request->input('topup_amount');
     $topup = $payment->where('customer_id', $customer_id)->increment('account_balance', $topup_amount);
     if ($topup) {
         flash()->success(nairaFormater($topup_amount) . ' was added to ' . customerFullname($customer_id) . '\'s Account!');
     } else {
         flash()->error('An error occurred while topping up ' . customerFullname($customer_id) . '\'s Account!');
     }
     return redirect()->route('customer.list');
 }