/** * creates the contracts - no containers, just "shared" */ protected function _createSharedContracts() { $cNumber = 1; $container = $this->_contractController->getSharedContractsContainer(); $cid = $container->getId(); $ccs = array($this->_developmentCostCenter, $this->_marketingCostCenter); $i = 0; $this->_setReferenceDate(); $customers = Sales_Controller_Customer::getInstance()->getAll(); $addresses = Sales_Controller_Address::getInstance()->getAll(); $customersCount = $customers->count(); $ccIndex = 0; while ($i < $customersCount) { $costcenter = $ccs[$i % 2]; $i++; $customer = $customers->getByIndex($ccIndex); $address = $addresses->filter('customer_id', $customer->getId())->filter('type', 'billing')->getFirstRecord(); $addressId = $address ? $address->getId() : NULL; $title = self::$_de ? 'Vertrag für KST ' . $costcenter->number . ' - ' . $costcenter->remark : 'Contract for costcenter ' . $costcenter->number . ' - ' . $costcenter->remark . ' ' . Tinebase_Record_Abstract::generateUID(3); $ccid = $costcenter->getId(); $contract = new Sales_Model_Contract(array('number' => $cNumber, 'title' => $title, 'description' => 'Created by Tine 2.0 DemoData', 'container_id' => $cid, 'status' => 'OPEN', 'cleared' => 'NOT_YET_CLEARED', 'start_date' => clone $this->_referenceDate, 'billing_address_id' => $addressId)); $relations = array(array('own_model' => 'Sales_Model_Contract', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Sales_Model_CostCenter', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $ccid, 'type' => 'LEAD_COST_CENTER'), array('own_model' => 'Sales_Model_Contract', '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' => 'CUSTOMER')); $genericProduct = Sales_Controller_Product::getInstance()->create(new Sales_Model_Product(self::$_de ? array('name' => 'Generisches Produkt', 'description' => 'ein generisches produkt aus den demo daten', 'price' => 100) : array('name' => 'Generic Product', 'description' => 'this is a generic product used in demo data', 'price' => 100))); $contract->products = array(array('product_id' => $genericProduct->getId(), 'quantity' => 1)); $contract->relations = $relations; $this->_contractController->create($contract); $cNumber++; $ccIndex++; if ($ccIndex == $customersCount) { $ccIndex = 0; } } }
/** * Returns registry data of the application. * * Each application has its own registry to supply static data to the client. * Registry data is queried only once per session from the client. * * This registry must not be used for rights or ACL purposes. Use the generic * rights and ACL mechanisms instead! * * @return mixed array 'variable name' => 'data' */ public function getRegistryData() { $sharedContainer = Sales_Controller_Contract::getSharedContractsContainer(); $sharedContainer->resolveGrantsAndPath(); // defaultContainer is deprecated, use defaultContractContainer // todo: remove first if sure it works everywhere return array('defaultContainer' => $sharedContainer->toArray(), 'defaultContractContainer' => $sharedContainer->toArray()); }
/** * create new contract * */ public function testCreateContract() { $contract = $this->_getContract(); $created = $this->_backend->create($contract); $this->assertEquals($created->title, $contract->title); $this->assertGreaterThan(0, $created->number); $this->assertEquals($created->container_id, Sales_Controller_Contract::getSharedContractsContainer()->getId()); $this->_backend->delete($contract); $this->_decreaseNumber(); }
/** * get contract * * @return Sales_Model_Contract */ protected function _getContract() { $contract = new Sales_Model_Contract(array('title' => 'phpunit contract', 'description' => 'blabla'), TRUE); // add container $contract->container_id = Sales_Controller_Contract::getSharedContractsContainer(); // add number $numberBackend = new Sales_Backend_Number(); $number = $numberBackend->getNext('Sales_Model_Contract', Tinebase_Core::getUser()->getId()); $contract->number = $number->number; return $contract; }
/** * create contracts, auto add timeaccounts if there are any * * @param array $contractData * @return Tinebase_Record_RecordSet */ protected function _createContracts($contractData = NULL) { // 1.1.20xx $startDate = clone $this->_referenceDate; $endDate = clone $startDate; // 1.8.20xx $endDate->addMonth(7); $this->_contractController = Sales_Controller_Contract::getInstance(); $container = $this->_contractController->getSharedContractsContainer(); $this->_sharedContractsContainerId = $container->getId(); if (!$contractData) { if (!$this->_costcenterRecords) { $this->_createCostCenters(); } if (!$this->_productRecords) { $this->_createProducts(); } if (!$this->_customerRecords) { $this->_createCustomers(); } if (!$this->_timesheetRecords) { $this->_createTimesheets(); } $contractData = array(array('number' => 1, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '1 unittest begin', 'container_id' => $this->_sharedContractsContainerId, 'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer1')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId(), 'start_date' => clone $startDate, 'end_date' => NULL, 'products' => array(array('start_date' => $startDate, 'end_date' => NULL, 'quantity' => 1, 'interval' => 1, 'billing_point' => 'begin', 'product_id' => $this->_productRecords->filter('name', 'Hours')->getFirstRecord()->getId()))), array('number' => 2, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '2 unittest end', 'container_id' => $this->_sharedContractsContainerId, 'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer2')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId(), 'start_date' => clone $startDate, 'end_date' => clone $endDate, 'products' => array(array('start_date' => clone $startDate, 'end_date' => clone $endDate, 'quantity' => 1, 'interval' => 4, 'billing_point' => 'end', 'product_id' => $this->_productRecords->filter('name', 'Hours')->getFirstRecord()->getId()))), array('number' => 3, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '3 unittest end', 'container_id' => $this->_sharedContractsContainerId, 'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer3')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId(), 'start_date' => clone $startDate, 'end_date' => NULL, 'products' => array(array('start_date' => clone $startDate, 'end_date' => NULL, 'quantity' => 1, 'interval' => 3, 'billing_point' => 'end', 'product_id' => $this->_productRecords->filter('name', 'Hours')->getFirstRecord()->getId()))), array('number' => 4, 'title' => Tinebase_Record_Abstract::generateUID(), 'description' => '4 unittest products', 'container_id' => $this->_sharedContractsContainerId, 'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer4')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId(), 'start_date' => clone $startDate, 'end_date' => NULL, 'products' => array(array('start_date' => clone $startDate, 'end_date' => NULL, 'quantity' => 1, 'interval' => 6, 'billing_point' => 'begin', 'product_id' => $this->_productRecords->filter('name', 'billhalfyearly')->getFirstRecord()->getId()), array('start_date' => clone $startDate, 'end_date' => NULL, 'quantity' => 1, 'interval' => 3, 'billing_point' => 'begin', 'product_id' => $this->_productRecords->filter('name', 'billeachquarter')->getFirstRecord()->getId())))); } $this->_contractRecords = new Tinebase_Record_RecordSet('Sales_Model_Contract'); $i = 0; foreach ($contractData as $cd) { $costcenter = $this->_costcenterRecords->getByIndex($i); $customer = $this->_customerRecords->getByIndex($i); if ($this->_timeaccountRecords) { $timeaccount = $this->_timeaccountRecords->getByIndex($i); } $i++; $contract = new Sales_Model_Contract($cd); $contract->setTimezone('UTC'); $contract->relations = array(array('own_model' => 'Sales_Model_Contract', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Sales_Model_CostCenter', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $costcenter->getId(), 'type' => 'LEAD_COST_CENTER'), array('own_model' => 'Sales_Model_Contract', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Sales_Model_Customer', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $customer->getId(), 'type' => 'CUSTOMER')); if ($this->_timeaccountRecords) { $contract->relations = array_merge($contract->relations, array(array('own_model' => 'Sales_Model_Contract', 'own_backend' => Tasks_Backend_Factory::SQL, 'own_id' => NULL, 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Timetracker_Model_Timeaccount', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $timeaccount->getId(), 'type' => 'TIME_ACCOUNT'))); } $this->_contractRecords->addRecord($this->_contractController->create($contract)); } return $this->_contractRecords; }
/** * try to get an empty contract */ public function testGetEmptyContract() { $contractData = $this->_instance->getContract(0); $this->assertEquals(Sales_Controller_Contract::getSharedContractsContainer()->getId(), $contractData['container_id']['id']); }
/** * Returns registry data of the application. * * Each application has its own registry to supply static data to the client. * Registry data is queried only once per session from the client. * * This registry must not be used for rights or ACL purposes. Use the generic * rights and ACL mechanisms instead! * * @return mixed array 'variable name' => 'data' */ public function getRegistryData() { $sharedContainer = Sales_Controller_Contract::getSharedContractsContainer(); $sharedContainer->resolveGrantsAndPath(); return array('defaultContainer' => $sharedContainer->toArray()); }