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)
|
private function populateDevisDataIntoThanatoExportFileContent(string $fileContent, array $devis)
|
||||||
{
|
{
|
||||||
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
$produitAsString = $this->getFormatDevisProduitsAsString($devis["produits"]);
|
||||||
$devisNum = (string)$devis["calendar_uuid"];
|
$devisNum = (string)($devis["calendar_uuid"] ?? "");
|
||||||
|
|
||||||
$fileContent = $fileContent.
|
$fileContent = $fileContent.
|
||||||
FileExportHelpers::FormatTextForExport($devisNum).';'.
|
FileExportHelpers::FormatTextForExport($devisNum).';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis['nom_thanato'] . ' ' . $devis['prenom_thanato']).';'.
|
FileExportHelpers::FormatTextForExport(($devis['nom_thanato'] ?? '') . ' ' . ($devis['prenom_thanato'] ?? '')).';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis["date"]).';'.
|
FileExportHelpers::FormatTextForExport($devis["date"] ?? "").';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis["startTime"]).';'.
|
FileExportHelpers::FormatTextForExport($devis["startTime"] ?? "").';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis["endTime"]).';'.
|
FileExportHelpers::FormatTextForExport($devis["endTime"] ?? "").';'.
|
||||||
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
FileExportHelpers::FormatTextForExport($produitAsString).';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis["dayType"]).';'.
|
FileExportHelpers::FormatTextForExport($devis["dayType"] ?? "").';'.
|
||||||
FileExportHelpers::FormatTextForExport('Non').';'.
|
'Non'.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis["nom_defunt"]).';'.
|
FileExportHelpers::FormatTextForExport($devis["nom_defunt"] ?? "").';'. // ICI
|
||||||
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
FileExportHelpers::FormatTextForExport($devis["nom_lieu"] ?? "").';'.
|
||||||
FileExportHelpers::FormatTextForExport($devis["nom_client"] ?? "").';'.
|
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\Constants\GeoConstant;
|
||||||
use OCA\Gestion\Helpers\GeoHelpers;
|
use OCA\Gestion\Helpers\GeoHelpers;
|
||||||
|
|
||||||
class GeoService {
|
class GeoService
|
||||||
|
{
|
||||||
public function __construct() {
|
public function __construct()
|
||||||
}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calcul la distance entre les deux points à vol d'oiseau
|
* 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
|
$R = 6371; // Rayon moyen de la Terre en kilomètres
|
||||||
$dLat = deg2rad($lat2 - $lat1);
|
$dLat = deg2rad($lat2 - $lat1);
|
||||||
$dLon = deg2rad($lon2 - $lon1);
|
$dLon = deg2rad($lon2 - $lon1);
|
||||||
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2);
|
$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));
|
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
||||||
$d = $R * $c;
|
$d = $R * $c;
|
||||||
return round($d, 2);
|
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";
|
$baseUrl = "https://api.geoapify.com/v1/routing";
|
||||||
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"],$origin["longitude"]);
|
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"], $origin["longitude"]);
|
||||||
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"],$destination["longitude"]);
|
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"], $destination["longitude"]);
|
||||||
|
|
||||||
$fullUrl = $baseUrl."?waypoints=$originPoints|$destinationPoints&mode=$mode&apiKey=9e23d93e7f454c988344f9171bf867aa";
|
$fullUrl = $baseUrl."?waypoints=$originPoints|$destinationPoints&mode=$mode&apiKey=9e23d93e7f454c988344f9171bf867aa";
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
@ -79,39 +82,39 @@ class GeoService {
|
|||||||
$travelTimeHours = round($travelTimeHours, 2);
|
$travelTimeHours = round($travelTimeHours, 2);
|
||||||
return $travelTimeHours;
|
return $travelTimeHours;
|
||||||
}
|
}
|
||||||
}
|
} catch(Exception $e) {
|
||||||
catch(Exception $e){
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines(array $routeLines){
|
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLinesSave(array $routeLines)
|
||||||
|
{
|
||||||
$distanceCumul = 0;
|
$distanceCumul = 0;
|
||||||
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
||||||
$lastPoint = NULL;
|
$lastPoint = null;
|
||||||
for ($i=0; $i < sizeof($routeLines); $i++) {
|
for ($i = 0; $i < sizeof($routeLines); $i++) {
|
||||||
$currentDistance = 0;
|
$currentDistance = 0;
|
||||||
if($routeLines[$i]['lieu_id'] != NULL){
|
if($routeLines[$i]['lieu_id'] != null) {
|
||||||
$lastPoint = $routeLines[$i];
|
$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(
|
$currentDistance = $this->getDistanceInKmBetweenTwoPoints(
|
||||||
floatval(value: $lastPoint['latitude']),
|
floatval(value: $lastPoint['latitude']),
|
||||||
floatval($lastPoint['longitude']),
|
floatval($lastPoint['longitude']),
|
||||||
floatval($routeLines[$i+1]['latitude']),
|
floatval($routeLines[$i + 1]['latitude']),
|
||||||
floatval($routeLines[$i+1]['longitude'])
|
floatval($routeLines[$i + 1]['longitude'])
|
||||||
);
|
);
|
||||||
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i+1]["source"] != "siege";
|
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i + 1]["source"] != "siege";
|
||||||
if($targetIsBetweenTwoDevisLocation){
|
if($targetIsBetweenTwoDevisLocation) {
|
||||||
$originPoints = [
|
$originPoints = [
|
||||||
"latitude" => $lastPoint["latitude"],
|
"latitude" => $lastPoint["latitude"],
|
||||||
"longitude" => $lastPoint["longitude"]
|
"longitude" => $lastPoint["longitude"]
|
||||||
];
|
];
|
||||||
$destinationPoints = [
|
$destinationPoints = [
|
||||||
"latitude" => $routeLines[$i+1]["latitude"],
|
"latitude" => $routeLines[$i + 1]["latitude"],
|
||||||
"longitude" => $routeLines[$i+1]["longitude"]
|
"longitude" => $routeLines[$i + 1]["longitude"]
|
||||||
];
|
];
|
||||||
$totalTravelingHoursBetweenTwoDevisLocation+= $this->getTravelingHourBetweenTwoPoints(
|
$totalTravelingHoursBetweenTwoDevisLocation += $this->getTravelingHourBetweenTwoPoints(
|
||||||
$originPoints,
|
$originPoints,
|
||||||
$destinationPoints,
|
$destinationPoints,
|
||||||
GeoConstant::DRIVING_MODE
|
GeoConstant::DRIVING_MODE
|
||||||
@ -125,4 +128,65 @@ class GeoService {
|
|||||||
"totalTravelingHours" => $totalTravelingHoursBetweenTwoDevisLocation
|
"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