fix statistique client calcul total HT
This commit is contained in:
parent
34717b772d
commit
411cc2d5a8
@ -3208,7 +3208,7 @@ class Bdd
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getClientFactureStatisticPerMonth($clientId, array $produitList)
|
||||
private function getClientFactureStatisticPerMonth($clientId, array $produitList, $clientGroupId = null)
|
||||
{
|
||||
$currentYear = date('Y');
|
||||
$monthLists = range(1, 12);
|
||||
@ -3245,7 +3245,8 @@ class Bdd
|
||||
$statisticForeachProductPerMonth[$produit['id']] = 0;
|
||||
}
|
||||
$productTotalCount = $this->getDevisProductsQuantityByDevisListAndProductId($factureDevisIds, $produit['id']);
|
||||
$totalWithoutVat = $productTotalCount * $produit["prix_unitaire"];
|
||||
$prixUnitaire = is_null($clientGroupId) ? $produit["prix_unitaire"] : $this->getProductPriceByClientGroupId($clientGroupId, $produit['id']);
|
||||
$totalWithoutVat = $productTotalCount * $prixUnitaire;
|
||||
$statisticForeachProductPerMonth[$produit['id']] += $productTotalCount;
|
||||
$produitsPrice += $totalWithoutVat;
|
||||
}
|
||||
@ -3272,9 +3273,10 @@ class Bdd
|
||||
$client = $this->getClientById($clientId);
|
||||
if($client != null) {
|
||||
$clientName = trim($client["client_nom"]) . '-' .trim($client['client_entreprise']);
|
||||
$clientGroupId = $client['fk_client_group_id'];
|
||||
}
|
||||
$data[$clientId]["client_name"] = $clientName;
|
||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId, $produitList);
|
||||
$data[$clientId]["client_data"] = $this->getClientFactureStatisticPerMonth($clientId, $produitList, $clientGroupId);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -30,94 +30,102 @@ use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ExportClientStatisticService {
|
||||
/** @var Bdd */
|
||||
private $gestionBdd;
|
||||
class ExportClientStatisticService
|
||||
{
|
||||
/** @var Bdd */
|
||||
private $gestionBdd;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
public function __construct(
|
||||
Bdd $gestionBdd,
|
||||
LoggerInterface $logger) {
|
||||
$this->logger = $logger;
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
public function __construct(
|
||||
Bdd $gestionBdd,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->gestionBdd = $gestionBdd;
|
||||
}
|
||||
|
||||
public function getFileName(array $clientIds){
|
||||
public function getFileName(array $clientIds)
|
||||
{
|
||||
$filename = "";
|
||||
$clients = $this->gestionBdd->getClientsByClientsID($clientIds);
|
||||
foreach($clients as $client){
|
||||
foreach($clients as $client) {
|
||||
$filename .= $client['client_nom'] . '-' . $client['client_entreprise'] . '--';
|
||||
}
|
||||
$filename = rtrim($filename, '-');
|
||||
$filename = str_replace(' ','-', $filename);
|
||||
$filename = str_replace(' ','-', $filename);
|
||||
$filename = str_replace(' ', '-', $filename);
|
||||
$filename = str_replace(' ', '-', $filename);
|
||||
return $filename;
|
||||
}
|
||||
|
||||
public function getExportClientFileHeader(): string{
|
||||
$fileHeader =
|
||||
'CLIENT'.';'.
|
||||
public function getExportClientFileHeader(): string
|
||||
{
|
||||
$fileHeader =
|
||||
'CLIENT'.';'.
|
||||
'MOIS'.';'.
|
||||
'ANNEE'.';'.
|
||||
'NB DE DEFUNTS'.';';
|
||||
'NB DE DEFUNTS'.';';
|
||||
|
||||
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||
foreach($produitList as $produit){
|
||||
$fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
|
||||
}
|
||||
$fileHeader .= 'TOTAL HT'.';'."\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
$produitList = $this->gestionBdd->getProduitsListAsArray();
|
||||
foreach($produitList as $produit) {
|
||||
$fileHeader .= FileExportHelpers::FormatTextForExport($produit['reference']).';';
|
||||
}
|
||||
$fileHeader .= 'TOTAL HT'.';'."\n";
|
||||
return $fileHeader;
|
||||
}
|
||||
|
||||
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
||||
foreach($exportData as $clientId => $clientData){
|
||||
$clientName = $clientData["client_name"];
|
||||
$clientStatPerMonth = $clientData["client_data"];
|
||||
$totalPrice = 0;
|
||||
if(!empty($clientStatPerMonth)){
|
||||
foreach($clientStatPerMonth as $month => $stat){
|
||||
$stat["client_name"] = $clientName;
|
||||
$totalPrice+=$stat["total_price"];
|
||||
$fileContent = $this->populateClientStatDataIntoFileContent($fileContent,$month,$stat);
|
||||
}
|
||||
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent,$totalPrice,count($stat["products"]));
|
||||
}
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
public function populateExportDataIntoFileContent(array $exportData, string $fileContent): string
|
||||
{
|
||||
foreach($exportData as $clientId => $clientData) {
|
||||
$clientName = $clientData["client_name"];
|
||||
$clientStatPerMonth = $clientData["client_data"];
|
||||
$totalPrice = 0;
|
||||
if(!empty($clientStatPerMonth)) {
|
||||
foreach($clientStatPerMonth as $month => $stat) {
|
||||
$stat["client_name"] = $clientName;
|
||||
$totalPrice += $stat["total_price"];
|
||||
$fileContent = $this->populateClientStatDataIntoFileContent($fileContent, $month, $stat);
|
||||
}
|
||||
$fileContent = $this->populateTotalPriceIntoFileContent($fileContent, $totalPrice, count($stat["products"]));
|
||||
}
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateTotalPriceIntoFileContent(string $fileContent,$totalPrice,$productsCount){
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';';
|
||||
while($productsCount > 0){
|
||||
$fileContent .= ''.';';
|
||||
$productsCount--;
|
||||
}
|
||||
$fileContent .= "$totalPrice".";"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
private function populateTotalPriceIntoFileContent(string $fileContent, $totalPrice, $productsCount)
|
||||
{
|
||||
$fileContent = $fileContent.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';'.
|
||||
''.';';
|
||||
while($productsCount > 0) {
|
||||
$fileContent .= ''.';';
|
||||
$productsCount--;
|
||||
}
|
||||
$fileContent .= "$totalPrice".";"."\n";
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
private function populateClientStatDataIntoFileContent(string $fileContent,$month,array $statPerMonth){
|
||||
$yearValue = $statPerMonth["year"];
|
||||
$defuntCount = $statPerMonth["defunt_count"];
|
||||
$products = $statPerMonth["products"];
|
||||
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($statPerMonth['client_name']).';'.
|
||||
"$month".';'.
|
||||
"$yearValue".';'.
|
||||
"$defuntCount".';';
|
||||
private function populateClientStatDataIntoFileContent(string $fileContent, $month, array $statPerMonth)
|
||||
{
|
||||
$yearValue = $statPerMonth["year"];
|
||||
$defuntCount = $statPerMonth["defunt_count"];
|
||||
$products = $statPerMonth["products"];
|
||||
$priceTotal = $statPerMonth["total_price"];
|
||||
|
||||
foreach($products as $productCount){
|
||||
$fileContent .= "$productCount".";";
|
||||
}
|
||||
$fileContent .= "\n";
|
||||
return $fileContent;
|
||||
$fileContent = $fileContent.
|
||||
FileExportHelpers::FormatTextForExport($statPerMonth['client_name']).';'.
|
||||
"$month".';'.
|
||||
"$yearValue".';'.
|
||||
"$defuntCount".';';
|
||||
|
||||
}
|
||||
foreach($products as $productCount) {
|
||||
$fileContent .= "$productCount".";";
|
||||
}
|
||||
$fileContent .= "$priceTotal".';'."\n";
|
||||
return $fileContent;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user