protected function updateData() { foreach ($this->data as $key => $value) { $item = new ModelSettings(); $item->key = $key; $item->value = $value; $item->save(); } }
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(); }
public function __construct() { parent::__construct(); $this->settings = ModelSettings::getInstance(); $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->payments = ModelPayment::getByPeriod($this->startDate, $this->endDate); }
function calculatePrices(\NinjaImg\Model\ModelOrganisation $organisation) { $firstDayPreviousMonth = date('01-m-y', strtotime('-1 month')); $lastDayPreviousMonth = date('t-m-y', strtotime('-1 month')); $masterImages = \NinjaImg\Model\ModelActivity::getMasterImagesByDate($organisation->id, $firstDayPreviousMonth, $lastDayPreviousMonth); $bandwidth = \NinjaImg\Model\ModelActivity::getBandwidthByDate($organisation->id, $firstDayPreviousMonth, $lastDayPreviousMonth); $masterImages = $masterImages ? (int) $masterImages : 0; $bandwidth = $bandwidth ? (int) $bandwidth : 0; $masterImagesPrice = (double) \NinjaImg\Model\ModelSettings::getInstance()->getPriceMasterImage() * $masterImages; $bandwidthPrice = (double) \NinjaImg\Model\ModelSettings::getInstance()->getPriceBandwidthGB() / 1024 * $bandwidth; return number_format($masterImagesPrice + $bandwidthPrice, 2); }
public function __construct() { parent::__construct(); $this->settings = ModelSettings::getInstance(); if ($this->isPostBack()) { /* @var $input \Pecee\Http\Input\InputItem */ foreach ($this->input('data') as $input) { $this->settings->data->{$input->getIndex()} = $input->getValue(); } $this->settings->update(); $this->setMessage(lang('Settings saved'), 'success'); response()->refresh(); } }
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(); }
protected function sendCustomerMail(OrganisationInvoice $invoice) { $users = ModelUser::getByOrganisationId($this->organisation->id, UserRole::TYPE_OWNER); if ($users->hasRows()) { foreach ($users as $user) { $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('New invoice available for ' . $this->organisation->name)); $currency = ModelSettings::getInstance()->data->default_currency_character; $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody("Dear {$user->data->name}!\n\nAttached is the latest invoice from NinjaImg.\n\nThe amount for invoice {$invoice->invoice_id} is {$invoice->amount_total}{$currency} with payment date {$invoice->due_date}.\n\nYou can always view your invoices at your controlpanel on ninjaimg.com.\n\nThanks for supporting our service, we really appreciate it!\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain'); $message->setTo($user->username); $attachment = new \Swift_Attachment(file_get_contents($invoice->path), basename($invoice->path), File::getMime($invoice->path)); $message->attach($attachment); $swift->send($message); } } }
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')); } } }
/** * Get total based on usage and fixed plan but with discounts. * @return float * * @param bool $includeVat */ public function getTotalWithDiscounts($includeVat = false) { $total = $this->getTotal(); // Calculate discount if ($this->organisation->free_amount) { $total -= (double) $this->organisation->free_amount; } if ($this->organisation->discount_percentage && $this->organisation->discount_percentage > 0 && $this->organisation->discount_percentage <= 100) { $discountAmount = $total * ((double) $this->organisation->discount_percentage / 100); if ($discountAmount > 0) { $total -= $discountAmount; } } if ($total > 0) { if ($includeVat) { $vatPercentage = ModelSettings::getInstance()->getVatPercentage() / 100; $vatAmount = $total * $vatPercentage; $total += $vatAmount; } return sprintf('%2.2f', $total); } return 0; }
<table> <thead> <tr> <th> <?php echo lang('Invoice ID'); ?> </th> <th> <?php echo lang('Due date'); ?> </th> <th> <?php echo lang('Amount %s', \NinjaImg\Model\ModelSettings::getInstance()->data->default_currency_character); ?> </th> </tr> </thead> <tbody> <?php /* @var $invoice \NinjaImg\Model\Organisation\OrganisationInvoice */ foreach ($this->invoices as $invoice) { ?> <tr> <td> <a href="<?php echo $invoice->path; ?> " target="_blank"><?php
<?php echo $this->form()->input('invoice_id', 'text', $this->getValue('invoice_id'), true)->addAttribute('placeholder', lang('Invoice ID')); ?> <br/> <?php echo $this->form()->input('due_date', 'text', $this->getValue('due_date'), true)->addAttribute('placeholder', lang('Due date')); ?> <br/> <?php echo $this->form()->input('amount', 'text', $this->getValue('amount_total'), true)->addAttribute('placeholder', lang('Amount')); ?> <?php echo \NinjaImg\Model\ModelSettings::getInstance()->data->default_currency_character; ?> <br/> <?php echo $this->form()->bool('payed', true)->addAttribute('id', 'payed'); ?> <label for="payed"><?php echo lang('Payed'); ?> </label><br/> <?php echo $this->form()->submit('save', lang('Upload'))->addAttribute('onclick', 'return confirm(\'' . lang('Please double check that this invoice is ready to be sent to the customer and press OK.') . '\')'); ?>