public static function getActiveServices(Subscriber $profile) { switch ($profile->plan_type) { case PREPAID_PLAN: return DB::table('user_recharges as r')->where('r.user_id', $profile->id)->select('r.time_limit', 'r.data_limit', 'recharged_on', 'r.expiration', 'plan_name', 'plan_type', 'l.limit_type')->join('prepaid_vouchers as v', 'v.id', '=', 'r.voucher_id')->leftJoin('voucher_limits as l', 'l.id', '=', 'v.limit_id')->first(); break; case FREE_PLAN: return Freebalance::where('user_id', $profile->id)->select('plan_type', 'limit_type', 'time_balance as time_limit', 'data_balance as data_limit', 'expiration', 'last_reset_on')->first(); break; case ADVANCEPAID_PLAN: return DB::table('ap_active_plans as p')->where('p.user_id', $profile->id)->select('plan_type', 'limit_type', 'time_balance as time_limit', 'data_balance as data_limit', 'plan_name', 'c.expiration')->leftJoin('ap_limits as l', 'l.id', '=', 'p.limit_id')->join('billing_cycles as c', 'c.user_id', '=', '.p.user_id')->first(); break; default: throw new Exception("Failed to identify service type: {$profile->plan_type}"); break; } }
public static function now($pin, $uid, $method = 'pin') { $coupon = self::where('pin', $pin)->first(); if ($coupon == NULL) { throw new Exception("Invalid PIN."); } if ($coupon->user_id != NULL) { throw new Exception('Invalid/Used Voucher.'); } $subscriber = Subscriber::find($uid); switch ($subscriber->plan_type) { case PREPAID_PLAN: $recharge = DB::table('user_recharges as r')->where('r.user_id', $uid)->join('prepaid_vouchers as v', 'r.voucher_id', '=', 'v.id')->join('user_accounts as u', 'u.id', '=', 'r.user_id')->leftJoin('voucher_limits as l', 'v.limit_id', '=', 'l.id')->select('r.id', 'v.plan_type', 'v.limit_id', 'r.expiration', 'l.aq_access', 'u.uname')->first(); if (is_null($recharge)) { throw new Exception("Cannot refill, account never recharged."); } if (strtotime($recharge->expiration) < time()) { throw new Exception("Cannot recharge account, validity expired on: " . date('d-M-y H:i', strtotime($recharge->expiration))); } if ($recharge->plan_type == UNLIMITED) { throw new Exception('Cannot refill Unlimited Account.'); } return self::refillPrepaid($coupon, $recharge); break; case FREE_PLAN: $balance = Freebalance::where('free_balance.user_id', $uid)->join('user_accounts as u', 'u.id', '=', 'free_balance.user_id')->select('free_balance.plan_type', 'free_balance.limit_type', 'free_balance.id', 'free_balance.aq_access', 'free_balance.aq_invocked', 'free_balance.time_balance', 'free_balance.data_balance', 'free_balance.expiration', 'u.uname')->first(); if (strtotime($balance->expiration) < time()) { throw new Exception("Cannot refill account, validity expired on: " . date('d-M-y H:i', strtotime($balance->expiration))); } if ($balance->plan_type == UNLIMITED) { throw new Exception("Cannot refill unlimited account."); } return self::refillFree($coupon, $balance); break; } }
public function dashboard() { $plan = Freebalance::where('user_id', Auth::id())->first(); // pr($plan->toArray()); return View::make('user.frinternet.dashboard')->with('profile', Auth::user())->with('plan', $plan); }