Formatting

This commit is contained in:
Marc Ole Bulling 2021-01-15 14:32:52 +01:00
parent 283962b8af
commit 1c1adc5f89
No known key found for this signature in database
GPG Key ID: C126AFC2A47B06FF

View File

@ -941,8 +941,10 @@ class StockService extends BaseService
* @return string[] Returns an array in the format "[amount] [name of product]"
* @throws \Exception
*/
public function GetShoppinglistInPrintableStrings($listId = 1): array {
if (!$this->ShoppingListExists($listId)) {
public function GetShoppinglistInPrintableStrings($listId = 1): array
{
if (!$this->ShoppingListExists($listId))
{
throw new \Exception('Shopping list does not exist');
}
@ -953,39 +955,50 @@ class StockService extends BaseService
$product = $this->getDatabase()->products()->where('id = :1', $row->product_id)->fetch();
$conversion = $this->getDatabase()->quantity_unit_conversions_resolved()->where('product_id = :1 AND from_qu_id = :2 AND to_qu_id = :3', $product->id, $product->qu_id_stock, $row->qu_id)->fetch();
$factor = 1.0;
if ($conversion != null) {
if ($conversion != null)
{
$factor = floatval($conversion->factor);
}
$amount = round($row->amount * $factor);
$note = "";
if (GROCY_TPRINTER_PRINT_NOTES) {
if ($row->note != "") {
if (GROCY_TPRINTER_PRINT_NOTES)
{
if ($row->note != "")
{
$note = ' (' . $row->note . ')';
}
}
if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) {
if (GROCY_TPRINTER_PRINT_QUANTITY_NAME)
{
$quantityname = $row->qu_name;
if ($amount > 1) {
if ($amount > 1)
{
$quantityname = $row->qu_name_plural;
}
array_push($result_quantity, $amount . ' ' . $quantityname);
array_push($result_product, $row->product_name . $note);
} else {
}
else
{
array_push($result_quantity, $amount);
array_push($result_product, $row->product_name . $note);
}
}
//Add padding to look nicer
$maxlength = 1;
foreach ($result_quantity as $quantity) {
foreach ($result_quantity as $quantity)
{
if (strlen($quantity) > $maxlength)
{
$maxlength = strlen($quantity);
}
}
$result = array();
$length = count($result_quantity);
for ($i = 0; $i < $length; $i++) {
for ($i = 0; $i < $length; $i++)
{
$quantity = str_pad($result_quantity[$i], $maxlength);
array_push($result, $quantity . ' ' . $result_product[$i]);
array_push($result, $quantity . ' ' . $result_product[$i]);
}
return $result;
}