use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Container\Product\ProductContainer; | |||||
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface; | ||||
class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface | class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface | ||||
{ | { | ||||
protected $em; | |||||
protected $adminUrlGenerator; | |||||
protected EntityManagerInterface $em; | |||||
protected ProductFamilyContainer $productFamilyContainer; | |||||
protected ProductContainer $productContainer; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
public function __construct(EntityManagerInterface $entityManager, ProductFamilyContainer $productFamilyContainer, ProductContainer $productContainer) | |||||
{ | { | ||||
$this->em = $entityManager; | $this->em = $entityManager; | ||||
$this->productFamilyContainer = $productFamilyContainer; | |||||
$this->productContainer = $productContainer; | |||||
} | } | ||||
public static function getSubscribedEvents() | public static function getSubscribedEvents() | ||||
{ | { | ||||
return [ | return [ | ||||
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamily'], | |||||
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamily'], | |||||
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamily'], | |||||
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamily'], | |||||
]; | ]; | ||||
} | } | ||||
public function processBeforePersistProductFamily(EntityManagerEvent $event) | public function processBeforePersistProductFamily(EntityManagerEvent $event) | ||||
{ | { | ||||
$entity = $event->getEntity(); | $entity = $event->getEntity(); | ||||
if($entity instanceof ProductFamilyInterface) { | |||||
if ($entity instanceof ProductFamilyInterface) { | |||||
$this->processProducts($entity); | $this->processProducts($entity); | ||||
$this->processPrice($entity); | $this->processPrice($entity); | ||||
$this->processReductionCatalog($entity); | $this->processReductionCatalog($entity); | ||||
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) { | if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) { | ||||
//$reductionCatalog->setSection($entity->getSection()); | //$reductionCatalog->setSection($entity->getSection()); | ||||
$reductionCatalog->setProductFamily($entity); | $reductionCatalog->setProductFamily($entity); | ||||
if(is_null($reductionCatalog->getId())) { | |||||
if (is_null($reductionCatalog->getId())) { | |||||
$this->em->create($reductionCatalog); | $this->em->create($reductionCatalog); | ||||
}else { | |||||
} else { | |||||
$this->em->update($reductionCatalog); | $this->em->update($reductionCatalog); | ||||
} | } | ||||
} | } | ||||
//Récupère le product origin | //Récupère le product origin | ||||
$originProducts = $this->em->getRepository(ProductInterface::class) | $originProducts = $this->em->getRepository(ProductInterface::class) | ||||
->findBy( | |||||
array( | |||||
'productFamily' => $entity->getId(), | |||||
'originProduct' => true, | |||||
) | |||||
); | |||||
->findBy( | |||||
array( | |||||
'productFamily' => $entity->getId(), | |||||
'originProduct' => true, | |||||
) | |||||
); | |||||
if (count($originProducts) > 1) { | if (count($originProducts) > 1) { | ||||
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab'); | throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab'); | ||||
if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) { | if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) { | ||||
$product->setTitle( | $product->setTitle( | ||||
str_replace('.', ',', $product->getQuantityInherited()).$product->getUnitInherited( | |||||
)->getWording() | |||||
str_replace('.', ',', $this->productContainer->getSolver()->getQuantityInherited($product)) . $this->productContainer->getSolver()->getUnitInherited($product)->getWording() | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* protected function processCategories(ProductFamilyInterface $entity) | |||||
{ | |||||
$productCategoryRepository = $this->em->getRepository(ProductCategoryInterface::class); | |||||
$productCategories = $entity->getProductCategories(); | |||||
$entity->initProductCategories(); | |||||
foreach ($productCategories as $key => $bool) { | |||||
if (is_bool($bool) && $bool) { | |||||
if (strpos($key, 'category_children_') !== false) { | |||||
$idCategory = (int)str_replace('category_children_', '', $key); | |||||
} else { | |||||
$idCategory = (int)str_replace('category_', '', $key); | |||||
} | |||||
$category = $productCategoryRepository->find($idCategory); | |||||
$entity->addProductCategory($category); | |||||
} | |||||
} | |||||
}*/ | |||||
/* protected function processCategories(ProductFamilyInterface $entity) | |||||
{ | |||||
$productCategoryRepository = $this->em->getRepository(ProductCategoryInterface::class); | |||||
$productCategories = $entity->getProductCategories(); | |||||
$entity->initProductCategories(); | |||||
foreach ($productCategories as $key => $bool) { | |||||
if (is_bool($bool) && $bool) { | |||||
if (strpos($key, 'category_children_') !== false) { | |||||
$idCategory = (int)str_replace('category_children_', '', $key); | |||||
} else { | |||||
$idCategory = (int)str_replace('category_', '', $key); | |||||
} | |||||
$category = $productCategoryRepository->find($idCategory); | |||||
$entity->addProductCategory($category); | |||||
} | |||||
} | |||||
}*/ | |||||
} | } |
namespace Lc\CaracoleBundle\Model\Product; | namespace Lc\CaracoleBundle\Model\Product; | ||||
/** | |||||
* @ORM\MappedSuperclass() | |||||
*/ | |||||
interface ProductFamilyInterface | interface ProductFamilyInterface | ||||
{ | { | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
/** | |||||
* @ORM\MappedSuperclass() | |||||
*/ | |||||
interface ProductInterface | interface ProductInterface | ||||
{ | { | ||||
jQuery(document).ready(function () { | |||||
initBtnShowTotalOrderProduct(); | |||||
}); | |||||
function initBtnShowTotalOrderProduct(){ | |||||
$('.lc-show-products-sales-statistic').unbind('click').on('click', function (){ | |||||
$btn = $(this); | |||||
var url = $(this).data('url'); | |||||
$('#modal-products-sales-statistic').remove(); | |||||
$.ajax({ | |||||
url: url, | |||||
method: "POST", | |||||
dataType: "json", | |||||
success: function (response) { | |||||
$('body').append(response.data); | |||||
$('#modal-products-sales-statistic').modal('show'); | |||||
initModalProductsSalesStatistic(response.statistics); | |||||
} | |||||
}); | |||||
}); | |||||
} | |||||
function initModalProductsSalesStatistic(statistics) { | |||||
var chart = null; | |||||
$('.btn-products-sales-statistic').off('click'); | |||||
$('.btn-products-sales-statistic').on('click', function () { | |||||
$('.table-products-sales-statistic').hide(); | |||||
$('.btn-products-sales-statistic').addClass('btn-secondary').removeClass('btn-primary'); | |||||
$(this).removeClass('btn-secondary').addClass('btn-primary'); | |||||
$('#table-products-sales-statistic-'+$(this).data('property-name')).show() | |||||
if (chart) chart.destroy(); | |||||
$(this).removeClass('btn-secondary'); | |||||
chart = drawProductsSalesStatistic(statistics,$(this).data('property-name')) | |||||
}); | |||||
$('.btn-products-sales-statistic').first().click(); | |||||
} | |||||
import { CaracStatistics } from '../../../functions/statistic.js'; | |||||
global.CaracStatistics = CaracStatistics; | |||||
function drawProductsSalesStatistic(statictics, propertyName) { | |||||
var options = { | |||||
bezierCurve : false, | |||||
tooltips: { | |||||
callbacks: { | |||||
label: (item) => item.yLabel , | |||||
}, | |||||
}, | |||||
}; | |||||
chart = new Chart(document.getElementById("chart"), { | |||||
"type": "line", | |||||
"data": { | |||||
"labels": Object.values(statictics.label), | |||||
"datasets": [{ | |||||
"label": "Vente de produits / semaine", | |||||
"data": Object.values(statictics.data[propertyName].data), | |||||
"fill": false, | |||||
"borderColor": "rgb(75, 192, 192)", | |||||
"lineTension": 0.1 | |||||
}] | |||||
}, | |||||
"options": options | |||||
}); | |||||
return chart; | |||||
} | |||||
jQuery(document).ready(function () { | |||||
CaracStatistics.initBtnShowTotalOrderProduct(); | |||||
}); | |||||
// | |||||
// function initBtnShowTotalOrderProduct(){ | |||||
// $('.lc-show-products-sales-statistic').unbind('click').on('click', function (){ | |||||
// $btn = $(this); | |||||
// var url = $(this).data('url'); | |||||
// $('#modal-products-sales-statistic').remove(); | |||||
// $.ajax({ | |||||
// url: url, | |||||
// method: "POST", | |||||
// dataType: "json", | |||||
// success: function (response) { | |||||
// $('body').append(response.data); | |||||
// $('#modal-products-sales-statistic').modal('show'); | |||||
// initModalProductsSalesStatistic(response.statistics); | |||||
// } | |||||
// }); | |||||
// }); | |||||
// } | |||||
// function initModalProductsSalesStatistic(statistics) { | |||||
// var chart = null; | |||||
// $('.btn-products-sales-statistic').off('click'); | |||||
// $('.btn-products-sales-statistic').on('click', function () { | |||||
// $('.table-products-sales-statistic').hide(); | |||||
// $('.btn-products-sales-statistic').addClass('btn-secondary').removeClass('btn-primary'); | |||||
// $(this).removeClass('btn-secondary').addClass('btn-primary'); | |||||
// | |||||
// $('#table-products-sales-statistic-'+$(this).data('property-name')).show() | |||||
// if (chart) chart.destroy(); | |||||
// $(this).removeClass('btn-secondary'); | |||||
// chart = drawProductsSalesStatistic(statistics,$(this).data('property-name')) | |||||
// }); | |||||
// $('.btn-products-sales-statistic').first().click(); | |||||
// | |||||
// } | |||||
// | |||||
// function drawProductsSalesStatistic(statictics, propertyName) { | |||||
// | |||||
// var options = { | |||||
// bezierCurve : false, | |||||
// tooltips: { | |||||
// callbacks: { | |||||
// label: (item) => item.yLabel , | |||||
// }, | |||||
// }, | |||||
// }; | |||||
// | |||||
// chart = new Chart(document.getElementById("chart"), { | |||||
// "type": "line", | |||||
// "data": { | |||||
// "labels": Object.values(statictics.label), | |||||
// "datasets": [{ | |||||
// "label": "Vente de produits / semaine", | |||||
// "data": Object.values(statictics.data[propertyName].data), | |||||
// "fill": false, | |||||
// "borderColor": "rgb(75, 192, 192)", | |||||
// "lineTension": 0.1 | |||||
// }] | |||||
// }, | |||||
// "options": options | |||||
// }); | |||||
// return chart; | |||||
// } |
export class CaracStatistics { | |||||
static initBtnShowTotalOrderProduct(){ | |||||
$('.lc-show-products-sales-statistic').unbind('click').on('click', function (){ | |||||
$btn = $(this); | |||||
var url = $(this).data('url'); | |||||
$('#modal-products-sales-statistic').remove(); | |||||
$.ajax({ | |||||
url: url, | |||||
method: "POST", | |||||
dataType: "json", | |||||
success: function (response) { | |||||
$('body').append(response.data); | |||||
$('#modal-products-sales-statistic').modal('show'); | |||||
initModalProductsSalesStatistic(response.statistics); | |||||
} | |||||
}); | |||||
}); | |||||
} | |||||
static initModalProductsSalesStatistic(statistics) { | |||||
var chart = null; | |||||
$('.btn-products-sales-statistic').off('click'); | |||||
$('.btn-products-sales-statistic').on('click', function () { | |||||
$('.table-products-sales-statistic').hide(); | |||||
$('.btn-products-sales-statistic').addClass('btn-secondary').removeClass('btn-primary'); | |||||
$(this).removeClass('btn-secondary').addClass('btn-primary'); | |||||
$('#table-products-sales-statistic-'+$(this).data('property-name')).show() | |||||
if (chart) chart.destroy(); | |||||
$(this).removeClass('btn-secondary'); | |||||
chart = drawProductsSalesStatistic(statistics,$(this).data('property-name')) | |||||
}); | |||||
$('.btn-products-sales-statistic').first().click(); | |||||
} | |||||
static drawProductsSalesStatistic(statictics, propertyName) { | |||||
var options = { | |||||
bezierCurve : false, | |||||
tooltips: { | |||||
callbacks: { | |||||
label: (item) => item.yLabel , | |||||
}, | |||||
}, | |||||
}; | |||||
chart = new Chart(document.getElementById("chart"), { | |||||
"type": "line", | |||||
"data": { | |||||
"labels": Object.values(statictics.label), | |||||
"datasets": [{ | |||||
"label": "Vente de produits / semaine", | |||||
"data": Object.values(statictics.data[propertyName].data), | |||||
"fill": false, | |||||
"borderColor": "rgb(75, 192, 192)", | |||||
"lineTension": 0.1 | |||||
}] | |||||
}, | |||||
"options": options | |||||
}); | |||||
return chart; | |||||
} | |||||
} |