diff --git a/gestion/lib/Constants/DevisMentionConstant.php b/gestion/lib/Constants/DevisMentionConstant.php index 6c0166a..96151cd 100644 --- a/gestion/lib/Constants/DevisMentionConstant.php +++ b/gestion/lib/Constants/DevisMentionConstant.php @@ -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"; } \ No newline at end of file diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 502428f..4fc2c4b 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -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); } /** diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 3784a63..ebc77f8 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -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); diff --git a/gestion/src/js/constants/invoiceConstant.js b/gestion/src/js/constants/invoiceConstant.js new file mode 100644 index 0000000..c387857 --- /dev/null +++ b/gestion/src/js/constants/invoiceConstant.js @@ -0,0 +1,4 @@ +export const FacturedDevisMentionConstant = "facturé"; +export const DefaultDevisMentionConstant = "Mention"; +export const NewDevisMentionConstant = "Nouveau"; +export const CanceledDevisMentionConstant = "CANCELED"; \ No newline at end of file diff --git a/gestion/src/js/listener/main_listener.js b/gestion/src/js/listener/main_listener.js index 955ea04..b95d6b7 100644 --- a/gestion/src/js/listener/main_listener.js +++ b/gestion/src/js/listener/main_listener.js @@ -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); diff --git a/gestion/src/js/objects/devis.mjs b/gestion/src/js/objects/devis.mjs index 91d7ba9..5766fb6 100644 --- a/gestion/src/js/objects/devis.mjs +++ b/gestion/src/js/objects/devis.mjs @@ -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 { '