当前位置: 首页>>代码示例>>PHP>>正文


PHP Tinebase_DateTime::subMonth方法代码示例

本文整理汇总了PHP中Tinebase_DateTime::subMonth方法的典型用法代码示例。如果您正苦于以下问题:PHP Tinebase_DateTime::subMonth方法的具体用法?PHP Tinebase_DateTime::subMonth怎么用?PHP Tinebase_DateTime::subMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tinebase_DateTime的用法示例。


在下文中一共展示了Tinebase_DateTime::subMonth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCalculation

 /**
  * tests account summary and getFeastAndFreeDays method calculation
  */
 public function testCalculation()
 {
     $employmentBegin = new Tinebase_DateTime('2012-12-15');
     $employmentChange = new Tinebase_DateTime('2014-01-01');
     $employmentEnd = new Tinebase_DateTime('2014-06-30');
     $referenceDate = new Tinebase_DateTime('2013-10-10');
     $contractController = HumanResources_Controller_Contract::getInstance();
     $employeeController = HumanResources_Controller_Employee::getInstance();
     $contractBackend = new HumanResources_Backend_Contract();
     $employee = $this->_getEmployee('unittest');
     $employee->employment_begin = $employmentBegin;
     $employee->employment_end = $employmentEnd;
     $contract1 = $this->_getContract();
     $contract1->start_date = $employmentBegin;
     $contract1->workingtime_json = '{"days": [8,8,8,8,8,0,0]}';
     $contract1->vacation_days = 25;
     $contract2 = $this->_getContract();
     $contract2->start_date = $employmentChange;
     $contract2->end_date = $employmentEnd;
     $contract2->workingtime_json = '{"days": [4,4,4,4,4,4,4]}';
     $rs = new Tinebase_Record_RecordSet('HumanResources_Model_Contract');
     $rs->addRecord($contract1);
     $rs->addRecord($contract2);
     $employee->contracts = $rs;
     $employee = $employeeController->create($employee);
     $json = new HumanResources_Frontend_Json();
     $accountController = HumanResources_Controller_Account::getInstance();
     $accountsFilter = array(array('field' => "employee_id", 'operator' => "AND", 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $employee->getId()))));
     // should not be created, exist already
     $accountController->createMissingAccounts(2013, $employee);
     $accountController->createMissingAccounts(2014, $employee);
     // create feast days
     $feastDays = array('01-01', '03-29', '04-01', '05-01', '05-09', '05-20', '10-03', '12-25', '12-26', '12-31');
     foreach ($feastDays as $day) {
         $date = new Tinebase_DateTime('2013-' . $day . ' 12:00:00');
         $this->_createFeastDay($date);
         $date = new Tinebase_DateTime('2014-' . $day . ' 12:00:00');
         $this->_createFeastDay($date);
     }
     // what about the holy evening? it's recurring
     // @see 0009114: Freetime edit dialog doesn't calculate recurring feast days
     //      https://forge.tine20.org/mantisbt/view.php?id=9114
     $this->_createRecurringFeastDay(new Tinebase_DateTime('2011-12-24'));
     $result = $json->searchAccounts($accountsFilter, array('sort' => 'year', 'dir' => 'DESC'));
     $this->assertEquals('3', $result['totalcount'], 'Three accounts should have been found!');
     $accountId2013 = $result['results'][1]['id'];
     $account2013 = $json->getAccount($accountId2013);
     $accountId2014 = $result['results'][0]['id'];
     $account2014 = $json->getAccount($accountId2014);
     $this->assertEquals(25, $account2013['possible_vacation_days']);
     $this->assertEquals(250, $account2013['working_days']);
     $this->assertEquals(15, $account2014['possible_vacation_days']);
     $this->assertEquals(175, $account2014['working_days']);
     // add 5 extra free days to the account with different expiration dates, 2 days aren't expired already
     $tomorrow = Tinebase_DateTime::now();
     $tomorrow->addDay(1);
     $yesterday = Tinebase_DateTime::now();
     $yesterday->subDay(1);
     $eft1 = new HumanResources_Model_ExtraFreeTime(array('days' => 2, 'account_id' => $accountId2013, 'expires' => $tomorrow));
     $eft2 = new HumanResources_Model_ExtraFreeTime(array('days' => 3, 'account_id' => $accountId2013, 'expires' => $yesterday));
     $eftController = HumanResources_Controller_ExtraFreeTime::getInstance();
     $eftController->create($eft1);
     $eftController->create($eft2);
     $account2013 = $json->getAccount($accountId2013);
     $this->assertEquals(27, $account2013['possible_vacation_days']);
     $this->assertEquals(27, $account2013['remaining_vacation_days']);
     $this->assertEquals(250, $account2013['working_days']);
     $this->assertEquals(3, $account2013['expired_vacation_days'], 'There should be 3 expired vacation days at first!');
     // the extra freetimes added to the account2013 should not affect account 2014
     $account2014 = $json->getAccount($accountId2014);
     $this->assertEquals(15, $account2014['possible_vacation_days']);
     $this->assertEquals(175, $account2014['working_days']);
     // now add 3 vacation days before the expiration day of the second extra free time
     // #8202: Allow to book remaining free days from last years' account, respect expiration
     $freetime = array('account_id' => $accountId2013, 'employee_id' => $employee->getId(), 'type' => 'vacation', 'status' => 'ACCEPTED', 'firstday_date' => $yesterday->subWeek(1)->toString());
     $nd = $referenceDate->subMonth(2);
     $freetime['freedays'] = array(array('duration' => '1', 'date' => $nd->toString()), array('duration' => '1', 'date' => $nd->addDay(1)->toString()), array('duration' => '1', 'date' => $nd->addDay(1)->toString()));
     $freetime = $this->_json->saveFreeTime($freetime);
     // so the 3 days haven't been expired, because 3 vacation days have been booked before
     $account2013 = $json->getAccount($accountId2013);
     $this->assertEquals(30, $account2013['possible_vacation_days'], 'There should be 30 possible vacation days after all!');
     $this->assertEquals(27, $account2013['remaining_vacation_days'], 'There should be 27 remaining vacation days after all!');
     $this->assertEquals(0, $account2013['expired_vacation_days'], 'There should be no expired vacation days after all!');
     $this->assertEquals(3, $account2013['taken_vacation_days'], 'He took 3 vacation days');
     // test account filter for: employee_id and year
     $accountsFilter = array(array('field' => "employee_id", 'operator' => "AND", 'value' => array(array('field' => ':id', 'operator' => 'equals', 'value' => $employee->getId()))), array('field' => 'year', 'operator' => 'equals', 'value' => $account2013['year']));
     $result = $json->searchAccounts($accountsFilter, array());
     $this->assertEquals(1, $result['totalcount']);
     // test account quicksearch filter
     $qsFilter = array(array('field' => "query", 'operator' => "contains", 'value' => Tinebase_Core::getUser()->accountFirstName));
     $result = $json->searchAccounts($qsFilter, array());
     $this->assertEquals(3, $result['totalcount'], 'should find exactly 3 accounts');
     $qsFilter = array(array('field' => "query", 'operator' => "contains", 'value' => 'Adsmin'));
     $result = $json->searchAccounts($qsFilter, array());
     $this->assertEquals(0, $result['totalcount']);
     $refdate = clone $referenceDate;
     // now we test if adding a vacation with dates of 2013 but the account of 2014 works as expected
//.........这里部分代码省略.........
开发者ID:bitExpert,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:101,代码来源:JsonTests.php

示例2: _createAutoInvoicesForContract

 /**
  * create auto invoices for one contract
  * 
  * @param Sales_Model_Contract $contract
  * @param Tinebase_DateTime $currentDate
  * @param boolean $merge
  */
 protected function _createAutoInvoicesForContract(Sales_Model_Contract $contract, Tinebase_DateTime $currentDate, $merge = false)
 {
     // set this current billing date (user timezone)
     $this->_currentBillingDate = clone $currentDate;
     $this->_currentBillingDate->setDate($this->_currentBillingDate->format('Y'), $this->_currentBillingDate->format('m'), 1);
     $this->_currentBillingDate->setTime(0, 0, 0);
     // check all prerequisites needed for billing of the contract
     if (!$this->_validateContract($contract)) {
         return false;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Processing contract "' . $this->_currentBillingContract->number . '"');
     }
     // fire event to allow other applications do some work before billing
     $this->_firePrebillEvent();
     // find product aggregates of the current contract
     $productAggregates = $this->_findProductAggregates();
     // find month that needs to be billed next (note: _currentMonthToBill is the 01-01 00:00:00 of the next month, its the border, like last_autobill)
     $this->_currentMonthToBill = null;
     foreach ($productAggregates as $productAggregate) {
         if (null != $productAggregate->last_autobill) {
             $tmp = clone $productAggregate->last_autobill;
             $tmp->setDate($tmp->format('Y'), $tmp->format('m'), 1);
             $tmp->setTime(0, 0, 0);
             if (null == $this->_currentMonthToBill || $tmp->isLater($this->_currentMonthToBill)) {
                 $this->_currentMonthToBill = $tmp;
             }
         }
     }
     // this contract has no productAggregates, maybe just time accounts? use last invoice to find already billed month
     if (null == $this->_currentMonthToBill) {
         // find newest invoice of contract (probably can be done more efficient!)
         $invoiceRelations = Tinebase_Relations::getInstance()->getRelations('Sales_Model_Contract', 'Sql', $contract->getId(), NULL, array(), TRUE, array('Sales_Model_Invoice'));
         // do not modify $newestInvoiceTime!!!! it does NOT get cloned!
         $newestInvoiceTime = null;
         $newestInvoice = null;
         foreach ($invoiceRelations as $invoiceRelation) {
             $invoiceRelation->related_record->setTimezone(Tinebase_Core::getUserTimezone());
             if (null == $newestInvoiceTime || $invoiceRelation->related_record->creation_time->isLater($newestInvoiceTime)) {
                 $newestInvoiceTime = $invoiceRelation->related_record->creation_time;
                 $newestInvoice = $invoiceRelation->related_record;
             }
         }
         if (null != $newestInvoice) {
             // we can only take the end_date because there are no product aggregates (that have a last_autobill set) in this contract, otherwise it might be one interval ahead!
             $this->_currentMonthToBill = clone $newestInvoice->end_date;
             $this->_currentMonthToBill->addDay(4);
             $this->_currentMonthToBill->subMonth(1);
             //$this->_currentMonthToBill->setTimezone(Tinebase_Core::getUserTimezone());
         }
     }
     $_addMonth = true;
     if (null == $this->_currentMonthToBill) {
         $this->_currentMonthToBill = clone $contract->start_date;
         $_addMonth = false;
     }
     $this->_currentMonthToBill->setTimezone(Tinebase_Core::getUserTimezone());
     $this->_currentMonthToBill->setDate($this->_currentMonthToBill->format('Y'), $this->_currentMonthToBill->format('m'), 1);
     $this->_currentMonthToBill->setTime(0, 0, 0);
     if ($_addMonth) {
         $this->_currentMonthToBill->addMonth(1);
     }
     $doSleep = false;
     if (($merge || $contract->merge_invoices) && $this->_currentMonthToBill->isEarlier($this->_currentBillingDate)) {
         $this->_currentMonthToBill = clone $this->_currentBillingDate;
     }
     while ($this->_currentMonthToBill->isEarlierOrEquals($this->_currentBillingDate)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' $this->_currentMonthToBill: ' . $this->_currentMonthToBill . ' $this->_currentBillingDate ' . $this->_currentBillingDate);
             foreach ($productAggregates as $productAggregate) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $productAggregate->id . ' ' . $productAggregate->last_autobill . ' ' . $productAggregate->interval);
             }
         }
         //required to have one sec difference in the invoice creation_time, can be optimized to look for milliseconds
         if ($doSleep) {
             sleep(1);
             $doSleep = false;
         }
         // prepare relations and find all billable accountables of the current contract
         list($relations, $billableAccountables) = $this->_prepareInvoiceRelationsAndFindBillableAccountables($productAggregates);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' count $billableAccountables: ' . count($billableAccountables));
             foreach ($billableAccountables as $ba) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' accountable: ' . get_class($ba['ac']) . ' id: ' . $ba['ac']->getId());
             }
         }
         // find invoice positions and the first start date and last end date of all billables
         list($invoicePositions, $earliestStartDate, $latestEndDate) = $this->_findInvoicePositionsAndInvoiceInterval($billableAccountables);
         /**** TODO ****/
         // if there are no positions, no more bills need to be created,
         // but the last_autobill info is set, if the current date is later
         if ($invoicePositions->count() > 0) {
             // prepare invoice
//.........这里部分代码省略.........
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:101,代码来源:Invoice.php

示例3: _getContract

 /**
  * returns a new contract
  * 
  * @var Tinebase_DateTime $sdate date begins
  * 
  * @return HumanResources_Model_Contract
  */
 protected function _getContract($sdate = NULL)
 {
     if (!$sdate) {
         $sdate = new Tinebase_DateTime();
         $sdate->subMonth(6);
     }
     $c = new HumanResources_Model_Contract(array('start_date' => $this->_startDate, 'end_date' => null, 'employee_id' => null, 'vacation_days' => 30, 'feast_calendar_id' => $this->_feastCalendar, 'workingtime_json' => $this->_getWorkingTime()->json), TRUE);
     return $c;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:16,代码来源:DemoData.php

示例4: appendFilterSql

 /**
  * appends sql to given select statement
  *
  * @param Zend_Db_Select                $_select
  * @param Tinebase_Backend_Sql_Abstract $_backend
  */
 function appendFilterSql($_select, $_backend)
 {
     $months = array();
     $db = $_backend->getAdapter();
     $date = new Tinebase_DateTime();
     $format = 'Y-m';
     $like = FALSE;
     if ($this->_operator == 'within') {
         switch ($this->_value) {
             case 'monthThis':
                 $months = array($date->format($format));
                 break;
             case 'monthLast':
                 $months = array($date->subMonth(1)->format($format));
                 break;
             case 'beforeLastMonth':
                 $months = array($date->subMonth(2)->format($format));
                 break;
             case 'quarterThis':
                 $month = ceil(intval($date->format('m')) / 3) * 3;
                 $date->setDate($date->format('Y'), $month, 15);
                 $months = array($date->format($format), $date->subMonth(1)->format($format), $date->subMonth(1)->format($format));
                 break;
             case 'quarterLast':
                 $date->subMonth(3);
                 $month = ceil(intval($date->format('m')) / 3) * 3;
                 $date->setDate($date->format('Y'), $month, 15);
                 $months = array($date->format($format), $date->subMonth(1)->format($format), $date->subMonth(1)->format($format));
                 break;
             case 'beforeLastQuarter':
                 $date->subMonth(6);
                 $month = ceil(intval($date->format('m')) / 3) * 3;
                 $date->setDate($date->format('Y'), $month, 15);
                 $months = array($date->format($format), $date->subMonth(1)->format($format), $date->subMonth(1)->format($format));
                 break;
             case 'yearThis':
                 $like = $date->format('Y') . '-%';
                 break;
             case 'yearLast':
                 $date->subYear(1);
                 $like = $date->format('Y') . '-%';
                 break;
             default:
                 throw new Tinebase_Exception_InvalidArgument('The value for the within operator is not supported: ' . $this->_value);
         }
         if ($like) {
             $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " LIKE (?)", $like));
         } else {
             $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " IN (?)", $months));
         }
     } elseif ($this->_operator == 'equals') {
         if ('' == $this->_value) {
             $_select->where($this->_getQuotedFieldName($_backend) . " = '0000-00-00 00:00:00' OR " . $this->_getQuotedFieldName($_backend) . ' IS NULL');
         } else {
             $split = explode('-', $this->_value);
             if (!(strlen($this->_value) == 7 && (int) $split[0] > 1900 && (int) $split[1] > 0 && (int) $split[1] < 13)) {
                 throw new Tinebase_Exception_MonthFormat();
             }
             $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " = (?)", $this->_value));
         }
     } else {
         $date = new Tinebase_DateTime($this->_value);
         $date->setTimezone(Tinebase_Core::getUserTimezone());
         $dateString = $date->format('Y-m');
         switch ($this->_operator) {
             case 'before':
                 $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " < (?)", $dateString));
                 break;
             case 'after':
                 $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " > (?)", $dateString));
                 break;
             case 'before_or_equals':
                 $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " <= (?)", $dateString));
                 break;
             case 'after_or_equals':
                 $_select->where($db->quoteInto($this->_getQuotedFieldName($_backend) . " >= (?)", $dateString));
                 break;
             default:
                 throw new Tinebase_Exception_InvalidArgument('The operator ' . $this->_operator . ' is not supported for this filter!');
         }
     }
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:88,代码来源:Month.php

示例5: syncLine

 /**
  * sync line
  * @param Sipgate_Model_Line $_line
  * @param Tinebase_DateTime $_from
  * @param Tinebase_DateTime $_to
  * @param boolean $verbose
  */
 public function syncLine(Sipgate_Model_Line $_line, Tinebase_DateTime $_from = NULL, Tinebase_DateTime $_to = NULL, $verbose = false)
 {
     $app = Tinebase_Application::getInstance()->getApplicationByName('Sipgate');
     if (!Tinebase_Core::getUser()->hasRight($app->getId(), Sipgate_Acl_Rights::SYNC_LINES)) {
         throw new Tinebase_Exception_AccessDenied('You are not allowed to sync lines!');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->debug('Synchronizing Line ' . $_line->sip_uri . '...');
     }
     $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
     $count = 0;
     if ($_from == null) {
         if ($_line->last_sync == null) {
             $_from = new Tinebase_DateTime();
             $_from->subMonth(2);
         } else {
             $_from = $_line->last_sync;
         }
     }
     $_to = $_to ? $_to : new Tinebase_DateTime();
     // timezone corrections
     $_from->setTimezone(Tinebase_Core::getUserTimezone());
     $_to->setTimezone(Tinebase_Core::getUserTimezone());
     if ($verbose) {
         echo 'Syncing line ' . $_line->sip_uri . ' from ' . $_from->getIso() . ' to ' . $_to->getIso() . PHP_EOL;
     }
     try {
         if (!$this->_apiBackend) {
             $this->_apiBackend = Sipgate_Backend_Api::getInstance()->connect($_line->account_id, $sipgate_user, $sipgate_pwd);
         }
         $response = $this->_apiBackend->getCallHistory($_line->__get('sip_uri'), $_from, $_to, 0, 1000);
         if (is_array($response['history']) && $response['totalcount'] > 0) {
             $paging = new Tinebase_Model_Pagination();
             // find already synced entries
             foreach ($response['history'] as $call) {
                 $entryIds[] = $call['EntryID'];
             }
             $filter = new Sipgate_Model_ConnectionFilter(array(), 'AND');
             $filter->addFilter(new Tinebase_Model_Filter_Id('entry_id', 'in', $entryIds));
             $result = Sipgate_Controller_Connection::getInstance()->search($filter, $paging, false, false);
             $oldEntries = array();
             foreach ($result->getIterator() as $connection) {
                 $oldEntries[] = $connection->entry_id;
             }
             unset($result, $connection, $filter);
             $count = 0;
             foreach ($response['history'] as $call) {
                 // skip sync if already in db
                 if (in_array($call['EntryID'], $oldEntries)) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug('Skipping call Id' . $call['EntryID'] . '.');
                     }
                     continue;
                 }
                 $localNumber = $this->_getLocalNumber($call['LocalUri']);
                 $remoteNumber = $this->_getRemoteNumber($call['RemoteUri'], $localNumber, true);
                 $filter = new Addressbook_Model_ContactFilter(array(array("field" => "telephone", "operator" => "contains", "value" => $remoteNumber)));
                 $s = Addressbook_Controller_Contact::getInstance()->search($filter, $paging);
                 $now = new Tinebase_DateTime();
                 $connection = new Sipgate_Model_Connection(array('tos' => $call['TOS'], 'entry_id' => $call['EntryID'], 'local_uri' => $call['LocalUri'], 'remote_uri' => $call['RemoteUri'], 'status' => $call['Status'], 'local_number' => '+' . $localNumber, 'remote_number' => $remoteNumber == 'anonymous' ? 'anonymous' : '+' . $remoteNumber, 'line_id' => $_line->getId(), 'timestamp' => strtotime($call['Timestamp']), 'creation_time' => $now, 'contact_id' => $s->getFirstRecord() ? $s->getFirstRecord()->getId() : null, 'contact_name' => $s->getFirstRecord() ? $s->getFirstRecord()->n_fn : ''));
                 $count++;
                 $this->create($connection);
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug('Creating call Id' . $call['EntryID'] . '.');
                 }
             }
         }
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     $_to->setTimezone('UTC');
     $_line->last_sync = $_to;
     Sipgate_Controller_Line::getInstance()->update($_line);
     Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->debug('Synchronizing Line ' . $_line->sip_uri . ' completed. Got ' . $count . ' new connections.');
     }
     return $count;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:87,代码来源:Connection.php

示例6: _getContract

 /**
  * returns a new contract
  * 
  * @param Tinebase_DateTime $sdate
  * @return HumanResources_Model_Contract
  */
 protected function _getContract($sdate = NULL)
 {
     if (!$sdate) {
         $sdate = new Tinebase_DateTime();
         $sdate->subMonth(1);
     }
     $c = new HumanResources_Model_Contract(array('start_date' => $sdate, 'end_date' => null, 'employee_id' => null, 'vacation_days' => 30, 'feast_calendar_id' => $this->_getFeastCalendar()), true);
     return $c;
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:15,代码来源:TestCase.php


注:本文中的Tinebase_DateTime::subMonth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。