Exemplo n.º 1
0
 public static function loadHistory($users)
 {
     $userIds = [];
     if (is_array($users)) {
         foreach ($users as $user) {
             $userIds[] = $user->user_id;
         }
     } else {
         $userIds[] = $users;
     }
     $activityTypes = [ACTIVITY_TYPE_CREATE_CLIENT, ACTIVITY_TYPE_CREATE_TASK, ACTIVITY_TYPE_UPDATE_TASK, ACTIVITY_TYPE_CREATE_INVOICE, ACTIVITY_TYPE_UPDATE_INVOICE, ACTIVITY_TYPE_EMAIL_INVOICE, ACTIVITY_TYPE_CREATE_QUOTE, ACTIVITY_TYPE_UPDATE_QUOTE, ACTIVITY_TYPE_EMAIL_QUOTE, ACTIVITY_TYPE_VIEW_INVOICE, ACTIVITY_TYPE_VIEW_QUOTE];
     $activities = Activity::scope()->with(['client.contacts', 'invoice', 'task'])->whereIn('user_id', $userIds)->whereIn('activity_type_id', $activityTypes)->orderBy('id', 'asc')->limit(100)->get();
     foreach ($activities as $activity) {
         if ($activity->activity_type_id == ACTIVITY_TYPE_CREATE_CLIENT) {
             $entity = $activity->client;
         } else {
             if ($activity->activity_type_id == ACTIVITY_TYPE_CREATE_TASK || $activity->activity_type_id == ACTIVITY_TYPE_UPDATE_TASK) {
                 $entity = $activity->task;
                 $entity->setRelation('client', $activity->client);
             } else {
                 $entity = $activity->invoice;
                 $entity->setRelation('client', $activity->client);
             }
         }
         static::trackViewed($entity);
     }
 }
Exemplo n.º 2
0
 /**
  * Handle the event.
  *
  * @param  UserSignedUp $event
  * @return void
  */
 public function handle(UserSignedUp $event)
 {
     $user = Auth::user();
     if (Utils::isNinjaProd()) {
         $this->userMailer->sendConfirmation($user);
     } elseif (Utils::isNinjaDev()) {
         // do nothing
     } else {
         $this->accountRepo->registerNinjaUser($user);
     }
     $activities = Activity::scope()->get();
     foreach ($activities as $activity) {
         $activity->message = str_replace('Guest', $user->getFullName(), $activity->message);
         $activity->save();
     }
     session([SESSION_COUNTER => -1]);
 }
Exemplo n.º 3
0
 public function invoiceHistory($publicId)
 {
     $invoice = Invoice::withTrashed()->scope($publicId)->firstOrFail();
     $invoice->load('user', 'invoice_items', 'account.country', 'client.contacts', 'client.country');
     $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date);
     $invoice->due_date = Utils::fromSqlDate($invoice->due_date);
     $invoice->is_pro = Auth::user()->isPro();
     $invoice->is_quote = intval($invoice->is_quote);
     $activityTypeId = $invoice->is_quote ? ACTIVITY_TYPE_UPDATE_QUOTE : ACTIVITY_TYPE_UPDATE_INVOICE;
     $activities = Activity::scope(false, $invoice->account_id)->where('activity_type_id', '=', $activityTypeId)->where('invoice_id', '=', $invoice->id)->orderBy('id', 'desc')->get(['id', 'created_at', 'user_id', 'json_backup']);
     $versionsJson = [];
     $versionsSelect = [];
     $lastId = false;
     foreach ($activities as $activity) {
         $backup = json_decode($activity->json_backup);
         $backup->invoice_date = Utils::fromSqlDate($backup->invoice_date);
         $backup->due_date = Utils::fromSqlDate($backup->due_date);
         $backup->is_pro = Auth::user()->isPro();
         $backup->is_quote = isset($backup->is_quote) && intval($backup->is_quote);
         $backup->account = $invoice->account->toArray();
         $versionsJson[$activity->id] = $backup;
         $key = Utils::timestampToDateTimeString(strtotime($activity->created_at)) . ' - ' . $activity->user->getDisplayName();
         $versionsSelect[$lastId ? $lastId : 0] = $key;
         $lastId = $activity->id;
     }
     $versionsSelect[$lastId] = Utils::timestampToDateTimeString(strtotime($invoice->created_at)) . ' - ' . $invoice->user->getDisplayName();
     $data = ['invoice' => $invoice, 'versionsJson' => json_encode($versionsJson), 'versionsSelect' => $versionsSelect, 'invoiceDesigns' => InvoiceDesign::getDesigns()];
     return View::make('invoices.history', $data);
 }
 public function invoiceHistory(InvoiceRequest $request)
 {
     $invoice = $request->entity();
     $invoice->load('user', 'invoice_items', 'documents', 'expenses', 'expenses.documents', 'account.country', 'client.contacts', 'client.country');
     $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date);
     $invoice->due_date = Utils::fromSqlDate($invoice->due_date);
     $invoice->features = ['customize_invoice_design' => Auth::user()->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN), 'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY), 'invoice_settings' => Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS)];
     $invoice->invoice_type_id = intval($invoice->invoice_type_id);
     $activityTypeId = $invoice->isType(INVOICE_TYPE_QUOTE) ? ACTIVITY_TYPE_UPDATE_QUOTE : ACTIVITY_TYPE_UPDATE_INVOICE;
     $activities = Activity::scope(false, $invoice->account_id)->where('activity_type_id', '=', $activityTypeId)->where('invoice_id', '=', $invoice->id)->orderBy('id', 'desc')->get(['id', 'created_at', 'user_id', 'json_backup']);
     $versionsJson = [];
     $versionsSelect = [];
     $lastId = false;
     foreach ($activities as $activity) {
         if ($backup = json_decode($activity->json_backup)) {
             $backup->invoice_date = Utils::fromSqlDate($backup->invoice_date);
             $backup->due_date = Utils::fromSqlDate($backup->due_date);
             $backup->features = ['customize_invoice_design' => Auth::user()->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN), 'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY), 'invoice_settings' => Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS)];
             $backup->invoice_type_id = isset($backup->invoice_type_id) && intval($backup->invoice_type_id) == INVOICE_TYPE_QUOTE;
             $backup->account = $invoice->account->toArray();
             $versionsJson[$activity->id] = $backup;
             $key = Utils::timestampToDateTimeString(strtotime($activity->created_at)) . ' - ' . $activity->user->getDisplayName();
             $versionsSelect[$lastId ? $lastId : 0] = $key;
             $lastId = $activity->id;
         } else {
             Utils::logError('Failed to parse invoice backup');
         }
     }
     if ($lastId) {
         $versionsSelect[$lastId] = Utils::timestampToDateTimeString(strtotime($invoice->created_at)) . ' - ' . $invoice->user->getDisplayName();
     }
     $data = ['invoice' => $invoice, 'versionsJson' => json_encode($versionsJson), 'versionsSelect' => $versionsSelect, 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts')];
     return View::make('invoices.history', $data);
 }
 public function submitSignup()
 {
     $rules = array('new_first_name' => 'required', 'new_last_name' => 'required', 'new_password' => 'required|min:6', 'new_email' => 'email|required|unique:users,email,' . Auth::user()->id . ',id');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return '';
     }
     $user = Auth::user();
     $user->first_name = trim(Input::get('new_first_name'));
     $user->last_name = trim(Input::get('new_last_name'));
     $user->email = trim(strtolower(Input::get('new_email')));
     $user->username = $user->email;
     $user->password = bcrypt(trim(Input::get('new_password')));
     $user->registered = true;
     $user->save();
     if (Utils::isNinja()) {
         $this->userMailer->sendConfirmation($user);
     }
     $activities = Activity::scope()->get();
     foreach ($activities as $activity) {
         $activity->message = str_replace('Guest', $user->getFullName(), $activity->message);
         $activity->save();
     }
     if (Input::get('go_pro') == 'true') {
         Session::set(REQUESTED_PRO_PLAN, true);
     }
     Session::set(SESSION_COUNTER, -1);
     return "{$user->first_name} {$user->last_name}";
 }