/** * Returns a multidimensional array of each center and each * account that the center has, along with the balance * of that account. * * @return array */ public static function getSeparateCenterAccounts($center_id = false) { $center_list_accounts = []; if ($center_id) { $centers = self::getCenter($center_id); } else { $centers = self::getCenter(); } for ($i = 0; $i < count($centers); $i++) { $center_list_accounts[$i]['center_name'] = $centers[$i]->name; $center_list_accounts[$i]['center_id'] = $centers[$i]->id; $center_list_accounts[$i]['accounts'] = []; $counter = 0; foreach ($centers[$i]->centers as $item) { $account_standing = 'black'; $account = Balance::getMonthlyBalance(Balance::getClosestRealTransaction(Carbon::now()->toDateString()), $item->id); $center_list_accounts[$i]['accounts'][$counter]['account_id'] = $item->id; $center_list_accounts[$i]['accounts'][$counter]['account_name'] = $account['center_name']; $center_list_accounts[$i]['accounts'][$counter]['balance'] = $account['balance']; if ($account['balance']->availableBalance < 0) { $account_standing = 'red'; } $center_list_accounts[$i]['accounts'][$counter]['standing'] = $account_standing; $counter++; } } return $center_list_accounts; }
/** * Execute the console command. * * @return mixed */ public function handle() { //Scheduler work - which is set up by every 30 min in Kernel.php //Decreament balance of every user by 10 unit $users_having_money = DB::table('users')->join('payments', 'users.id', '=', 'payments.user_id')->select('users.id as user_id', DB::raw('sum(payments.money_amount) as total'))->groupBy('users.id')->get(); foreach ($users_having_money as $key => $value) { $balance = new Balance(); if ($value->total > 10) { $balance->money_amount = -10; } else { if ($value->total !== 0) { $balance->money_amount = -$value->total; } } $balance->transection_by = 'system'; $balance->user_id = $value->user_id; $balance->save(); } }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $newUser = User::create(['username' => $data['username'], 'password' => bcrypt($data['password']), 'created_at' => gmdate('Y-m-d H:i:s'), 'updated_at' => gmdate('Y-m-d H:i:s'), 'userTypeId' => $data['userTypeId']]); $userTypeId = $newUser->userTypeId; if ($userTypeId == 1 || $userTypeId == 2) { $newEmployee = Employee::create(['userId' => $newUser->id, 'firstName' => $data['firstName'], 'lastName' => $data['lastName'], 'email' => $data['email'], 'phone' => $data['phone'], 'streetAddress' => $data['streetAddress'], 'city' => $data['city'], 'state' => $data['state'], 'zipcode' => $data['zipcode'], 'ssn' => $data['ssn'], 'hourlyRate' => $data['hourlyRate'], 'primaryStoreId' => $data['primaryStoreId']]); } if ($userTypeId == 3) { if (array_key_exists('accountId', $data)) { $newContact = Contact::create(['userId' => $newUser->id, 'accountId' => $data['accountId'], 'firstName' => $data['firstName'], 'lastName' => $data['lastName'], 'email' => $data['email'], 'phone' => $data['phone'], 'contactTypeId' => $data['contactTypeId']]); } else { $newAccount = Account::create(['companyName' => $data['companyName'], 'streetAddress' => $data['streetAddress'], 'city' => $data['city'], 'state' => $data['state'], 'zipcode' => $data['zipcode'], 'accountStatus' => $data['accountStatus']]); $accntId = $newAccount->id; $newContant = Contact::create(['userId' => $newUser->id, 'accountId' => $accntId, 'firstName' => $data['firstName'], 'lastName' => $data['lastName'], 'email' => $data['email'], 'phone' => $data['phone'], 'contactTypeId' => $data['contactTypeId']]); $newBalance = Balance::create(['accountId' => $accntId, 'balance' => 0.0]); } } return $newUser; }
/** * Gets the monthly of an individual center instead of all of the accounts. * * * @param $center_id * @return array|string */ public function getCenterMonthlyBalance($center_id) { return Balance::getMonthlyBalance(false, $center_id); }
/** * Finds the closest transaction for a given date, should there not be * any data for the date given. This uses the center_id of 1, which * is an Admin account. This assumes that when the data is posted * that particular Admin account's data is posted each and every * time. This has been the case in the past and assumes it * will be the case in the future. * * @param $date * @return mixed */ public static function getClosestRealTransaction($date) { $output = Balance::select('date')->where('date', '<=', $date)->where('center_id', '=', 1)->orderBy('date', 'dec')->first(); return $output->date; }
public function add_balance() { $requestData = Request::all(); $balance = new Balance(); $balance->user_id = Auth::user()->id; $balance->money_amount = $requestData['balance']; $balance->transection_by = 'user'; $balance->save(); return Redirect::back()->withErrors(['Balance Successfully Added']); }
protected function portalEmailBalance($id) { if ( \Auth::user() ) { $userTypeID = \Auth::user()->userTypeId; if ( $userTypeID == 1 || $userTypeID == 2 ) { $authUserId = \Auth::id(); $authEmployee = Employee::where('userId','=',$authUserId)->first(); $accountId = $id; $account = Account::where('id','=',$accountId)->first(); $contact = Contact::where('accountId','=',$accountId)->where('contactTypeId','=',1)->first(); $balance = Balance::where('accountId','=',$accountId)->first()->balance; $data = array( 'contact' => $contact->firstName . ' ' . $contact->lastName, 'id' => $accountId, 'name' => $account->companyName, 'balance' => $balance, ); $test = "hello"; Mail::send('email_invoice_balance', $data, function ($message) use($contact){ $message->from('*****@*****.**', 'D.C.I. Printing & Graphics, Inc.'); $message->to($contact->email, $contact->firstName)->subject('Account Balance'); }); return Redirect::to('/portal-invoices'); } else { return Redirect::to('/account'); } } else { return Redirect::to('/'); } }