show with canevas some statistics

This commit is contained in:
Kayn Ty 2018-05-22 16:38:51 +02:00
parent 70bbc42b93
commit fe4f202bed
No known key found for this signature in database
GPG Key ID: 55B09AA0ED327CD3
6 changed files with 533 additions and 436 deletions

View File

@ -22,7 +22,7 @@
</div>
{% if not (app.user.products |length) %}
<div class="alert alert-info">
<div class="alert alert-info" ng-if="!productsFromDB.length && initLoadDone">
<i class="fa fa-info"></i>
Créez facilement vos catégories de produits et vos produits juste en écrivant un nom par ligne dans

View File

@ -7,6 +7,10 @@
<div class="row">
<h1>Historique</h1>
</div>
<div id="chartContainer" style="display: inline-block; height: 300px; width: 49%;"></div>
<div id="chartContainerChiffreAffaire" style="display: inline-block; height: 300px; width: 49%;"></div>
<div class="row">
<div class="col-xs-6">
<div class="sells">
@ -83,4 +87,48 @@
</div>
</div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script>
var dataPoints = [
{% for pair in statisticsSoldProducts %}
{ label: "{{ pair.name }}", y: {{ pair.count }} },
{% endfor %}
];
var dataPointsChiffreAffaire = [
{% for pair in statisticsSoldProducts %}
{ label: "{{ pair.name }}", y: {{ pair.value }} },
{% endfor %}
];
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "Volume de produits vendus"
},
animationEnabled: true,
data: [
{
// Change type to "doughnut", "line", "splineArea", etc.
type: "pie",
dataPoints: dataPoints
}
]
});
chart.render();
var chartContainerChiffreAffaire = new CanvasJS.Chart("chartContainerChiffreAffaire", {
title:{
text: "Valeur en euros des produits vendus"
},
animationEnabled: true,
data: [
{
// Change type to "doughnut", "line", "splineArea", etc.
type: "pie",
dataPoints: dataPointsChiffreAffaire
}
]
});
chartContainerChiffreAffaire.render();
</script>
{% endblock %}

View File

@ -1,8 +1,10 @@
// require('../../../node_modules/canvasjs/dist/canvasjs.3');
var $ = require('jquery');
// JS is equivalent to the normal "bootstrap" package
// no need to set this to a variable, just require it
require('bootstrap-sass');
// or you can include specific pieces
// require('bootstrap-sass/javascripts/bootstrap/tooltip');
// require('bootstrap-sass/javascripts/bootstrap/popover');

View File

@ -10,6 +10,7 @@
"dependencies": {
"angular": "1.5",
"bootstrap": "^4.0.0",
"canvasjs": "^1.8.1",
"font-awesome": "^4.7.0",
"jquery": "1.12.2"
}

View File

@ -14,78 +14,83 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
class DefaultController extends Controller {
class DefaultController extends Controller
{
private $tokenManager;
public function __construct( CsrfTokenManagerInterface $tokenManager = null ) {
public function __construct(CsrfTokenManagerInterface $tokenManager = null)
{
$this->tokenManager = $tokenManager;
}
/**
* @Route("/", name="homepage")
*/
public function indexAction( Request $request ) {
public function indexAction(Request $request)
{
$m = $this->getDoctrine()->getManager();
$userRepo = $m->getRepository( 'AppBundle:User' );
$userRepo = $m->getRepository('AppBundle:User');
$allUsers = $userRepo->findAll();
// replace this example code with whatever you need
return $this->render( 'default/index.html.twig',
return $this->render('default/index.html.twig',
[
'usersCount' => count( $allUsers ),
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
] );
'usersCount' => count($allUsers),
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
]);
}
/**
* @Route("/dashboard", name="dashboard")
*/
public function dashboardAction( Request $request ) {
public function dashboardAction(Request $request)
{
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
// TODO on first login set default values
$lastFestival = $currentUser->getActiveFestival();
if ( ! $lastFestival ) {
$lastFestival = $m->getRepository( 'AppBundle:Festival' )
->findOneBy( [ 'user' => $this->getUser()->getId() ],
[ 'id' => 'desc' ],
if (!$lastFestival) {
$lastFestival = $m->getRepository('AppBundle:Festival')
->findOneBy(['user' => $this->getUser()->getId()],
['id' => 'desc'],
0,
1 );
1);
}
if ( $lastFestival ) {
if ($lastFestival) {
$lastFestival->recalculateChiffreAffaire();
}
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categRepo = $m->getRepository('AppBundle:ProductCategory');
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
$categories = $categRepo->findAll();
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
$recentSells = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 5);
return $this->render( 'logged/dashboard.html.twig',
return $this->render('logged/dashboard.html.twig',
[
'lastFestival' => $lastFestival,
'categories' => $categories,
'currentUser' => $currentUser,
'recentSells' => $recentSells,
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
] );
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
]);
}
/**
* envoyer un email
*/
public function emailAction() {
public function emailAction()
{
$name = "noble barbare";
$message = \Swift_Message::newInstance()
->setSubject( 'Hello Email' )
->setFrom( 'test-symfony-tykayn@caisse.ciperbliss.com' )
->setTo( 'tykayn@gmail.com' )
->setBody( $this->renderView( 'default/test-email.html.twig' ),
'text/html' );
$this->get( 'mailer' )->send( $message );
->setSubject('Hello Email')
->setFrom('test-symfony-tykayn@caisse.ciperbliss.com')
->setTo('tykayn@gmail.com')
->setBody($this->renderView('default/test-email.html.twig'),
'text/html');
$this->get('mailer')->send($message);
//return 'yay test de mail';
return $this->render(
@ -99,56 +104,57 @@ class DefaultController extends Controller {
* get user products
* @return JsonResponse
*/
public function getMyProductsAction() {
public function getMyProductsAction()
{
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
if ( ! $currentUser ) {
return new JsonResponse( [
'categories' => [ [ 'name' => 'demo category', 'products' => [] ] ],
'recentSells' => [ [ '' ] ],
] );
if (!$currentUser) {
return new JsonResponse([
'categories' => [['name' => 'demo category', 'products' => []]],
'recentSells' => [['']],
]);
}
$activeFestival = $currentUser->getActiveFestival();
if ( ! $activeFestival ) {
$activeFestival = $m->getRepository( 'AppBundle:Festival' )
->findOneBy( [ 'user' => $this->getUser()->getId() ],
[ 'id' => 'desc' ],
if (!$activeFestival) {
$activeFestival = $m->getRepository('AppBundle:Festival')
->findOneBy(['user' => $this->getUser()->getId()],
['id' => 'desc'],
0,
1 );
if ( ! $activeFestival ) {
1);
if (!$activeFestival) {
$activeFestival = new Festival();
$activeFestival->setDateCreation( new \DateTime() )
->setName( 'default festival' )
->setChiffreAffaire( 0 )
->setFondDeCaisseAvant( 0 )
->setFondDeCaisseApres( 0 )
->setUser( $currentUser );
$activeFestival->setDateCreation(new \DateTime())
->setName('default festival')
->setChiffreAffaire(0)
->setFondDeCaisseAvant(0)
->setFondDeCaisseApres(0)
->setUser($currentUser);
}
$currentUser->setActiveFestival( $activeFestival );
$m->persist( $activeFestival );
$m->persist( $currentUser );
$currentUser->setActiveFestival($activeFestival);
$m->persist($activeFestival);
$m->persist($currentUser);
$m->flush();
}
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categRepo = $m->getRepository('AppBundle:ProductCategory');
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
$categories = $currentUser->getCategories();
if ( ! count( $categories ) ) {
$categories = $defaultCategories = $categRepo->findById( [ 1, 2 ] );
$currentUser->setCategories( $defaultCategories );
$m->persist( $currentUser );
if (!count($categories)) {
$categories = $defaultCategories = $categRepo->findById([1, 2]);
$currentUser->setCategories($defaultCategories);
$m->persist($currentUser);
}
$serializedCategories = [];
foreach ( $categories as $category ) {
foreach ($categories as $category) {
$products = $category->getProducts();
if ( $products ) {
if ($products) {
$listOfProductsInArray = [];
foreach ( $products as $product ) {
foreach ($products as $product) {
$listOfProductsInArray[] = [
'id' => $product->getId(),
'name' => $product->getName(),
@ -170,22 +176,22 @@ class DefaultController extends Controller {
$categories = $serializedCategories;
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
$recentSells = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 5);
return new JsonResponse( [
return new JsonResponse([
'categories' => $categories,
'recentSells' => count( $recentSells ),
'recentSells' => count($recentSells),
'lastFestival' => [
'id' => $activeFestival->getId(),
'name' => $activeFestival->getName(),
'commentaire' => $activeFestival->getComment(),
'dateCreation' => $activeFestival->getDateCreation(),
'chiffreAffaire' => $activeFestival->getChiffreAffaire(),
'clientsCount' => count( $activeFestival->getSellRecords() ),
'clientsCount' => count($activeFestival->getSellRecords()),
'fondDeCaisseAvant' => $activeFestival->getFondDeCaisseAvant(),
'fondDeCaisseApres' => $activeFestival->getFondDeCaisseApres(),
],
] );
]);
}
/**
@ -194,80 +200,81 @@ class DefaultController extends Controller {
*
* @return JsonResponse
*/
public function addSellingAction( Request $request ) {
public function addSellingAction(Request $request)
{
$json = json_decode( $request->getContent(), true );
$json = json_decode($request->getContent(), true);
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$newSellRecord = new SellRecord();
// sort user categories
$myCategories = $m->getRepository( 'AppBundle:ProductCategory' )->findAll();
$myCategories = $m->getRepository('AppBundle:ProductCategory')->findAll();
$categoriesByID = [];
foreach ( $myCategories as $my_category ) {
$categoriesByID[ $my_category->getId() ] = $my_category;
foreach ($myCategories as $my_category) {
$categoriesByID[$my_category->getId()] = $my_category;
}
$productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
$productsModels = $m->getRepository('AppBundle:Product')->findAll();
$productsModelsByID = [];
foreach ( $productsModels as $product ) {
$productsModelsByID[ $product->getId() ] = $product;
foreach ($productsModels as $product) {
$productsModelsByID[$product->getId()] = $product;
}
$sumAmount = 0;
foreach ( $json[ 'activeSelling' ] as $record ) {
$productModel = $productsModelsByID[ $record[ 'id' ] ];
foreach ($json['activeSelling'] as $record) {
$productModel = $productsModelsByID[$record['id']];
$newProductSold = new ProductSold();
$newProductSold->setName( $record[ 'name' ] );
$newProductSold->setImage( "image mock" );
$newProductSold->setUser( $currentUser );
$newProductSold->setPrice( $record[ 'price' ] );
$newProductSold->setComment( $json[ 'sellingComment' ] );
$newProductSold->setProduct( $productModel );
$newProductSold->setSellRecords( $newSellRecord );
$newProductSold->setName($record['name']);
$newProductSold->setImage("image mock");
$newProductSold->setUser($currentUser);
$newProductSold->setPrice($record['price']);
$newProductSold->setComment($json['sellingComment']);
$newProductSold->setProduct($productModel);
$newProductSold->setSellRecords($newSellRecord);
// link selling record with user, festival
$currentUser->addProductsSold( $newProductSold );
$currentUser->addProductsSold($newProductSold);
// persist all
$productModel->setStockCount( $productModel->getStockCount() - 1 );
$m->persist( $productModel );
$m->persist( $newProductSold );
$m->persist( $newProductSold );
$sumAmount += $record[ 'price' ];
$productModel->setStockCount($productModel->getStockCount() - 1);
$m->persist($productModel);
$m->persist($newProductSold);
$m->persist($newProductSold);
$sumAmount += $record['price'];
}
$festivalFound = $m->getRepository( 'AppBundle:Festival' )->find( $json[ 'activeFestival' ][ 'id' ] );
$newSellRecord->setFestival( $festivalFound );
$newSellRecord->setAmount( $sumAmount );
$newSellRecord->setDate( new \DateTime() );
$newSellRecord->setUser( $currentUser );
$newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
$newSellRecord->setComment( $json[ 'sellingComment' ] );
$festivalFound = $m->getRepository('AppBundle:Festival')->find($json['activeFestival']['id']);
$newSellRecord->setFestival($festivalFound);
$newSellRecord->setAmount($sumAmount);
$newSellRecord->setDate(new \DateTime());
$newSellRecord->setUser($currentUser);
$newSellRecord->setPaidByClient($json['paidByClient']);
$newSellRecord->setComment($json['sellingComment']);
$festivalFound->addSellRecord( $newSellRecord );
$currentUser->addSellRecords( $newSellRecord );
$festivalFound->addSellRecord($newSellRecord);
$currentUser->addSellRecords($newSellRecord);
$m->persist( $newSellRecord );
$m->persist( $currentUser );
$m->persist( $festivalFound );
$m->persist($newSellRecord);
$m->persist($currentUser);
$m->persist($festivalFound);
$m->flush();
$festivalFound->recalculateChiffreAffaire();
$m->persist( $festivalFound );
$m->persist($festivalFound);
$m->flush();
// setup dates
// fetch back history of selling
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$lastSellings = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 3 );
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
$lastSellings = $sellingRepo->findBy(['user' => $currentUser->getId()], ['id' => 'desc'], 0, 3);
return new JsonResponse( [
return new JsonResponse([
"message" => "ok",
"newChiffreAffaire" => $festivalFound->getChiffreAffaire(),
"clientsCount" => count( $festivalFound->getSellRecords() ),
"recent_sellings" => json_encode( $lastSellings ),
"clientsCount" => count($festivalFound->getSellRecords()),
"recent_sellings" => json_encode($lastSellings),
"dump" => $json,
], 200 );
], 200);
}
@ -275,40 +282,72 @@ class DefaultController extends Controller {
* get the history of user's sellings
* @Route("/history", name="history")
*/
public function historyAction() {
public function historyAction()
{
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
$mySellings = $sellingRepo->findByUser($currentUser->getId());
$chiffreAffaires = 0;
foreach ( $mySellings as $client ) {
foreach ( $client->getProductsSold() as $product ) {
$productsSoldOfUser = $currentUser->getProductsSold();
$statisticsSoldProducts = [
// ['name' => 'bidule', 'count' => 0, 'value' => 0],
];
$statsForFestival = [
['name' => 'festoche bidule', 'clients_count' => 125, 'chiffre_affaire' => 236],
];
foreach ($mySellings as $client) {
foreach ($client->getProductsSold() as $product) {
$chiffreAffaires += $product->getPrice();
}
if (!isset($statisticsSoldProducts[$product->getName()])) {
$statisticsSoldProducts[$product->getName()] =
[
'name' => $product->getName(),
'count' => 0,
'value' => 0
];
}
return $this->render( 'logged/history.html.twig',
// echo '<pre>';
// var_dump(intval($product->getPrice()));
// echo '</pre>';
$statisticsSoldProducts[$product->getName()]['count']++;
$statisticsSoldProducts[$product->getName()]['value'] = $statisticsSoldProducts[$product->getName()]['value'] + intval($product->getPrice());
}
}
// echo '<pre>';
// var_dump($statisticsSoldProducts);
// echo '</pre>';
return $this->render('logged/history.html.twig',
[
'statisticsSoldProducts' => $statisticsSoldProducts,
'chiffreAffaires' => $chiffreAffaires,
'recentSells' => $mySellings,
'base_dir' => realpath( $this->getParameter( 'kernel.project_dir' ) ) . DIRECTORY_SEPARATOR,
] );
'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
]);
}
/**
* export all clients
* @Route("/export-all", name="export_all")
*/
public function exportAllAction() {
public function exportAllAction()
{
// TODO
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$mySellings = $sellingRepo->findByUser( $currentUser->getId() );
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
$mySellings = $sellingRepo->findByUser($currentUser->getId());
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date( 'Y-m-d_H-i-s' );
$fileName = "export_caisse-cipherbliss_" . $currentUser->getUsername() . '_' . date('Y-m-d_H-i-s');
$handle = fopen( 'php://memory', 'r+' );
$handle = fopen('php://memory', 'r+');
$firstLine = [
'product sold id',
'date',
@ -331,21 +370,21 @@ class DefaultController extends Controller {
'festival comment',
];
// save the column headers
fputcsv( $handle,
$firstLine );
fputcsv($handle,
$firstLine);
$chiffreAffaires = 0;
foreach ( $mySellings as $sellRecord ) {
foreach ( $sellRecord->getProductsSold() as $productSold ) {
foreach ($mySellings as $sellRecord) {
foreach ($sellRecord->getProductsSold() as $productSold) {
$chiffreAffaires += $productSold->getPrice();
// add a line to the csv file
fputcsv( $handle,
fputcsv($handle,
[
$productSold->getId(),
$sellRecord->getDate()->format( 'c' ),
$sellRecord->getDate()->format( 'H' ),
$sellRecord->getDate()->format( 'i' ),
$sellRecord->getDate()->format( 's' ),
$sellRecord->getDate()->format('c'),
$sellRecord->getDate()->format('H'),
$sellRecord->getDate()->format('i'),
$sellRecord->getDate()->format('s'),
$sellRecord->getComment(),
$sellRecord->getPaidByClient(),
$productSold->getName(),
@ -353,9 +392,9 @@ class DefaultController extends Controller {
$productSold->getProduct()->getCategory()->getId(),
$productSold->getProduct()->getCategory()->getName(),
$productSold->getPrice(),
] );
if ( $sellRecord->getFestival() ) {
fputcsv( $handle,
]);
if ($sellRecord->getFestival()) {
fputcsv($handle,
[
'',
'',
@ -371,19 +410,19 @@ class DefaultController extends Controller {
'',
$sellRecord->getFestival()->getId(),
$sellRecord->getFestival()->getName(),
$sellRecord->getFestival()->getDateCreation()->format( 'c' ),
$sellRecord->getFestival()->getDateCreation()->format('c'),
$sellRecord->getFestival()->getFondDeCaisseAvant(),
$sellRecord->getFestival()->getFondDeCaisseApres(),
$sellRecord->getFestival()->getChiffreAffaire(),
$sellRecord->getFestival()->getComment(),
] );
]);
}
}
}
rewind( $handle );
$content = stream_get_contents( $handle );
fclose( $handle );
rewind($handle);
$content = stream_get_contents($handle);
fclose($handle);
return new Response(
$content, 200, [
@ -397,37 +436,40 @@ class DefaultController extends Controller {
/**
* @Route("/set-active-festival/{id}", name="set_active_festival")
*/
public function setActiveFestivalAction( $id ) {
public function setActiveFestivalAction($id)
{
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$repo = $m->getRepository( 'AppBundle:Festival' );
$repo = $m->getRepository('AppBundle:Festival');
$currentUser->setActiveFestival( $repo->find( $id ) );
$m->persist( $currentUser );
$currentUser->setActiveFestival($repo->find($id));
$m->persist($currentUser);
$m->flush();
// replace this example code with whatever you need
return $this->redirectToRoute( 'dashboard' );
return $this->redirectToRoute('dashboard');
}
/**
* @Route("/import", name="import")
*/
public function importAction() {
public function importAction()
{
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$sellingRepo = $m->getRepository('AppBundle:SellRecord');
return $this->render( 'logged/import.html.twig',
return $this->render('logged/import.html.twig',
[
'base_dir' => '',
] );
]);
}
/**
* @Route("/mass-create", name="mass_create")
*/
public function massCreateAction( Request $request ) {
public function massCreateAction(Request $request)
{
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
@ -436,36 +478,36 @@ class DefaultController extends Controller {
$myProductsByName = [];
$currentCategory = new ProductCategory();
$currentCategory
->addUser( $currentUser )
->setName( 'default category' );
->addUser($currentUser)
->setName('default category');
foreach ( $myCategories as $my_category ) {
$myCategoriesByName [ $my_category->getName() ] = $my_category;
foreach ( $my_category->getProducts() as $product ) {
$myProductsByName[ $product->getName() ] = $product;
foreach ($myCategories as $my_category) {
$myCategoriesByName [$my_category->getName()] = $my_category;
foreach ($my_category->getProducts() as $product) {
$myProductsByName[$product->getName()] = $product;
}
$currentCategory = $my_category;
}
$massLines = $request->request->get( 'produits' );
if ( $request->getMethod() == 'POST' ) {
$lines = preg_split( '/$\R?^/m', trim( $massLines ) );
foreach ( $lines as $line ) {
$massLines = $request->request->get('produits');
if ($request->getMethod() == 'POST') {
$lines = preg_split('/$\R?^/m', trim($massLines));
foreach ($lines as $line) {
if ( strpos( $line, ':' ) ) {
if (strpos($line, ':')) {
// manage catgegories
$boom = explode( ':', trim( $line ) );
$firstPart = $boom[ 0 ];
$value = $boom[ 1 ];
$boom = explode(':', trim($line));
$firstPart = $boom[0];
$value = $boom[1];
echo "gérer une catégorie nommée: $value";
if ( $firstPart === 'catégorie' && $value ) {
if ($firstPart === 'catégorie' && $value) {
// look for category by name
if ( ! isset( $myCategoriesByName[ $value ] ) ) {
if (!isset($myCategoriesByName[$value])) {
$newCateg = new ProductCategory();
$newCateg
->addUser( $currentUser )
->setName( $value );
$currentUser->addCategory( $newCateg );
$m->persist( $newCateg );
->addUser($currentUser)
->setName($value);
$currentUser->addCategory($newCateg);
$m->persist($newCateg);
$currentCategory = $newCateg; // associate further categories with the newly created one
} else {
echo " la catégorie existe déjà";
@ -474,37 +516,37 @@ class DefaultController extends Controller {
} else {
// manage product
echo "<br/> $line";
$boom = explode( ';', $line );
$productName = $boom[ 0 ];
$boom = explode(';', $line);
$productName = $boom[0];
$price = 0;
if ( $boom[ 1 ] ) {
$price = intval( str_replace( '€', '', $boom[ 1 ] ) );
if ($boom[1]) {
$price = intval(str_replace('€', '', $boom[1]));
}
// or create new product
if ( $productName && ! isset( $myProductsByName[ $productName ] ) ) {
if ($productName && !isset($myProductsByName[$productName])) {
$newProduct = new Product();
$newProduct->setCategory( $currentCategory )
->setName( $productName )
->setUser( $currentUser )
->setPrice( $price ) // removing euro symbol
$newProduct->setCategory($currentCategory)
->setName($productName)
->setUser($currentUser)
->setPrice($price) // removing euro symbol
;
$currentUser->addProduct( $newProduct );
$m->persist( $newProduct );
$currentUser->addProduct($newProduct);
$m->persist($newProduct);
}// look for existing products
else {
$myProductsByName[ $productName ]->setPrice( $price );
$myProductsByName[$productName]->setPrice($price);
}
}
$m->persist( $currentUser );
$m->persist($currentUser);
}
// check with existing categories and products, sort them by name.
// save all
$m->flush();
}
return $this->render( 'logged/import.html.twig',
[] );
return $this->render('logged/import.html.twig',
[]);
}
}

View File

@ -1078,6 +1078,10 @@ caniuse-lite@^1.0.30000792:
version "1.0.30000819"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000819.tgz#aabee5fd15a080febab6ae5d30c9ea15f4c6d4e2"
canvasjs@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/canvasjs/-/canvasjs-1.8.1.tgz#698a4e002e336ce83ef2f9101a6bd276ba7657a3"
caseless@~0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7"