THANASOFT-HFC/gestion/src/js/objects/clientGroupDiscount.mjs

86 lines
3.1 KiB
JavaScript

import { showError } from "@nextcloud/dialogs";
import { baseUrl, cur, LoadDT, showDone } from "../modules/mainFunction.mjs";
export class ClientGroupDiscount {
/**
*
* @param myresp instantiate client group discount object
*/
constructor(myresp) {
this.id = myresp.id;
this.clientGroupName = ClientGroupDiscount.getClientGroupNameFromClientGroupResponse(myresp);
this.productReference = ClientGroupDiscount.getProductReferenceFromClientGroupResponse(myresp);
this.htAmount = myresp.ht_amount;
this.clientGroupId = myresp.fk_client_group_id;
this.productId = myresp.fk_produit_id;
}
static getProductReferenceFromClientGroupResponse(myresp){
let productReference = '-';
if(myresp.produit_reference != null && myresp.produit_reference.length > 0){
productReference = myresp.produit_reference;
}
return productReference;
}
static getClientGroupNameFromClientGroupResponse(myresp){
let clientGroupName = '-';
if(myresp.client_group_name != null && myresp.client_group_name.length > 0){
clientGroupName = myresp.client_group_name;
}
return clientGroupName;
}
/**
* Get datatable row for a client group discount
*/
getDTRow() {
let clientGroupDiscountRow = [
'<div>' + this.id + '</div>',
'<div class="selectClientGroupList" data-table="client_group_discount" data-column="fk_client_group_id" data-id="' + this.id + '" data-current="' + this.clientGroupId + '">' + this.clientGroupName + '</div>',
'<div class="selectProductsList" data-table="client_group_discount" data-column="fk_produit_id" data-id="' + this.id + '" data-current="' + this.productId + '">' + this.productReference + '</div>',
'<div class="editableNumeric" data-table="client_group_discount" data-column="ht_amount" data-id="' + this.id + '">' + cur.format(this.htAmount) + '</div>',
'<div data-modifier="clientGroupDiscount" data-id=' + this.id + ' data-table="client_group_discount" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
];
return clientGroupDiscountRow;
}
/**
*
* @param {*} clientGroupDiscountDatatable
*/
static loadClientGroupDiscountDatatable(clientGroupDiscountDatatable) {
var oReq = new XMLHttpRequest();
oReq.open('PROPFIND', baseUrl + '/getClientGroupDiscounts', true);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
LoadDT(clientGroupDiscountDatatable, JSON.parse(this.response), ClientGroupDiscount);
}else{
showError(this.response);
}
};
oReq.send();
}
/**
*
* @param {*} dt
*/
static createDefaultClientGroupDiscount(dt) {
var oReq = new XMLHttpRequest();
oReq.open('POST', baseUrl + '/clientGroupDiscount/createDefaultClientGroupDiscount', true);
oReq.onload = function(e){
if (this.status == 200) {
showDone()
ClientGroupDiscount.loadClientGroupDiscountDatatable(dt);
}else{
showError(this.response);
}
};
oReq.send();
}
}