WIP export client with articles
This commit is contained in:
parent
97f1d2b244
commit
30e5c7852a
@ -2618,7 +2618,7 @@ class PageController extends Controller {
|
|||||||
catch(\OCP\Files\NotPermittedException $e) {
|
catch(\OCP\Files\NotPermittedException $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader();
|
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader($exportData);
|
||||||
$fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
$fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
||||||
$fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport);
|
$fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport);
|
||||||
$fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv';
|
$fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv';
|
||||||
|
|||||||
@ -1919,7 +1919,8 @@ class Bdd {
|
|||||||
lieu.latitude as lieu_latitude,
|
lieu.latitude as lieu_latitude,
|
||||||
lieu.longitude as lieu_longitude,
|
lieu.longitude as lieu_longitude,
|
||||||
client.nom as nom_client,
|
client.nom as nom_client,
|
||||||
client.entreprise as client_entreprise
|
client.entreprise as client_entreprise,
|
||||||
|
client.adresse as client_adresse
|
||||||
FROM ".$this->tableprefix."devis as devis
|
FROM ".$this->tableprefix."devis as devis
|
||||||
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
|
||||||
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
|
||||||
@ -1980,6 +1981,31 @@ class Bdd {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getDevisProduitByDevisAndProduit($devisId,$produitId){
|
||||||
|
$sql = "SELECT
|
||||||
|
produit_devis.id,
|
||||||
|
produit_devis.produit_id,
|
||||||
|
produit_devis.quantite,
|
||||||
|
produit_devis.discount,
|
||||||
|
produit.prix_unitaire as produit_price,
|
||||||
|
produit.reference as produit_reference,
|
||||||
|
produit.description as produit_description,
|
||||||
|
produit.vat as produit_vat
|
||||||
|
FROM ".$this->tableprefix ."produit_devis as produit_devis
|
||||||
|
LEFT JOIN ".$this->tableprefix."produit as produit on produit_devis.produit_id = produit.id
|
||||||
|
WHERE produit_devis.devis_id = ? AND
|
||||||
|
produit.id = ?;";
|
||||||
|
|
||||||
|
$produitList = $this->execSQLNoJsonReturn(
|
||||||
|
$sql,
|
||||||
|
[$devisId,$produitId]);
|
||||||
|
|
||||||
|
if(!empty($produitList)){
|
||||||
|
return $produitList[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private function getDevisProduits($devisId){
|
private function getDevisProduits($devisId){
|
||||||
$sql = "SELECT
|
$sql = "SELECT
|
||||||
produit_devis.id,
|
produit_devis.id,
|
||||||
@ -2001,22 +2027,16 @@ class Bdd {
|
|||||||
return $produitList;
|
return $produitList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProduitsDevisStatistic($devisId){
|
private function getProduitsDevisStatistic($devisId,$produitId){
|
||||||
$produitList = $this->getDevisProduits($devisId);
|
$produitQuantity = 0;
|
||||||
$productsCount = count($produitList);
|
$devisProduit = $this->getDevisProduitByDevisAndProduit($devisId,$produitId);
|
||||||
$productsPrice = 0;
|
if($devisProduit){
|
||||||
|
$produitQuantity = $devisProduit["quantite"];
|
||||||
foreach($produitList as $produit){
|
|
||||||
$productsPrice += $produit["quantite"] * $produit["produit_price"];
|
|
||||||
}
|
}
|
||||||
|
return $produitQuantity;
|
||||||
return [
|
|
||||||
"count" => $productsCount,
|
|
||||||
"total_price" => $productsPrice
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getClientFactureStatisticPerMonth($clientId){
|
private function getClientFactureStatisticPerMonth($clientId,array $produitList){
|
||||||
$currentYear = date('Y');
|
$currentYear = date('Y');
|
||||||
$monthLists = range(1,12);
|
$monthLists = range(1,12);
|
||||||
$data = [] ;
|
$data = [] ;
|
||||||
@ -2044,8 +2064,15 @@ class Bdd {
|
|||||||
$defuntCount = count($factureList);
|
$defuntCount = count($factureList);
|
||||||
$produitsCount = 0;
|
$produitsCount = 0;
|
||||||
$produitsPrice = 0;
|
$produitsPrice = 0;
|
||||||
|
$statisticForeachProduct = [];
|
||||||
foreach($factureList as $facture){
|
foreach($factureList as $facture){
|
||||||
$devisProduitStat = $this->getProduitsDevisStatistic($facture["devis_id"]);
|
foreach($produitList as $produit){
|
||||||
|
$devisProduitStat = $this->getProduitsDevisStatistic($facture["devis_id"],$produit['id']);
|
||||||
|
if(!isset($statisticForeachProduct[$produit['reference']])){
|
||||||
|
$statisticForeachProduct[$produit['reference']] = [];
|
||||||
|
}
|
||||||
|
$statisticForeachProduct[$produit['reference']]
|
||||||
|
}
|
||||||
$produitsCount+= $devisProduitStat["count"];
|
$produitsCount+= $devisProduitStat["count"];
|
||||||
$produitsPrice+= $devisProduitStat["total_price"];
|
$produitsPrice+= $devisProduitStat["total_price"];
|
||||||
}
|
}
|
||||||
@ -2061,6 +2088,7 @@ class Bdd {
|
|||||||
|
|
||||||
public function getExportClientStatData(array $clientIds){
|
public function getExportClientStatData(array $clientIds){
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$produitList = $this->getProduitsListAsArray();
|
||||||
foreach($clientIds as $clientId){
|
foreach($clientIds as $clientId){
|
||||||
if(!isset($data[$clientId])){
|
if(!isset($data[$clientId])){
|
||||||
$data[$clientId] = [];
|
$data[$clientId] = [];
|
||||||
@ -2072,7 +2100,7 @@ class Bdd {
|
|||||||
$clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']);
|
$clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']);
|
||||||
}
|
}
|
||||||
$data[$clientId]["client_name"] = $clientName;
|
$data[$clientId]["client_name"] = $clientName;
|
||||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId);
|
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId,$produitList);
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@ -2163,4 +2191,14 @@ class Bdd {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getProduitsListAsArray(){
|
||||||
|
$sql = "SELECT * FROM ".$this->tableprefix."produit as produit;";
|
||||||
|
|
||||||
|
$produitList = $this->execSQLNoJsonReturn(
|
||||||
|
$sql,
|
||||||
|
[]);
|
||||||
|
|
||||||
|
return $produitList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -55,15 +55,20 @@ class ExportClientStatisticService {
|
|||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExportClientFileHeader(): string{
|
public function getExportClientFileHeader($exportData): string{
|
||||||
$fileHeader =
|
$fileHeader =
|
||||||
'Client'.';'.
|
'Client'.';'.
|
||||||
'Mois'.';'.
|
'Mois'.';'.
|
||||||
utf8_decode(html_entity_decode('Année')).';'.
|
utf8_decode(html_entity_decode('Année')).';'.
|
||||||
utf8_decode(html_entity_decode('Nb défunts')).';'.
|
utf8_decode(html_entity_decode('Nb défunts')).';'.
|
||||||
'Nb articles'.';'.
|
'Nb articles'.';'.
|
||||||
'Total HT'.';'.
|
'Total HT'.';';
|
||||||
"\n";
|
|
||||||
|
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||||
|
foreach($produitList as $produit){
|
||||||
|
$fileHeader .= $produit['reference'].';';
|
||||||
|
}
|
||||||
|
$fileHeader .= "\n";
|
||||||
return $fileHeader;
|
return $fileHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -128,7 +128,7 @@ class ExportThanatoStatisticService {
|
|||||||
utf8_decode(html_entity_decode($devis["nom_defunt"])).';'.
|
utf8_decode(html_entity_decode($devis["nom_defunt"])).';'.
|
||||||
utf8_decode(html_entity_decode($devis["nom_lieu"] ?? "")).';'.
|
utf8_decode(html_entity_decode($devis["nom_lieu"] ?? "")).';'.
|
||||||
utf8_decode(html_entity_decode($devis["nom_client"] ?? "")).';'.
|
utf8_decode(html_entity_decode($devis["nom_client"] ?? "")).';'.
|
||||||
utf8_decode(html_entity_decode($devis["client_entreprise"] ?? ""))."\n";
|
utf8_decode(html_entity_decode($devis["client_adresse"] ?? ""))."\n";
|
||||||
|
|
||||||
return $fileContent;
|
return $fileContent;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user