92 lines
3.3 KiB
JavaScript
92 lines
3.3 KiB
JavaScript
import { showError } from "@nextcloud/dialogs";
|
|
import { baseUrl, cur, LoadDT, showDone } from "../modules/mainFunction.mjs";
|
|
export class ThanatoProductFee {
|
|
|
|
/**
|
|
*
|
|
* @param myresp instantiate thanato product fee object
|
|
*/
|
|
constructor(myresp) {
|
|
this.id = myresp.id;
|
|
this.thanatoFullName = ThanatoProductFee.getThanatoFullname(myresp);
|
|
this.productReference = ((myresp.produit_reference == null || myresp.produit_reference.length === 0) ? '-' : myresp.produit_reference);
|
|
this.htAmount = myresp.produit_ht_price;
|
|
this.thanatoId = myresp.fk_thanato_id;
|
|
this.productId = myresp.fk_product_id;
|
|
}
|
|
|
|
static getThanatoFullname(myresp){
|
|
let thanatoPrenom = '';
|
|
let thanatoNom = '';
|
|
let thanatoFullName = '';
|
|
if(myresp.thanato_nom != null && myresp.thanato_nom.length != 0){
|
|
thanatoNom = myresp.thanato_nom;
|
|
thanatoFullName += thanatoNom;
|
|
}
|
|
if(myresp.thanato_prenom != null && myresp.thanato_prenom.length != 0){
|
|
thanatoPrenom = myresp.thanato_prenom;
|
|
if(thanatoNom.length > 0 && thanatoPrenom.length > 0){
|
|
thanatoFullName += ' '
|
|
}
|
|
thanatoFullName += thanatoPrenom;
|
|
}
|
|
return (thanatoFullName.length === 0) ? '-' : thanatoFullName;
|
|
}
|
|
|
|
/**
|
|
* Get datatable row for a fee per thanato per product
|
|
*/
|
|
getDTRow() {
|
|
let thanatoProductFeeRow = [
|
|
'<div>'+ this.id + '</div>',
|
|
'<div class="getThanatosSubcontractor" data-table="thanato_product_discount" data-column="fk_thanato_id" data-id="' + this.id + '" data-current="' + this.thanatoId + '">' + this.thanatoFullName + '</div>',
|
|
'<div class="selectProductsList" data-table="thanato_product_discount" data-column="fk_product_id" data-id="' + this.id + '" data-current="' + this.productId + '">' + this.productReference + '</div>',
|
|
'<div class="editableNumeric" data-table="thanato_product_discount" data-column="ht_price" data-id="' + this.id + '">' + cur.format(this.htAmount) + '</div>',
|
|
'<div data-modifier="thanatoProductFee" data-id=' + this.id + ' data-table="thanato_product_discount" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
|
|
];
|
|
|
|
return thanatoProductFeeRow;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} ThanatoProductFeeDatatable
|
|
*/
|
|
static loadThanatoProductFeeDatatable(ThanatoProductFeeDatatable) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('PROPFIND', baseUrl + '/thanatoProductFees/list', true);
|
|
oReq.setRequestHeader("Content-Type", "application/json");
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
LoadDT(ThanatoProductFeeDatatable, JSON.parse(this.response), ThanatoProductFee);
|
|
}else{
|
|
showError(this.response);
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {*} dt
|
|
*/
|
|
static createDefaultThanatoProductFee(dt) {
|
|
var oReq = new XMLHttpRequest();
|
|
oReq.open('POST', baseUrl + '/thanatoProductFees/createDefaultThanatoProductFee', true);
|
|
oReq.onload = function(e){
|
|
if (this.status == 200) {
|
|
if(this.response != null){
|
|
showDone()
|
|
ThanatoProductFee.loadThanatoProductFeeDatatable(dt);
|
|
}
|
|
else{
|
|
showError("Erreur dans la création de tarifs par produit par thanato");
|
|
}
|
|
}else{
|
|
showError("Erreur dans la création de tarifs par produit par thanato");
|
|
}
|
|
};
|
|
oReq.send();
|
|
}
|
|
}
|