Files
grocy/controllers/StockController.php
T

540 lines
25 KiB
PHP
Raw Normal View History

2018-04-11 19:49:35 +02:00
<?php
namespace Grocy\Controllers;
2021-06-12 17:21:12 +02:00
use Grocy\Helpers\Grocycode;
2020-10-31 10:25:33 -05:00
use Grocy\Services\RecipesService;
2018-04-11 19:49:35 +02:00
class StockController extends BaseController
{
2021-07-16 17:32:08 +02:00
use GrocycodeTrait;
2020-02-11 17:42:03 +01:00
public function Consume(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
return $this->renderPage($response, 'consume', [
'products' => $this->getDatabase()->products()->where('active = 1')->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)')->orderBy('name'),
2020-12-20 16:00:14 +01:00
'barcodes' => $this->getDatabase()->product_barcodes_comma_separated(),
2020-11-17 19:11:02 +01:00
'recipes' => $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
2018-04-11 19:49:35 +02:00
]);
}
2020-02-11 17:42:03 +01:00
public function Inventory(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
return $this->renderPage($response, 'inventory', [
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
2020-12-20 16:00:14 +01:00
'barcodes' => $this->getDatabase()->product_barcodes_comma_separated(),
2020-11-17 19:11:02 +01:00
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
2018-04-11 19:49:35 +02:00
]);
}
2020-08-31 20:40:31 +02:00
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2019-12-19 12:48:36 -06:00
{
2021-07-13 19:29:23 +02:00
if (isset($request->getQueryParams()['months']) && filter_var($request->getQueryParams()['months'], FILTER_VALIDATE_INT) !== false)
{
$months = $request->getQueryParams()['months'];
$where = "row_created_timestamp > DATE(DATE('now', 'localtime'), '-$months months')";
}
else
{
// Default 6 months
$where = "row_created_timestamp > DATE(DATE('now', 'localtime'), '-6 months')";
}
if (isset($request->getQueryParams()['product']) && filter_var($request->getQueryParams()['product'], FILTER_VALIDATE_INT) !== false)
{
$productId = $request->getQueryParams()['product'];
$where .= " AND product_id = $productId";
}
2020-11-17 19:11:02 +01:00
$usersService = $this->getUsersService();
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'stockjournal', [
2021-07-13 19:29:23 +02:00
'stockLog' => $this->getDatabase()->uihelper_stock_journal()->where($where)->orderBy('row_created_timestamp', 'DESC'),
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'users' => $usersService->GetUsersAsDto(),
2021-06-12 17:21:12 +02:00
'transactionTypes' => GetClassConstants('\Grocy\Services\StockService', 'TRANSACTION_TYPE_')
2019-12-19 12:48:36 -06:00
]);
}
2020-08-31 20:40:31 +02:00
public function LocationContentSheet(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'locationcontentsheet', [
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'currentStockLocationContent' => $this->getStockService()->GetCurrentStockLocationContent()
2018-04-11 19:49:35 +02:00
]);
}
2020-08-31 20:40:31 +02:00
public function LocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
if ($args['locationId'] == 'new')
{
return $this->renderPage($response, 'locationform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('locations')
]);
}
else
{
return $this->renderPage($response, 'locationform', [
'location' => $this->getDatabase()->locations($args['locationId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('locations')
]);
}
}
2020-02-11 17:42:03 +01:00
public function LocationsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
return $this->renderPage($response, 'locations', [
2020-11-17 19:11:02 +01:00
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'userfields' => $this->getUserfieldsService()->GetFields('locations'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('locations')
2018-04-11 19:49:35 +02:00
]);
}
2020-08-31 20:40:31 +02:00
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
$usersService = $this->getUsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_due_soon_days'];
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'stockoverview', [
'currentStock' => $this->getStockService()->GetCurrentStockOverview(),
2020-11-17 19:11:02 +01:00
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'currentStockLocations' => $this->getStockService()->GetCurrentStockLocations(),
'nextXDays' => $nextXDays,
2020-11-17 19:11:02 +01:00
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
2018-09-24 13:02:52 +02:00
]);
}
2020-08-31 20:40:31 +02:00
public function ProductBarcodesEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
2020-08-31 20:40:31 +02:00
$product = null;
if (isset($request->getQueryParams()['product']))
{
$product = $this->getDatabase()->products($request->getQueryParams()['product']);
}
if ($args['productBarcodeId'] == 'new')
{
return $this->renderPage($response, 'productbarcodeform', [
2020-08-31 20:40:31 +02:00
'mode' => 'create',
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
'product' => $product,
2020-11-17 19:11:02 +01:00
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
'userfields' => $this->getUserfieldsService()->GetFields('product_barcodes')
2020-08-31 20:40:31 +02:00
]);
}
else
{
return $this->renderPage($response, 'productbarcodeform', [
2020-08-31 20:40:31 +02:00
'mode' => 'edit',
'barcode' => $this->getDatabase()->product_barcodes($args['productBarcodeId']),
'product' => $product,
2020-11-17 19:11:02 +01:00
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
'userfields' => $this->getUserfieldsService()->GetFields('product_barcodes')
2020-08-31 20:40:31 +02:00
]);
}
2018-04-11 19:49:35 +02:00
}
2020-02-11 17:42:03 +01:00
public function ProductEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
if ($args['productId'] == 'new')
{
return $this->renderPage($response, 'productform', [
2020-08-31 20:40:31 +02:00
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
2020-11-17 19:11:02 +01:00
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'productgroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('parent_product_id IS NULL and active = 1')->orderBy('name', 'COLLATE NOCASE'),
'isSubProductOfOthers' => false,
2018-04-11 19:49:35 +02:00
'mode' => 'create'
]);
}
else
{
$product = $this->getDatabase()->products($args['productId']);
return $this->renderPage($response, 'productform', [
2020-08-31 20:40:31 +02:00
'product' => $product,
2020-11-17 19:11:02 +01:00
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
2020-11-17 19:11:02 +01:00
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'productgroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('id != :1 AND parent_product_id IS NULL and active = 1', $product->id)->orderBy('name', 'COLLATE NOCASE'),
'isSubProductOfOthers' => $this->getDatabase()->products()->where('parent_product_id = :1', $product->id)->count() !== 0,
'mode' => 'edit',
2020-11-17 19:11:02 +01:00
'quConversions' => $this->getDatabase()->quantity_unit_conversions(),
'productBarcodeUserfields' => $this->getUserfieldsService()->GetFields('product_barcodes'),
'productBarcodeUserfieldValues' => $this->getUserfieldsService()->GetAllValues('product_barcodes')
2018-04-11 19:49:35 +02:00
]);
}
}
2021-06-12 17:21:12 +02:00
public function ProductGrocycodeImage(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2021-07-13 19:29:23 +02:00
$gc = new Grocycode(Grocycode::PRODUCT, $args['productId']);
2021-07-16 17:32:08 +02:00
return $this->ServeGrocycodeImage($request, $response, $gc);
2021-06-12 17:21:12 +02:00
}
2020-08-31 20:40:31 +02:00
public function ProductGroupEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
2020-08-31 20:40:31 +02:00
if ($args['productGroupId'] == 'new')
2018-04-11 19:49:35 +02:00
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'productgroupform', [
'mode' => 'create',
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('product_groups')
2018-04-11 19:49:35 +02:00
]);
}
else
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'productgroupform', [
'group' => $this->getDatabase()->product_groups($args['productGroupId']),
'mode' => 'edit',
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('product_groups')
2018-04-11 19:49:35 +02:00
]);
}
}
2020-08-31 20:40:31 +02:00
public function ProductGroupsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'productgroups', [
2020-11-17 19:11:02 +01:00
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('product_groups'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('product_groups')
]);
}
public function ProductsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$products = $this->getDatabase()->products();
if (!isset($request->getQueryParams()['include_disabled']))
2020-12-07 19:48:33 +01:00
{
$products = $products->where('active = 1');
2020-12-07 19:48:33 +01:00
}
if (isset($request->getQueryParams()['only_in_stock']))
2020-12-07 19:48:33 +01:00
{
$products = $products->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)');
2020-12-07 19:48:33 +01:00
}
$products = $products->orderBy('name', 'COLLATE NOCASE');
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'products', [
2020-12-07 19:48:33 +01:00
'products' => $products,
2020-11-17 19:11:02 +01:00
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'),
'shoppingLocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function Purchase(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'purchase', [
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
2020-12-20 16:00:14 +01:00
'barcodes' => $this->getDatabase()->product_barcodes_comma_separated(),
2020-11-17 19:11:02 +01:00
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
2020-08-31 20:40:31 +02:00
]);
}
public function QuantityUnitConversionEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$product = null;
if (isset($request->getQueryParams()['product']))
{
2020-08-31 20:40:31 +02:00
$product = $this->getDatabase()->products($request->getQueryParams()['product']);
}
2020-08-31 20:40:31 +02:00
$defaultQuUnit = null;
if (isset($request->getQueryParams()['qu-unit']))
{
2020-08-31 20:40:31 +02:00
$defaultQuUnit = $this->getDatabase()->quantity_units($request->getQueryParams()['qu-unit']);
}
2020-08-31 20:40:31 +02:00
if ($args['quConversionId'] == 'new')
2018-09-24 13:02:52 +02:00
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'quantityunitconversionform', [
'mode' => 'create',
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('quantity_unit_conversions'),
2020-11-17 19:11:02 +01:00
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'product' => $product,
'defaultQuUnit' => $defaultQuUnit
2018-09-24 13:02:52 +02:00
]);
}
else
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'quantityunitconversionform', [
'quConversion' => $this->getDatabase()->quantity_unit_conversions($args['quConversionId']),
'mode' => 'edit',
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('quantity_unit_conversions'),
2020-11-17 19:11:02 +01:00
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'product' => $product,
'defaultQuUnit' => $defaultQuUnit
2018-09-24 13:02:52 +02:00
]);
}
}
2020-02-11 17:42:03 +01:00
public function QuantityUnitEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
if ($args['quantityunitId'] == 'new')
{
return $this->renderPage($response, 'quantityunitform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'pluralCount' => $this->getLocalizationService()->GetPluralCount(),
'pluralRule' => $this->getLocalizationService()->GetPluralDefinition()
2018-04-11 19:49:35 +02:00
]);
}
else
{
$quantityUnit = $this->getDatabase()->quantity_units($args['quantityunitId']);
return $this->renderPage($response, 'quantityunitform', [
2020-08-31 20:40:31 +02:00
'quantityUnit' => $quantityUnit,
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'pluralCount' => $this->getLocalizationService()->GetPluralCount(),
'pluralRule' => $this->getLocalizationService()->GetPluralDefinition(),
'defaultQuConversions' => $this->getDatabase()->quantity_unit_conversions()->where('from_qu_id = :1 AND product_id IS NULL', $quantityUnit->id),
'quantityUnits' => $this->getDatabase()->quantity_units()
2018-04-11 19:49:35 +02:00
]);
}
2020-08-31 20:40:31 +02:00
}
public function QuantityUnitPluralFormTesting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'quantityunitpluraltesting', [
2020-11-17 19:11:02 +01:00
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE')
2020-08-31 20:40:31 +02:00
]);
}
public function QuantityUnitsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'quantityunits', [
2020-11-17 19:11:02 +01:00
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('quantity_units')
]);
}
public function ShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$listId = 1;
if (isset($request->getQueryParams()['list']))
{
$listId = $request->getQueryParams()['list'];
}
return $this->renderPage($response, 'shoppinglist', [
'listItems' => $this->getDatabase()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId),
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'missingProducts' => $this->getStockService()->GetMissingProducts(),
2020-11-17 19:11:02 +01:00
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'selectedShoppingListId' => $listId,
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
2020-11-17 19:11:02 +01:00
'productUserfields' => $this->getUserfieldsService()->GetFields('products'),
'productUserfieldValues' => $this->getUserfieldsService()->GetAllValues('products'),
'userfields' => $this->getUserfieldsService()->GetFields('shopping_list'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('shopping_list')
2020-08-31 20:40:31 +02:00
]);
}
public function ShoppingListEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['listId'] == 'new')
{
return $this->renderPage($response, 'shoppinglistform', [
2020-11-17 19:11:02 +01:00
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_lists')
2020-08-31 20:40:31 +02:00
]);
}
else
{
return $this->renderPage($response, 'shoppinglistform', [
'shoppingList' => $this->getDatabase()->shopping_lists($args['listId']),
2020-11-17 19:11:02 +01:00
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_lists')
2020-08-31 20:40:31 +02:00
]);
}
2018-04-11 19:49:35 +02:00
}
2020-02-11 17:42:03 +01:00
public function ShoppingListItemEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
2018-04-11 19:49:35 +02:00
{
if ($args['itemId'] == 'new')
{
return $this->renderPage($response, 'shoppinglistitemform', [
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name', 'COLLATE NOCASE'),
'mode' => 'create',
2020-11-17 19:11:02 +01:00
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
'userfields' => $this->getUserfieldsService()->GetFields('shopping_list')
2018-04-11 19:49:35 +02:00
]);
}
else
{
return $this->renderPage($response, 'shoppinglistitemform', [
2020-08-31 20:40:31 +02:00
'listItem' => $this->getDatabase()->shopping_list($args['itemId']),
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name', 'COLLATE NOCASE'),
'mode' => 'edit',
2020-11-17 19:11:02 +01:00
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
'userfields' => $this->getUserfieldsService()->GetFields('shopping_list')
2018-04-11 19:49:35 +02:00
]);
}
}
2020-08-31 20:40:31 +02:00
public function ShoppingListSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'shoppinglistsettings');
}
public function ShoppingLocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['shoppingLocationId'] == 'new')
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'shoppinglocationform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations')
]);
}
else
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'shoppinglocationform', [
'shoppinglocation' => $this->getDatabase()->shopping_locations($args['shoppingLocationId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations')
]);
}
}
2020-08-31 20:40:31 +02:00
public function ShoppingLocationsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'shoppinglocations', [
2020-11-17 19:11:02 +01:00
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('shopping_locations')
]);
}
2020-08-31 20:40:31 +02:00
public function StockEntryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'stockentryform', [
'stockEntry' => $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(),
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE')
]);
}
2021-06-12 17:21:12 +02:00
public function StockEntryGrocycodeImage(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$stockEntry = $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch();
$gc = new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id]);
2021-07-16 17:32:08 +02:00
return $this->ServeGrocycodeImage($request, $response, $gc);
2021-06-12 17:21:12 +02:00
}
public function StockEntryGrocycodeLabel(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$stockEntry = $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch();
return $this->renderPage($response, 'stockentrylabel', [
'stockEntry' => $stockEntry,
'product' => $this->getDatabase()->products($stockEntry->product_id),
]);
}
2020-08-31 20:40:31 +02:00
public function StockSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'stocksettings', [
2020-11-17 19:11:02 +01:00
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE')
]);
}
2020-08-31 20:40:31 +02:00
public function Stockentries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
$usersService = $this->getUsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_due_soon_days'];
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'stockentries', [
2020-11-17 19:11:02 +01:00
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
2020-08-31 20:40:31 +02:00
'stockEntries' => $this->getDatabase()->stock()->orderBy('product_id'),
'currentStockLocations' => $this->getStockService()->GetCurrentStockLocations(),
'nextXDays' => $nextXDays,
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
2020-08-31 20:40:31 +02:00
public function Transfer(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'transfer', [
'products' => $this->getDatabase()->products()->where('active = 1')->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)')->orderBy('name', 'COLLATE NOCASE'),
2020-12-20 16:00:14 +01:00
'barcodes' => $this->getDatabase()->product_barcodes_comma_separated(),
2020-11-17 19:11:02 +01:00
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
2020-08-31 20:40:31 +02:00
]);
}
2020-09-06 13:18:51 +02:00
public function JournalSummary(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$entries = $this->getDatabase()->uihelper_stock_journal_summary();
if (isset($request->getQueryParams()['product_id']))
{
$entries = $entries->where('product_id', $request->getQueryParams()['product_id']);
}
if (isset($request->getQueryParams()['user_id']))
{
$entries = $entries->where('user_id', $request->getQueryParams()['user_id']);
}
if (isset($request->getQueryParams()['transaction_type']))
{
$entries = $entries->where('transaction_type', $request->getQueryParams()['transaction_type']);
}
2020-11-17 19:11:02 +01:00
$usersService = $this->getUsersService();
2020-09-06 13:18:51 +02:00
return $this->renderPage($response, 'stockjournalsummary', [
2020-11-17 19:11:02 +01:00
'entries' => $entries,
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'users' => $usersService->GetUsersAsDto(),
'transactionTypes' => GetClassConstants('\Grocy\Services\StockService', 'TRANSACTION_TYPE_')
2020-09-06 13:18:51 +02:00
]);
}
2018-04-11 19:49:35 +02:00
}