<?php
namespace App\Controller\Statistiques;
use App\Entity\Articles\RaisonMouvementStock;
use App\Entity\Clients\Categorie;
use App\Entity\FO\Societe;
use App\Entity\GestionComerciale\Commande;
use App\Service\Articles\ArticleService;
use App\Service\Statistiques\StatsService;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Snappy\Pdf;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class StatistiqueController extends AbstractController
{
/**
* @Route("/stats/articles/pdf", name="dtc_stats_articles_pdf")
*/
public function statsArticlesPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$retour = $repoCommande->statArticles($param['param']);
$dateN1Debut = \DateTime::createFromFormat('d/m/Y', $param['param']['date_debut']);
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = \DateTime::createFromFormat('d/m/Y', $param['param']['date_fin']);
$dateN1Fin->setTime(23, 59, 59);
$dateN1Fin->sub(new \DateInterval('P1Y'));
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/STATS/articles.pdf';
$dateDebut = \DateTime::createFromFormat('d/m/Y', $param['param']['date_debut']);
$dateDebut->setTime(00, 00, 00);
$dateFin = \DateTime::createFromFormat('d/m/Y', $param['param']['date_fin']);
$dateFin->setTime(23, 59, 59);
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('orientation', "Landscape");
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
if (array_key_exists('categorie_client', $param['param']) and $param['param']["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param['param']["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/stats_articles_pdf.html.twig',
[
'societe' => $societe,
'parametres' => $param['param'],
'articles' => $retour,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"dateN1Debut" => $dateN1Debut,
"dateN1Fin" => $dateN1Fin,
"dateDebut" => $dateDebut,
"dateFin" => $dateFin,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/articles", name="dtc_stats_articles")
*/
public function statsArticlesAction(Request $request, EntityManagerInterface $em)
{
$dateN1Debut = new \DateTime();
$dateN1Fin = new \DateTime();
$dateDebut = new \DateTime();
$dateFin = new \DateTime();
$retour = ["articles" => []];
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$articles = [];
$param = $request->query->all();
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
//print_r($_GET);
$repoCommande = $em->getRepository(Commande::class);
$retour = $repoCommande->statArticles($param);
$dateDebut = \DateTime::createFromFormat('d/m/Y', $param['date_debut']);
$dateDebut->setTime(00, 00, 00);
$dateN1Debut = \DateTime::createFromFormat('d/m/Y', $param['date_debut']);
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateFin = \DateTime::createFromFormat('d/m/Y', $param['date_fin']);
$dateFin->setTime(23, 59, 59);
$dateN1Fin = \DateTime::createFromFormat('d/m/Y', $param['date_fin']);
$dateN1Fin->setTime(23, 59, 59);
$dateN1Fin->sub(new \DateInterval('P1Y'));
}
if (array_key_exists('categorie_client', $param) and $param["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
return $this->render('Statistiques/Statistique/stats_articles.html.twig', [
"articles" => $articles,
'parametres' => $param,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"param" => $param,
'articles' => $retour,
"dateN1Debut" => $dateN1Debut,
"dateN1Fin" => $dateN1Fin,
"dateDebut" => $dateDebut,
"dateFin" => $dateFin,
]);
}
/**
* @Route("/stats/articles/xls", name="dtc_stats_articles_xls")
*/
public function statsArticlesXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$retour = $repoCommande->statArticles($param['param']);
$dateN1Debut = \DateTime::createFromFormat('d/m/Y', $param['param']['date_debut']);
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = \DateTime::createFromFormat('d/m/Y', $param['param']['date_fin']);
$dateN1Fin->setTime(23, 59, 59);
$dateN1Fin->sub(new \DateInterval('P1Y'));
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Réf');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Nom');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Total HT');
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'stat_articles.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/hit/articles", name="dtc_top_articles")
*/
public function topArticlesAction(Request $request, EntityManagerInterface $em)
{
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$articles = [];
$param = $request->query->all();
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
//print_r($_GET);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topArticles($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1M'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("d/m/Y");
$param['date_fin'] = $dateN1Fin->format("d/m/Y");
$param['nbel'] = 500;
$param['nbelgraphe'] = 10;
//print_r($param);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topArticles($param);
}
if (array_key_exists('categorie_client', $param) and $param["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
return $this->render('Statistiques/Statistique/top_articles.html.twig', [
"articles" => $articles,
'parametres' => $param,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"param" => $param,
]);
}
/**
* @Route("/stats/hit/articles/xls", name="dtc_top_articles_xls")
*/
public function topArticlesXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, StatsService $statService)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topArticles($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Réf');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Nom');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Qte');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Total HT');
$n1 = "0";
if (array_key_exists('param', $param) && array_key_exists('n1', $param["param"]) and $param["param"]['n1'] == "1") {
$n1 = "1";
}
if ($n1 == "1") {
$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Qté n-1');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('F1', 'Total HT n-1');
}
$row = 2;
$col = 0;
for ($i = 0; $i < count($articles); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['reference']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['libelle']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['total_quantite']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['total']));
$col++;
if ($n1 == "1") {
/*
{% set totalN1 = dtc_stats.getTopClientn1(parametres,c.client_id) %}
*/
$totalN1 = $statService->getTopArticlen1($param["param"], $articles[$i]['article_id']);
//print_r($totalN1);
//exit;
$totalTemp = $totalN1["total"];
$qteTemp = $totalN1["total_quantite"];
if ($totalTemp == "") {
$totalTemp = "0";
}
if ($qteTemp == "") {
$qteTemp = "0";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $qteTemp);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalTemp);
$col++;
}
$col = 0;
$row++;
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'top_articles.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/hit/articles/pdf", name="dtc_top_articles_pdf")
*/
public function topArticlesPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topArticles($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/HIT/articles.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
if (array_key_exists('categorie_client', $param['param']) and $param['param']["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param['param']["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/top_articles_pdf.html.twig',
[
'societe' => $societe,
'parametres' => $param['param'],
'articles' => $articles,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/suivi-consommation", name="dtc_suivi_consommation")
*/
public function suiviConsommationAction(Request $request, EntityManagerInterface $em)
{
$articles = [];
$param = $request->query->all();
$moisDebut = "";
$moisFin = "";
$valeurs = ["articles" => "", "mois" => "", "total" => ""];
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommation($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
//$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Debut->sub(new \DateInterval('P6M'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("m/Y");
$param['date_fin'] = $dateN1Fin->format("m/Y");
$param['consommation'] = "vente";
$param['non_mouv'] = "0";
//$param['nbel']=500;
//$param['nbelgraphe']=10;
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommation($param);
}
//print_r($param);
return $this->render('Statistiques/Statistique/suivi_consommation.html.twig', [
"articles" => $valeurs['articles'],
"mois" => $valeurs['mois'],
"total" => $valeurs['total'],
"parametres" => $param,
]);
}
/**
* @Route("/stats/suivi-consommation/xls", name="dtc_suivi_consommation_xls")
*/
public function suiviConsommationXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommation($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Ref');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Libellé');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Qté totale');
$row = 1;
$col = 3;
for ($i = 0; $i < count($valeurs['mois']); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['mois'][$i]);
$col++;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Stock");
$col++;
$row = 2;
$col = 0;
for ($i = 0; $i < count($valeurs['articles']); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['articles'][$i]["reference"]);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['articles'][$i]["libelle"]);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['articles'][$i]["total"]);
$col++;
for ($z = 0; $z < count($valeurs['articles'][$i]['valeurs']); $z++) {
if ($valeurs['articles'][$i]['valeurs'][$z]['quantite'] == "") {
$valeurs['articles'][$i]['valeurs'][$z]['quantite'] = 0;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['articles'][$i]['valeurs'][$z]['quantite']);
$col++;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['articles'][$i]["stock"]);
$row++;
$col = 0;
}/*->setCellValue('B1', 'Libellé')
->setCellValue('C1', 'Qtité')
*/;
$boucle = 2;
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'suivi_conso.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/suivi-consommation/pdf", name="dtc_suivi_consommation_pdf")
*/
public function suiviConsommationPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommation($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/SUIVI/suivi_consommation.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$snappy->setOption('orientation', "Landscape");
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/suivi_consommation_pdf.html.twig',
[
'societe' => $societe,
"articles" => $valeurs['articles'],
"mois" => $valeurs['mois'],
"parametres" => $param['param'],
"total" => $valeurs['total'],
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("", name="")
*/
public function topClientsDetailPdfAction(Request $request, $parametres = [], EntityManagerInterface $em)
{
$get = $request->query->all();
$get = $parametres;
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topClientsDetails($parametres);
return $this->render(
'Statistiques/Statistique/top_clients_detail.html.twig',
["client_id" => $parametres["client"], "articles" => $articles, "parametres" => $parametres]
);
}
/**
* @Route("", name="")
*/
public function topClientsDetailAction(Request $request, EntityManagerInterface $em)
{
$get = $request->query->all();
$client_id = trim($get["client"]);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topClientsDetails($get);
$rendu = $this->renderView(
'Statistiques/Statistique/top_clients_detail.html.twig',
["client_id" => $get["client_id"], "articles" => $articles, "parametres" => $get]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '']);
}
/**
* @Route("/stats/hit/clients", name="dtc_top_clients")
*/
public function topClientsAction(Request $request, EntityManagerInterface $em)
{
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$clients = [];
$param = $request->query->all();
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
//print_r($_GET);
$repoCommande = $em->getRepository(Commande::class);
$clients = $repoCommande->topClients($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1M'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("d/m/Y");
$param['date_fin'] = $dateN1Fin->format("d/m/Y");
$param['nbel'] = 500;
$param['nbelgraphe'] = 10;
//print_r($param);
$repoCommande = $em->getRepository(Commande::class);
$clients = $repoCommande->topClients($param);
}
if (array_key_exists('categorie_client', $param) and $param["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
return $this->render('Statistiques/Statistique/top_clients.html.twig', [
"clients" => $clients,
'parametres' => $param,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"param" => $param,
]);
}
/**
* @Route("/stats/hit/clients/xls", name="dtc_top_clients_xls")
*/
public function topClientsXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, StatsService $statService)
{
$param = $request->query->all();
$detail = "0";
if (array_key_exists('detail', $param) and $param['detail'] == "1") {
$detail = "1";
}
$n1 = "0";
if (array_key_exists('param', $param) && array_key_exists('n1', $param["param"]) and $param["param"]['n1'] == "1") {
$n1 = "1";
}
$repoCommande = $em->getRepository(Commande::class);
$clients = $repoCommande->topClients($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Réf');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Nom');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Qté');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Factures');
if ($n1 == "1") {
$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Qté n-1');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('F1', 'Factures n-1');
}
//echo $param["n1"];
//$articleService = $this->container->get('dtc.article');
$row = 2;
$col = 0;
for ($i = 0; $i < count($clients); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($clients[$i]['reference']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($clients[$i]['prenom'])." ".trim($clients[$i]['nom']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($clients[$i]['qte']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($clients[$i]['total']));
$col++;
if ($n1 == "1") {
/*
{% set totalN1 = dtc_stats.getTopClientn1(parametres,c.client_id) %}
*/
$totalN1 = $statService->getTopClientn1($param["param"], $clients[$i]['client_id']);
$totalTemp = $totalN1["total"];
$qteTemp = $totalN1["qte"];
if ($totalTemp == "") {
$totalTemp = "0";
}
if ($qteTemp == "") {
$qteTemp = "0";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $qteTemp);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalTemp);
$col++;
}
if ($detail == 1) {
$row++;
$col = 0;
$param_details = $param['param'];
$param_details["client"] = $clients[$i]['client_id'];
$param_details["client_id"] = $clients[$i]['client_id'];
$articles = $repoCommande->topClientsDetails($param_details);
if (count($articles) > 0) {
for ($f = 0; $f < count($articles); $f++) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "");
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$f]["reference"]." ".$articles[$f]["libelle"]);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$f]["total_qte"]));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$f]["total"]));
$col++;
if ($n1 == "1") {
$tabDetailsN1 = $param["param"];
$tabDetailsN1["client"] = $clients[$i]['client_id'];
$tabDetailsN1["client_id"] = $clients[$i]['client_id'];
$transporteur_id = "";
if (array_key_exists('transporteur_id', $articles[$f]) and $articles[$f]['transporteur_id'] != "") {
$transporteur_id = $articles[$f]['transporteur_id'];
}
$totalN1 = $statService->getTopClientn1Details($tabDetailsN1, $articles[$f]['article_id'], $transporteur_id);
$totalTemp = $totalN1["total"];
$qteTemp = $totalN1["total_qte"];
if ($totalTemp == "") {
$totalTemp = "0";
}
if ($qteTemp == "") {
$qteTemp = "0";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $qteTemp);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalTemp);
$col++;
/*
{% set totalN1 = dtc_stats.getTopClientn1Details(parametres,a.article_id) %}
<td style="text-align:right;">{{totalN1.total_qte|number_format(2, '.', ' ')|replace({".00" : ""})|raw}}</td>
<td style="text-align:right;">{{totalN1.total|number_format(2, '.', ' ')|replace({".00" : ""})|raw}}</td>
*/
}
$col = 0;
$row++;
}
}
}
$col = 0;
$row++;
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'top_clients.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/hit/clients/pdf", name="dtc_top_clients_pdf")
*/
public function topClientsPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$clients = $repoCommande->topClients($param['param']);
$get = $request->query->all();
$detail = "0";
if (array_key_exists('detail', $get) and $get['detail'] == "1") {
$detail = "1";
}
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/HIT/client.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
if (array_key_exists('categorie_client', $param['param']) and $param['param']["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param['param']["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/top_clients_pdf.html.twig',
[
'detail' => $detail,
'societe' => $societe,
'parametres' => $param['param'],
'clients' => $clients,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/statistiques", name="dtc_statistiques")
*/
public function indexAction(Request $request)
{
return $this->render('Statistiques/Statistique/index.html.twig', []);
}
/**
* @Route("/stats/port/suivi-consommation", name="dtc_suivi_consommation_frais_port")
*/
public function suiviConsommationPortAction(Request $request, EntityManagerInterface $em)
{
$articles = [];
$param = $request->query->all();
$moisDebut = "";
$moisFin = "";
$valeurs = ["articles" => "", "mois" => "", "total" => ""];
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommationPort($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("m/Y");
$param['date_fin'] = $dateN1Fin->format("m/Y");
//$param['nbel']=500;
//$param['nbelgraphe']=10;
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommationPort($param);
}
//print_r($param);
return $this->render('Statistiques/Statistique/suivi_consommation_frais_port.html.twig', [
"transporteurs" => $valeurs['transporteurs'],
"mois" => $valeurs['mois'],
"total" => $valeurs['total'],
"parametres" => $param,
]);
}
/**
* @Route("/stats/port/suivi-consommation/xls", name="dtc_suivi_consommation_frais_port_xls")
*/
public function suiviConsommationPortXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommationPort($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Transporteur');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Total');
$row = 1;
$col = 2;
for ($i = 0; $i < count($valeurs['mois']); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['mois'][$i]);
$col++;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total");
$col++;
$row = 2;
$col = 0;
for ($i = 0; $i < count($valeurs['transporteurs']); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['transporteurs'][$i]["libelle"]);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['transporteurs'][$i]["total"]." (".$valeurs['transporteurs'][$i]["expedition"].")");
$col++;
for ($z = 0; $z < count($valeurs['transporteurs'][$i]['valeurs']); $z++) {
if ($valeurs['transporteurs'][$i]['valeurs'][$z]['quantite'] == "") {
$valeurs['transporteurs'][$i]['valeurs'][$z]['quantite'] = 0;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(
$col,
$row,
$valeurs['transporteurs'][$i]['valeurs'][$z]['quantite']." (".$valeurs['transporteurs'][$i]['valeurs'][$z]['expedition'].")"
);
$col++;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['transporteurs'][$i]["total"]." (".$valeurs['transporteurs'][$i]["expedition"].")");
$row++;
$col = 0;
}
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total");
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['total']["valeur"]."(".$valeurs['total']["expedition"].")");
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['total']["valeur"]."(".$valeurs['total']["expedition"].")");
$col++;
//print_r($valeurs['total']['totalMois']);
foreach ($valeurs['total']['totalMois'] as $cle => $valeur) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeur."(".$valeurs['total']['expeditionMois'][$cle].")");
$col++;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $valeurs['total']["valeur"]."(".$valeurs['total']["expedition"].")");
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'suivi_conso_port.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/port/suivi-consommation/pdf", name="dtc_suivi_consommation_frais_port_pdf")
*/
public function suiviConsommationPortPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommationPort($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/SUIVI/suivi_consommation_frais_port.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$snappy->setOption('orientation', "Landscape");
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/suivi_consommation_frais_port_pdf.html.twig',
[
'societe' => $societe,
"transporteurs" => $valeurs['transporteurs'],
"mois" => $valeurs['mois'],
"parametres" => $param['param'],
"total" => $valeurs['total'],
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("", name="")
*/
public function _suiviConsommationPortPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommation($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
//echo "AAA";
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->suiviConsommationPort($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/SUIVI/suivi_consommation_frais_port.pdf';
print_r($param);
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$snappy->setOption('orientation', "Landscape");
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/suivi_consommation_frais_port_pdf.html.twig',
[
'societe' => $societe,
"transporteurs" => $valeurs['transporteurs'],
"mois" => $valeurs['mois'],
"total" => $valeurs['total'],
"parametres" => $param,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/mouvementes/articles/xls", name="dtc_vivant_articles_xls")
*/
public function vivantArticlesXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->vivantArticles($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Réf');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Libellé');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Date');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Qté');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Raison');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('F1', 'Equipier');
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Catégorie');
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Dern. Entrée');
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Dern. Sortie');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('G1', 'Stock');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('H1', 'Cump');
$row = 2;
$col = 0;
for ($i = 0; $i < count($articles); $i++) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['reference']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['libelle']));
$col++;
$date_mouvement = new \Datetime($articles[$i]['date_mouvement']);
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $date_mouvement->format("d/m/Y H:i:s"));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$i]['quantite']);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$i]['raison_libelle']);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$i]['utilisateur_libelle']);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$i]['stock']);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, round($articles[$i]['pump'], 2));
$col++;
$col = 0;
$row++;
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'mort_articles.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/non-mouvementes/articles/xls", name="dtc_mort_articles_xls")
*/
public function mortArticlesXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, ArticleService $articleService)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->mortArticles($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Réf');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Libellé');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Catégorie');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Dern. Entrée');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Dern. Sortie');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('F1', 'Stock');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('G1', 'Cump');
$row = 2;
$col = 0;
for ($i = 0; $i < count($articles); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$dernier_entree = $articleService->derniereEntreeStock($articles[$i]['article_id'], []);
$date_dernier_entree = new \DateTime($dernier_entree["dernier"]);
$dernier_sortie = $articleService->derniereSortieStock($articles[$i]['article_id'], []);
$date_dernier_sortie = new \DateTime($dernier_sortie["dernier"]);
$categories = $articleService->getCategorieNiveauUn($articles[$i]['article_id']);
$string_categorie = "";
if (count($categories) > 0) {
foreach ($categories as $c) {
$string_categorie .= $c["libelle"]." ";
}
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['reference']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$i]['libelle']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $string_categorie);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $date_dernier_entree->format("d/m/Y"));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $date_dernier_sortie->format("d/m/Y"));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$i]['stock']);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$i]['cpump']);
$col++;
$col = 0;
$row++;
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'mort_articles.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/non-mouvementes/articles/pdf", name="dtc_mort_articles_pdf")
*/
public function mortArticlesPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->mortArticles($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/MORT/articles.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$repo_raison_mvmt = $em->getRepository(RaisonMouvementStock::class);
$raisons_mvmt = $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/mort_articles_pdf.html.twig',
[
'societe' => $societe,
'parametres' => $param['param'],
'articles' => $articles,
'raisons_mvmt' => $raisons_mvmt,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/mouvementes/articles/pdf", name="dtc_vivant_articles_pdf")
*/
public function vivantArticlesPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->vivantArticles($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/VIVANT/articles.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$repo_raison_mvmt = $em->getRepository(RaisonMouvementStock::class);
$raisons_mvmt = $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/vivant_articles_pdf.html.twig',
[
'societe' => $societe,
'parametres' => $param['param'],
'articles' => $articles,
'raisons_mvmt' => $raisons_mvmt,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/mouvementes/articles", name="dtc_vivant_articles")
*/
public function vivantArticlesAction(Request $request, EntityManagerInterface $em)
{
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$repo_raison_mvmt = $em->getRepository(RaisonMouvementStock::class);
$raisons_mvmt = $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$articles = [];
$param = $request->query->all();
//print_r($param);
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
//print_r($_GET);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->vivantArticles($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1M'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("d/m/Y");
$param['date_fin'] = $dateN1Fin->format("d/m/Y");
$param['nbel'] = -1;
$param['nbelgraphe'] = 10;
//print_r($param);
if (count($raisons_mvmt) > 0) {
foreach ($raisons_mvmt as $rm) {
if (
$rm->getId() != 1
&&
$rm->getId() != 3
&&
$rm->getId() != 15
&&
$rm->getId() != 8
&&
$rm->getId() != 10
&&
$rm->getId() != 18
) {
$param["origine_".$rm->getId()] = $rm->getId();
}
}
}
$repoCommande = $em->getRepository(Commande::class);
//$articles = $repoCommande->mortArticles($param);
$articles = [];
}
if (array_key_exists('categorie_client', $param) and $param["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
return $this->render('Statistiques/Statistique/vivant_articles.html.twig', [
"articles" => $articles,
'parametres' => $param,
'raisons_mvmt' => $raisons_mvmt,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"param" => $param,
]);
}
/**
* @Route("/stats/non-mouvementes/articles", name="dtc_mort_articles")
*/
public function mortArticlesAction(Request $request, EntityManagerInterface $em)
{
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$repo_raison_mvmt = $em->getRepository(RaisonMouvementStock::class);
$raisons_mvmt = $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$articles = [];
$param = $request->query->all();
//print_r($param);
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
//print_r($_GET);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->mortArticles($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("d/m/Y");
$param['date_fin'] = $dateN1Fin->format("d/m/Y");
$param['nbel'] = -1;
$param['nbelgraphe'] = 10;
//print_r($param);
$repoCommande = $em->getRepository(Commande::class);
//$articles = $repoCommande->mortArticles($param);
$articles = [];
}
if (array_key_exists('categorie_client', $param) and $param["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
return $this->render('Statistiques/Statistique/mort_articles.html.twig', [
"articles" => $articles,
'parametres' => $param,
'raisons_mvmt' => $raisons_mvmt,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"param" => $param,
]);
}
/**
* @Route("/stats/ca-articles", name="dtc_stats_ca_articles")
*/
public function statsCaArticlesAction(Request $request, EntityManagerInterface $em)
{
$articles = [];
$param = $request->query->all();
$moisDebut = "";
$moisFin = "";
$valeurs = ["articles" => "", "mois" => "", "total" => ""];
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
$repoCommande = $em->getRepository(Commande::class);
//$valeurs = $repoCommande->statCaArticles($param);
$statsPort = $repoCommande->suiviConsommationPort($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("m/Y");
$param['date_fin'] = $dateN1Fin->format("m/Y");
$param['consommation'] = "vente";
//$param['nbel']=500;
//$param['nbelgraphe']=10;
$repoCommande = $em->getRepository(Commande::class);
$statsPort = $repoCommande->suiviConsommationPort($param);
//$valeurs = $repoCommande->statCaArticles($param);
}
//print_r($statsPort);
$dateDebut = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebut->setTime(00, 00, 00);
$dateFin = \DateTime::createFromFormat('m/Y', $param['date_fin']);
$dateFin->modify('last day of this month');
$dateFin->setTime(23, 59, 59);
$dateFinBoucle = \DateTime::createFromFormat('m/Y', $param['date_fin']);
$dateFinBoucle->modify('last day of this month');
$dateFinBoucle->setTime(23, 59, 59);
//var_dump($dateFinBoucle->format('d/m/Y'));
$dateDebutBoucle = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebutBoucle->setTime(00, 00, 00);
$dateDebutBoucleN1 = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebutBoucleN1->setTime(00, 00, 00);
$dateDebutBoucleN1->sub(new \DateInterval('P1Y'));
$mois_boucle = [];
$mois_boucle_n1 = [];
while ($dateDebutBoucle < $dateFinBoucle) {
$mois_boucle[] = $dateDebutBoucle->format("m/Y");
$mois_boucle_n1[] = $dateDebutBoucleN1->format("m/Y");
$dateDebutBoucle->add(new \DateInterval('P1M'));
$dateDebutBoucleN1->add(new \DateInterval('P1M'));
}
//print_r($mois_boucle);
return $this->render('Statistiques/Statistique/stats_ca_articles.html.twig', [
"articles" => $valeurs['articles'],
"mois" => $valeurs['mois'],
"total" => $valeurs['total'],
"parametres" => $param,
"mois_boucle" => $mois_boucle,
"mois_boucle_n1" => $mois_boucle_n1,
"stats_ports" => $statsPort,
]);
}
/**
* @Route("/stats/ca-articles/pdf", name="dtc_stats_ca_articles_pdf")
*/
public function statsCaArticlesPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$articles = [];
$param = $request->query->all();
$param = $param["param"];
//print_r($param);
$moisDebut = "";
$moisFin = "";
$valeurs = ["articles" => "", "mois" => "", "total" => ""];
if (array_key_exists('operation', $param)) {
//if($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"]=="valider") {
//echo "GGG";
$repoCommande = $em->getRepository(Commande::class);
$statsPort = $repoCommande->suiviConsommationPort($param);
//$valeurs = $repoCommande->statCaArticles($param);
} else {
//echo "RRRRR";
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("m/Y");
$param['date_fin'] = $dateN1Fin->format("m/Y");
$repoCommande = $em->getRepository(Commande::class);
$statsPort = $repoCommande->suiviConsommationPort($param);
//$valeurs = $repoCommande->statCaArticles($param);
}
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/STATS/ca_articles.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('orientation', "Landscape");
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$dateDebut = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebut->setTime(00, 00, 00);
$dateFin = \DateTime::createFromFormat('m/Y', $param['date_fin']);
$dateFin->setTime(23, 59, 59);
$dateFinBoucle = \DateTime::createFromFormat('m/Y', $param['date_fin']);
$dateFinBoucle->setTime(23, 59, 59);
$dateDebutBoucle = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebutBoucle->setTime(00, 00, 00);
$dateDebutBoucleN1 = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebutBoucleN1->setTime(00, 00, 00);
$dateDebutBoucleN1->sub(new \DateInterval('P1Y'));
$mois_boucle = [];
$mois_boucle_n1 = [];
while ($dateDebutBoucle < $dateFinBoucle) {
$mois_boucle[] = $dateDebutBoucle->format("m/Y");
$mois_boucle_n1[] = $dateDebutBoucleN1->format("m/Y");
$dateDebutBoucle->add(new \DateInterval('P1M'));
$dateDebutBoucleN1->add(new \DateInterval('P1M'));
}
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/stats_ca_articles_pdf.html.twig',
[
'societe' => $societe,
"articles" => $valeurs['articles'],
"mois" => $valeurs['mois'],
"total" => $valeurs['total'],
"parametres" => $param,
"mois_boucle" => $mois_boucle,
"mois_boucle_n1" => $mois_boucle_n1,
"stats_ports" => $statsPort,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/ca-articles/xls", name="dtc_stats_ca_articles_xls")
*/
public function statsCaArticlesXlsAction(Request $request, EntityManagerInterface $em, StatsService $statsService)
{
$articles = [];
$param = $request->query->all();
$moisDebut = "";
$moisFin = "";
$valeurs = ["articles" => "", "mois" => "", "total" => ""];
$param = $param["param"];
if ($request->isMethod('GET')) {
$repoCommande = $em->getRepository(Commande::class);
//$valeurs = $repoCommande->statCaArticles($param);
$statsPort = $repoCommande->suiviConsommationPort($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("m/Y");
$param['date_fin'] = $dateN1Fin->format("m/Y");
$param['consommation'] = "vente";
//$param['nbel']=500;
//$param['nbelgraphe']=10;
$repoCommande = $em->getRepository(Commande::class);
$statsPort = $repoCommande->suiviConsommationPort($param);
//$valeurs = $repoCommande->statCaArticles($param);
}
$dateDebut = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebut->setTime(00, 00, 00);
$dateFin = \DateTime::createFromFormat('m/Y', $param['date_fin']);
$dateFin->setTime(23, 59, 59);
$dateFinBoucle = \DateTime::createFromFormat('m/Y', $param['date_fin']);
$dateFinBoucle->setTime(23, 59, 59);
$dateDebutBoucle = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebutBoucle->setTime(00, 00, 00);
$dateDebutBoucleN1 = \DateTime::createFromFormat('d/m/Y', '01/'.$param['date_debut']);
$dateDebutBoucleN1->setTime(00, 00, 00);
$dateDebutBoucleN1->sub(new \DateInterval('P1Y'));
$mois_boucle = [];
$mois_boucle_n1 = [];
while ($dateDebutBoucle < $dateFinBoucle) {
$mois_boucle[] = $dateDebutBoucle->format("m/Y");
$mois_boucle_n1[] = $dateDebutBoucleN1->format("m/Y");
$dateDebutBoucle->add(new \DateInterval('P1M'));
$dateDebutBoucleN1->add(new \DateInterval('P1M'));
}
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$row = 1;
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "");
$col++;
$avecN1 = false;
$typeCa = ["Atelier MO", "Mag Atelier", "Magasin", "VO", "PO", "PE"];
$intgereBl = false;
$intgereN1 = false;
if (array_key_exists('n1', $param) && $param["n1"] == "1") {
$intgereN1 = true;
}
if (array_key_exists('bl', $param) && $param["bl"] == "1") {
$intgereBl = true;
}
$indice = 0;
foreach ($mois_boucle as $mois) {
//print_r($mois);
//echo "AAA";
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($mois));
$col++;
if ($intgereN1) {
//echo "BBBB";
$avecN1 = true;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($mois_boucle_n1[$indice]));
$col++;
}
$indice++;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total N");
$col++;
if ($intgereN1) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total N-1");
$col++;
}
/*
{% for a in typeCa %}
{% set cle = 0 %}
{% set totalLigne = 0 %}
{% set totalLigneN1 = 0 %}
*/
$totaux = [];
$totauxN1 = [];
foreach ($typeCa as $a) {
$row++;
$col = 0;
$cle = "0";
$totalLigne = "0";
$totalLigneN1 = "0";
if ($a == "PO") {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Pcs occasion");
} elseif ($a == "PE") {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Pcs export");
} else {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $a);
}
foreach ($mois_boucle as $q) {
$cle++;
//{% set totalCa = dtc_stats.calculCaPeriode(a,q,intgereBl,false) %}
$totalCa = round($statsService->calculCaPeriode($a, $q, $intgereBl, false), 2);
$totalLigne += $totalCa;
if (array_key_exists($cle, $totaux)) {
$totaux[$cle] += $totalCa;
} else {
$totaux[$cle] = $totalCa;
}
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalCa);
if ($intgereN1) {
$cle++;
$col++;
$totalCaN1 = round($statsService->calculCaPeriode($a, $q, $intgereBl, true), 2);
if (array_key_exists($cle, $totaux)) {
$totaux[$cle] += $totalCaN1;
} else {
$totaux[$cle] = $totalCaN1;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalCaN1);
$totalLigneN1 += $totalCaN1;
}
}
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, round($totalLigne, 2), \PHPExcel_Cell_DataType::TYPE_NUMERIC);
if ($intgereN1) {
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, round($totalLigneN1, 2), \PHPExcel_Cell_DataType::TYPE_NUMERIC);
}
}
if (count($statsPort) > 0) {
$cle = "0";
$row++;
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Frais de port");
$totaGlobalPort = 0;
foreach ($statsPort["total"]["totalMois"] as $key => $value) {
$cle++;
$totaGlobalPort += $value;
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
if (array_key_exists($cle, $totaux)) {
$totaux[$cle] += $value;
} else {
$totaux[$cle] = $value;
}
}
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totaGlobalPort);
}
$totalLigne = 0;
$totalLigneN1 = 0;
$row++;
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total");
$indice = 1;
foreach ($totaux as $q) {
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $q);
if ($intgereN1) {
if ($intgereN1 && $indice % 2 == 0) {
$totalLigneN1 += $q;
} else {
$totalLigne += $q;
}
} else {
$totalLigne += $q;
}
$indice++;
}
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalLigne);
if ($intgereN1) {
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalLigneN1);
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'stat_ca_articles.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("", name="")
*/
public function ___statsCaArticlesXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator
) {
$articles = [];
$param = $request->query->all();
$param = $param["param"];
//print_r($param);
$moisDebut = "";
$moisFin = "";
$valeurs = ["articles" => "", "mois" => "", "total" => ""];
if (array_key_exists('operation', $param)) {
//if($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"]=="valider") {
//echo "GGG";
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->statCaArticles($param);
} else {
//echo "RRRRR";
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1Y'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("m/Y");
$param['date_fin'] = $dateN1Fin->format("m/Y");
$repoCommande = $em->getRepository(Commande::class);
$valeurs = $repoCommande->statCaArticles($param);
}
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$row = 1;
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "");
$col++;
$avecN1 = false;
foreach ($valeurs['mois'] as $mois) {
//print_r($mois);
if (array_key_exists('0', $mois)) {
//echo "AAA";
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($mois[0]));
$col++;
}
if (array_key_exists('1', $mois)) {
//echo "BBBB";
$avecN1 = true;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($mois[1]));
$col++;
}
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total N");
$col++;
if ($avecN1) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total N-1");
$col++;
}
//exit;
$totaux = [];
foreach ($valeurs['articles'] as $article) {
$totalLigne = 0;
$totalLigneN1 = 0;
$row++;
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($article["libelle"]));
$col++;
$cle = "0";
foreach ($article['valeurs'] as $valeur) {
$cle++;
if ( ! array_key_exists($cle, $totaux)) {
$totaux[$cle] = "";
}
$montant = $valeur["quantite"];
$montant = round($montant, 2);
$montant = str_replace(".00", "", $montant);
if ($montant == "0") {
$montant = "";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($montant));
$col++;
$totaux[$cle] = $totaux[$cle] + $montant;
$totalLigne = $totalLigne + $montant;
if ($avecN1) {
$cle++;
if ( ! array_key_exists($cle, $totaux)) {
//echo "<div>creation cle : ".$cle."</div>";
$totaux[$cle] = "";
}
$montant = $valeur["quantite_n1"];
$montant = round($montant, 2);
$montant = str_replace(".00", "", $montant);
if ($montant == "0") {
$montant = "";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($montant));
$col++;
$totaux[$cle] = $totaux[$cle] + $montant;
$totalLigneN1 = $totalLigneN1 + $montant;
}
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($totalLigne));
$col++;
if ($avecN1) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($totalLigneN1));
$col++;
}
}
$row++;
$col = 0;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "Total");
$col++;
//exit;
$compteur = 0;
$totalLigne = 0;
$totalLigneN1 = 0;
foreach ($totaux as $total) {
$compteur++;
$montant = $total;
$montant = round($montant, 2);
$montant = str_replace(".00", "", $montant);
if ($montant == "0") {
$montant = "";
}
if ($compteur % 2 == 0) {
$totalLigneN1 = $totalLigneN1 + $montant;
} else {
$totalLigne = $totalLigne + $montant;
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($montant));
$col++;
}
if ($totalLigne == "0") {
$totalLigne = "";
}
if ($totalLigneN1 == "0") {
$totalLigneN1 = "";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($totalLigne));
$col++;
if ($avecN1) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($totalLigneN1));
$col++;
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'stat_ca_articles.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/hit/clients/detail", name="dtc_top_clients_detail")
*/
public function __topClientsDetailAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator)
{
$get = $request->query->all();
$client_id = trim($get["client"]);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topClientsDetails($get);
$rendu = $this->renderView(
'Statistiques/Statistique/top_clients_detail.html.twig',
["client_id" => $get["client_id"], "articles" => $articles, "parametres" => $get]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '']);
}
/**
* @Route("/stats/hit/marques", name="dtc_top_marques")
*/
public function topMarquesAction(Request $request, EntityManagerInterface $em)
{
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
$articles = [];
$param = $request->query->all();
if ($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"] == "valider") {
//print_r($_GET);
$repoCommande = $em->getRepository(Commande::class);
$marques = $repoCommande->topMarques($param);
} else {
$dateN1Debut = new \DateTime();
$dateN1Debut->setTime(00, 00, 00);
$dateN1Debut->sub(new \DateInterval('P1M'));
$dateN1Fin = new \DateTime();
$param = [];
$param['date_debut'] = $dateN1Debut->format("d/m/Y");
$param['date_fin'] = $dateN1Fin->format("d/m/Y");
$param['nbel'] = 500;
$param['nbelgraphe'] = 10;
//print_r($param);
$repoCommande = $em->getRepository(Commande::class);
$marques = $repoCommande->topMarques($param);
}
if (array_key_exists('categorie_client', $param) and $param["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
return $this->render('Statistiques/Statistique/top_marques.html.twig', [
"marques" => $marques,
'parametres' => $param,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
"param" => $param,
]);
}
/**
* @Route("/stats/hit/marques/xls", name="dtc_top_marques_xls")
*/
public function topMarquesXlsAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, StatsService $statService)
{
$param = $request->query->all();
$detail = "0";
if (array_key_exists('detail', $param) and $param['detail'] == "1") {
$detail = "1";
}
$n1 = "0";
if (array_key_exists('param', $param) && array_key_exists('n1', $param["param"]) and $param["param"]['n1'] == "1") {
$n1 = "1";
}
$repoCommande = $em->getRepository(Commande::class);
$marques = $repoCommande->topMarques($param['param']);
$societe = $em->getRepository(Societe::class)->find(1);
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Réf');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('B1', 'Nom');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Qté');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Total HT');
if ($n1 == "1") {
$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Qté n-1');
$spreadsheet->setActiveSheetIndex(0)->setCellValue('F1', 'Total HT n-1');
}
//echo $param["n1"];
//$articleService = $this->container->get('dtc.article');
$row = 2;
$col = 0;
for ($i = 0; $i < count($marques); $i++) {
//$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($marques[$i]['reference']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($marques[$i]['libelle']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($marques[$i]['total_quantite']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($marques[$i]['total']));
$col++;
if ($n1 == "1") {
/*
{% set totalN1 = dtc_stats.getTopClientn1(parametres,c.client_id) %}
*/
//{% set totalN1 = dtc_stats.getTopMarquen1(parametres,a.marque_id) %}
//$totalN1 = $statService->getTopClientn1($param["param"],$marques[$i]['marque_id']);
$totalN1 = $statService->getTopMarquen1($param["param"], $marques[$i]['marque_id']);
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($totalN1['total_quantite']));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($totalN1['total']));
$col++;
}
if ($detail == 1) {
$row++;
$col = 0;
$param_details = $param['param'];
$param_details["marque"] = $marques[$i]['marque_id'];
$param_details["marque_id"] = $marques[$i]['marque_id'];
$articles = $repoCommande->topMarquesDetails($param_details);
if (count($articles) > 0) {
for ($f = 0; $f < count($articles); $f++) {
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, "");
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $articles[$f]["reference"]." ".$articles[$f]["libelle"]);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$f]["total_qte"]));
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, trim($articles[$f]["total"]));
$col++;
if ($n1 == "1") {
$tabDetailsN1 = $param["param"];
$tabDetailsN1["marque"] = $marques[$i]['marque_id'];
$tabDetailsN1["marque_id"] = $marques[$i]['marque_id'];
$totalN1 = $statService->getTopMarquen1Details($tabDetailsN1, $articles[$f]['article_id']);
$totalTemp = $totalN1["total"];
$qteTemp = $totalN1["total_qte"];
if ($totalTemp == "") {
$totalTemp = "0";
}
if ($qteTemp == "") {
$qteTemp = "0";
}
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $qteTemp);
$col++;
$spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $totalTemp);
$col++;
/*
{% set totalN1 = dtc_stats.getTopClientn1Details(parametres,a.article_id) %}
<td style="text-align:right;">{{totalN1.total_qte|number_format(2, '.', ' ')|replace({".00" : ""})|raw}}</td>
<td style="text-align:right;">{{totalN1.total|number_format(2, '.', ' ')|replace({".00" : ""})|raw}}</td>
*/
}
$col = 0;
$row++;
}
}
}
$col = 0;
$row++;
}
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'top_marques.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
// Create the excel file in the tmp directory of the system
$writer->save($temp_file);
// Return the excel file as an attachment
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/stats/hit/marques/pdf", name="dtc_top_marques_pdf")
*/
public function topMarquesPdfAction(Request $request, $param = [], $retour = true, EntityManagerInterface $em, Pdf $snappy)
{
$param = $request->query->all();
$repoCommande = $em->getRepository(Commande::class);
$marques = $repoCommande->topMarques($param['param']);
$get = $request->query->all();
$detail = "0";
if (array_key_exists('detail', $get) and $get['detail'] == "1") {
$detail = "1";
}
$societe = $em->getRepository(Societe::class)->find(1);
$chemin_pdf = 'PDF/HIT/marques.pdf';
if (file_exists($chemin_pdf)) {
//return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
unlink($chemin_pdf);
}
$footer = $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
//$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe' => $societe,'commande' => $bonPreparation));
$header = "";
$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$snappy->setOption('margin-bottom', "10");
$categorie_enfants = [];
$repo_categorie_client = $em->getRepository(Categorie::class);
$categorie_client_racine = $repo_categorie_client->findBy(["modifiable" => 0]);
if (array_key_exists('categorie_client', $param['param']) and $param['param']["categorie_client"] > 0) {
$parent = $repo_categorie_client->find($param['param']["categorie_client"]);
if (is_object($parent)) {
$categorie_enfants = $repo_categorie_client->findBy(["categorieParent" => $parent]);
}
}
$snappy->generateFromHtml(
$this->renderView(
//'GestionComerciale/BonLivraison/template_pdf.html.twig',
'Statistiques/Statistique/top_marques_pdf.html.twig',
[
'detail' => $detail,
'societe' => $societe,
'parametres' => $param['param'],
'marques' => $marques,
"categorie_client" => $categorie_client_racine,
"sous_categorie_client" => $categorie_enfants,
]
),
$chemin_pdf
);
if ($retour == true) {
return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
}
}
/**
* @Route("/stats/hit/marques/detail", name="dtc_top_marques_detail")
*/
public function topMarquesDetailAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator)
{
$get = $request->query->all();
$marque_id = trim($get["marque_id"]);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topMarquesDetails($get);
$rendu = $this->renderView(
'Statistiques/Statistique/top_marques_detail.html.twig',
["marque_id" => $get["marque_id"], "articles" => $articles, "parametres" => $get]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '']);
}
/**
* @Route("", name="")
*/
public function topMarquesDetailPdfAction(Request $request, $parametres = [], EntityManagerInterface $em)
{
$get = $request->query->all();
$get = $parametres;
$marque_id = trim($get["marque_id"]);
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topMarquesDetails($parametres);
return $this->render(
'Statistiques/Statistique/top_marques_detail.html.twig',
["marque_id" => $parametres["marque"], "articles" => $articles, "parametres" => $parametres]
);
}
/**
* @Route("", name="")
*/
public function __topClientsDetailPdfAction(Request $request, $parametres = [], EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator)
{
$get = $request->query->all();
$get = $parametres;
$repoCommande = $em->getRepository(Commande::class);
$articles = $repoCommande->topClientsDetails($parametres);
return $this->render(
'Statistiques/Statistique/top_clients_detail.html.twig',
["client_id" => $parametres["client"], "articles" => $articles, "parametres" => $parametres]
);
}
}