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 = [ '
'+ this.id + '
', '
' + this.thanatoFullName + '
', '
' + this.productReference + '
', '
' + cur.format(this.htAmount) + '
', '
' ]; 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(); } }