/**
  * Get events by week.
  *
  * @param   QueryBuilder  $query
  * @param   Carbon|int    $year  Year or date
  * @param   int           $week  Week number if year is int
  * @return  QueryBuilder
  *
  * @throws  ApplicationException  on missing parameters
  */
 public function scopeWeek($query, $year, $week = null)
 {
     if ($year instanceof Carbon) {
         $from = $year->copy()->startOfWeek();
     } else {
         if ($week) {
             $from = Carbon::create($year, 1, 1)->startOfWeek();
             // Is the first day of the year on a week of last year?
             if ($from->weekOfYear != 1) {
                 $from->addWeek();
             }
             if ($week > 1) {
                 $from->addWeeks($week - 1);
             }
         } else {
             throw new ApplicationException('Week missing');
         }
     }
     return $this->scopeBetween($query, $from, $from->copy()->endOfWeek());
 }
Example #2
2
 /**
  * @param Carbon $weekBeginning
  * @param int $offsetFromUTC
  * @param bool $hasPeriodNumbers
  * @return array
  */
 public function outputHotFormatToPinFormat(Carbon $weekBeginning, $offsetFromUTC = 0, $hasPeriodNumbers = true)
 {
     $hotFormat = $this->hotFormatArray;
     // $hotFormat[period][day]
     $days = [];
     // Add days
     for ($dayNum = $this->mondayColumnNum; $dayNum < $this->mondayColumnNum + 7; $dayNum++) {
         $day = [];
         // Add periods
         for ($periodNum = 0; $periodNum < count($hotFormat); $periodNum += 2) {
             $hotName = $hotFormat[$periodNum][$dayNum];
             // Skip empty periods
             if (str_replace(' ', '', $hotName) == "") {
                 continue;
             }
             $hotPeriod = $hotFormat[$periodNum][$this->periodColumnNum];
             $hotStartTime = $hotFormat[$periodNum][$this->startTimeColumnNum];
             $hotEndTime = $hotFormat[$periodNum][$this->endTimeColumnNum];
             $hotLocation = $hotFormat[$periodNum + 1][$dayNum];
             $startTime = Carbon::parse($hotStartTime);
             $endTime = Carbon::parse($hotEndTime);
             $carbon = $weekBeginning->copy();
             $lessonDateTime = $carbon->addDays($dayNum - $this->mondayColumnNum)->hour($startTime->hour)->minute($startTime->minute)->subMinutes($offsetFromUTC);
             $day[] = ['id' => '', 'time' => $lessonDateTime->format('Y-m-d\\TH:i:s\\Z'), 'duration' => $startTime->diffInMinutes($endTime), 'layout' => ['type' => 'calendarPin', 'title' => true === $hasPeriodNumbers ? $hotPeriod . ' - ' . $hotName : $hotName]];
             if (!empty($hotLocation)) {
                 $day[count($day) - 1]['layout']['locationName'] = $hotLocation;
             }
         }
         $days[] = $day;
     }
     return $days;
 }
 public function getTransactionsByMember(Corporation $corp, array $member_ids, Carbon $date)
 {
     $start = $date->copy();
     $start->subMonth()->setTime(0, 0, 0);
     $end = $date->copy();
     $end->setTime(23, 59, 59);
     $sql = 'SELECT jt.owner_id2, group_concat(DISTINCT jt.id) as ids
         FROM journal_transactions as jt
         LEFT JOIN accounts as acc on jt.account_id=acc.id
         WHERE  acc.corporation_id = :corp_id
         AND jt.owner_id2 in ( :owner_ids )
         AND jt.date >= :start_date
         AND jt.date <= :end_date
         GROUP BY jt.owner_id2';
     $rsm = new ResultSetMappingBuilder($this->getEntityManager());
     $rsm->addRootEntityFromClassMetadata('AppBundle\\Entity\\JournalTransaction', 'jt');
     $rsm->addFieldResult('jt', 'owner_id2', 'owner_id2');
     $rsm->addFieldResult('jt', 'ids', 'id');
     $q = $this->getEntityManager()->createNativeQuery($sql, $rsm);
     $q->setParameter('corp_id', $corp->getId());
     $q->setParameter('owner_ids', $member_ids, Connection::PARAM_INT_ARRAY);
     $q->setParameter('start_date', $start);
     $q->setParameter('end_date', $end);
     $results = $q->getResult();
     $real_res = [];
     foreach ($results as $res) {
         $ids = explode(',', $res->getId());
         $rt = $this->createQueryBuilder('jt')->select('sum(jt.amount) as total_amount')->where('jt.id in (:j_ids)')->setParameter('j_ids', $ids)->getQuery()->getResult();
         $r = $this->createQueryBuilder('jt')->select('jt')->where('jt.id in (:j_ids)')->setParameter('j_ids', $ids)->getQuery()->getResult();
         $real_res[] = ['user' => $res->getOwnerId2(), 'total' => $rt, 'orig_ids' => $r];
     }
     return $real_res;
 }
 public function updateFromSalesforceRefresh(array $salesforceToken)
 {
     $this->dateIssued = Carbon::createFromTimestamp((int) ($salesforceToken['issued_at'] / 1000));
     $this->dateExpires = $this->dateIssued->copy()->addHour()->subMinutes(5);
     $this->signature = $salesforceToken['signature'];
     $this->accessToken = $salesforceToken['access_token'];
 }
Example #5
0
 /**
  * Return the next yule party date
  *
  * @return Carbon
  */
 public function getYulePartyDate()
 {
     $potentialDate = $this->fromDateToYuleDate($this->date->copy()->month(12)->day(1)->hour(15)->minute(0)->second(0));
     if ($this->strict || $potentialDate->isSameDay($this->date) || $potentialDate->gte($this->date)) {
         return $potentialDate;
     }
     return $this->fromDateToYuleDate($this->date->copy()->addYear(1)->month(12)->day(1)->hour(15)->minute(0)->second(0));
 }
 public function getEventsStatByCardNumberAndDate($cardNumber, Carbon $date)
 {
     $firstDayOfMonth = $date->copy()->startOfMonth();
     $endDayOfMonth = $date->copy()->endOfMonth();
     $events = $this->getEventsBetweenDatesAndCardNumber($cardNumber, $firstDayOfMonth, $endDayOfMonth);
     $eventSummaryByDate = $this->groupEventsByDayDate($events);
     $eventsSummaryByDateWithTime = $this->eventsSummarizeByDateWithTime($eventSummaryByDate);
     $dayStats = $this->mixWithMonthDays($eventsSummaryByDateWithTime, $firstDayOfMonth, $endDayOfMonth);
     return $dayStats;
 }
Example #7
0
 /**
  * Generates a year calendar array for front end usage
  *
  * @param array $marked for the dates to mark
  * @return array
  */
 public function generateYearCalendar(array $marked = [])
 {
     $calendar = [];
     $firstOfYear = $this->now->copy()->firstOfYear();
     $lastOfYear = $this->now->copy()->lastOfYear();
     while ($firstOfYear != $lastOfYear) {
         $day = ['carbon' => $firstOfYear->copy(), 'marked' => false];
         foreach ($marked as $mark) {
             /** @var Carbon $mark */
             if ($mark->isSameDay($day['carbon'])) {
                 $day['marked'] = true;
                 break;
             }
         }
         $calendar[$firstOfYear->month][] = $day;
         //increment day
         $firstOfYear->addDay();
     }
     //build out months => weeks => days
     $generated_year = ['year' => $this->now->year, 'months' => []];
     foreach ($calendar as $month => $days) {
         //add month
         $generated_year['months'][] = ['month' => ['month' => $month, 'year' => $this->now->year, 'pretty' => Carbon::create(null, $month)->format('F')], 'weeks' => []];
         //reset week index, month index
         $week_index = 0;
         foreach ($days as $day) {
             if ($day['carbon']->dayOfWeek == Carbon::MONDAY) {
                 $week_index++;
                 //add week
                 $generated_year['months'][$month - 1]['weeks'][$week_index] = ['days' => []];
             }
             if ($day['carbon']->day == 1) {
                 $pad = $day['carbon']->dayOfWeek - 1 >= 0 ? $day['carbon']->dayOfWeek - 1 : 6;
                 for ($p = $pad; $p > 0; $p--) {
                     //add empty days for start of week
                     $generated_year['months'][$month - 1]['weeks'][$week_index]['days'][] = false;
                 }
             }
             //add day
             $generated_year['months'][$month - 1]['weeks'][$week_index]['days'][] = ['day' => $day['carbon']->format('Y-m-d'), 'day_of_month' => $day['carbon']->day, 'marked' => $day['marked']];
         }
     }
     //add empty days at end of weeks with less than 7 days
     foreach ($calendar as $month => $days) {
         $month -= 1;
         foreach ($generated_year['months'][$month]['weeks'] as $week_index => $week) {
             # empty days to add
             $empty = 7 - count($week['days']);
             for ($e = $empty; $e > 0; $e--) {
                 $generated_year['months'][$month]['weeks'][$week_index]['days'][] = false;
             }
         }
     }
     return $generated_year;
 }
 /**
  *
  */
 public function calculatePayDays()
 {
     $result = [];
     $currentMonth = $this->startDate->copy();
     while ($currentMonth->lte($this->endDate) && $currentMonth->diffInMonths($this->endDate) >= 0) {
         $resultForCurrentMonth = ['month' => $currentMonth->copy()];
         $resultForCurrentMonth['salaryDate'] = $this->calculateSalaryDateByMonth($currentMonth->copy());
         $resultForCurrentMonth['bonusDate'] = $this->calculateBonusDateByMonth($currentMonth->copy());
         $currentMonth->addMonth();
         $result[] = $resultForCurrentMonth;
     }
     return $result;
 }
Example #9
0
 public function calcElements()
 {
     $this->calHeadings = [Lang::get('kurtjensen.mycalendar::lang.month.day_sun'), Lang::get('kurtjensen.mycalendar::lang.month.day_mon'), Lang::get('kurtjensen.mycalendar::lang.month.day_tue'), Lang::get('kurtjensen.mycalendar::lang.month.day_wed'), Lang::get('kurtjensen.mycalendar::lang.month.day_thu'), Lang::get('kurtjensen.mycalendar::lang.month.day_fri'), Lang::get('kurtjensen.mycalendar::lang.month.day_sat')];
     $time = new Carbon($this->month . '/1/' . $this->year);
     $time->copy();
     $this->monthTitle = $time->format('F');
     $this->monthNum = $time->month;
     $this->running_day = $time->dayOfWeek;
     $this->days_in_month = $time->daysInMonth;
     $this->dayPointer = 0 - $this->running_day;
     $prevMonthLastDay = $time->copy()->subMonth()->daysInMonth;
     $this->prevMonthMonday = $this->dayPointer + $prevMonthLastDay + 1;
     $this->linkNextMonth = $time->copy()->addDays(32);
     $this->linkPrevMonth = $time->copy()->subDays(2);
 }
 /**
  * @return null|Carbon
  */
 public function getDeletedAt()
 {
     if ($this->deletedAt === null) {
         return null;
     }
     return $this->deletedAt->copy();
 }
Example #11
0
 /**
  * @param Carbon $date
  * @param string $chunk
  * @return ChannelProgramming
  * @throws \Exception
  */
 private static function parseChannelChunk(Carbon $date, $chunk)
 {
     $res = new ChannelProgramming();
     $channelName = self::str_between_exclude($chunk, '<div class="tabla_topic">', '</div>');
     $channelName = trim(strip_tags($channelName));
     if (!$channelName) {
         throw new \Exception('parse error: no channel name');
     }
     $res->setChannelName($channelName);
     $content = self::str_between_exclude($chunk, '<ul class="prog_tabla">', '</ul>');
     if (!$content) {
         throw new \Exception('parse error: no content');
     }
     $content = str_replace('</li>', "\n", $content);
     $content = str_replace("\t", '', $content);
     $content = strip_tags($content);
     $programs = explode("\n", trim($content));
     $foundHour = 0;
     $addDays = 0;
     /** @var ChannelEvent $event */
     $event = null;
     foreach ($programs as $prog) {
         if (!$prog) {
             continue;
         }
         preg_match('/^(?<hh>[\\d]+)+\\:(?<mm>[\\d]+)+$/ui', $prog, $match);
         if (!empty($match['hh']) && !empty($match['mm'])) {
             $event = new ChannelEvent();
             $time = explode(' ', $prog)[0];
             $timeParts = explode(':', $time);
             if ($timeParts[0] < $foundHour) {
                 // new day
                 $addDays = 1;
             }
             $foundHour = $timeParts[0];
             $event->starts_at = $date->copy();
             $event->starts_at->addDays($addDays);
             $event->starts_at->hour = $timeParts[0];
             $event->starts_at->minute = $timeParts[1];
             continue;
         }
         if (!$event) {
             continue;
         }
         $event->title = $prog;
         $res->addEvent($event);
     }
     // guesstimate end time for each event
     $events = $res->getEvents();
     for ($i = 0; $i < count($events); $i++) {
         if (!empty($events[$i + 1])) {
             $events[$i]->ends_at = $events[$i + 1]->starts_at->copy();
         } else {
             // HACK: we dont know end of last event, so we add 2 hours
             $events[$i]->ends_at = $events[$i]->starts_at->copy()->addHours(2);
         }
     }
     $res->setEvents($events);
     return $res;
 }
 protected function getTotalByTypeDate($type, Account $acc, Carbon $date)
 {
     $start = $date->copy();
     $start->setTime(0, 0, 0);
     $end = $start->copy();
     $end->setTime(23, 59, 59);
     return $this->createQueryBuilder('mt')->leftJoin('mt.account', 'acc')->where('acc = :acc')->andWhere('mt.date >= :start')->andWhere('mt.date <= :end')->andWhere('mt.transaction_type = :type')->setParameters(['acc' => $acc, 'start' => $start, 'end' => $end, 'type' => $type]);
 }
 /**
  * Calculate event length in seconds
  *
  * @param array $data
  *
  * @return int
  */
 protected function calculateEventLength(array $data)
 {
     $start = $this->carbon->copy()->setTimestamp(strtotime($data['start']['date'] . ' ' . $data['start']['time']));
     if (array_key_exists('all_day', $data)) {
         $end = $this->carbon->copy()->setTimestamp(strtotime($data['start']['date'] . ' 23:59:59'));
     } else {
         $end = $this->carbon->copy()->setTimestamp(strtotime($data['start']['date'] . ' ' . $data['end']['time']));
     }
     return $start->diffInSeconds($end);
 }
Example #14
0
 public static function zipOneDay(Carbon $date)
 {
     $begin = $date->copy()->setTime(0, 0, 0);
     $end = $date->copy()->setTime(23, 59, 59);
     $deleteLocs = [];
     $videoLocs = [];
     $videos = Video::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($videos as $video) {
         $deleteLocs[] = $video->location;
         $videoLocs[] = storage_path('app/' . $video->location);
         $video->state = 'zipped';
         $video->save();
     }
     $imageLocs = [];
     $images = Image::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($images as $image) {
         $deleteLocs[] = $image->location;
         $imageLocs[] = storage_path('app/' . $image->location);
         $image->state = 'zipped';
         $image->save();
     }
     $locs = array_merge($videoLocs, $imageLocs);
     if (count($locs) == 0) {
         Log::info('TumblrZip : no file to be ziped.');
         return;
     }
     $zipName = $begin->toDateString() . '.zip';
     $zipLocs = 'zips/' . $zipName;
     $zippy = Zippy::load();
     $zippy->create(storage_path('app/' . $zipLocs), $locs);
     $zip = new Zip();
     $zip->state = 'ziped';
     $zip->error = '';
     $zip->name = $zipName;
     $zip->date = $begin->toDateString();
     $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB';
     $zip->imageSize = count($imageLocs);
     $zip->videoSize = count($videoLocs);
     $zip->location = $zipLocs;
     $zip->save();
     Storage::delete($deleteLocs);
 }
Example #15
0
 /**
  * Set label for line and bar charts
  *
  * @return Collection
  */
 private function setLabel()
 {
     // Copy the Carbon instance of start_date
     $iterate_date = $this->start_date->copy();
     $labels = collect();
     while ($iterate_date <= $this->end_date) {
         $labels->push($iterate_date->format('M d'));
         $iterate_date->addDay();
     }
     return $labels;
 }
 /**
  * Set the internal iterator for day of week for the instance.
  *
  * @param $dayOfWeek
  * @param callable $callback
  * @return $this
  */
 public function eachDayOfWeek($dayOfWeek, \Closure $callback)
 {
     $start = $this->startDate->copy();
     if ($start->dayOfWeek !== $dayOfWeek) {
         $start->next($dayOfWeek);
     }
     if ($start < $this->endDate) {
         $period = new static($start, $this->endDate);
         $period->eachDays(CarbonDate::DAYS_PER_WEEK, function (CarbonPeriod $period) use($callback) {
             $callback(new static($period->start(), $period->start()->addDay()));
         });
     }
     return $this;
 }
 /**
  * Purge the expired records.
  *
  * @param string $model
  * @param int    $days
  *
  * @return int|boolean
  */
 protected function purgeExpiredRecordsForModel($model, $days)
 {
     if (!class_exists($model)) {
         $this->recordMessage(sprintf("The model [%s] was not found.", $model), 'warning');
         return false;
     }
     if (!method_exists($model, 'onlyTrashed') || !method_exists($model, 'forceDelete')) {
         $this->recordMessage(sprintf("The model [%s] does not support soft deleting.", $model), 'error');
         return false;
     }
     $expiration = $this->now->copy()->subDays($days);
     $query = $this->laravel->make($model)->where('deleted_at', '<', $expiration)->onlyTrashed();
     $count = $this->purgeRecordsAsConfigured($query, $model);
     $this->recordMessage(sprintf("Purged %s record(s) for %s that was deleted before %s.", $count, $model, $expiration->toIso8601String()));
     return $count;
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create($member_id)
 {
     $memberships = Membership::all()->lists('description', 'id');
     $membershipsAll = Membership::all();
     $member = Member::find($member_id);
     $rangeArray = array();
     $rangeDates = \App\Affiliation::orderBy('finalization', 'DEC')->where('member_id', $member_id)->where('finalization', '>=', Carbon::now())->get();
     foreach ($rangeDates as $range) {
         $initiationRange = new Carbon($range->initiation);
         $finalizationRange = new Carbon($range->finalization);
         $diference = $initiationRange->diffInDays($finalizationRange);
         for ($i = 0; $i <= $diference; $i++) {
             array_unshift($rangeArray, "'" . $initiationRange->copy()->format('Y-m-d') . "'");
             $initiationRange->addDay();
         }
     }
     return view('affiliation.create')->with('memberships', $memberships)->with('membershipsAll', $membershipsAll)->with('member', $member)->with('affiliationRange', $rangeArray);
 }
Example #19
0
 public function monthlyLogs(Carbon $date, $branch)
 {
     $arr = [];
     $fr = $date->firstOfMonth();
     $to = $date->copy()->lastOfMonth();
     $data = $this->aggregateDailyLogs($fr, $to, $branch->id);
     for ($i = 0; $i < $date->daysInMonth; $i++) {
         $date = $fr->copy()->addDays($i);
         $filtered = $data->filter(function ($item) use($date) {
             return $item->filedate->format('Y-m-d') == $date->format('Y-m-d') ? $item : null;
         });
         $b = $filtered->first();
         if (!is_null($b)) {
             $e = file_exists(config('filesystems.disks.backup.' . app()->environment() . '.root') . $branch->code . DS . $b->year . DS . $b->filedate->format('m') . DS . $b->filename);
         } else {
             $e = 0;
         }
         array_push($arr, ['date' => $date, 'backup' => $b, 'exist' => $e]);
     }
     return $arr;
 }
Example #20
0
 public function dayStart(Carbon $date = null)
 {
     if ($date === null) {
         $date = new Carbon();
     }
     $creationTime = Carbon::createFromTimestamp($this->getCreationTime());
     return $date->copy()->setTime($creationTime->hour, 0);
 }
 public function getRawEmployeeTimelog($employeeid, Carbon $fr, Carbon $to)
 {
     return $this->scopeQuery(function ($query) use($employeeid, $fr, $to) {
         return $query->where('employeeid', $employeeid)->whereBetween('datetime', [$fr->copy()->format('Y-m-d') . ' 06:00:00', $to->copy()->addDay()->format('Y-m-d') . ' 05:59:59']);
     });
 }
Example #22
0
 /**
  * Return starting time for this shift
  * @param Carbon $time
  * @return Carbon
  */
 public function setRelativeTime($time)
 {
     $this->relativeTime = $time->copy();
     return $this;
 }
Example #23
0
 /**
  * Calculate how many minutes have been spent on the activity
  * for the week
  * @param Carbon $startOfWeek
  * @param Carbon $endOfWeek
  * @return int
  */
 public function calculateTotalMinutesForWeek(Carbon $startOfWeek, Carbon $endOfWeek)
 {
     $total = 0;
     $day = $endOfWeek->copy();
     while ($day >= $startOfWeek) {
         $total += $this->calculateTotalMinutesForDay($day->copy()->startOfDay(), $day->copy()->endOfDay());
         $day = $day->subDay();
     }
     return $total;
 }
 public function generateWorkOrdersForPo($po, $workOrders, $startDate = null)
 {
     $newWoIds = [];
     if ($workOrders && is_array($workOrders)) {
         $pickupDate = new Carbon($po->pickup_date);
         $pickupDate->timezone = 'America/Halifax';
         if ($startDate != null) {
             $workOrderStart = new Carbon($startDate);
         } else {
             $workOrderStart = $pickupDate->copy()->subDays($this->daysLeadTimeFromPickup);
         }
         $workOrderEnd = $pickupDate;
         foreach ($workOrders as $wo) {
             $quantityToCreate = $wo['quantity_to_create'];
             for ($i = 0; $i < $quantityToCreate; $i++) {
                 $newWo = WorkOrder::create(['customer_id' => $po->customer_id, 'product_id' => $wo['product_id'], 'purchase_order_id' => $po->id, 'quantity' => 1, 'start_date' => $workOrderStart, 'end_date' => $workOrderEnd, 'completed' => 0, 'notes' => 'Generated by PO #' . $po->id]);
                 array_push($newWoIds, $newWo->id);
             }
             /*
                             $newWo = WorkOrder::create(['customer_id' => $po->customer_id,
                                 'product_id' => $wo['product_id'],
                                 'purchase_order_id' => $po->id,
                                 'quantity' => $wo['quantity_to_create'],
                                 'start_date' => $workOrderStart,
                                 'end_date' => $workOrderEnd,
                                 'completed' => 0,
                                 'notes' => 'Generated by PO #' . $po->id
                             ]);
             
                             array_push($newWoIds, $newWo->id);
             */
         }
     }
     return $newWoIds;
 }
 /**
  * Zoom uses a non-standard date format.
  * Format: 2015-01-01T00:00:00Z
  */
 protected function formatDateToZoom(Carbon $time)
 {
     return $time->copy()->tz('UTC')->format(self::TIME_FORMAT);
 }
 public function getOrderedBalancesByDate(Account $acc, Carbon $date)
 {
     $end = $date->copy();
     $start = $date->subDays(7);
     return $this->createQueryBuilder('ab')->leftJoin('ab.account', 'acc')->where('acc = :account')->andWhere('ab.created_at >= :start')->andWhere('ab.created_at <= :end')->addOrderBy('ab.created_at', 'ASC')->setParameters(['account' => $acc, 'start' => $start, 'end' => $end])->getQuery()->getResult();
 }
Example #27
0
 /**
  * Convert the supplied Carbon instance to an XML string.
  *
  * @param Carbon $php
  * @return string
  */
 public function toXml($php)
 {
     return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $php->copy()->timezone('UTC')->format($this->xmlFormat));
 }
 public function todayTopSales(Carbon $date, $limit = 10)
 {
     $arr = [];
     $ds_null = false;
     $current_day_zero_sales = false;
     $ds = DailySales::where('date', $date->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get();
     if (count($ds) == '0') {
         $ds = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get();
         $ds_null = true;
     } else {
         foreach ($ds as $d) {
             if ($d->sales == '0.00') {
                 $ds = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get();
                 $ds_null = true;
                 continue;
             }
         }
     }
     foreach ($ds as $d) {
         $branch = Branch::where('id', $d->branchid)->get(['code', 'descriptor', 'id'])->first();
         if ($ds_null) {
             $ds_today = new DailySales();
             $ds_yesteday = $d;
         } else {
             $ds_today = $d;
             $ds_yesteday = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->where('branchid', $d->branchid)->first();
         }
         $ds_otherday = DailySales::where('date', $date->copy()->subDay(2)->format('Y-m-d'))->where('branchid', $d->branchid)->first();
         $s = new StdClass();
         $c = new StdClass();
         $s->branch = $branch;
         $s->today = $ds_today;
         $s->yesterday = $ds_yesteday;
         $s->otherday = $ds_otherday;
         $c->sales = $ds_today->sales - $ds_yesteday->sales;
         $s->today->sign = $this->getSign($ds_today->sales - $ds_yesteday->sales);
         $c->sales1 = $ds_yesteday->sales - $ds_otherday->sales;
         $s->yesterday->sign = $this->getSign($ds_yesteday->sales - $ds_otherday->sales);
         $s->diff = $c;
         array_push($arr, $s);
     }
     return collect($arr);
 }
Example #29
-1
 public function endDate() : Carbon
 {
     return $this->endDate->copy();
 }
Example #30
-2
 /**
  * Index Page for this controller.
  *
  * Maps to the following URL
  * 		http://example.com/index.php/welcome
  *	- or -
  * 		http://example.com/index.php/welcome/index
  *	- or -
  * Since this controller is set as the default controller in
  * config/routes.php, it's displayed at http://example.com/
  *
  * So any other public methods not prefixed with an underscore will
  * map to /index.php/welcome/<method_name>
  * @see http://codeigniter.com/user_guide/general/urls.html
  */
 public function index()
 {
     // $this->load->view('welcome_message');
     $personas = array(array("nombre" => "beimar", "apellido" => "huarachi"), array("nombre" => "carlos", "apellido" => "mamani"), array("nombre" => "alison", "apellido" => "fernandez"), array("nombre" => "diego", "apellido" => "ortiz"));
     foreach ($personas as $persona) {
         foreach ($persona as $key => $value) {
             echo "<br>";
             echo $key . " === " . $value;
         }
         echo "otra Persona<br>";
     }
     $timestamp = '2016-01-06 16:34:00';
     $otro = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'America/La_Paz');
     echo $otro->timezoneName . "<br>";
     echo "==========<br>";
     $moment = Carbon::now();
     echo "" . $moment . "<br>";
     echo "" . $moment->timezoneName . "<br>";
     $moment->timezone = "America/La_Paz";
     $moment->timestamp = 169957925;
     echo "" . $moment->timezoneName . "<br>";
     echo "" . $moment . "<br>";
     echo "==========<br>";
     $date = new Carbon("2016-01-06 16:34:00");
     $fecha = $date->copy()->addDay();
     echo "<br>" . $fecha;
     $texto = "hola '" . $fecha . "'";
     echo "<br>" . $texto;
     if ($date) {
         for ($i = 0; $i < 4; $i++) {
             echo "<br>";
             echo "fecha : ";
             $date->addHour();
             echo $date->toDateTimeString();
         }
     }
 }