/**
  * checks if the number is always set to the correct value
  */
 public function testNumberable()
 {
     $controller = Sales_Controller_OrderConfirmation::getInstance();
     $record = $controller->create(new Sales_Model_OrderConfirmation(array('title' => 'auto1')));
     $this->assertEquals('AB-00001', $record->number);
     $record = $controller->create(new Sales_Model_OrderConfirmation(array('title' => 'auto2')));
     $this->assertEquals('AB-00002', $record->number);
     // set number to 4, should return the formatted number
     $record = $controller->create(new Sales_Model_OrderConfirmation(array('title' => 'manu1', 'number' => 4)));
     $this->assertEquals('AB-00004', $record->number);
     // the next number should be a number after the manual number
     $record = $controller->create(new Sales_Model_OrderConfirmation(array('title' => 'auto3')));
     $this->assertEquals('AB-00005', $record->number);
     // the user manually set this numer, so this should be corrected
     $record = $controller->create(new Sales_Model_OrderConfirmation(array('title' => 'manu1', 'number' => 'AB-100')));
     $this->assertEquals('AB-00100', $record->number);
 }
 /**
  * deletes existing records
  *
  * @param  array $ids
  * @return string
  */
 public function deleteOrderConfirmations($ids)
 {
     return $this->_delete($ids, Sales_Controller_OrderConfirmation::getInstance());
 }
 /**
  * transfers all contracts starting with AB- to orderconfirmation
  */
 public function transferContractsToOrderConfirmation()
 {
     if (!Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_ORDERCONFIRMATIONS_MODULE)) {
         Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' transferContractsToOrderConfirmation ran allthoug feature ' . Sales_Config::FEATURE_ORDERCONFIRMATIONS_MODULE . ' is disabled');
         return false;
     }
     $contractController = Sales_Controller_Contract::getInstance();
     $ocController = Sales_Controller_OrderConfirmation::getInstance();
     $rel = Tinebase_Relations::getInstance();
     $filter = new Sales_Model_ContractFilter(array(array('field' => 'number', 'operator' => 'startswith', 'value' => 'AB-')), 'AND');
     $contracts = $contractController->search($filter);
     foreach ($contracts as $contract) {
         $oc = $ocController->create(new Sales_Model_OrderConfirmation(array('number' => $contract->number, 'title' => $contract->title, 'description' => '')));
         $rel->setRelations('Sales_Model_OrderConfirmation', 'Sql', $oc->getId(), array(array('related_degree' => 'sibling', 'related_degree' => 'sibling', 'related_model' => 'Sales_Model_Contract', 'related_backend' => 'Sql', 'related_id' => $contract->getId(), 'type' => 'CONTRACT')));
     }
 }
 /**
  * the singleton pattern
  *
  * @return Sales_Controller_OrderConfirmation
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * transfers all contracts starting with AB- to orderconfirmation
  */
 public function transferContractsToOrderConfirmation()
 {
     $contractController = Sales_Controller_Contract::getInstance();
     $ocController = Sales_Controller_OrderConfirmation::getInstance();
     $rel = Tinebase_Relations::getInstance();
     $filter = new Sales_Model_ContractFilter(array(array('field' => 'number', 'operator' => 'startswith', 'value' => 'AB-')), 'AND');
     $contracts = $contractController->search($filter);
     foreach ($contracts as $contract) {
         $oc = $ocController->create(new Sales_Model_OrderConfirmation(array('number' => $contract->number, 'title' => $contract->title, 'description' => '')));
         $rel->setRelations('Sales_Model_OrderConfirmation', 'Sql', $oc->getId(), array(array('own_degree' => 'sibling', 'related_degree' => 'sibling', 'related_model' => 'Sales_Model_Contract', 'related_backend' => 'Sql', 'related_id' => $contract->getId(), 'type' => 'CONTRACT')));
     }
 }
 /**
  * creates some offers
  */
 protected function _createSharedOffers()
 {
     $i = 0;
     $this->_setReferenceDate();
     $customers = Sales_Controller_Customer::getInstance()->getAll('number');
     $orderconfirmations = Sales_Controller_OrderConfirmation::getInstance()->getAll('number');
     foreach ($customers as $customer) {
         $oc = $orderconfirmations->getByIndex($i);
         $i++;
         $relations = array(array('own_model' => 'Sales_Model_Offer', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Sales_Model_Customer', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $customer->getId(), 'type' => 'OFFER'), array('own_model' => 'Sales_Model_Offer', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Sales_Model_OrderConfirmation', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $oc->getId(), 'type' => 'OFFER'));
         $customer = $customers->getById($relation->own_id);
         $offer = Sales_Controller_Offer::getInstance()->create(new Sales_Model_Offer(array('number' => $i, 'title' => self::$_de ? 'Angebot für Kunde ' . $customer->name : 'Offer for Customer' . $customer->name, 'description' => 'Created by Tine 2.0 DemoData', 'relations' => $relations)));
     }
 }