Your IP : 216.73.216.212


Current Path : /home/a/t/a/ataenra/www/ATA/INTRANET/Admin/Gestion_ACC/PV/
Upload File :
Current File : /home/a/t/a/ataenra/www/ATA/INTRANET/Admin/Gestion_ACC/PV/UpPointProdac.php

<?php
$IDpmo = $_POST['ID_pmo'];
$IDsite = $_POST['ID_site'];
require_once 'PVGISClient.php';
require_once 'CsvConverter.php';
require_once 'FileManager.php'; 

if($_POST['pcentrale'] <18){$PPV = 1500; $PM=30;}elseif(($_POST['pcentrale'] >18 )&&($_POST['pcentrale'] <36)){$PPV = 1200; $PM=25;}elseif($_POST['pcentrale'] >36 ){$PPV = 1000;$PM=20;}
$PVF = $PPV*$_POST['pcentrale'];
$PMF = $PM*$_POST['pcentrale'];

//Puissance centrale 
$pc = $_POST['pcentrale'];


//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;
    }



$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;



$UP6 = $dbco->prepare('UPDATE gest_acc_sites SET CP = :CP, site_type = :site_type, orientation = :orientation, inclinaison = :inclinaison, pcentrale = :pcentrale, 
site_prime = :site_prime, site_pvinj = :site_pvinj, Etat = :Etat, PV_install = :PV_install, PV_maint = :PV_maint, f_type = :f_type, f_taux = :f_taux, f_duree = :f_duree, f_invest = :f_invest, f_loyer = :f_loyer, f_final = :f_final, f_cout = :f_cout WHERE ID_acc_site = :ID_acc_site');
$UP6->bindvalue('CP','Non');
$UP6->bindvalue('site_type','AutoConso');
$UP6->bindparam('orientation',$_POST['orientation']);
$UP6->bindparam('inclinaison',$_POST['inclinaison']);
$UP6->bindparam('pcentrale',$_POST['pcentrale']);
$UP6->bindvalue('Etat','Incomplet');
$UP6->bindparam('site_prime',$prime);
$UP6->bindparam('site_pvinj',$pachat);
$UP6->bindvalue('ID_acc_site',$_POST['ID_site']);
$UP6->bindvalue('PV_install',$PVF);
$UP6->bindvalue('PV_maint',$PMF);
$UP6->bindvalue('f_type',$_POST['f_type']);
$UP6->bindvalue('f_taux',$taux);
$UP6->bindvalue('f_duree',$duree);
$UP6->bindvalue('f_invest',$invest);
$UP6->bindvalue('f_loyer',$f_loyer);
$UP6->bindvalue('f_final',$f_final);
$UP6->bindvalue('f_cout',$f_cout);
$UP6->execute();

$list1 = $dbco->prepare("SELECT * FROM gest_acc_sites S JOIN gest_acc_pmo P ON S.ID_pmo=P.ID_pmo WHERE S.ID_pmo='$IDpmo' AND S.ID_acc_site ='$IDsite'"); 
$list1->execute();
$R1 = $list1->fetch(PDO::FETCH_OBJ);


    try {
       
        $lat = $R1->latitude;
        $lon = $R1->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";
        $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 ('CSVAC.php');

?>