2020-02-09 22:10:29 +01:00
|
|
|
<?php
|
2022-11-29 21:21:26 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 - 2022 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 Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-03-15 13:56:31 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-02-09 22:10:29 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-09 22:10:29 +01:00
|
|
|
*
|
2020-02-22 18:14:36 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-02-09 22:10:29 +01:00
|
|
|
*
|
|
|
|
* 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
|
2020-02-22 18:14:36 +01:00
|
|
|
* GNU Affero General Public License for more details.
|
2020-02-09 22:10:29 +01:00
|
|
|
*
|
2020-02-22 18:14:36 +01:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-02-09 22:10:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
|
|
|
|
use App\Entity\Attachments\AttachmentType;
|
|
|
|
use App\Entity\Attachments\PartAttachment;
|
|
|
|
use App\Entity\Parts\Category;
|
|
|
|
use App\Entity\Parts\Footprint;
|
|
|
|
use App\Entity\Parts\Manufacturer;
|
2023-07-17 00:34:00 +02:00
|
|
|
use App\Entity\Parts\ManufacturingStatus;
|
2020-02-09 22:10:29 +01:00
|
|
|
use App\Entity\Parts\Part;
|
|
|
|
use App\Entity\Parts\PartLot;
|
2023-09-04 22:57:40 +02:00
|
|
|
use App\Entity\Parts\StorageLocation;
|
2020-02-09 22:10:29 +01:00
|
|
|
use App\Entity\Parts\Supplier;
|
|
|
|
use App\Entity\PriceInformations\Orderdetail;
|
|
|
|
use App\Entity\PriceInformations\Pricedetail;
|
2020-05-21 13:46:17 +02:00
|
|
|
use Brick\Math\BigDecimal;
|
2022-08-14 19:32:53 +02:00
|
|
|
use DateTime;
|
2020-02-09 22:10:29 +01:00
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
2023-06-18 22:06:42 +02:00
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
2020-02-09 22:10:29 +01:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
|
|
|
|
2023-06-18 22:06:42 +02:00
|
|
|
class PartFixtures extends Fixture implements DependentFixtureInterface
|
2020-02-09 22:10:29 +01:00
|
|
|
{
|
2023-06-11 14:15:46 +02:00
|
|
|
public function __construct(protected EntityManagerInterface $em)
|
2020-02-09 22:10:29 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-15 13:56:31 +01:00
|
|
|
public function load(ObjectManager $manager): void
|
2020-02-09 22:10:29 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
/** Simple part */
|
|
|
|
$part = new Part();
|
|
|
|
$part->setName('Part 1');
|
|
|
|
$part->setCategory($manager->find(Category::class, 1));
|
|
|
|
$manager->persist($part);
|
|
|
|
|
|
|
|
/** More complex part */
|
|
|
|
$part = new Part();
|
|
|
|
$part->setName('Part 2');
|
|
|
|
$part->setCategory($manager->find(Category::class, 1));
|
|
|
|
$part->setFootprint($manager->find(Footprint::class, 1));
|
|
|
|
$part->setManufacturer($manager->find(Manufacturer::class, 1));
|
|
|
|
$part->setTags('test, Test, Part2');
|
|
|
|
$part->setMass(100.2);
|
2023-11-12 00:36:13 +01:00
|
|
|
$part->setIpn('IPN123');
|
2020-02-09 22:10:29 +01:00
|
|
|
$part->setNeedsReview(true);
|
2023-07-17 00:34:00 +02:00
|
|
|
$part->setManufacturingStatus(ManufacturingStatus::ACTIVE);
|
2020-02-09 22:10:29 +01:00
|
|
|
$manager->persist($part);
|
|
|
|
|
|
|
|
/** Part with orderdetails, storelocations and Attachments */
|
|
|
|
$part = new Part();
|
|
|
|
$part->setFavorite(true);
|
2020-04-09 14:23:26 +02:00
|
|
|
$part->setName('Part 3');
|
2020-02-09 22:10:29 +01:00
|
|
|
$part->setCategory($manager->find(Category::class, 1));
|
|
|
|
$partLot1 = new PartLot();
|
|
|
|
$partLot1->setAmount(1.0);
|
2023-09-04 22:57:40 +02:00
|
|
|
$partLot1->setStorageLocation($manager->find(StorageLocation::class, 1));
|
2020-02-09 22:10:29 +01:00
|
|
|
$part->addPartLot($partLot1);
|
|
|
|
|
|
|
|
$partLot2 = new PartLot();
|
2022-08-14 19:32:53 +02:00
|
|
|
$partLot2->setExpirationDate(new DateTime());
|
2020-02-09 22:10:29 +01:00
|
|
|
$partLot2->setComment('Test');
|
|
|
|
$partLot2->setNeedsRefill(true);
|
2023-09-04 22:57:40 +02:00
|
|
|
$partLot2->setStorageLocation($manager->find(StorageLocation::class, 3));
|
2023-11-17 23:29:06 +01:00
|
|
|
$partLot2->setVendorBarcode('lot2_vendor_barcode');
|
2020-02-09 22:10:29 +01:00
|
|
|
$part->addPartLot($partLot2);
|
|
|
|
|
|
|
|
$orderdetail = new Orderdetail();
|
|
|
|
$orderdetail->setSupplier($manager->find(Supplier::class, 1));
|
2020-05-21 13:46:17 +02:00
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(BigDecimal::of('10.0')));
|
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(BigDecimal::of('15.0')));
|
2020-02-09 22:10:29 +01:00
|
|
|
$part->addOrderdetail($orderdetail);
|
|
|
|
|
|
|
|
$orderdetail = new Orderdetail();
|
|
|
|
$orderdetail->setSupplierpartnr('BC 547');
|
|
|
|
$orderdetail->setObsolete(true);
|
|
|
|
$orderdetail->setSupplier($manager->find(Supplier::class, 1));
|
2020-05-21 13:46:17 +02:00
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(BigDecimal::of('10.0')));
|
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(BigDecimal::of('15.1')));
|
2020-02-09 22:10:29 +01:00
|
|
|
$part->addOrderdetail($orderdetail);
|
|
|
|
|
|
|
|
$attachment = new PartAttachment();
|
|
|
|
$attachment->setName('TestAttachment');
|
|
|
|
$attachment->setURL('www.foo.bar');
|
|
|
|
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1));
|
|
|
|
$part->addAttachment($attachment);
|
|
|
|
|
|
|
|
$attachment = new PartAttachment();
|
|
|
|
$attachment->setName('Test2');
|
|
|
|
$attachment->setPath('invalid');
|
|
|
|
$attachment->setShowInTable(true);
|
|
|
|
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1));
|
|
|
|
$part->addAttachment($attachment);
|
|
|
|
|
|
|
|
$manager->persist($part);
|
|
|
|
$manager->flush();
|
|
|
|
}
|
2023-06-18 22:06:42 +02:00
|
|
|
|
|
|
|
public function getDependencies(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
DataStructureFixtures::class
|
|
|
|
];
|
|
|
|
}
|
2020-03-15 13:56:31 +01:00
|
|
|
}
|