added stock edition
This commit is contained in:
parent
0b085a4586
commit
d935a40bcb
12 changed files with 256 additions and 47 deletions
6
admin/articles.php
Normal file
6
admin/articles.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
$relativePath = "../";
|
||||||
|
|
||||||
|
$pageTitle = "Gestion des articles";
|
||||||
|
$script = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/articles.js\"></script>";
|
||||||
|
include("template.php");
|
|
@ -2,13 +2,23 @@
|
||||||
$relativePath = "../";
|
$relativePath = "../";
|
||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<div class="admin-container">
|
<div class="admin-container" style="display: flex">
|
||||||
<a href="stock.php">
|
<div style="margin: auto">
|
||||||
<button class="btn btn-primary btn-large">Gestion des stocks</button>
|
<div style="display: flex" class="my-5">
|
||||||
|
<a href="stock.php" style="margin: auto">
|
||||||
|
<button class="btn btn-primary btn-lg">Gestion du stocks</button>
|
||||||
</a>
|
</a>
|
||||||
<a href="categories.php">
|
</div>
|
||||||
<button class="btn btn-primary btn-large">Gestion des catégories</button>
|
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<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/admin.css" media="screen,projection"/>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
$relativePath = "../";
|
$relativePath = "../";
|
||||||
|
|
||||||
$pageTitle = "Gestion des articles";
|
$isStock = true;
|
||||||
$script = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/articles.js\"></script>";
|
$pageTitle = "Gestion des stocks";
|
||||||
|
$script = "<script type=\"text/javascript\" src=\"" . $relativePath . "assets/js/stock.js\"></script>";
|
||||||
include("template.php");
|
include("template.php");
|
||||||
|
|
|
@ -1,35 +1,61 @@
|
||||||
<?php
|
<?php
|
||||||
$relativePath = "../";
|
$relativePath = "../";
|
||||||
|
|
||||||
|
if (!isset($isStock))
|
||||||
|
$isStock = false;
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<div class="admin-container">
|
<div class="admin-container">
|
||||||
|
|
||||||
<a href="index.php">
|
<a href="index.php">
|
||||||
<button class="btn btn-primary btn-large">Retour</button>
|
<button class="btn btn-primary btn-large">
|
||||||
|
<span class="mdi mdi-chevron-left"></span>
|
||||||
|
Retour
|
||||||
|
</button>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<h1 class="text-center"><?= $pageTitle ?></h1>
|
<h1 class="text-center"><?= $pageTitle ?></h1>
|
||||||
|
|
||||||
|
<?php if (!$isStock): ?>
|
||||||
<div style="display: flex">
|
<div style="display: flex">
|
||||||
<button class="btn btn-success" style="margin: auto" onclick="listManager.showEditPopup(-1)">
|
<button class="btn btn-success" style="margin: auto" onclick="listManager.showEditPopup(-1)">
|
||||||
<i class="mdi mdi-plus"></i>
|
<i class="mdi mdi-plus"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="listContainer">
|
<div id="listContainer">
|
||||||
<ul id="dataList">
|
<ul id="dataList">
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
||||||
|
<div style="display: flex">
|
||||||
|
<button id="saveButton" style="margin: auto" class="btn btn-lg my-2">Sauvegarder</button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
</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/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
|
<?php
|
||||||
$pageContent = ob_get_clean();
|
$pageContent = ob_get_clean();
|
||||||
|
|
|
@ -33,13 +33,13 @@
|
||||||
margin: 20px 0 20px 0;
|
margin: 20px 0 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mdi {
|
#listContainer .mdi {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list-name {
|
.list-name {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
width: 150px;
|
width: 200px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,15 @@
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list-image img {
|
.list-image {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.list-image img {
|
||||||
|
width: 45px;
|
||||||
|
height: 45px;
|
||||||
|
margin: auto;
|
||||||
}
|
}
|
|
@ -1,33 +1,43 @@
|
||||||
|
#dataList {
|
||||||
.name-column {
|
display: grid;
|
||||||
width: 200px;
|
grid-template-columns: auto auto ;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quantity-column, .price-column {
|
.img-container {
|
||||||
width: 150px;
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.code-column {
|
.grid-item {
|
||||||
width: 200px;
|
display: flex;
|
||||||
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.type-column {
|
|
||||||
width: 200px;
|
.grid-container {
|
||||||
overflow-x: auto;
|
width: 100px;
|
||||||
|
margin: auto;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-column {
|
.grid-container input {
|
||||||
width: 150px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions-column {
|
|
||||||
width: 100px;
|
width: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#stockTable tr {
|
.grid-container p {
|
||||||
border-bottom: 1px solid #dedede;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.row-img {
|
.grid-container img {
|
||||||
height: 50px;
|
width : 100px;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-container {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-container button {
|
||||||
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,23 @@ class AjaxManager {
|
||||||
} else
|
} else
|
||||||
return 1;
|
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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
2
assets/js/jquery-confirm-defaults.js
vendored
2
assets/js/jquery-confirm-defaults.js
vendored
|
@ -1,7 +1,7 @@
|
||||||
jconfirm.defaults = {
|
jconfirm.defaults = {
|
||||||
title: 'Title',
|
title: 'Title',
|
||||||
titleClass: '',
|
titleClass: '',
|
||||||
type: 'red',
|
type: 'blue',
|
||||||
typeAnimated: true,
|
typeAnimated: true,
|
||||||
draggable: false,
|
draggable: false,
|
||||||
dragWindowGap: 15,
|
dragWindowGap: 15,
|
||||||
|
|
|
@ -138,7 +138,9 @@ class ListManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
getImagePicker(id, index) {
|
getImagePicker(id, index) {
|
||||||
let imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
|
let imageSrc = undefined;
|
||||||
|
if (index !== -1)
|
||||||
|
imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
|
||||||
return (
|
return (
|
||||||
'<img style="width: 50px; height: 50px" src="' + imageSrc + '" id="image_' + id + '"/>' +
|
'<img style="width: 50px; height: 50px" src="' + imageSrc + '" id="image_' + id + '"/>' +
|
||||||
'<div class="custom-file">\n' +
|
'<div class="custom-file">\n' +
|
||||||
|
|
106
assets/js/stock.js
Normal file
106
assets/js/stock.js
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -137,4 +137,12 @@ class Dao
|
||||||
} else
|
} else
|
||||||
return 0;
|
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
|
class PostHandler
|
||||||
{
|
{
|
||||||
private $valid_types = ["article", "category", "article_categories", 'image'];
|
private $valid_types = ["article", "category", "article_categories", "image", "stock"];
|
||||||
private $valid_actions = ["create", "update", "remove", "get"];
|
private $valid_actions = ["create", "update", "remove", "get", "buy", "sell"];
|
||||||
|
|
||||||
private $action;
|
private $action;
|
||||||
private $type;
|
private $type;
|
||||||
|
@ -35,6 +35,8 @@ class PostHandler
|
||||||
$result = -1;
|
$result = -1;
|
||||||
if ($this->type == "image") {
|
if ($this->type == "image") {
|
||||||
$result = $this->save_image();
|
$result = $this->save_image();
|
||||||
|
} else if ($this->type == "stock") {
|
||||||
|
$result = $this->updateStock();
|
||||||
} else if (count($this->data) > 0) {
|
} else if (count($this->data) > 0) {
|
||||||
if ($this->action == "create")
|
if ($this->action == "create")
|
||||||
$result = $this->create();
|
$result = $this->create();
|
||||||
|
@ -151,6 +153,19 @@ class PostHandler
|
||||||
return $result;
|
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()
|
function setUnknownTypeResponse()
|
||||||
{
|
{
|
||||||
$this->responseArray["status"] = 1;
|
$this->responseArray["status"] = 1;
|
||||||
|
|
Loading…
Reference in a new issue