2013-11-26 22:26:08 +01:00
|
|
|
<?php
|
|
|
|
|
2013-11-26 22:45:10 +01:00
|
|
|
define("ACTIVITY_TYPE_CREATE_CLIENT", 1);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_CLIENT", 2);
|
|
|
|
define("ACTIVITY_TYPE_CREATE_INVOICE", 3);
|
|
|
|
define("ACTIVITY_TYPE_EMAIL_INVOICE", 4);
|
|
|
|
define("ACTIVITY_TYPE_VIEW_INVOICE", 5);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_INVOICE", 6);
|
|
|
|
define("ACTIVITY_TYPE_CREATE_PAYMENT", 7);
|
|
|
|
define("ACTIVITY_TYPE_ARCHIVE_PAYMENT", 8);
|
|
|
|
|
2013-11-26 22:26:08 +01:00
|
|
|
class Activity extends Eloquent
|
|
|
|
{
|
|
|
|
private static function getBlank()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
$activity = new Activity;
|
|
|
|
$activity->user_id = $user->id;
|
|
|
|
$activity->account_id = $user->account_id;
|
|
|
|
|
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-11-27 08:38:37 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' created client ' . $client->name;
|
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)
|
|
|
|
{
|
|
|
|
$activity = Activity::getBlank();
|
|
|
|
$activity->invoice_id = $invoice->id;
|
|
|
|
$activity->client_id = $invoice->client_id;
|
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_CREATE_INVOICE;
|
2013-11-27 08:38:37 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' created invoice ' . $invoice->number;
|
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-11-27 08:38:37 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' archived 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
|
|
|
{
|
|
|
|
$activity = Activity::getBlank();
|
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-11-28 17:40:13 +01:00
|
|
|
//$activity->message = Auth::user()->getFullName() . ' emailed invoice ' . $invitation->invoice->number . ' to ' . $contact->getFullName();
|
2013-11-26 22:26:08 +01:00
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
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-11-27 08:38:37 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' created invoice ' . $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;
|
|
|
|
$activity->invoice_id = $payment->invoice_id;
|
|
|
|
$activity->client_id = $payment->invoice->client_id;
|
|
|
|
$activity->activity_type_id = ACTIVITY_TYPE_CREATE_PAYMENT;
|
|
|
|
$activity->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-11-27 08:38:37 +01:00
|
|
|
$activity->message = Auth::user()->getFullName() . ' archived payment ' . $invoice->number;
|
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-11-28 17:40:13 +01:00
|
|
|
$activity->invitation_id = $invitation->invitation_id;
|
|
|
|
$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-11-28 13:15:34 +01:00
|
|
|
//$activity->message = $contact->getFullName() . ' viewed 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
|
|
|
}
|