diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 2725fb81cff0..dd436cc1687a 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -434,6 +434,8 @@ class AccountController extends \BaseController { { $config->$field = trim(Input::get($gateway->id.'_'.$field)); } + //dd(Input::all()); + //dd($config); $accountGateway->config = json_encode($config); $account->account_gateways()->save($accountGateway); diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 75bed4ee107d..387098978965 100755 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -16,21 +16,6 @@ class HomeController extends BaseController { public function logError() { - $count = Session::get('error_count', 0); - Session::put('error_count', ++$count); - if ($count > LOGGED_ERROR_LIMIT) return 'logged'; - - $data = [ - 'context' => 'JavaScript', - 'user_id' => Auth::check() ? Auth::user()->id : 0, - 'url' => Input::get('url'), - 'user_agent' => $_SERVER['HTTP_USER_AGENT'], - 'ip' => Request::getClientIp(), - 'count' => $count - ]; - - Log::error(Input::get('error'), $data); - - return 'logged'; + return Utils::logError(Input::get('error'), 'JavaScript'); } } \ No newline at end of file diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index bc40a8c8724d..ce74031238d4 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -132,6 +132,7 @@ class InvoiceController extends \BaseController { } Activity::viewInvoice($invitation); + Event::fire('invoice.viewed', $invoice); $client->account->loadLocalizationSettings(); @@ -200,20 +201,21 @@ class InvoiceController extends \BaseController { if (!$ref) { - Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
'); + return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
', $response->getMessage()); } $payment = Payment::createNew(); $payment->invitation_id = $invitation->id; + $payment->account_gateway_id = $accountGateway->id; $payment->invoice_id = $invoice->id; $payment->amount = $invoice->amount; $payment->client_id = $invoice->client_id; + $payment->currency_id = $invoice->currency_id ? $invoice->currency_id : 0; $payment->contact_id = $invitation->contact_id; $payment->transaction_reference = $ref; + $payment->payment_date = date_create(); $payment->save(); - $invoice->balance = floatval($invoice->amount) - floatval($paymount->amount); - if ($response->isSuccessful()) { @@ -229,7 +231,7 @@ class InvoiceController extends \BaseController { } catch (\Exception $e) { - return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
'.$e); + return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
', $e); } } @@ -263,19 +265,22 @@ class InvoiceController extends \BaseController { { $invoice->invoice_status_id = INVOICE_STATUS_PARTIAL; } - $invoice->save(); + $invoice->save(); + + Event::fire('invoice.paid', $invoice); + Session::flash('message', 'Successfully applied payment'); return Redirect::to('view/' . $payment->invitation->invitation_key); } else { - return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
'.$response->getMessage()); + return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
', $response->getMessage()); } } catch (\Exception $e) { - return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
'.$e); + return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.
', $e); } } diff --git a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php index 9638598df53a..4d949015cdab 100755 --- a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php +++ b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php @@ -432,6 +432,7 @@ class ConfideSetupUsersTable extends Migration { $t->unsignedInteger('contact_id')->nullable(); $t->unsignedInteger('invitation_id')->nullable(); $t->unsignedInteger('user_id')->nullable(); + $t->unsignedInteger('account_gateway_id')->nullable(); $t->unsignedInteger('currency_id')->default(1); $t->timestamps(); $t->softDeletes(); @@ -446,6 +447,7 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('contact_id')->references('id')->on('contacts'); + $t->foreign('account_gateway_id')->references('id')->on('account_gateways'); $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->foreign('currency_id')->references('id')->on('currencies'); diff --git a/app/libraries/utils.php b/app/libraries/utils.php index b13f22a72061..832e3671e100 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -2,16 +2,41 @@ class Utils { - public static function fatalError($error = false) + public static function fatalError($message = false, $exception = false) { - if (!$error) + if (!$message) { - $error = "An error occurred, please try again later"; + $message = "An error occurred, please try again later"; } - Log::error($error); + static::logError($message . ' ' . $exception); - return View::make('error')->with('error', $error); + return View::make('error')->with('error', $message); + } + + public static function logError($error, $context = 'PHP') + { + $count = Session::get('error_count', 0); + Session::put('error_count', ++$count); + if ($count > LOGGED_ERROR_LIMIT) return 'logged'; + + $data = [ + 'context' => $context, + 'user_id' => Auth::check() ? Auth::user()->id : 0, + 'url' => Input::get('url'), + 'user_agent' => $_SERVER['HTTP_USER_AGENT'], + 'ip' => Request::getClientIp(), + 'count' => Session::get('error_count', 0) + ]; + + Log::error($error, $data); + + /* + Mail::queue('emails.error', ['message'=>$error.' '.json_encode($data)], function($message) + { + $message->to($email)->subject($subject); + }); + */ } public static function formatPhoneNumber($phoneNumber) @@ -285,9 +310,9 @@ class Utils public static function encodeActivity($person = null, $action, $entity = null, $otherPerson = null) { - $person = $person ? $person->getFullName() : 'System'; + $person = $person ? $person->getDisplayName() : 'System'; $entity = $entity ? '[' . $entity->getKey() . ']' : ''; - $otherPerson = $otherPerson ? 'to ' . $otherPerson->getFullName() : ''; + $otherPerson = $otherPerson ? 'to ' . $otherPerson->getDisplayName() : ''; return trim("$person $action $entity $otherPerson"); } diff --git a/app/models/Account.php b/app/models/Account.php index 51d08eb4f73b..80ed5e6f5756 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -61,6 +61,8 @@ class Account extends Eloquent public function isGatewayConfigured($gatewayId = 0) { + $this->load('account_gateways'); + if ($gatewayId) { return $this->getGatewayConfig($gatewayId) != false; @@ -103,13 +105,19 @@ class Account extends Eloquent public function getNextInvoiceNumber() { - $order = Invoice::withTrashed()->scope(false, $this->id)->orderBy('created_at', 'DESC')->first(); + $orders = Invoice::withTrashed()->scope(false, $this->id)->get(); - if ($order) + $max = 0; + + foreach ($orders as $order) { - $number = preg_replace("/[^0-9]/", "", $order->invoice_number); - $number = intval($number) + 1; - return str_pad($number, 4, "0", STR_PAD_LEFT); + $number = intval(preg_replace("/[^0-9]/", "", $order->invoice_number)); + $max = max($max, $number); + } + + if ($max > 0) + { + return str_pad($max+1, 4, "0", STR_PAD_LEFT); } else { diff --git a/app/models/Activity.php b/app/models/Activity.php index f7688cce5a56..fc5407a7b0c2 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -152,7 +152,7 @@ class Activity extends Eloquent $activity->invoice_id = $invitation->invoice_id; $activity->contact_id = $invitation->contact_id; $activity->activity_type_id = ACTIVITY_TYPE_EMAIL_INVOICE; - $activity->message = Utils::encodeActivity(Auth::check() ? Auth::user() : null, 'emailed', $invoice, $invitation->contact); + $activity->message = Utils::encodeActivity(Auth::check() ? Auth::user() : null, 'emailed', $invitation->invoice, $invitation->contact); $activity->balance = $client->balance; $activity->adjustment = $adjustment; $activity->save(); @@ -226,7 +226,7 @@ class Activity extends Eloquent { $activity = new Activity; $activity->contact_id = $payment->contact_id; - //$activity->message = $contact->getFullName() . ' created payment ' . $payment->transaction_reference; + $activity->message = Utils::encodeActivity($payment->invitation->contact, 'created payment'); } $activity->payment_id = $payment->id; diff --git a/app/models/User.php b/app/models/User.php index a8d32599e43e..f5c71a7a9ae6 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -69,6 +69,19 @@ class User extends ConfideUser implements UserInterface, RemindableInterface return $this->email; } + public function getDisplayName() + { + if (!$this->first_name && !$this->last_name) + { + return $this->email; + } + else + { + return $this->getFullName(); + } + + } + public function getFullName() { $fullName = $this->first_name . ' ' . $this->last_name; diff --git a/app/ninja/mailers/Mailer.php b/app/ninja/mailers/Mailer.php index 69976a78a314..42a202c2340b 100755 --- a/app/ninja/mailers/Mailer.php +++ b/app/ninja/mailers/Mailer.php @@ -10,7 +10,6 @@ abstract class Mailer { 'emails.'.$view.'_html', 'emails.'.$view.'_text' ]; - \Log::info('data: ' . json_encode($data)); Mail::queue($views, $data, function($message) use ($toEmail, $fromEmail, $subject) { diff --git a/app/start/global.php b/app/start/global.php index 53662a0e06b8..046970c8f303 100755 --- a/app/start/global.php +++ b/app/start/global.php @@ -58,16 +58,9 @@ $monolog->pushHandler(new Monolog\Handler\SyslogHandler('intranet', 'user', Logg App::error(function(Exception $exception, $code) { - $data = [ - 'context' => 'PHP', - 'user_id' => Auth::check() ? Auth::user()->id : 0, - 'code' => $code, - 'url' => Request::url(), - 'user_agent' => $_SERVER['HTTP_USER_AGENT'], - 'ip' => Request::getClientIp() - ]; + //Log::error($exception); - Log::error($exception, $data); + Utils::logError($exception . ' ' . $code); }); /* diff --git a/app/views/accounts/settings.blade.php b/app/views/accounts/settings.blade.php index 9f4233b3c544..eaaa7dafbb8c 100755 --- a/app/views/accounts/settings.blade.php +++ b/app/views/accounts/settings.blade.php @@ -14,7 +14,13 @@ @if ($accountGateway) {{ Former::populateField('gateway_id', $accountGateway->gateway_id) }} @foreach ($accountGateway->fields as $field => $junk) - {{ Former::populateField($accountGateway->gateway_id.'_'.$field, $config->$field) }} + @if ($field == 'testMode' || $field == 'developerMode') + @if ($config->$field) + {{ Former::populateField($accountGateway->gateway_id.'_'.$field, true ) }} + @endif + @else + {{ Former::populateField($accountGateway->gateway_id.'_'.$field, $config->$field) }} + @endif @endforeach @endif diff --git a/app/views/clients/edit.blade.php b/app/views/clients/edit.blade.php index 8fe5365bb636..f72549f8146e 100755 --- a/app/views/clients/edit.blade.php +++ b/app/views/clients/edit.blade.php @@ -87,19 +87,37 @@ $('#country_id').combobox(); }); - function ContactModel() { + function ContactModel(data) { var self = this; self.public_id = ko.observable(''); self.first_name = ko.observable(''); self.last_name = ko.observable(''); self.email = ko.observable(''); self.phone = ko.observable(''); + + if (data) { + ko.mapping.fromJS(data, {}, this); + } } - function ContactsModel() { + function ContactsModel(data) { var self = this; self.contacts = ko.observableArray(); + self.mapping = { + 'contacts': { + create: function(options) { + return new ContactModel(options.data); + } + } + } + + if (data) { + ko.mapping.fromJS(data, self.mapping, this); + } else { + self.contacts.push(new ContactModel()); + } + self.placeholderName = ko.computed(function() { if (self.contacts().length == 0) return ''; var contact = self.contacts()[0]; @@ -111,12 +129,7 @@ }); } - @if ($client) - window.model = ko.mapping.fromJS({{ $client }}); - @else - window.model = new ContactsModel(); - addContact(); - @endif + window.model = new ContactsModel({{ $client }}); model.showContact = function(elem) { if (elem.nodeType === 1) $(elem).hide().slideDown() } model.hideContact = function(elem) { if (elem.nodeType === 1) $(elem).slideUp(function() { $(elem).remove(); }) } diff --git a/app/views/emails/error.blade.php b/app/views/emails/error.blade.php new file mode 100755 index 000000000000..e69de29bb2d1 diff --git a/app/views/header.blade.php b/app/views/header.blade.php index a470def00bbd..e93b31dad10b 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -173,8 +173,7 @@ @endif - Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice-ninja', 'open source', array('target'=>'_blank')) }}, email us at {{ link_to('mailto:contact@invoiceninja.com', 'contact@invoiceninja.com') }}. -
This is a demo site, the data is erased.
+ Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice-ninja', 'open source', array('target'=>'_blank')) }}, email us at {{ link_to('mailto:contact@invoiceninja.com', 'contact@invoiceninja.com') }}. diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index bd614b8b52ad..12ee304bcb91 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -43,7 +43,7 @@ @endif