Compare commits
No commits in common. "d9e799a5389c7bfa5dfdecc3f8d7d35aa1aede78" and "0b085a45864affb246246cc245a1eeeeb654d3fd" have entirely different histories.
d9e799a538
...
0b085a4586
14 changed files with 71 additions and 365 deletions
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
$relativePath = "../";
|
||||
|
||||
$pageTitle = "Gestion des articles";
|
||||
$script = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/articles.js\"></script>";
|
||||
include("template.php");
|
||||
|
|
@ -2,28 +2,13 @@
|
|||
$relativePath = "../";
|
||||
ob_start();
|
||||
?>
|
||||
<div class="admin-container" style="display: flex">
|
||||
<div style="margin: auto">
|
||||
<div style="display: flex" class="my-5">
|
||||
<a href="stock.php" style="margin: auto">
|
||||
<button class="btn btn-success btn-lg">Gestion du stocks</button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="my-5" style="display: flex">
|
||||
<a href="articles.php" style="margin: auto" class="mx-1">
|
||||
<button class="btn btn-primary btn-lg">Créer/Éditer des articles</button>
|
||||
</a>
|
||||
<a href="categories.php" style="margin: auto" class="mx-1">
|
||||
<button class="btn btn-primary btn-lg">Créer/Éditer des catégories</button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div style="display: flex" class="my-5">
|
||||
<button id="uploadButton" class="btn btn-warning btn-lg" style="margin: auto">Mettre l'inventaire en ligne
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-container">
|
||||
<a href="stock.php">
|
||||
<button class="btn btn-primary btn-large">Gestion des stocks</button>
|
||||
</a>
|
||||
<a href="categories.php">
|
||||
<button class="btn btn-primary btn-large">Gestion des catégories</button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/admin.css" media="screen,projection"/>
|
||||
|
|
@ -31,12 +16,5 @@ ob_start();
|
|||
<?php
|
||||
$pageContent = ob_get_clean();
|
||||
$pageTitle = "Admin";
|
||||
$pageScripts =
|
||||
"
|
||||
<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/jquery-confirm-defaults.js\"></script>
|
||||
<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/index.js\"></script>
|
||||
";
|
||||
|
||||
|
||||
include($relativePath . "includes/template.php");
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
$relativePath = "../";
|
||||
|
||||
$isStock = true;
|
||||
$pageTitle = "Gestion des stocks";
|
||||
$script = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/stock.js\"></script>";
|
||||
$pageTitle = "Gestion des articles";
|
||||
$script = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/articles.js\"></script>";
|
||||
include("template.php");
|
||||
|
|
|
|||
|
|
@ -1,61 +1,35 @@
|
|||
<?php
|
||||
$relativePath = "../";
|
||||
|
||||
if (!isset($isStock))
|
||||
$isStock = false;
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="admin-container">
|
||||
|
||||
<a href="index.php">
|
||||
<button class="btn btn-primary btn-large">
|
||||
<span class="mdi mdi-chevron-left"></span>
|
||||
Retour
|
||||
</button>
|
||||
<button class="btn btn-primary btn-large">Retour</button>
|
||||
</a>
|
||||
|
||||
<h1 class="text-center"><?= $pageTitle ?></h1>
|
||||
|
||||
<?php if (!$isStock): ?>
|
||||
<div style="display: flex">
|
||||
<button class="btn btn-success" style="margin: auto" onclick="listManager.showEditPopup(-1)">
|
||||
<i class="mdi mdi-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div id="listContainer">
|
||||
<ul id="dataList">
|
||||
<div style="display: flex">
|
||||
<button class="btn btn-success" style="margin: auto" onclick="listManager.showEditPopup(-1)">
|
||||
<i class="mdi mdi-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div>
|
||||
<h3 class="text-center">Mode</h3>
|
||||
<div class="button-container">
|
||||
<button id="buyButton" class="btn mr-0">Achat</button>
|
||||
<button id="sellButton" class="btn ml-0">Vente</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="dataList">
|
||||
<div id="listContainer">
|
||||
<ul id="dataList">
|
||||
|
||||
</div>
|
||||
<div style="display: flex">
|
||||
<button id="saveButton" style="margin: auto" class="btn btn-lg my-2">Sauvegarder</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/libs/materialdesignicons.min.css"
|
||||
media="screen,projection"/>
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/libs/materialdesignicons.min.css" media="screen,projection"/>
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/admin.css" media="screen,projection"/>
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/categories.css" media="screen,projection"/>
|
||||
|
||||
<?php if (!$isStock): ?>
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/list.css" media="screen,projection"/>
|
||||
<?php else: ?>
|
||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/stock.css" media="screen,projection"/>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
$pageContent = ob_get_clean();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,22 @@
|
|||
<?php
|
||||
$relativePath = "../";
|
||||
require_once $relativePath.'classes/postHandler.php';
|
||||
$rest_json = file_get_contents("php://input");
|
||||
$_POST = json_decode($rest_json, true);
|
||||
|
||||
$handler = new PostHandler(null, null);
|
||||
|
||||
echo json_encode($handler->write_json());
|
||||
//var_dump($_POST);
|
||||
|
||||
$fp = fopen('../data/stock-v2.json', 'w');
|
||||
$result = fwrite($fp, json_encode($_POST["v2"]));
|
||||
fclose($fp);
|
||||
|
||||
$fp = fopen('../data/stock.json', 'w');
|
||||
$result = fwrite($fp, json_encode($_POST["v1"]));
|
||||
fclose($fp);
|
||||
|
||||
if ($result) {
|
||||
echo 'Réussite !';
|
||||
} else {
|
||||
echo 'Echec!
|
||||
'; // Allows to create a newline
|
||||
var_dump($_POST);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@
|
|||
margin: 20px 0 20px 0;
|
||||
}
|
||||
|
||||
#listContainer .mdi {
|
||||
.mdi {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.list-name {
|
||||
font-weight: bold;
|
||||
width: 200px;
|
||||
width: 150px;
|
||||
height: 50px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
|
@ -61,15 +61,7 @@
|
|||
text-align: right;
|
||||
}
|
||||
|
||||
.list-image {
|
||||
.list-image img {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
.list-image img {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
margin: auto;
|
||||
}
|
||||
|
|
@ -1,43 +1,33 @@
|
|||
#dataList {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto ;
|
||||
width: 100%;
|
||||
|
||||
.name-column {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.img-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
.quantity-column, .price-column {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
display: flex;
|
||||
padding: 5px;
|
||||
.code-column {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
|
||||
.grid-container {
|
||||
width: 100px;
|
||||
margin: auto;
|
||||
display: block;
|
||||
.type-column {
|
||||
width: 200px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.grid-container input {
|
||||
.image-column {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.actions-column {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.grid-container p {
|
||||
text-align: center;
|
||||
#stockTable tr {
|
||||
border-bottom: 1px solid #dedede;
|
||||
}
|
||||
|
||||
.grid-container img {
|
||||
width : 100px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.button-container {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.button-container button {
|
||||
margin: auto;
|
||||
.row-img {
|
||||
height: 50px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,23 +78,6 @@ class AjaxManager {
|
|||
} else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static async saveStockChange(data, isSell) {
|
||||
let formattedData = {
|
||||
type: 'stock',
|
||||
action: isSell ? 'sell' : 'buy',
|
||||
data: data,
|
||||
};
|
||||
let response = await $.ajax({
|
||||
type: "POST",
|
||||
url: "json_ajax.php",
|
||||
data: JSON.stringify(formattedData),
|
||||
dataType: "json",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
});
|
||||
console.log(response);
|
||||
return response['data'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
async function sendRequest() {
|
||||
let response = await $.ajax({
|
||||
type: "POST",
|
||||
url: "write_json.php",
|
||||
});
|
||||
response = JSON.parse(response);
|
||||
console.log(response);
|
||||
return response["status"];
|
||||
}
|
||||
|
||||
|
||||
$('#uploadButton').on('click', function () {
|
||||
$.confirm({
|
||||
title: 'Confirmer',
|
||||
content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS.",
|
||||
type: "orange",
|
||||
buttons: {
|
||||
formSubmit: {
|
||||
text: 'Confirmer',
|
||||
btnClass: "btn-warning",
|
||||
action: async function () {
|
||||
let result = await sendRequest();
|
||||
if (result !== 0) {
|
||||
$.alert({
|
||||
title: "Erreur",
|
||||
content: "Une erreur est survenue, merci de réessayer plus tard.",
|
||||
type: "red",
|
||||
})
|
||||
} else {
|
||||
$.alert({
|
||||
title: "Succès",
|
||||
content: "Le stock a bien été mis à jour.",
|
||||
type: "green",
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: 'Annuler',
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
2
assets/js/jquery-confirm-defaults.js
vendored
2
assets/js/jquery-confirm-defaults.js
vendored
|
|
@ -1,7 +1,7 @@
|
|||
jconfirm.defaults = {
|
||||
title: 'Title',
|
||||
titleClass: '',
|
||||
type: 'blue',
|
||||
type: 'red',
|
||||
typeAnimated: true,
|
||||
draggable: false,
|
||||
dragWindowGap: 15,
|
||||
|
|
|
|||
|
|
@ -138,9 +138,7 @@ class ListManager {
|
|||
}
|
||||
|
||||
getImagePicker(id, index) {
|
||||
let imageSrc = undefined;
|
||||
if (index !== -1)
|
||||
imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
|
||||
let imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
|
||||
return (
|
||||
'<img style="width: 50px; height: 50px" src="' + imageSrc + '" id="image_' + id + '"/>' +
|
||||
'<div class="custom-file">\n' +
|
||||
|
|
|
|||
|
|
@ -1,106 +0,0 @@
|
|||
let listContainer = $("#dataList");
|
||||
let displayedItems = [];
|
||||
let fetchedData = {};
|
||||
|
||||
let currentMode = "sell";
|
||||
|
||||
let sellCLass = 'btn-danger';
|
||||
let buyClass = 'btn-success';
|
||||
|
||||
$(document).ready(async function () {
|
||||
fetchedData = await AjaxManager.getAll();
|
||||
|
||||
$('#sellButton').addClass(sellCLass);
|
||||
$('#saveButton').addClass(sellCLass);
|
||||
|
||||
generateList();
|
||||
$('#buyButton').on('click', function () {
|
||||
if (!$(this).hasClass(buyClass)) {
|
||||
$(this).addClass(buyClass);
|
||||
$('#sellButton').removeClass(sellCLass);
|
||||
$('#saveButton').removeClass(sellCLass).addClass(buyClass);
|
||||
currentMode = "buy";
|
||||
}
|
||||
});
|
||||
$('#sellButton').on('click', function () {
|
||||
if (!$(this).hasClass(sellCLass)) {
|
||||
$(this).addClass(sellCLass);
|
||||
$('#buyButton').removeClass(buyClass);
|
||||
$('#saveButton').removeClass(buyClass).addClass(sellCLass);
|
||||
currentMode = "sell";
|
||||
}
|
||||
});
|
||||
$('#saveButton').on('click', function () {
|
||||
let values = getValues();
|
||||
let message = 'Voulez vous vraimer ajouter ces articles au stock ?<br><ul>';
|
||||
let color = 'green';
|
||||
if (currentMode === "sell"){
|
||||
message = 'Voulez vous vraiment supprimer ces articles du stock ?<br><ul>';
|
||||
color = 'red';
|
||||
}
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
if (values[i]['value'] > 0){
|
||||
message += '<li>' + fetchedData['articles'][i]['name'] + ' : ' + values[i]['value'] + '</li>'
|
||||
}
|
||||
}
|
||||
message += '</ul>';
|
||||
$.confirm({
|
||||
title: 'Confirmer',
|
||||
content: message,
|
||||
type: color,
|
||||
buttons: {
|
||||
formSubmit: {
|
||||
text: 'Confirmer',
|
||||
action: function () {
|
||||
window.location.reload();
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: 'Annuler',
|
||||
}
|
||||
}
|
||||
});
|
||||
AjaxManager.saveStockChange(getFormattedValues(values), currentMode === "sell");
|
||||
});
|
||||
});
|
||||
|
||||
function getListItem(item) {
|
||||
return (
|
||||
'<div class="grid-item">' +
|
||||
'<div class="grid-container">' +
|
||||
'<img class="list-image" src="../uploaded_images/' + item['id'] + '.jpg"/>' +
|
||||
'<p>' + item['name'] + '</p>' +
|
||||
'<p>Quantité : ' + item['quantity'] + '</p>' +
|
||||
'<input placeholder="Nombre" type="number" value="0" class="form-control"/>' +
|
||||
'</div>' +
|
||||
'</div>');
|
||||
}
|
||||
|
||||
|
||||
function generateList() {
|
||||
for (let i = 0; i < fetchedData['articles'].length; i++) {
|
||||
let listItem = getListItem(fetchedData['articles'][i]);
|
||||
displayedItems.push($(listItem));
|
||||
listContainer.append(displayedItems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getValues() {
|
||||
let values = [];
|
||||
for (let i = 0; i < displayedItems.length; i++) {
|
||||
let value = displayedItems[i].find('input').val();
|
||||
let id = fetchedData['articles'][i]['id'];
|
||||
values.push({id: id, value: value});
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
function getFormattedValues(values) {
|
||||
let newValues = [];
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
if (values[i]['value'] > 0)
|
||||
newValues.push(values[i]);
|
||||
}
|
||||
return newValues;
|
||||
}
|
||||
|
|
@ -35,19 +35,6 @@ class Dao
|
|||
return $cursor->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public function get_categories_of_article($articleid)
|
||||
{
|
||||
$sql = 'SELECT category_id FROM article_categories WHERE article_id=?';
|
||||
$cursor = $this->conn->prepare($sql);
|
||||
$cursor->execute([$articleid]);
|
||||
$result = $cursor->fetchAll(PDO::FETCH_ASSOC);
|
||||
$final = [];
|
||||
foreach ($result as $row) {
|
||||
array_push($final, $row["category_id"]);
|
||||
}
|
||||
return $final;
|
||||
}
|
||||
|
||||
public function get_article_categories()
|
||||
{
|
||||
$sql = 'SELECT * FROM article_categories';
|
||||
|
|
@ -150,12 +137,4 @@ class Dao
|
|||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function update_article_stock($articleid, $diff)
|
||||
{
|
||||
$sql = 'UPDATE articles SET quantity=quantity+? WHERE id=?';
|
||||
$cursor = $this->conn->prepare($sql);
|
||||
$data = [$diff, $articleid];
|
||||
return $cursor->execute($data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ require_once 'dao.php';
|
|||
|
||||
class PostHandler
|
||||
{
|
||||
private $valid_types = ["article", "category", "article_categories", "image", "stock"];
|
||||
private $valid_actions = ["create", "update", "remove", "get", "buy", "sell"];
|
||||
private $valid_types = ["article", "category", "article_categories", 'image'];
|
||||
private $valid_actions = ["create", "update", "remove", "get"];
|
||||
|
||||
private $action;
|
||||
private $type;
|
||||
|
|
@ -13,8 +13,6 @@ class PostHandler
|
|||
private $data;
|
||||
private $dao;
|
||||
private $uploadBaseDir = '../uploaded_images/';
|
||||
private $stockFile = "../data/stock-v2.json";
|
||||
private $imageBaseUrl = "https://etud.insa-toulouse.fr/~proximo/uploaded_images/";
|
||||
|
||||
private $responseArray = array(
|
||||
"status" => 0,
|
||||
|
|
@ -37,8 +35,6 @@ class PostHandler
|
|||
$result = -1;
|
||||
if ($this->type == "image") {
|
||||
$result = $this->save_image();
|
||||
} else if ($this->type == "stock") {
|
||||
$result = $this->updateStock();
|
||||
} else if (count($this->data) > 0) {
|
||||
if ($this->action == "create")
|
||||
$result = $this->create();
|
||||
|
|
@ -61,44 +57,16 @@ class PostHandler
|
|||
return $this->responseArray;
|
||||
}
|
||||
|
||||
public function write_json()
|
||||
{
|
||||
$result = 0;
|
||||
$fp = fopen($this->stockFile, "w");
|
||||
$array = array(
|
||||
"types" => $this->dao->get_categories(),
|
||||
"articles" => $this->get_articles_json_list(),
|
||||
);
|
||||
fwrite($fp, json_encode($array));
|
||||
fclose($fp);
|
||||
|
||||
$this->responseArray["data"] = $result;
|
||||
return $this->responseArray;
|
||||
}
|
||||
|
||||
public function get_articles_json_list()
|
||||
{
|
||||
$articles = $this->dao->get_articles();
|
||||
$formatted_articles = [];
|
||||
foreach ($articles as $article) {
|
||||
$article["type"] = $this->dao->get_categories_of_article($article["id"]);
|
||||
$article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
|
||||
array_push($formatted_articles, $article);
|
||||
}
|
||||
|
||||
return $formatted_articles;
|
||||
}
|
||||
|
||||
private function save_image()
|
||||
{
|
||||
$success = true;
|
||||
if ($this->filesData["image"]["size"] > 0 && $this->data != null) {
|
||||
$uploadPath = $this->uploadBaseDir . $this->data . ".jpg";
|
||||
$uploadPath = $this->uploadBaseDir.$this->data.".jpg";
|
||||
|
||||
if (move_uploaded_file($this->filesData["image"]["tmp_name"], $uploadPath)) {
|
||||
$this->responseArray["message"] = "Image upload success";
|
||||
} else {
|
||||
$this->responseArray["message"] = "Image upload failure: " . $uploadPath;
|
||||
$this->responseArray["message"] = "Image upload failure: ". $uploadPath;
|
||||
$this->responseArray["status"] = 1;
|
||||
$success = false;
|
||||
}
|
||||
|
|
@ -110,12 +78,11 @@ class PostHandler
|
|||
if ($success)
|
||||
return 0;
|
||||
else
|
||||
return json_encode($this->filesData) . "id: " . $this->data;
|
||||
return json_encode($this->filesData)."id: ".$this->data;
|
||||
}
|
||||
|
||||
private function remove_image()
|
||||
{
|
||||
$uploadPath = $this->uploadBaseDir . $this->data["id"] . ".jpg";
|
||||
private function remove_image() {
|
||||
$uploadPath = $this->uploadBaseDir.$this->data["id"].".jpg";
|
||||
if (file_exists($uploadPath) && unlink($uploadPath)) {
|
||||
$this->responseArray["message"] = "Success: Deleted image";
|
||||
} else if (!file_exists($uploadPath)) {
|
||||
|
|
@ -184,20 +151,6 @@ class PostHandler
|
|||
return $result;
|
||||
}
|
||||
|
||||
function updateStock()
|
||||
{
|
||||
$result = 0;
|
||||
foreach ($this->data as $row) {
|
||||
$value = $row["value"];
|
||||
if ($this->action == "sell")
|
||||
$value = -$value;
|
||||
$result = $this->dao->update_article_stock($row["id"], $value);
|
||||
if (!$result)
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function setUnknownTypeResponse()
|
||||
{
|
||||
$this->responseArray["status"] = 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue