stock_order.js 4.65 KB
Newer Older
Administrator committed
1

2 3
/* Page de la commande:
 * Creation d'un nouvelle commande d'un fournisseur.
Administrator committed
4 5 6 7
 *  Liste des articles d'un fournisseur (Recherche des fournisseurs avec un prés saisi)
 *  Sur un article on a les stocks, la moyenne des ventes des 4 dernière semaines en incluant les rupture
 *  Visualisation par un graph des vente des 4 dernier semaines
 *  Pré-saisie des qantitee à commander en fonction du stock, des moyennes de vente, d'un coef multi et la date de la prochaine commande
8
 *
Administrator committed
9 10 11 12
 * */


var table_article;
13
var dataSet =[];
Administrator committed
14 15 16 17
var csrftoken;
var four_id=0;

// lance la recherche sur le nom des l'article
18
function search_table_article() {
Administrator committed
19 20

    table_article.ajax.url('get_list_article_fournisseur/'+four_id+"/").load();
21 22


Administrator committed
23 24 25 26
}

// Initialise  le table des articles
$(document).ready(function() {
27 28
    table_article = $('#tableArticle').DataTable({
        "ajax": {
Administrator committed
29
            "url": "get_list_article_fournisseur/1712/",
30 31
            "data": ""

Administrator committed
32
        },
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        "columns":[
            {data:"name_template", "title":"Article", "width": "50%"},
            {data:"stock_qty", "title":"En Stock", "width": "10%"},
            {data:"average", "title":"Moyen de vente", "width": "10%"},
            {data:"average_breaking", "title":"Moyenne vent rupture", "width": "10%"}
        ],

        "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
70 71
        }
    });
72
});
Administrator committed
73

74
/* Listener */
Administrator committed
75 76


77 78 79
$(document).on('click', '#dp_Search', function() {
    search_table_article();
});
Administrator committed
80 81 82 83 84

//barcode-reader


$(document).ready(function() {
85 86 87
    var pressed = false;
    var chars = [];

Administrator committed
88 89 90 91
    $(window).keypress(function(e) {
        if (e.which >= 48 && e.which <= 57) {
            chars.push(String.fromCharCode(e.which));
        }
92

Administrator committed
93
        if (pressed == false) {
94
            setTimeout(function() {
Administrator committed
95 96
                if (chars.length >= 13) {
                    var barcode = chars.join("");
97

Administrator committed
98 99 100 101 102
                    if (!isNaN(barcode)) {
                        chars = [];
                        pressed = false;
                        search_article_byBarcode();
                    }
103

Administrator committed
104
                }
105 106

            }, 300);
Administrator committed
107 108 109 110 111 112
        }
        pressed = true;
    });
});

$(document).ready(function() {
113
    csrftoken = getCookie('csrftoken');
Administrator committed
114 115 116
});

// Lancement de la rupture sur l'article choisie
117
function ruptureArticle(test) {
Administrator committed
118 119

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


    $.ajaxSetup({ headers: { "X-CSRFToken": csrftoken } });
Administrator committed
123
    $.ajax({
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        type: "PUT",
        url: "set_rupture",
        //dataType: "json",
        traditional: true,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(jIdArcticle),

        success: function(data) {

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

        }
Administrator committed
139
    });
140
}
Administrator committed
141 142 143 144 145 146 147 148 149 150

var selArctileData;




$(document).ready(function() {
    var options = {
        url : "get_liste_supplyer",
        list: {
151 152 153 154 155 156 157 158 159
            maxNumberOfElements: 8,
            match: {
                enabled: true
            },
            sort: {
                enabled: true
            },
            onSelectItemEvent: function() {
                four_id = $("#template-custom").getSelectedItemData().id;
Administrator committed
160
            }
161 162 163

        },

Administrator committed
164 165
        getValue: "display_name",
        template: {
166
            type: "display_name"
Administrator committed
167 168 169 170 171 172 173 174 175 176
            //method: function(value, item) {
            //    return "<img src='" + item.icon + "' /> | " + item.type + " | " + value;
            //}
        }
    };

    $("#template-custom").easyAutocomplete(options);
});