Skip to content

Commit

Permalink
CRUD Fournisseur
Browse files Browse the repository at this point in the history
  • Loading branch information
guillainbisimwa committed Jul 8, 2019
1 parent cfc3044 commit e65cfd1
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 18 deletions.
23 changes: 22 additions & 1 deletion assets/DisplayFrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ $("#apropos-titre").text(json.name+" - "+json.section_apropos.name);
$(".nav-link-med").text((json.med.plurial).toUpperCase());
$(".nav-link-forme").text((json.forme.plurial).toUpperCase());
$(".nav-link-cat").text((json.cat.plurial).toUpperCase());
$(".nav-link-frnssr").text((json.fournisseur.plurial).toUpperCase());

//Tab med
//Header of Table
Expand All @@ -55,6 +56,12 @@ $(".tab_forme thead tr .2").text(json.forme.designation);
$(".tab_cat thead tr .1").text(json.nbr);
$(".tab_cat thead tr .2").text(json.cat.designation);

//Tab fournisseur
$(".tab_frnssr thead tr .1").text(json.nbr);
$(".tab_frnssr thead tr .2").text(json.fournisseur.designation);
$(".tab_frnssr thead tr .3").text(json.fournisseur.phone);
$(".tab_frnssr thead tr .4").text(json.fournisseur.adress);

//Modals Med
$(".med-modal-title").text(json.med.add);
$("label.design_med").text(json.med.designation);
Expand All @@ -79,6 +86,12 @@ $("#UploadMedModal").find(".btn-2").text(json.buttons.upload.name);
$("#submit_med span").text(json.buttons.valid.name);
$("#submit_med").find("i").addClass(json.buttons.valid.icon);

//Modals fournisseur
$(".frnssr-modal-title").text(json.fournisseur.add);
$("label.design_frnssr").text(json.fournisseur.designation);
$("#SuppFrnssrModal").find("h3 span").text(json.fournisseur.del_confirm_msg);
$("#SuppFrnssrModal").find("h4").text(json.fournisseur.del);

//Med
$("#save_med span").text(json.buttons.add.name);
$("#save_med").find("i").addClass(json.buttons.add.icon);
Expand All @@ -103,6 +116,14 @@ $("#update_cat").find("i").addClass(json.buttons.edit.icon);
$("#supp_cat span").text(json.buttons.del.name);
$("#supp_cat").find("i").addClass(json.buttons.del.icon);

//FOURNISSEUR
$("#save_frnssr span").text(json.buttons.add.name);
$("#save_frnssr").find("i").addClass(json.buttons.add.icon);
$("#update_frnssr span").text(json.buttons.edit.name);
$("#update_frnssr").find("i").addClass(json.buttons.edit.icon);
$("#supp_frnssr span").text(json.buttons.del.name);
$("#supp_frnssr").find("i").addClass(json.buttons.del.icon);

/**
* ENTREES
*/
Expand Down Expand Up @@ -136,7 +157,7 @@ $(".qt_titre").text(json.entree.quantité);
/**
* SORTIE
*/
//Modals Entree
//Modals sortie
$(".sortie-modal-title").text(json.sortie.add);
$("label.design_sortie").text(json.sortie.quantité);
$("#SuppSortieModal").find("h3 .confirm_msg_sortie").text(json.sortie.del_confirm_msg);
Expand Down
12 changes: 12 additions & 0 deletions assets/values/String.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@
"upload":"Importer un fichier CSV",
"stock_init":"Stock initial"
},
"fournisseur": {
"name": "Fournisseur",
"plurial": "Fournisseurs",
"add": "Ajouter un fournisseur",
"del": "Supprimer un fournisseur",
"edit": "Modifier un fournisseur",
"file_name":"Liste de fournisseurs",
"del_confirm_msg":"Voulez-vous vraiment supprimer le fournisseur : ",
"designation":"Nom du fournisseur",
"adress":"Adresse",
"phone":"Contact"
},
"entree": {
"name": "Entrée",
"plurial": "Entrées",
Expand Down
2 changes: 1 addition & 1 deletion data/.db/entrees.db
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{"id_medicament":"mgBjuURjANvDuVin","qt":670,"date_":{"$$date":1562238848473},"_id":"38Ft9fcIZVtKiNNE"}
{"id_medicament":"tX8hYersEhb8yZjp","qt":240,"date_":{"$$date":1562238846977},"_id":"3BXonMYN68TQf3yE"}
{"id_medicament":"Kye7XeJjR2xYOUa8","qt":460,"date_":{"$$date":1562238847753},"_id":"3V2HkEyHtDSKbV2I"}
{"id_medicament":"IBwJbYlOeQRmJ2OI","qt":23,"date_":{"$$date":1562315374095},"_id":"3YXOvVXzVvgqSdRo"}
{"id_medicament":"JfslvyTEDQfTP6rt","qt":310,"date_":{"$$date":1562238847220},"_id":"3tWcTJpkBdCv4R1x"}
{"id_medicament":"Rjwrxmpy9o6gGBP8","qt":540,"date_":{"$$date":1562238848056},"_id":"41bDq98BApXwSruH"}
{"id_medicament":"zNnFbQF4ugB3gGq5","qt":710,"date_":{"$$date":1562238848640},"_id":"46sTKFu8yeL4LgVu"}
Expand Down Expand Up @@ -86,4 +87,3 @@
{"id_medicament":"DPOXlFEmyXquVJxi","qt":500,"date_":{"$$date":1562238847891},"_id":"vce7ajFASbqvlXPo"}
{"id_medicament":"4SLHy9V77DsKCPaM","qt":650,"date_":{"$$date":1562238848408},"_id":"vwktBHnyNO55lPYe"}
{"id_medicament":"41Ymwlz9wJ1NZObC","qt":700,"date_":{"$$date":1562238848606},"_id":"zPz7HGCtJjJm3fs6"}
{"id_medicament":"IBwJbYlOeQRmJ2OI","qt":23,"date_":{"$$date":1562315374095},"_id":"3YXOvVXzVvgqSdRo"}
2 changes: 2 additions & 0 deletions data/.db/fournisseurs.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"nom_fournisseur":"ULB-COOPERATION","adress":"+24388000023","phone":"Q. les volcans, avenue de l'hopital, Numero 190","_id":"hP2n2JclUL22vKd8"}
{"nom_fournisseur":"ASRAMES","adress":"+24300009880","phone":"Avenue Kalindi, Q. des volcan, Numero 112","_id":"nAM9hWv2zFYdOt7S"}
1 change: 0 additions & 1 deletion data/.db/medicaments.db
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
{"nom_medicament":"Gentamycine 40mg/ml","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"JUHGWq090UcQ3h07","_id":"e1qFw8NPdA0B3Ei1"}
{"nom_medicament":"Norfloxacin 500mg","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"3pwyBUoibEYngM1W","_id":"erHtQXb0tVnw3KiH"}
{"nom_medicament":"Ampicilline 500mg, fl","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"8g5RiLDpodin5p46","_id":"feAJY9ZmVSIJLKXf"}
{"nom_medicament":"Amoxicilline 250mg","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"vySulEcTAXQPnNMH","_id":"fv12oxdvZRTCEjm2"}
{"nom_medicament":"Cefixime 40mg/ml","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"XIUnLMFolZpi3f52","_id":"gI8Bynw3Vt09WXvu"}
{"nom_medicament":"Levofloxacin 500mg/100ml","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"nxrBg4WTwNin4jnM","_id":"hXPlqdmWi8AcevKA"}
{"nom_medicament":"Amoxicilline 500mg + acide clavulanique 50mg, fl","id_categorie":"OMVOYYZxkl1q0dvm","id_forme":"vGeFkTEYbscoGsCE","_id":"i1j9hzKcTYzUK0Hu"}
Expand Down
11 changes: 11 additions & 0 deletions data/Fournisseur.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var Document = require('camo').Document;

class Fournisseur extends Document {
constructor() {
super();
this.nom_fournisseur = String;
this.adress = String;
this.phone = String;
}
}
module.exports = Fournisseur
187 changes: 185 additions & 2 deletions renderer-scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ $(document).ready(function() {
const Medicament = require('../data/Medicament');
const Entree = require('../data/Entree');
const Sortie = require('../data/Sortie');
const Fournisseur = require('../data/Fournisseur');

//Init tables
var _tab_forme = $("#tab_forme").DataTable();
var _tab_cat = $("#tab_cat").DataTable();
var _tab_med = $("#tab_med").DataTable();
var _tab_fournisseur = $("#tab_frnssr").DataTable();

var tab_uploaded_med = $("#tab_uploaded_med").DataTable(
{
Expand Down Expand Up @@ -99,6 +101,11 @@ $(document).ready(function() {
populateTabMed();
});

// Populate tab fournisseur
$(".nav-link-frnssr").click(function(){
populateTabFournisseur();
});

//Save forme
$("#save_forme").click(function(){
var _forme = $("#design_forme").val();
Expand Down Expand Up @@ -159,6 +166,33 @@ $(document).ready(function() {
$("#design_med").val("");
});

//save fournisseur
$("#save_frnssr").click(function(){
var _nom_fnssr = $("#nom_fnssr").val();
var _phone_fnssr = $("#phone_fnssr").val();
var _adress_fnssr = $("#adress_fnssr").val();

var frnssr = Fournisseur.create({
nom_fournisseur: _nom_fnssr,
adress: _phone_fnssr,
phone: _adress_fnssr
});

frnssr.save().then(function(addedfrnssr) {
console.log(addedfrnssr._id);
//Close programmaticaly the modal
$("#AddFrnssrModal .close").click();
$("#nom_fnssr").val("");
$("#phone_fnssr").val("");
$("#adress_fnssr").val("");

populateTabFournisseur();
});
$("#nom_fnssr").val("");
$("#phone_fnssr").val("");
$("#adress_fnssr").val("");
});

//Update forme
/**
* https://github.com/scottwrobinson/camo#creating-and-saving
Expand Down Expand Up @@ -201,6 +235,20 @@ $(document).ready(function() {
});
});

//Update fournisseur
$("#update_frnssr").click(function(){
var _id_frnssr = $("#_id_fnssr").val();
var _nom_fnssr = $("#nom_fnssr").val();
var _phone_fnssr = $("#phone_fnssr").val();
var _adress_fnssr = $("#adress_fnssr").val();

Fournisseur.findOneAndUpdate({_id:_id_frnssr},{nom_fournisseur: _nom_fnssr,adress:_phone_fnssr,phone:_adress_fnssr},{upsert: true}).then(function(updatedFnssr) {
populateTabFournisseur();
console.log("_id = ", updatedFnssr._id)
$("#AddFrnssrModal .close").click();
});
});

//Supprimer une forme
$("#supp_forme").click(function(){
var _id_del_design_forme = $("#_id_del_design_forme").val();
Expand Down Expand Up @@ -235,8 +283,8 @@ $(document).ready(function() {
});
});

//Supprimer un medicament
$("#supp_med").click(function(){
//Supprimer un medicament
$("#supp_med").click(function(){
var _id_del_design_med = $("#_id_del_design_med").val();
var del_design_med = $("#del_design_med").text();
Medicament.deleteOne({_id:_id_del_design_med}).then(function(deletedMed) {
Expand All @@ -245,6 +293,17 @@ $(document).ready(function() {
populateTabMed();
});
});

//Supprimer un fournisseur
$("#supp_frnssr").click(function(){
var _id_del_frnssr = $("#_id_del_frnssr").val();
var del_nom_frnssr = $("#del_nom_frnssr").text();
Fournisseur.deleteOne({_id:_id_del_frnssr}).then(function(deletedFrnssr) {
console.log('Deleted ', deletedFrnssr, ' fournisseur from the database.');
result_del(deletedFrnssr,del_nom_frnssr,"SuppFrnssrModal");
populateTabFournisseur();
});
});

//Function, update values before adding forme
function updateValueModalForme(forme,_id){
Expand Down Expand Up @@ -309,6 +368,34 @@ $(document).ready(function() {
//Find is-filled is-focused
$("#AddMedModal").find(".form-group").addClass("has-danger is-filled is-focused");
}

//Function, update values before adding fournisseur
function updateValueModalFrnssr(frnssr, phone,addres,_id){
$("#update_frnssr").css("display","block");
$("#save_frnssr").css("display","none");
$(".frnssr-modal-title").text(json.fournisseur.edit);
$(".frnssr-modal-title").css("color","#a11");
//$("#design_forme").click();
$("#nom_fnssr").val(frnssr);
$("#phone_fnssr").val(phone);
$("#adress_fnssr").val(addres);
$("#_id_fnssr").val(_id);

//Find is-filled is-focused
$("#AddFrnssrModal").find(".form-group").addClass("has-danger is-filled is-focused");
}
function addValueModalFrnssr(){
$("#update_frnssr").css("display","none");
$("#save_frnssr").css("display","block");
$(".frnssr-modal-title").text(json.fournisseur.add);
$(".frnssr-modal-title").css("color","#000");
$("#AddFrnssrModal").find(".form-group").removeClass("has-danger is-filled is-focused");
$("#nom_fnssr").val("");
$("#_id_fnssr").val("");
$("#phone_fnssr").val("");
$("#adress_fnssr").val("");
}

function addValueModalMed(){
$("#update_med").css("display","none");
$("#save_med").css("display","block");
Expand Down Expand Up @@ -338,6 +425,12 @@ $(document).ready(function() {
$("#_id_del_design_med").val(_id);
}

//Function, update values before adding fournisseur
function delValueModalFrnssr(frnssr,_id){
$("#del_nom_frnssr").text(frnssr);
$("#_id_del_frnssr").val(_id);
}

//Function populate tab Forme
function populateTabForme(){
var tab_forme = [];
Expand Down Expand Up @@ -633,6 +726,96 @@ $(document).ready(function() {
});
}

//Function populate tab fournisseur
function populateTabFournisseur(){
var tab_fournisseur = [];
_tab_fournisseur.destroy();
//$("#tab_fournisseur").empty();
Fournisseur.find({},{sort:'nom_fournisseur'}).then(function(foundFournisseur) {
i = 0;
foundFournisseur.forEach(function(foundSingleFournissr) {
i++;
var localSingleFournissr = [i, foundSingleFournissr.nom_fournisseur, foundSingleFournissr.adress, foundSingleFournissr.phone,foundSingleFournissr._id];
tab_fournisseur.push(Array.from(localSingleFournissr))
});

console.log(Array.from(tab_fournisseur))
//_tab_fournisseur.DataTable({
_tab_fournisseur = $('#tab_frnssr').DataTable({

dom: 'Blfrtip',
select: true,
buttons: [
{
text: '<li class="'+json.buttons.new.icon+'"></li> '+json.buttons.new.name,
action: function ( e, dt, node, config ) {
//console.log("_id = ", foundSingleFournissr._id)
addValueModalFrnssr();
$("#AddFrnssrModal").modal();
}
},
{
text: '<li class="'+json.buttons.edit.icon+'"></li> '+json.buttons.edit.name,
action: function ( e, dt, node, config ) {
console.log(
'Row data: '+
JSON.stringify( dt.row( { selected: true } ).data() )
);
updateValueModalFrnssr(dt.row( { selected: true } ).data()[1], dt.row( { selected: true } ).data()[2], dt.row( { selected: true } ).data()[3], dt.row( { selected: true } ).data()[4]);
$("#AddFrnssrModal").modal();
},
enabled: false
},
{
text: '<li class=" '+json.buttons.del.icon+'"></li> '+json.buttons.del.name,
action: function ( e, dt, node, config ) {
console.log(
'Row data: '+
JSON.stringify( dt.row( { selected: true } ).data() )
);
delValueModalFrnssr(dt.row( { selected: true } ).data()[1], dt.row( { selected: true } ).data()[4]);
$("#SuppFrnssrModal").modal();
},
enabled: false
},
//'copy', 'csv', 'excel', 'pdf', 'print', "colvis"
{
extend: 'csv',
text: '<i class="'+json.buttons.export.icon+'"></i> '+json.buttons.export.name,
titleAttr: 'CSV',
filename: json.fournisseur.file_name,
exportOptions: {
columns: [0, 1]
},
}
],
// ICI on choisi la langue des details du tableau
language:{
url:'./assets/values/French.json'
},
"order": [[ 0, "asc" ]],
// Les donnees sont affichees dans le tableau HTML
data:tab_fournisseur,
// On affiche pas la troisieme colonne, elle reprend les _id
"columnDefs": [
{
"targets": [ 4 ],
"visible": false,
"searchable": false
},
],
destroy:true
});

_tab_fournisseur.on( 'select deselect', function () {
var selectedRows = _tab_fournisseur.rows( { selected: true } ).count();
console.log("ok: "+selectedRows)
_tab_fournisseur.button( 1 ).enable( selectedRows === 1 );
_tab_fournisseur.button( 2 ).enable( selectedRows === 1 );
});
});
}

//Populate forme SELECTPICKERS
function populateSelectForme(){

Expand Down
Loading

0 comments on commit e65cfd1

Please sign in to comment.