Example #1
0
 /**
  * Returns number opene invoices for entity.
  * 
  * @param RM_Holder_iHolderable $obEntity
  * @return bool
  */
 public function _checkInOtherOpenedInvoice(RM_Holder_Invoice $obInvoice, RM_Holder_iHolderable $obEntity)
 {
     $query = M('Db')->createQuery($this->_tables['invoice_item'] . ' ii')->what('*')->addTable($this->_tables['invoice'] . ' i')->where('ii.invoice_id = i.id AND ii.entity_id = ? ', $obEntity->id(), $obInvoice->id())->where('ii.invoice_id != ? AND ii.invoice_state NOT IN (?, ?, ?)', RM_Holder_Invoice_Item_State::KIT, RM_Holder_Invoice_Item_State::OTHER, RM_Holder_Invoice_Item_State::DEL)->where('i.is_deleted = ?', 0);
     return count(M('Store')->requestQuery(M('Store')->factoryObject(), $query)) > 0;
 }
Example #2
0
 /**
  * Enter description here...
  *
  * @param RM_Holder_iHolderable $obEquipment
  * @param RM_Holder_Object $obDestinationHolder
  * @return int
  */
 public function moveEntity(RM_Holder_iHolderable $obEntity, RM_Holder_Object $obDestinationHolder)
 {
     $obEntity->setHolder($obDestinationHolder);
     return $obEntity->save();
 }
Example #3
0
 /**
  * Remove equipment from invoice
  *
  * @param 		RM_Holder_iHolderable $obEntity
  * @return 		void
  */
 public function removeEntity(RM_Holder_iHolderable $obEntity)
 {
     if (!$this->canChangeItemState()) {
         return FALSE;
     }
     $this->_items();
     if ($this->is_deleted || $this->state == RM_Holder_Invoice_State::CLOSED) {
         throw new RM_Base_Exception_BadUsage(__METHOD__ . ' : change closed invoice');
     }
     if (!isset($this->_items[$obEntity->guidType()][$obEntity->id()])) {
         throw new RM_Base_Exception_BadUsage(__METHOD__ . ' : remove unknown entity');
     }
     if (!$this->_items[$obEntity->guidType()][$obEntity->id()]->changeState(RM_Holder_Invoice_Item_State::DEL)) {
         return FALSE;
     }
     $this->_items[$obEntity->guidType()][$obEntity->id()]->mdate = M('Date')->dbDateTime();
     if ($this->_items[$obEntity->guidType()][$obEntity->id()]->save()) {
         unset($this->_items[$obEntity->guidType()][$obEntity->id()]);
         $obEntity->setInvoice();
         $obEntity->save();
     }
     return TRUE;
 }
Example #4
0
 /**
  * Enter description here...
  *
  * @param RM_Holder_iHolderable $obEntity
  * @param RM_Holder_Object $obDestinationHolder
  */
 public function moveEntity(RM_Holder_iHolderable $obEntity, RM_Holder_Object $obDestinationHolder)
 {
     if ($obEntity->getHolder()->id() != $this->id) {
         throw new RM_Base_Exception_BadUsage(__METHOD__ . ' : equipment in other holder');
     }
     if (!isNull($obEntity->getInvoice())) {
         throw new RM_Base_Exception_BadUsage(__METHOD__ . ' : equipment in invoice ');
     }
     return $this->_access($obDestinationHolder)->moveEntity($obEntity, $obDestinationHolder);
 }
Example #5
0
 /**
  * Add entity to exists invoice between holders or, if necessary, create new invloice and add entity
  *
  * @param RM_Holder_iHolderable $obEntity
  * @param RM_Holder_Object $obDestinationHolder
  * 
  * @return bool
  */
 public function moveEntity(RM_Holder_iHolderable $obEntity, RM_Holder_Object $obDestinationHolder)
 {
     $obInvoice = M('Holder')->getInvoiceBetweenHoldersOrCreate($obEntity->getHolder(), $obDestinationHolder);
     return $obInvoice->addEntity($obEntity);
 }