stock_rupture.js 5.28 KB
Newer Older
Administrator committed
1 2

/* Module de rupture : Selection un article et le met en rupture à 0 dans les stockes:
3
 *
Administrator committed
4 5 6
 *  Ecran de rechreche d'un article sur le nom et sur le code barre */


7
var table_article = null;
8
var dataSet =[];
9
var csrftoken = '';
Administrator committed
10 11

// lance la recherche sur le nom des l'article
12 13
function search_table_article() {
    table_article.ajax.url('get_list_article?rech='+$("#searchInput").val()).load();
Administrator committed
14 15 16
}

// Lance la recherche sur les codes barres
17
function search_article_byBarcode() {
Administrator committed
18
    table_article.ajax.url('get_article_byBarcode?rech='+$("#searchInput").val()).load();
19
}
Administrator committed
20 21 22 23


// Initialise  le table des articles
$(document).ready(function() {
24 25
    table_article = $('#tableArticle').DataTable({
        "ajax": {
Administrator committed
26 27 28
            "url": "get_list_article?rech=",
            "data": ""
        },
29 30 31 32
        "columns":[
            {
                data:"image_small",
                "title":"Photo",
33
                "render": function (data, type, full) {
34 35 36

                    debut = '<button id="page1" type="button" data-toggle="modal" data-target=".modal" data-remote=' + full.id + ' class="btn btn-primary">';
                    fin = "</button>";
Administrator committed
37

38 39 40 41 42 43
                    return debut + "<img  src='data:image/png;base64," + data + "'>" + fin;
                }
            },
            {data:"name", "title":"Article", "width": "50%"},
            {data:"qty_available", "title":"En Stock", "width": "10%"},
            {data:"uom_id",
44
                "render":function (data) {
45 46

                    return data[1];
Administrator committed
47
                },
48 49 50
                "title":"Unité", "width":"5%"},
            {data:"reception_status",
                "title":"Rupture", "className":"dt-body-center",
51
                "render": function (data, type, full) {
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
                    if (full.qty_available > 0) {
                        return "<div><button id='bt_change' href='#'>Rupture</button></div>";
                    } else {
                        return "<div>--</div>";
                    }
                }
            }
        ],

        "searching": false,
        "order": [
            [
                0,
                "desc"
            ]
        ],
        "iDisplayLength": 25,
        "language": {
            "emptyTable":     "Pas de donnée",
            "info":           "Affiché : lignes _START_ à _END_ sur _TOTAL_",
            "infoEmpty":      "Affiché : 0 ligne",
            "infoFiltered":   "(filtré de _MAX_ lignes au total)",
            "thousands":      ",",
            "lengthMenu":     "Afficher _MENU_ lignes",
            "loadingRecords": "Loading...",
            "processing":     "Processing...",
            //"search":         "Rechercher un article :",
            //"searchPlaceholder": "Référence, nom du fournisseur...",
            "zeroRecords":    "Aucun résultat",
            "paginate": {
                "first":      "Premier",
                "last":       "Dernier",
                "next":       "Suivant",
                "previous":   "Precedant"
            },
            "aria": {
                "sortAscending":  ": activate to sort column ascending",
                "sortDescending": ": activate to sort column descending"
Administrator committed
90 91 92
            }
        }
    });
93
});
Administrator committed
94

95
/* Listener */
Administrator committed
96 97


98 99 100
$(document).on('click', '#dp_Search', function() {
    search_table_article();
});
Administrator committed
101 102 103 104 105

//barcode-reader


$(document).ready(function() {
106 107 108
    var pressed = false;
    var chars = [];

Administrator committed
109 110 111 112
    $(window).keypress(function(e) {
        if (e.which >= 48 && e.which <= 57) {
            chars.push(String.fromCharCode(e.which));
        }
113

Administrator committed
114
        if (pressed == false) {
115
            setTimeout(function() {
Administrator committed
116 117
                if (chars.length >= 13) {
                    var barcode = chars.join("");
118

Administrator committed
119 120 121 122 123
                    if (!isNaN(barcode)) {
                        chars = [];
                        pressed = false;
                        search_article_byBarcode();
                    }
124

Administrator committed
125
                }
126 127

            }, 300);
Administrator committed
128 129 130 131 132 133
        }
        pressed = true;
    });
});

$(document).ready(function() {
134
    csrftoken = getCookie('csrftoken');
Administrator committed
135 136 137
});

// Lancement de la rupture sur l'article choisie
138
function ruptureArticle() {
Administrator committed
139 140 141

    var jIdArcticle = { 'idArticle': selArctileData.id, 'uom_id' :  selArctileData.uom_id[0] };

142
    $.ajaxSetup({ headers: { "X-CSRFToken": csrftoken } });
Administrator committed
143
    $.ajax({
144 145 146 147 148 149 150
        type: "PUT",
        url: "set_rupture",
        //dataType: "json",
        traditional: true,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(jIdArcticle),

151
        success: function() {
152 153 154 155 156 157 158

            document.location.href = "/stock/listArticleBreaking";
        },
        error: function(resultat, statut, erreur) {
            alert('Erreur' + erreur);

        }
Administrator committed
159
    });
160
}
Administrator committed
161

162
var selArctileData = null;
Administrator committed
163

164
// Fenetre de validation sur l'article
Administrator committed
165 166 167 168 169 170 171

$(document).on('click', 'button#bt_change', function () {
    var row = table_article.row($(this).parents('tr'));
    var data = row.data();

    html ='<div id="askTitle" >Vous êtes sur que cet article est en rupture de stock ? </div>';
    html += '<div id="showData" ><img id ="showImg" WIDTH="100" HEIGHT="100" src="data:image/png;base64,'+data.image_small+'"><div id="articleName" >'+data.name+'</div><div id="articleQty" >'+data.qty_available+ ' - '+data.uom_id[1] + '</div></div>';
172
    selArctileData = data;
Administrator committed
173 174

    openModal(html, ruptureArticle, " - Ok - ");
175 176

});
Administrator committed
177 178 179