import hiltes

This commit is contained in:
mmoeller
2023-02-02 13:48:54 +01:00
parent 3493e038e3
commit 7100cc5a89
11 changed files with 418 additions and 364 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Repository;
use App\Entity\Stock;
use App\Entity\Warehouse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@@ -47,6 +48,7 @@ class StockRepository extends ServiceEntityRepository
}
$stock->setStock($entity->getStock());
$stock->setUpdateTime(new \DateTime('now'));
$this->getEntityManager()->flush();
}
@@ -55,16 +57,28 @@ class StockRepository extends ServiceEntityRepository
* @param Stock $entity
* @return void
*/
public function upsert(Stock $entity): void
public function upsert(Stock $stock): void
{
$stock = $this->findByGtin($entity->getGtin());
//$stock = $this->findByGtin($entity->getGtin());
if ($stock) {
// $warehouse = $this->getEntityManager()->find(Warehouse::class, $stock->getWarehouseId());
// $stock->setWarehouse($warehouse);
//
// $this->getEntityManager()->persist($stock);
//
// $this->getEntityManager()->flush();
$s = $this->findOneBy([
'gtin' => $stock->getGtin(),
//'warehouse_id' => $stock->getWarehouseId()
]);
if ($s) {
// $stock->setStock($entity->getStock());
// $this->getEntityManager()->flush();
$this->update($entity,$stock[0]->getId());
$this->update($stock,$s->getId());
}else{
$this->add($entity,true);
$this->add($stock,true);
}
}

View File

@@ -21,13 +21,15 @@ class WarehouseRepository extends ServiceEntityRepository
parent::__construct($registry, Warehouse::class);
}
public function add(Warehouse $entity, bool $flush = false): void
public function add(Warehouse $entity, bool $flush = false): ?int
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
return $entity->getId();
}
public function remove(Warehouse $entity, bool $flush = false): void