Merge branch 'fixes/fix-order-business-logic' into releases/release-h2f

This commit is contained in:
Tiavina 2025-02-21 16:29:25 +03:00
commit f089adc400
10 changed files with 173 additions and 35 deletions

View File

@ -167,6 +167,8 @@ return [
['name' => 'order#getOrderTotalAmount', 'url' => '/order/{orderId}/totalAmount', 'verb' => 'PROPFIND'], ['name' => 'order#getOrderTotalAmount', 'url' => '/order/{orderId}/totalAmount', 'verb' => 'PROPFIND'],
['name' => 'order#exportOrderToPdf', 'url' => '/order/{orderId}/exportToPdf', 'verb' => 'POST'], ['name' => 'order#exportOrderToPdf', 'url' => '/order/{orderId}/exportToPdf', 'verb' => 'POST'],
['name' => 'order#addOrderItems', 'url' => '/order/{orderId}/addItems', 'verb' => 'POST'], ['name' => 'order#addOrderItems', 'url' => '/order/{orderId}/addItems', 'verb' => 'POST'],
['name' => 'order#getOrderDevisProduitsByDevisId', 'url' => '/order/getOrderDevisProduitsByDevisId', 'verb' => 'POST'],
['name' => 'order#getTotalOrderDevisAmount', 'url' => '/order/getTotalOrderDevisAmount', 'verb' => 'POST'],
//clients discount //clients discount
['name' => 'page#getClientGroupDiscounts', 'url' => '/getClientGroupDiscounts', 'verb' => 'PROPFIND'], ['name' => 'page#getClientGroupDiscounts', 'url' => '/getClientGroupDiscounts', 'verb' => 'PROPFIND'],

File diff suppressed because one or more lines are too long

View File

@ -292,5 +292,27 @@ class OrderController extends Controller {
return $orderProducts; return $orderProducts;
} }
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $devisId
*/
public function getOrderDevisProduitsByDevisId($devisId) {
return $this->orderService->getOrderDevisProduitsByDevisId($devisId);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $devisId
*/
public function getTotalOrderDevisAmount($devisId) {
$total = $this->orderService->getTotalOrderDevisAmount($devisId);
$res = array();
$res['total'] = $total;
return json_encode($res);
}
} }

View File

@ -2101,7 +2101,13 @@ class Bdd {
} }
private function setDevisProduitsList($devis){ private function setDevisProduitsList($devis){
$produitsList = $this->getDevisProduits($devis['id']); $devisIsForSubContractor = $devis["fk_thanato_type_key"] == ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
if($devisIsForSubContractor){
$produitsList = $this->getOrderDevisProduits($devis['id']);
}
else{
$produitsList = $this->getDevisProduits($devis['id']);
}
$totalPrice = 0; $totalPrice = 0;
foreach($produitsList as $produit){ foreach($produitsList as $produit){
if (!isset($devis['produits'])) { if (!isset($devis['produits'])) {
@ -2366,6 +2372,46 @@ class Bdd {
return $produitReferences; return $produitReferences;
} }
public function getOrderDevisProduits($devisId){
$sql = "SELECT
produit_devis.id,
produit_devis.produit_id,
produit_devis.quantite,
produit_devis.discount,
produit_devis.devis_id,
produit.prix_unitaire as produit_price,
produit.reference as produit_reference,
produit.description as produit_description,
produit.vat as produit_vat,
devis.id_client as devis_client_id,
thanato.id as fk_thanato_id,
thanato.fk_thanato_type_key as fk_thanato_type_key
FROM ".$this->tableprefix ."produit_devis as produit_devis
LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id
LEFT JOIN ".$this->tableprefix."devis as devis on produit_devis.devis_id = devis.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
WHERE produit_devis.devis_id = ?;";
$produitList = $this->execSQLNoJsonReturn(
$sql,
[$devisId]);
if(!empty($produitList)){
$thanatoTypeKey = $produitList[0]["fk_thanato_type_key"];
$thanatoId = $produitList[0]["fk_thanato_id"];
$needToApplyThanatoFee = $thanatoTypeKey == ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
if($needToApplyThanatoFee && $thanatoId != null){
foreach($produitList as &$produit){
$productPrice = $this->getProductPriceByThanatoId($thanatoId,$produit['id']);
$productPrice = $productPrice ?? $produit['produit_price'];
$produit['produit_price'] = $productPrice * $produit["quantite"];
}
}
}
return $produitList;
}
public function getDevisProduits($devisId){ public function getDevisProduits($devisId){
$sql = "SELECT $sql = "SELECT
produit_devis.id, produit_devis.id,
@ -2391,18 +2437,8 @@ class Bdd {
[$devisId]); [$devisId]);
if(!empty($produitList)){ if(!empty($produitList)){
$thanatoTypeKey = $produitList[0]["thanato_type_key"]; $clientId = $produitList[0]["devis_client_id"];
$thanatoId = $produitList[0]["fk_thanato_id"]; if($clientId != null && $clientId != 0){
$needToApplyThanatoFee = $thanatoTypeKey == ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
if($needToApplyThanatoFee && $thanatoId != null){
foreach($produitList as &$produit){
$productPrice = $this->getProductPriceByThanatoId($thanatoId,$produit['id']);
$productPrice = $productPrice ?? $produit['produit_price'];
$produit['produit_price'] = $productPrice * $produit["quantite"];
}
}
else{
$clientId = $produitList[0]["devis_client_id"];
$client = $this->getClientById($clientId); $client = $this->getClientById($clientId);
foreach($produitList as &$produit){ foreach($produitList as &$produit){
$productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['produit_id']); $productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['produit_id']);
@ -3064,7 +3100,9 @@ class Bdd {
$sql = "SELECT * $sql = "SELECT *
FROM ".$this->tableprefix ."thanato_product_discount as thanato_product_discount FROM ".$this->tableprefix ."thanato_product_discount as thanato_product_discount
WHERE thanato_product_discount.fk_thanato_id = ? AND WHERE thanato_product_discount.fk_thanato_id = ? AND
thanato_product_discount.fk_product_id = ?; thanato_product_discount.fk_product_id = ?
ORDER BY thanato_product_discount.id DESC
LIMIT 1;
"; ";
$thanatoProductDiscount = $this->execSQLNoJsonReturn( $thanatoProductDiscount = $this->execSQLNoJsonReturn(
$sql, $sql,
@ -3084,6 +3122,43 @@ class Bdd {
return $res[0]; return $res[0];
} }
return null; return null;
}
public function getOrderDevisProduitsByDevisId($devisId){
$sql = "SELECT ".
$this->tableprefix."produit.id as pid,"
.$this->tableprefix."produit_devis.id as pdid, reference, description,"
.$this->tableprefix."produit_devis.comment, quantite, prix_unitaire, "
.$this->tableprefix."devis.id_client,id_thanato
FROM ".$this->tableprefix."produit, ".$this->tableprefix."devis, ".$this->tableprefix."produit_devis
WHERE ".$this->tableprefix."produit.id = produit_id AND ".$this->tableprefix."devis.id = devis_id AND ".$this->tableprefix."devis.id = ?";
$produits = $this->execSQLNoJsonReturn($sql,[$devisId]);
if(!empty($produits)){
$thanatoId = $produits[0]["id_thanato"];
if($thanatoId != null && $thanatoId != 0){
$thanato = $this->getThanatoByThanatoId($thanatoId);
if($thanato != null){
foreach($produits as &$produit){
$productPrice = $this->getProductPriceByThanatoId($thanatoId,$produit['pid']);
$productPrice = ($productPrice ?? $produit['prix_unitaire']) * $produit["quantite"];
$produit['prix_unitaire'] = $productPrice;
}
}
}
}
return json_encode($produits);
}
public function getTotalOrderDevisAmount($devisId){
$produits = $this->getOrderDevisProduits($devisId);
$total=0;
foreach($produits as $produit) {
$total += $produit["produit_price"] * $produit["quantite"];
}
return $total;
} }
} }

View File

@ -125,7 +125,7 @@ class OrderService {
} }
$orderProducts = []; $orderProducts = [];
if($orderDetails["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){ if($orderDetails["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){
$orderProducts = $this->gestionBdd->getDevisProduits($orderDetails["fk_devis_id"]); $orderProducts = $this->gestionBdd->getOrderDevisProduits($orderDetails["fk_devis_id"]);
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($orderDetails["client_adresse"]); $clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($orderDetails["client_adresse"]);
$orderDetails["client_real_adress"] = $clientAdresses["address"]; $orderDetails["client_real_adress"] = $clientAdresses["address"];
$orderDetails["client_adress_city"] = $clientAdresses["city"]; $orderDetails["client_adress_city"] = $clientAdresses["city"];
@ -151,7 +151,7 @@ class OrderService {
$orderDetails["devis_date"] = $orderDetails["order_date"]; $orderDetails["devis_date"] = $orderDetails["order_date"];
} }
$orderDetails["products"] = $orderProducts; $orderDetails["products"] = $orderProducts;
var_dump($orderDetails);
return $orderDetails; return $orderDetails;
} }
@ -198,4 +198,12 @@ class OrderService {
} }
return true; return true;
} }
public function getOrderDevisProduitsByDevisId($devisId){
return $this->gestionBdd->getOrderDevisProduitsByDevisId($devisId);
}
public function getTotalOrderDevisAmount($devisId){
return $this->gestionBdd->getTotalOrderDevisAmount($devisId);
}
} }

View File

@ -148,9 +148,11 @@ class OrderPdfHandler extends FPDF {
$totalTtc+=$valueTtc; $totalTtc+=$valueTtc;
$productDescription = $product["produit_reference"]; $productDescription = $product["produit_reference"];
$dateValue = ""; $dateValue = "";
if($product === end($products) && $this->orderData["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){ if($product === end($products) ){
$dateValue = $this->orderData["order_date"]; $dateValue = $this->orderData["devis_date"];
$productDescription .= " de " . $this->orderData["defunt_name_with_sexe"]; if($this->orderData["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){
$productDescription .= " de " . $this->orderData["defunt_name_with_sexe"];
}
} }
$tvaAmount = $valueTtc - $valueHt; $tvaAmount = $valueTtc - $valueHt;
$this->SetXY( 10,$yValue ); $this->SetXY( 10,$yValue );

View File

@ -1,6 +1,6 @@
import { showMessage, showSuccess, showError } from "@nextcloud/dialogs"; import { showMessage, showSuccess, showError } from "@nextcloud/dialogs";
import { translate as t, translatePlural as n } from '@nextcloud/l10n' import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import { baseUrl, cur, getGlobal, insertCell, insertRow, insertRowWeekendRow, modifyCell } from "./mainFunction.mjs"; import { baseUrl, cur, getGlobal, getTotalOrderDevisAmount, insertCell, insertRow, insertRowWeekendRow, modifyCell } from "./mainFunction.mjs";
import { getOrderItemsByOrderId } from "./order/orderAjaxRequest.mjs"; import { getOrderItemsByOrderId } from "./order/orderAjaxRequest.mjs";
/** /**
@ -837,34 +837,34 @@ export function exportCareCertificate(defuntIdPayload) {
/** /**
* Get a product in database using devisId * Get a product in database using devisId
*/ */
export function getProduitsByDevisId(devisId) { export function getProduitsByOrderDevisId(devisId) {
var myData = { numdevis: devisId }; var payload = { devisId: devisId };
$.ajax({ $.ajax({
url: baseUrl + '/getProduitsById', url: baseUrl + '/order/getOrderDevisProduitsByDevisId',
type: 'POST', type: 'POST',
async: false, async: false,
contentType: 'application/json', contentType: 'application/json',
data: JSON.stringify(myData) data: JSON.stringify(payload)
}).done(function (response, code) { }).done(function (response, code) {
$('#produits tbody').empty(); $('#orderDevisProducts tbody').empty();
var total = 0; var total = 0;
var deleteDisable = ""; var deleteDisable = "";
if ($('#produits').data("type") === "facture") { if ($('#orderDevisProducts').data("type") === "facture") {
deleteDisable = "d-none"; deleteDisable = "d-none";
} }
$.each(JSON.parse(response), function (arrayID, myresp) { $.each(JSON.parse(response), function (arrayID, myresp) {
$('#produits tbody').append('<tr><td><div data-modifier="getProduitsById" data-id="' + myresp.pdid + '" data-table="produit_devis" class="' + deleteDisable + ' deleteItem icon-delete"></div><div style="display:inline;" data-val="' + myresp.pid + '" data-id="' + myresp.pdid + '" class="selectable">' + myresp.reference + '</div></td>' + $('#orderDevisProducts tbody').append('<tr><td><div data-modifier="orderDevisProducts" data-id="' + myresp.pdid + '" data-table="produit_devis" class="' + deleteDisable + ' deleteItem icon-delete"></div><div style="display:inline;" data-val="' + myresp.pid + '" data-id="' + myresp.pdid + '" class="selectable">' + myresp.reference + '</div></td>' +
'<td>' + myresp.description + '</td>' + '<td>' + myresp.description + '</td>' +
'<td><div class="editableNumber getProduitsById" style="display:inline;" data-modifier="getProduitsById" data-table="produit_devis" data-column="quantite" data-id=' + myresp.pdid + '>' + myresp.quantite + '</div> </td>' + '<td><div class="editableNumber getProduitsById" style="display:inline;" data-modifier="orderDevisProducts" data-table="produit_devis" data-column="quantite" data-id=' + myresp.pdid + '>' + myresp.quantite + '</div> </td>' +
'<td>' + cur.format(myresp.prix_unitaire) + '</td>' + '<td>' + cur.format(myresp.prix_unitaire) + '</td>' +
'<td>' + cur.format((myresp.quantite * myresp.prix_unitaire)) + '</td></tr>'); '<td>' + cur.format((myresp.quantite * myresp.prix_unitaire)) + '</td></tr>');
total += (myresp.quantite * myresp.prix_unitaire); total += (myresp.quantite * myresp.prix_unitaire);
}); });
$("#totaldevis tbody").empty(); $("#totalOrderDevis tbody").empty();
getGlobal(devisId); getTotalOrderDevisAmount(devisId);
}).fail(function (response, code) { }).fail(function (response, code) {
showError(response); showError(response);
}); });

View File

@ -223,6 +223,35 @@ export function getGlobal(id_devis) {
}) })
} }
/**
*
* @param {*} devisId
*/
export function getTotalOrderDevisAmount(devisId) {
$.ajax({
url: baseUrl + '/getConfiguration',
type: 'PROPFIND',
contentType: 'application/json',
}).done(function (response) {
$.ajax({
url: baseUrl + '/order/getTotalOrderDevisAmount',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
devisId: devisId
})
}).done((function (res) {
var myresp = JSON.parse(response)[0];
var total = JSON.parse(res).total;
var tva = parseFloat(myresp.tva_default);
$('#totalOrderDevis tbody').empty();
$('#totalOrderDevis tbody').append(
'<tr><td style="text-align:center;">' + cur.format(total) + '</td><td id="tva" style="text-align:center;">' + tva + ' %</td><td id="totaltva" style="text-align:center;">' + cur.format(Math.round((total * tva)) / 100) + '</td><td style="text-align:center;">' + cur.format(Math.round((total * (tva + 100))) / 100) + '</td></tr>');
$('#mentions_default').html(myresp.mentions_default);
}));
})
}
export function getGlobalPromise() { export function getGlobalPromise() {
return $.ajax({ return $.ajax({
url: baseUrl + '/getConfiguration', url: baseUrl + '/getConfiguration',

View File

@ -4,7 +4,7 @@ import "../css/mycss.css";
import { globalConfiguration } from "./modules/mainFunction.mjs"; import { globalConfiguration } from "./modules/mainFunction.mjs";
import "./listener/main_listener"; import "./listener/main_listener";
import "./listener/orderListener"; import "./listener/orderListener";
import { getProduitsByDevisId } from "./modules/ajaxRequest.mjs"; import { getProduitsByOrderDevisId } from "./modules/ajaxRequest.mjs";
import { getOrderItemsByOrderId } from "./modules/order/orderAjaxRequest.mjs"; import { getOrderItemsByOrderId } from "./modules/order/orderAjaxRequest.mjs";
window.addEventListener("DOMContentLoaded", function () { window.addEventListener("DOMContentLoaded", function () {
@ -16,7 +16,7 @@ window.addEventListener("DOMContentLoaded", function () {
const isOrderDevis = devisId != null; const isOrderDevis = devisId != null;
if(isOrderDevis){ if(isOrderDevis){
getProduitsByDevisId(devisId); getProduitsByOrderDevisId(devisId);
} }
else{ else{
getOrderItemsByOrderId(orderId); getOrderItemsByOrderId(orderId);

View File

@ -112,7 +112,7 @@ use OCA\Gestion\Constants\OrderTypeConstant;
<div class="table-responsive"> <div class="table-responsive">
<?php <?php
$tableProductId = $isOrderDevis ? $tableProductId = $isOrderDevis ?
"produits" : "orderDevisProducts" :
"orderItems"; "orderItems";
?> ?>
<table id="<?php echo $tableProductId ?>" class="table table-striped"> <table id="<?php echo $tableProductId ?>" class="table table-striped">
@ -136,7 +136,7 @@ use OCA\Gestion\Constants\OrderTypeConstant;
<div class="mt-0 table-responsive"> <div class="mt-0 table-responsive">
<?php <?php
$tableTotalProductAmountId = $isOrderDevis? $tableTotalProductAmountId = $isOrderDevis?
"totaldevis" : "totalOrderDevis" :
"totalOrderItems"; "totalOrderItems";
?> ?>
<table id="<?php echo $tableTotalProductAmountId ?>" class="table table-striped table-xl"> <table id="<?php echo $tableTotalProductAmountId ?>" class="table table-striped table-xl">