public function checkForSalesItemEdit(SalesItem $salesItem, SalesItemDataTransferObject $dto)
 {
     $edit = null;
     $oldAttributes = [];
     $newAttributes = [];
     $reflectedObject = new \ReflectionObject($salesItem);
     $reflectedProperties = $reflectedObject->getProperties();
     foreach ($reflectedProperties as $reflectedProperty) {
         $propertyName = $reflectedProperty->getName();
         if ($propertyName !== 'bin' and property_exists($dto, $propertyName)) {
             $reflectedProperty->setAccessible(true);
             $liveValue = $reflectedProperty->getValue($salesItem);
             $value = $dto->{$propertyName};
             if ($liveValue !== $value) {
                 $oldAttributes[$propertyName] = (is_object($liveValue) and method_exists($liveValue, 'getId')) ? $liveValue->getId() : $liveValue;
                 $newAttributes[$propertyName] = (is_object($value) and method_exists($value, 'getId')) ? $value->getId() : $value;
             }
         }
     }
     if (count($oldAttributes) > 0) {
         $edit = new InventorySalesItemEdit();
         $edit->setSalesItem($salesItem);
         $edit->setByUser($this->getUser());
         $edit->setEditedAt(new \DateTime());
         $edit->setOldAttributes($oldAttributes);
         $edit->setNewAttributes($newAttributes);
         $this->getDoctrine()->getManager()->persist($edit);
     }
     return $edit;
 }
 public function getLogEntityForSalesItem(SalesItem $salesItem, User $user)
 {
     switch ($this->type) {
         case 'edit':
             $logEntity = new InventorySalesItemEdit();
             $logEntity->setOldAttributes($this->oldAttributes);
             $logEntity->setNewAttributes($this->newAttributes);
             $logEntity->setEditedAt(new \DateTime());
             $logEntity->setByUser($user);
             $logEntity->setSalesItem($salesItem);
             return $logEntity;
         case 'move':
             $logEntity = new InventorySalesItemMovement();
             $logEntity->fromBin($this->fromBin);
             $logEntity->toBin($this->toBin);
             $logEntity->setMovedAt(new \DateTime());
             $logEntity->setByUser($user);
             $logEntity->setSalesItem($salesItem);
             return $logEntity;
         default:
             throw new \Exception("Must Supply a type('edit','move') for a Mass Sales Item Update");
     }
 }