Merge branch 'fixes/fix-order-business-logic' into releases/release-h2f
This commit is contained in:
commit
f089adc400
@ -167,6 +167,8 @@ return [
|
||||
['name' => 'order#getOrderTotalAmount', 'url' => '/order/{orderId}/totalAmount', 'verb' => 'PROPFIND'],
|
||||
['name' => 'order#exportOrderToPdf', 'url' => '/order/{orderId}/exportToPdf', '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
|
||||
['name' => 'page#getClientGroupDiscounts', 'url' => '/getClientGroupDiscounts', 'verb' => 'PROPFIND'],
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -292,5 +292,27 @@ class OrderController extends Controller {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2101,7 +2101,13 @@ class Bdd {
|
||||
}
|
||||
|
||||
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;
|
||||
foreach($produitsList as $produit){
|
||||
if (!isset($devis['produits'])) {
|
||||
@ -2366,6 +2372,46 @@ class Bdd {
|
||||
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){
|
||||
$sql = "SELECT
|
||||
produit_devis.id,
|
||||
@ -2391,18 +2437,8 @@ class Bdd {
|
||||
[$devisId]);
|
||||
|
||||
if(!empty($produitList)){
|
||||
$thanatoTypeKey = $produitList[0]["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"];
|
||||
}
|
||||
}
|
||||
else{
|
||||
$clientId = $produitList[0]["devis_client_id"];
|
||||
$clientId = $produitList[0]["devis_client_id"];
|
||||
if($clientId != null && $clientId != 0){
|
||||
$client = $this->getClientById($clientId);
|
||||
foreach($produitList as &$produit){
|
||||
$productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['produit_id']);
|
||||
@ -3064,7 +3100,9 @@ class Bdd {
|
||||
$sql = "SELECT *
|
||||
FROM ".$this->tableprefix ."thanato_product_discount as thanato_product_discount
|
||||
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(
|
||||
$sql,
|
||||
@ -3084,6 +3122,43 @@ class Bdd {
|
||||
return $res[0];
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ class OrderService {
|
||||
}
|
||||
$orderProducts = [];
|
||||
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"]);
|
||||
$orderDetails["client_real_adress"] = $clientAdresses["address"];
|
||||
$orderDetails["client_adress_city"] = $clientAdresses["city"];
|
||||
@ -151,7 +151,7 @@ class OrderService {
|
||||
$orderDetails["devis_date"] = $orderDetails["order_date"];
|
||||
}
|
||||
$orderDetails["products"] = $orderProducts;
|
||||
|
||||
var_dump($orderDetails);
|
||||
return $orderDetails;
|
||||
}
|
||||
|
||||
@ -198,4 +198,12 @@ class OrderService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getOrderDevisProduitsByDevisId($devisId){
|
||||
return $this->gestionBdd->getOrderDevisProduitsByDevisId($devisId);
|
||||
}
|
||||
|
||||
public function getTotalOrderDevisAmount($devisId){
|
||||
return $this->gestionBdd->getTotalOrderDevisAmount($devisId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,9 +148,11 @@ class OrderPdfHandler extends FPDF {
|
||||
$totalTtc+=$valueTtc;
|
||||
$productDescription = $product["produit_reference"];
|
||||
$dateValue = "";
|
||||
if($product === end($products) && $this->orderData["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){
|
||||
$dateValue = $this->orderData["order_date"];
|
||||
$productDescription .= " de " . $this->orderData["defunt_name_with_sexe"];
|
||||
if($product === end($products) ){
|
||||
$dateValue = $this->orderData["devis_date"];
|
||||
if($this->orderData["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){
|
||||
$productDescription .= " de " . $this->orderData["defunt_name_with_sexe"];
|
||||
}
|
||||
}
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
$this->SetXY( 10,$yValue );
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { showMessage, showSuccess, showError } from "@nextcloud/dialogs";
|
||||
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";
|
||||
|
||||
/**
|
||||
@ -837,34 +837,34 @@ export function exportCareCertificate(defuntIdPayload) {
|
||||
/**
|
||||
* Get a product in database using devisId
|
||||
*/
|
||||
export function getProduitsByDevisId(devisId) {
|
||||
var myData = { numdevis: devisId };
|
||||
export function getProduitsByOrderDevisId(devisId) {
|
||||
var payload = { devisId: devisId };
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/getProduitsById',
|
||||
url: baseUrl + '/order/getOrderDevisProduitsByDevisId',
|
||||
type: 'POST',
|
||||
async: false,
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(myData)
|
||||
data: JSON.stringify(payload)
|
||||
}).done(function (response, code) {
|
||||
$('#produits tbody').empty();
|
||||
$('#orderDevisProducts tbody').empty();
|
||||
var total = 0;
|
||||
var deleteDisable = "";
|
||||
if ($('#produits').data("type") === "facture") {
|
||||
if ($('#orderDevisProducts').data("type") === "facture") {
|
||||
deleteDisable = "d-none";
|
||||
}
|
||||
|
||||
$.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><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.quantite * myresp.prix_unitaire)) + '</td></tr>');
|
||||
total += (myresp.quantite * myresp.prix_unitaire);
|
||||
});
|
||||
|
||||
$("#totaldevis tbody").empty();
|
||||
getGlobal(devisId);
|
||||
$("#totalOrderDevis tbody").empty();
|
||||
getTotalOrderDevisAmount(devisId);
|
||||
}).fail(function (response, code) {
|
||||
showError(response);
|
||||
});
|
||||
|
||||
@ -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() {
|
||||
return $.ajax({
|
||||
url: baseUrl + '/getConfiguration',
|
||||
|
||||
@ -4,7 +4,7 @@ import "../css/mycss.css";
|
||||
import { globalConfiguration } from "./modules/mainFunction.mjs";
|
||||
import "./listener/main_listener";
|
||||
import "./listener/orderListener";
|
||||
import { getProduitsByDevisId } from "./modules/ajaxRequest.mjs";
|
||||
import { getProduitsByOrderDevisId } from "./modules/ajaxRequest.mjs";
|
||||
import { getOrderItemsByOrderId } from "./modules/order/orderAjaxRequest.mjs";
|
||||
|
||||
window.addEventListener("DOMContentLoaded", function () {
|
||||
@ -16,7 +16,7 @@ window.addEventListener("DOMContentLoaded", function () {
|
||||
const isOrderDevis = devisId != null;
|
||||
|
||||
if(isOrderDevis){
|
||||
getProduitsByDevisId(devisId);
|
||||
getProduitsByOrderDevisId(devisId);
|
||||
}
|
||||
else{
|
||||
getOrderItemsByOrderId(orderId);
|
||||
|
||||
@ -112,7 +112,7 @@ use OCA\Gestion\Constants\OrderTypeConstant;
|
||||
<div class="table-responsive">
|
||||
<?php
|
||||
$tableProductId = $isOrderDevis ?
|
||||
"produits" :
|
||||
"orderDevisProducts" :
|
||||
"orderItems";
|
||||
?>
|
||||
<table id="<?php echo $tableProductId ?>" class="table table-striped">
|
||||
@ -136,7 +136,7 @@ use OCA\Gestion\Constants\OrderTypeConstant;
|
||||
<div class="mt-0 table-responsive">
|
||||
<?php
|
||||
$tableTotalProductAmountId = $isOrderDevis?
|
||||
"totaldevis" :
|
||||
"totalOrderDevis" :
|
||||
"totalOrderItems";
|
||||
?>
|
||||
<table id="<?php echo $tableTotalProductAmountId ?>" class="table table-striped table-xl">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user