add move to trash calendar, wip update calendar

This commit is contained in:
Tiavina 2025-02-04 16:25:49 +03:00
parent bfc30fbb35
commit 0d5dba82fb
27 changed files with 190 additions and 24 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,9 @@
namespace OCA\Gestion\AppInfo;
use OCA\DAV\Events\CalendarObjectCreatedEvent;
use OCA\DAV\Events\CalendarObjectMovedToTrashEvent;
use OCA\Gestion\Listener\CalendarObjectCreatedListener;
use OCA\Gestion\Listener\CalendarObjectMovedToTrashListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
@ -21,6 +23,7 @@ class Application extends App implements IBootstrap {
public function register(IRegistrationContext $context): void {
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class);
$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectMovedToTrashListener::class);
}
public function boot(IBootContext $context): void {

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace OCA\Gestion\Constants;
abstract class DevisMentionConstant
{ const FACTURED = "factur&eacute;";
const FACTURED_FORMATTED = "facturé";
const MENTION = "Mention";
const NEW = "Nouveau";
const CANCELED = "CANCELED";
}

View File

@ -2,6 +2,7 @@
namespace OCA\Gestion\Db;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Constants\DevisMentionConstant;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Helpers\VCalendarHelpers;
use OCP\IDBConnection;
@ -2676,4 +2677,36 @@ class Bdd {
return $this->execSQL($sql,[BddConstant::DEFAULT_THANATOS_GROUP_NAME]);
}
public function getDevisByCalendarUuid($calendarUuid){
if($calendarUuid === self::DEFAULT_CALENDAR_UUID_FOR_DEVIS){
return null;
}
$sql = "SELECT
devis.id,
devis.id_thanato,
devis.id_defunt as defunt_id,
devis.num,
devis.comment,
devis.id_lieu as lieu_id,
devis.id_client as client_id,
defunt.nom as defunt_nom
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
WHERE devis.num = ? ;";
$devis = $this->execSQLNoJsonReturn($sql, array($calendarUuid));
if(empty($devis)){
return null;
}
return $devis[0];
}
public function updateDevisMentionToCanceled($devisId){
$sql= "UPDATE ".$this->tableprefix."devis as devis
SET devis.mentions = ?
WHERE devis.id = ?";
$this->execSQLNoData($sql,[DevisMentionConstant::CANCELED,$devisId]);
}
}

View File

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/*
* @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Gestion\Listener;
use OCA\DAV\Events\CalendarObjectMovedToTrashEvent;
use OCA\Gestion\Service\GestionService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;
class CalendarObjectMovedToTrashListener implements IEventListener {
/** @var LoggerInterface */
private $logger;
/** @var GestionService */
private $gestionService;
public function __construct(
LoggerInterface $logger,GestionService $gestionService) {
$this->logger = $logger;
$this->gestionService = $gestionService;
}
public function handle(Event $event): void {
if (!($event instanceof CalendarObjectMovedToTrashEvent)) {
return;
}
$calendarData = $event->getObjectData();
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleCalendarObjectMovedToTrash($vCalendarString);
}
}

View File

@ -246,4 +246,13 @@ class GestionService {
$mapped = array_map('trim', $articles);
return $mapped;
}
public function HandleCalendarObjectMovedToTrash(string $vCalendarString){
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if($devis != null){
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
}
return true;
}
}

View File

@ -0,0 +1,9 @@
export const FacturedDevisMentionConstant = "factur&eacute;";
export const FacturedDevisMentionConstantFormatted = "facturé";
export const DefaultDevisMentionConstant = "Mention";
export const NewDevisMentionConstant = "Nouveau";
export const CanceledDevisMentionConstant = "CANCELED";
export const FactureStatusPaid = "PAID";
export const FactureStatusPending = "PENDING";
export const FactureStatusCanceled = "CANCELED";

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, FacturedDevisMentionConstantFormatted } from "../constants/invoiceConstant.js";
export class Devis {
/**
@ -26,10 +26,50 @@ export class Devis {
this.nomThanato = ((myresp.nom_thanato == null || myresp.prenom_thanato.length === 0) ? '-' : `${myresp.nom_thanato +' '+ myresp.prenom_thanato}`);
this.version = ((myresp.version == null || myresp.version.length === 0) ? '-' : myresp.version);
this.lieu = ((myresp.lieu == null || myresp.lieu.length === 0) ? '-' : myresp.lieu);
this.mentions = ((myresp.mentions == null || myresp.mentions.length === 0) ? '-' : myresp.mentions);
this.mentions = Devis.getDevisMentionFromApiResponse(myresp);
this.baseUrl = generateUrl(`/apps/gestion/devis/${this.id}/show`);
}
static getDevisMentionLabelFromMention(mention){
let labelValue = mention;
switch (mention) {
case FacturedDevisMentionConstant:
labelValue = "Facturé"
break;
case CanceledDevisMentionConstant:
labelValue = "Annulé"
break;
case FacturedDevisMentionConstantFormatted:
labelValue = "Facturé"
break;
default:
labelValue = mention
}
return labelValue;
}
static getDevisMentionFromApiResponse(myresp){
let mention = "-";
if(myresp.mentions != null && myresp.mentions.length > 0){
mention = myresp.mentions;
}
return mention;
}
static getDevisMentionCssStyle(mention){
let style = "display:inline; border-radius: 5px; padding: 8px;";
if(mention === FacturedDevisMentionConstant || mention === FacturedDevisMentionConstantFormatted){
style += " background-color:green !important; color: white";
}
else if(mention === CanceledDevisMentionConstant){
style += " background-color:red !important; color: white";
}
else{
style += " background-color:yellow !important";
}
return style;
}
/**undefined
* Get datatable row for a devis
*/
@ -44,7 +84,7 @@ export class Devis {
'<div class="loadSelect_listclient" data-table="devis" data-column="id_client" data-id="' + this.id + '" data-current="' + this.cid + '">'+ this.cid + ' (' + this.prenom + ' ' + this.nom + ')</div>',
'<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>',
(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;
@ -94,7 +134,11 @@ export class Devis {
oReq.setRequestHeader("Content-Type", "application/json");
oReq.onload = function(e){
if (this.status == 200) {
let devis_temp = (JSON.parse(JSON.parse(this.response))).filter((d)=>(d.mentions != "factur&eacute;"));
let devis_temp = (JSON.parse(JSON.parse(this.response))).filter((d)=>(
d.mentions != FacturedDevisMentionConstant &&
d.mentions != FacturedDevisMentionConstantFormatted &&
d.mentions != CanceledDevisMentionConstant
));
devis_temp = JSON.stringify(JSON.stringify(devis_temp));
callback(JSON.parse(devis_temp));
}else{