fix erreur stats thanato
This commit is contained in:
parent
03784fd8e6
commit
a28b7f6ea6
@ -369,22 +369,23 @@ class ExportThanatoStatisticService
|
||||
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent, array $devis)
|
||||
{
|
||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||
$devisNum = (string)$devis["calendar_uuid"];
|
||||
$devisNum = (string)($devis["calendar_uuid"] ?? "");
|
||||
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($devisNum).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanato']).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["date"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
|
||||
FileExportHelpers::FormatTextForExport(($devis['nom_thanato'] ?? '') . ' ' . ($devis['prenom_thanato'] ?? '')).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["date"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["startTime"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["endTime"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
|
||||
FileExportHelpers::FormatTextForExport('Non').';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["dayType"] ?? "").';'.
|
||||
'Non'.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"] ?? "").';'. // ICI
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").
|
||||
FileExportHelpers::FormatTextForExport($devis["client_adresse"] ?? "").';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
|
||||
@ -30,28 +30,31 @@ use Exception;
|
||||
use OCA\Gestion\Constants\GeoConstant;
|
||||
use OCA\Gestion\Helpers\GeoHelpers;
|
||||
|
||||
class GeoService {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
class GeoService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcul la distance entre les deux points à vol d'oiseau
|
||||
*/
|
||||
private function getDistanceInKmBetweenTwoPoints($lat1, $lon1, $lat2, $lon2) {
|
||||
private function getDistanceInKmBetweenTwoPoints($lat1, $lon1, $lat2, $lon2)
|
||||
{
|
||||
$R = 6371; // Rayon moyen de la Terre en kilomètres
|
||||
$dLat = deg2rad($lat2 - $lat1);
|
||||
$dLon = deg2rad($lon2 - $lon1);
|
||||
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2);
|
||||
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
|
||||
$a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon / 2) * sin($dLon / 2);
|
||||
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
||||
$d = $R * $c;
|
||||
return round($d, 2);
|
||||
}
|
||||
|
||||
private function getTravelingHourBetweenTwoPoints(array $origin,array $destination,$mode = "driving"){
|
||||
private function getTravelingHourBetweenTwoPoints(array $origin, array $destination, $mode = "driving")
|
||||
{
|
||||
$baseUrl = "https://api.geoapify.com/v1/routing";
|
||||
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"],$origin["longitude"]);
|
||||
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"],$destination["longitude"]);
|
||||
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"], $origin["longitude"]);
|
||||
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"], $destination["longitude"]);
|
||||
|
||||
$fullUrl = $baseUrl."?waypoints=$originPoints|$destinationPoints&mode=$mode&apiKey=9e23d93e7f454c988344f9171bf867aa";
|
||||
$curl = curl_init();
|
||||
@ -66,11 +69,11 @@ class GeoService {
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'GET',
|
||||
));
|
||||
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
|
||||
if ($response === false) {
|
||||
return 0;
|
||||
} else {
|
||||
@ -79,45 +82,45 @@ class GeoService {
|
||||
$travelTimeHours = round($travelTimeHours, 2);
|
||||
return $travelTimeHours;
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
} catch(Exception $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines(array $routeLines){
|
||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLinesSave(array $routeLines)
|
||||
{
|
||||
$distanceCumul = 0;
|
||||
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
||||
$lastPoint = NULL;
|
||||
for ($i=0; $i < sizeof($routeLines); $i++) {
|
||||
$lastPoint = null;
|
||||
for ($i = 0; $i < sizeof($routeLines); $i++) {
|
||||
$currentDistance = 0;
|
||||
if($routeLines[$i]['lieu_id'] != NULL){
|
||||
if($routeLines[$i]['lieu_id'] != null) {
|
||||
$lastPoint = $routeLines[$i];
|
||||
}
|
||||
if($lastPoint['lieu_id'] != NULL && $routeLines[$i+1]['lieu_id'] != NULL){
|
||||
}
|
||||
if($lastPoint['lieu_id'] != null && $routeLines[$i + 1]['lieu_id'] != null) {
|
||||
$currentDistance = $this->getDistanceInKmBetweenTwoPoints(
|
||||
floatval(value: $lastPoint['latitude']),
|
||||
floatval($lastPoint['longitude']),
|
||||
floatval($routeLines[$i+1]['latitude']),
|
||||
floatval($routeLines[$i+1]['longitude'])
|
||||
floatval(value: $lastPoint['latitude']),
|
||||
floatval($lastPoint['longitude']),
|
||||
floatval($routeLines[$i + 1]['latitude']),
|
||||
floatval($routeLines[$i + 1]['longitude'])
|
||||
);
|
||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i+1]["source"] != "siege";
|
||||
if($targetIsBetweenTwoDevisLocation){
|
||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i + 1]["source"] != "siege";
|
||||
if($targetIsBetweenTwoDevisLocation) {
|
||||
$originPoints = [
|
||||
"latitude" => $lastPoint["latitude"],
|
||||
"longitude" => $lastPoint["longitude"]
|
||||
];
|
||||
$destinationPoints = [
|
||||
"latitude" => $routeLines[$i+1]["latitude"],
|
||||
"longitude" => $routeLines[$i+1]["longitude"]
|
||||
"latitude" => $routeLines[$i + 1]["latitude"],
|
||||
"longitude" => $routeLines[$i + 1]["longitude"]
|
||||
];
|
||||
$totalTravelingHoursBetweenTwoDevisLocation+= $this->getTravelingHourBetweenTwoPoints(
|
||||
$totalTravelingHoursBetweenTwoDevisLocation += $this->getTravelingHourBetweenTwoPoints(
|
||||
$originPoints,
|
||||
$destinationPoints,
|
||||
GeoConstant::DRIVING_MODE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$distanceCumul += $currentDistance;
|
||||
}
|
||||
return [
|
||||
@ -125,4 +128,65 @@ class GeoService {
|
||||
"totalTravelingHours" => $totalTravelingHoursBetweenTwoDevisLocation
|
||||
];
|
||||
}
|
||||
|
||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines(array $routeLines)
|
||||
{
|
||||
$distanceCumul = 0;
|
||||
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
||||
$lastPoint = null;
|
||||
|
||||
for ($i = 0; $i < sizeof($routeLines); $i++) {
|
||||
$currentDistance = 0;
|
||||
|
||||
// Vérifier que l'élément actuel existe
|
||||
if(!isset($routeLines[$i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($routeLines[$i]['lieu_id'] != null) {
|
||||
$lastPoint = $routeLines[$i];
|
||||
}
|
||||
|
||||
// Vérifier que $i+1 existe ET que $lastPoint n'est pas null
|
||||
if($lastPoint !== null &&
|
||||
isset($routeLines[$i + 1]) &&
|
||||
isset($lastPoint['lieu_id']) &&
|
||||
isset($routeLines[$i + 1]['lieu_id']) &&
|
||||
$lastPoint['lieu_id'] != null &&
|
||||
$routeLines[$i + 1]['lieu_id'] != null) {
|
||||
|
||||
$currentDistance = $this->getDistanceInKmBetweenTwoPoints(
|
||||
floatval($lastPoint['latitude']),
|
||||
floatval($lastPoint['longitude']),
|
||||
floatval($routeLines[$i + 1]['latitude']),
|
||||
floatval($routeLines[$i + 1]['longitude'])
|
||||
);
|
||||
|
||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i + 1]["source"] != "siege";
|
||||
|
||||
if($targetIsBetweenTwoDevisLocation) {
|
||||
$originPoints = [
|
||||
"latitude" => $lastPoint["latitude"],
|
||||
"longitude" => $lastPoint["longitude"]
|
||||
];
|
||||
$destinationPoints = [
|
||||
"latitude" => $routeLines[$i + 1]["latitude"],
|
||||
"longitude" => $routeLines[$i + 1]["longitude"]
|
||||
];
|
||||
$totalTravelingHoursBetweenTwoDevisLocation += $this->getTravelingHourBetweenTwoPoints(
|
||||
$originPoints,
|
||||
$destinationPoints,
|
||||
GeoConstant::DRIVING_MODE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$distanceCumul += $currentDistance;
|
||||
}
|
||||
|
||||
return [
|
||||
"totalDistance" => round($distanceCumul, 2),
|
||||
"totalTravelingHours" => round($totalTravelingHoursBetweenTwoDevisLocation, 2)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user