stock_saleWithNotSale.js 4.63 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 7 8
 *  Ecran de rechreche d'un article sur le nom et sur le code barre */


// Initialise  le table des articles
$(document).ready(function() {
9 10
    table_article = $('#tableArticle').DataTable({
        "ajax": {
Administrator committed
11 12 13
            "url": "get_saleWitheNotSale",
            "data": ""
        },
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        "columns":[

            {data:"name", "title":"Article", "width": "50%"},


            {data:"qty", "title":"Qt. en vendu", "width":"15%"
            },
            {data:"daySale", "title":"Jours de vente", "width":"15%"
            }

        ],

        "searching": true,
        "order": [
            [
                2,
                "desc"
            ]
        ],
        "iDisplayLength": 50,
        "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
56 57
        }
    });
58
});
Administrator committed
59

60
/* Listener */
Administrator committed
61 62


63 64 65
$(document).on('click', '#dp_Search', function() {
    search_table_article();
});
Administrator committed
66

67
var csrftoken = '';
Administrator committed
68 69

$(document).ready(function() {
70
    csrftoken = getCookie('csrftoken');
Administrator committed
71 72 73 74
});


// Lancement de la rupture sur l'article choisie
75 76 77 78 79 80
function ruptureArticle() {
    var jIdArcticle = { 'idArticle': selArctileData.id, 'uom_id' :  selArctileData.uom_id };

    actionButton("set_rupture", jIdArcticle, "/stock/stockQuantLastSale");
}
function archiveArticle() {
Administrator committed
81
    var jIdArcticle = { 'idArticle': selArctileData.id};
82

Administrator committed
83
    actionButton("set_archive", jIdArcticle, "/stock/stockQuantLastSale");
84
}
Administrator committed
85

86
function dontPurchase() {
Administrator committed
87
    var jIdArcticle = { 'idArticle': selArctileData.id};
88

Administrator committed
89
    actionButton("set_dontPurchase", jIdArcticle, "/stock/stockQuantLastSale");
90 91 92 93
}
function actionButton (vUrl, jIdArcticle, followPage) {

    $.ajaxSetup({ headers: { "X-CSRFToken": csrftoken } });
Administrator committed
94
    $.ajax({
95 96 97 98 99 100
        type: "PUT",
        url: vUrl,
        //dataType: "json",
        traditional: true,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(jIdArcticle),
101
        success: function() {
102 103 104 105 106 107
            document.location.href = followPage;
        },
        error: function(resultat, statut, erreur) {
            alert('Erreur' + erreur);

        }
Administrator committed
108 109 110
    });
}

111
var selArctileData = null;
Administrator committed
112

113
// Fenetre de validation sur l'article
Administrator committed
114 115 116 117

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

Administrator committed
119 120
    html ='<div id="askTitle" >Vous êtes sur que cet article est en rupture de stock ? </div>';
    html += '<div id="showData" ><div id="articleName" >'+data.name+'</div><div id="articleQty" >'+data.stockqt+ ' - '+data.uom_id + '</div></div>';
121
    selArctileData = data;
Administrator committed
122
    openModal(html, ruptureArticle, " - Ok - ");
123 124 125
});

$(document).on('click', 'button#bt_archive', function () {
Administrator committed
126 127
    var row = table_article.row($(this).parents('tr'));
    var data = row.data();
128

Administrator committed
129 130
    html ='<div id="askTitle" >Vous êtes sur que cet article doit être archivée ? </div>';
    html += '<div id="showData" ><div id="articleName" >'+data.name+'</div><div id="articleQty" >'+data.stockqt+ ' - '+data.uom_id + '</div></div>';
131
    selArctileData = data;
Administrator committed
132
    openModal(html, archiveArticle, " - Ok - ");
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

});
$(document).on('click', '#bt_dontPurchase', function () {

    if (!this.checked) {
        var row = table_article.row($(this).parents('tr'));
        var data = row.data();

        html ='<div id="askTitle" >Vous êtes sur que cet article ne doit plus être acheter ? </div>';
        html += '<div id="showData" ><div id="articleName" >'+data.name+'</div><div id="articleQty" >'+data.stockqt+ ' - '+data.uom_id + '</div></div>';
        selArctileData = data;
        openModal(html, dontPurchase, " - Ok - ");
        this.checked = true;
    } else {
        this.checked = false;
Administrator committed
148
    }
149 150

});
Administrator committed
151 152 153 154 155