mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Added an price field to allow defining the price of non-part BOM entries
This commit is contained in:
parent
f62937096f
commit
0e020dab74
7 changed files with 161 additions and 39 deletions
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20221229125204 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE device_parts ADD name VARCHAR(255) DEFAULT NULL, ADD comment LONGTEXT NOT NULL, ADD last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, ADD datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE quantity quantity DOUBLE PRECISION NOT NULL');
|
||||
$this->addSql('ALTER TABLE devices ADD status VARCHAR(64) NOT NULL, ADD description LONGTEXT NOT NULL');
|
||||
$this->addSql('ALTER TABLE parts ADD built_project_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEE8AE70D9 FOREIGN KEY (built_project_id) REFERENCES devices (id)');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FEE8AE70D9 ON parts (built_project_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE devices DROP status, DROP description');
|
||||
$this->addSql('ALTER TABLE device_parts DROP name, DROP comment, DROP last_modified, DROP datetime_added, CHANGE quantity quantity INT NOT NULL');
|
||||
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FEE8AE70D9');
|
||||
$this->addSql('DROP INDEX UNIQ_6940A7FEE8AE70D9 ON `parts`');
|
||||
$this->addSql('ALTER TABLE `parts` DROP built_project_id');
|
||||
}
|
||||
}
|
48
migrations/Version20221231173322.php
Normal file
48
migrations/Version20221231173322.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20221231173322 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE device_parts ADD price_currency_id INT DEFAULT NULL, ADD name VARCHAR(255) DEFAULT NULL, ADD comment LONGTEXT NOT NULL, ADD price NUMERIC(11, 5) DEFAULT NULL COMMENT \'(DC2Type:big_decimal)\', ADD last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, ADD datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE quantity quantity DOUBLE PRECISION NOT NULL');
|
||||
$this->addSql('ALTER TABLE device_parts ADD CONSTRAINT FK_AFC547993FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id)');
|
||||
$this->addSql('CREATE INDEX IDX_AFC547993FFDCD60 ON device_parts (price_currency_id)');
|
||||
$this->addSql('ALTER TABLE devices ADD status VARCHAR(64) DEFAULT NULL, ADD description LONGTEXT NOT NULL');
|
||||
$this->addSql('ALTER TABLE groups CHANGE permissions_data permissions_data LONGTEXT DEFAULT \'[]\' NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||
$this->addSql('ALTER TABLE parts ADD built_project_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEE8AE70D9 FOREIGN KEY (built_project_id) REFERENCES devices (id)');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FEE8AE70D9 ON parts (built_project_id)');
|
||||
$this->addSql('ALTER TABLE users CHANGE permissions_data permissions_data LONGTEXT DEFAULT \'[]\' NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE devices DROP status, DROP description');
|
||||
$this->addSql('ALTER TABLE device_parts DROP FOREIGN KEY FK_AFC547993FFDCD60');
|
||||
$this->addSql('DROP INDEX IDX_AFC547993FFDCD60 ON device_parts');
|
||||
$this->addSql('ALTER TABLE device_parts DROP price_currency_id, DROP name, DROP comment, DROP price, DROP last_modified, DROP datetime_added, CHANGE quantity quantity INT NOT NULL');
|
||||
$this->addSql('ALTER TABLE `groups` CHANGE permissions_data permissions_data LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) NOT NULL');
|
||||
$this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FEE8AE70D9');
|
||||
$this->addSql('DROP INDEX UNIQ_6940A7FEE8AE70D9 ON `parts`');
|
||||
$this->addSql('ALTER TABLE `parts` DROP built_project_id');
|
||||
$this->addSql('ALTER TABLE `users` CHANGE permissions_data permissions_data LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||
}
|
||||
}
|
|
@ -25,6 +25,10 @@ namespace App\Entity\ProjectSystem;
|
|||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Validator\Constraints\BigDecimal\BigDecimalPositive;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
@ -86,6 +90,29 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
*/
|
||||
protected ?Part $part = null;
|
||||
|
||||
/**
|
||||
* @var BigDecimal The price of this non-part BOM entry
|
||||
* @ORM\Column(type="big_decimal", precision=11, scale=5, nullable=true)
|
||||
* @Assert\AtLeastOneOf({
|
||||
* @BigDecimalPositive(),
|
||||
* @Assert\IsNull()
|
||||
* })
|
||||
*/
|
||||
protected ?BigDecimal $price;
|
||||
|
||||
/**
|
||||
* @var ?Currency The currency for the price of this non-part BOM entry
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
|
||||
* @ORM\JoinColumn(nullable=true)
|
||||
* @Selectable()
|
||||
*/
|
||||
protected ?Currency $price_currency = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->price = BigDecimal::zero()->toScale(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
|
@ -196,6 +223,44 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price of this BOM entry, if existing.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
* @return BigDecimal|null
|
||||
*/
|
||||
public function getPrice(): ?BigDecimal
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the price of this BOM entry.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
* @param BigDecimal|null $price
|
||||
*/
|
||||
public function setPrice(?BigDecimal $price): void
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Currency|null
|
||||
*/
|
||||
public function getPriceCurrency(): ?Currency
|
||||
{
|
||||
return $this->price_currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Currency|null $price_currency
|
||||
*/
|
||||
public function setPriceCurrency(?Currency $price_currency): void
|
||||
{
|
||||
$this->price_currency = $price_currency;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Assert\Callback
|
||||
*/
|
||||
|
@ -231,6 +296,13 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
->addViolation();
|
||||
}
|
||||
|
||||
//Prices are only only allowed on non-part BOM entries
|
||||
if ($this->part !== null && $this->price !== null) {
|
||||
$context->buildViolation('project.bom_entry.price_not_allowed_on_parts')
|
||||
->atPath('price')
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
//Check that the part is not the build representation part of this device or one of its parents
|
||||
if ($this->part && $this->part->getBuiltProject() !== null) {
|
||||
//Get the associated project
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace App\Form\ProjectSystem;
|
|||
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||
use App\Form\Type\BigDecimalNumberType;
|
||||
use App\Form\Type\CurrencyEntityType;
|
||||
use App\Form\Type\PartSelectType;
|
||||
use App\Form\Type\RichTextEditorType;
|
||||
use App\Form\Type\SIUnitType;
|
||||
|
@ -63,6 +65,22 @@ class ProjectBOMEntryType extends AbstractType
|
|||
'rows' => 2,
|
||||
],
|
||||
])
|
||||
->add('price', BigDecimalNumberType::class, [
|
||||
'label' => false,
|
||||
'required' => false,
|
||||
'scale' => 5,
|
||||
'html5' => true,
|
||||
'attr' => [
|
||||
'min' => 0,
|
||||
'step' => 'any',
|
||||
],
|
||||
])
|
||||
->add('priceCurrency', CurrencyEntityType::class, [
|
||||
'required' => false,
|
||||
'label' => false,
|
||||
'short' => true,
|
||||
])
|
||||
|
||||
;
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,17 @@
|
|||
<td colspan="5" class="accordion-body collapse" id="{{ target_id }}">
|
||||
<div class="">
|
||||
{{ form_row(form.mountnames) }}
|
||||
<div class="row mb-2">
|
||||
<label class="col-form-label col-sm-3">{% trans %}project.bom.price{% endtrans %}</label>
|
||||
<div class="col-sm-9">
|
||||
<div class="input-group">
|
||||
{{ form_widget(form.price) }}
|
||||
{{ form_widget(form.priceCurrency, {'attr': {'class': 'selectpicker', 'data-controller': 'elements--selectpicker'}}) }}
|
||||
</div>
|
||||
{{ form_errors(form.price) }}
|
||||
{{ form_errors(form.priceCurrency) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ form_row(form.comment) }}
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -10127,5 +10127,11 @@ Element 3</target>
|
|||
<target>Subprojects</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="CTIbEF6" name="project.bom.price">
|
||||
<segment>
|
||||
<source>project.bom.price</source>
|
||||
<target>Price</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
|
@ -275,5 +275,11 @@
|
|||
<target>The project BOM has to include all subprojects builds parts. Part %part_name% of project %project_name% missing!</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="U9b1EzD" name="project.bom_entry.price_not_allowed_on_parts">
|
||||
<segment>
|
||||
<source>project.bom_entry.price_not_allowed_on_parts</source>
|
||||
<target>Prices are not allowed on BOM entries associated with a part. Define the price on the part instead.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue