/** * add one record * * @param Tinebase_Record_Interface $_record * @return Sales_Model_Contract */ public function create(Tinebase_Record_Interface $_record) { // add container $_record->container_id = self::getSharedContractsContainer()->getId(); // add number $numberBackend = new Sales_Backend_Number(); $number = $numberBackend->getNext(Sales_Model_Number::TYPE_CONTRACT, $this->_currentAccount->getId()); $_record->number = $number->number; return parent::create($_record); }
/** * decrease contracts number * */ protected function _decreaseNumber() { $numberBackend = new Sales_Backend_Number(); $number = $numberBackend->getNext('Sales_Model_Contract', Tinebase_Core::getUser()->getId()); // reset or delete old number if ($number->number == 2) { $numberBackend->delete($number); } else { $number->number -= 2; $numberBackend->update($number); } }
/** * get next number * */ public function testGetNextNumber() { $userId = Tinebase_Core::getUser()->getId(); $number = $this->_backend->getNext(Sales_Model_Number::TYPE_CONTRACT, $userId); $nextNumber = $this->_backend->getNext(Sales_Model_Number::TYPE_CONTRACT, $userId); $this->assertEquals($number->number + 1, $nextNumber->number); $this->assertEquals($number->type, $nextNumber->type); // reset or delete old number if ($number->number == 1) { $this->_backend->delete($number); } else { $number->number--; $this->_backend->update($number); } }
/** * get next number */ public function testGetNextNumber() { $userId = Tinebase_Core::getUser()->getId(); $number = $this->_backend->getNext('Sales_Model_Contract', $userId); $nextNumber = $this->_backend->getNext('Sales_Model_Contract', $userId); $this->assertEquals($number->number + 1, $nextNumber->number); $this->assertEquals($number->model, $nextNumber->model); // reset or delete old number if ($number->number == 1) { $this->_backend->delete($number); } else { $number->number--; $this->_backend->update($number); } }
/** * sets the last number by a given record, if the number has been manually set * * @param Tinebase_Record_Interface $record */ protected function _setLastNumber($record) { $numberBackend = new Sales_Backend_Number(); $number = $numberBackend->getCurrent($this->_modelName); $this->_removePrefix($record); if (intval($record->{$this->_numberProperty}) > $number) { $numberBackend->setCurrent($this->_modelName, $record->{$this->_numberProperty}); } $this->_formatNumber($record); }