partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

PartDistributor.php (5831B)


      1 <?php
      2 
      3 namespace PartKeepr\PartBundle\Entity;
      4 
      5 use Doctrine\ORM\Mapping as ORM;
      6 use PartKeepr\CoreBundle\Entity\BaseEntity;
      7 use PartKeepr\DistributorBundle\Entity\Distributor;
      8 use PartKeepr\PartBundle\Exceptions\PackagingUnitOutOfRangeException;
      9 use Symfony\Component\Serializer\Annotation\Groups;
     10 use Symfony\Component\Validator\Constraints as Assert;
     11 
     12 /**
     13  * This class represents the link between a part and a distributor.
     14  *
     15  * @ORM\Entity
     16  */
     17 class PartDistributor extends BaseEntity
     18 {
     19     /**
     20      * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="distributors")
     21      *
     22      * @var Part
     23      */
     24     private $part;
     25 
     26     /**
     27      * @ORM\ManyToOne(targetEntity="PartKeepr\DistributorBundle\Entity\Distributor")
     28      * @Groups({"default"})
     29      */
     30     private $distributor;
     31 
     32     /**
     33      * The order number for the part and distributor.
     34      *
     35      * @ORM\Column(type="string",nullable=true)
     36      * @Groups({"default"})
     37      *
     38      * @var string
     39      */
     40     private $orderNumber;
     41 
     42     /**
     43      * Defines the packaging unit when ordering a part. Some items can't be ordered in a quantity of just one at
     44      * certain manufacturers.
     45      *
     46      * @ORM\Column(type="integer")
     47      * @Groups({"default"})
     48      *
     49      * @var int
     50      */
     51     private $packagingUnit;
     52 
     53     /**
     54      * Specifies the price of the part. Note that the price
     55      * needs to be per item, not per packaging unit.
     56      *
     57      * @ORM\Column(type="decimal",precision=13,scale=4,nullable=true)
     58      * @Groups({"default"})
     59      *
     60      * @var float
     61      */
     62     private $price;
     63 
     64     /**
     65      * Specifies the currency of the part.
     66      *
     67      * @ORM\Column(type="string", length=3,nullable=true)
     68      * @Groups({"default"})
     69      *
     70      * @Assert\Currency
     71      */
     72     private $currency;
     73 
     74     /**
     75      * The distributor's SKU (stock keeping unit) for the part.  Used with barcodes.
     76      *
     77      * @ORM\Column(type="string",nullable=true)
     78      * @Groups({"default"})
     79      *
     80      * @var string
     81      */
     82     private $sku;
     83 
     84     /**
     85      * Defines if the distributor is ignored for pricing calculations.
     86      *
     87      * @ORM\Column(type="boolean",nullable=true)
     88      * @Groups({"default"})
     89      *
     90      * @var bool
     91      */
     92     private $ignoreForReports = 0;
     93 
     94     /**
     95      * Creates a new part->distributor link. Initializes the packaging unit with a quantity of "1".
     96      */
     97     public function __construct()
     98     {
     99         $this->setPackagingUnit(1);
    100     }
    101 
    102     /**
    103      * @return bool
    104      */
    105     public function isIgnoreForReports()
    106     {
    107         return $this->ignoreForReports;
    108     }
    109 
    110     /**
    111      * @param bool $ignoreForReports
    112      */
    113     public function setIgnoreForReports($ignoreForReports)
    114     {
    115         $this->ignoreForReports = $ignoreForReports;
    116     }
    117 
    118     /**
    119      * @return mixed
    120      */
    121     public function getCurrency()
    122     {
    123         return $this->currency;
    124     }
    125 
    126     /**
    127      * @param mixed $currency
    128      */
    129     public function setCurrency($currency)
    130     {
    131         $this->currency = $currency;
    132     }
    133 
    134     /**
    135      * Returns the packaging unit.
    136      *
    137      * @return int The packaging unit
    138      */
    139     public function getPackagingUnit()
    140     {
    141         return $this->packagingUnit;
    142     }
    143 
    144     /**
    145      * Sets the packaging unit for a specific distributor.
    146      *
    147      * For example, some distributors only sell resistors in packs of 100, so you can't order just one. We use the
    148      * packagingUnit to calculate how many pieces will be delivered once ordered. So if your stock level falls below
    149      * the minimum (example: you would need to order 10 resistors), we suggest that you only order one resistor pack
    150      * instead of 10.
    151      *
    152      * @param int $packagingUnit The amount of items in one package
    153      *
    154      * @throws PackagingUnitOutOfRangeException When the packaging unit is less than 1
    155      */
    156     public function setPackagingUnit($packagingUnit)
    157     {
    158         $packagingUnit = intval($packagingUnit);
    159 
    160         if ($packagingUnit < 1) {
    161             throw new PackagingUnitOutOfRangeException();
    162         }
    163 
    164         $this->packagingUnit = $packagingUnit;
    165     }
    166 
    167     /**
    168      * Returns the part.
    169      *
    170      * @return Part The part
    171      */
    172     public function getPart()
    173     {
    174         return $this->part;
    175     }
    176 
    177     /**
    178      * Sets the part.
    179      *
    180      * @param Part $part The part
    181      */
    182     public function setPart(Part $part = null)
    183     {
    184         $this->part = $part;
    185     }
    186 
    187     /**
    188      * Returns the distributor.
    189      *
    190      * @return Distributor The distributor
    191      */
    192     public function getDistributor()
    193     {
    194         return $this->distributor;
    195     }
    196 
    197     /**
    198      * Sets the distributor.
    199      *
    200      * @param \PartKeepr\DistributorBundle\Entity\Distributor $distributor The distributor
    201      */
    202     public function setDistributor(Distributor $distributor)
    203     {
    204         $this->distributor = $distributor;
    205     }
    206 
    207     /**
    208      * Returns the order number.
    209      *
    210      * @return string The order number
    211      */
    212     public function getOrderNumber()
    213     {
    214         return $this->orderNumber;
    215     }
    216 
    217     /**
    218      * Sets the order number.
    219      *
    220      * @param string $orderNumber The order number
    221      */
    222     public function setOrderNumber($orderNumber)
    223     {
    224         $this->orderNumber = $orderNumber;
    225     }
    226 
    227     /**
    228      * Returns the price.
    229      */
    230     public function getPrice()
    231     {
    232         return $this->price;
    233     }
    234 
    235     /**
    236      * Sets the price.
    237      *
    238      * @param float $price
    239      */
    240     public function setPrice($price)
    241     {
    242         $this->price = $price;
    243     }
    244 
    245     /**
    246      * Returns the SKU (stock keeping unit).
    247      *
    248      * @return string The SKU
    249      */
    250     public function getSku()
    251     {
    252         return $this->sku;
    253     }
    254 
    255     /**
    256      * Sets the SKU (stock keeping unit).
    257      *
    258      * @param string $sku The SKU
    259      */
    260     public function setSku($sku)
    261     {
    262         $this->sku = $sku;
    263     }
    264 }