Browse Source

Correctif backoffice

master
Fab 4 years ago
parent
commit
8ebfb1a2bd
12 changed files with 75 additions and 76 deletions
  1. +1
    -1
      ShopBundle/Controller/Admin/AdminController.php
  2. +10
    -9
      ShopBundle/Controller/Admin/ProductFamilyController.php
  3. +9
    -15
      ShopBundle/Form/ProductType.php
  4. +7
    -6
      ShopBundle/Model/SortableTrait.php
  5. +14
    -0
      ShopBundle/Resources/public/js/backend/script/default/init-common.js
  6. +0
    -13
      ShopBundle/Resources/public/js/backend/script/default/init-edit.js
  7. +2
    -1
      ShopBundle/Resources/public/js/backend/script/default/init-list.js
  8. +2
    -1
      ShopBundle/Resources/public/js/backend/script/default/vuejs-mixins.js
  9. +13
    -10
      ShopBundle/Resources/public/js/backend/script/productfamily/vuejs-product-family.js
  10. +2
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  11. +7
    -2
      ShopBundle/Resources/views/backend/default/list.html.twig
  12. +8
    -17
      ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig

+ 1
- 1
ShopBundle/Controller/Admin/AdminController.php View File



$fields = $this->entity['list']['fields']; $fields = $this->entity['list']['fields'];
$paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']); $paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']);
dump($paginator->getCurrentPageResults());
$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]); $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);


$positionForm = $this->createFormBuilder(array('entities', $paginator->getCurrentPageResults())) $positionForm = $this->createFormBuilder(array('entities', $paginator->getCurrentPageResults()))

+ 10
- 9
ShopBundle/Controller/Admin/ProductFamilyController.php View File

{ {
$productFamilyRequest = $this->request->request->get('productfamily'); $productFamilyRequest = $this->request->request->get('productfamily');


$taxRateId = intval($productFamilyRequest['taxRate']);
if ($taxRateId > 0) {
$repo = $this->em->getRepository(TaxRateInterface::class);
$entity->setTaxRate($repo->find($taxRateId));
if(isset($productFamilyRequest['taxRate'])) {
$taxRateId = intval($productFamilyRequest['taxRate']);
if ($taxRateId > 0) {
$repo = $this->em->getRepository(TaxRateInterface::class);
$entity->setTaxRate($repo->find($taxRateId));
}
} }


$unitId = intval($productFamilyRequest['unit']); $unitId = intval($productFamilyRequest['unit']);


protected function processProducts($entity) protected function processProducts($entity)
{ {
$repo = $this->em->getRepository(UnitInterface::class);
//si il existe un et un seul produit pour ce product family n'ajoute rien supprime rien //si il existe un et un seul produit pour ce product family n'ajoute rien supprime rien
if (count($entity->getProducts()) == 0) { if (count($entity->getProducts()) == 0) {
$product = new Product(); $product = new Product();
$product->setCreatedBy($this->getUser());
$product->setUpdatedBy($this->getUser());
$product->setProductFamily($entity); $product->setProductFamily($entity);
$this->em->persist($product); $this->em->persist($product);


$entity->addProduct($product); $entity->addProduct($product);
} else { } else {


foreach ($entity->getProducts() as $product) {
foreach ($entity->getProducts() as $i=>$product) {

$product->setProductFamily($entity); $product->setProductFamily($entity);
$product->setCreatedBy($this->getUser());
$product->setUpdatedBy($this->getUser());
$this->em->persist($product); $this->em->persist($product);
$entity->addProduct($product); $entity->addProduct($product);


// die('ncici'); // die('ncici');
} }
} }

} }


protected function processCategories(ProductFamilyInterface $entity) protected function processCategories(ProductFamilyInterface $entity)

+ 9
- 15
ShopBundle/Form/ProductType.php View File

use Lc\ShopBundle\Context\TaxRateInterface; use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Context\UnitInterface; use Lc\ShopBundle\Context\UnitInterface;
use Lc\ShopBundle\Services\Utils; use Lc\ShopBundle\Services\Utils;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\DateType;
protected $em; protected $em;
protected $utils; protected $utils;



public function __construct(EntityManagerInterface $entityManager, Utils $utils) public function __construct(EntityManagerInterface $entityManager, Utils $utils)
{ {
$this->em = $entityManager; $this->em = $entityManager;
] ]
)); ));



$this->choicesUnitsReference = [];
$unitClass = $this->em->getClassMetadata(UnitInterface::class)->getName(); $unitClass = $this->em->getClassMetadata(UnitInterface::class)->getName();
foreach ($this->em->getRepository($unitClass)->findAll() as $unit) {
$choicesUnits[$unit->getWording()] = $unit->getId();
$this->choicesUnitsReference[$unit->getId()]['unit-reference'] = $unit->getUnitReference();
$this->choicesUnitsReference[$unit->getId()]['coefficient'] = $unit->getCoefficient();
}

$builder->add('unit', ChoiceType::class, array(
'label' => 'TVA du fournisseur',
'choices' => $choicesUnits,

$builder->add('unit', EntityType::class, array(
'class'=> $unitClass,
'data' => 0, 'data' => 0,
'required'=>false, 'required'=>false,
'mapped' => false,
'choice_attr' => function ($choice, $key, $value) {
'choice_attr' => function ($choice) {
dump($choice);
return [ return [
'data-unit-reference' => $this->choicesUnitsReference[$choice]['unit-reference'],
'data-coefficient' => $this->choicesUnitsReference[$choice]['coefficient']
'data-unit-reference' => $choice->getUnitReference(),
'data-coefficient' => $choice->getCoefficient()
]; ];
}, },
)); ));

+ 7
- 6
ShopBundle/Model/SortableTrait.php View File



use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Mapping\Annotation as Gedmo;
use phpDocumentor\Reflection\Types\Integer;


trait SortableTrait trait SortableTrait
{ {
/** /**
* @var string * @var string
* @ORM\Column(type="string")
* @ORM\Column(type="integer")
*/ */
protected $position = 0; protected $position = 0;


/** /**
* @return string
* @return int
*/ */
public function getPosition(): string
public function getPosition(): int
{ {
return $this->position; return $this->position;
} }


/** /**
* @param string $position
* @param int $position
* @return $this * @return $this
*/ */
public function setPosition(string $position): self
public function setPosition(int $position): self
{ {
$this->position = $position; $this->position = $position;
return $this; return $this;
} }
}
}

+ 14
- 0
ShopBundle/Resources/public/js/backend/script/default/init-common.js View File

return myselect; return myselect;
} }
} }

function checkForm(){
$('form').addClass('form-sent');
//Panel vues js
if($('form').find('.panel').length){
$('form').find('.panel').each(function(i, panel){
if($(panel).find(':invalid').length){
$('#nav-params').find('.nav-item:eq('+i+')').addClass('has-invalid');
}else{
$('#nav-params').find('.nav-item:eq('+i+')').removeClass('has-invalid');
}
})
}
}

+ 0
- 13
ShopBundle/Resources/public/js/backend/script/default/init-edit.js View File

}); });
}); });


function checkForm(){
$('form').addClass('form-sent');
//Panel vues js
if($('form').find('.panel').length){
$('form').find('.panel').each(function(i, panel){
if($(panel).find(':invalid').length){
$('#nav-params').find('.nav-item:eq('+i+')').addClass('has-invalid');
}else{
$('#nav-params').find('.nav-item:eq('+i+')').removeClass('has-invalid');
}
})
}
}


/* CKEditor */ /* CKEditor */



+ 2
- 1
ShopBundle/Resources/public/js/backend/script/default/init-list.js View File

$(this).html('') $(this).html('')
} }
}); });
log();
var table = $(".table.datatable-simple").DataTable({ var table = $(".table.datatable-simple").DataTable({
orderCellsTop: true, orderCellsTop: true,
order: [[$('th.sorted').data('index'), 'asc']],
fixedHeader: { fixedHeader: {
header: true, header: true,
headerOffset: $('.main-header').outerHeight(), headerOffset: $('.main-header').outerHeight(),

+ 2
- 1
ShopBundle/Resources/public/js/backend/script/default/vuejs-mixins.js View File

this.priceUpdate('price'); this.priceUpdate('price');
}, },
setMultiplyingFactor: function () { setMultiplyingFactor: function () {
log('SETFACTOR')
if (this.priceWithTax && this.buyingPrice) { if (this.priceWithTax && this.buyingPrice) {
this.multiplyingFactor = parseFloat(this.priceWithTaxValue / this.buyingPriceValue).toFixed(3); this.multiplyingFactor = parseFloat(this.priceWithTaxValue / this.buyingPriceValue).toFixed(3);
} }
}, },
priceByRefUnitUpdate: function () { priceByRefUnitUpdate: function () {

if (this.unitCoefficient && this.quantityValue) { if (this.unitCoefficient && this.quantityValue) {
this.priceByRefUnit = parseFloat((this.priceValue / this.quantityValue) * this.unitCoefficient).toFixed(2); this.priceByRefUnit = parseFloat((this.priceValue / this.quantityValue) * this.unitCoefficient).toFixed(2);
this.priceByRefUnitWithTax = parseFloat((this.priceWithTaxValue / this.quantityValue) * this.unitCoefficient).toFixed(2); this.priceByRefUnitWithTax = parseFloat((this.priceWithTaxValue / this.quantityValue) * this.unitCoefficient).toFixed(2);

+ 13
- 10
ShopBundle/Resources/public/js/backend/script/productfamily/vuejs-product-family.js View File

else return this.productFamily.unit; else return this.productFamily.unit;
}, },
propertyExpirationDateFormated: function () { propertyExpirationDateFormated: function () {
log(this.propertyExpirationDate)
log(this.productFamily.propertyExpirationDate)

if (this.propertyExpirationDate) return getDateFormatted(this.propertyExpirationDate, '-') if (this.propertyExpirationDate) return getDateFormatted(this.propertyExpirationDate, '-')
else return getDateFormatted(this.productFamily.propertyExpirationDate, '-') else return getDateFormatted(this.productFamily.propertyExpirationDate, '-')
} }
}, window.productForm[this.keyForm]) }, window.productForm[this.keyForm])
}, },
mounted: function () { mounted: function () {
//INIT VAR
//INIT VAR
updateSortableProducts(); updateSortableProducts();


$(this.$el).find('select').each(function (i, select) { $(this.$el).find('select').each(function (i, select) {
log($(select).parents('td'));
setSelect2($(select)); setSelect2($(select));
}); });


this.updateProductView(); this.updateProductView();
}, },
methods: { methods: {
updateLine: function(){
this.changePriceWithTax();
this.changeBuyingPriceWithTax();
},
updateProductForm: function () { updateProductForm: function () {

this.changePriceWithTax(); this.changePriceWithTax();
this.changeBuyingPriceWithTax(); this.changeBuyingPriceWithTax();
//EDIT UNIT //EDIT UNIT


updateProductView: function () { updateProductView: function () {


if (this.unitValue == 'piece') {

/*if (this.unitValue == 'piece') {
$('.priceByRefUnit').hide(); $('.priceByRefUnit').hide();
} else { } else {
$('.priceByRefUnit').show(); $('.priceByRefUnit').show();
} else { } else {
$('.products-collection-table').find('.stock').show(); $('.products-collection-table').find('.stock').show();
$('#product-item-' + this.keyForm).find('.stock').html(this.availableQuantity + ' / ' + this.unitReference); $('#product-item-' + this.keyForm).find('.stock').html(this.availableQuantity + ' / ' + this.unitReference);
}
}*/
}, },
saveProductForm: function () { saveProductForm: function () {
this.updateProductView(); this.updateProductView();
}, },
}, },
watch: { watch: {
titleInherited: function (val) {
/*titleInherited: function (val) {

if (val) this.title = null; if (val) this.title = null;
}, },
unitInherited: function (val) { unitInherited: function (val) {
}, },
priceInherited: function (val) { priceInherited: function (val) {
if (val) this.price = null; if (val) this.price = null;
},
},*/
} }
}); });



+ 2
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml View File

taxRate: Règle de taxe taxRate: Règle de taxe
value: Valeur value: Valeur
behaviorAddToCart: Ajout au panier behaviorAddToCart: Ajout au panier

Supplier:
user: Utilisateur lié
ProductFamily: ProductFamily:
taxRateInherited: Utiliser la TVA par défaut taxRateInherited: Utiliser la TVA par défaut
activeProducts: Activer les déclinaisons activeProducts: Activer les déclinaisons

+ 7
- 2
ShopBundle/Resources/views/backend/default/list.html.twig View File

{% block table_head %} {% block table_head %}


<tr> <tr>
{% set i=0 %}
{% if _has_batch_actions %} {% if _has_batch_actions %}
<th width="1px"><span><input type="checkbox" class="form-batch-checkbox-all"></span></th>
<th data-index="{{ i }}" width="1px"><span><input type="checkbox" class="form-batch-checkbox-all"></span></th>
{% set i=1 %}
{% endif %} {% endif %}


{% for field, metadata in _fields_visible_by_user %} {% for field, metadata in _fields_visible_by_user %}

{% set isSortingField = (metadata.property == app.request.get('sortField')) or ('association' == metadata.type and app.request.get('sortField') starts with metadata.property ~ '.') %} {% set isSortingField = (metadata.property == app.request.get('sortField')) or ('association' == metadata.type and app.request.get('sortField') starts with metadata.property ~ '.') %}
{% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'DESC' %} {% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'DESC' %}
{% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %} {% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
{% endif %} {% endif %}


{#<th class="{{ isSortingField ? 'sorted' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" >#} {#<th class="{{ isSortingField ? 'sorted' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" >#}
<th data-searchable="{{ searchable }}" >
<th data-index="{{ i }}" class="{{ isSortingField ? 'sorted' }}" data-searchable="{{ searchable }}" >

{% if metadata.sortable %} {% if metadata.sortable %}
{{ metadata.fieldName|lc_trad(_entity_config['name']) }} {{ metadata.fieldName|lc_trad(_entity_config['name']) }}
{% else %} {% else %}
<span>{{ metadata.fieldName|lc_trad(_entity_config['name']) }}</span> <span>{{ metadata.fieldName|lc_trad(_entity_config['name']) }}</span>
{% endif %} {% endif %}
</th> </th>
{% set i= i +1 %}
{% endfor %} {% endfor %}


{% if _list_item_actions|length > 0 %} {% if _list_item_actions|length > 0 %}

+ 8
- 17
ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig View File

</div> </div>
</div> </div>
<div v-show="quantityInherited == true"> <div v-show="quantityInherited == true">
{{ form_widget(product.quantity, {'attr' : {'v-model' : 'quantity', 'v-on:focusout': 'quantityInherited = false'}}) }}
{{ form_widget(product.quantity, {'attr' : {'v-model' : 'quantity', 'v-on:focusout': 'quantityInherited = false', '@change' : 'updateLine'}}) }}
</div> </div>
</td> </td>


</div> </div>
</div> </div>
<div v-show="unitInherited == true"> <div v-show="unitInherited == true">
{{ form_widget(product.unit, {'attr' : {'v-model' : 'unit', 'v-on:focusout': 'unitInherited = false'}}) }}
{{ form_widget(product.unit, {'attr' : {'v-model' : 'unit', 'v-on:focusout': 'unitInherited = false', '@change' : 'updateLine'}}) }}
</div> </div>
</td> </td>


</div> </div>
</td> </td>


<td colspan="2" class="priceByRefUnit">
<div v-if="priceByRefUnit">
{# <td colspan="2" class="priceByRefUnit">
{% verbatim %}{{ priceByRefUnit }}€{% endverbatim %} {% verbatim %}{{ priceByRefUnit }}€{% endverbatim %}
</div>
<div v-else class="inherited">
{% verbatim %}{{ productFamily.priceByRefUnit }}€{% endverbatim %}
</div>
</td> </td>
<td colspan="2" class="priceByRefUnit priceByRefUnitWithTax"> <td colspan="2" class="priceByRefUnit priceByRefUnitWithTax">
<div v-if="priceByRefUnitWithTax">
{% verbatim %}{{ priceByRefUnitWithTax }}€{% endverbatim %} {% verbatim %}{{ priceByRefUnitWithTax }}€{% endverbatim %}
</div>
<div v-else class="inherited">
{% verbatim %}{{ productFamily.priceByRefUnitWithTax }}€{% endverbatim %}
</div>
</td>
</td>#}




<td v-show="productFamily.behaviorCountStock== 'by-product'" class="stock availableQuantity " v-on:click="availableQuantityInherited = true"> <td v-show="productFamily.behaviorCountStock== 'by-product'" class="stock availableQuantity " v-on:click="availableQuantityInherited = true">
<th colspan="2" class="price"> <th colspan="2" class="price">
PV TTC PV TTC
</th> </th>
<th colspan="2" class="priceByRefUnit">
{# <th colspan="2" class="priceByRefUnit">
PV HT / ${ getUnitReference() } PV HT / ${ getUnitReference() }
</th> </th>
<th colspan="2" class="priceByRefUnit"> <th colspan="2" class="priceByRefUnit">
PV TTC / ${ getUnitReference() } PV TTC / ${ getUnitReference() }
</th>
</th>#}


<th v-show="behaviorCountStock== 'by-product'"> <th v-show="behaviorCountStock== 'by-product'">
Stock Stock
window.productForm[{{ keyForm }}] = { window.productForm[{{ keyForm }}] = {
{% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %} {% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %}
{% if product.vars.value.quantity %}quantity: "{{ product.vars.value.quantity }}",{% endif %} {% if product.vars.value.quantity %}quantity: "{{ product.vars.value.quantity }}",{% endif %}
{% if product.vars.value.unit %}unit: "{{ product.vars.value.unit }}",{% endif %}
{% if product.vars.value.unit %}unit: {{ product.vars.value.unit.id }},{% endif %}
{% if product.vars.value.buyingPrice %}buyingPrice: "{{ product.vars.value.buyingPrice }}",{% endif %} {% if product.vars.value.buyingPrice %}buyingPrice: "{{ product.vars.value.buyingPrice }}",{% endif %}
{% if product.vars.value.price %}price: parseFloat({{ product.vars.value.price }}).toFixed(3),{% endif %} {% if product.vars.value.price %}price: parseFloat({{ product.vars.value.price }}).toFixed(3),{% endif %}
{% if product.vars.value.availableQuantity %}availableQuantity: parseInt({{ product.vars.value.availableQuantity }}),{% endif %} {% if product.vars.value.availableQuantity %}availableQuantity: parseInt({{ product.vars.value.availableQuantity }}),{% endif %}
}; };
window.formProductTemplate[{{ keyForm }}] = '{{ formMacros.printProductRow(product)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; window.formProductTemplate[{{ keyForm }}] = '{{ formMacros.printProductRow(product)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}';
{% endfor %} {% endfor %}

</script> </script>



Loading…
Cancel
Save