wip order frontend and api

This commit is contained in:
Tiavina 2025-02-04 17:56:09 +03:00
parent e4a93b775a
commit 3960e2a642
10 changed files with 508 additions and 0 deletions

View File

@ -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'],
]
];

View File

@ -6,4 +6,6 @@ abstract class OrderStatusConstant
{
const ORDERED_KEY = "ORDERED";
const CANCELED_KEY = "CANCELED";
const NEW_KEY = "NEW";
}

View File

@ -0,0 +1,109 @@
<?php
namespace OCA\Gestion\Controller;
use Exception;
use OCA\Gestion\Service\NavigationService;
use OCA\Gestion\Service\OrderService;
defined("TAB1") or define("TAB1", "\t");
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCA\Gestion\Db\Bdd;
use OCP\IURLGenerator;
use OCP\IConfig;
date_default_timezone_set('Europe/Paris');
class OrderController extends Controller {
private $idNextcloud;
private $myDb;
// private $src_path = "/var/www/html/apps/gestion/img/";
private $src_path = "/var/www/html/custom_apps/gestion/img/";
private const H2F_DEFAULT_ADMIN = "Emmanuelle";
private const DEFAULT_ADMIN = "admin";
private $urlGenerator;
private $mailer;
private $config;
/** @var IRootStorage */
private $storage;
private $user;
private $groups = [];
/** @var \OCA\Gestion\Service\OrderService */
private $orderService;
/** @var \OCA\Gestion\Service\NavigationService */
private $navigationService;
/**
* Constructor
*/
public function __construct($AppName,
IRequest $request,
$UserId,
Bdd $myDb,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IMailer $mailer,
Iconfig $config,
IUserSession $userSession,
IGroupManager $groupManager,
OrderService $orderService,
NavigationService $navigationService
){
parent::__construct($AppName, $request);
$this->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);
}
}

View File

@ -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();
}
}

View File

@ -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,[]);
}
}

View File

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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"),
);
}
}

View File

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -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 = [
'<div>' + this.id + '</div>',
'<div class="editable" data-table="client_group" data-column="client_group_name" data-id="' + this.id + '">' + this.clientGroupName + '</div>',
'<div data-modifier="clientGroup" data-id=' + this.id + ' data-table="client_group" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>'
];
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();
}
}

View File

@ -0,0 +1,32 @@
<div id="contentTable">
<div class="breadcrumb" data-html2canvas-ignore>
<div class="crumb svg crumbhome">
<a href="<?php echo($_['url']['index']); ?>" class="icon-home"></a>
<span style="display: none;"></span>
</div>
<div class="crumb svg crumbhome">
<span>Commandes</span>
</div>
<div class="crumb svg crumbhome">
<button style="margin-left:3px;" type="button" id="newOrder">Ajouter une commande</button>
</div>
</div>
<table id="tableOrderList" class="display tabledt">
<thead>
<tr>
<th></th>
<th><?php p($l->t('ID'));?></th>
<th><?php p($l->t('Date de commande'));?></th>
<th><?php p($l->t('Numéro de commande'));?></th>
<th><?php p($l->t('Défunt'));?></th>
<th><?php p($l->t('Client'));?></th>
<th><?php p($l->t('Type de soins'));?></th>
<th><?php p($l->t('Lieu'));?></th>
<th><?php p($l->t('Etat'));?></th>
<th><?php p($l->t('Actions'));?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>

View File

@ -0,0 +1,18 @@
<?php
style('gestion', array('style'));
// script('gestion', array('clientGroup.app', '814.app', '856.app'));
?>
<div id="app">
<div id="app-navigation">
<?php print_unescaped($this->inc('navigation/index')); ?>
<?php print_unescaped($this->inc('settings/index')); ?>
</div>
<div id="app-content">
<div id="app-content-wrapper">
<?php print_unescaped($this->inc('content/changelog')); ?>
<?php print_unescaped($this->inc('content/orders')); ?>
</div>
</div>
</div>