예제 #1
0
 /**
  *
  * Создает новый трансфер с указанным списком товаров, но не проводит его
  * Если указанно, то создает резерв товара
  *
  * @param ProductQtyCollection $collection
  * @param Warehouse $source
  * @param Warehouse $target
  * @param boolean $reserve //зарезервировать товары?
  * @return StockTransfer
  */
 public function createTransfer(ProductQtyCollection $collection, Warehouse $source, Warehouse $target, $reserve = false)
 {
     if ($source->organization()->id != $target->organization()->id) {
         throw new StockException('Для перемещения между организациями, используйте метод StockRepository::createOrganisationsTransfer');
     }
     $transfer = new StockTransfer();
     $organization = $source->organization();
     $transfer->sourceOrganization()->associate($organization);
     $transfer->targetOrganization()->associate($organization);
     $transfer->sourceWarehouse()->associate($source);
     $transfer->targetWarehouse()->associate($target);
     $transfer->save();
     foreach ($collection as $row) {
         $productId = $row['id'];
         $qty = $row['qty'];
         $product = Product::findOrFail($productId);
         $stock = $this->stockRepository->findStockByProductAndWarehouse($product, $source);
         if (empty($stock)) {
             throw new StockNotFound();
         }
         $item = new StockTransferItem();
         $item->product()->associate($product);
         $item->stock()->associate($stock);
         $item->setQty($qty);
         $item->save();
     }
     if ($reserve === true) {
         $transfer->is_reserved = true;
         $rep = new ReserveRepository();
         $rep->createByDocument($transfer);
     }
     return $transfer;
 }
예제 #2
0
 /**
  * @param Product $product
  * @param Warehouse $warehouse
  * @return Stock
  */
 public function findStockByProductAndWarehouse(Product $product, Warehouse $warehouse)
 {
     return $stock = $warehouse->stocks()->ofProduct($product)->first();
 }
예제 #3
0
파일: Stock.php 프로젝트: ElMiKu/AQAL
 /**
  * @param $query
  * @param Warehouse $warehouse
  * @return mixed
  */
 public function scopeOfWarehouse($query, Warehouse $warehouse)
 {
     return $query->whereWarehouseId($warehouse->getId());
 }
예제 #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('warehouses')->delete();
     Warehouse::create(['title' => 'Основной склад', 'code' => 'aristos_main_house', 'organization_id' => 1]);
     Warehouse::create(['title' => 'Склад Oursson', 'code' => 'oursson_house', 'organization_id' => 1]);
 }