Skip to content

Commit

Permalink
Merge pull request #224 from AndresC1/bugfix/production
Browse files Browse the repository at this point in the history
fix: Inventario con disponibilidad de entrada
  • Loading branch information
AndresC1 committed Jun 13, 2024
2 parents da7ccc0 + 42b5375 commit 09a191d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
33 changes: 24 additions & 9 deletions app/Http/Controllers/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,40 @@ public function index(TypeInventoryRequest $request)
$inventory = Inventory::where('type', $request->type)
->where('organization_id', auth()->user()->organization->id)
->paginate(10);
return response()->json([
'inventario' => InventoryCleanResource::collection($inventory),
'meta' => [
$filteredInventories = $inventory;
$response = [
'inventario' => InventoryCleanResource::collection($filteredInventories),
'mensaje' => 'Inventario de '.$typeInventory.' obtenido correctamente',
'estado' => 200
];
if($request->is_available === "true"){
$filteredInventories = $inventory->filter(function ($inventory) {
$inventory->productInputs = $inventory->productInputs->filter(function ($productInput) {
return $productInput->disponibility > 0;
});
return $inventory->productInputs->isNotEmpty();
});
$response['inventario'] = $filteredInventories;
}else{
$paginate_meta = [
'total' => $inventory->total(),
'current_page' => $inventory->currentPage(),
'per_page' => $inventory->perPage(),
'last_page' => $inventory->lastPage(),
'from' => $inventory->firstItem(),
'to' => $inventory->lastItem()
],
'links' => [
];
$paginate_links = [
'prev_page_url' => $inventory->previousPageUrl() ? $inventory->previousPageUrl()."&type=".$request->type : null,
'next_page_url' => $inventory->nextPageUrl() ? $inventory->nextPageUrl()."&type=".$request->type : null,
'last_page_url' => $inventory->url($inventory->lastPage()) ? $inventory->url($inventory->lastPage())."&type=".$request->type : null,
'first_page_url' => $inventory->url(1) ? $inventory->url(1)."&type=".$request->type : null,
],
'mensaje' => 'Inventario de '.$typeInventory.' obtenido correctamente',
'estado' => 200
], 200);
];
array_push($response, $paginate_meta);
array_push($response, $paginate_links);
}

return response()->json($response, 200);
} catch(Exception $e) {
return response()->json([
'mensaje' => 'Error al obtener el inventario',
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/ProductInputController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public function store(StoreProductInputRequest $request, EntryProductService $en
public function show(ShowInventoryRequest $request)
{
try{
$productInputs = Inventory::find($request->inventory_id)->productInputs()->paginate(10);
$productInputs = Inventory::find($request->inventory_id)
->productInputs()
->where('disponibility', '>', 0)
->paginate(10);
return response()->json([
'entradas' => EntryProductResource::collection($productInputs),
'meta' => [
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/Inventory/TypeInventoryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function rules(): array
{
return [
'type' => 'required|string|in:MP,PT',
'is_available' => 'in:true,false|nullable',
];
}

Expand All @@ -37,6 +38,7 @@ public function messages(): array
'type.required' => 'El tipo de inventario es requerido',
'type.string' => 'El tipo de inventario debe ser una cadena de caracteres',
'type.in' => 'El tipo de inventario debe ser MP o PT',
'is_available.in' => 'El tipo de valor debe ser true o false',
];
}
}

0 comments on commit 09a191d

Please sign in to comment.