diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 16f7b0545c42..51be35c41fbe 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -215,7 +215,7 @@ class AccountController extends \BaseController { } $client->save(); - $client->contacts()->save($contact); + $client->contacts()->save($contact); } $message = pluralize('Successfully created ? client', $count); diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index 2419872d8719..29020e45896e 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -25,7 +25,7 @@ class ClientController extends \BaseController { }) ->addColumn('contact', function($model) { - return $model->contacts[0]->fullName(); + return $model->contacts[0]->getFullName(); }) ->addColumn('last_login', function($model) { diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 936960268ba9..eb9ca4d5e1af 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -40,6 +40,10 @@ class InvoiceController extends \BaseController { public function view($invoiceKey) { $invoice = Invoice::with('invoice_items', 'client.account.account_gateways')->where('invoice_key', '=', $invoiceKey)->firstOrFail(); + $contact = null; + + Activity::viewInvoice($invoice, $contact) + return View::make('invoices.view')->with('invoice', $invoice); } @@ -98,6 +102,7 @@ class InvoiceController extends \BaseController { $payment = new Payment; $payment->invoice_id = $invoice->id; $payment->account_id = $invoice->account_id; + $payment->contact_id = 0; $payment->transaction_reference = $response->getTransactionReference(); $payment->save(); @@ -272,6 +277,8 @@ class InvoiceController extends \BaseController { $message->to($contact->email); }); + Activity::emailInvoice($invoice, $contact); + Session::flash('message', 'Successfully emailed invoice'); } else { Session::flash('message', 'Successfully saved invoice'); 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 fe9f678e2a96..33b32aefe8f5 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 @@ -10,6 +10,7 @@ class ConfideSetupUsersTable extends Migration { */ public function up() { + Schema::dropIfExists('activities'); Schema::dropIfExists('account_gateways'); Schema::dropIfExists('gateways'); Schema::dropIfExists('products'); @@ -176,13 +177,13 @@ class ConfideSetupUsersTable extends Migration { //$t->foreign('account_id')->references('id')->on('accounts'); }); - - Schema::create('payments', function($t) { $t->increments('id'); $t->integer('invoice_id'); $t->integer('account_id'); + $t->integer('contact_id'); + $t->integer('user_id'); $t->timestamps(); $t->softDeletes(); @@ -193,6 +194,20 @@ class ConfideSetupUsersTable extends Migration { //$t->foreign('account_id')->references('id')->on('accounts'); }); + Schema::create('activities', function($t) + { + $t->increments('id'); + $t->integer('account_id'); + $t->integer('user_id'); + $t->integer('client_id'); + $t->integer('contact_id'); + $t->integer('invoice_id'); + $t->integer('payment_id'); + $t->timestamps(); + + $t->integer('activity_type_id'); + $t->text('message'); + }); } /** @@ -202,6 +217,7 @@ class ConfideSetupUsersTable extends Migration { */ public function down() { + Schema::dropIfExists('activities'); Schema::dropIfExists('account_gateways'); Schema::dropIfExists('gateways'); Schema::dropIfExists('products'); diff --git a/app/database/seeds/ConstantsSeeder.php b/app/database/seeds/ConstantsSeeder.php index 1c835105f394..d5b5757c4b87 100755 --- a/app/database/seeds/ConstantsSeeder.php +++ b/app/database/seeds/ConstantsSeeder.php @@ -6,10 +6,16 @@ class ConstantsSeeder extends Seeder public function run() { DB::table('gateways')->delete(); - + Gateway::create(array( 'name' => 'PayPal Express', 'provider' => 'PayPal_Express' )); + + /* + ActivityType::create(array( + 'name' => 'Created invoice' + )); + */ } } \ No newline at end of file diff --git a/app/database/seeds/UserTableSeeder.php b/app/database/seeds/UserTableSeeder.php index f3d01f819f68..3da62963161b 100755 --- a/app/database/seeds/UserTableSeeder.php +++ b/app/database/seeds/UserTableSeeder.php @@ -5,15 +5,21 @@ class UserTableSeeder extends Seeder public function run() { - DB::table('users')->delete(); + //DB::table('users')->delete(); + /* - User::create(array( - 'first_name' => 'Hillel', + $account = Account::create(array( + 'name' => 'Acme Inc', + )); + + $user = User::create(array( + 'account_id' => $account->id, + 'first_name' => 'Hillel', 'last_name' => 'Coren', - 'email' => 'hillelcoren@gmail.com', + 'email' => 'hillelcoren@gmail.com', 'password' => Hash::make('1234'), )); - */ + */ } } \ No newline at end of file diff --git a/app/models/Activity.php b/app/models/Activity.php index 85b9f665de78..bd87d9de78de 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -1,13 +1,16 @@ activity_type_id = ACTIVITY_TYPE_CREATE_CLIENT; $activity->message = $user->getFullName() . ' created client ' . $client->name; $activity->save(); - } + } public static function archiveClient($client) { @@ -66,20 +69,19 @@ define("ACTIVITY_TYPE_CONTACT_LOGIN", 12); $activity->save(); } - public static function createPayment($payment, $contact) + public static function createPayment($payment) { - if ($contact) - { - $activity = new Activity; - $activity->contact_id = $contact->id; - $activity->message = $contact->getFullName() . ' created payment ' . $payment->transaction_reference; - } - else + if (Auth::check()) { $activity = Activity::getBlank(); $activity->message = $user->getFullName() . ' created invoice ' . $payment->transaction_reference; } - + else + { + $activity = new Activity; + $activity->contact_id = $payment->contact_id; + $activity->message = $contact->getFullName() . ' created payment ' . $payment->transaction_reference; + } $activity->payment_id = $payment->id; $activity->invoice_id = $payment->invoice_id; @@ -101,11 +103,11 @@ define("ACTIVITY_TYPE_CONTACT_LOGIN", 12); public static function viewInvoice($invoice, $contact) { $activity = new Activity; - $activity->contact_id = $contact->id; + //$activity->contact_id = $contact->id; $activity->invoice_id = $invoice->id; $activity->client_id = $invoice->client_id; $activity->activity_type_id = ACTIVITY_TYPE_VIEW_INVOICE; $activity->message = $contact->getFullName() . ' viewed invoice ' . $invoice->number; $activity->save(); - } + } } \ No newline at end of file diff --git a/app/models/Client.php b/app/models/Client.php index ef7f5ee994d6..3e410df89f86 100755 --- a/app/models/Client.php +++ b/app/models/Client.php @@ -27,4 +27,9 @@ class Client extends Eloquent { return $this->hasMany('Contact'); } -} \ No newline at end of file +} + +Client::created(function($client) +{ + Activity::createClient($client); +}); \ No newline at end of file diff --git a/app/models/Contact.php b/app/models/Contact.php index f4238645ad4e..a3424d23a53b 100755 --- a/app/models/Contact.php +++ b/app/models/Contact.php @@ -14,11 +14,6 @@ class Contact extends Eloquent return $this->belongsTo('Client'); } - public function fullName() - { - return $this->first_name . ' ' . $this->last_name; - } - public function lastLogin() { if ($this->last_login == '0000-00-00 00:00:00') @@ -30,4 +25,18 @@ class Contact extends Eloquent return $this->last_login; } } + + public function getFullName() + { + $fullName = $this->first_name . ' ' . $this->last_name; + + if ($fullName == ' ') + { + return "Unknown"; + } + else + { + return $fullName; + } + } } \ No newline at end of file diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 1f93e5896170..f7e302772123 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -25,4 +25,9 @@ class Invoice extends Eloquent return $total; } -} \ No newline at end of file +} + +Invoice::created(function($invoice) +{ + Activity::createInvoice($invoice); +}); \ No newline at end of file diff --git a/app/models/Payment.php b/app/models/Payment.php index 2992fd3067ef..225bae31eedc 100755 --- a/app/models/Payment.php +++ b/app/models/Payment.php @@ -8,4 +8,9 @@ class Payment extends Eloquent { return $this->belongsTo('Invoice'); } -} \ No newline at end of file +} + +Payment::created(function($payment) +{ + Activity::createPayment($payment); +}); \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index 78d729fc750b..48b3d2eafc73 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -68,4 +68,17 @@ class User extends ConfideUser implements UserInterface, RemindableInterface { return $this->email; } + public function getFullName() + { + $fullName = $this->first_name . ' ' . $this->last_name; + + if ($fullName == ' ') + { + return "Unknown"; + } + else + { + return $fullName; + } + } } \ No newline at end of file diff --git a/app/views/header.blade.php b/app/views/header.blade.php index 38c2788c0e55..e9fc11fac162 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -261,11 +261,11 @@