Added an page for editing order informations

This commit is contained in:
Jan Böhmer 2019-08-30 14:25:05 +02:00
parent 1776cd9a77
commit 8c6342bffe
14 changed files with 504 additions and 12 deletions

View file

@ -45,6 +45,7 @@ class CurrencyAdminForm extends BaseEntityAdminForm
$is_new = $entity->getID() === null;
$builder->add('iso_code', CurrencyType::class , ['required' => true,
'required' => false,
'label' => 'currency.iso_code.label',
'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],

View file

@ -0,0 +1,82 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\Part;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Orderdetail;
use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OrderdetailType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('supplierpartnr', TextType::class, [
'required' => false,
'empty_data' => ""
]);
$builder->add('supplier', StructuralEntityType::class, ['class' => Supplier::class, 'disable_not_selectable' => true]);
$builder->add('supplierProductUrl', UrlType::class, [
'required' => false,
'empty_data' => ""
]);
$builder->add('obsolete', CheckboxType::class, [
'required' => false,
'label_attr' => ['class' => 'checkbox-custom']
]);
//Attachment section
$builder->add('priceDetails', CollectionType::class, [
'entry_type' => PricedetailType::class,
'allow_add' => true, 'allow_delete' => true,
'label' => false,
'by_reference' => false
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Orderdetail::class,
'error_bubbling' => false,
]);
}
}

View file

@ -144,6 +144,14 @@ class PartBaseType extends AbstractType
'by_reference' => false
]);
//Attachment section
$builder->add('orderDetails', CollectionType::class, [
'entry_type' => OrderdetailType::class,
'allow_add' => true, 'allow_delete' => true,
'label' => false,
'by_reference' => false,
]);
$builder
//Buttons
->add('save', SubmitType::class, ['label' => 'part.edit.save'])

View file

@ -0,0 +1,62 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\Part;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use App\Form\Type\CurrencyEntityType;
use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PricedetailType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add("minDiscountQuantity", IntegerType::class);
$builder->add("priceRelatedQuantity", IntegerType::class);
$builder->add("price", NumberType::class);
$builder->add("currency", CurrencyEntityType::class, ['required' => false]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Pricedetail::class,
]);
}
}

View file

@ -0,0 +1,118 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\Type;
use App\Entity\Base\StructuralDBElement;
use App\Entity\PriceInformations\Currency;
use App\Services\TreeBuilder;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CurrencyEntityType extends StructuralEntityType
{
protected $base_currency;
public function __construct(EntityManagerInterface $em, TreeBuilder $builder, $base_currency)
{
parent::__construct($em, $builder);
$this->base_currency = $base_currency;
}
public function configureOptions(OptionsResolver $resolver)
{
//Important to call the parent resolver!
parent::configureOptions($resolver);
$resolver->setDefault('class', Currency::class);
$resolver->setDefault('disable_not_selectable', true);
// This options allows you to override the currency shown for the null value
$resolver->setDefault('base_currency', null);
$resolver->setDefault('empty_message', function (Options $options) {
//By default we use the global base currency:
$iso_code = $this->base_currency;
if ($options['base_currency']) { //Allow to override it
$iso_code = $options['base_currency'];
}
return Currencies::getSymbol($iso_code);
});
}
public function generateChoiceLabels(StructuralDBElement $choice, $key, $value): string
{
//Similar to StructuralEntityType, but we use the currency symbol instead if available
/** @var StructuralDBElement|null $parent */
$parent = $this->options['subentities_of'];
/*** @var Currency $choice */
$level = $choice->getLevel();
//If our base entity is not the root level, we need to change the level, to get zero position
if ($this->options['subentities_of'] !== null) {
$level -= $parent->getLevel() - 1;
}
$tmp = str_repeat('&nbsp;&nbsp;&nbsp;', $choice->getLevel()); //Use 3 spaces for intendation
if (empty($choice->getIsoCode())) {
$tmp .= htmlspecialchars($choice->getName());
} else {
$tmp .= Currencies::getSymbol($choice->getIsoCode());
}
return $tmp;
}
protected function generateChoiceAttr(StructuralDBElement $choice, $key, $value) : array
{
/** @var Currency $choice */
$tmp = array();
if (!empty($choice->getIsoCode())) {
//Show the name of the currency
$tmp += ['data-subtext' => $choice->getName()];
}
//Disable attribute if the choice is marked as not selectable
if ($this->options['disable_not_selectable'] && $choice->isNotSelectable()) {
$tmp += ['disabled' => 'disabled'];
}
return $tmp;
}
}

View file

@ -77,14 +77,14 @@ class StructuralEntityType extends AbstractType
function ($value) use ($options){
return $this->transform($value, $options);
}, function ($value) use ($options) {
return $this->reverseTransform($value, $options);
return $this->reverseTransform($value, $options);
}));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(['class']);
$resolver->setDefaults(['attr' => ['class' => 'selectpicker', 'data-live-search' => true],
$resolver->setDefaults([
'show_fullpath_in_subtext' => true, //When this is enabled, the full path will be shown in subtext
'subentities_of' => null, //Only show entities with the given parent class
'disable_not_selectable' => false, //Disable entries with not selectable property
@ -99,6 +99,16 @@ class StructuralEntityType extends AbstractType
return $this->generateChoiceAttr($choice, $key, $value);
}
]);
$resolver->setDefault('empty_message', null);
$resolver->setDefault('attr', function (Options $options) {
$tmp = ['class' => 'selectpicker', 'data-live-search' => true];
if ($options['empty_message']) {
$tmp['data-none-Selected-Text'] = $options['empty_message'];
}
return $tmp;
});
}
protected function generateChoiceAttr(StructuralDBElement $choice, $key, $value) : array
@ -130,7 +140,7 @@ class StructuralEntityType extends AbstractType
$tmp = str_repeat('&nbsp;&nbsp;&nbsp;', $choice->getLevel()); //Use 3 spaces for intendation
$tmp .= htmlspecialchars($choice->getName($parent));
$tmp .= htmlspecialchars($choice->getName());
return $tmp;
}