Exemplo n.º 1
0
 public function __construct($organisationId = null)
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Organisations'));
     if ($organisationId !== null) {
         $this->currentUser->setActiveOrganisation($organisationId);
         redirect(url('controlpanel.home'));
     }
     // Set template and stuff specific for this page
     $this->setTemplate('Organisations.php');
     $this->getSite()->addWrappedCss('fonts.css');
     $this->getSite()->addWrappedCss('organisations.css');
     $this->getSite()->addWrappedJs('tab.js');
     // Get a list of organisations
     $this->organisations = $this->currentUser->getOrganisations();
     // If the user tries to create an organisation
     if ($this->isPostBack()) {
         $this->post->organisation->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             // Check if organisation name is taken
             if (ModelOrganisation::getByName($this->input('company'))->hasRow()) {
                 $this->setError(lang('An organisation with the name %s already exists - please request an invite from the organisation owner instead.', $this->input('company')));
             }
             if (!$this->hasErrors()) {
                 $organisation = new ModelOrganisation();
                 $organisation->setName($this->input('organisation'));
                 $organisation->save();
                 $this->currentUser->addOrganisation($organisation, UserRole::TYPE_OWNER);
                 $this->setMessage(lang('The organisation %s has been created', $organisation->name), 'success');
                 response()->refresh();
             }
         }
     }
 }
Exemplo n.º 2
0
 public function __construct()
 {
     parent::__construct();
     $this->startDate = $this->input('start_date', date('01-m-Y', strtotime('-1 month')));
     $this->endDate = $this->input('end_date', date('t-m-Y', strtotime('-1 month')));
     $this->currency = ModelSettings::getInstance()->getCurrency();
     $this->organisations = ModelOrganisation::get();
 }
Exemplo n.º 3
0
 public function __construct()
 {
     parent::__construct();
     $this->contentProviders = ModelContentProvider::all();
     if ($this->input('organisation')) {
         $this->organisations = ModelOrganisation::getByQuery($this->input('organisation'), 20, 0);
     }
 }
Exemplo n.º 4
0
 public function __construct($organisationId)
 {
     parent::__construct();
     $this->organisation = ModelOrganisation::getById($organisationId);
     if (!$this->organisation->hasRow()) {
         redirect(url('admin.home'));
     }
     $this->organisationsMenu = new Menu();
     $this->organisationsMenu->addItem(lang('Overview'), url('admin.organisation.home', ['organisationId' => $this->organisation->id]));
     $this->organisationsMenu->addItem(lang('Activity'), url('admin.organisation.activity', ['organisationId' => $this->organisation->id]));
     $this->organisationsMenu->addItem(lang('Invoices'), url('admin.organisation.invoices', ['organisationId' => $this->organisation->id]));
 }
Exemplo n.º 5
0
function shutdownAccount(\NinjaImg\Model\ModelOrganisation $organisation, $amount)
{
    $lastMonthDate = date('Y-m-01', strtotime('-1 month'));
    $currency = \NinjaImg\Model\ModelSettings::getInstance()->getCurrency();
    $lastPaymentDate = \NinjaImg\Model\ModelPayment::getLastPaymentDate($organisation->id, $lastMonthDate);
    if (!$lastPaymentDate) {
        $lastPaymentDate = \Pecee\Date::toDateTime();
        savePayment($organisation->id, $amount, $lastMonthDate);
    }
    $lastTryDaysAgo = daysAgo($lastPaymentDate, \Pecee\Date::toDateTime());
    if ($lastTryDaysAgo > MAX_PAYMENT_ATTEMPTS_DAYS) {
        echo sprintf('disabled due to no payment in %s days', MAX_PAYMENT_ATTEMPTS_DAYS);
        mailAdmins('[WARNING] ' . $organisation->name . ' shut down warning', sprintf("Hi bitches!\n\nThe organisation {$organisation->name} has been shut down due to invalid and/or no payment in over %s days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // TODO: Send notification to user about shutting down
        $organisation->disabled = true;
        $organisation->update();
    } else {
        $shutdownDays = MAX_PAYMENT_ATTEMPTS_DAYS - $lastTryDaysAgo;
        echo sprintf('%s days before shutting down account', $shutdownDays);
        mailAdmins('[INFO] ' . $organisation->name . ' payment not received', sprintf("Hi bitches!\n\nFailed to charge {$organisation->name} and will be automatically disabled in {$shutdownDays} days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // Register try
    }
}
Exemplo n.º 6
0
 public function handle(Request $request)
 {
     $this->request = $request;
     // Extending this class requires the user to be authenticated
     if (!ModelUser::isLoggedIn()) {
         $this->setMessage('This page can only be viewed when logged in', 'warning', 'main');
         redirect(url('home'), 301);
     }
     $this->request->user = ModelUser::current();
     $this->validateOrganisation();
     if ($this->request->user->getActiveOrganisation()) {
         $this->request->organisation = ModelOrganisation::getById($this->request->user->getActiveOrganisation());
     }
 }
Exemplo n.º 7
0
 public function __construct($organisationId)
 {
     parent::__construct();
     $this->organisation = ModelOrganisation::getById($organisationId);
     if (!$this->organisation->hasRow()) {
         $this->setError(lang('Organisation not found'));
         redirect(url('admin.payment'));
     }
     $this->startDate = $this->input('start_date', date('Y-m-01', strtotime('-1 month')));
     $this->endDate = $this->input('end_date', date('Y-m-t', strtotime('-1 month')));
     $this->settings = ModelSettings::getInstance();
     $this->payments = ModelPayment::getByOrganisationPeriod($this->organisation->id, $this->startDate, $this->endDate);
     $this->chargeCustomer();
     $this->markPayed();
 }
Exemplo n.º 8
0
 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Register'));
     $this->currency = ModelSettings::getInstance();
     $role = UserRole::TYPE_OWNER;
     if ($this->get->email->getValue()) {
         $this->invite = OrganisationInvite::getByEmail($this->get->email->getValue());
         if ($this->invite->hasRow()) {
             $this->organisation = ModelOrganisation::getById($this->invite->organisation_id);
             $role = $this->invite->role;
         }
     }
     if ($this->isPostBack()) {
         $this->post->name->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->email->addValidation(new ValidateInputEmail());
         if ($this->organisation === null || !$this->organisation->hasRow()) {
             $this->post->company->addValidation(new ValidateInputNotNullOrEmpty());
         }
         $this->post->password->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->terms->addValidation(new ValidateInputNotNullOrEmpty());
         $this->post->password_repeat->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             // Do not create organisation if invite is available
             if ($this->organisation === null || !$this->organisation->hasRow()) {
                 // Check if organisation name is taken
                 if (ModelOrganisation::getByName($this->input('company'))->hasRow()) {
                     $this->setError(lang('An organisation with the name %s already exists - please request an invite from the organisation owner instead.', $this->input('company')));
                     response()->refresh();
                 }
                 $organisation = new ModelOrganisation();
                 $organisation->setName($this->input('company'));
                 $organisation->save();
                 $role = UserRole::TYPE_OWNER;
             } else {
                 $organisation = $this->organisation;
             }
             $user = new ModelUser();
             $user->username = $this->post->email->getValue();
             $user->data->name = $this->input('name');
             $user->setPassword($this->input('password'));
             try {
                 $user->save();
                 $this->sendWelcomeMail($user);
             } catch (UserException $e) {
                 if ($e->getCode() === ModelUser::ERROR_TYPE_EXISTS) {
                     $error = lang('The e-mail is already registered.');
                 } else {
                     $error = $e->getMessage();
                 }
                 $this->setError($error);
                 response()->refresh();
             }
             $user->addOrganisation($organisation, $role);
             $user->auth();
             // Delete invite
             if ($this->invite && $this->invite->hasRow()) {
                 $this->invitationAcceptedMail($this->invite, $organisation, $user);
                 $this->invite->delete();
             }
             redirect(url('controlpanel.organisations'));
         }
     }
 }
Exemplo n.º 9
0
 public function getOrganisation()
 {
     return ModelOrganisation::getById($this->organisation_id);
 }
Exemplo n.º 10
0
 public function getOrganisations()
 {
     return ModelOrganisation::getByUserId($this->id);
 }