Applied PHP-CS-Fixer rules

This commit is contained in:
Bernd Bestel
2020-09-01 21:29:47 +02:00
parent 3da8904cba
commit 836bcc82e5
56 changed files with 150 additions and 467 deletions

View File

@@ -32,7 +32,7 @@ class ApiKeyService extends BaseService
return $apiKey->id;
}
// Returns any valid key for $keyType,
// Returns any valid key for $keyType,
// not allowed for key type "default"
public function GetOrCreateApiKey($keyType)
{
@@ -52,9 +52,7 @@ class ApiKeyService extends BaseService
{
return $this->CreateApiKey($keyType);
}
}
}
public function GetUserByApiKey($apiKey)
@@ -84,7 +82,7 @@ class ApiKeyService extends BaseService
if ($apiKeyRow !== null)
{
// This should not change the database file modification time as this is used
// This should not change the database file modification time as this is used
// to determine if REALLY something has changed
$dbModTime = $this->getDatabaseService()->GetDbChangedTime();
$apiKeyRow->update([
@@ -98,9 +96,7 @@ class ApiKeyService extends BaseService
{
return false;
}
}
}
public function RemoveApiKey($apiKey)
@@ -112,5 +108,4 @@ class ApiKeyService extends BaseService
{
return RandomString(50);
}
}

View File

@@ -29,8 +29,7 @@ class ApplicationService extends BaseService
}
// Sort changelog items to have the changelog descending by newest version
usort($changelogItems, function ($a, $b)
{
usort($changelogItems, function ($a, $b) {
if ($a['release_number'] == $b['release_number'])
{
return 0;
@@ -59,7 +58,6 @@ class ApplicationService extends BaseService
$this->InstalledVersion->Version = "pre-release-$commitHash";
$this->InstalledVersion->ReleaseDate = substr($commitDate, 0, 19);
}
}
return $this->InstalledVersion;
@@ -77,5 +75,4 @@ class ApplicationService extends BaseService
'sqlite_version' => $sqliteVersion
];
}
}

View File

@@ -61,5 +61,4 @@ class BaseService
{
return UsersService::getInstance();
}
}

View File

@@ -66,5 +66,4 @@ class BatteriesService extends BaseService
$batteryRow = $this->getDatabase()->batteries()->where('id = :1', $batteryId)->fetch();
return $batteryRow !== null;
}
}

View File

@@ -2,14 +2,6 @@
namespace Grocy\Services;
#use \Grocy\Services\StockService;
#use \Grocy\Services\TasksService;
#use \Grocy\Services\ChoresService;
#use \Grocy\Services\BatteriesService;
#use \Grocy\Services\UsersService;
use Grocy\Helpers\UrlManager;
class CalendarService extends BaseService
@@ -34,9 +26,7 @@ class CalendarService extends BaseService
'link' => $this->UrlManager->ConstructUrl('/stockoverview')
];
}
}
}
$taskEvents = [];
@@ -54,7 +44,6 @@ class CalendarService extends BaseService
'link' => $this->UrlManager->ConstructUrl('/tasks')
];
}
}
$choreEvents = [];
@@ -85,7 +74,6 @@ class CalendarService extends BaseService
'allDay' => $chore->track_date_only == 1
];
}
}
$batteryEvents = [];
@@ -104,7 +92,6 @@ class CalendarService extends BaseService
'link' => $this->UrlManager->ConstructUrl('/batteriesoverview')
];
}
}
$mealPlanRecipeEvents = [];
@@ -129,7 +116,6 @@ class CalendarService extends BaseService
'link' => $this->UrlManager->ConstructUrl('/recipes' . '?recipe=' . $recipeOfCurrentDay->includes_recipe_id . '#fullscreen')
];
}
}
$mealPlanDayNotes = $this->getDatabase()->meal_plan()->where('type', 'note');
@@ -158,7 +144,6 @@ class CalendarService extends BaseService
'date_format' => 'date'
];
}
}
return array_merge($stockEvents, $taskEvents, $choreEvents, $batteryEvents, $mealPlanRecipeEvents, $mealPlanNotesEvents, $mealPlanProductEvents);
@@ -169,5 +154,4 @@ class CalendarService extends BaseService
parent::__construct();
$this->UrlManager = new UrlManager(GROCY_BASE_URL);
}
}

View File

@@ -5,23 +5,15 @@ namespace Grocy\Services;
class ChoresService extends BaseService
{
const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order';
const CHORE_ASSIGNMENT_TYPE_NO_ASSIGNMENT = 'no-assignment';
const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random';
const CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST = 'who-least-did-first';
const CHORE_PERIOD_TYPE_DAILY = 'daily';
const CHORE_PERIOD_TYPE_DYNAMIC_REGULAR = 'dynamic-regular';
const CHORE_PERIOD_TYPE_MANUALLY = 'manually';
const CHORE_PERIOD_TYPE_MONTHLY = 'monthly';
const CHORE_PERIOD_TYPE_WEEKLY = 'weekly';
const CHORE_PERIOD_TYPE_YEARLY = 'yearly';
public function CalculateNextExecutionAssignment($choreId)
@@ -45,33 +37,29 @@ class ChoresService extends BaseService
{
$assignedUsers[] = $user;
}
}
$nextExecutionUserId = null;
if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_RANDOM)
{
// Random assignment and only 1 user in the group? Well, ok - will be hard to guess the next one...
// Random assignment and only 1 user in the group? Well, ok - will be hard to guess the next one...
if (count($assignedUsers) == 1)
{
$nextExecutionUserId = array_shift($assignedUsers)->id;
}
else
{
// Randomness in small groups will likely often result in the same user, so try it as long as this is the case
// Randomness in small groups will likely often result in the same user, so try it as long as this is the case
while ($nextExecutionUserId == null || $nextExecutionUserId == $lastDoneByUserId)
{
$nextExecutionUserId = $assignedUsers[array_rand($assignedUsers)]->id;
}
}
}
else if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER)
elseif ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER)
{
usort($assignedUsers, function ($a, $b)
{
usort($assignedUsers, function ($a, $b) {
return strcmp($a->display_name, $b->display_name);
});
@@ -88,24 +76,21 @@ class ChoresService extends BaseService
{
$nextRoundMatches = true;
}
}
// If nothing has matched, probably it was the last user in the sorted list -> the first one is the next one
// If nothing has matched, probably it was the last user in the sorted list -> the first one is the next one
if ($nextExecutionUserId == null)
{
$nextExecutionUserId = array_shift($assignedUsers)->id;
}
}
else if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST)
elseif ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST)
{
$row = $this->getDatabase()->chores_execution_users_statistics()->where('chore_id = :1', $choreId)->orderBy('execution_count')->limit(1)->fetch();
if ($row != null)
{
$nextExecutionUserId = $row->user_id;
}
}
$chore->update([
@@ -217,5 +202,4 @@ class ChoresService extends BaseService
$choreRow = $this->getDatabase()->chores()->where('id = :1', $choreId)->fetch();
return $choreRow !== null;
}
}

View File

@@ -24,16 +24,12 @@ class DatabaseMigrationService extends BaseService
$migrationNumber = ltrim($migrationFile->getBasename('.php'), '0');
$this->ExecutePhpMigrationWhenNeeded($migrationNumber, $migrationFile->getPathname());
}
else
if ($migrationFile->getExtension() === 'sql')
elseif ($migrationFile->getExtension() === 'sql')
{
$migrationNumber = ltrim($migrationFile->getBasename('.sql'), '0');
$this->ExecuteSqlMigrationWhenNeeded($migrationNumber, file_get_contents($migrationFile->getPathname()));
}
}
}
private function ExecutePhpMigrationWhenNeeded(int $migrationId, string $phpFile)
@@ -45,7 +41,6 @@ class DatabaseMigrationService extends BaseService
include $phpFile;
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
}
}
private function ExecuteSqlMigrationWhenNeeded(int $migrationId, string $sql)
@@ -57,7 +52,5 @@ class DatabaseMigrationService extends BaseService
$this->getDatabaseService()->ExecuteDbStatement($sql);
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
}
}
}

View File

@@ -2,8 +2,6 @@
namespace Grocy\Services;
#use \Grocy\Services\ApplicationService;
class DatabaseService
{
private static $DbConnection = null;
@@ -99,5 +97,4 @@ class DatabaseService
return GROCY_DATAPATH . '/grocy.db';
}
}

View File

@@ -2,8 +2,6 @@
namespace Grocy\Services;
#use \Grocy\Services\LocalizationService;
class DemoDataGeneratorService extends BaseService
{
protected $LocalizationService;
@@ -311,7 +309,6 @@ class DemoDataGeneratorService extends BaseService
$this->DownloadFileIfNotAlreadyExists('https://releases.grocy.info/demoresources/chocolate_sauce.jpg', "$recipePicturesFolder/chocolate_sauce.jpg");
$this->DownloadFileIfNotAlreadyExists('https://releases.grocy.info/demoresources/pancakes_chocolate_sauce.jpg', "$recipePicturesFolder/pancakes_chocolate_sauce.jpg");
}
}
public function __construct()
@@ -331,7 +328,6 @@ class DemoDataGeneratorService extends BaseService
]
])));
}
}
private function NextSupermarketId()
@@ -366,5 +362,4 @@ class DemoDataGeneratorService extends BaseService
$localizedText = $this->getLocalizationService()->__t($text, null);
return str_replace("'", "''", $localizedText);
}
}

View File

@@ -34,22 +34,17 @@ class FilesService extends BaseService
{
$image->resizeToBestFit($bestFitWidth, $bestFitHeight);
}
else
if ($bestFitHeight !== null)
elseif ($bestFitHeight !== null)
{
$image->resizeToHeight($bestFitHeight);
}
else
if ($bestFitWidth !== null)
elseif ($bestFitWidth !== null)
{
$image->resizeToWidth($bestFitWidth);
}
$image->save($filePathDownscaled);
}
}
catch (ImageResizeException $ex)
{
@@ -81,7 +76,5 @@ class FilesService extends BaseService
{
mkdir($this->StoragePath);
}
}
}

View File

@@ -2,7 +2,6 @@
namespace Grocy\Services;
#use \Grocy\Services\DatabaseService;
use Gettext\Translation;
use Gettext\Translations;
use Gettext\Translator;
@@ -31,9 +30,7 @@ class LocalizationService
$this->PotMain[] = $translation;
$this->PotMain->toPoFile(__DIR__ . '/../localization/strings.pot');
}
}
}
public function GetPluralCount()
@@ -46,7 +43,6 @@ class LocalizationService
{
return 2;
}
}
public function GetPluralDefinition()
@@ -59,7 +55,6 @@ class LocalizationService
{
return '(n != 1)';
}
}
public function GetPoAsJsonString()
@@ -93,7 +88,6 @@ class LocalizationService
{
return vsprintf($this->Translator->gettext($text), ...$placeholderValues);
}
}
public static function getInstance(string $culture)
@@ -137,7 +131,6 @@ class LocalizationService
{
$this->Pot = $this->Pot->mergeWith(Translations::fromPoFile(__DIR__ . '/../localization/demo_data.pot'));
}
}
$this->PoUserStrings = new Translations();
@@ -213,5 +206,4 @@ class LocalizationService
$this->Translator = new Translator();
$this->Translator->loadTranslations($this->Po);
}
}

View File

@@ -2,8 +2,6 @@
namespace Grocy\Services;
#use \Grocy\Services\StockService;
use LessQL\Result;
class RecipesService extends BaseService
@@ -42,11 +40,8 @@ class RecipesService extends BaseService
]);
$shoppinglistRow->save();
}
}
}
}
public function ConsumeRecipe($recipeId)
@@ -65,7 +60,6 @@ class RecipesService extends BaseService
{
$this->getStockService()->ConsumeProduct($recipePosition->product_id, $recipePosition->recipe_amount, false, StockService::TRANSACTION_TYPE_CONSUME, 'default', $recipeId, null, $transactionId, true);
}
}
$recipeRow = $this->getDatabase()->recipes()->where('id = :1', $recipeId)->fetch();
@@ -75,7 +69,6 @@ class RecipesService extends BaseService
$recipeResolvedRow = $this->getDatabase()->recipes_resolved()->where('recipe_id = :1', $recipeId)->fetch();
$this->getStockService()->AddProduct($recipeRow->product_id, floatval($recipeRow->desired_servings), null, StockService::TRANSACTION_TYPE_SELF_PRODUCTION, date('Y-m-d'), floatval($recipeResolvedRow->costs));
}
}
public function GetRecipesPosResolved()
@@ -99,5 +92,4 @@ class RecipesService extends BaseService
$recipeRow = $this->getDataBase()->recipes()->where('id = :1', $recipeId)->fetch();
return $recipeRow !== null;
}
}

View File

@@ -13,7 +13,7 @@ class SessionService extends BaseService
$expires = date('Y-m-d H:i:s', intval(time() + 2592000));
// Default is that sessions expire in 30 days
// Default is that sessions expire in 30 days
if ($stayLoggedInPermanently === true)
{
$expires = date('Y-m-d H:i:s', PHP_INT_SIZE == 4 ? PHP_INT_MAX : PHP_INT_MAX >> 32); // Never
@@ -61,7 +61,7 @@ class SessionService extends BaseService
if ($sessionRow !== null)
{
// This should not change the database file modification time as this is used
// This should not change the database file modification time as this is used
// to determine if REALLY something has changed
$dbModTime = $this->getDatabaseService()->GetDbChangedTime();
$sessionRow->update([
@@ -75,9 +75,7 @@ class SessionService extends BaseService
{
return false;
}
}
}
public function RemoveSession($sessionKey)
@@ -89,5 +87,4 @@ class SessionService extends BaseService
{
return RandomString(50);
}
}

View File

@@ -5,21 +5,13 @@ namespace Grocy\Services;
class StockService extends BaseService
{
const TRANSACTION_TYPE_CONSUME = 'consume';
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
const TRANSACTION_TYPE_PRODUCT_OPENED = 'product-opened';
const TRANSACTION_TYPE_PURCHASE = 'purchase';
const TRANSACTION_TYPE_SELF_PRODUCTION = 'self-production';
const TRANSACTION_TYPE_STOCK_EDIT_NEW = 'stock-edit-new';
const TRANSACTION_TYPE_STOCK_EDIT_OLD = 'stock-edit-old';
const TRANSACTION_TYPE_TRANSFER_FROM = 'transfer_from';
const TRANSACTION_TYPE_TRANSFER_TO = 'transfer_to';
public function AddMissingProductsToShoppingList($listId = 1)
@@ -38,8 +30,8 @@ class StockService extends BaseService
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id', $missingProduct->id)->fetch();
if ($alreadyExistingEntry) // Update
{
if ($alreadyExistingEntry)
{ // Update
if ($alreadyExistingEntry->amount < $amountToAdd)
{
$alreadyExistingEntry->update([
@@ -47,10 +39,9 @@ class StockService extends BaseService
'shopping_list_id' => $listId
]);
}
}
else // Insert
{
else
{ // Insert
$shoppinglistRow = $this->getDatabase()->shopping_list()->createRow([
'product_id' => $missingProduct->id,
'amount' => $amountToAdd,
@@ -58,9 +49,7 @@ class StockService extends BaseService
]);
$shoppinglistRow->save();
}
}
}
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $quFactorPurchaseToStock, $locationId = null, $shoppingLocationId = null, &$transactionId = null)
@@ -70,9 +59,9 @@ class StockService extends BaseService
throw new \Exception('Product does not exist or is inactive');
}
// Tare weight handling
// Tare weight handling
// The given amount is the new total amount including the container weight (gross)
// The given amount is the new total amount including the container weight (gross)
// The amount to be posted needs to be the given amount - stock amount - tare weight
$productDetails = (object) $this->GetProductDetails($productId);
@@ -86,14 +75,14 @@ class StockService extends BaseService
$amount = $amount - floatval($productDetails->stock_amount) - floatval($productDetails->product->tare_weight);
}
//Sets the default best before date, if none is supplied
//Sets the default best before date, if none is supplied
if ($bestBeforeDate == null)
{
if (intval($productDetails->product->default_best_before_days) == -1)
{
$bestBeforeDate = date('2999-12-31');
}
else if (intval($productDetails->product->default_best_before_days) > 0)
elseif (intval($productDetails->product->default_best_before_days) > 0)
{
$bestBeforeDate = date('Y-m-d', strtotime(date('Y-m-d') . ' + ' . $productDetails->product->default_best_before_days . ' days'));
}
@@ -101,7 +90,6 @@ class StockService extends BaseService
{
$bestBeforeDate = date('Y-m-d');
}
}
if ($transactionType === self::TRANSACTION_TYPE_PURCHASE || $transactionType === self::TRANSACTION_TYPE_INVENTORY_CORRECTION || $transactionType == self::TRANSACTION_TYPE_SELF_PRODUCTION)
@@ -149,7 +137,6 @@ class StockService extends BaseService
{
throw new \Exception("Transaction type $transactionType is not valid (StockService.AddProduct)");
}
}
public function AddProductToShoppingList($productId, $amount = 1, $note = null, $listId = 1)
@@ -165,16 +152,16 @@ class StockService extends BaseService
}
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id = :1 AND shopping_list_id = :2', $productId, $listId)->fetch();
if ($alreadyExistingEntry) // Update
{
if ($alreadyExistingEntry)
{ // Update
$alreadyExistingEntry->update([
'amount' => ($alreadyExistingEntry->amount + $amount),
'shopping_list_id' => $listId,
'note' => $note
]);
}
else // Insert
{
else
{ // Insert
$shoppinglistRow = $this->getDatabase()->shopping_list()->createRow([
'product_id' => $productId,
'amount' => $amount,
@@ -183,7 +170,6 @@ class StockService extends BaseService
]);
$shoppinglistRow->save();
}
}
public function ClearShoppingList($listId = 1)
@@ -208,9 +194,9 @@ class StockService extends BaseService
throw new \Exception('Location does not exist');
}
// Tare weight handling
// Tare weight handling
// The given amount is the new total amount including the container weight (gross)
// The given amount is the new total amount including the container weight (gross)
// The amount to be posted needs to be the absolute value of the given amount - stock amount - tare weight
$productDetails = (object) $this->GetProductDetails($productId);
@@ -226,12 +212,12 @@ class StockService extends BaseService
if ($transactionType === self::TRANSACTION_TYPE_CONSUME || $transactionType === self::TRANSACTION_TYPE_INVENTORY_CORRECTION)
{
if ($locationId === null) // Consume from any location
{
if ($locationId === null)
{ // Consume from any location
$potentialStockEntries = $this->GetProductStockEntries($productId, false, $allowSubproductSubstitution);
}
else // Consume only from the supplied location
{
else
{ // Consume only from the supplied location
$potentialStockEntries = $this->GetProductStockEntriesForLocation($productId, $locationId, false, $allowSubproductSubstitution);
}
@@ -259,8 +245,8 @@ class StockService extends BaseService
break;
}
if ($amount >= $stockEntry->amount) // Take the whole stock entry
{
if ($amount >= $stockEntry->amount)
{ // Take the whole stock entry
$logRow = $this->getDatabase()->stock_log()->createRow([
'product_id' => $stockEntry->product_id,
'amount' => $stockEntry->amount * -1,
@@ -281,8 +267,8 @@ class StockService extends BaseService
$amount -= $stockEntry->amount;
}
else // Stock entry amount is > than needed amount -> split the stock entry resp. update the amount
{
else
{ // Stock entry amount is > than needed amount -> split the stock entry resp. update the amount
$restStockAmount = $stockEntry->amount - $amount;
$logRow = $this->getDatabase()->stock_log()->createRow([
@@ -307,7 +293,6 @@ class StockService extends BaseService
$amount = 0;
}
}
return $this->getDatabase()->lastInsertId();
@@ -316,7 +301,6 @@ class StockService extends BaseService
{
throw new Exception("Transaction type $transactionType is not valid (StockService.ConsumeProduct)");
}
}
public function EditStockEntry(int $stockRowId, float $amount, $bestBeforeDate, $locationId, $shoppingLocationId, $price, $open, $purchasedDate, $quFactorPurchaseToStock)
@@ -354,9 +338,7 @@ class StockService extends BaseService
{
$openedDate = date('Y-m-d');
}
else
if (!$open)
elseif (!$open)
{
$openedDate = null;
}
@@ -399,8 +381,8 @@ class StockService extends BaseService
$plugin = $this->LoadBarcodeLookupPlugin();
$pluginOutput = $plugin->Lookup($barcode);
if ($pluginOutput !== null) // Lookup was successful
{
if ($pluginOutput !== null)
{ // Lookup was successful
if ($addFoundProduct === true)
{
// Add product to database and include new product id in output
@@ -409,7 +391,6 @@ class StockService extends BaseService
$pluginOutput['id'] = $newRow->id;
}
}
return $pluginOutput;
@@ -466,7 +447,6 @@ class StockService extends BaseService
{
return $this->getDatabase()->uihelper_stock_current_overview_including_opened();
}
}
public function GetExpiringProducts(int $days = 5, bool $excludeExpired = false)
@@ -605,7 +585,7 @@ class StockService extends BaseService
public function GetProductStockEntries($productId, $excludeOpened = false, $allowSubproductSubstitution = false, $ordered = true)
{
// In order of next use:
// In order of next use:
// First expiring first, then first in first out
$sqlWhereProductId = 'product_id = :1';
@@ -623,7 +603,9 @@ class StockService extends BaseService
}
$result = $this->getDatabase()->stock()->where($sqlWhereProductId . ' ' . $sqlWhereAndOpen, $productId);
if ($ordered)
{
return $result->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC');
}
return $result;
}
@@ -662,9 +644,9 @@ class StockService extends BaseService
$shoppingLocationId = $productDetails->last_shopping_location_id;
}
// Tare weight handling
// Tare weight handling
// The given amount is the new total amount including the container weight (gross)
// The given amount is the new total amount including the container weight (gross)
// So assume that the amount in stock is the amount also including the container weight
$containerWeight = 0;
@@ -677,9 +659,7 @@ class StockService extends BaseService
{
throw new \Exception('The new amount cannot equal the current stock amount');
}
else
if ($newAmount > floatval($productDetails->stock_amount) + $containerWeight)
elseif ($newAmount > floatval($productDetails->stock_amount) + $containerWeight)
{
$bookingAmount = $newAmount - floatval($productDetails->stock_amount);
@@ -690,9 +670,7 @@ class StockService extends BaseService
return $this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, date('Y-m-d'), $price, $locationId, $shoppingLocationId);
}
else
if ($newAmount < $productDetails->stock_amount + $containerWeight)
elseif ($newAmount < $productDetails->stock_amount + $containerWeight)
{
$bookingAmount = $productDetails->stock_amount - $newAmount;
@@ -747,8 +725,8 @@ class StockService extends BaseService
$newBestBeforeDate = date('Y-m-d', strtotime('+' . $product->default_best_before_days_after_open . ' days'));
}
if ($amount >= $stockEntry->amount) // Mark the whole stock entry as opened
{
if ($amount >= $stockEntry->amount)
{ // Mark the whole stock entry as opened
$logRow = $this->getDatabase()->stock_log()->createRow([
'product_id' => $stockEntry->product_id,
'amount' => $stockEntry->amount,
@@ -772,8 +750,8 @@ class StockService extends BaseService
$amount -= $stockEntry->amount;
}
else // Stock entry amount is > than needed amount -> split the stock entry
{
else
{ // Stock entry amount is > than needed amount -> split the stock entry
$restStockAmount = $stockEntry->amount - $amount;
$newStockRow = $this->getDatabase()->stock()->createRow([
@@ -812,7 +790,6 @@ class StockService extends BaseService
$amount = 0;
}
}
return $this->getDatabase()->lastInsertId();
@@ -827,7 +804,7 @@ class StockService extends BaseService
$productRow = $this->getDatabase()->shopping_list()->where('product_id = :1', $productId)->fetch();
//If no entry was found with for this product, we return gracefully
//If no entry was found with for this product, we return gracefully
if ($productRow != null && !empty($productRow))
{
$newAmount = $productRow->amount - $amount;
@@ -839,9 +816,7 @@ class StockService extends BaseService
{
$productRow->update(['amount' => $newAmount]);
}
}
}
public function TransferProduct(int $productId, float $amount, int $locationIdFrom, int $locationIdTo, $specificStockEntryId = 'default', &$transactionId = null)
@@ -861,9 +836,9 @@ class StockService extends BaseService
throw new \Exception('Destination location does not exist');
}
// Tare weight handling
// Tare weight handling
// The given amount is the new total amount including the container weight (gross)
// The given amount is the new total amount including the container weight (gross)
// The amount to be posted needs to be the absolute value of the given amount - stock amount - tare weight
$productDetails = (object) $this->GetProductDetails($productId);
@@ -871,7 +846,6 @@ class StockService extends BaseService
{
// Hard fail for now, as we not yet support transfering tare weight enabled products
throw new \Exception('Transfering tare weight enabled products is not yet possible');
if ($amount < floatval($productDetails->product->tare_weight))
{
throw new \Exception('The amount cannot be lower than the defined tare weight');
@@ -912,23 +886,22 @@ class StockService extends BaseService
$locationFrom = $this->getDatabase()->locations()->where('id', $locationIdFrom)->fetch();
$locationTo = $this->getDatabase()->locations()->where('id', $locationIdTo)->fetch();
// Product was moved from a non-freezer to freezer location -> freeze
// Product was moved from a non-freezer to freezer location -> freeze
if (intval($locationFrom->is_freezer) === 0 && intval($locationTo->is_freezer) === 1 && $productDetails->product->default_best_before_days_after_freezing > 0)
{
$newBestBeforeDate = date('Y-m-d', strtotime('+' . $productDetails->product->default_best_before_days_after_freezing . ' days'));
}
// Product was moved from a freezer to non-freezer location -> thaw
// Product was moved from a freezer to non-freezer location -> thaw
if (intval($locationFrom->is_freezer) === 1 && intval($locationTo->is_freezer) === 0 && $productDetails->product->default_best_before_days_after_thawing > 0)
{
$newBestBeforeDate = date('Y-m-d', strtotime('+' . $productDetails->product->default_best_before_days_after_thawing . ' days'));
}
}
$correlationId = uniqid();
if ($amount >= $stockEntry->amount) // Take the whole stock entry
{
if ($amount >= $stockEntry->amount)
{ // Take the whole stock entry
$logRowForLocationFrom = $this->getDatabase()->stock_log()->createRow([
'product_id' => $stockEntry->product_id,
'amount' => $stockEntry->amount * -1,
@@ -968,8 +941,8 @@ class StockService extends BaseService
$amount -= $stockEntry->amount;
}
else // Stock entry amount is > than needed amount -> split the stock entry resp. update the amount
{
else
{ // Stock entry amount is > than needed amount -> split the stock entry resp. update the amount
$restStockAmount = $stockEntry->amount - $amount;
$logRowForLocationFrom = $this->getDatabase()->stock_log()->createRow([
@@ -1026,7 +999,6 @@ class StockService extends BaseService
$amount = 0;
}
}
return $this->getDatabase()->lastInsertId();
@@ -1041,7 +1013,7 @@ class StockService extends BaseService
throw new \Exception('Booking does not exist or was already undone');
}
// Undo all correlated bookings first, in order from newest first to the oldest
// Undo all correlated bookings first, in order from newest first to the oldest
if (!$skipCorrelatedBookings && !empty($logRow->correlation_id))
{
$correlatedBookings = $this->getDatabase()->stock_log()->where('undone = 0 AND correlation_id = :1', $logRow->correlation_id)->orderBy('id', 'DESC')->fetchAll();
@@ -1122,7 +1094,7 @@ class StockService extends BaseService
}
elseif ($logRow->transaction_type === self::TRANSACTION_TYPE_TRANSFER_FROM)
{
// Add corresponding amount back to stock or
// Add corresponding amount back to stock or
// create a row if missing
$stockRow = $this->getDatabase()->stock()->where('stock_id = :1 AND location_id = :2', $logRow->stock_id, $logRow->location_id)->fetch();
@@ -1214,7 +1186,6 @@ class StockService extends BaseService
{
throw new \Exception('This booking cannot be undone');
}
}
public function UndoTransaction($transactionId)
@@ -1230,7 +1201,6 @@ class StockService extends BaseService
{
$this->UndoBooking($transactionBooking->id, true);
}
}
private function LoadBarcodeLookupPlugin()
@@ -1253,7 +1223,6 @@ class StockService extends BaseService
{
throw new \Exception("Plugin $pluginName was not found");
}
}
private function LocationExists($locationId)
@@ -1273,5 +1242,4 @@ class StockService extends BaseService
$shoppingListRow = $this->getDatabase()->shopping_lists()->where('id = :1', $listId)->fetch();
return $shoppingListRow !== null;
}
}

View File

@@ -46,5 +46,4 @@ class TasksService extends BaseService
$taskRow = $this->getDatabase()->tasks()->where('id = :1', $taskId)->fetch();
return $taskRow !== null;
}
}

View File

@@ -5,27 +5,16 @@ namespace Grocy\Services;
class UserfieldsService extends BaseService
{
const USERFIELD_TYPE_CHECKBOX = 'checkbox';
const USERFIELD_TYPE_DATE = 'date';
const USERFIELD_TYPE_DATETIME = 'datetime';
const USERFIELD_TYPE_DECIMAL_NUMBER = 'number-decimal';
const USERFIELD_TYPE_FILE = 'file';
const USERFIELD_TYPE_IMAGE = 'image';
const USERFIELD_TYPE_INTEGRAL_NUMBER = 'number-integral';
const USERFIELD_TYPE_LINK = 'link';
const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist';
const USERFIELD_TYPE_PRESET_LIST = 'preset-list';
const USERFIELD_TYPE_SINGLE_LINE_TEXT = 'text-single-line';
const USERFIELD_TYPE_SINGLE_MULTILINE_TEXT = 'text-multi-line';
protected $OpenApiSpec = null;
@@ -117,14 +106,14 @@ class UserfieldsService extends BaseService
$alreadyExistingEntry = $this->getDatabase()->userfield_values()->where('field_id = :1 AND object_id = :2', $fieldId, $objectId)->fetch();
if ($alreadyExistingEntry) // Update
{
if ($alreadyExistingEntry)
{ // Update
$alreadyExistingEntry->update([
'value' => $value
]);
}
else // Insert
{
else
{ // Insert
$newRow = $this->getDatabase()->userfield_values()->createRow([
'field_id' => $fieldId,
'object_id' => $objectId,
@@ -132,9 +121,7 @@ class UserfieldsService extends BaseService
]);
$newRow->save();
}
}
}
public function __construct()
@@ -156,5 +143,4 @@ class UserfieldsService extends BaseService
{
return in_array($entity, $this->GetEntities());
}
}

View File

@@ -62,7 +62,6 @@ class UsersService extends BaseService
{
return null;
}
}
public function GetUserSettings($userId)
@@ -106,7 +105,6 @@ class UsersService extends BaseService
]);
$settingRow->save();
}
}
private function UserExists($userId)
@@ -114,5 +112,4 @@ class UsersService extends BaseService
$userRow = $this->getDatabase()->users()->where('id = :1', $userId)->fetch();
return $userRow !== null;
}
}