Show shopping informations in part details

This commit is contained in:
Jan Böhmer 2019-08-02 12:17:56 +02:00
parent 855eace81d
commit c2b4d100f0
11 changed files with 250 additions and 44 deletions

View file

@ -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;
}

View file

@ -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
*

View file

@ -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;
}