| Current Path : /home/ataenra/www/ATA/INTRANET/Admin/Gestion_ACC/AC/ |
| Current File : /home/ataenra/www/ATA/INTRANET/Admin/Gestion_ACC/AC/UpPointAutoConso.php |
<?php
$IDpmo = $_POST['ID_pmo'];
require_once 'PVGISClient.php';
require_once 'CsvConverter.php';
require_once 'FileManager.php';
if($_POST['nbo']==1){$pc = $_POST['pcentrale'];}
elseif($_POST['nbo']==2){$pc = $_POST['pcentrale']+$_POST['pcentrale2'];}
elseif($_POST['nbo']==3){$pc = $_POST['pcentrale']+$_POST['pcentrale2']+$_POST['pcentrale3'];}
if($pc <18){$PPV = 1500;$PM = 30;}elseif(($pc >18 )&&($pc <30)){$PPV = 1200;$PM = 25;}elseif($pc >30 ){$PPV = 1000; $PM=20;}
$PVF = $PPV*$pc;
$PMF = $PM*$pc;
//Type de financement
//COMPTANT
if($_POST['f_type']=='CPT'){
$taux = 0;
$duree = 0;
$invest = 0;
$f_final = $PVF;
$f_loyer = 0;
$f_cout = 0;
}
//FINANCEMENT CLIENT
if($_POST['f_type']=='FC'){
$taux = $_POST['f_taux'];
$duree = $_POST['f_duree'];
$invest = 0;
//calcul mensualité
$n = $PVF*$taux/12/100;
$dn3 = -($duree);
$dn2 = (1+(($taux/100)/12));
$dn1 = pow($dn2,$dn3);
$dn = (1-($dn1));
//calculs couts credit
$f_loyer = round($n/$dn,2);
$f_final = round(($f_loyer * $duree),2);
$f_cout = $f_final-$PVF;
}
//LEASING ATA
if($_POST['f_type']=='FATA'){
$taux = $_POST['f_taux1'];
$duree = $_POST['f_duree1'];
$invest = 0;
//calcul mensualité
$n = $PVF*$taux/12/100;
$dn3 = -($duree);
$dn2 = (1+(($taux/100)/12));
$dn1 = pow($dn2,$dn3);
$dn = (1-($dn1));
//calculs couts credit
$f_loyer = round($n/$dn,2);
$f_final = round(($f_loyer * $duree),2);
$f_cout = $f_final-$PVF;
}
//TIERS INVESTISSEUR
if($_POST['f_type']=='FTI'){
$taux = 0;
$duree = 0;
$invest = $_POST['f_invest'];
$f_final = 0;
$f_loyer = 0;
$f_cout = 0;
}
//CALCUL DES PRIMES ET TARIF EDF
$list1 = $dbco->prepare("SELECT prime, pachat FROM gest_acc_aci_s21 WHERE pmin < '$pc' AND pmax >= '$pc'");
$list1->execute();
$R1 = $list1->fetch(PDO::FETCH_OBJ);
$prime = $R1->prime*$pc;
$pachat = $R1->pachat;
$UP3 = $dbco->prepare("INSERT INTO gest_acc_sites (ID_pmo, Nom, Etat, site_type, racc, ID_abo, adresse, nbo, longitude, latitude, orientation, inclinaison, pcentrale, site_prime, site_pvinj, PV_install, PV_maint, f_type, f_taux, f_duree, f_invest, f_final, f_loyer, f_cout)
VALUES (:ID_pmo, :Nom, :Etat, :site_type, :racc, :ID_abo, :adresse, :nbo, :longitude, :latitude, :orientation, :inclinaison, :pcentrale, :site_prime, :site_pvinj, :PV_install, :PV_maint, :f_type, :f_taux, :f_duree, :f_invest, :f_final, :f_loyer, :f_cout)");
$UP3->bindparam(':ID_pmo',$_POST['ID_pmo']);
$UP3->bindvalue(':Etat','Incomplet');
$UP3->bindparam(':Nom',$_POST['site_nom']);
$UP3->bindparam(':site_type',$_POST['site_type']);
$UP3->bindparam(':racc',$_POST['racc']);
$UP3->bindparam(':ID_abo',$_POST['abo']);
$UP3->bindparam(':adresse',$_POST['site_adresse']);
$UP3->bindparam(':nbo',$_POST['nbo']);
$UP3->bindparam(':longitude',$_POST['longitude']);
$UP3->bindparam(':latitude',$_POST['latitude']);
$UP3->bindparam(':orientation',$_POST['orientation']);
$UP3->bindparam(':inclinaison',$_POST['inclinaison']);
$UP3->bindparam(':pcentrale',$pc);
$UP3->bindparam(':site_prime',$prime);
$UP3->bindparam(':site_pvinj',$pachat);
$UP3->bindvalue(':PV_install',$PVF);
$UP3->bindvalue(':PV_maint',$PMF);
$UP3->bindparam(':f_type',$_POST['f_type']);
$UP3->bindparam(':f_taux',$taux);
$UP3->bindparam(':f_duree',$duree);
$UP3->bindparam(':f_invest',$invest);
$UP3->bindparam(':f_final',$f_final);
$UP3->bindparam(':f_loyer',$f_loyer);
$UP3->bindparam(':f_cout',$f_cout);
$UP3->execute();
$IDsite= $dbco->lastInsertId();
if(isset($_FILES['CC']) && $_FILES['CC']['error'] === 0) {
$filename = $_FILES["CC"]["name"];
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$newname = "CC";
$chemin ="../../../FICHIERS/ACC/$IDpmo/Sites/$IDsite/CC";
// Vérifie si le répertoire existe :
if (!is_dir($chemin)) {mkdir($chemin, 0777,true);}
$cheminD ="../../../FICHIERS/ACC/$IDpmo/Sites/$IDsite/CC/$newname.$IDsite.$extension";
if (move_uploaded_file($_FILES["CC"]["tmp_name"], $cheminD)) {
//Rentrer les infos de la courbe de charge.
} else {
echo "<h4>Fichiers non téléchargés / Voici plus d'informations :\n</h4>";
}
}
try {
$lat = $_POST['latitude'];
$lon = $_POST['longitude'];
$peakpower = $_POST['pcentrale'];
$loss = 14;
$angle = $_POST['inclinaison'];
$aspect = $_POST['orientation'];
$pvgisClient = new PVGISClient();
$data = $pvgisClient->getData($lat, $lon, $peakpower, $loss, $angle, $aspect);
$converter = new CSVConverter();
$csvContent = $converter->convertToCSV($data);
$fileManager = new FileManager();
$filename = "CP.$IDsite.1";
$filepath = $fileManager->saveCSV($csvContent, $filename);
$message = "Fichier CSV créé avec succès : " . basename($filepath);
$success = true;
} catch (Exception $e) {
$message = "Erreur : " . $e->getMessage();
$success = false;
}
if($_POST['nbo']==2){
try {
$lat = $_POST['latitude'];
$lon = $_POST['longitude'];
$peakpower = $_POST['pcentrale2'];
$loss = 14;
$angle = $_POST['inclinaison2'];
$aspect = $_POST['orientation2'];
$pvgisClient = new PVGISClient();
$data = $pvgisClient->getData($lat, $lon, $peakpower, $loss, $angle, $aspect);
$converter = new CSVConverter();
$csvContent = $converter->convertToCSV($data);
$fileManager = new FileManager();
$filename = "CP.$IDsite.2";
$filepath = $fileManager->saveCSV($csvContent, $filename);
$message = "Fichier CSV créé avec succès : " . basename($filepath);
$success = true;
} catch (Exception $e) {
$message = "Erreur : " . $e->getMessage();
$success = false;
}
}
if($_POST['nbo']==3){
try {
$lat = $_POST['latitude'];
$lon = $_POST['longitude'];
$peakpower = $_POST['pcentrale2'];
$loss = 14;
$angle = $_POST['inclinaison2'];
$aspect = $_POST['orientation2'];
$pvgisClient = new PVGISClient();
$data = $pvgisClient->getData($lat, $lon, $peakpower, $loss, $angle, $aspect);
$converter = new CSVConverter();
$csvContent = $converter->convertToCSV($data);
$fileManager = new FileManager();
$filename = "CP.$IDsite.2";
$filepath = $fileManager->saveCSV($csvContent, $filename);
$message = "Fichier CSV créé avec succès : " . basename($filepath);
$success = true;
} catch (Exception $e) {
$message = "Erreur : " . $e->getMessage();
$success = false;
}
try {
$lat = $_POST['latitude'];
$lon = $_POST['longitude'];
$peakpower = $_POST['pcentrale3'];
$loss = 14;
$angle = $_POST['inclinaison3'];
$aspect = $_POST['orientation3'];
$pvgisClient = new PVGISClient();
$data = $pvgisClient->getData($lat, $lon, $peakpower, $loss, $angle, $aspect);
$converter = new CSVConverter();
$csvContent = $converter->convertToCSV($data);
$fileManager = new FileManager();
$filename = "CP.$IDsite.3";
$filepath = $fileManager->saveCSV($csvContent, $filename);
$message = "Fichier CSV créé avec succès : " . basename($filepath);
$success = true;
} catch (Exception $e) {
$message = "Erreur : " . $e->getMessage();
$success = false;
}
}
?>
<div class="container1">
<?php if (isset($message)){echo htmlspecialchars($message);} ?>
</div>
<?php
require ('CSVCC.php');
require ('CSVAC.php');
$UP6 = $dbco->prepare('UPDATE gest_acc_sites SET Etat = :Etat WHERE ID_acc_site = :ID_acc_site');
$UP6->bindvalue('Etat','Incomplet');
$UP6->bindvalue('ID_acc_site',$IDsite);
$UP6->execute();
?>