diff --git a/action.php b/action.php
index 650110d..0b20759 100644
--- a/action.php
+++ b/action.php
@@ -57,7 +57,7 @@ if ($action=='load')
mysqli_query($conn, $sql);
- header("Location: index.php");
+ //header("Location: index.php");
// Open uploaded CSV file with read-only mode
$csvFile = fopen($_FILES['file']['tmp_name'], 'r');
@@ -67,43 +67,72 @@ if ($action=='load')
// Parse data from CSV file line by line
// Parse data from CSV file line by line
- while (($getData = fgetcsv($csvFile, 10000, ",")) !== FALSE)
+ $i=1;
+ while (($getData = fgetcsv($csvFile, 10000, ";")) !== FALSE)
{
// Get row data
+ $code_JNL = $getData[2];
+ $date_piece = $getData[4];
+ $dmy=explode('/',$date_piece);
+ $date_piece=$dmy[2].'-'.$dmy[1].'-'.$dmy[0];
$no_compte = $getData[0];
$lib_compte = $getData[1];
- $code_JNL = $getData[2];
$No_piece = $getData[3];
- $date_piece = $getData[4];
- $compte_contrepartie = $getData[5];
$lib_mouvement = $getData[6];
- $debit = $getData[7];
- $credit = $getData[8];
- $solde = $getData[9];
- $sens = $getData[10];
- $code_activite = $getData[11];
- $lib_activite = $getData[12];
-
- // If user already exists in the database with the same email
- $query = "SELECT id FROM users WHERE email = '" . $getData[1] . "'";
-
- $check = mysqli_query($conn, $query);
-
- if ($check->num_rows > 0)
+ if (trim($getData[8])!='')
{
- mysqli_query($conn, "UPDATE users SET name = '" . $name . "', phone = '" . $phone . "', status = '" . $status . "', created_at = NOW() WHERE email = '" . $email . "'");
+ $credit = "-".str_replace(',','.',trim($getData[8]));
}
else
{
- mysqli_query($conn, "INSERT INTO users (name, email, phone, created_at, updated_at, status) VALUES ('" . $name . "', '" . $email . "', '" . $phone . "', NOW(), NOW(), '" . $status . "')");
-
+ $credit = '';
+ }
+
+ $code_activite = trim($getData[11]);
+
+
+ // // on ajoute la ligne si pas déjà ajoutée !
+ // $query = "SELECT count(*) FROM importation_data_aidimpact WHERE
+ // code_JNL='".$code_JNL."'
+ // AND date_piece='".$date_piece."'
+ // AND no_compte='".$no_compte."'
+ // AND No_piece='".$No_piece."'
+ // AND lib_mouvement='".$lib_mouvement."'
+ // AND credit='".$credit."'
+ // AND code_activite='".$code_activite."';";
+
+ // $check = mysqli_query($conn, $query);
+ // $row = mysqli_fetch_row($check);
+ // $num = $row[0];
+
+ // if ($num==0)
+ // {
+
+ $sql="INSERT INTO importation_data_aidimpact (id,code_JNL,date_piece,no_compte,No_piece,lib_mouvement,credit,code_activite) VALUES (".$id.",'".$code_JNL."','".$date_piece."','".$no_compte."','".$No_piece."','".$lib_mouvement."','".$credit."','".$code_activite."');";
+ //mysqli_query($conn, $sql);
+
+ if (!mysqli_query($conn,$sql)) {
+ echo "==>".$i.$getData[8]."
";
+ echo("Error description: " . mysqli_error($conn));
}
+ $i++;
+
+
+
+
}
// Close opened CSV file
fclose($csvFile);
-
+
+ //mise à jour du nombre de lignes importées
+ $sql="UPDATE importation SET count=".$i." WHERE id=".$id;
+
+ if (!mysqli_query($conn,$sql)) {
+ echo("Error description: " . mysqli_error($conn));
+ }
+
header("Location: index.php");
}
@@ -116,11 +145,52 @@ if ($action=='load')
}
elseif ($action=='remove')
{
- $sql="DELETE from importation where id=".$id;
- mysqli_query($conn, $sql);
+ $sql="DELETE from importation_data_aidimpact where id=".$id;
+ if (!mysqli_query($conn,$sql)) {
+ echo("Error description: " . mysqli_error($conn));
+ }
+
+ $sql="DELETE from importation where id=".$id;
+ if (!mysqli_query($conn,$sql)) {
+ echo("Error description: " . mysqli_error($conn));
+ }
+
header("Location: index.php");
}
+elseif ($action=='download')
+{
+
+
+
+ $sql="select code_JNL,date_piece,no_compte,lib_compte,No_piece,lib_mouvement,debit,credit,code_activite from importation_data_aidimpact where id=".$id;
+
+ $result=mysqli_query($conn, $sql);
+
+ $data = array();
+ if (mysqli_num_rows($result) > 0) {
+ while ($row = mysqli_fetch_assoc($result)) {
+ $data[] = $row;
+ }
+ }
+
+header('Content-Type: text/csv; charset=utf-8');
+header('Content-Disposition: attachment; filename=aidimpact.csv');
+$output = fopen('php://output', 'w');
+$header=implode(";",array('Code JNL','Date de pièce','N° de compte','Libellé du compte','N° de pièce','Libellé mouvement','Débit','Crédit','Codeactivité'))."\r\n";
+fputs($output, $header);
+
+
+if (count($data) > 0) {
+ foreach ($data as $row) {
+
+ $line=implode(";", $row)."\r\n";
+
+ fputs($output,$line);
+ //fputcsv($output, $row);
+ }
+}
+}
?>
\ No newline at end of file
diff --git a/index.php b/index.php
index d0a71fe..24ad1a4 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,7 @@