Exemple #1
0
 /**
  * Gets the sum of all services, converted to user's
  * preferred currency with current exchange rate.
  *
  * It is possible to pass a collection of services to this method,
  * and it will return the sum of that collection.
  *
  * @param  Collection|null $services
  * @return [type]
  */
 public function getSum(Collection $services = null)
 {
     if (!$services instanceof Collection) {
         $services = $this->all();
     }
     $preferredCurrency = strtoupper(auth()->user()->preferred_currency);
     $sum = 0;
     foreach ($services as $service) {
         $currentCurrency = strtoupper($service->currency);
         $exchange_rate = \Swap::quote("{$currentCurrency}/{$preferredCurrency}")->getValue();
         $sum += $service->cost / 100 * $exchange_rate;
     }
     //$sum = ceil($sum);
     return number_format($sum, 2, ',', '.') . ' ' . $preferredCurrency;
 }
 /**
  * Changes business day by variable 'new_date'
  *
  * 
  * @return \Illuminate\Http\Response
  */
 public function changeDay()
 {
     SwapsController::final_store();
     $trader = User::findOrFail(\Auth::user()->id);
     $swaps = Swap::where('company', $trader->company)->get();
     $current_date = null;
     foreach ($swaps as $swap) {
         $date = Carbon::parse(Input::get('new_date'));
         $swap->business_date = $date;
         $swap->update();
         $current_date = $date;
         if (Carbon::parse($swap->end_date)->diffInWeekdays(Carbon::parse($current_date)) <= 5 && Carbon::parse($swap->end_date) >= Carbon::parse($current_date)) {
             $swap['maturity'] = 1;
         } else {
         }
         $swap['current_spread'] = $swap->fixed_rate - $swap->floating_spread + rand(-100, 100) / 100;
     }
     return View::make('swapMaturities')->with('trader', $trader)->with('swaps', $swaps)->with('current_date', $current_date);
 }