fix defunt cover business logic
This commit is contained in:
parent
9676985c5f
commit
078172f2d5
@ -3321,26 +3321,15 @@ class Bdd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getProductAsDefuntCoverProduct($productCoverId){
|
private function getProductAsDefuntCoverProduct($productCoverId){
|
||||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count(ProductConstant::PRODUCT_COVER_REFERENCE_LIST), '?'));
|
$product = $this->getProductByProductId($productCoverId);
|
||||||
$sql = "SELECT
|
if($product == null){
|
||||||
produit.id,
|
return null;
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
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){
|
private function isProductAlreadyExistInDevis($productId,$devisId){
|
||||||
@ -3396,6 +3385,22 @@ class Bdd {
|
|||||||
$this->insertDevisArticle(devisId: $devisId, articleId: $productId,idNextcloud: $idNextcloud);
|
$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){
|
public function setDefuntCover($defuntId, $productCoverId){
|
||||||
$defunt = $this->getDefuntById($defuntId);
|
$defunt = $this->getDefuntById($defuntId);
|
||||||
if($defunt == null){
|
if($defunt == null){
|
||||||
@ -3409,13 +3414,14 @@ class Bdd {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$productCoverReferencesList = ProductConstant::PRODUCT_COVER_REFERENCE_LIST;
|
$coverProductList = $this->getProductsByProductTypeKey(ProductConstant::PRODUCT_COVER_TYPE_KEY);
|
||||||
foreach($productCoverReferencesList as $currentProductCoverReference){
|
$coverProductList = json_decode($coverProductList);
|
||||||
if($currentProductCoverReference === $product["reference"]){
|
foreach($coverProductList as $currentCoverProduct){
|
||||||
|
if($currentCoverProduct->id == $product["id"]){
|
||||||
$this->createProductDevisIfNotExist($product["id"],$defunt["devis_id"]);
|
$this->createProductDevisIfNotExist($product["id"],$defunt["devis_id"]);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->removeProductFromDevisByProductReference($currentProductCoverReference,$defunt["devis_id"]);
|
$this->removeProductFromDevis($currentCoverProduct->id,$defunt["devis_id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user