public function destroy(ShareValuation $shareValuation)
 {
     if (is_integer($shareValuation)) {
         $shareValuation = ShareValuation::find($shareValuation);
     }
     $shareValuation->delete();
     Flash::success('ShareValuation has been created Deleted!');
     return Redirect::back();
 }
Esempio n. 2
0
 public function currencyRate(Share $fromShare, Share $toShare, $date)
 {
     $latestShareValue = ShareValuation::where('share_id', $toShare->id)->orderBy('dateval', 'desc')->first();
     $baseClass = Currency::EUR;
     if ($toShare->currency->id == $fromShare->currency->id) {
         $currencyRate = 1;
     } else {
         if ($toShare->currency->id == 2) {
             $baseClass = Currency::USD;
         } else {
         }
         $currencyRate = Exchange::base($baseClass)->historical($latestShareValue->dateval)->get()['EUR'];
     }
     return $currencyRate;
 }
 public function destroy($shareValuation)
 {
     $shareValuation = ShareValuation::find($shareValuation);
     $shareValuation->delete();
     return response(['data' => true, 'status' => 'success', 'message' => 'successfully deleted']);
 }
 public function get_indirectholdinglist()
 {
     $toReturn = collect();
     $operations = Operation::groupBy('to_share_id')->get();
     foreach ($operations as $operation) {
         $row = collect();
         // if ($operation->to_share_id!=10) { //just for test
         //     continue;
         // }
         $share = $operation->toShareId;
         $commitmentsSum = Operation::where('to_share_id', $operation->to_share_id)->sum('commitment');
         $row->put('commitmentsSum', $commitmentsSum);
         $realizedValue = Operation::where('to_share_id', $operation->to_share_id)->where('cash_transfert', '>', 0)->sum('cash_transfert');
         $row->put('realizedValue', $realizedValue);
         $amountCalled = Operation::where('to_share_id', $operation->to_share_id)->where('cash_transfert', '<', 0)->sum('cash_transfert');
         $row->put('amountCalled', $amountCalled);
         // Unrealised //
         //Unrealised Value = somme des number of shares ($shareSum) * derniere valorisation de l'action($latestShareValue)
         $shareSum = Operation::where('to_share_id', $operation->to_share_id)->sum('number_of_shares');
         $latestShareValue = ShareValuation::where('share_id', $operation->to_share_id)->orderBy('dateval', 'desc')->first();
         if (isset($latestShareValue->value)) {
             //echo $latestShareValue->value;
             $Unrealised_value = $shareSum * $latestShareValue->value;
         } else {
             $Unrealised_value = null;
         }
         $row->put('Unrealised_value', $Unrealised_value);
         $totalValue = $realizedValue + $Unrealised_value;
         $row->put('totalValue', $totalValue);
         if (abs($amountCalled) > 0) {
             $dpi = $realizedValue / abs($amountCalled);
         } else {
             $dpi = null;
         }
         $row->put('DPI', $dpi);
         if (abs($amountCalled) > 0) {
             $rvpi = $Unrealised_value / abs($amountCalled);
         } else {
             $rvpi = null;
         }
         $row->put('RVPI', $rvpi);
         if (abs($amountCalled) > 0) {
             $tvpi = $totalValue / abs($amountCalled);
         } else {
             $tvpi = null;
         }
         $row->put('TVPI', $tvpi);
         //  XIRR //
         //cash_transfert avec date // unrealized avec date de unrealized (dateval) (appliquer finction excel)
         //le premier cash transfert est negatif
         //la dernier value : share value (dernier valeur de l'action)
         $amountSerie = collect();
         $serie = Operation::where('to_share_id', $operation->to_share_id)->orderBy('date', 'asc')->get();
         foreach ($serie as $cash) {
             $amountSerie->push($cash->cash_transfert);
         }
         $dateSerie = collect();
         foreach ($serie as $cash) {
             $dateSerie->push($cash->date);
         }
         if (isset($latestShareValue->dateval)) {
             $dateSerie->push($latestShareValue->dateval);
         }
         $amounts = [];
         foreach ($amountSerie as $amount) {
             $amounts[] = $amount;
         }
         $dates = [];
         foreach ($dateSerie as $date) {
             $dates[] = $date->timestamp;
         }
         $financial = new \Organit\test\Financial();
         $XIRR = $financial->XIRR($amountSerie, $dateSerie, 0.1);
         $row->put('XIRR', $XIRR);
         $toReturn->push($row);
     }
     return $toReturn;
 }