import { showError } from "@nextcloud/dialogs"; import { generateUrl } from "@nextcloud/router"; import { baseUrl, LoadDT, showDone } from "../modules/mainFunction.mjs"; import { Devis } from "./devis.mjs"; import { FactureTypeSingle } from "../constants/invoiceConstant.js"; export class Facture { /** * Facture object * @param myresp instantiate Facture object */ constructor(myresp) { this.id = myresp.id; this.user_id = myresp.user_id; this.date = ((myresp.date == null || myresp.date.length === 0) ? '-' : myresp.date); this.num = ((myresp.num == null || myresp.num.length === 0) ? '-' : myresp.num); this.version = ((myresp.version == null || myresp.version.length === 0) ? '-' : myresp.version); this.date_paiement = ((myresp.date_paiement == null || myresp.date_paiement.length === 0) ? '-' : myresp.date_paiement); this.type_paiement = ((myresp.facture_payment_type_label != null && myresp.facture_payment_type_label.length > 0)) ? myresp.facture_payment_type_label : '-'; this.dnum = ((myresp.dnum == null || myresp.dnum.length === 0) ? '-' : myresp.dnum); this.nom_defunt = ((myresp.nom_defunt == null || myresp.nom_defunt.length == 0) ? '-' : myresp.nom_defunt); this.nom = ((myresp.nom == null || myresp.nom.length === 0) ? '-' : myresp.nom); this.lieu = ((myresp.lieu == null || myresp.lieu.length === 0) ? '-' : myresp.lieu); this.prenom = ((myresp.prenom == null || myresp.prenom.length === 0) ? '-' : myresp.prenom); this.status_paiement = ((myresp.facture_status_label == null || myresp.facture_status_label.length === 0) ? '-' : myresp.facture_status_label); this.id_devis = ((myresp.id_devis == null || myresp.id_devis.length === 0) ? '-' : myresp.id_devis); this.baseUrl = generateUrl(`/apps/gestion/facture/${this.id}/show`); this.factureProduits = Devis.getDevisProduitsString(myresp); let paymentDate = "-"; if(myresp.payment_date != null && myresp.payment_date.length > 0){ paymentDate = new Date(myresp.payment_date); paymentDate = paymentDate.toLocaleDateString("fr-FR"); } this.payment_date = paymentDate; this.factureType = myresp.facture_type; const isFactureSingle = this.factureType == FactureTypeSingle; if(isFactureSingle){ this.baseUrl = generateUrl(`/apps/gestion/facture/${this.id}/show`); } else{ this.baseUrl = generateUrl(`/apps/gestion/facture/${this.id}/groupDetails`); } this.clientName = this.nom; if(isFactureSingle == false){ const isFactureClientWithoutGroup = myresp.facture_client_id != null && myresp.facture_client_id != 0; if(isFactureClientWithoutGroup){ this.clientName = ((myresp.facture_client_name == null || myresp.facture_client_name.length == 0) ? '-' : myresp.facture_client_name); } else{ this.clientName = ((myresp.facture_group_name == null || myresp.facture_group_name.length == 0) ? '-' : myresp.facture_group_name); } } } /** * Get datatable row for a devis */ getDTRow() { let myrow = [ '', '