mirror of
https://github.com/grocy/grocy.git
synced 2026-04-06 21:06:15 +02:00
Added padding
This commit is contained in:
parent
2b3f0978b7
commit
283962b8af
|
|
@ -941,14 +941,13 @@ class StockService extends BaseService
|
||||||
* @return string[] Returns an array in the format "[amount] [name of product]"
|
* @return string[] Returns an array in the format "[amount] [name of product]"
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function GetShoppinglistInPrintableStrings($listId = 1): array
|
public function GetShoppinglistInPrintableStrings($listId = 1): array {
|
||||||
{
|
if (!$this->ShoppingListExists($listId)) {
|
||||||
if (!$this->ShoppingListExists($listId))
|
|
||||||
{
|
|
||||||
throw new \Exception('Shopping list does not exist');
|
throw new \Exception('Shopping list does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array();
|
$result_product = array();
|
||||||
|
$result_quantity = array();
|
||||||
$rowsShoppingListProducts = $this->getDatabase()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll();
|
$rowsShoppingListProducts = $this->getDatabase()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll();
|
||||||
foreach ($rowsShoppingListProducts as $row) {
|
foreach ($rowsShoppingListProducts as $row) {
|
||||||
$product = $this->getDatabase()->products()->where('id = :1', $row->product_id)->fetch();
|
$product = $this->getDatabase()->products()->where('id = :1', $row->product_id)->fetch();
|
||||||
|
|
@ -959,26 +958,35 @@ class StockService extends BaseService
|
||||||
}
|
}
|
||||||
$amount = round($row->amount * $factor);
|
$amount = round($row->amount * $factor);
|
||||||
$note = "";
|
$note = "";
|
||||||
if (GROCY_TPRINTER_PRINT_NOTES)
|
if (GROCY_TPRINTER_PRINT_NOTES) {
|
||||||
{
|
|
||||||
if ($row->note != "") {
|
if ($row->note != "") {
|
||||||
$note = ' (' . $row->note . ')';
|
$note = ' (' . $row->note . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GROCY_TPRINTER_PRINT_QUANTITY_NAME)
|
if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) {
|
||||||
{
|
|
||||||
$quantityname = $row->qu_name;
|
$quantityname = $row->qu_name;
|
||||||
if ($amount > 1)
|
if ($amount > 1) {
|
||||||
{
|
|
||||||
$quantityname = $row->qu_name_plural;
|
$quantityname = $row->qu_name_plural;
|
||||||
}
|
}
|
||||||
array_push($result, $amount . ' ' . $quantityname . ' ' . $row->product_name . $note);
|
array_push($result_quantity, $amount . ' ' . $quantityname);
|
||||||
}
|
array_push($result_product, $row->product_name . $note);
|
||||||
else
|
} else {
|
||||||
{
|
array_push($result_quantity, $amount);
|
||||||
array_push($result, $amount . ' ' . $row->product_name . $note);
|
array_push($result_product, $row->product_name . $note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Add padding to look nicer
|
||||||
|
$maxlength = 1;
|
||||||
|
foreach ($result_quantity as $quantity) {
|
||||||
|
if (strlen($quantity) > $maxlength)
|
||||||
|
$maxlength = strlen($quantity);
|
||||||
|
}
|
||||||
|
$result = array();
|
||||||
|
$length = count($result_quantity);
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$quantity = str_pad($result_quantity[$i], $maxlength);
|
||||||
|
array_push($result, $quantity . ' ' . $result_product[$i]);
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user