mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-07 19:49:30 +00:00
Show shopping informations in part details
This commit is contained in:
parent
855eace81d
commit
c2b4d100f0
11 changed files with 250 additions and 44 deletions
|
|
@ -33,6 +33,8 @@ declare(strict_types=1);
|
|||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class Orderdetail.
|
||||
|
|
@ -79,6 +81,12 @@ class Orderdetail extends DBElement
|
|||
*/
|
||||
protected $supplier_product_url;
|
||||
|
||||
/**
|
||||
* @var \DateTime The date when this element was created.
|
||||
* @ORM\Column(type="datetimetz", name="datetime_added")
|
||||
*/
|
||||
protected $addedDate;
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
|
|
@ -142,6 +150,17 @@ class Orderdetail extends DBElement
|
|||
return (bool) $this->obsolete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date/time when the element was created.
|
||||
* Returns null if the element was not yet saved to DB yet.
|
||||
*
|
||||
* @return \DateTime|null The creation time of the part.
|
||||
*/
|
||||
public function getAddedDate(): ?\DateTime
|
||||
{
|
||||
return $this->addedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to the website of the article on the suppliers website.
|
||||
*
|
||||
|
|
@ -152,8 +171,8 @@ class Orderdetail extends DBElement
|
|||
*/
|
||||
public function getSupplierProductUrl(bool $no_automatic_url = false): string
|
||||
{
|
||||
if ($no_automatic_url || '' !== $this->supplierpartnr) {
|
||||
return $this->supplierpartnr;
|
||||
if ($no_automatic_url || '' !== $this->supplier_product_url) {
|
||||
return $this->supplier_product_url;
|
||||
}
|
||||
|
||||
return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr); // maybe an automatic url is available...
|
||||
|
|
@ -162,12 +181,12 @@ class Orderdetail extends DBElement
|
|||
/**
|
||||
* Get all pricedetails.
|
||||
*
|
||||
* @return Pricedetails[] all pricedetails as a one-dimensional array of Pricedetails objects,
|
||||
* @return Pricedetail[] all pricedetails as a one-dimensional array of Pricedetails objects,
|
||||
* sorted by minimum discount quantity
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getPricedetails(): array
|
||||
public function getPricedetails(): PersistentCollection
|
||||
{
|
||||
return $this->pricedetails;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class Part extends AttachmentContainingDBElement
|
|||
protected $master_picture_attachment;
|
||||
|
||||
/**
|
||||
* @var
|
||||
* @var Orderdetail[]
|
||||
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="part")
|
||||
*
|
||||
* @ColumnSecurity(prefix="orderdetails", type="object")
|
||||
|
|
@ -499,7 +499,7 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
|
||||
*
|
||||
* @return Orderdetails[] * all orderdetails as a one-dimensional array of Orderdetails objects
|
||||
* @return Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
|
||||
* (empty array if there are no ones)
|
||||
* * the array is sorted by the suppliers names / minimum order quantity
|
||||
*
|
||||
|
|
|
|||
|
|
@ -95,31 +95,27 @@ class Pricedetail extends DBElement
|
|||
return $this->orderdetail;
|
||||
}
|
||||
|
||||
public function getPrice() : float
|
||||
{
|
||||
return (float) $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price.
|
||||
* Get the price for a single unit.
|
||||
*
|
||||
* @param bool $as_money_string * if true, this method returns a money string incl. currency
|
||||
* * if false, this method returns the price as float
|
||||
* @param int $multiplier The returned price (float or string) will be multiplied
|
||||
* with this multiplier.
|
||||
*
|
||||
* You will get the price for $multiplier parts. If you want the price which is stored
|
||||
* in the database, you have to pass the "price_related_quantity" count as $multiplier.
|
||||
*
|
||||
* @return float the price as a float number (if "$as_money_string == false")
|
||||
* @return string the price as a string incl. currency (if "$as_money_string == true")
|
||||
*
|
||||
* @see floatToMoneyString()
|
||||
* @return float the price as a float number
|
||||
|
||||
*/
|
||||
public function getPrice(bool $as_money_string = false, int $multiplier = 1)
|
||||
public function getPricePerUnit(int $multiplier = 1) : float
|
||||
{
|
||||
$price = ($this->price * $multiplier) / $this->price_related_quantity;
|
||||
|
||||
if ($as_money_string) {
|
||||
throw new \Exception('Not implemented yet...');
|
||||
//return floatToMoneyString($price);
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
|
|
|
|||
59
src/Services/MoneyFormatter.php
Normal file
59
src/Services/MoneyFormatter.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||
* http://code.google.com/p/part-db/
|
||||
*
|
||||
* Part-DB Version 0.4+
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* https://github.com/jbtronics
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use Gerardojbaez\Money\Money;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
|
||||
|
||||
class MoneyFormatter
|
||||
{
|
||||
|
||||
private $params;
|
||||
|
||||
public function __construct(ContainerBagInterface $params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function format($amount, string $currency = "") : string
|
||||
{
|
||||
if ($currency === "") {
|
||||
$currency = $this->params->get("default_currency");
|
||||
}
|
||||
|
||||
$money = new Money($amount, $currency);
|
||||
|
||||
return $money->format();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ namespace App\Twig;
|
|||
use App\Entity\Attachment;
|
||||
use App\Entity\DBElement;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\MoneyFormatter;
|
||||
use App\Services\TreeBuilder;
|
||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
|
@ -47,22 +48,26 @@ class AppExtension extends AbstractExtension
|
|||
protected $cache;
|
||||
protected $serializer;
|
||||
protected $treeBuilder;
|
||||
protected $moneyFormatter;
|
||||
|
||||
public function __construct(EntityURLGenerator $entityURLGenerator, AdapterInterface $cache,
|
||||
SerializerInterface $serializer, TreeBuilder $treeBuilder)
|
||||
SerializerInterface $serializer, TreeBuilder $treeBuilder,
|
||||
MoneyFormatter $moneyFormatter)
|
||||
{
|
||||
$this->entityURLGenerator = $entityURLGenerator;
|
||||
$this->cache = $cache;
|
||||
$this->serializer = $serializer;
|
||||
$this->treeBuilder = $treeBuilder;
|
||||
$this->moneyFormatter = $moneyFormatter;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('entityURL', [$this, 'generateEntityURL']),
|
||||
new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
];
|
||||
new TwigFilter('entityURL', [$this, 'generateEntityURL']),
|
||||
new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
new TwigFilter('moneyFormat', [$this, 'formatCurrency'])
|
||||
];
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
|
|
@ -107,4 +112,9 @@ class AppExtension extends AbstractExtension
|
|||
|
||||
return $item->get();
|
||||
}
|
||||
|
||||
public function formatCurrency($amount, $currency = "")
|
||||
{
|
||||
return $this->moneyFormatter->format($amount, $currency);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue