Merge branch 'fixes/fix-defunt-cover-business-logic' into releases/release-hytha-prod
This commit is contained in:
commit
4b7ef348a5
@ -3321,26 +3321,15 @@ class Bdd {
|
||||
}
|
||||
|
||||
private function getProductAsDefuntCoverProduct($productCoverId){
|
||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count(ProductConstant::PRODUCT_COVER_REFERENCE_LIST), '?'));
|
||||
$sql = "SELECT
|
||||
produit.id,
|
||||
produit.reference
|
||||
FROM ".$this->tableprefix."produit as produit
|
||||
WHERE produit.id = ? AND
|
||||
produit.reference IN ($sqlConditionsPlaceholder)
|
||||
LIMIT 1;";
|
||||
|
||||
$product = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
array_merge(
|
||||
[$productCoverId],
|
||||
ProductConstant::PRODUCT_COVER_REFERENCE_LIST
|
||||
)
|
||||
);
|
||||
if(!empty($product)){
|
||||
return $product[0];
|
||||
$product = $this->getProductByProductId($productCoverId);
|
||||
if($product == null){
|
||||
return null;
|
||||
}
|
||||
return $product;
|
||||
$productCoverType = $this->getProductTypeByKey(ProductConstant::PRODUCT_COVER_TYPE_KEY);
|
||||
if($product["fk_product_type_id"] == $productCoverType["id"]){
|
||||
return $product;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function isProductAlreadyExistInDevis($productId,$devisId){
|
||||
@ -3396,6 +3385,22 @@ class Bdd {
|
||||
$this->insertDevisArticle(devisId: $devisId, articleId: $productId,idNextcloud: $idNextcloud);
|
||||
}
|
||||
}
|
||||
|
||||
private function getProductByProductId($productId){
|
||||
$sql = "SELECT
|
||||
produit.id,
|
||||
produit.reference,
|
||||
produit.fk_product_type_id
|
||||
FROM ".$this->tableprefix."produit as produit
|
||||
WHERE produit.id = ?
|
||||
LIMIT 1;";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$productId]);
|
||||
if(!empty($result)){
|
||||
return $result[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function setDefuntCover($defuntId, $productCoverId){
|
||||
$defunt = $this->getDefuntById($defuntId);
|
||||
if($defunt == null){
|
||||
@ -3409,13 +3414,14 @@ class Bdd {
|
||||
return null;
|
||||
}
|
||||
|
||||
$productCoverReferencesList = ProductConstant::PRODUCT_COVER_REFERENCE_LIST;
|
||||
foreach($productCoverReferencesList as $currentProductCoverReference){
|
||||
if($currentProductCoverReference === $product["reference"]){
|
||||
$coverProductList = $this->getProductsByProductTypeKey(ProductConstant::PRODUCT_COVER_TYPE_KEY);
|
||||
$coverProductList = json_decode($coverProductList);
|
||||
foreach($coverProductList as $currentCoverProduct){
|
||||
if($currentCoverProduct->id == $product["id"]){
|
||||
$this->createProductDevisIfNotExist($product["id"],$defunt["devis_id"]);
|
||||
}
|
||||
else{
|
||||
$this->removeProductFromDevisByProductReference($currentProductCoverReference,$defunt["devis_id"]);
|
||||
$this->removeProductFromDevis($currentCoverProduct->id,$defunt["devis_id"]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user