Example #1
0
 /**
  * Returns the yule party date for the given year
  *
  * @param Carbon $date
  * @return Carbon
  */
 private function fromDateToYuleDate(Carbon $date)
 {
     while ($date->dayOfWeek != Carbon::FRIDAY) {
         $date->addDay();
     }
     $date->addDays(8);
     return $date;
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     try {
         DB::beginTransaction();
         $validator = Validator::make(Input::all(), array('name' => 'required', 'email' => 'required|email', 'password' => 'required'));
         if ($validator->fails()) {
             return Response::json($validator->messages(), 400);
         }
         $name = Input::get('name');
         $password = Input::get('password');
         $email = Input::get('email');
         $user = User::findUserByEmail($email);
         if (isset($user)) {
             return Response::json(array('error' => Config::get('constants.STATUS_CODES.USER.USER_EXISTS'), 'error_message' => 'User already exists'), 500);
         }
         $user = User::create(array('name' => $name, 'uid' => 'usr_' . str_random(16), 'english_name' => $name, 'email' => $email, 'password' => $password, 'raw_password' => $password, 'activated' => Config::get('auth.need_activated') ? false : true));
         if (Config::get('auth.need_activated')) {
             $activateTokens = $user->validActivationCodes()->get();
             if (count($activateTokens) > 1) {
                 throw new Exception('More than one activated token found, user: '******'auth.activated_token_expired_in'));
                 \Log::info($expire_time->timestamp);
                 $token = Util::geneateRandom();
                 $userActivationCode = new UserActivationCode();
                 $userActivationCode->token = $token;
                 $userActivationCode->expire_time = $expire_time->timestamp;
                 $user->validActivationCodes()->save($userActivationCode);
             }
         }
         $userRole = Role::where('name', 'user')->get()->first();
         $user->attachRole($userRole);
         if (Config::get('auth.need_activated')) {
             $this->mailer->welcomeButNeedActivate($user);
         } else {
             $this->mailer->welcome($user);
         }
         DB::commit();
         if (!Config::get('auth.need_activated')) {
             return Response::json(array('success_code' => Config::get('constants.STATUS_CODES.USER.OK'), 'data' => $user->toArray()));
         } else {
             return Response::json(array('error' => Config::get('constants.STATUS_CODES.USER.NEED_ACTIVATED'), 'error_message' => 'Successfully Registered, You need to activate then.', 'data' => $user->toArray()), 500);
         }
     } catch (Exception $e) {
         \Log::error($e);
         DB::rollback();
         return Response::json(array('error' => true, 'error_message' => $e->getMessage()), 500);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(AffiliationCreateRequest $request)
 {
     //dd($request);
     /*"_token" => "8s9rQffPRk7lOCtbGidK1Wzvp4fmMQ00GLTvNFQv"
           "member_id" => "1"
           "membership_id" => "1"
           "initiation" => "2016-02-11"
           "type" => "payment"
     
               0 => "initiation"
         1 => "finalization"
         2 => "price"
         3 => "payout"
         4 => "type"
         5 => "active"
         6 => "member_id"
         7 => "membership_id"*/
     $membership = Membership::find($request->membership_id);
     $affiliation = new Affiliation($request->all());
     $payment = new Payment();
     $end = new Carbon($request->initiation);
     if ($membership->month > 0) {
         $end->addMonths($membership->month);
     }
     if ($membership->day > 0) {
         $end->addDays($membership->day - 1);
     }
     $payment->member_id = $request->member_id;
     $affiliation->finalization = $end;
     $affiliation->price = $membership->price;
     if ($request->type == "credit") {
         $payment->amount = $request->payout;
         $payment->type = "payout";
     } else {
         $payment->amount = $membership->price;
         $payment->type = "payment";
     }
     $affiliation->save();
     if ($payment->amount > 0) {
         $payment->save();
     }
     Flash::success("¡Se ha registrado la afiliacion del miembro de manera exitosa!");
     return redirect()->route('admin.member.show', [$request->member_id, '#membership-member']);
 }
Example #4
0
File: Queue.php Project: pckg/queue
 public function getChartData()
 {
     $minDate = date('Y-m-d', strtotime('-3 months'));
     $maxDate = date('Y-m-d', strtotime('+1 day'));
     $data = (new QueueEntity())->select(['status', 'week' => 'WEEKOFYEAR(created_at)', 'year' => 'YEAR(created_at)', 'count' => 'COUNT(id)'])->groupBy('WEEKOFYEAR(created_at), YEAR(year), status')->where('created_at', $minDate, '>')->all();
     $date = new Carbon($minDate);
     $times = [];
     /**
      * Prepare times.
      */
     while ($maxDate > $date) {
         $times[$date->year . '-' . $date->weekOfYear] = [];
         $date->addDays(7);
     }
     $statuses = [];
     $data->each(function (QueueRecord $queue) use(&$times, &$statuses) {
         $times[$queue->year . '-' . $queue->week][$queue->status] = $queue->count;
         $statuses[$queue->status][$queue->year . '-' . $queue->week] = $queue->count;
     });
     $chart = ['labels' => array_keys($times), 'datasets' => []];
     $colors = ['finished' => 'rgba(0, 255, 0, 0.33)', 'failed_permanently' => 'rgba(255, 0, 0, 0.33)', 'created' => 'rgba(0, 0, 255, 0.33)', 'skipped_unique' => 'rgba(100, 100, 100, 0.33)', 'total' => 'rgba(50, 50, 50, 0.33)'];
     foreach ($statuses as $status => $statusTimes) {
         $dataset = ['label' => $status, 'data' => [], 'borderColor' => $colors[$status], 'backgroundColor' => 'transparent', 'borderWidth' => 1];
         foreach ($times as $time => $timeStatuses) {
             $dataset['data'][] = $statusTimes[$time] ?? 0;
         }
         $chart['datasets'][] = $dataset;
     }
     $dataset = ['label' => 'total', 'data' => [], 'borderColor' => $colors['total'], 'backgroundColor' => 'transparent', 'borderWidth' => 1];
     foreach ($times as $time => $statuses) {
         $total = 0;
         foreach ($statuses as $status) {
             $total += $status;
         }
         $dataset['data'][] = $total;
     }
     $chart['datasets'][] = $dataset;
     return $chart;
 }
Example #5
0
 protected function calculateObservedDay(Carbon $date)
 {
     if ($date->dayOfWeek === Carbon::SUNDAY) {
         return $date->addDays(1);
     } elseif ($date->dayOfWeek === Carbon::SATURDAY) {
         return $date->subDays(1);
     }
     return $date;
 }
Example #6
0
 /**
  * Restricts to dates after $days days from today.
  * @param  object $query
  * @param  integer $days
  * @return object $query
  */
 public function scopeFuture($query, $days)
 {
     $date = new Carbon();
     $date->addDays($days);
     return $query->where('date', '<=', $date);
 }
Example #7
0
 /**
  * Display single items of a plan with options to move to the next or previous item on this plan
  *
  * This is used for the presentation views (lyrics, chords, sheetmusic or leader)
  *
  * @param  int     $id      item id
  * @param  string  $present (optional) chords (default), sheetmusic or present (for overhead presentations) or leader for the Leader's Event Script
  *
  * @return \Illuminate\Http\Response
  */
 public function show($id, $present = null)
 {
     $item = Item::find($id);
     if ($item) {
         $events = [];
         // is this the Announcements Slide?
         if ($item->key == 'announcements') {
             $today = new Carbon($item->plan->date);
             $oneWeek = $today->addDays(7);
             // get ALL future events incl today
             $events = Plan::with(['type', 'leader', 'teacher'])->whereDate('date', '>', $item->plan->date->subDay())->whereDate('date', '<', $oneWeek)->where('id', '!=', $item->plan_id)->orderBy('date', 'asc')->get();
         }
         // default presentation type is to show chords
         if (!$present) {
             $present = 'chords';
         }
         return view('cspot.' . $present, ['item' => $item, 'events' => $events, 'versionsEnum' => json_decode(env('BIBLE_VERSIONS')), 'items' => $item->plan->items->sortBy('seq_no')->all(), 'type' => $present, 'bibleTexts' => getBibleTexts($item->comment)]);
     }
     flashError('Error! Item with ID "' . $id . '" was not found! (F:show)');
     return \Redirect::route('home');
 }
 /**
  * @param $dateSelected
  *
  * @return array
  */
 protected function getBeginningAndEndingWeekDates($dateSelected)
 {
     $dateSelected = $this->deriveDateSelected($dateSelected);
     $bwDate = new Carbon($dateSelected);
     if ($bwDate->dayOfWeek == 0) {
         $ewDate = new Carbon($bwDate);
         $iso_beginning_dow_date = new Carbon($bwDate);
         $ewDate->addDays(6);
     } else {
         $bwDate->startOfWeek();
         // iso standard; Monday is the start of week.
         $iso_beginning_dow_date = new Carbon($bwDate);
         $bwDate->subDay();
         // adjust to Sunday as this is our current offset.
         $ewDate = new Carbon($bwDate);
         $ewDate->addDays(6);
     }
     return [$bwDate, $ewDate, $iso_beginning_dow_date];
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $faker = \Faker\Factory::create();
     // create agents
     $agents_counter = 1;
     for ($a = 1; $a <= $this->agents_qty; $a++) {
         $agent_info = new \App\User();
         $agent_info->name = $faker->name;
         $agent_info->email = 'agent' . $agents_counter . $this->email_domain;
         $agent_info->ticketit_agent = 1;
         $agent_info->password = Hash::make($this->default_agent_password);
         $agent_info->save();
         $agents[$agent_info->id] = $agent_info;
         $agents_counter++;
     }
     // create tickets statuses
     foreach ($this->statuses as $name => $color) {
         $status = \Kordy\Ticketit\Models\Status::create(['name' => $name, 'color' => $color]);
     }
     $counter = 0;
     // create tickets statuses
     foreach ($this->categories as $name => $color) {
         $category = \Kordy\Ticketit\Models\Category::create(['name' => $name, 'color' => $color]);
         $agent = array_rand($agents, $this->agents_per_category);
         $category->agents()->attach($agent);
         $counter++;
     }
     // create tickets statuses
     foreach ($this->priorities as $name => $color) {
         $priority = \Kordy\Ticketit\Models\Priority::create(['name' => $name, 'color' => $color]);
     }
     $categories_qty = \Kordy\Ticketit\Models\Category::count();
     $priorities_qty = \Kordy\Ticketit\Models\Priority::count();
     $statuses_qty = \Kordy\Ticketit\Models\Status::count();
     // create users
     $users_counter = 1;
     for ($u = 1; $u <= $this->users_qty; $u++) {
         $user_info = new \App\User();
         $user_info->name = $faker->name;
         $user_info->email = 'user' . $users_counter . $this->email_domain;
         $user_info->ticketit_agent = 0;
         $user_info->password = Hash::make($this->default_user_password);
         $user_info->save();
         $users_counter++;
         $tickets_qty = rand($this->tickets_per_user_min, $this->tickets_per_user_max);
         for ($t = 1; $t <= $tickets_qty; $t++) {
             $rand_category = rand(1, $categories_qty);
             $priority_id = rand(1, $priorities_qty);
             do {
                 $rand_status = rand(1, $statuses_qty);
             } while ($rand_status == $this->default_closed_status_id);
             $category = \Kordy\Ticketit\Models\Category::find($rand_category);
             $agents = $category->agents()->lists('name', 'id')->toArray();
             $agent_id = array_rand($agents);
             $random_create = rand(1, $this->tickets_date_period);
             $random_complete = rand($this->tickets_min_close_period, $this->tickets_max_close_period);
             $ticket = new \Kordy\Ticketit\Models\Ticket();
             $ticket->subject = $faker->text(50);
             $ticket->content = $faker->paragraph($nbSentences = 10);
             $ticket->status_id = $rand_status;
             $ticket->priority_id = $priority_id;
             $ticket->user_id = $user_info->id;
             $ticket->agent_id = $agent_id;
             $ticket->category_id = $rand_category;
             $ticket->created_at = \Carbon\Carbon::now()->subDays($random_create);
             $ticket->updated_at = \Carbon\Carbon::now()->subDays($random_create);
             $completed_at = new Carbon($ticket->created_at);
             if (!$completed_at->addDays($random_complete)->gt(\Carbon\Carbon::now())) {
                 $ticket->completed_at = $completed_at;
                 $ticket->updated_at = $completed_at;
                 $ticket->status_id = $this->default_closed_status_id;
             }
             $ticket->save();
             $comments_qty = rand($this->comments_per_ticket_min, $this->comments_per_ticket_max);
             for ($c = 1; $c <= $comments_qty; $c++) {
                 if (is_null($ticket->completed_at)) {
                     $random_comment_date = $faker->dateTimeBetween('-' . $random_create . ' days', 'now');
                 } else {
                     $random_comment_date = $faker->dateTimeBetween('-' . $random_create . ' days', '-' . ($random_create - $random_complete) . ' days');
                 }
                 $comment = new \Kordy\Ticketit\Models\Comment();
                 $comment->ticket_id = $ticket->id;
                 $comment->content = $faker->paragraph($nbSentences = 10);
                 if ($c % 2 == 0) {
                     $comment->user_id = $ticket->user_id;
                 } else {
                     $comment->user_id = $ticket->agent_id;
                 }
                 $comment->created_at = $random_comment_date;
                 $comment->updated_at = $random_comment_date;
                 $comment->save();
             }
             $last_comment = $ticket->Comments->sortByDesc('created_at')->first();
             $ticket->updated_at = $last_comment['created_at'];
             $ticket->save();
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $today = Carbon::today();
     $nextMonth = Carbon::today()->addMonth();
     $monday = new Carbon('next monday');
     $sunday = new Carbon('next monday');
     $sunday->addDays(6);
     echo $sunday;
     $planningen = Planning::where('first_day', '>', $today)->get();
     var_dump($planningen);
     while ($monday < $nextMonth) {
         $not_exists = true;
         foreach ($planningen as $planning) {
             if ($monday >= $planning->first_day && $monday <= $planning->last_day) {
                 $not_exists = false;
             }
         }
         if ($not_exists) {
             $newPlanning = new Planning();
             $newPlanning->first_day = $monday;
             $newPlanning->last_day = $sunday;
             $newPlanning->save();
         }
         $monday->addWeek();
         $sunday->addWeek();
     }
 }
Example #11
-7
 /**
  *
  * @param Item $item
  * @param Carbon $notBeforeTime
  * @return Carbon
  */
 private function calculateNotBeforeTime(Item $item, Carbon $notBeforeTime)
 {
     switch ($item->recurring_unit) {
         case "minute":
             $notBeforeTime->addMinutes($item->recurring_frequency);
             break;
         case "hour":
             $notBeforeTime->addHours($item->recurring_frequency);
             break;
         case "day":
             $notBeforeTime->addDays($item->recurring_frequency);
             break;
         case "week":
             $notBeforeTime->addWeeks($item->recurring_frequency);
             break;
         case "month":
             $notBeforeTime->addMonths($item->recurring_frequency);
             break;
         case "year":
             $notBeforeTime->addYears($item->recurring_frequency);
             break;
     }
     return $notBeforeTime;
 }