diff --git a/gestion/appinfo/routes.php b/gestion/appinfo/routes.php index ff5be3f..3213624 100644 --- a/gestion/appinfo/routes.php +++ b/gestion/appinfo/routes.php @@ -15,6 +15,7 @@ return [ ['name' => 'page#isConfig', 'url' => '/isconfig', 'verb' => 'GET'], ['name' => 'page#statistique', 'url' => '/statistique', 'verb' => 'GET'], ['name' => 'page#legalnotice', 'url' => '/legalnotice', 'verb' => 'GET'], + ['name' => 'page#orders', 'url' => '/orders', 'verb' => 'GET'], ['name' => 'page#france', 'url' => '/legalnotice/france', 'verb' => 'GET'], @@ -149,5 +150,7 @@ return [ //relation of user and thanato ['name' => 'page#getUsersNotLinkedToThanato','url' => '/user/getUsersNotLinkedToThanato', 'verb' => 'PROPFIND'], + //order + ['name' => 'page#getOrders','url' => '/order/list', 'verb' => 'GET'], ] ]; \ No newline at end of file diff --git a/gestion/lib/Constants/OrderStatusConstant.php b/gestion/lib/Constants/OrderStatusConstant.php index d5209a1..b27e926 100644 --- a/gestion/lib/Constants/OrderStatusConstant.php +++ b/gestion/lib/Constants/OrderStatusConstant.php @@ -6,4 +6,6 @@ abstract class OrderStatusConstant { const ORDERED_KEY = "ORDERED"; const CANCELED_KEY = "CANCELED"; + + const NEW_KEY = "NEW"; } \ No newline at end of file diff --git a/gestion/lib/Controller/OrderController.php b/gestion/lib/Controller/OrderController.php new file mode 100644 index 0000000..8f79fd5 --- /dev/null +++ b/gestion/lib/Controller/OrderController.php @@ -0,0 +1,109 @@ +idNextcloud = $UserId; + $this->myDb = $myDb; + $this->urlGenerator = $urlGenerator; + $this->mailer = $mailer; + $this->config = $config; + $this->orderService = $orderService; + $this->navigationService = $navigationService; + //$this->fpdf = $fpdf; + + if ($userSession->isLoggedIn()) { + $this->user = $userSession->getUser(); + } + + if ($this->user != null) { + $groups = $groupManager->getUserGroups($this->user); + $this->groups = []; + foreach ($groups as $group) { + $this->groups[] = $group->getGID(); + } + } + + try{ + $this->storage = $rootFolder->getUserFolder($this->idNextcloud); + }catch(\OC\User\NoUserException $e){ + + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function orders() { + return new TemplateResponse('gestion', 'orders', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink())); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getOrders() { + $orders = $this->orderService->getOrdersWithDetailsAsArray(); + return json_encode($orders); + } +} diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 14a87aa..1379389 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -2803,4 +2803,20 @@ class PageController extends Controller { return json_encode([]); } } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function orders() { + return new TemplateResponse('gestion', 'orders', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->getNavigationLink())); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getOrders() { + return $this->myDb->getOrdersWithDetails(); + } } diff --git a/gestion/lib/Db/OrderBdd.php b/gestion/lib/Db/OrderBdd.php index c7bff6a..04cba47 100644 --- a/gestion/lib/Db/OrderBdd.php +++ b/gestion/lib/Db/OrderBdd.php @@ -127,4 +127,63 @@ class OrderBdd { $this->execSQLNoData($sql,[$statusKey,$orderId]); } + public function getOrderProductsByOrderId($orderId){ + $sql = "SELECT + order_product.id as order_product_id, + produit.id as produit_id, + produit.reference as produit_reference, + produit.description as produit_description + FROM ".$this->orderTablePrefix."order_product as order_product + LEFT JOIN ".$this->orderTablePrefix."produit as produit on order_product.fk_product_id = produit.id + WHERE order_product.fk_order_id = ?;"; + $produitsList = $this->execSQLNoJsonReturn( + $sql, + [$orderId]); + + $finalProduitList = []; + foreach($produitsList as $produit){ + if($produit['produit_id'] != null){ + $finalProduitList[] = $produit; + } + } + return $finalProduitList; + } + + public function getOrdersWithDetails(){ + $sql = "SELECT + orders.id, + orders.order_date, + orders.order_number, + orders.order_full_number, + orders.order_comment, + orders.fk_defunt_id, + orders.fk_lieu_id, + orders.fk_client_id, + orders.fk_thanato_id, + orders.fk_orders_status_key, + thanto.id as thanato_id, + thanato.nom as thanato_nom, + thanato.prenom as thanato_prenom, + client.id as client_id, + client.nom as client_nom, + client.prenom as client_prenom, + client.entreprise as client_entreprise, + defunt.id as defunt_id, + defunt.nom as defunt_nom, + lieu.id as lieu_id, + lieu.adresse as lieu_adresse, + lieu.nom as lieu_nom, + order_status.status_label as order_status_label + FROM " + .$this->orderTablePrefix."orders as orders + LEFT JOIN ".$this->orderTablePrefix."thanato as thanato on orders.fk_thanato_id = thanato.id + LEFT JOIN ".$this->orderTablePrefix."client as client on orders.fk_client_id = client.id + LEFT JOIN ".$this->orderTablePrefix."defunt as defunt on orders.fk_defunt_id = defunt.id + LEFT JOIN ".$this->orderTablePrefix."lieu as lieu on orders.fk_lieu_id = lieu.id + LEFT JOIN ".$this->orderTablePrefix."order_status as order_status on orders.fk_order_status_key = order_status.status_key + " + ; + + return $this->execSQLNoJsonReturn($sql,[]); + } } \ No newline at end of file diff --git a/gestion/lib/Service/NavigationService.php b/gestion/lib/Service/NavigationService.php new file mode 100644 index 0000000..8988a4d --- /dev/null +++ b/gestion/lib/Service/NavigationService.php @@ -0,0 +1,59 @@ + + * + * @author Anna Larch + * @author Richard Steinmetz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 library. If not, see . + * + */ + +namespace OCA\Gestion\Service; + +use OCP\IURLGenerator; +use Psr\Log\LoggerInterface; + +class NavigationService { + private $urlGenerator; + + public function __construct(IURLGenerator $urlGenerator) { + $this->urlGenerator = $urlGenerator; + } + + public function getNavigationLink(){ + return array( + "index" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.index"), + "defunt" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.defunt"), + "devis" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.devis"), + "thanatopracteur" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.thanatopracteur"), + "trajet" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.trajet"), + "lieu" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.lieu"), + "facture" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.facture"), + "produit" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.produit"), + "article" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.article"), + "bibliotheque" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.bibliotheque"), + "config" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.config"), + "isConfig" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.isConfig"), + "statistique" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.statistique"), + "legalnotice" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.legalnotice"), + "france" => $this->urlGenerator->linkToRouteAbsolute("gestion.page.france"), + ); + } + +} diff --git a/gestion/lib/Service/Order/OrderService.php b/gestion/lib/Service/Order/OrderService.php new file mode 100644 index 0000000..3c3ad7c --- /dev/null +++ b/gestion/lib/Service/Order/OrderService.php @@ -0,0 +1,62 @@ + + * + * @author Anna Larch + * @author Richard Steinmetz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 library. If not, see . + * + */ + +namespace OCA\Gestion\Service; + +use OCA\Gestion\Db\OrderBdd; +use Psr\Log\LoggerInterface; + +class OrderService { + /** @var \OCA\Gestion\Db\OrderBdd */ + private $orderBdd; + + /** @var LoggerInterface */ + private $logger; + + public function __construct( + OrderBdd $orderBdd, + LoggerInterface $logger) { + $this->logger = $logger; + $this->orderBdd = $orderBdd; + } + + public function getOrdersWithDetailsAsArray(){ + $orders = $this->orderBdd->getOrdersWithDetails(); + foreach($orders as &$order){ + $currentOrderProductsReferenceAsString = ""; + $currentOrderProductsReferences = []; + $currentOrderProducts = $this->orderBdd->getOrderProductsByOrderId($order['id']); + foreach($currentOrderProducts as $currentProduct){ + $currentOrderProductsReferences[] = $currentProduct["produit_reference"]; + } + if(!empty($currentOrderProductsReferences)){ + $currentOrderProductsReferenceAsString = implode('-',$currentOrderProductsReferences); + } + $order["product_references"] = $currentOrderProductsReferenceAsString; + } + return $orders; + } +} diff --git a/gestion/src/js/objects/order.mjs b/gestion/src/js/objects/order.mjs new file mode 100644 index 0000000..2004246 --- /dev/null +++ b/gestion/src/js/objects/order.mjs @@ -0,0 +1,148 @@ +import { showError } from "@nextcloud/dialogs"; +import { baseUrl, checkSelectPurJs, LoadDT, showDone } from "../modules/mainFunction.mjs"; +import { updateDB } from "../modules/ajaxRequest.mjs"; + +export class Order { + + /** + * + * @param myresp instantiate client group object + */ + constructor(myresp) { + this.id = myresp.id; + this.clientGroupName = ((myresp.client_group_name.length === 0) ? '-' : myresp.client_group_name); + } + + /** + * Get datatable row for a client group + */ + getDTRow() { + let clientGroupRow = [ + '
' + this.id + '
', + '
' + this.clientGroupName + '
', + '
' + ]; + + return clientGroupRow; + } + + /** + * + * @param {*} orderDatatable + */ + static loadOrderDatatable(orderDatatable) { + var oReq = new XMLHttpRequest(); + oReq.open('PROPFIND', baseUrl + '/getClientGroups', true); + oReq.setRequestHeader("Content-Type", "application/json"); + oReq.onload = function(e){ + if (this.status == 200) { + LoadDT(orderDatatable, JSON.parse(this.response), ClientGroup); + }else{ + showError(this.response); + } + }; + oReq.send(); + } + + /** + * + * @param {*} dt + */ + static newProduct(dt) { + var oReq = new XMLHttpRequest(); + oReq.open('POST', baseUrl + '/produit/insert', true); + oReq.onload = function(e){ + if (this.status == 200) { + showDone() + Produit.loadProduitDT(dt); + }else{ + showError(this.response); + } + }; + oReq.send(); + } + + static getClientGroups(callback){ + var oReq = new XMLHttpRequest(); + oReq.open('PROPFIND', baseUrl + '/getClientGroups', true); + oReq.setRequestHeader("Content-Type", "application/json"); + oReq.onload = function(e){ + if (this.status == 200) { + callback(JSON.parse(this.response)); + }else{ + showError(this.response); + } + }; + oReq.send(); + } + + /** + * + * @param {*} lid + */ + static loadClientGroupListToSelect(e){ + ClientGroup.getClientGroups(response => { + + var selectElement = document.createElement("select"); + selectElement.dataset.current = e.target.dataset.current; + selectElement.dataset.id = e.target.dataset.id; + selectElement.dataset.old = e.target.innerHTML; + + selectElement.addEventListener("change", el=>{ + if(el.target.value != 0){ + updateDB(el.target.parentElement.dataset.table, + el.target.parentElement.dataset.column, + el.target.value, + el.target.parentElement.dataset.id + ); + + // location.reload(); + + var parentElement = el.target.parentElement + parentElement.innerHTML = el.target.options[el.target.selectedIndex].text; + parentElement.dataset.current = el.target.value; + }else{ + var parentElement = el.target.parentElement + parentElement.innerHTML = el.target.dataset.old + } + }); + + var option = document.createElement("option"); + option.value = 0; + option.text = t('gestion', 'Cancel'); + selectElement.appendChild(option); + + JSON.parse(response).forEach(myresp => { + var txt = document.createElement("textarea"); + txt.innerHTML = myresp.client_group_name; + var option = document.createElement("option"); + option.value = myresp.id; + option.text = txt.value; + selectElement.appendChild(option); + }); + + checkSelectPurJs(selectElement); + + e.target.innerHTML = '' + e.target.appendChild(selectElement); + }); + } + + /** + * + * @param {*} dt + */ + static createDefaultClientGroup(dt) { + var oReq = new XMLHttpRequest(); + oReq.open('POST', baseUrl + '/clientGroup/createDefaultClientGroup', true); + oReq.onload = function(e){ + if (this.status == 200) { + showDone() + ClientGroup.loadClientGroupDatatable(dt); + }else{ + showError(this.response); + } + }; + oReq.send(); + } +} diff --git a/gestion/templates/content/orders.php b/gestion/templates/content/orders.php new file mode 100644 index 0000000..3e7cf62 --- /dev/null +++ b/gestion/templates/content/orders.php @@ -0,0 +1,32 @@ +
+ + + + + + + + + + + + + + + + + + +
t('ID'));?>t('Date de commande'));?>t('Numéro de commande'));?>t('Défunt'));?>t('Client'));?>t('Type de soins'));?>t('Lieu'));?>t('Etat'));?>t('Actions'));?>
+
\ No newline at end of file diff --git a/gestion/templates/orders.php b/gestion/templates/orders.php new file mode 100644 index 0000000..6ef7861 --- /dev/null +++ b/gestion/templates/orders.php @@ -0,0 +1,18 @@ + +
+
+ inc('navigation/index')); ?> + inc('settings/index')); ?> +
+ +
+
+ inc('content/changelog')); ?> + inc('content/orders')); ?> +
+
+
+