finish product discount price impact into the backend , WIP create group - attach group to client - create discount on frontend part
This commit is contained in:
parent
cd94ada9bd
commit
af1033ad0e
@ -549,8 +549,25 @@ class Bdd {
|
||||
}
|
||||
|
||||
public function getListProduit($numdevis, $idNextcloud){
|
||||
$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 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 = ?";
|
||||
return $this->execSQL($sql, array($numdevis));
|
||||
$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
|
||||
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,[$numdevis]);
|
||||
|
||||
if(!empty($produits)){
|
||||
$clientId = $produits[0]["id_client"];
|
||||
$client = $this->getClientById($clientId);
|
||||
foreach($produits as &$produit){
|
||||
$productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['pid']);
|
||||
$produit['prix_unitaire'] = $productPrice ?? $produit['prix_unitaire'];
|
||||
}
|
||||
}
|
||||
return json_encode($produits);
|
||||
}
|
||||
|
||||
public function getListArticle($numdevis, $idNextcloud) {
|
||||
@ -2136,18 +2153,53 @@ class Bdd {
|
||||
produit.prix_unitaire as produit_price,
|
||||
produit.reference as produit_reference,
|
||||
produit.description as produit_description,
|
||||
produit.vat as produit_vat
|
||||
produit.vat as produit_vat,
|
||||
devis.id_client as devis_client_id
|
||||
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
|
||||
WHERE produit_devis.devis_id = ?;";
|
||||
|
||||
$produitList = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
[$devisId]);
|
||||
|
||||
if(!empty($produitList)){
|
||||
$clientId = $produitList[0]["devis_client_id"];
|
||||
$client = $this->getClientById($clientId);
|
||||
foreach($produitList as &$produit){
|
||||
$productPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$produit['produit_id']);
|
||||
$produit['produit_price'] = $productPrice ?? $produit['produit_price'];
|
||||
}
|
||||
}
|
||||
|
||||
return $produitList;
|
||||
}
|
||||
|
||||
private function getProductPriceByClientGroupId($clientGroupId,$productId){
|
||||
$sql = "SELECT *
|
||||
FROM ".$this->tableprefix ."client_group_discount as client_group_discount
|
||||
WHERE client_group_discount.fk_client_group_id = ? AND
|
||||
client_group_discount.fk_produit_id = ?;
|
||||
";
|
||||
$clientGroupDiscount = $this->execSQLNoJsonReturn(
|
||||
$sql,
|
||||
[$clientGroupId,$productId]);
|
||||
if(!empty($clientGroupDiscount)){
|
||||
return $clientGroupDiscount[0]['ht_amount'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getProductPriceByClient($productId,$clientId,$productInitialPrice){
|
||||
$client = $this->getClientById($clientId);
|
||||
if($client != null){
|
||||
$productDiscountPrice = $this->getProductPriceByClientGroupId($client['fk_client_group_id'],$productId);
|
||||
$productInitialPrice = $productDiscountPrice ?? $productInitialPrice;
|
||||
}
|
||||
return $productInitialPrice;
|
||||
}
|
||||
|
||||
private function getDevisProductsQuantityByDevisListAndProductId($devisList,$productId){
|
||||
if(empty($devisList)){
|
||||
return 0;
|
||||
@ -2245,7 +2297,8 @@ class Bdd {
|
||||
client.id,
|
||||
client.nom as client_nom,
|
||||
client.prenom as client_prenom,
|
||||
client.entreprise as client_entreprise
|
||||
client.entreprise as client_entreprise,
|
||||
client.fk_client_group_id as fk_client_group_id
|
||||
FROM ".$this->tableprefix."client as client
|
||||
WHERE client.id = ?;";
|
||||
$clientList = $this->execSQLNoJsonReturn(
|
||||
@ -2256,7 +2309,7 @@ class Bdd {
|
||||
return $clientList[0];
|
||||
}
|
||||
|
||||
return $clientList;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getClientsByClientsID(array $clientIds){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user