Added default_currency and shipping cost fields to supplier admin page.

This commit is contained in:
Jan Böhmer 2019-08-14 15:41:01 +02:00
parent e274d6aa9e
commit 06c6483fd1
6 changed files with 121 additions and 9 deletions

View file

@ -37,6 +37,7 @@ use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Supplier;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\AdminPages\CompanyForm;
use App\Form\AdminPages\SupplierForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
@ -55,7 +56,7 @@ class SupplierController extends BaseAdminController
protected $entity_class = Supplier::class;
protected $twig_template = 'AdminPages/SupplierAdmin.html.twig';
protected $form_class = CompanyForm::class;
protected $form_class = SupplierForm::class;
protected $route_base = "supplier";
/**

View file

@ -102,7 +102,7 @@ class Supplier extends Company
/**
* @var float|null The shipping costs that have to be paid, when ordering via this supplier.
* @ORM\Column(name="shipping_costs", nullable=true, type="decimal")
* @ORM\Column(name="shipping_costs", nullable=true, type="decimal", precision=11, scale=5)
* @Assert\PositiveOrZero()
*/
protected $shipping_costs;
@ -126,18 +126,19 @@ class Supplier extends Company
}
/**
* @return ?float
* @return ?string
*/
public function getShippingCosts() : ?float
public function getShippingCosts() : ?string
{
dump($this);
return $this->shipping_costs;
}
/**
* @param ?float $shipping_costs
* @param ?string $shipping_costs
* @return Supplier
*/
public function setShippingCosts(?float $shipping_costs) : Supplier
public function setShippingCosts(?string $shipping_costs) : Supplier
{
$this->shipping_costs = $shipping_costs;
return $this;

View file

@ -0,0 +1,102 @@
<?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\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Entity\PriceInformations\Currency;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
class SupplierForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$builder->add('address', TextareaType::class, ['label' => 'company.address.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.address.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('phone_number', TelType::class, ['label' => 'company.phone_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.phone_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('fax_number', TelType::class, ['label' => 'company.fax_number.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('email_address', EmailType::class, ['label' => 'company.email.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.email.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('website', UrlType::class, ['label' => 'company.website.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.website.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('auto_product_url', UrlType::class, ['label' => 'company.auto_product_url.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.auto_product_url.placeholder'], 'required' => false,
'empty_data' => ''
]);
$builder->add('default_currency', StructuralEntityType::class, ['class' => Currency::class,
'required' => false, 'label' => 'supplier.default_currency.label', 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('shipping_costs', MoneyType::class, [ 'required' => false,
'currency' => $this->params->get('default_currency'), 'scale' => 3,
'label' => 'supplier.shipping_costs.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)
]);
}
}

View file

@ -51,7 +51,7 @@ final class Version20190812154222 extends AbstractMigration
$this->addSql('ALTER TABLE storelocations ADD storage_type_id INT DEFAULT NULL, ADD only_single_part TINYINT(1) NOT NULL, ADD limit_to_existing_parts TINYINT(1) NOT NULL, ADD not_selectable TINYINT(1) NOT NULL, CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE storelocations ADD CONSTRAINT FK_7517020B270BFF1 FOREIGN KEY (storage_type_id) REFERENCES `measurement_units` (id)');
$this->addSql('CREATE INDEX IDX_7517020B270BFF1 ON storelocations (storage_type_id)');
$this->addSql('ALTER TABLE suppliers ADD default_currency_id INT DEFAULT NULL, ADD shipping_costs NUMERIC(10, 0) DEFAULT NULL, ADD not_selectable TINYINT(1) NOT NULL, CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE suppliers ADD default_currency_id INT DEFAULT NULL, ADD shipping_costs NUMERIC(11, 5) DEFAULT NULL, ADD not_selectable TINYINT(1) NOT NULL, CHANGE parent_id parent_id INT DEFAULT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL, CHANGE last_modified last_modified DATETIME NOT NULL');
$this->addSql('ALTER TABLE suppliers ADD CONSTRAINT FK_AC28B95CECD792C0 FOREIGN KEY (default_currency_id) REFERENCES currencies (id)');
$this->addSql('CREATE INDEX IDX_AC28B95CECD792C0 ON suppliers (default_currency_id)');
$this->addSql('ALTER TABLE parts DROP FOREIGN KEY parts_id_storelocation_fk');