Exemplo n.º 1
0
 public function assemblyPrice()
 {
     $price = 0;
     foreach ($this->assemblies as $assembly) {
         $finalQty = Unit::convert($assembly->pivot->quantity, $assembly->pivot->unit_id, $assembly->unit_id);
         $price += $assembly->costPrice * $finalQty;
     }
     return $price;
 }
Exemplo n.º 2
0
 public function move($itemId, $toWarehouseId, $qty)
 {
     $stockClass = config('mojito.stockClass', 'Stock');
     $pivotFrom = $stockClass::where('warehouse_id', '=', $this->id)->where('item_id', '=', $itemId)->first();
     if ($pivotFrom == null) {
         return false;
     }
     $pivotTo = $stockClass::where('warehouse_id', '=', $toWarehouseId)->where('item_id', '=', $itemId)->first();
     if ($pivotTo != null) {
         $destQty = Unit::convert($qty, $pivotFrom->unit_id, $pivotTo->unit_id);
     } else {
         $destQty = $qty;
     }
     if ($pivotTo == null) {
         $stockClass::create(['warehouse_id' => $toWarehouseId, 'item_id' => $itemId, 'quantity' => $qty, 'unit_id' => $pivotFrom->unit_id, 'alert' => 0]);
     } else {
         $pivotTo->update(["quantity" => $pivotTo->quantity + $destQty]);
     }
     $pivotFrom->update(["quantity" => $pivotFrom->quantity - $qty]);
     StockMovement::create(['item_id' => $itemId, 'from_warehouse_id' => $this->id, 'to_warehouse_id' => $toWarehouseId, 'quantity' => $qty, 'action' => Warehouse::ACTION_MOVE]);
     return true;
 }