Browse Source

Improved stock management

keplyx 1 year ago
parent
commit
b46717d982
2 changed files with 46 additions and 23 deletions
  1. 14
    5
      assets/css/stock.css
  2. 32
    18
      assets/js/stock.js

+ 14
- 5
assets/css/stock.css View File

@@ -1,17 +1,20 @@
1 1
 #dataList {
2
-    display: grid;
2
+    display: flex;
3
+    flex-wrap: wrap;
3 4
     grid-template-columns: auto auto ;
4 5
     width: 100%;
5 6
 }
6 7
 
7 8
 .img-container {
8 9
     display: flex;
9
-    width: 100%;
10
+    width: 100px;
11
+    height: 100px;
12
+    margin-bottom: 5px;
10 13
 }
11 14
 
12 15
 .grid-item {
13 16
     display: flex;
14
-    padding: 5px;
17
+    margin: 10px;
15 18
 }
16 19
 
17 20
 
@@ -25,13 +28,19 @@
25 28
     width: 100px;
26 29
 }
27 30
 
28
-.grid-container p {
31
+.grid-container p, .grid-container h5 {
29 32
     text-align: center;
30 33
 }
31 34
 
35
+.grid-container h5 {
36
+    overflow: hidden;
37
+}
38
+
32 39
 .grid-container img {
33
-    width : 100px;
34 40
     margin: auto;
41
+    height: 100%;
42
+    width: 100%;
43
+    object-fit: contain;
35 44
 }
36 45
 
37 46
 .button-container {

+ 32
- 18
assets/js/stock.js View File

@@ -2,31 +2,31 @@ let listContainer = $("#dataList");
2 2
 let displayedItems = [];
3 3
 let fetchedData = {};
4 4
 
5
-let currentMode = "sell";
5
+let currentMode = "buy";
6 6
 
7
-let sellCLass = 'btn-danger';
7
+let sellClass = 'btn-danger';
8 8
 let buyClass = 'btn-success';
9 9
 
10 10
 $(document).ready(async function () {
11
-    fetchedData = await AjaxManager.getAll();
11
+    await generateList();
12
+
13
+    $('#buyButton').addClass(buyClass);
14
+    $('#saveButton').addClass(buyClass);
12 15
 
13
-    $('#sellButton').addClass(sellCLass);
14
-    $('#saveButton').addClass(sellCLass);
15 16
 
16
-    generateList();
17 17
     $('#buyButton').on('click', function () {
18 18
         if (!$(this).hasClass(buyClass)) {
19 19
             $(this).addClass(buyClass);
20
-            $('#sellButton').removeClass(sellCLass);
21
-            $('#saveButton').removeClass(sellCLass).addClass(buyClass);
20
+            $('#sellButton').removeClass(sellClass);
21
+            $('#saveButton').removeClass(sellClass).addClass(buyClass);
22 22
             currentMode = "buy";
23 23
         }
24 24
     });
25 25
     $('#sellButton').on('click', function () {
26
-        if (!$(this).hasClass(sellCLass)) {
27
-            $(this).addClass(sellCLass);
26
+        if (!$(this).hasClass(sellClass)) {
27
+            $(this).addClass(sellClass);
28 28
             $('#buyButton').removeClass(buyClass);
29
-            $('#saveButton').removeClass(buyClass).addClass(sellCLass);
29
+            $('#saveButton').removeClass(buyClass).addClass(sellClass);
30 30
             currentMode = "sell";
31 31
         }
32 32
     });
@@ -51,8 +51,9 @@ $(document).ready(async function () {
51 51
             buttons: {
52 52
                 formSubmit: {
53 53
                     text: 'Confirmer',
54
-                    action: function () {
55
-                        window.location.reload();
54
+                    action: async function () {
55
+                        await AjaxManager.saveStockChange(getFormattedValues(values), currentMode === "sell");
56
+                        await generateList();
56 57
                     }
57 58
                 },
58 59
                 cancel: {
@@ -60,24 +61,37 @@ $(document).ready(async function () {
60 61
                 }
61 62
             }
62 63
         });
63
-        AjaxManager.saveStockChange(getFormattedValues(values), currentMode === "sell");
64 64
     });
65 65
 });
66 66
 
67 67
 function getListItem(item) {
68
+    const inputId = 'stockDiffInput' + item['id'];
69
+    const labelId = 'stockDiffLabel' + item['id'];
68 70
     return (
69 71
         '<div class="grid-item">' +
70 72
         '<div class="grid-container">' +
73
+        '<div class="img-container">' +
71 74
         '<img class="list-image" src="../uploaded_images/' + item['id'] + '.jpg"/>' +
72
-        '<p>' + item['name'] + '</p>' +
73
-        '<p>Quantité : ' + item['quantity'] + '</p>' +
74
-        '<input placeholder="Nombre" type="number" value="0" class="form-control"/>' +
75
+        '</div>' +
76
+        '<h5>' + item['name'] + '</h5>' +
77
+        '<p>Quantité : <strong>' + item['quantity'] + '</strong></p>' +
78
+        '<label for="' + inputId + '" id="' + labelId + '">À Ajouter :</label>' +
79
+        '<input id="' + inputId + '" placeholder="Nombre" type="number" value="0" class="form-control" onchange="onStockDiffInputChange(this)"/>' +
75 80
         '</div>' +
76 81
         '</div>');
77 82
 }
78 83
 
84
+function onStockDiffInputChange(input) {
85
+    if ($(input).val() < 0 || isNaN(parseInt($(input).val()))) {
86
+        $(input).val(0);
87
+    }
88
+}
89
+
79 90
 
80
-function generateList() {
91
+async function generateList() {
92
+    fetchedData = await AjaxManager.getAll();
93
+    displayedItems = [];
94
+    listContainer.html('');
81 95
     for (let i = 0; i < fetchedData['articles'].length; i++) {
82 96
         let listItem = getListItem(fetchedData['articles'][i]);
83 97
         displayedItems.push($(listItem));

Loading…
Cancel
Save