/**
  * Delete prediction action
  * @return string
  */
 public function delete()
 {
     $response = array('success' => false);
     if (Request::ajax()) {
         $predictionIds = Input::get('predictionIds');
         $tabletId = null;
         if ($predictionIds) {
             $predictionIdsArray = $this->_getPredictionIdsArray($predictionIds);
             foreach ($predictionIdsArray as $predictionId) {
                 $prediction = Prediction::find($predictionId);
                 if (!$tabletId) {
                     $tablet = Tablet::find($prediction->tablet_id);
                 }
                 $predictionExpenses = $prediction->expenses;
                 foreach ($predictionExpenses as $expense) {
                     $tablet->total_expenses = $tablet->total_expenses - $expense->value;
                     $tablet->current_sum = $tablet->current_sum + $expense->value;
                 }
                 $tablet->save();
             }
             Prediction::destroy($predictionIdsArray);
             $response['success'] = true;
         }
     }
     return Response::json($response);
 }
 */
Event::listen('expense.create.success', function ($expense) {
    $predictionId = $expense->prediction_id;
    $prediction = Prediction::find($predictionId);
    if ($prediction->id) {
        $tablet = $prediction->tablet;
        $tablet->current_sum = $tablet->current_sum - $expense->value;
        $tablet->save();
    }
});
/**
 * Update Prediction value upon expense.create.success
 */
Event::listen('expense.create.success', function ($expense) {
    $predictionId = $expense->prediction_id;
    $prediction = Prediction::find($predictionId);
    if ($prediction->id) {
        $currentValue = (double) $prediction->value;
        $expenseValue = (double) $expense->value;
        $prediction->value = $currentValue - $expenseValue;
        $prediction->save();
    }
});
/**
 * Update current_sum on Tablet upon income.create.success
 */
Event::listen('income.create.success', function ($incomeValue, $tabletId) {
    $tablet = Tablet::find($tabletId);
    if ($tablet->id) {
        $oldCurrentSum = $tablet->current_sum;
        $newCurrentSum = $oldCurrentSum + $incomeValue;