fix client group discount impact
This commit is contained in:
parent
a2f4f5c92e
commit
b6e7b36193
@ -486,7 +486,14 @@ class PageController extends Controller {
|
|||||||
);
|
);
|
||||||
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
||||||
foreach ($produits as $key => $produit) {
|
foreach ($produits as $key => $produit) {
|
||||||
$facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite;
|
$htPrice = $produit->prix_unitaire;
|
||||||
|
if($facture->fk_client_group_id != null){
|
||||||
|
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id,$produit->id);
|
||||||
|
if($price != null){
|
||||||
|
$htPrice = $price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
|
||||||
};
|
};
|
||||||
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
|
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
|
||||||
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
|
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
|
||||||
@ -737,7 +744,14 @@ class PageController extends Controller {
|
|||||||
);
|
);
|
||||||
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
||||||
foreach ($produits as $key => $produit) {
|
foreach ($produits as $key => $produit) {
|
||||||
$facture_temp['montant_htc'] += $produit->prix_unitaire * $produit->quantite;
|
$htPrice = $produit->prix_unitaire;
|
||||||
|
if($facture->fk_client_group_id != null){
|
||||||
|
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id,$produit->id);
|
||||||
|
if($price != null){
|
||||||
|
$htPrice = $price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
|
||||||
};
|
};
|
||||||
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
|
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
|
||||||
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
|
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
|
||||||
|
|||||||
@ -357,7 +357,7 @@ class Bdd {
|
|||||||
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
|
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
|
||||||
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
||||||
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
||||||
.$this->tableprefix."client.mail as mail_client, "
|
.$this->tableprefix."client.mail as mail_client, ".$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
|
||||||
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
||||||
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
||||||
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
||||||
@ -409,6 +409,7 @@ class Bdd {
|
|||||||
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
|
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
|
||||||
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
||||||
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
||||||
|
.$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
|
||||||
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
||||||
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
||||||
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
||||||
@ -567,8 +568,25 @@ class Bdd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getListProduit($numdevis, $idNextcloud){
|
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 = ?";
|
$sql = "SELECT ".
|
||||||
return $this->execSQL($sql, array($numdevis));
|
$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) {
|
public function getListArticle($numdevis, $idNextcloud) {
|
||||||
@ -1486,15 +1504,33 @@ class Bdd {
|
|||||||
* Annual turnover per month without VAT
|
* Annual turnover per month without VAT
|
||||||
*/
|
*/
|
||||||
public function getAnnualTurnoverPerMonthNoVat($idNextcloud){
|
public function getAnnualTurnoverPerMonthNoVat($idNextcloud){
|
||||||
$sql = "SELECT EXTRACT(YEAR FROM ".$this->tableprefix."facture.date_paiement) as y,
|
$sql = "SELECT
|
||||||
EXTRACT(MONTH FROM ".$this->tableprefix."facture.date_paiement) as m,
|
EXTRACT(YEAR FROM facture.date_paiement) AS y,
|
||||||
sum(".$this->tableprefix."produit.prix_unitaire * ".$this->tableprefix."produit_devis.quantite) as total
|
EXTRACT(MONTH FROM facture.date_paiement) AS m,
|
||||||
FROM `".$this->tableprefix."facture`, `".$this->tableprefix."produit_devis`, `".$this->tableprefix."produit`
|
SUM(
|
||||||
WHERE ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."produit_devis.devis_id
|
COALESCE(client_group_discount.ht_amount,produit.prix_unitaire)
|
||||||
AND ".$this->tableprefix."produit_devis.produit_id = ".$this->tableprefix."produit.id
|
* produit_devis.quantite
|
||||||
GROUP BY EXTRACT(YEAR FROM ".$this->tableprefix."facture.date_paiement), EXTRACT(MONTH FROM ".$this->tableprefix."facture.date_paiement)
|
) AS total
|
||||||
ORDER BY EXTRACT(YEAR FROM ".$this->tableprefix."facture.date_paiement) DESC, EXTRACT(MONTH FROM ".$this->tableprefix."facture.date_paiement);";
|
FROM ".$this->tableprefix."facture AS facture
|
||||||
// return $this->execSQL($sql, array($idNextcloud));
|
JOIN ".$this->tableprefix."produit_devis AS produit_devis
|
||||||
|
ON facture.id_devis = produit_devis.devis_id
|
||||||
|
JOIN ".$this->tableprefix."produit AS produit
|
||||||
|
ON produit_devis.produit_id = produit.id
|
||||||
|
JOIN ".$this->tableprefix."devis AS devis
|
||||||
|
ON facture.id_devis = devis.id
|
||||||
|
JOIN ".$this->tableprefix."client AS client
|
||||||
|
ON devis.id_client = client.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."client_group AS client_group
|
||||||
|
ON client.fk_client_group_id = client_group.id
|
||||||
|
LEFT JOIN ".$this->tableprefix."client_group_discount AS client_group_discount
|
||||||
|
ON client_group.id = client_group_discount.fk_client_group_id
|
||||||
|
AND produit.id = client_group_discount.fk_produit_id
|
||||||
|
GROUP BY
|
||||||
|
EXTRACT(YEAR FROM facture.date_paiement),
|
||||||
|
EXTRACT(MONTH FROM facture.date_paiement)
|
||||||
|
ORDER BY
|
||||||
|
EXTRACT(YEAR FROM facture.date_paiement) DESC,
|
||||||
|
EXTRACT(MONTH FROM facture.date_paiement);";
|
||||||
return $this->execSQL($sql, array());
|
return $this->execSQL($sql, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2286,6 +2322,15 @@ class Bdd {
|
|||||||
$sql,
|
$sql,
|
||||||
[$devisId]);
|
[$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;
|
return $produitList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2651,7 +2696,7 @@ class Bdd {
|
|||||||
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
|
.$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
|
||||||
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
.$this->tableprefix."devis.num as dnum,".$this->tableprefix."devis.version as adresse_devis,".$this->tableprefix."devis.comment as numero_commande, "
|
||||||
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
.$this->tableprefix."client.adresse as adresse_client, ".$this->tableprefix."devis.date as date_soin, "
|
||||||
.$this->tableprefix."client.mail as mail_client, "
|
.$this->tableprefix."client.mail as mail_client, ".$this->tableprefix."client.entreprise as client_entreprise, ".$this->tableprefix."client.fk_client_group_id as fk_client_group_id, "
|
||||||
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
.$this->tableprefix."devis.id_client as id_client, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom as nom, prenom, entreprise, "
|
||||||
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,"
|
||||||
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt,"
|
||||||
@ -2878,4 +2923,19 @@ class Bdd {
|
|||||||
return $this->execSQL($sql, array());
|
return $this->execSQL($sql, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user