finished delete calendar object from agenda: create canceled mentions in devis, on facture retrieve only devis who are not factured yet or canceled, assign canceled mention on devis when deleting from agenda

This commit is contained in:
Tiavina 2025-01-15 10:38:28 +03:00
parent d7a8e8167f
commit 3464679fbd
7 changed files with 79 additions and 39 deletions

View File

@ -3,11 +3,8 @@ declare(strict_types=1);
namespace OCA\Gestion\Constants;
abstract class DevisMentionConstant
{
const DEFAULT_CALENDAR_UUID_FOR_DEVIS = "not-related";
const FACTURED = "facturé";
const MENTION = "mention";
{ const FACTURED = "facturé";
const MENTION = "Mention";
const NEW = "Nouveau";
const CANCELED = "CANCELED";
}

View File

@ -1316,8 +1316,8 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getDevis() {
return $this->myDb->getDevis($this->idNextcloud);
public function getDevis($mentionFilters = []) {
return $this->myDb->getDevis($this->idNextcloud,$mentionFilters);
}
/**

View File

@ -226,7 +226,7 @@ class Bdd {
return $this->execSQL($sql, array($id));
}
public function getDevis($idNextcloud){
public function getDevis($idNextcloud,$mentionFilters = []){
$sql = "SELECT ".$this->tableprefix."devis.id, ".$this->tableprefix."devis.id as devisid, ".$this->tableprefix."devis.user_id,".$this->tableprefix."devis.id_nextcloud ,".$this->tableprefix."devis.comment ,"
.$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, ".$this->tableprefix."client.id as cid, ".$this->tableprefix."client.id as id_client, "
.$this->tableprefix."client.adresse as adresse_cli,".$this->tableprefix."client.mail as mail_cli,".$this->tableprefix."client.telephone as telephone_cli,".$this->tableprefix."client.legal_one as legalone_cli,"
@ -235,13 +235,20 @@ class Bdd {
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,".$this->tableprefix."devis.id_lieu, "
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt, "
.$this->tableprefix."devis.devis_full_number as devis_full_number
FROM (".$this->tableprefix."devis
FROM ".$this->tableprefix."devis
LEFT JOIN ".$this->tableprefix."defunt on id_defunt = ".$this->tableprefix."defunt.id
LEFT JOIN ".$this->tableprefix."client on id_client = ".$this->tableprefix."client.id
LEFT JOIN ".$this->tableprefix."thanato on id_thanato = ".$this->tableprefix."thanato.id
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id
) ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
return $this->execSQL($sql, array());
LEFT JOIN ".$this->tableprefix."lieu on id_lieu = ".$this->tableprefix."lieu.id";
$conditions = [];
if(!empty($mentionFilters)){
$mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionFilters), '?'));
$sql .= " WHERE ". $this->tableprefix."devis.mentions IN ($mentionsFilterPlaceholders)";
$conditions = array_merge($conditions, $mentionFilters);
}
$sql .= " ORDER BY ".$this->tableprefix."devis.id DESC, ".$this->tableprefix."devis.date DESC;";
return $this->execSQL($sql, $conditions);
}
public function getDevisWithProduits($idNextcloud){
@ -1125,26 +1132,30 @@ class Bdd {
return $last;
}
private function getDevisIdListFilteredByMentionAndDevisListId($mentionToNotInclude,$devisListId){
private function getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter,$devisListId){
if (empty($devisListId)) {
return [];
}
$placeholders = implode(',', array_fill(0, count($devisListId), '?'));
$mentionsFilterPlaceholders = implode(',', array_fill(0, count($mentionsFilter), '?'));
$this->logger->debug('Placeholders : ' . $placeholders);
$sql = "SELECT devis.id as id,devis.date as devis_date
FROM ".$this->tableprefix."devis as devis
WHERE devis.id IN ($placeholders) AND mentions != ?";
WHERE devis.id IN ($placeholders) AND
mentions IN ($mentionsFilterPlaceholders)";
$this->logger->debug('SQL : ' . $sql);
$result = $this->execSQLNoJsonReturn($sql,array_merge($devisListId, [$mentionToNotInclude]));
$result = $this->execSQLNoJsonReturn($sql,array_merge(
$devisListId,
$mentionsFilter));
return $result;
}
public function insertFactureForeEachDevisId($idNextCloud,$devisIdArray,$paymentDate = null){
$devisIdarrayToString = implode(',', $devisIdArray);
$this->logger->debug($devisIdarrayToString);
$mentionToNotInclude = 'facturé';
$devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionToNotInclude,$devisIdArray);
$mentionsFilter = [
DevisMentionConstant::NEW,
DevisMentionConstant::MENTION
];
$devisIdListFiltered = $this->getDevisIdListFilteredByMentionAndDevisListId($mentionsFilter,$devisIdArray);
$factureIdsGenerated = [];
foreach($devisIdListFiltered as $devis){
$factureId = $this->insertFactureByDevisId($idNextCloud,$devis['id'],$devis['devis_date'],$paymentDate);

View File

@ -0,0 +1,4 @@
export const FacturedDevisMentionConstant = "facturé";
export const DefaultDevisMentionConstant = "Mention";
export const NewDevisMentionConstant = "Nouveau";
export const CanceledDevisMentionConstant = "CANCELED";

View File

@ -16,6 +16,7 @@ import { Defunt } from "../objects/defunt.mjs";
import { Bibliotheque } from "../objects/bibliotheque.mjs";
import { ClientGroup } from '../objects/clientGroup.mjs';
import { ClientGroupDiscount } from "../objects/clientGroupDiscount.mjs";
import { DefaultDevisMentionConstant, FacturedDevisMentionConstant, NewDevisMentionConstant } from "../constants/invoiceConstant";
var choose_folder = t('gestion', 'Choose work folder');
@ -68,7 +69,13 @@ document.body.addEventListener('click', e => {
Devis.loadDevisList_dnum(e);
}else if(e.target.className.includes("loadSelect_listalldevis")){
Devis.loadAllDevisList_dnum(e);
}else if(e.target.className.includes("loadSelect_listDelphineDevis")){
}else if(e.target.className.includes("selectAvailableDevis")){
Devis.loadAllDevisList_dnum(e,[
NewDevisMentionConstant,
DefaultDevisMentionConstant
]);
}
else if(e.target.className.includes("loadSelect_listDelphineDevis")){
Devis.loadDelphineDevisList_dnum(e);
}else if(e.target.className.includes("loadSelect_listdefunt")){
Defunt.loadDefuntList_tid(e);

View File

@ -1,7 +1,7 @@
import { generateUrl } from "@nextcloud/router";
import { updateDB } from "../modules/ajaxRequest.mjs";
import { baseUrl, checkSelectPurJs, LoadDT, showDone } from "../modules/mainFunction.mjs";
import { NewDevisMentionConstant,FacturedDevisMentionConstant,DefaultDevisMentionConstant,CanceledDevisMentionConstant } from "../constants/invoiceConstant.js";
export class Devis {
/**
@ -34,14 +34,27 @@ export class Devis {
this.devisProduits = Devis.getDevisProduitsString(myresp);
}
static getDevisMentionLabelFromMention(mention){
let labelValue = mention;
switch (mention) {
case FacturedDevisMentionConstant:
labelValue = "Facturé"
break;
case CanceledDevisMentionConstant:
labelValue = "Annulé"
break;
default:
labelValue = mention
}
return labelValue;
}
static getDevisMentionFromApiResponse(myresp){
mention = "-";
let mention = "-";
if(myresp.mentions != null && myresp.mentions.length > 0){
mention = myresp.mentions;
if(mention === 'CANCELED'){
mention = 'Annulé';
}
}
return mention;
}
static getDevisThanatoFullname(myresp){
@ -62,14 +75,18 @@ export class Devis {
return (thanatoFullName.length === 0) ? '-' : thanatoFullName;
}
static getDevisMentionColumnColor(mention) {
if(mention === 'facturé'){
return 'green';
static getDevisMentionCssStyle(mention){
let style = "display:inline; border-radius: 5px; padding: 8px;";
if(mention === FacturedDevisMentionConstant){
style += " background-color:green !important; color: white";
}
if(mention === 'CANCELED'){
return 'red';
else if(mention === CanceledDevisMentionConstant){
style += " background-color:red !important; color: white";
}
return 'yellow';
else{
style += " background-color:yellow !important";
}
return style;
}
static getDevisProduitsString(myresp){
@ -104,7 +121,7 @@ export class Devis {
'<div class="loadSelect_listthanato" data-table="devis" data-column="id_thanato" data-id="' + this.id + '" data-current="' + this.tid + '">'+ this.tid + ' (' + this.nomThanato+ ')</div>',
'<div class="loadSelect_listlieu" data-table="devis" data-column="id_lieu" data-id="' + this.id + '" data-current="' + this.lid + '">' + this.lieu + '</div>',
'<div>' + this.devisProduits + '</div>',
(this.mentions == "factur&eacute;")?('<div data-table="devis" data-column="mentions" data-id="' + this.id +'" style="display:inline; border-radius: 5px; padding: 8px;background-color:green !important; color: white">'+ this.mentions + '</div>'):('<div data-table="devis" data-column="mentions" data-id="' + this.id +'" style="display:inline; border-radius: 5px; padding: 8px;background-color:yellow !important">'+ this.mentions + '</div>'),
'<div data-table="devis" data-column="mentions" data-id="' + this.id +'" style="'+ Devis.getDevisMentionCssStyle(this.mentions) +'">' +Devis.getDevisMentionLabelFromMention(this.mentions) + '</div>',
'<div style="display:inline-block;margin-right:0px;width:80%;"><a href="' + this.baseUrl + '"><button>' + t('gestion', 'Open') + '</button></a></div><div data-modifier="devis" data-id=' + this.id + ' data-table="devis" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
];
return myrow;
@ -138,7 +155,6 @@ export class Devis {
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
console.log(this.response);
// let devis_temp = (JSON.parse(JSON.parse(this.response))).filter((d)=>(d.mentions != "factur&eacute;"));
// devis_temp = JSON.stringify(JSON.stringify(devis_temp));
LoadDT(devisDT, JSON.parse(this.response), Devis);
@ -165,9 +181,14 @@ export class Devis {
oReq.send();
}
static getAllDevis(callback){
static getAllDevis(callback,mentionFilters = []){
var oReq = new XMLHttpRequest();
oReq.open('PROPFIND', baseUrl + '/getDevis', true);
let url = baseUrl + '/getDevis';
if(mentionFilters.length > 0){
const queryParams = mentionFilters.map(mention => `mentionFilters[]=${encodeURIComponent(mention)}`).join('&');
url = `${url}?${queryParams}`;
}
oReq.open('PROPFIND', url, true);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
@ -246,7 +267,7 @@ export class Devis {
});
}
static loadAllDevisList_dnum(e){
static loadAllDevisList_dnum(e,mentionFilters = []){
Devis.getAllDevis( response => {
var selectElement = document.createElement("select");
selectElement.dataset.current = e.target.dataset.current;
@ -292,7 +313,7 @@ export class Devis {
e.target.innerHTML = ''
e.target.appendChild(selectElement);
});
},mentionFilters);
}
static loadDelphineDevisList_dnum(e){

View File

@ -38,7 +38,7 @@ export class Facture {
'<input style="margin:0;padding:0;" class="inputDate devisOrFactureInputDate" type="date" value=' + this.date + ' data-table="facture" data-column="date" data-id="' + this.id + '"/>',
'<input style="margin:0;padding:0;" class="inputDate devisOrFactureInputDate" type="date" value=' + this.date_paiement + ' data-table="facture" data-column="date_paiement" data-id="' + this.id + '"/>',
'<div class="editable" data-table="facture" data-column="type_paiement" data-id="' + this.id + '">' + this.type_paiement + '</div>',
'<div class="loadSelect_listdevis" data-table="facture" data-column="id_devis" data-id="' + this.id + '" data-current="' + this.id_devis + '">' + this.nom_defunt + ' | <span style="font-size: 0.7rem">' + this.prenom + ' ' + this.nom + '</span></div>',
'<div class="selectAvailableDevis" data-table="facture" data-column="id_devis" data-id="' + this.id + '" data-current="' + this.id_devis + '">' + this.nom_defunt + ' | <span style="font-size: 0.7rem">' + this.prenom + ' ' + this.nom + '</span></div>',
'<div class="" data-table="facture" data-column="" data-id="' + this.id + '" style="display:inline">' + this.lieu + '</div>',
'<div>' + this.factureProduits + '</div>',
'<div class="editable" data-table="facture" data-column="status_paiement" data-id="' + this.id + '" style="display:inline">' + this.status_paiement + '</div>',