/**
  * Show the board index for the user.
  *
  * @return Response
  */
 public function getContribute()
 {
     $devStart = new Carbon(static::$ContributeProjectStart);
     $devCarbon = new Carbon(static::$ContributePublicStart);
     $devTimeSum = 0;
     $devTimer = "0 hours";
     $donorGroups = Payment::getDonorGroups();
     $donorWeights = ['uber' => 25, 'plat' => 20, 'gold' => 15, 'silver' => 10, 'bronze' => 10];
     foreach ($donorGroups as $donorGroup) {
         foreach ($donorGroup as $donor) {
             // Add the amount to the dev timer.
             $devTimeSum += $donor->amount;
         }
     }
     // Determine the time in a literal string.
     $devHours = 0;
     $devDays = 0;
     $devInflation = static::$ContributeDevInflation;
     // This inflation factor will make the dev timer reflect off hours too, on the assumption of a 40 hour work week.
     $devTime = $devTimeSum / 100 / (double) env('CONTRIB_HOUR_COST', 10) * $devInflation;
     $devCarbon->addHours($devTime);
     $devDays = $devCarbon->diffInDays();
     $devHours = $devCarbon->diffInHours() - $devDays * 24;
     if ($devHours > 0 || $devDays > 0) {
         $devTimer = "";
         if ($devDays > 0) {
             if ($devDays != 1) {
                 $devTimer .= "{$devDays} days";
             } else {
                 $devTimer .= "{$devDays} day";
             }
             if ($devHours > 0) {
                 $devTimer .= " and ";
             }
         }
         if ($devHours > 0) {
             if ($devHours != 1) {
                 $devTimer .= "{$devHours} hours";
             } else {
                 $devTimer .= "{$devHours} hour";
             }
         }
     }
     return $this->view(static::VIEW_CONTRIBUTE, ["devCarbon" => $devCarbon, "devTimer" => $devTimer, "devStart" => $devStart, "donations" => $devTimeSum, "donors" => $donorGroups, "donorWeight" => $donorWeights]);
 }
 /**
  * @param Carbon $startDate
  * @param Carbon $endDate
  * @return mixed
  */
 public static function title(Carbon $startDate, Carbon $endDate)
 {
     $hours = $startDate->diffInHours($endDate);
     if ($hours <= 24) {
         return trans('analytics::messages.hour');
     }
     if ($hours > 24 && $hours <= 720) {
         return trans('analytics::messages.day');
     }
     if ($hours > 720 && $hours <= 8766) {
         return trans('analytics::messages.month');
     }
     if ($hours > 8766) {
         return trans('analytics::messages.year');
     }
 }
Example #3
1
 /**
  * Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika
  *
  * @return array
  */
 public function getFilters()
 {
     return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) {
         $format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M';
         if (!$dateTime instanceof Carbon) {
             $dateTime = new Carbon($dateTime);
         }
         $now = Carbon::now();
         if (!$diffForHumans) {
             return $dateTime->formatLocalized($format);
         } elseif ($dateTime->diffInHours($now) < 1) {
             return $dateTime->diffForHumans(null, true) . ' temu';
         } elseif ($dateTime->isToday()) {
             return 'dziƛ, ' . $dateTime->format('H:i');
         } elseif ($dateTime->isYesterday()) {
             return 'wczoraj, ' . $dateTime->format('H:i');
         } else {
             return $dateTime->formatLocalized($format);
         }
     }), new Twig_SimpleFilter('timestamp', function ($dateTime) {
         if ($dateTime instanceof Carbon) {
             return $dateTime->getTimestamp();
         } else {
             return strtotime($dateTime);
         }
     })];
 }
 public function calculateModuleExpenditure($id, $fromDate, $toDate)
 {
     $module = Module::find($id);
     $activities = $module->activities;
     $activityCosts = array();
     $totalModuleCost = 0;
     foreach ($activities as $activity) {
         $sessions = $activity->sessions()->whereBetween('date_of_session', array($fromDate, $toDate))->orderBy('date_of_session')->get();
         $totalHoursPerPerson = 0;
         $activityTitle = $activity->title;
         $role = $activity->role_type;
         //the 'role' the PHD student was for the given 'session'
         if ($role == 'Demonstrator') {
             $payRate = 12.21;
         } elseif ($role = 'Teaching') {
             $payRate = 10.58;
         }
         foreach ($sessions as $session) {
             $startTime = new Carbon($session->start_time);
             //http://carbon.nesbot.com/docs/#api-humandiff
             $endTime = new Carbon($session->end_time);
             //http://carbon.nesbot.com/docs/#api-humandiff
             $totalHoursPerPerson += $startTime->diffInHours($endTime);
             //http://carbon.nesbot.com/docs/#api-humandiff
         }
         if (array_key_exists($activityTitle, $activityCosts)) {
             $activityCosts[$activityTitle] += $totalHoursPerPerson * $activity->quant_ppl_needed * $payRate;
         } else {
             $activityCosts[$activityTitle] = $totalHoursPerPerson * $activity->quant_ppl_needed * $payRate;
             //this 0verwrites 0ld values2d
         }
         $totalModuleCost += $totalHoursPerPerson * $activity->quant_ppl_needed * $payRate;
     }
     return view('calculateModuleExpenditureResults')->with(['module' => $module, 'totalModuleCost' => $totalModuleCost, 'activityCosts' => $activityCosts]);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $force = $input->getOption('force', false);
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $log = $this->getContainer()->get('logger');
     $dataUpdateService = $this->getContainer()->get('app.evedataupdate.service');
     $updateRegistry = $this->getContainer()->get('app.evedata.registry');
     $log->info('Preparing Reference Data');
     $corps = $em->getRepository('AppBundle:Corporation')->findAll();
     $now = new Carbon();
     $stationLastUpdate = $em->getRepository('AppBundle:ApiUpdate')->getLastUpdateByType(ApiUpdate::CONQUERABLE_STATIONS);
     $refTypeLastUpdate = $em->getRepository('AppBundle:ApiUpdate')->getLastUpdateByType(ApiUpdate::REF_TYPES);
     $update = false;
     if ($stationLastUpdate === null || $now->diffInHours(Carbon::instance($stationLastUpdate->getCreatedAt())) > 24) {
         $log->info('Updating Conquerable Stations');
         $updateRegistry->get(ConquerableStationManager::getName())->updateConquerableStations();
         $update = $dataUpdateService->createApiUpdate(ApiUpdate::CACHE_STYLE_LONG, ApiUpdate::CONQUERABLE_STATIONS, true);
         $em->persist($update);
         $update = true;
     }
     if ($refTypeLastUpdate === null || $now->diffInHours(Carbon::Instance($refTypeLastUpdate->getCreatedAt())) > 24) {
         $log->info('Updating Reference Types');
         $updateRegistry->get(RefTypeManager::getName())->updateRefTypes();
         $update = $dataUpdateService->createApiUpdate(ApiUpdate::CACHE_STYLE_LONG, ApiUpdate::REF_TYPES, true);
         $em->persist($update);
         $update = true;
     }
     if ($update) {
         $log->info('Flushing Data');
         $em->flush();
     }
     $corp_ids = [];
     foreach ($corps as $c) {
         $log->info("Starting Update {$c->getCorporationDetails()->getName()}\n\n");
         $this->getContainer()->get('app.corporation.manager')->checkCorporationDetails($c);
         $dataUpdateService->updateShortTimerCalls($c, $force);
         $em->flush();
         $dataUpdateService->updateLongTimerCalls($c, $force);
         $em->flush();
         $corp_ids[] = $c->getId();
         $log->info("Finished Updated {$c->getCorporationDetails()->getName()}");
     }
     $log->info("Updating Compound Fields.");
     $start = microtime(true);
     $dataUpdateService->updateAssetCache($corp_ids);
     $log->info(sprintf("Done in %s", microtime(true) - $start));
 }
 /**
  * Get the difference between start and end dates of the period in hours.
  *
  * @return int
  */
 public function lengthInHours()
 {
     return $this->startDate->diffInHours($this->endDate);
 }
 /**
  * Takes a laravel collection (see https://laravel.com/docs/5.2/collections) 
  * of Session instances (instances of the 'Session' model) and returns
  * a mapping (an associative array ) where each key represents a role
  * that a PHD student may undertake for a session and each key
  * represents the number of hours that are related to that role
  * for the sessions passed to the function.
  * 
  * @param collection $sessions
  * @return [] $hoursWorkedMapping
  */
 public function getRoleToHoursWorkedMapping($sessions)
 {
     $hoursWorkedMapping = array('Demonstrator' => 0, 'Teaching' => 0);
     foreach ($sessions as $session) {
         $startTime = new Carbon($session->start_time);
         $endTime = new Carbon($session->end_time);
         $sessionDuration = $startTime->diffInHours($endTime);
         /*
             Work out what role the PHD student undertook for the session
             by querying the session's activity relationship to work out 
             what the parent support activity is for the session
             i.e. what support activity the sesion relates to then grab
             the value of the 'role_type' field of the support activity.
         */
         $role = $session->activity->role_type;
         $hoursWorkedMapping[$role] += $sessionDuration;
     }
     return $hoursWorkedMapping;
 }
Example #8
0
<?php

require_once 'vendor/autoload.php';
use Carbon\Carbon;
use Citco\Carbon as CitcoCarbon;
use CarbonExt\FiscalYear\Calculator;
// Object Instantiation
$brisbane = new Carbon('2015-12-01', 'Australia/Brisbane');
$newYorkCity = new Carbon('2015-12-01', 'America/New_York');
$dtBerlin = new Carbon('2015-12-01', 'Europe/Berlin');
$outputString = "Time difference between %s & %s: %s hours.\n";
// Date difference
printf($outputString, "Berlin", "Brisbane, Australia", $dtBerlin->diffInHours($brisbane, false));
printf($outputString, "Berlin", "New York City, America", $dtBerlin->diffInHours($newYorkCity, false));
$septEighteen2014 = Carbon::createFromDate(2014, 9, 18, $dtBerlin->getTimezone());
printf("difference between now and %s in \n\thours: %d, \n\tdays: %d, \n\tweeks: %d, \n\tweekend days: %d, \n\tweek days: %s, \n\thuman readable: %s\n", $septEighteen2014->toFormattedDateString(), $dtBerlin->diffInHours($septEighteen2014), $dtBerlin->diffInDays($septEighteen2014), $dtBerlin->diffInWeeks($septEighteen2014), $dtBerlin->diffInWeekendDays($septEighteen2014), $dtBerlin->diffInWeekDays($septEighteen2014), $dtBerlin->diffForHumans($septEighteen2014));
// Date formatting
echo $dtBerlin->toDateString() . "\n";
echo $dtBerlin->toFormattedDateString() . "\n";
echo $dtBerlin->toTimeString() . "\n";
echo $dtBerlin->toDateTimeString() . "\n";
echo $dtBerlin->toDayDateTimeString() . "\n";
echo $dtBerlin->toRfc1036String() . "\n";
echo $dtBerlin->toAtomString() . "\n";
echo $dtBerlin->toCookieString() . "\n";
echo $dtBerlin->toRssString() . "\n";
$dtBerlin->setToStringFormat('l jS \\of F Y');
echo $dtBerlin . "\n";
echo (int) $dtBerlin->isLeapYear() . "\n";
// is* range of functions test
printf("Is yesterday? %s\n", $dtBerlin->isYesterday() ? "yes" : "no");
 public function enviarDatos($id)
 {
     $cajero = $this->cajeroRepo->findOrFail($id);
     $idCajero = $cajero->id;
     $fechaSistema = new Carbon();
     $sucursal = $this->sucursalRepo->findOrFail($cajero->idSucursal);
     $idBranch = $sucursal->idBranch;
     $branch = $this->branchRepo->findOrFail($idBranch);
     $fechaBranch = new Carbon($branch->fecha);
     $horario = $fechaBranch->diffInHours($fechaSistema, false);
     $message = "Los datos fueron registrados con exito en el servidor";
     $success = true;
     if ($horario >= 0 and $horario < 24) {
         $bitacora = $this->bitacoraRepo->findByFieldAnd2('id_cajero', $idCajero, 'tipo', 'pendiente');
         $contador = 0;
         foreach ($bitacora as $key => $value) {
             if ($value->tipo_transaccion == 'credito') {
                 //credito
                 $cliente['codigo'] = $value->codigo_cliente;
                 $cliente['dpi'] = $value->dpi;
                 $cliente['nit'] = $value->nit;
                 $cliente['nombre'] = $value->nombre;
                 $cliente['apellido'] = $value->apellido;
                 $cliente['direccion'] = $value->direccion;
                 $cliente['telefono'] = $value->telefono;
                 $cliente['fechaNacimiento'] = $value->nacimiento;
                 $cliente = $this->clienteRepo->create($cliente);
                 $credito['codigo'] = $value->codigo_credito;
                 $credito['saldo'] = $value['cuota_mensual_credito'] * $value['numero_cuotas_credito'];
                 $credito['interes'] = $value->interes_credito;
                 $credito['is_host'] = false;
                 $credito['idCliente'] = $cliente->id;
                 $credito['no_cuotas'] = $value['numero_cuotas_credito'];
                 $credito = $this->creditoRepo->create($credito);
                 $fechaPago = Carbon::now();
                 for ($i = 1; $i <= $value['numero_cuotas_credito']; $i++) {
                     $dataCuota['idCredito'] = $credito->id;
                     $dataCuota['montoCuota'] = $value['cuota_mensual_credito'];
                     $dataCuota['fechaPago'] = $fechaPago->addMonth();
                     $dataCuota['estado'] = 'activa';
                     $dataCuota['balance'] = $value['cuota_mensual_credito'];
                     $this->cuotaRepo->create($dataCuota);
                 }
                 $transaccion['code'] = $value->codigo_credito;
                 $transaccion['tipoTransaccion'] = 'credito';
                 $transaccion['monto'] = $credito->saldo;
                 $transaccion['estado'] = 'registrado';
                 $transaccion['idCajero'] = $idCajero;
                 $transaccion['idCredito'] = $credito->id;
                 $transaccion['idTipoMoneda'] = 1;
                 $transaccionMaster = $this->transaccionRepo->create($transaccion);
                 $bitacoraData = $this->bitacoraRepo->findOrFail($value->id);
                 $bitacoraData['tipo'] = 'registrado';
                 $bitacoraData['idTransaccionMaster'] = $transaccionMaster->id;
                 $bitacoraData->save();
                 $contador++;
             } else {
                 //abono de deuda
                 //Registro la transaccion
                 $transaccion['code'] = 'tr' + time();
                 $transaccion['tipoTransaccion'] = 'debito';
                 $transaccion['monto'] = $value->cantidad_credito;
                 $transaccion['estado'] = 'registrado';
                 $transaccion['idCajero'] = $idCajero;
                 $transaccion['idCredito'] = $value->id_credito;
                 $transaccion['idTipoMoneda'] = $value->id_tipo_moneda;
                 $transaccionMaster = $this->transaccionRepo->create($transaccion);
                 //Cancelar la cuota
                 $cuota = $this->cuotaRepo->findOrFail($value->id_cuota);
                 $cuota['estado'] = 'Cancelada';
                 $cuota['balance'] = 0.0;
                 $cuota->save();
                 //Actualizar el credito
                 $credito = $this->creditoRepo->findOrFail($value->id_credito);
                 $credito['saldo'] = $credito['saldo'] - $value['monto_transaccion'];
                 $credito->save();
                 //Cancelar la bitacora
                 $bitacoraData = $this->bitacoraRepo->findOrFail($value->id);
                 $bitacoraData['tipo'] = 'registrado';
                 $bitacoraData['idTransaccionMaster'] = $transaccionMaster->id;
                 $bitacoraData->save();
                 $contador++;
             }
         }
         if ($contador == 0) {
             $message = "Ningun registro para enviar al servidor";
         }
     } else {
         $message = "El servidor rechazo la peticion, la fecha de su Branch no coincide con la del servidor";
         $success = false;
     }
     return compact('success', 'message');
 }
Example #10
-3
 public function getProfile($userid)
 {
     $user = User::find($userid);
     if (count($user) >= 1) {
         $updated = new Carbon($user->updated_at);
         $now = Carbon::now();
         if ($updated->diff($now)->m < 1) {
             $lastOnline = "Last seen less than a minute ago";
         } elseif ($updated->diff($now)->h < 1) {
             $lastOnline = $updated->diffInMinutes($now) > 1 ? sprintf("Last seen %d minutes ago", $updated->diffInMinutes($now)) : sprintf("Last seen %d minute ago", $updated->diffInMinutes($now));
         } elseif ($updated->diff($now)->d < 1) {
             $lastOnline = $updated->diffInHours($now) > 1 ? sprintf("Last seen %d hours ago", $updated->diffInHours($now)) : sprintf("Last seen %d hour ago", $updated->diffInHours($now));
         } elseif ($updated->diff($now)->d < 7) {
             $lastOnline = $updated->diffInDays($now) > 1 ? sprintf("Last seen %d days ago", $updated->diffInDays($now)) : sprintf("Last seen %d day ago", $updated->diffInDays($now));
         } elseif ($updated->diff($now)->m < 1) {
             $lastOnline = $updated->diffInWeeks($now) > 1 ? sprintf("Last seen %d weeks ago", $updated->diffInWeeks($now)) : sprintf("Last seen %d week ago", $updated->diffInWeeks($now));
         } elseif ($updated->diff($now)->y < 1) {
             $lastOnline = $updated->diffInMonths($now) > 1 ? sprintf("Last seen %d months ago", $updated->diffInMonths($now)) : sprintf("Last seen %d month ago", $updated->diffInMonths($now));
         } else {
             $lastOnline = $updated->diffInYears($now) > 1 ? sprintf("Last seen %d years ago", $updated->diffInYears($now)) : sprintf("Last seen %d year ago", $updated->diffInYears($now));
         }
         return view('dashboard.userProfile', ['user' => $user, 'lastOnline' => $lastOnline]);
     } else {
         return view('dashboard.userProfile');
     }
 }