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) {
|
||||
|
||||
}
|
||||
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader();
|
||||
$fileHeader = $this->exportClientStatisticService->getExportClientFileHeader($exportData);
|
||||
$fileContent = $this->exportClientStatisticService->populateExportDataIntoFileContent($exportData,$fileHeader);
|
||||
$fileName = $this->exportClientStatisticService->getFileName($clientIdsToExport);
|
||||
$fileNamePath = $_clean_folder."STAT-CLIENTS-" . $fileName .'.csv';
|
||||
|
||||
@ -1919,7 +1919,8 @@ class Bdd {
|
||||
lieu.latitude as lieu_latitude,
|
||||
lieu.longitude as lieu_longitude,
|
||||
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
|
||||
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
|
||||
@ -1980,6 +1981,31 @@ class Bdd {
|
||||
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){
|
||||
$sql = "SELECT
|
||||
produit_devis.id,
|
||||
@ -2001,22 +2027,16 @@ class Bdd {
|
||||
return $produitList;
|
||||
}
|
||||
|
||||
private function getProduitsDevisStatistic($devisId){
|
||||
$produitList = $this->getDevisProduits($devisId);
|
||||
$productsCount = count($produitList);
|
||||
$productsPrice = 0;
|
||||
|
||||
foreach($produitList as $produit){
|
||||
$productsPrice += $produit["quantite"] * $produit["produit_price"];
|
||||
private function getProduitsDevisStatistic($devisId,$produitId){
|
||||
$produitQuantity = 0;
|
||||
$devisProduit = $this->getDevisProduitByDevisAndProduit($devisId,$produitId);
|
||||
if($devisProduit){
|
||||
$produitQuantity = $devisProduit["quantite"];
|
||||
}
|
||||
|
||||
return [
|
||||
"count" => $productsCount,
|
||||
"total_price" => $productsPrice
|
||||
];
|
||||
return $produitQuantity;
|
||||
}
|
||||
|
||||
private function getClientFactureStatisticPerMonth($clientId){
|
||||
private function getClientFactureStatisticPerMonth($clientId,array $produitList){
|
||||
$currentYear = date('Y');
|
||||
$monthLists = range(1,12);
|
||||
$data = [] ;
|
||||
@ -2044,8 +2064,15 @@ class Bdd {
|
||||
$defuntCount = count($factureList);
|
||||
$produitsCount = 0;
|
||||
$produitsPrice = 0;
|
||||
$statisticForeachProduct = [];
|
||||
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"];
|
||||
$produitsPrice+= $devisProduitStat["total_price"];
|
||||
}
|
||||
@ -2061,6 +2088,7 @@ class Bdd {
|
||||
|
||||
public function getExportClientStatData(array $clientIds){
|
||||
$data = [];
|
||||
$produitList = $this->getProduitsListAsArray();
|
||||
foreach($clientIds as $clientId){
|
||||
if(!isset($data[$clientId])){
|
||||
$data[$clientId] = [];
|
||||
@ -2072,7 +2100,7 @@ class Bdd {
|
||||
$clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']);
|
||||
}
|
||||
$data[$clientId]["client_name"] = $clientName;
|
||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId);
|
||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId,$produitList);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@ -2163,4 +2191,14 @@ class Bdd {
|
||||
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;
|
||||
}
|
||||
|
||||
public function getExportClientFileHeader(): string{
|
||||
public function getExportClientFileHeader($exportData): string{
|
||||
$fileHeader =
|
||||
'Client'.';'.
|
||||
'Mois'.';'.
|
||||
utf8_decode(html_entity_decode('Année')).';'.
|
||||
utf8_decode(html_entity_decode('Nb défunts')).';'.
|
||||
'Nb articles'.';'.
|
||||
'Total HT'.';'.
|
||||
"\n";
|
||||
'Total HT'.';';
|
||||
|
||||
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||
foreach($produitList as $produit){
|
||||
$fileHeader .= $produit['reference'].';';
|
||||
}
|
||||
$fileHeader .= "\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
|
||||
|
||||
@ -128,7 +128,7 @@ class ExportThanatoStatisticService {
|
||||
utf8_decode(html_entity_decode($devis["nom_defunt"])).';'.
|
||||
utf8_decode(html_entity_decode($devis["nom_lieu"] ?? "")).';'.
|
||||
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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user