public function testLifecycleSupplier() { $retVal = $this->_createSupplier(); $this->assertEquals(4294967, $retVal["number"]); $this->assertEquals("Worldwide Electronics International", $retVal["name"]); $this->assertEquals("http://wwei.cn", $retVal["url"]); $this->assertEquals(NULL, $retVal['description']); $this->assertEquals('Yiting', $retVal['cpextern_id']['n_given']); $this->assertEquals('Huang', $retVal['cpextern_id']['n_family']); $this->assertEquals('Hans Friedrich', $retVal['cpintern_id']['n_given']); $this->assertEquals('Ochs', $retVal['cpintern_id']['n_family']); // delete record (set deleted=1) of customer and assigned addresses $this->_json->deleteSuppliers(array($retVal['id'])); $customerBackend = new Sales_Backend_Supplier(); $deletedSupplier = $customerBackend->get($retVal['id'], TRUE); $this->assertEquals(1, $deletedSupplier->is_deleted); $addressBackend = new Sales_Backend_Address(); $deletedAddresses = $addressBackend->getMultipleByProperty($retVal['id'], 'customer_id', TRUE); $this->assertEquals(1, $deletedAddresses->count()); foreach ($deletedAddresses as $address) { $this->assertEquals(1, $address->is_deleted); } $this->setExpectedException('Tinebase_Exception_NotFound'); return $this->_json->getSupplier($retVal['id']); }
/** * tests if a product interval of 36 is possible and if an empty string gets converted to null */ public function testContract() { $product = Sales_Controller_Product::getInstance()->create($this->_getProduct()); $contract = array('id' => NULL, 'number' => 1, 'title' => 'test123', 'products' => array(array('product_id' => $product->getId(), 'interval' => 36, 'billing_point' => 'begin', 'quantity' => ''))); $contract = $this->_instance->saveContract($contract); $this->assertEquals(NULL, $contract['products'][0]['quantity']); $this->assertEquals(36, $contract['products'][0]['interval']); }
/** * testGetRegistryData (shared contracts container) */ public function testGetRegistryData() { $data = $this->_instance->getRegistryData(); $this->assertTrue(isset($data['defaultContainer'])); $this->assertTrue(isset($data['defaultContainer']['path'])); $this->assertTrue(isset($data['defaultContainer']['account_grants'])); $this->assertTrue(is_array($data['defaultContainer']['account_grants'])); }
/** * try to delete a PurchaseInvoice */ public function testDeletePurchaseInvoice() { $purchase = $this->_createPurchaseInvoice(); $this->assertEquals('R-12345', $purchase['number']); // delete record $this->_json->deletePurchaseInvoices($purchase['id']); $this->setExpectedException('Tinebase_Exception_NotFound'); $customerBackend = new Sales_Backend_PurchaseInvoice(); $deletedPurchase = $customerBackend->get($purchase['id'], TRUE); $this->assertEquals(1, $deletedPurchase->is_deleted); }
/** * @see 0011494: activate advanced search for contracts (customers, ...) */ public function testAdvancedContractsSearch() { Tinebase_Core::getPreference()->setValue(Tinebase_Preference::ADVANCED_SEARCH, true); $contract = Sales_Controller_Contract::getInstance()->create($this->_getContract()); list($contact1) = $this->_createContacts(1); $this->_setContractRelations($contract, array($contact1), 'RESPONSIBLE'); $result = $this->_instance->searchContracts($this->_getFilter('wolf'), array()); $this->assertEquals(1, $result['totalcount'], 'should find contract of customer person Peter Wolf'); // test notcontains $contract2 = Sales_Controller_Contract::getInstance()->create($this->_getContract('test2')); $result = $this->_instance->searchContracts($this->_getFilter(), array()); $this->assertEquals(2, $result['totalcount'], 'should find 2 contracts'); // search with notcontains $search = $this->_instance->searchContracts(array(array('field' => 'query', 'operator' => 'notcontains', 'value' => 'wolf')), $this->_getPaging()); $this->assertEquals($contract2->title, $search['results'][0]['title']); $this->assertEquals(1, $search['totalcount']); }
/** * make sure that timesheets get created for the right month */ public function test2MonthIntervalTimesheetOnMonthEndAndBegin() { $dates = array(clone $this->_referenceDate, clone $this->_referenceDate, clone $this->_referenceDate, clone $this->_referenceDate); // 0: 1.1.xxxx, 1: 31.1.xxxx, 2: 1.2.xxxx, 3: 28/29.2.xxxx $dates[1]->addMonth(1)->subDay(1); $dates[2]->addMonth(1); $dates[3]->addMonth(2)->subDay(1); // create much more timesheets $dt = clone $this->_referenceDate; for ($i = 0; $i < 80; $i++) { $dt->addHour(12); $dates[] = clone $dt; } $customer = $this->_createCustomers(1)->getFirstRecord(); $this->_createCostCenters(); // has no budget $ta = $this->_createTimeaccounts(array(array('title' => 'TaTest', 'description' => 'blabla', 'is_open' => 1, 'status' => 'not yet billed', 'budget' => null)))->getFirstRecord(); foreach ($dates as $date) { $this->_createTimesheets(array(array('account_id' => Tinebase_Core::getUser()->getId(), 'timeaccount_id' => $ta->getId(), 'start_date' => $date, 'duration' => 105, 'description' => 'ts from ' . (string) $date))); } $this->assertEquals(84, $this->_timesheetRecords->count()); $this->_createProducts(); $csDate = clone $this->_referenceDate; $csDate->subMonth(10); $lab = clone $this->_referenceDate; $this->_createContracts(array(array('number' => 100, 'title' => 'MyContract', 'description' => 'unittest', 'container_id' => $this->_sharedContractsContainerId, 'billing_point' => 'begin', 'billing_address_id' => $this->_addressRecords->filter('customer_id', $customer->getId())->filter('type', 'billing')->getFirstRecord()->getId(), 'start_date' => $csDate, 'end_date' => NULL, 'products' => array(array('start_date' => $csDate, 'end_date' => NULL, 'quantity' => 1, 'interval' => 1, 'billing_point' => 'end', 'product_id' => $this->_productRecords->filter('name', 'Hours')->getFirstRecord()->getId()))))); $json = new Sales_Frontend_Json(); $date = clone $this->_referenceDate; // this is set by cli if called by cli $date->setTime(3, 0, 0); $result = $this->_invoiceController->createAutoInvoices($date); $this->assertEquals(0, $result['created_count']); $date->addMonth(1); $result = $this->_invoiceController->createAutoInvoices($date); $this->assertEquals(1, $result['created_count']); $invoice1Id = $result['created'][0]; $filter = new Timetracker_Model_TimesheetFilter(array()); $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'invoice_id', 'operator' => 'equals', 'value' => $invoice1Id))); $timesheets = $this->_timesheetController->search($filter); $this->assertEquals(63, $timesheets->count()); $date->addMonth(1); $result = $this->_invoiceController->createAutoInvoices($date); $this->assertEquals(1, $result['created_count'], (string) $date); $invoice2Id = $result['created'][0]; $invoice = $json->getInvoice($invoice2Id); $this->assertEquals(1, count($invoice['positions'])); $date->addMonth(1); $result = $this->_invoiceController->createAutoInvoices($date); $this->assertEquals(0, $result['created_count']); $filter = new Timetracker_Model_TimesheetFilter(array()); $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'invoice_id', 'operator' => 'equals', 'value' => $invoice2Id))); $timesheets = $this->_timesheetController->search($filter); $this->assertEquals(21, $timesheets->count()); }
/** * test constraints after changing relation */ public function testTimeaccountRelation() { $sjson = new Sales_Frontend_Json(); $tjson = new Timetracker_Frontend_Json(); $ta = $tjson->saveTimeaccount(array('number' => 43379, 'title' => 'bla')); $c1 = $sjson->saveContract(array('number' => '1', 'description' => 'blub bla', 'title' => 'blub')); $c2 = $sjson->saveContract(array('number' => '2', 'description' => 'bla blub', 'title' => 'bla')); $c1['relations'] = array(array('related_model' => 'Timetracker_Model_Timeaccount', 'related_id' => $ta['id'], 'related_degree' => 'sibling', 'type' => 'TIME_ACCOUNT', 'remark' => 'unittest', 'related_backend' => 'Sql')); $c1 = $sjson->saveContract($c1); $c1Id = $c1['id']; // delete timeaccount relation from the first contract $c1 = $sjson->getContract($c1Id); $c1['relations'] = array(); $c1 = $sjson->saveContract($c1); // save second contract having the timeaccount related $c2['relations'] = array(array('related_model' => 'Timetracker_Model_Timeaccount', 'related_id' => $ta['id'], 'related_degree' => 'sibling', 'type' => 'TIME_ACCOUNT', 'remark' => 'unittest', 'related_backend' => 'Sql')); $c2 = $sjson->saveContract($c2); $this->assertEquals(1, count($c2['relations'])); }
/** * testTransfer * * @see 0009210: Allow to change relations * https://forge.tine20.org/mantisbt/view.php?id=9210 */ public function testTransfer() { $sclever = Addressbook_Controller_Contact::getInstance()->get($this->_personas['sclever']->contact_id, null, false); $pwulf = Addressbook_Controller_Contact::getInstance()->get($this->_personas['pwulf']->contact_id, null, false); $container = Tinebase_Container::getInstance()->create(new Tinebase_Model_Container(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId(), 'type' => Tinebase_Model_Container::TYPE_SHARED, 'backend' => 'sql', 'name' => 'testsdf'))); $contract = new Sales_Model_Contract(array('number' => '23547', 'title' => 'test', 'container_id' => $container->getId())); $contract = Sales_Controller_Contract::getInstance()->create($contract); $contract2 = new Sales_Model_Contract(array('number' => '23347', 'title' => 'test', 'container_id' => $container->getId())); $contract2 = Sales_Controller_Contract::getInstance()->create($contract2); $json = new Sales_Frontend_Json(); $contractJson = $contract->toArray(); $contractJson['relations'][] = array('own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Addressbook_Model_Contact', 'related_record' => $sclever->toArray(), 'type' => 'CUSTOMER'); $contractJson = $json->saveContract($contractJson); $contract2Json = $contract2->toArray(); $contract2Json['relations'][] = array('own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Addressbook_Model_Contact', 'related_record' => $sclever->toArray(), 'type' => 'PARTNER'); $contract2Json['relations'][] = array('own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Addressbook_Model_Contact', 'related_record' => $pwulf->toArray(), 'type' => 'PARTNER'); $contract2Json = $json->saveContract($contract2Json); $this->assertEquals($sclever->getId(), $contractJson['relations'][0]['related_id']); $skipped = Tinebase_Relations::getInstance()->transferRelations($sclever->getId(), $pwulf->getId(), 'Addressbook_Model_Contact'); $this->assertEquals(1, count($skipped)); $skipped = array_pop($skipped); $this->assertEquals($sclever->getId(), $skipped['own_id']); $contractJson = $json->getContract($contract->getId()); $this->assertEquals($pwulf->getId(), $contractJson['relations'][0]['related_id']); $this->setExpectedException('Tinebase_Exception_NotFound'); Tinebase_Relations::getInstance()->transferRelations($sclever->getId(), $pwulf->getId(), 'Addressbook_Model_Contract'); }
/** * checks cleared state and sets the date to the current date, also sets all billables billed * * @param Tinebase_Record_Interface $record * @param Tinebase_Record_Interface $oldRecord */ protected function _checkCleared(Tinebase_Record_Interface &$record, Tinebase_Record_Interface $oldRecord = NULL) { $foundCustomer = NULL; if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Invoice: ' . print_r($record->toArray(), true)); } if (is_array($record->relations)) { foreach ($record->relations as $relation) { if ($relation['related_model'] == 'Sales_Model_Customer') { $foundCustomer = $relation['related_record']; break; } if ($relation['related_model'] == 'Sales_Model_Contract') { $foundContractRecord = Sales_Controller_Contract::getInstance()->get($relation['related_record']['id']); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Contract: ' . print_r($foundContractRecord->toArray(), true)); } foreach ($foundContractRecord->relations as $relation) { if ($relation['related_model'] == 'Sales_Model_Customer') { $foundCustomer = $relation['related_record']; break; } } } } } if (empty($record->address_id) && $foundCustomer) { $json = new Sales_Frontend_Json(); $resolved = $json->getCustomer($foundCustomer->getId()); if (!empty($resolved['billing'])) { $record->address_id = $resolved['billing'][0]['id']; } else { throw new Tinebase_Exception_Data('You have to set a billing address!'); } } // if the record hasn't been cleared before, clear billables if ($record->cleared == 'CLEARED' && (!$oldRecord || $oldRecord->cleared != 'CLEARED')) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->log(__METHOD__ . '::' . __LINE__ . ' Clearing Invoice ' . print_r($record->toArray(), 1), Zend_Log::INFO); } if (!$record->date) { $record->date = new Tinebase_DateTime(); } $this->_setNextNumber($record, isset($oldRecord)); $address = Sales_Controller_Address::getInstance()->get(is_string($record->address_id) ? $record->address_id : $record->address_id . id); $string = $foundCustomer['name'] . PHP_EOL; $string .= $address->prefix1 ? $address->prefix1 . "\n" : ''; $string .= $address->prefix2 ? $address->prefix2 . "\n" : ''; $string .= $address->pobox ? $address->pobox . "\n" : ''; $string .= $address->street ? $address->street . "\n" : ''; $poloc = $address->postalcode ? $address->postalcode . " " : ''; $poloc .= $address->locality ? $address->locality : ''; if (!empty($poloc)) { $string .= $poloc . PHP_EOL; } $string .= $address->countryname ? $address->countryname : ''; $record->fixed_address = $string; // clear all billables if (!empty($record->relations)) { foreach ($record->relations as $relation) { if (in_array('Sales_Model_Accountable_Interface', class_implements($relation['related_model']))) { if (is_array($relation['related_record'])) { $rr = new $relation['related_model']($relation['related_record']); } else { $rr = $relation['related_record']; } $rr->clearBillables($record); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->log(__METHOD__ . '::' . __LINE__ . ' Clearing billables ' . print_r($rr->toArray(), 1), Zend_Log::INFO); } } } } } }
/** * test if relation record gets deleted on both sides on deleting the relation on one side */ public function testDeleteTimeaccountWitContractRelation() { $taContainer = Tinebase_Container::getInstance()->getDefaultContainer('Timetracker_Model_Timeaccount'); $cContainer = Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract'); $ta = new Timetracker_Model_Timeaccount(array('number' => 83209, 'title' => 'unitttest', 'container_id' => $taContainer->getId())); $contract = new Sales_Model_Contract(array('number' => 83209, 'title' => 'unittest', 'container_id' => $cContainer->getId())); $contract = Sales_Controller_Contract::getInstance()->create($contract); $ta = Timetracker_Controller_Timeaccount::getInstance()->create($ta); $r = new Tinebase_Model_Relation(array('own_model' => 'Timetracker_Model_Timeaccount', 'own_backend' => 'Sql', 'own_degree' => 'sibling', 'own_id' => $ta->getId(), 'remark' => 'PHP UNITTEST', 'related_model' => 'Sales_Model_Contract', 'related_backend' => 'Sql', 'related_id' => $contract->getId(), 'type' => 'CONTRACT')); $ta->relations = array($r); $ta = Timetracker_Controller_Timeaccount::getInstance()->update($ta); $feTa = new Timetracker_Frontend_Json(); $feCo = new Sales_Frontend_Json(); $jsonTa = $feTa->getTimeaccount($ta->getId()); $jsonCo = $feCo->getContract($contract->getId()); $this->assertEquals(1, count($jsonTa['relations'])); $this->assertEquals(1, count($jsonCo['relations'])); $feTa->deleteTimeaccounts(array($ta->getId())); $jsonCo = $feCo->getContract($contract->getId()); $this->assertEquals(0, count($jsonCo['relations'])); }