public function toDate($date = null) { if (!($date = $this->filterDate($date))) { return $this; } else { return $this->andWhere('inv.issue_date < ?', sfDate::getInstance($date)->addDay(1)->to_database())->andWhere('inv.draft = ?', 0); } }
public function recursionHappensOn($ts) { $objTestDate = new sfDate($ts); $objStartDate = new sfDate($this->ts); // Current date is before the recurring event begins. if ($objTestDate->get() < $objStartDate->get()) { return false; } elseif (in_array($objTestDate->date(), $this->exceptions)) { return false; } switch ($this->event->CustomRecursionType) { // Daily case 1: return $this->event->DailyInterval ? ($ts - $this->ts) / self::DAY % $this->event->DailyInterval == 0 : false; break; // Weekly // Weekly case 2: return ($objTestDate->firstDayOfWeek()->get() - $objStartDate->firstDayOfWeek()->get()) / self::WEEK % $this->event->WeeklyInterval == 0 && in_array($objTestDate->reset()->format('w'), $this->allowedDaysOfWeek); break; // Monthly // Monthly case 3: if (self::difference_in_months($objTestDate, $objStartDate) % $this->event->MonthlyInterval == 0) { // A given set of dates in the month e.g. 2 and 15. if ($this->event->MonthlyRecursionType1 == 1) { return in_array($objTestDate->reset()->format('j'), $this->allowedDaysOfMonth); } elseif ($this->event->MonthlyRecursionType2 == 1) { // Last day of the month? if ($this->event->MonthlyIndex == 5) { $targetDate = $objTestDate->addMonth()->firstDayOfMonth()->previousDay($this->event->MonthlyDayOfWeek)->dump(); } else { $objTestDate->subtractMonth()->finalDayOfMonth(); for ($i = 0; $i < $this->event->MonthlyIndex; $i++) { $objTestDate->nextDay($this->event->MonthlyDayOfWeek)->dump(); } $targetDate = $objTestDate->dump(); } return $objTestDate->reset()->dump() == $targetDate; } } return false; } }
/** * Retrieve Items that has been invoiced with this product * and whose invoice status is not draft * * @return Doctrine_Collection * @author JoeZ99 <*****@*****.**> **/ public function getInvoicedItems($product_id, $date_range = array()) { $res = Doctrine::getTable('Item')->createQuery()->addSelect("i.quantity, i.unitary_cost")->from("Item i")->innerJoin("i.Common as inv WITH (inv.type = ? AND inv.draft != ?)", array('Invoice', 1))->where('product_id = ?', $product_id); if (isset($date_range['from']) && ($filtered_date = Tools::filterDate($date_range['from']))) { $res->andWhere('inv.issue_date >= ?', sfDate::getInstance($filtered_date)->to_database()); } if (isset($date_range['to']) && ($filtered_date = Tools::filterDate($date_range['to']))) { $res->andWhere('inv.issue_date <= ?', sfDate::getInstance($filtered_date)->to_database()); } return $res->execute(); }
protected function configure() { $this->addOptions(array(new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'), new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), new sfCommandOption('date', null, sfCommandOption::PARAMETER_REQUIRED, 'Date', sfDate::getInstance()->dump()))); $this->namespace = 'siwapp'; $this->name = 'create-pending-invoices'; $this->briefDescription = 'Generates all pending invoices'; $this->detailedDescription = <<<EOF The [create-pending-invoices|INFO] task checks the database and generates all pending invoices. EOF; }
public function process() { increase_time_limit_to(300); DB::query("DELETE FROM CachedCalendarEntry"); $future_years = $this->config()->cache_future_years; foreach (Calendar::get() as $calendar) { echo "<h2>Caching calendar '{$calendar->Title}'</h2>\n"; foreach ($calendar->getAllCalendars() as $c) { foreach ($c->AllChildren() as $event) { // All the dates of regular events if ($event->Recursion) { echo "<h3>Creating recurring events for '{$event->Title}'</h3>\n"; $i = 0; $dt = $event->DateTimes()->first(); if (!$dt) { continue; } if ($dt->EndDate) { $end_date = sfDate::getInstance($dt->EndDate); } else { $end_date = sfDate::getInstance()->addYear($future_years); } $start_date = sfDate::getInstance($dt->StartDate); $recursion = $event->getRecursionReader(); while ($start_date->get() <= $end_date->get()) { if ($recursion->recursionHappensOn($start_date->get())) { $dt->StartDate = $start_date->format('Y-m-d'); $cached = CachedCalendarEntry::create_from_datetime($dt, $calendar); $cached->EndDate = $cached->StartDate; $cached->write(); } $start_date->addDay(); $i++; } echo "<p>{$i} events created.</p>\n"; } else { foreach ($event->DateTimes() as $dt) { echo "<p>Adding dates for event '{$event->Title}'</p>\n"; $cached = CachedCalendarEntry::create_from_datetime($dt, $calendar); $cached->write(); } } // Announcements } foreach ($c->Announcements() as $a) { echo "<p>Adding announcement {$a->Title}</p>\n"; $cached = CachedCalendarEntry::create_from_announcement($a, $calendar); $cached->write(); } } } echo "Done!"; }
/** * Handles returning the JSON events data for a time range. * * @param SS_HTTPRequest $request * @return SS_HTTPResponse */ public function eventsdata($request) { $start = $request->getVar('start'); $end = $request->getVar('end'); // for testing if (!$end) { $end = '2013-12-12'; } $events = $this->owner->data()->getEventList(sfDate::getInstance($start)->date(), sfDate::getInstance($end)->date(), null, null); $result = array(); if ($events) { foreach ($events as $event) { $result[] = array('id' => $event->ID, 'title' => $event->getTitle(), 'start' => strtotime("{$event->StartDate} {$event->StartTime}"), 'end' => strtotime("{$event->EndDate} {$event->EndTime}"), 'startTime' => $event->getFormattedStartTime(), 'endTime' => $event->getFormattedEndTime(), 'allDay' => (bool) $event->AllDay, 'url' => $event->Link()); } } $this->owner->getRequest()->addHeader('Content-Type', 'application/json'); return Convert::array2json($result); }
public static function sfDateFromArray($date_array, $lastminute = false) { $valid = true; foreach (array('year', 'month', 'day') as $key) { $valid = isset($date_array[$key]) && strlen($date_array[$key]) && $valid; } if (!$valid) { return false; } $date = sfDate::getInstance()->clearTime(); if ($lastminute) { $date->setHour(23)->setMinute(59)->setSecond(59); } $date->setDay($date_array['day']); $date->setMonth($date_array['month']); $date->setYear($date_array['year']); return $date; }
protected function MicroformatEnd($offset = true) { if ($this->AllDay() && $this->StartDate) { $time = "00:00:00"; $end = new sfDate($this->StartDate); $date = $end->tomorrow()->date(); unset($end); } else { $date = $this->EndDate ? $this->EndDate : $this->StartDate; $time = $this->EndTime && $this->StartTime ? $this->EndTime : (!$this->EndTime && $this->StartTime ? $this->StartTime : "00:00:00"); } return CalendarUtil::Microformat($date, $time, $offset); }
protected function generatePayments() { // Payments $date1 = sfDate::getInstance($this->inv->getIssueDate()); $date2 = sfDate::getInstance($this->inv->getDueDate()); $total = $this->inv->setAmounts()->getGrossAmount(); if (mt_rand(1, 10) == 1) { $q = mt_rand(1, 5); $paid = 0; for ($k = 0; $k < $q && $paid < $total; $k++) { $payment = new Payment(); $payment_date = sfDate::getInstance($date2->get() - mt_rand(1, $date2->diff($date1))); $payment->setDate($payment_date->format('Y-m-d')); $payment->setNotes($this->items[array_rand($this->items)]); $rest = $total - $paid; $sum = round($rest * (0.25 * mt_rand(1, 3)), 2); $paid += $sum; $payment->setAmount($sum); $this->inv->Payments[] = $payment; } } else { $payment = new Payment(); $payment_date = sfDate::getInstance($date2->get() - mt_rand(1, $date2->diff($date1))); $payment->setDate($payment_date->format('Y-m-d')); $payment->setNotes($this->items[array_rand($this->items)]); $payment->setAmount($total); $this->inv->Payments[] = $payment; } }
/** * Limits the results to those customer whose invoices are issued in a date smaller or equal than that * one passed as parameter. * @param mixed date value * @return InvoiceFinder the same instance * @author Carlos Escribano <*****@*****.**> */ public function toDate($date = null) { if (!($date = $this->filterDate($date))) { return $this; } else { return $this->andWhere('i.customer_id = id')->andWhere('i.issue_date < ?', sfDate::getInstance($date)->addDay(1)->to_database()); } }
$t = new lime_test(9, new lime_output_color()); $dispatcher = new sfEventDispatcher(); $request = new sfWebRequest($dispatcher); $guard_user = Doctrine::getTable('sfGuardUser')->findOneBy('Username', 'test'); $user = new SiwappUser($dispatcher, new sfSessionTestStorage(array('session_path' => '/tmp'))); $user->signin($guard_user); $request->setParameter('searchNamespace', 'invoices'); $t->diag('->updateSearch()'); $user->updateSearch($request); $request->setParameter('page', 2); $user->updateSearch($request); $t->is($user->getAttribute('page', null, 'invoices'), 2, '->updateSearch() sets the page to request page parameter'); $request->setParameter('search', array('query' => 'galaxy')); $user->updateSearch($request); $t->is($user->getAttribute('page', null, 'invoices'), 1, '->updateSearch() sets the page to 1 if the search changes'); $request->setParameter('page', 4); $user->updateSearch($request); $request->setParameter('sort', array('customer_name', 'asc')); $user->updateSearch($request); $t->is($user->getAttribute('page', null, 'invoices'), 1, '->updateSearch() sets the page to 1 if the sort changes'); $t->diag('Testing the default search filter settings'); $user->getProfile()->setSearchFilter('last_month'); $user->updateSearch($request); $search = $user->getAttribute('search', null, 'invoices'); $today = new sfDate(); $t->is($search['to']['year'], $today->getYear(), 'sets right the to_year'); $t->is($search['to']['month'], $today->getMonth(), 'sets right the to_month'); $t->is($search['to']['day'], $today->getDay(), 'sets right the to_day'); $t->is($search['from']['year'], $today->subtractMonth(1)->getYear(), 'sets right the from_year'); $t->is($search['from']['month'], $today->getMonth(), 'sets right the from_month'); $t->is($search['from']['day'], $today->getDay(), 'sets right the from_day');
/** * @return boolean true if date is Holiday in culture 'fr' */ public function isHolidayFr() { // add fixed holydays $holidays = array("Nouvel an" => array('month' => 1, 'day' => 1), "Armistice 39-45" => array('month' => 5, 'day' => 8), "Toussaint" => array('month' => 11, 'day' => 1), "Armistice 14-18" => array('month' => 11, 'day' => 11), "Assomption" => array('month' => 8, 'day' => 15), "Fete du travail" => array('month' => 5, 'day' => 1), "Fete nationnale" => array('month' => 7, 'day' => 14), "Noel" => array('month' => 12, 'day' => 25)); // add mobile holidays too // add easter_day $easter_monday_date = sfDate::getInstance(easter_date($this->getYear()))->addDay(1); $holidays['Lundi de Paques'] = array('month' => $easter_monday_date->getMonth(), 'day' => $easter_monday_date->getDay()); $ascension_date = sfDate::getInstance(easter_date($this->getYear()))->addDay(39); $holidays['Ascenscion'] = array('month' => $ascension_date->getMonth(), 'day' => $ascension_date->getDay()); $pentecote_date = sfDate::getInstance(easter_date($this->getYear()))->addDay(49); $holidays['Pentecote'] = array('month' => $pentecote_date->getMonth(), 'day' => $pentecote_date->getDay()); // test if the current date is in Holidays $cur_month = $this->retrieve(sfTime::MONTH); $cur_day = $this->retrieve(sfTime::DAY); foreach ($holidays as $key => $val) { // if not the proper month, goto the next if ($cur_month != $val['month']) { continue; } // if not the proper day, goto the next if ($cur_day != $val['day']) { continue; } // return true; return true; } // if all the tests passed return false; }
/** * Generates and saves an invoice based on this recurring * * @return Invoice **/ public function generateInvoice() { $i = new Invoice(); // Get Invoice column mapping and intersect with Recurring one // to remove non common columns. Unset id and type columns. $iKeys = array_flip(array_keys($i->getTable()->getColumns())); $data = $this->toArray(false); unset($data['id'], $data['type'], $data['must_occurrences'], $data['created_at'], $data['last_execution_date'], $data['occurrences']); $data = array_intersect_key($data, $iKeys); // Add specific fields for Invoice and hydrate. $data = array_merge($data, array('recurring_invoice_id' => $this->getId(), 'issue_date' => sfDate::getInstance()->format('Y-m-d'), 'due_date' => sfDate::getInstance()->addDay($this->getDaysToDue())->format('Y-m-d'), 'draft' => false)); $i->fromArray($data); // Copy Items and taxes foreach ($this->Items as $item) { $iTmp = $item->copy(false); foreach ($item->Taxes as $tax) { $iTmp->Taxes[] = $tax; } $i->Items[] = $iTmp; } // copy tags foreach ($this->getTags() as $tag) { $i->addTag($tag); } if ($i->trySave()) { $this->setLastExecutionDate(sfDate::getInstance()->format('Y-m-d')); $this->save(); } return $i; }
$t->is(sfDate::getInstance('2010-01-01 01:01:00')->diffHour('2010-01-01 00:00:00'), 1, 'diffHour'); $t->is(sfDate::getInstance('2010-01-01 00:00:00')->diffHour('2010-01-01 01:01:00'), -1, 'diffHour inverse'); $t->is(sfDate::getInstance('2010-01-01 01:59:00')->diffHour('2010-01-01 00:00:00'), 1, 'diffHour almost 2'); $t->is(sfDate::getInstance('2010-01-02')->diffDay('2010-01-01'), 1, 'diffDay'); $t->is(sfDate::getInstance('2010-01-01')->diffDay('2010-01-02'), -1, 'diffDay inverse'); $t->is(sfDate::getInstance('2010-01-01 23:59:59')->diffDay('2010-01-01 00:00:00'), 0, 'diffDay almost 2'); $t->is(sfDate::getInstance('2010-01-08')->diffWeek('2010-01-01'), 1, 'diffWeek'); $t->is(sfDate::getInstance('2010-01-01')->diffWeek('2010-01-08'), -1, 'diffWeek inverse'); // addCalendarMonth and subtractCalendarMonth $t->is(sfDate::getInstance('2010-01-21')->addCalendarMonth(1)->format('Ymd'), '20100221', 'add calendar month simple'); $t->is(sfDate::getInstance('2010-01-30')->addCalendarMonth(1)->format('Ymd'), '20100228', 'add calendar month special'); $t->is(sfDate::getInstance('2010-01-31')->addCalendarMonth(3)->format('Ymd'), '20100430', 'add calendar month special adding 3'); $t->is(sfDate::getInstance('2010-11-30')->addCalendarMonth(3)->format('Ymd'), '20110228', 'add calendar month special changing year'); $t->is(sfDate::getInstance('2010-02-21')->subtractCalendarMonth(1)->format('Ymd'), '20100121', 'subtract calendar month simple'); $t->is(sfDate::getInstance('2010-03-30')->subtractCalendarMonth(1)->format('Ymd'), '20100228', 'subtract calendar month special'); $t->is(sfDate::getInstance('2010-07-31')->subtractCalendarMonth(3)->format('Ymd'), '20100430', 'subtract calendar month special subtracting 3'); $t->is(sfDate::getInstance('2011-02-28')->subtractCalendarMonth(3)->format('Ymd'), '20101128', 'subtract calendar month special changing year'); // diffMonth and diffYear $t->is(sfDate::getInstance('2010-02-01')->diffMonth('2010-01-01'), 1, 'diffMonth'); $t->is(sfDate::getInstance('2010-01-01')->diffMonth('2010-02-01'), -1, 'diffMonth inverse'); $t->is(sfDate::getInstance('2010-03-31')->diffMonth('2010-01-01'), 2, 'diffMonth almost 3 but 2'); $t->is(sfDate::getInstance('2010-01-01')->diffMonth('2010-03-31'), -2, 'diffMonth almost 3 but 2 inverse'); $t->is(sfDate::getInstance('2011-03-22')->diffMonth('2010-01-01'), 14, 'diffMonth 14'); $t->is(sfDate::getInstance('2011-01-01')->diffYear('2010-01-01'), 1, 'diffYear exactly 1'); $t->is(sfDate::getInstance('2010-01-01')->diffYear('2011-01-01'), -1, 'diffYear exactly 1 inversed'); $t->is(sfDate::getInstance('2010-01-01')->diffYear('2010-12-31'), 0, 'diffYear almost 1 year'); $t->is(sfDate::getInstance('2011-01-01')->diffYear('2010-01-02'), 0, 'diffYear almost 1 year'); $t->is(sfDate::getInstance('2010-01-02')->diffYear('2011-01-01'), 0, 'diffYear almost 1 year inverse'); $t->is(sfDate::getInstance('2010-01-02')->diffYear('2014-03-15'), -4, 'diffYear 4 years and some months'); $t->is(sfDate::getInstance('2014-03-15')->diffYear('2010-01-02'), 4, 'diffYear 4 years and some months inversed');
public function generateInvoice() { $invoice = new Invoice(); // Get Invoice column mapping and intersect with Estimate columns // to remove non common columns. Unset id and type columns. $iKeys = array_flip(array_keys($invoice->getTable()->getColumns())); $data = $this->toArray(false); unset($data['id'], $data['type'], $data['created_at'], $data['updated_at'], $data['draft'], $data['number'], $data['sent_by_email']); $data = array_intersect_key($data, $iKeys); $invoice->fromArray($data); // $invoice->setDraft(true); $invoice->setIssueDate(sfDate::getInstance()->format('Y-m-d')); $invoice->setDueDate(sfDate::getInstance()->addMonth()->format('Y-m-d')); // Copy Items and taxes foreach ($this->Items as $item) { $iTmp = $item->copy(false); foreach ($item->Taxes as $tax) { $iTmp->Taxes[] = $tax; } $invoice->Items[] = $iTmp; } // copy tags foreach ($this->getTags() as $tag) { $invoice->addTag($tag); } if ($invoice->trySave()) { $invoice->refresh(true)->setAmounts()->save(); return $invoice; } return false; }
/** * this checks if recalculation of totals and status is needed * of the opened invoices * * @return void **/ private function checkIfUpdateTotals() { // if the property is not set, we set it here if (!PropertyTable::get('last_calculation_date')) { PropertyTable::set('last_calculation_date', '1970-01-01'); } $last = new sfDate(PropertyTable::get('last_calculation_date')); $today = new sfDate(); if ($today->diff($last, sfTime::DAY) > 0) { CommonTable::calculateTotals(); PropertyTable::set('last_calculation_date', $today->format('Y-m-d')); } }
/** * this function sets the $search array with default settings * if the user has default settings for the search form * * @param $search array The search array * * @return array The search array **/ private function getSearchSettings($search) { if ($profile = $this->getProfile()) { $from = $to = null; if (isset($search['from'])) { $from = Tools::sfDateFromArray($search['from']); } if (isset($search['to'])) { $to = Tools::sfDateFromArray($search['to']); } if (!isset($search['quick_dates']) && !$from && !$to && ($searchFilter = $profile->getSearchFilter())) { $to = sfDate::getInstance(); $search['to'] = array('day' => $to->getDay(), 'month' => $to->format('n'), 'year' => $to->getYear()); $from = sfDate::getInstance(); switch ($searchFilter) { case 'last_week': $from->subtractWeek(1); break; case 'last_month': $from->subtractMonth(1); break; case 'last_year': $from->subtractYear(1); break; case 'last_5_years': $from->subtractYear(5); break; case 'this_week': $from->firstDayOfWeek(); break; case 'this_month': $from->firstDayOfMonth(); break; case 'this_year': $from->firstDayOfYear(); break; } $search['from'] = array('day' => $from->format('j'), 'month' => $from->format('n'), 'year' => $from->getYear()); $search['quick_dates'] = $searchFilter; } } return $search; }
public function getTitle() { return strftime("%a", sfDate::getInstance()->nextDay($this->Value)->get()); }
protected function getNavigationOptions() { $options = new DataObjectSet(); $counter = new sfDate($this->start_date->get()); $counter->subtractMonth(6); for ($i = 0; $i < 12; $i++) { $options->push(new ArrayData(array('Link' => $this->ShowMonthLink($counter->format('Ym')), 'Selected' => $this->start_date->format('Ym') == $counter->format('Ym') ? 'selected="selected"' : '', 'Month' => CalendarUtil::i18n_date('%B, %Y', $counter->get())))); $counter->addMonth(); } unset($counter); return $options; }
public function RecentEvents($limit = null, $filter = null, $announcement_filter = null) { $start_date = new sfDate(); $end_date = $start_date; $events = $this->Events($filter, $start_date->subtractMonth(Calendar::$defaultFutureMonths), $end_date->yesterday(), true, $limit === null ? $this->DefaultEventDisplay : $limit, $announcement_filter); $events->sort('StartDate', 'DESC'); return $events; }
public function getAllDatesInRange() { $start = sfDate::getInstance($this->StartDate); $end = sfDate::getInstance($this->EndDate); $dates = array(); while ($start->get() <= $end->get()) { $dates[] = $start->format('Y-m-d'); $start->tomorrow(); } return $dates; }
public function getStatus() { $now = new sfDate(); $dt = new sfDate($this->getFinish()); if (parent::getStatus() == sfConfig::get('app_task_status_open') && $this->getFinish() < date('Y-m-d H:i:s')) { return sfConfig::get('app_task_status_overdue'); } if (parent::getStatus() == sfConfig::get('app_task_status_open') && ($now <= $dt && $now->addDay(sfConfig::get('app_task_status_upcoming_days')) >= $dt)) { return sfConfig::get('app_task_status_upcoming'); } if (parent::getStatus() == sfConfig::get('app_task_status_open')) { return sfConfig::get('app_task_status_open'); } if (parent::getStatus() == sfConfig::get('app_task_status_completed')) { return sfConfig::get('app_task_status_completed'); } return sfConfig::get('app_task_status_unknown'); }
public function MonthJumpForm() { $this->parseURL($this->getRequest()); $dummy = sfDate::getInstance($this->startDate); $range = range($dummy->subtractYear(3)->format('Y'), $dummy->addYear(6)->format('Y')); $year_map = array_combine($range, $range); $f = new Form($this, "MonthJumpForm", new FieldList($m = new DropdownField('Month', '', CalendarUtil::get_months_map('%B')), $y = new DropdownField('Year', '', $year_map)), new FieldList(new FormAction('doMonthJump', _t('Calendar.JUMP', 'Go')))); if ($this->startDate) { $m->setValue($this->startDate->format('m')); $y->setValue($this->startDate->format('Y')); } else { $m->setValue(date('m')); $y->setValue(date('Y')); } return $f; }
/** * checks and sets the status * * @return Invoice $this **/ public function checkStatus() { if ($this->getDraft()) { $this->setStatus(Invoice::DRAFT); } else { if ($this->getClosed() || $this->getDueAmount() == 0) { $this->setStatus(Invoice::CLOSED); } else { if ($this->getDueDate() > sfDate::getInstance()->format('Y-m-d')) { $this->setStatus(Invoice::OPENED); } else { $this->setStatus(Invoice::OVERDUE); } } } return $this; }