root 3 years ago
parent
commit
166a7d8998
5 changed files with 1489 additions and 8 deletions
  1. +126
    -0
      action.php
  2. +10
    -0
      db.php
  3. +39
    -8
      index.php
  4. +32
    -0
      load_data.php
  5. +1282
    -0
      phpminiadmin.php

+ 126
- 0
action.php View File

@ -0,0 +1,126 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// include mysql database configuration file
include_once 'db.php';
$action=$_GET['action'];
if (isset($_GET['id']))
{
$id=$_GET['id'];
}
if ($action=='load')
{
if (isset($_POST['submit']))
{
// Allowed mime types
$fileMimes = array(
'text/x-comma-separated-values',
'text/comma-separated-values',
'application/octet-stream',
'application/vnd.ms-excel',
'application/x-csv',
'text/x-csv',
'text/csv',
'application/csv',
'application/excel',
'application/vnd.msexcel',
'text/plain'
);
// Validate whether selected file is a CSV file
if (!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'], $fileMimes))
{
//ajout du fichier dans la table importation_compta
$sql="INSERT INTO importation (date_import, filename,count) VALUES (NOW(), '" . $_FILES['file']['name'] . "',0)";
mysqli_query($conn, $sql);
//recuperation de l'id de la ligne ajoutée
$sql="select id from importation order by id desc LIMIT 1";
$result=mysqli_query($conn, $sql);
foreach ($result as $row)
{
$id=$row['id'];
}
//mise à jour du champ pour identifier le dernier import
$sql="UPDATE importation set last=False";
mysqli_query($conn, $sql);
$sql="UPDATE importation set last=True where id=$id";
mysqli_query($conn, $sql);
header("Location: index.php");
// Open uploaded CSV file with read-only mode
$csvFile = fopen($_FILES['file']['tmp_name'], 'r');
// Skip the first line
fgetcsv($csvFile);
// Parse data from CSV file line by line
// Parse data from CSV file line by line
while (($getData = fgetcsv($csvFile, 10000, ",")) !== FALSE)
{
// Get row data
$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)
{
mysqli_query($conn, "UPDATE users SET name = '" . $name . "', phone = '" . $phone . "', status = '" . $status . "', created_at = NOW() WHERE email = '" . $email . "'");
}
else
{
mysqli_query($conn, "INSERT INTO users (name, email, phone, created_at, updated_at, status) VALUES ('" . $name . "', '" . $email . "', '" . $phone . "', NOW(), NOW(), '" . $status . "')");
}
}
// Close opened CSV file
fclose($csvFile);
header("Location: index.php");
}
else
{
echo "Please select valid file";
}
}
}
elseif ($action=='remove')
{
$sql="DELETE from importation where id=".$id;
mysqli_query($conn, $sql);
header("Location: index.php");
}
?>

+ 10
- 0
db.php View File

@ -0,0 +1,10 @@
<?php
$servername='10.10.10.102';
$username='oe';
$password='toto2018';
$dbname = "oe_aidimpact";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect MySql Server:' .mysql_error());
}
?>

+ 39
- 8
index.php View File

@ -64,6 +64,11 @@
Exports AidImpact
</a>
</nav>
<?php
//Chargement de la liste des imports
include_once 'load_data.php';
?>
<table id="table" class="table">
<thead>
<tr>
@ -76,28 +81,54 @@
</tr>
</thead>
<tbody>
<?php echo $tr; ?>
</tbody>
</table>
<form id="form" action="action.php?action=load" method="post" enctype="multipart/form-data">
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" id="customFileInput" aria-describedby="customFileInput" name="file">
<label class="custom-file-label" for="customFileInput">Sélectionner le fichier comptable</label>
</div>
<div class="input-group-append">
<input type="submit" name="submit" value="Upload" class="btn btn-primary">
</div>
</div>
</form>
<button type="button" class="btn btn-warning" aria-label="Left Align">
<!-- <button type="button" class="btn btn-warning" aria-label="Left Align">
<span>Importer un fichier comptable</span>
</button>
</button> -->
</div>
</body>
<script type="text/javascript">
$(document).ready(function () {
for (let pas = 0; pas < 30; pas++) {
$( "#table" ).append(
"<tr><td>28/08/2022 13:02:30</td><td>GLA112-Z03 Z09 Z14A Z06 Z06A - originecompta.csv</td><td>100</td><td><button type='button' class='btn btn-primary' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-success' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-danger' aria-label='Left Align'> <i class='fa-solid fa-trash'></i></td></tr>");
function remove(id)
{
//alert(id);
window.location.replace('action.php?action=remove&id='+id);
$('#form').attr('action', 'action.php?action=remove&id='+id);
$('#form').submit();
}
$(document).ready(function () {
// $( "#table" ).append(
// "<tr><td>28/08/2022 13:02:30</td><td>GLA112-Z03 Z09 Z14A Z06 Z06A - originecompta.csv</td><td>100</td><td><button type='button' class='btn btn-primary' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-success' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-danger' aria-label='Left Align'> <i class='fa-solid fa-trash'></i></td></tr>");
// for (let pas = 0; pas < 30; pas++) {
// $( "#table" ).append(
// "<tr><td>28/08/2022 13:02:30</td><td>GLA112-Z03 Z09 Z14A Z06 Z06A - originecompta.csv</td><td>100</td><td><button type='button' class='btn btn-primary' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-success' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td></td></tr>");
// }
$('#table').DataTable(
{
language: {
url: 'datatables.french.json'
}
},
bSort: false
}
);


+ 32
- 0
load_data.php View File

@ -0,0 +1,32 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// include mysql database configuration file
include_once 'db.php';
$query = "SELECT id,date_import,filename,last FROM importation ORDER BY id DESC;";
$result = mysqli_query($conn, $query);
$tr="";
if ($result->num_rows > 0)
{
$i=1;
foreach ($result as $row)
{
if ($row['last']==True)
{
//ajout du bouton de suppression
$tr.="<tr><td>".$row['date_import']."</td><td>".$row['filename']."</td><td>0</td><td><button type='button' class='btn btn-primary' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-success' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' onclick='remove(".$row['id'].");' class='btn btn-danger' aria-label='Left Align'> <i class='fa-solid fa-trash'></i></td></tr>";
}
else
{
$tr.="<tr><td>".$row['date_import']."</td><td>".$row['filename']."</td><td>0</td><td><button type='button' class='btn btn-primary' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td><button type='button' class='btn btn-success' aria-label='Left Align'> <i class='fa-solid fa-download'></i></td><td></td></tr>";
}
$i++;
}
}
?>

+ 1282
- 0
phpminiadmin.php
File diff suppressed because it is too large
View File


Loading…
Cancel
Save