Fix formatting and whitespace

This commit is contained in:
Zeb Fross 2020-04-01 20:09:22 -07:00
parent ad0abe6b59
commit 8d0622cafa
6 changed files with 52 additions and 36 deletions

View File

@ -307,15 +307,23 @@ class StockApiController extends BaseApiController
} }
$default_location_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id'); $default_location_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id');
$default_qu_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_qu_id');
if (!$default_location_id) if (!$default_location_id)
{
$default_location_id = $this->getDatabase()->locations()->limit(1)->fetch()['id']; $default_location_id = $this->getDatabase()->locations()->limit(1)->fetch()['id'];
}
$default_qu_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_qu_id');
if (!$default_qu_id) if (!$default_qu_id)
{
$default_qu_id = $this->getDatabase()->quantity_units()->limit(1)->fetch()['id']; $default_qu_id = $this->getDatabase()->quantity_units()->limit(1)->fetch()['id'];
}
$shopping_location_id = null;
if (array_key_exists('shopping_location_id', $requestBody))
{
$shopping_location_id = $requestBody['shopping_location_id'];
}
$shopping_location_id = array_key_exists('shopping_location_id', $requestBody) ? $requestBody['shopping_location_id'] : null;
$parsedData = json_decode($requestBody['json-data'], true); $parsedData = json_decode($requestBody['json-data'], true);
$lastInsertId = $this->getStockService()->AddMultipleProducts($parsedData, $default_qu_id, $lastInsertId = $this->getStockService()->AddMultipleProducts($parsedData, $default_qu_id,

View File

@ -79,16 +79,24 @@ class StockController extends BaseController
$location_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id'); $location_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id');
$location = null; $location = null;
if ($location_id > 0) if ($location_id > 0)
{
$location = $this->getDatabase()->locations()->where('id', $location_id).fetch(); $location = $this->getDatabase()->locations()->where('id', $location_id).fetch();
}
else else
{
$location = $this->getDatabase()->locations()->limit(1)->fetch(); $location = $this->getDatabase()->locations()->limit(1)->fetch();
}
$qu_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id'); $qu_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id');
$quantity_unit = null; $quantity_unit = null;
if ($qu_id > 0) if ($qu_id > 0)
{
$quantity_unit = $this->getDatabase()->quantity_units()->where('id', $qui_id).fetch(); $quantity_unit = $this->getDatabase()->quantity_units()->where('id', $qui_id).fetch();
}
else else
{
$quantity_unit = $this->getDatabase()->quantity_units()->limit(1)->fetch(); $quantity_unit = $this->getDatabase()->quantity_units()->limit(1)->fetch();
}
return $this->renderPage($response, 'uploadjson', [ return $this->renderPage($response, 'uploadjson', [
'location' => $location, 'location' => $location,

View File

@ -6,10 +6,10 @@ class KrogerToGrocyConverter
{ {
// Fields returned: 'name', 'location_id', 'qu_id_purchase', 'qu_id_stock', // Fields returned: 'name', 'location_id', 'qu_id_purchase', 'qu_id_stock',
// 'qu_factor_purchase_to_stock', 'barcode', 'default_best_before_days' // 'qu_factor_purchase_to_stock', 'barcode', 'default_best_before_days'
// 'quantity', 'transaction_date', 'price_paid', 'picture_url' // 'quantity', 'transaction_date', 'price_paid', 'picture_url', 'min_stock_amount'
public static function ConvertJson($data, $default_quantity_units, $default_location_id) public static function ConvertJson($data, $default_quantity_units, $default_location_id)
{ {
if (array_key_exists("data", $data)) if ($data != null && array_key_exists("data", $data))
{ {
$data = $data['data']; $data = $data['data'];
} }

View File

@ -17,35 +17,35 @@ final class KrogerToGrocyConverterTest extends TestCase
$this->assertEquals( $this->assertEquals(
"0072220005165", "0072220005165",
KrogerToGrocyConverter::ConvertUpcToBarcode("0000007222000516") KrogerToGrocyConverter::ConvertUpcToBarcode("0000007222000516")
); );
$this->assertEquals( $this->assertEquals(
"0000000041300", "0000000041300",
KrogerToGrocyConverter::ConvertUpcToBarcode("0000000004130") KrogerToGrocyConverter::ConvertUpcToBarcode("0000000004130")
); );
} }
public function testConvertJson(): void public function testConvertJson(): void
{ {
$testjson = file_get_contents(dirname(__FILE__) . "/testdata/receipts.json"); $testjson = file_get_contents(dirname(__FILE__) . "/testdata/receipts.json");
$default_quantity_units = 3; $default_quantity_units = 3;
$default_location_id = 2; $default_location_id = 2;
$products = KrogerToGrocyConverter::ConvertJson(json_decode($testjson, true), $default_quantity_units, $default_location_id); $products = KrogerToGrocyConverter::ConvertJson(json_decode($testjson, true), $default_quantity_units, $default_location_id);
$expectedjson = file_get_contents(dirname(__FILE__) . "/testdata/receipts_expected.json"); $expectedjson = file_get_contents(dirname(__FILE__) . "/testdata/receipts_expected.json");
$expected = json_decode($expectedjson, true); $expected = json_decode($expectedjson, true);
$this->assertEquals(count($expected), count($products)); $this->assertEquals(count($expected), count($products));
foreach ($expected as $index => $product) foreach ($expected as $index => $product)
{ {
foreach ($product as $key => $value) foreach ($product as $key => $value)
{ {
$this->assertEquals($value, $products[$index][$key], "Failed matching key " . $key); $this->assertEquals($value, $products[$index][$key], "Failed matching key " . $key);
} }
} }
} }
} }
?> ?>

View File

@ -1,4 +1,4 @@
{ {
"Version": "2.6.3", "Version": "2.6.2",
"ReleaseDate": "2020-03-29" "ReleaseDate": "2020-03-29"
} }

View File

@ -209,7 +209,7 @@
@if(GROCY_FEATURE_FLAG_UPLOAD_JSON) @if(GROCY_FEATURE_FLAG_UPLOAD_JSON)
<li class="nav-item nav-item-sidebar" data-toggle="tooltip" data-placement="right" title="{{ $__t('Upload json') }}" data-nav-for-page="upload-json"> <li class="nav-item nav-item-sidebar" data-toggle="tooltip" data-placement="right" title="{{ $__t('Upload json') }}" data-nav-for-page="upload-json">
<a class="nav-link discrete-link" href="{{ $U('/uploadjson') }}"> <a class="nav-link discrete-link" href="{{ $U('/uploadjson') }}">
<i class="fas fa-fire"></i> <i class="fas fa-code"></i>
<span class="nav-link-text">{{ $__t('Upload Json') }}</span> <span class="nav-link-text">{{ $__t('Upload Json') }}</span>
</a> </a>
</li> </li>