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); } }
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; }
/** * 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(); }
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; }
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; }
$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');
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; } }
/** * @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; }
/** * 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()); }
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; }
/** * 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; }
/** * 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()); } }
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; }