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_qu_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_qu_id');
if (!$default_location_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)
{
$default_qu_id = $this->getDatabase()->quantity_units()->limit(1)->fetch()['id'];
}
$shopping_location_id = array_key_exists('shopping_location_id', $requestBody) ? $requestBody['shopping_location_id'] : null;
$shopping_location_id = null;
if (array_key_exists('shopping_location_id', $requestBody))
{
$shopping_location_id = $requestBody['shopping_location_id'];
}
$parsedData = json_decode($requestBody['json-data'], true);
$lastInsertId = $this->getStockService()->AddMultipleProducts($parsedData, $default_qu_id,

View File

@ -73,23 +73,31 @@ class StockController extends BaseController
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function UploadJson(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$location_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id');
$location = null;
if ($location_id > 0)
{
$location = $this->getDatabase()->locations()->where('id', $location_id).fetch();
}
else
{
$location = $this->getDatabase()->locations()->limit(1)->fetch();
}
$qu_id = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, 'product_presets_location_id');
$quantity_unit = null;
if ($qu_id > 0)
{
$quantity_unit = $this->getDatabase()->quantity_units()->where('id', $qui_id).fetch();
}
else
{
$quantity_unit = $this->getDatabase()->quantity_units()->limit(1)->fetch();
}
return $this->renderPage($response, 'uploadjson', [
'location' => $location,
'quantityunit' => $quantity_unit,

View File

@ -6,10 +6,10 @@ class KrogerToGrocyConverter
{
// Fields returned: 'name', 'location_id', 'qu_id_purchase', 'qu_id_stock',
// '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)
{
if (array_key_exists("data", $data))
if ($data != null && array_key_exists("data", $data))
{
$data = $data['data'];
}

View File

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

View File

@ -209,7 +209,7 @@
@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">
<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>
</a>
</li>