2013-11-26 22:26:08 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-01 21:58:25 +01:00
|
|
|
|
2013-11-26 22:45:10 +01:00
|
|
|
define("ACTIVITY_TYPE_CREATE_CLIENT", 1);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_CLIENT", 2);
|
2013-12-01 21:58:25 +01:00
|
|
|
define("ACTIVITY_TYPE_DELETE_CLIENT", 3);
|
|
|
|
define("ACTIVITY_TYPE_CREATE_INVOICE", 4);
|
|
|
|
define("ACTIVITY_TYPE_EMAIL_INVOICE", 5);
|
|
|
|
define("ACTIVITY_TYPE_VIEW_INVOICE", 6);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_INVOICE", 7);
|
|
|
|
define("ACTIVITY_TYPE_DELETE_INVOICE", 8);
|
|
|
|
define("ACTIVITY_TYPE_CREATE_PAYMENT", 9);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_PAYMENT", 10);
|
|
|
|
define("ACTIVITY_TYPE_DELETE_PAYMENT", 11);
|
|
|
|
define("ACTIVITY_TYPE_CREATE_CREDIT", 12);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_CREDIT", 13);
|
|
|
|
define("ACTIVITY_TYPE_DELETE_CREDIT", 14);
|
2013-12-10 23:10:43 +01:00
|
|
|
|
2013-11-26 22:45:10 +01:00
|
|
|
|
2013-11-26 22:26:08 +01:00
|
|
|
class Activity extends Eloquent
|
|
|
|
{
|
2013-12-04 17:20:14 +01:00
|
|
|
protected $hidden = array('id');
|
|
|
|
|
2013-12-03 18:32:33 +01:00
|
|
|
public function scopeScope($query)
|
|
|
|
{
|
|
|
|
return $query->whereAccountId(Auth::user()->account_id);
|
|
|
|
}
|
|
|
|
|
2013-12-29 18:40:11 +01:00
|
|
|
public function account()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Account');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-10 18:18:35 +01:00
|
|
|
private static function getBlank($entity = false)
|
2013-11-26 22:26:08 +01:00
|
|
|
{
|
|
|
|
$activity = new Activity;
|
2013-12-10 18:18:35 +01:00
|
|
|
|
|
|
|
if (Auth::check()) {
|
|
|
|
$activity->user_id = Auth::user()->id;
|
|
|
|
$activity->account_id = Auth::user()->account_id;
|
|
|
|
} else if ($entity) {
|
|
|
|
$activity->user_id = $entity->user_id;
|
|
|
|
$activity->account_id = $entity->account_id;
|
|
|
|
} else {
|
|
|
|
exit; // TODO_FIX log error
|
|
|
|
}
|
2013-11-26 22:26:08 +01:00
|
|
|
|
2013-11-27 08:38:37 +01:00
|
|
|
return $activity;
|
2013-11-26 22:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function createClient($client)
|
2013-12-01 08:33:17 +01:00
|
|
|
{
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity = Activity::getBlank();
|
|
|
|
$activity->client_id = $client->id;
|
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_CREATE_CLIENT;
|
2013-12-07 19:45:00 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' created client ' . link_to('clients/'.$client->public_id, $client->name);
|
2013-12-01 21:58:25 +01:00
|
|
|
|
2013-12-01 08:33:17 +01:00
|
|
|
$activity->save();
|
2013-11-26 22:45:10 +01:00
|
|
|
}
|
2013-11-26 22:26:08 +01:00
|
|
|
|
|
|
|
public static function archiveClient($client)
|
|
|
|
{
|
|
|
|
$activity = Activity::getBlank();
|
|
|
|
$activity->client_id = $client->id;
|
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_ARCHIVE_CLIENT;
|
2013-11-27 08:38:37 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' archived client ' . $client->name;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function createInvoice($invoice)
|
|
|
|
{
|
2013-12-10 18:18:35 +01:00
|
|
|
$userName = Auth::check() ? Auth::user()->getFullName() : '<i>System</i>';
|
2013-12-11 12:11:59 +01:00
|
|
|
|
2013-12-13 10:13:57 +01:00
|
|
|
if ($invoice->is_recurring) {
|
2013-12-11 12:11:59 +01:00
|
|
|
$message = $userName . ' created ' . link_to('invoices/'.$invoice->public_id, 'recuring invoice');
|
|
|
|
} else {
|
|
|
|
$message = $userName . ' created invoice ' . link_to('invoices/'.$invoice->public_id, $invoice->invoice_number);
|
|
|
|
}
|
|
|
|
|
2013-12-10 18:18:35 +01:00
|
|
|
$activity = Activity::getBlank($invoice);
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->invoice_id = $invoice->id;
|
|
|
|
$activity->client_id = $invoice->client_id;
|
2013-12-29 18:40:11 +01:00
|
|
|
$activity->currency_id = $invoice->currency_id;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_CREATE_INVOICE;
|
2013-12-11 12:11:59 +01:00
|
|
|
$activity->message = $message;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function archiveInvoice($invoice)
|
|
|
|
{
|
|
|
|
$activity = Activity::getBlank();
|
|
|
|
$activity->invoice_id = $invoice->id;
|
|
|
|
$activity->client_id = $invoice->client_id;
|
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_ARCHIVE_INVOICE;
|
2013-12-01 21:58:25 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' archived invoice ' . $invoice->invoice_number;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:40:13 +01:00
|
|
|
public static function emailInvoice($invitation)
|
2013-11-26 22:26:08 +01:00
|
|
|
{
|
2013-12-10 18:18:35 +01:00
|
|
|
$userName = Auth::check() ? Auth::user()->getFullName() : '<i>System</i>';
|
|
|
|
$activity = Activity::getBlank($invitation);
|
2013-12-02 13:22:29 +01:00
|
|
|
$activity->client_id = $invitation->invoice->client_id;
|
2013-11-28 17:40:13 +01:00
|
|
|
$activity->invoice_id = $invitation->invoice_id;
|
|
|
|
$activity->contact_id = $invitation->contact_id;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_EMAIL_INVOICE;
|
2013-12-10 18:18:35 +01:00
|
|
|
$activity->message = $userName . ' emailed invoice ' . link_to('invoices/'.$invitation->invoice->public_id, $invitation->invoice->invoice_number) . ' to ' . $invitation->contact->getFullName();
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
|
|
|
}
|
2013-12-11 12:11:59 +01:00
|
|
|
|
2013-11-26 22:45:10 +01:00
|
|
|
public static function createPayment($payment)
|
2013-11-26 22:26:08 +01:00
|
|
|
{
|
2013-11-26 22:45:10 +01:00
|
|
|
if (Auth::check())
|
2013-11-26 22:26:08 +01:00
|
|
|
{
|
2013-11-26 22:45:10 +01:00
|
|
|
$activity = Activity::getBlank();
|
2013-12-01 21:58:25 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' created payment ' . $payment->transaction_reference;
|
2013-11-26 22:26:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-26 22:45:10 +01:00
|
|
|
$activity = new Activity;
|
|
|
|
$activity->contact_id = $payment->contact_id;
|
2013-11-28 13:15:34 +01:00
|
|
|
//$activity->message = $contact->getFullName() . ' created payment ' . $payment->transaction_reference;
|
2013-11-26 22:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$activity->payment_id = $payment->id;
|
2013-12-05 16:23:24 +01:00
|
|
|
if ($payment->invoice_id) {
|
|
|
|
$activity->invoice_id = $payment->invoice_id;
|
|
|
|
}
|
|
|
|
$activity->client_id = $payment->client_id;
|
2013-12-29 18:40:11 +01:00
|
|
|
$activity->currency_id = $payment->currency_id;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_CREATE_PAYMENT;
|
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
2013-12-05 16:23:24 +01:00
|
|
|
|
|
|
|
public static function createCredit($credit)
|
|
|
|
{
|
|
|
|
$activity = Activity::getBlank();
|
|
|
|
$activity->message = Auth::user()->getFullName() . ' created credit';
|
|
|
|
$activity->credit_id = $credit->id;
|
|
|
|
$activity->client_id = $credit->client_id;
|
2013-12-29 18:40:11 +01:00
|
|
|
$activity->currency_id = $credit->currency_id;
|
2013-12-05 16:23:24 +01:00
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_CREATE_CREDIT;
|
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-26 22:26:08 +01:00
|
|
|
public static function archivePayment($payment)
|
|
|
|
{
|
|
|
|
$activity = Activity::getBlank();
|
|
|
|
$activity->invoice_id = $invoice->id;
|
|
|
|
$activity->client_id = $invoice->client_id;
|
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_ARCHIVE_PAYMENT;
|
2013-12-07 19:45:00 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' archived payment';
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:40:13 +01:00
|
|
|
public static function viewInvoice($invitation)
|
2013-11-26 22:26:08 +01:00
|
|
|
{
|
|
|
|
$activity = new Activity;
|
2013-12-02 13:22:29 +01:00
|
|
|
$activity->user_id = $invitation->user_id;
|
|
|
|
$activity->account_id = $invitation->user->account_id;
|
|
|
|
$activity->client_id = $invitation->invoice->client_id;
|
|
|
|
$activity->invitation_id = $invitation->id;
|
2013-11-28 17:40:13 +01:00
|
|
|
$activity->contact_id = $invitation->contact_id;
|
|
|
|
$activity->invoice_id = $invitation->invoice_id;
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_VIEW_INVOICE;
|
2013-12-07 19:45:00 +01:00
|
|
|
$activity->message = $invitation->contact->getFullName() . ' viewed invoice ' . link_to('invoices/'.$invitation->invoice->public_id, $invitation->invoice->invoice_number);
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
2013-11-26 22:45:10 +01:00
|
|
|
}
|
2013-11-26 22:26:08 +01:00
|
|
|
}
|