Пример #1
0
 public function virtual_to_cubi(Request $request, Service $service)
 {
     $this->validate($request, ['quantity' => 'required|numeric|min:1']);
     $user = Auth::user();
     $role = $user->characterId();
     if ($user->money >= $request->quantity * $service->price) {
         if (!$this->checkOnline($role)) {
             $user->money = $user->money - $request->quantity * $service->price;
             $user->save();
             Transfer::create(['user_id' => $user->ID, 'zone_id' => 1, 'cash' => $request->quantity * 100]);
             flash()->success(trans('services.' . $service->key . '.complete'));
         } else {
             flash()->error(trans('services.must_logout'));
         }
     } else {
         flash()->error(trans('main.not_enough', ['currency' => strtolower(settings('currency_name'))]));
     }
 }
Пример #2
0
 public function postCheck(Request $request, VoteSite $site)
 {
     if (!VoteLog::recent($request, $site)->exists()) {
         switch ($site->type) {
             case 'virtual':
                 $user = Auth::user();
                 $user->money = $site->double_rewards ? $site->reward_amount * 2 : $site->reward_amount + $user->money;
                 $user->save();
                 break;
             case 'cubi':
                 Transfer::create(['user_id' => Auth::user()->ID, 'zone_id' => 1, 'cash' => $site->double_rewards ? $site->reward_amount * 2 : $site->reward_amount]);
                 break;
         }
         VoteLog::create(['user_id' => Auth::user()->ID, 'ip_address' => $request->ip(), 'reward' => $site->double_rewards ? $site->reward_amount * 2 : $site->reward_amount, 'site_id' => $site->id]);
         return redirect('vote/success/' . $site->id);
     } else {
         flash()->error(trans('vote.already_voted'));
         return redirect()->back();
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // check if account exists
     $account = Account::find($id);
     if ($account === null || $account->user_id != Auth::user()->id) {
         // stuff to pass into view
         $title = "Error";
         $errmsg = "The account does not exist.";
         return view('errors.error', compact('errmsg', 'title', 'heading'));
     }
     // start database transaction
     DB::transaction(function () use($account) {
         // delete account
         $account->delete();
         // get obsolete transfers
         $transfers = Transfer::whereNull('account_from')->whereNull('account_to')->get();
         // delete transfers
         foreach ($transfers as $transfer) {
             $transfer->delete();
         }
     });
     // flash message
     session()->flash('flash_message', 'Account deleted successfully.');
     // redirect to accounts
     return redirect()->route('accounts.index');
 }
Пример #4
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     /*
      * Cubi Transferring
      */
     $schedule->call(function () {
         $transfers = Transfer::all();
         foreach ($transfers as $transfer) {
             if (!DB::table('usecashnow')->where('userid', $transfer->user_id)->where('zoneid', $transfer->zone_id)->take(1)->exists()) {
                 DB::table('usecashnow')->insert(['userid' => $transfer->user_id, 'zoneid' => $transfer->zone_id, 'sn' => 0, 'aid' => 1, 'point' => 0, 'cash' => $transfer->cash, 'status' => 1, 'creatime' => Carbon::now()]);
                 DB::table('pweb_transfer')->where('user_id', $transfer->user_id)->where('zone_id', $transfer->zone_id)->where('cash', $transfer->cash)->take(1)->delete();
             }
         }
     })->everyMinute();
     /*
      * Update Players
      */
     $schedule->call(function () {
         $api = new API();
         if ($api->online) {
             set_time_limit(0);
             $users = User::all();
             foreach ($users as $user) {
                 $roles = $api->getRoles($user->ID) ? $api->getRoles($user->ID)['roles'] : [];
                 foreach ($roles as $role) {
                     $role_data = $api->getRole($role['id']);
                     $var_data = settings('server_version') != '07' ? $api->parseOctet($role_data['status']['var_data'], 'var_data') : ['pk_count' => 0, 'dead_flag' => 0];
                     if (!empty($role_data['status']['faction_contrib'])) {
                         $faction_contrib = $api->parseOctet($role_data['status']['faction_contrib'], 'faction_contrib');
                     }
                     if (!empty($role_data['status']['force_data'])) {
                         $force_data = $api->parseOctet($role_data['status']['force_data'], 'force_data');
                     }
                     if (!empty($role_data['status']['title_data'])) {
                         $title_data = $api->parseOctet($role_data['status']['title_data'], 'title_data');
                     }
                     $user_faction = $api->getUserFaction($role['id']);
                     if (!empty($user_faction['fid'])) {
                         $faction_info = $api->getFactionInfo($user_faction['fid']);
                     }
                     $role_info = ['id' => $role_data['base']['id'], 'name' => $role_data['base']['name'], 'cls' => $role_data['base']['cls'], 'gender' => $role_data['base']['gender'], 'spouse' => $role_data['base']['spouse'], 'level' => $role_data['status']['level'], 'level2' => $role_data['status']['level2'], 'hp' => $role_data['status']['hp'], 'mp' => $role_data['status']['mp'], 'pariah_time' => $role_data['status']['pariah_time'], 'reputation' => $role_data['status']['reputation'], 'time_used' => $role_data['status']['time_used'], 'pk_count' => $var_data['pk_count'], 'dead_flag' => $var_data['dead_flag'], 'force_id' => !empty($force_data['cur_force_id']) ? $force_data['cur_force_id'] : 0, 'title_id' => !empty($title_data['cur_title_id']) ? $title_data['cur_title_id'] : 0, 'faction_id' => !empty($user_faction['fid']) ? $user_faction['fid'] : '', 'faction_name' => !empty($faction_info['name']) ? $faction_info['name'] : '', 'faction_role' => !empty($user_faction['role']) ? $user_faction['role'] : '', 'faction_contrib' => !empty($faction_contrib['consume_contrib']) ? $faction_contrib['consume_contrib'] : 0, 'faction_feat' => !empty($faction_contrib['cumulate_contrib']) ? $faction_contrib['cumulate_contrib'] : 0, 'equipment' => json_encode($role_data['equipment'])];
                     if ($player = Player::find($role_info['id'])) {
                         $player->update($role_info);
                     } else {
                         Player::create($role_info);
                     }
                     unset($role_data);
                     unset($var_data);
                     unset($force_data);
                     unset($faction_info);
                     unset($faction_contrib);
                     unset($user_faction);
                 }
             }
         }
     })->everyTenMinutes();
     /*
      * Update Factions
      */
     $schedule->call(function () {
         $gamed = new Gamed();
         $api = new API();
         $handler = NULL;
         if ($api->online) {
             set_time_limit(0);
             do {
                 $raw_info = $api->getRaw('factioninfo', $handler);
                 if (isset($raw_info['Raw']) || count($raw_info['Raw']) > 1) {
                     return true;
                 }
                 for ($i = 0; $i < count($raw_info['Raw']); $i++) {
                     if (empty($raw_info['Raw'][$i]['key']) || empty($raw_info['Raw'][$i]['value'])) {
                         unset($raw_info['Raw'][$i]);
                         continue;
                     }
                     $id = $gamed->getArrayValue(unpack("N", pack("H*", $raw_info['Raw'][$i]['key'])), 1);
                     $pack = pack("H*", $raw_info['Raw'][$i]['value']);
                     $faction = $gamed->unmarshal($pack, $api->data['FactionInfo']);
                     if (!empty($faction['master']['roleid']) && $faction['master']['roleid'] > 0) {
                         $user_faction = $api->getUserFaction($faction['master']['roleid']);
                         $faction_info = ['id' => $faction['fid'], 'name' => $faction['name'], 'level' => $faction['level'] + 1, 'master' => $faction['master']['roleid'], 'master_name' => $user_faction['name'], 'members' => count($faction['member']), 'reputation' => $this->getFactionStat($faction['fid'], 'reputation') > 0 ? $this->getFactionStat($faction['fid'], 'reputation') : 0, 'time_used' => $this->getFactionStat($faction['fid'], 'time_used') > 0 ? $this->getFactionStat($faction['fid'], 'time_used') : 0, 'pk_count' => $this->getFactionStat($faction['fid'], 'pk_count') > 0 ? $this->getFactionStat($faction['fid'], 'pk_count') : 0, 'announce' => $faction['announce'], 'territories' => Territory::where('owner', $faction['fid'])->count()];
                         if ($faction = Faction::find($faction_info['id'])) {
                             $faction->update($faction_info);
                         } else {
                             Faction::create($faction_info);
                         }
                     }
                     unset($id);
                     unset($faction);
                     unset($user_faction);
                     unset($raw_info['Raw'][$i]['value']);
                 }
                 $raw_count = count($raw_info['Raw']) - 1;
                 $last_raw = $raw_info['Raw'][$raw_count];
                 $last_key = $last_raw['key'];
                 $new_key = hexdec($last_key) + 1;
                 $handler = bin2hex(pack("N*", $new_key));
             } while (TRUE);
         }
     })->everyTenMinutes();
     /*
      * Update Territories
      */
     $schedule->call(function () {
         $api = new API();
         if ($api->online) {
             $territories = $api->getTerritories() ? $api->getTerritories()['Territory'] : [];
             foreach ($territories as $territory) {
                 if ($territory['owner'] > 0) {
                     $owner = $api->getFactionInfo($territory['owner']);
                 }
                 if ($territory['challenger'] > 0) {
                     $challenger = $api->getFactionInfo($territory['challenger']);
                 }
                 $territory_info = ['id' => $territory['id'], 'level' => $territory['level'], 'owner' => $territory['owner'], 'owner_name' => !empty($owner['name']) ? $owner['name'] : '', 'occupy_time' => $territory['occupy_time'], 'challenger' => $territory['challenger'], 'challenger_name' => !empty($challenger['name']) ? $challenger['name'] : '', 'deposit' => $territory['deposit'], 'cutoff_time' => $territory['cutoff_time'], 'battle_time' => $territory['battle_time'], 'bonus_time' => $territory['bonus_time'], 'color' => $territory['color'], 'status' => $territory['status'], 'timeout' => $territory['timeout'], 'maxbonus' => $territory['maxbonus'], 'challenge_time' => $territory['challenge_time'], 'challengerdetails' => $territory['challengerdetails']];
                 if ($territory = Territory::find($territory_info['id'])) {
                     $territory->update($territory_info);
                 } else {
                     Territory::create($territory_info);
                 }
                 unset($owner);
                 unset($challenger);
             }
         }
     })->everyTenMinutes();
 }
 /**
  * Run the database seed for account "Compte joint".
  *
  * @return void
  */
 public function runAccount1()
 {
     Transfer::create(['from_account_id' => 1, 'to_account_id' => 3, 'name' => "Surplus de liquidité", 'amount' => 1000, 'date' => Carbon::create(2015, 8, 5, 0)]);
     Transfer::create(['from_account_id' => 1, 'to_account_id' => 4, 'name' => 'Virement au PEL', 'amount' => 45, 'date' => Carbon::create(2015, 8, 17, 0)]);
     Transfer::create(['from_account_id' => 1, 'to_account_id' => 2, 'name' => 'Virement au CSL', 'amount' => 10, 'date' => Carbon::create(2015, 8, 17, 0)]);
 }
 /**
  * Run the database seed for account "CEL".
  *
  * @return void
  */
 public function runAccount3()
 {
     Transfer::create(['from_account_id' => 3, 'to_account_id' => 1, 'name' => "Manque de liquidité", 'amount' => 1000, 'date' => Carbon::create(2015, 7, 30, 0)]);
 }
 /**
  * Display search results
  *
  * @return \Illuminate\Http\Response
  */
 public function search(Request $request)
 {
     // get a list of all transfers
     $transfers = Transfer::where('user_id', Auth::user()->id)->where('comment', 'LIKE', '%' . $request->q . '%');
     // remember total records
     session()->flash('total_count', ceil($transfers->count() / 25));
     // sort
     if (!empty($request->sort)) {
         $transfers = $transfers->orderBy($request->sort, $request->order)->simplePaginate(25);
     } else {
         $transfers = $transfers->orderBy('date', 'desc')->simplePaginate(25);
     }
     // stuff to pass into view
     $action = 'TransfersController@search';
     $emptyMsg = "No Results for '" . $request->q . "'";
     $title = "Search Transfers";
     $heading = "Search Transfers - '" . $request->q . "'";
     $request->flash();
     return view('transfers.index', compact('transfers', 'action', 'emptyMsg', 'title', 'heading'));
 }
Пример #8
0
 /**
  * Save request inputs into account's incoming transfer
  * @param  \Illuminate\Http\Request $request
  * @param  \App\Account $account Account
  * @param  \App\Operation|null $operation Operation
  * @return void
  */
 public function saveIncomingTransfer(Request $request, Account $account, $operation)
 {
     if (is_null($operation)) {
         $operation = new Transfer();
     }
     $operation->fill(['from_account_id' => $request->get('from_account_id'), 'to_account_id' => $account->id, 'name' => $request->get('name'), 'amount' => $request->get('amount'), 'date' => Carbon::createFromFormat('d/m/Y', $request->get('date'))->startOfDay()])->save();
 }
 public function postIndex()
 {
     $user = Auth::user();
     $id = Input::get('payment');
     /*
      *There is an invisible field called form that tells what form was submitted
      *
      */
     if (Input::get('form') == 'trans') {
         $monthNum = substr(Input::get('date'), 0, 2);
         $month = date('M', mktime(0, 0, 0, $monthNum, 10));
         $year = substr(Input::get('date'), -4);
         $transaction = new Transaction();
         $transaction->userID = $user->id;
         $transaction->date = Input::get('date');
         $transaction->amount = Input::get('amount');
         $transaction->typeID = Input::get('type');
         $transaction->note = Input::get('note');
         $transaction->year = $year;
         $transaction->month = $month;
         if ($id == 'cash') {
             $month = Month::where('userID', $user->id)->where('name', $month)->where('year', date("Y"))->first();
             $month->cash -= Input::get('amount');
             $month->save();
             $transaction->accountID = 0;
         } else {
             $transaction->accountID = $id;
             $account = Account::find($id);
             //add for credit subtract for bank
             if ($account->accountType == 'c') {
                 $account->balance += Input::get('amount');
             } else {
                 $account->balance -= Input::get('amount');
             }
             $account->save();
         }
         $transaction->save();
         return redirect('options')->with('message', 'Transaction added successfully.');
     } else {
         if (Input::get('form') == 'type') {
             $type = new Type();
             $type->userID = $user->id;
             $type->name = Input::get('name');
             $type->save();
             return redirect('options')->with('message', 'Category added successfully.');
         } else {
             if (Input::get('form') == 'payment') {
                 $monthNum = substr(Input::get('date'), 0, 2);
                 $month = date('M', mktime(0, 0, 0, $monthNum, 10));
                 $year = substr(Input::get('date'), -4);
                 $amount = Input::get('amount');
                 $bankID = Input::get('bank');
                 $ccID = Input::get('payment');
                 $note = Input::get('note');
                 $date = Input::get('date');
                 if ($ccID == 'cash') {
                     $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                     $month2->cash = $month2->cash + $amount;
                     $month2->save();
                     if ($bankID == 'cash') {
                         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                         $month2->cash = $month2->cash - $amount;
                         $month2->save();
                     } else {
                         $bank = Account::find($bankID);
                         $bank->balance = $bank->balance - $amount;
                         $bank->save();
                     }
                     $transfer = new Transfer();
                     $transfer->userID = $user->id;
                     $transfer->creditAccountID = $bankID;
                     $transfer->debitAccountID = 0;
                     $transfer->amount = $amount;
                     $transfer->note = $note;
                     $transfer->date = $date;
                     $transfer->year = $year;
                     $transfer->month = $month;
                     $transfer->save();
                 } else {
                     $cc = Account::find($ccID);
                     if ($bankID == 'cash') {
                         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                         $month2->cash = $month2->cash - $amount;
                         $month2->save();
                     } else {
                         $bank = Account::find($bankID);
                         $bank->balance = $bank->balance - $amount;
                         $bank->save();
                     }
                     if ($cc->accountType == 'b') {
                         //transfer
                         $cc->balance = $cc->balance + $amount;
                         $transfer = new Transfer();
                         $transfer->userID = $user->id;
                         $transfer->creditAccountID = $bankID;
                         $transfer->debitAccountID = $ccID;
                         $transfer->amount = $amount;
                         $transfer->note = $note;
                         $transfer->date = $date;
                         $transfer->year = $year;
                         $transfer->month = $month;
                         $transfer->save();
                     } else {
                         //payment
                         $cc->balance = $cc->balance - $amount;
                         $payment = new Payment();
                         $payment->userID = $user->id;
                         $payment->creditAccountID = $bankID;
                         $payment->debitAccountID = $ccID;
                         $payment->amount = $amount;
                         $payment->note = $note;
                         $payment->date = $date;
                         $payment->year = $year;
                         $payment->month = $month;
                         $payment->save();
                     }
                     $cc->save();
                 }
                 return redirect('options')->with('message', 'Payment saved successfully.');
             } else {
                 if (Input::get('form') == 'cc') {
                     $cc = new Account();
                     $cc->userID = $user->id;
                     $cc->name = Input::get('name');
                     $cc->balance = Input::get('balance');
                     $cc->creditLimit = Input::get('limit');
                     $cc->statementDay = Input::get('date');
                     $cc->accountType = 'c';
                     $cc->save();
                     return redirect('options')->with('message', 'Credit Card added successfully.');
                 } else {
                     if (Input::get('form') == 'bank') {
                         $bank = new Account();
                         $bank->userID = $user->id;
                         $bank->name = Input::get('name');
                         $bank->balance = Input::get('balance');
                         $bank->accountType = 'b';
                         $bank->save();
                         return redirect('options')->with('message', 'Bank Account added successfully.');
                     } else {
                         if (Input::get('form') == 'income') {
                             $date = Input::get('date');
                             $monthNum = substr($date, 0, 2);
                             $month = date('M', mktime(0, 0, 0, $monthNum, 10));
                             $amount = Input::get('amount');
                             $bankID = Input::get('bank');
                             $year = substr(Input::get('date'), -4);
                             $income = new Income();
                             $income->userID = $user->id;
                             $income->month = $month;
                             $income->amount = $amount;
                             $income->note = Input::get('note');
                             $income->date = $date;
                             $income->year = $year;
                             if ($bankID == "cash") {
                                 $income->accountID = 0;
                                 $month = Month::where('userID', $user->id)->where('name', $month)->first();
                                 $month->cash = $month->cash + $amount;
                                 $month->save();
                             } else {
                                 $income->accountID = $bankID;
                                 $bank = Account::find($bankID);
                                 $bank->balance = $bank->balance + $amount;
                                 $bank->save();
                             }
                             $income->save();
                             return redirect('options')->with('message', 'Income added successfully.');
                         }
                     }
                 }
             }
         }
     }
 }
Пример #10
0
 public function paymentDelete($type, $id)
 {
     $user = Auth::user();
     $date = Input::get('date');
     $amount = Input::get('amount');
     $bankID = Input::get('bank');
     $accountID = Input::get('payment');
     $note = Input::get('note');
     //add intial trans back onto
     if ($type == 0) {
         //tansfer
         $trans = Transfer::where('id', $id)->where('userID', $user->id)->first();
         if ($trans->creditAccountID == 0) {
             $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
             $month->cash = $month->cash + $trans->amount;
             $month->save();
         } else {
             $debit = Account::find($trans->creditAccountID);
             $debit->balance = $debit->balance + $trans->amount;
             $debit->save();
         }
         if ($trans->debitAccountID == 0) {
             $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
             $month->cash = $month->cash - $trans->amount;
             $month->save();
         } else {
             $debit = Account::find($trans->debitAccountID);
             $debit->balance = $debit->balance + $trans->amount;
             $debit->save();
         }
     } else {
         //payment
         $trans = Payment::where('id', $id)->where('userID', $user->id)->first();
         //add initial payment amount back on
         if ($trans->creditAccountID == 0) {
             $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
             $month->cash = $month->cash + $trans->amount;
             $month->save();
         } else {
             $credit = Account::find($trans->creditAccountID);
             $credit->balance = $credit->balance + $trans->amount;
             $credit->save();
         }
         //add initial payment back on
         $debit = Account::find($trans->debitAccountID);
         $debit->balance = $debit->balance + $trans->amount;
         $debit->save();
     }
     $trans->forceDelete();
     return redirect('home')->with('message', 'Payment/Transfer deleted successfully.');
 }