/** * the singleton pattern * * @return Sales_Controller_Supplier */ public static function getInstance() { if (self::$_instance === NULL) { self::$_instance = new self(); } return self::$_instance; }
/** * export suppliers * * @param string $filter JSON encoded string with employee ids for multi export or employee filter * @param string $options format or export definition id */ public function exportSuppliers($filter, $options) { $decodedFilter = Zend_Json::decode($filter); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Export filter: ' . print_r($decodedFilter, TRUE)); } if (!is_array($decodedFilter)) { $decodedFilter = array(array('field' => 'id', 'operator' => 'equals', 'value' => $decodedFilter)); } $filter = new Sales_Model_SupplierFilter($decodedFilter); parent::_export($filter, Zend_Json::decode($options), Sales_Controller_Supplier::getInstance()); }
/** * checks if the number is always set to the correct value */ public function testNumberable() { $controller = Sales_Controller_Supplier::getInstance(); $record = $controller->create(new Sales_Model_Supplier(array('name' => 'auto1'))); $this->assertGreaterThan(0, $record->number); $initialNumber = $record->number; $record = $controller->create(new Sales_Model_Supplier(array('name' => 'auto2'))); $this->assertEquals($initialNumber + 1, $record->number); // set number to $initialNumber + 3, should return the formatted number $record = $controller->create(new Sales_Model_Supplier(array('name' => 'manu1', 'number' => $initialNumber + 3))); $this->assertEquals($initialNumber + 3, $record->number); // the next number should be a number after the manual number $record = $controller->create(new Sales_Model_Supplier(array('name' => 'auto3'))); $this->assertEquals($initialNumber + 4, $record->number); }
/** * deletes existing records * * @param array $ids * @return string */ public function deleteSuppliers($ids) { return $this->_delete($ids, Sales_Controller_Supplier::getInstance()); }
/** * resolve address records before setting headers, so we know how much addresses exist * * @param Sales_Model_SupplierFilter $filter * @param Sales_Controller_Supplier $controller */ protected function _resolveAddresses($filter, $controller) { $suppliers = $controller->search($filter); $supplierIds = $suppliers->id; $contactIds = array_unique(array_merge($suppliers->cpextern_id, $suppliers->cpintern_id)); unset($suppliers); $be = new Sales_Backend_Address(); $this->_specialFieldDefinitions = array(array('header' => 'Postal Address', 'identifier' => 'postal_address', 'type' => 'postal')); $filter = new Sales_Model_AddressFilter(array()); $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'customer_id', 'operator' => 'in', 'value' => $supplierIds))); $this->_addresses = $be->search($filter); $this->_contacts = Addressbook_Controller_Contact::getInstance()->getMultiple($contactIds); }