285 lines
8.8 KiB
JavaScript
285 lines
8.8 KiB
JavaScript
import { showError } from "@nextcloud/dialogs";
|
|
import {
|
|
baseUrl,
|
|
checkSelectPurJs,
|
|
LoadDT,
|
|
showDone,
|
|
} from "../modules/mainFunction.mjs";
|
|
import { updateDB } from "../modules/ajaxRequest.mjs";
|
|
|
|
export class ClientGroupFacturation {
|
|
/**
|
|
*
|
|
* @param myresp instantiate client group facturation object
|
|
*/
|
|
constructor(myresp) {
|
|
this.id = myresp.id;
|
|
this.clientGroupFacturationName =
|
|
myresp.group_facturation_name.length === 0
|
|
? "-"
|
|
: myresp.group_facturation_name;
|
|
this.phoneNumber =
|
|
myresp.phone_number != null && myresp.phone_number.length > 0
|
|
? myresp.phone_number
|
|
: "-";
|
|
this.address =
|
|
myresp.address != null && myresp.address.length > 0
|
|
? myresp.address
|
|
: "-";
|
|
this.postalCode =
|
|
myresp.postal_code != null && myresp.postal_code.length > 0
|
|
? myresp.postal_code
|
|
: "-";
|
|
this.city =
|
|
myresp.city != null && myresp.city.length > 0 ? myresp.city : "-";
|
|
this.email =
|
|
myresp.email != null && myresp.email.length > 0 ? myresp.email : "-";
|
|
this.siretNumber =
|
|
myresp.siret_number != null && myresp.siret_number.length > 0
|
|
? myresp.siret_number
|
|
: "-";
|
|
this.tvaIntraCommu =
|
|
myresp.tva_intracommu != null && myresp.tva_intracommu.length > 0
|
|
? myresp.tva_intracommu
|
|
: "-";
|
|
this.templateTypeKey =
|
|
myresp.fk_template_type_key != null &&
|
|
myresp.fk_template_type_key.length > 0
|
|
? myresp.fk_template_type_key
|
|
: "-";
|
|
}
|
|
|
|
/**
|
|
* Get datatable row for a client group facturation
|
|
*/
|
|
getDTRow() {
|
|
let clientGroupFacturationRow = [
|
|
"<div>" + this.id + "</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="group_facturation_name" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.clientGroupFacturationName +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="address" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.address +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="city" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.city +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="postal_code" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.postalCode +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="email" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.email +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="phone_number" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.phoneNumber +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="siret_number" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.siretNumber +
|
|
"</div>",
|
|
'<div class="editable" data-table="client_group_facturation" data-column="tva_intracommu" data-id="' +
|
|
this.id +
|
|
'">' +
|
|
this.tvaIntraCommu +
|
|
"</div>",
|
|
'<div class="selectClientTemplateTypes" data-table="client_group_facturation" data-column="fk_template_type_key" data-id="' +
|
|
this.id +
|
|
'" data-current="' +
|
|
this.templateTypeKey +
|
|
'">' +
|
|
this.templateTypeKey +
|
|
"</div>",
|
|
'<div data-modifier="clientGroupFacturation" data-id=' +
|
|
this.id +
|
|
' data-table="client_group_facturation" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>',
|
|
];
|
|
|
|
return clientGroupFacturationRow;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} clientGroupFacturationDatatable
|
|
*/
|
|
static loadClientGroupFacturationDatatable(clientGroupFacturationDatatable) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open("PROPFIND", baseUrl + "/client/getClientGroupFacturations", true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function (e) {
|
|
if (this.status == 200) {
|
|
LoadDT(
|
|
clientGroupFacturationDatatable,
|
|
JSON.parse(this.response),
|
|
ClientGroupFacturation
|
|
);
|
|
} else {
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
static getClientGroupFacturations(callback) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open("PROPFIND", baseUrl + "/client/getClientGroupFacturations", true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function (e) {
|
|
if (this.status == 200) {
|
|
callback(JSON.parse(this.response));
|
|
} else {
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} lid
|
|
*/
|
|
static loadClientGroupFacturationListToSelect(e) {
|
|
ClientGroupFacturation.getClientGroupFacturations((response) => {
|
|
var selectElement = document.createElement("select");
|
|
selectElement.dataset.current = e.target.dataset.current;
|
|
selectElement.dataset.id = e.target.dataset.id;
|
|
selectElement.dataset.old = e.target.innerHTML;
|
|
|
|
selectElement.addEventListener("change", (el) => {
|
|
if (el.target.value != 0) {
|
|
updateDB(
|
|
el.target.parentElement.dataset.table,
|
|
el.target.parentElement.dataset.column,
|
|
el.target.value,
|
|
el.target.parentElement.dataset.id
|
|
);
|
|
|
|
// location.reload();
|
|
|
|
var parentElement = el.target.parentElement;
|
|
parentElement.innerHTML =
|
|
el.target.options[el.target.selectedIndex].text;
|
|
parentElement.dataset.current = el.target.value;
|
|
} else {
|
|
var parentElement = el.target.parentElement;
|
|
parentElement.innerHTML = el.target.dataset.old;
|
|
}
|
|
});
|
|
|
|
var option = document.createElement("option");
|
|
option.value = 0;
|
|
option.text = t("gestion", "Cancel");
|
|
selectElement.appendChild(option);
|
|
|
|
JSON.parse(response).forEach((myresp) => {
|
|
var txt = document.createElement("textarea");
|
|
txt.innerHTML = myresp.group_facturation_name;
|
|
var option = document.createElement("option");
|
|
option.value = myresp.id;
|
|
option.text = txt.value;
|
|
selectElement.appendChild(option);
|
|
});
|
|
|
|
checkSelectPurJs(selectElement);
|
|
|
|
e.target.innerHTML = "";
|
|
e.target.appendChild(selectElement);
|
|
});
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} dt
|
|
*/
|
|
static createDefaultClientGroupFacturation(dt) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open(
|
|
"POST",
|
|
baseUrl + "/client/createDefaultClientGroupFacturation",
|
|
true
|
|
);
|
|
oReq.onload = function (e) {
|
|
if (this.status == 200) {
|
|
showDone();
|
|
ClientGroupFacturation.loadClientGroupFacturationDatatable(dt);
|
|
} else {
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
static getClientTemplateTypes(callback) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open("PROPFIND", baseUrl + "/client/getClientTemplateTypes", true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function (e) {
|
|
if (this.status == 200) {
|
|
callback(JSON.parse(this.response));
|
|
} else {
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
static loadClientTemplateTypesIntoSelect(e) {
|
|
ClientGroupFacturation.getClientTemplateTypes((response) => {
|
|
var selectElement = document.createElement("select");
|
|
selectElement.dataset.current = e.target.dataset.current;
|
|
selectElement.dataset.id = e.target.dataset.id;
|
|
selectElement.dataset.old = e.target.innerHTML;
|
|
|
|
selectElement.addEventListener("change", (el) => {
|
|
if (el.target.value != "") {
|
|
updateDB(
|
|
el.target.parentElement.dataset.table,
|
|
el.target.parentElement.dataset.column,
|
|
el.target.value,
|
|
el.target.parentElement.dataset.id
|
|
);
|
|
|
|
var parentElement = el.target.parentElement;
|
|
parentElement.innerHTML =
|
|
el.target.options[el.target.selectedIndex].text;
|
|
parentElement.dataset.current = el.target.value;
|
|
} else {
|
|
var parentElement = el.target.parentElement;
|
|
parentElement.innerHTML = el.target.dataset.old;
|
|
}
|
|
});
|
|
|
|
var option = document.createElement("option");
|
|
option.value = "";
|
|
option.text = t("gestion", "Cancel");
|
|
selectElement.appendChild(option);
|
|
|
|
JSON.parse(response).forEach((myresp) => {
|
|
var txt = document.createElement("textarea");
|
|
txt.innerHTML = myresp.template_type_key;
|
|
var option = document.createElement("option");
|
|
option.value = myresp.template_type_key;
|
|
option.text = txt.value;
|
|
selectElement.appendChild(option);
|
|
});
|
|
|
|
checkSelectPurJs(selectElement);
|
|
|
|
e.target.innerHTML = "";
|
|
e.target.appendChild(selectElement);
|
|
});
|
|
}
|
|
}
|