diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 5c644c5b4b..795e241e62 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -154,7 +154,7 @@ class CheckData extends Command { $clients->where('clients.id', '=', $this->option('client_id')); } else { $clients->where('invoices.is_deleted', '=', 0) - ->where('invoices.is_quote', '=', 0) + ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('invoices.is_recurring', '=', 0) ->havingRaw('abs(clients.balance - sum(invoices.balance)) > .01 and clients.balance != 999999999.9999'); } @@ -184,7 +184,7 @@ class CheckData extends Command { if ($activity->invoice_id) { $invoice = DB::table('invoices') ->where('id', '=', $activity->invoice_id) - ->first(['invoices.amount', 'invoices.is_recurring', 'invoices.is_quote', 'invoices.deleted_at', 'invoices.id', 'invoices.is_deleted']); + ->first(['invoices.amount', 'invoices.is_recurring', 'invoices.invoice_type_id', 'invoices.deleted_at', 'invoices.id', 'invoices.is_deleted']); // Check if this invoice was once set as recurring invoice if ($invoice && !$invoice->is_recurring && DB::table('invoices') @@ -221,14 +221,14 @@ class CheckData extends Command { && $invoice->amount > 0; // **Fix for allowing converting a recurring invoice to a normal one without updating the balance** - if ($noAdjustment && !$invoice->is_quote && !$invoice->is_recurring) { - $this->info("No adjustment for new invoice:{$activity->invoice_id} amount:{$invoice->amount} isQuote:{$invoice->is_quote} isRecurring:{$invoice->is_recurring}"); + if ($noAdjustment && $invoice->invoice_type_id == INVOICE_TYPE_STANDARD && !$invoice->is_recurring) { + $this->info("No adjustment for new invoice:{$activity->invoice_id} amount:{$invoice->amount} invoiceTypeId:{$invoice->invoice_type_id} isRecurring:{$invoice->is_recurring}"); $foundProblem = true; $clientFix += $invoice->amount; $activityFix = $invoice->amount; // **Fix for updating balance when creating a quote or recurring invoice** - } elseif ($activity->adjustment != 0 && ($invoice->is_quote || $invoice->is_recurring)) { - $this->info("Incorrect adjustment for new invoice:{$activity->invoice_id} adjustment:{$activity->adjustment} isQuote:{$invoice->is_quote} isRecurring:{$invoice->is_recurring}"); + } elseif ($activity->adjustment != 0 && ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE || $invoice->is_recurring)) { + $this->info("Incorrect adjustment for new invoice:{$activity->invoice_id} adjustment:{$activity->adjustment} invoiceTypeId:{$invoice->invoice_type_id} isRecurring:{$invoice->is_recurring}"); $foundProblem = true; $clientFix -= $activity->adjustment; $activityFix = 0; diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 49955e184b..6544333a3f 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -590,8 +590,8 @@ class AccountController extends BaseController // sample invoice to help determine variables $invoice = Invoice::scope() + ->invoiceType(INVOICE_TYPE_STANDARD) ->with('client', 'account') - ->where('is_quote', '=', false) ->where('is_recurring', '=', false) ->first(); diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index d2a0633e5c..8a45111311 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -136,7 +136,7 @@ class ClientController extends BaseController 'credit' => $client->getTotalCredit(), 'title' => trans('texts.view_client'), 'hasRecurringInvoices' => Invoice::scope()->where('is_recurring', '=', true)->whereClientId($client->id)->count() > 0, - 'hasQuotes' => Invoice::scope()->where('is_quote', '=', true)->whereClientId($client->id)->count() > 0, + 'hasQuotes' => Invoice::scope()->invoiceType(INVOICE_TYPE_QUOTE)->whereClientId($client->id)->count() > 0, 'hasTasks' => Task::scope()->whereClientId($client->id)->count() > 0, 'gatewayLink' => $client->getGatewayLink($accountGateway), 'gateway' => $accountGateway diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 56dd183b19..ba025e283f 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -62,7 +62,7 @@ class ClientPortalController extends BaseController if (!Input::has('phantomjs') && !Input::has('silent') && !Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) { - if ($invoice->is_quote) { + if ($invoice->isType(INVOICE_TYPE_QUOTE)) { event(new QuoteInvitationWasViewed($invoice, $invitation)); } else { event(new InvoiceInvitationWasViewed($invoice, $invitation)); diff --git a/app/Http/Controllers/DashboardApiController.php b/app/Http/Controllers/DashboardApiController.php index 1170812b83..e7e96a5ad9 100644 --- a/app/Http/Controllers/DashboardApiController.php +++ b/app/Http/Controllers/DashboardApiController.php @@ -24,7 +24,7 @@ class DashboardApiController extends BaseAPIController ->where('clients.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false) ->where('invoices.is_recurring', '=', false) - ->where('invoices.is_quote', '=', false); + ->where('invoices.invoice_type_id', '=', false); if(!$view_all){ $metrics = $metrics->where(function($query) use($user_id){ @@ -62,7 +62,7 @@ class DashboardApiController extends BaseAPIController ->where('accounts.id', '=', Auth::user()->account_id) ->where('clients.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false) - ->where('invoices.is_quote', '=', false) + ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('invoices.is_recurring', '=', false); if(!$view_all){ @@ -106,7 +106,7 @@ class DashboardApiController extends BaseAPIController $pastDue = $pastDue->where('invoices.user_id', '=', $user_id); } - $pastDue = $pastDue->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'is_quote']) + $pastDue = $pastDue->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'invoice_type_id']) ->orderBy('invoices.due_date', 'asc') ->take(50) ->get(); @@ -131,7 +131,7 @@ class DashboardApiController extends BaseAPIController } $upcoming = $upcoming->take(50) - ->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'is_quote']) + ->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'invoice_type_id']) ->get(); $payments = DB::table('payments') @@ -157,7 +157,7 @@ class DashboardApiController extends BaseAPIController $hasQuotes = false; foreach ([$upcoming, $pastDue] as $data) { foreach ($data as $invoice) { - if ($invoice->is_quote) { + if ($invoice->isType(INVOICE_TYPE_QUOTE)) { $hasQuotes = true; } } diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 718d73c67d..283a098477 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -26,7 +26,7 @@ class DashboardController extends BaseController ->where('clients.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false) ->where('invoices.is_recurring', '=', false) - ->where('invoices.is_quote', '=', false); + ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD); if(!$view_all){ $metrics = $metrics->where(function($query) use($user_id){ @@ -64,7 +64,7 @@ class DashboardController extends BaseController ->where('accounts.id', '=', Auth::user()->account_id) ->where('clients.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false) - ->where('invoices.is_quote', '=', false) + ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('invoices.is_recurring', '=', false); if(!$view_all){ @@ -121,7 +121,7 @@ class DashboardController extends BaseController $pastDue = $pastDue->where('invoices.user_id', '=', $user_id); } - $pastDue = $pastDue->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'is_quote']) + $pastDue = $pastDue->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'invoice_type_id']) ->orderBy('invoices.due_date', 'asc') ->take(50) ->get(); @@ -147,7 +147,7 @@ class DashboardController extends BaseController } $upcoming = $upcoming->take(50) - ->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'is_quote']) + ->select(['invoices.due_date', 'invoices.balance', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id', 'invoice_type_id']) ->get(); $payments = DB::table('payments') @@ -173,7 +173,7 @@ class DashboardController extends BaseController $hasQuotes = false; foreach ([$upcoming, $pastDue] as $data) { foreach ($data as $invoice) { - if ($invoice->is_quote) { + if ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE) { $hasQuotes = true; } } diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index c7f30b03be..244b6e8aee 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -134,23 +134,23 @@ class ExportController extends BaseController if ($request->input(ENTITY_INVOICE)) { $data['invoices'] = Invoice::scope() + ->invoiceType(INVOICE_TYPE_STANDARD) ->with('user', 'client.contacts', 'invoice_status') ->withArchived() - ->where('is_quote', '=', false) ->where('is_recurring', '=', false) ->get(); $data['quotes'] = Invoice::scope() + ->invoiceType(INVOICE_TYPE_QUOTE) ->with('user', 'client.contacts', 'invoice_status') ->withArchived() - ->where('is_quote', '=', true) ->where('is_recurring', '=', false) ->get(); $data['recurringInvoices'] = Invoice::scope() + ->invoiceType(INVOICE_TYPE_STANDARD) ->with('user', 'client.contacts', 'invoice_status', 'frequency') ->withArchived() - ->where('is_quote', '=', false) ->where('is_recurring', '=', true) ->get(); } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 9a0dadf494..62faaca695 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -567,9 +567,9 @@ class InvoiceController extends BaseController 'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY), 'invoice_settings' => Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS), ]; - $invoice->is_quote = intval($invoice->is_quote); + $invoice->invoice_type_id = intval($invoice->invoice_type_id); - $activityTypeId = $invoice->is_quote ? ACTIVITY_TYPE_UPDATE_QUOTE : ACTIVITY_TYPE_UPDATE_INVOICE; + $activityTypeId = $invoice->isType(INVOICE_TYPE_QUOTE) ? ACTIVITY_TYPE_UPDATE_QUOTE : ACTIVITY_TYPE_UPDATE_INVOICE; $activities = Activity::scope(false, $invoice->account_id) ->where('activity_type_id', '=', $activityTypeId) ->where('invoice_id', '=', $invoice->id) @@ -589,7 +589,7 @@ class InvoiceController extends BaseController 'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY), 'invoice_settings' => Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS), ]; - $backup->is_quote = isset($backup->is_quote) && intval($backup->is_quote); + $backup->invoice_type_id = isset($backup->invoice_type_id) && intval($backup->invoice_type_id) == INVOICE_TYPE_QUOTE; $backup->account = $invoice->account->toArray(); $versionsJson[$activity->id] = $backup; diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 6a5742fabe..c0dd4a9f85 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -77,8 +77,8 @@ class PaymentController extends BaseController public function create(PaymentRequest $request) { $invoices = Invoice::scope() + ->invoiceType(INVOICE_TYPE_STANDARD) ->where('is_recurring', '=', false) - ->where('is_quote', '=', false) ->where('invoices.balance', '>', 0) ->with('client', 'invoice_status') ->orderBy('invoice_number')->get(); @@ -108,7 +108,7 @@ class PaymentController extends BaseController $data = array( 'client' => null, 'invoice' => null, - 'invoices' => Invoice::scope()->where('is_recurring', '=', false)->where('is_quote', '=', false) + 'invoices' => Invoice::scope()->invoiceType(INVOICE_TYPE_STANDARD)->where('is_recurring', '=', false) ->with('client', 'invoice_status')->orderBy('invoice_number')->get(), 'payment' => $payment, 'method' => 'PUT', diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 4f162f260d..65d379eb3f 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -168,7 +168,7 @@ class ReportController extends BaseController ->groupBy($groupBy); if ($entityType == ENTITY_INVOICE) { - $records->where('is_quote', '=', false) + $records->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('is_recurring', '=', false); } elseif ($entityType == ENTITY_PAYMENT) { $records->join('invoices', 'invoices.id', '=', 'payments.invoice_id') @@ -374,7 +374,7 @@ class ReportController extends BaseController $query->where('invoice_date', '>=', $startDate) ->where('invoice_date', '<=', $endDate) ->where('is_deleted', '=', false) - ->where('is_quote', '=', false) + ->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('is_recurring', '=', false) ->with(['payments' => function($query) { $query->withTrashed() @@ -429,7 +429,7 @@ class ReportController extends BaseController ->with(['invoices' => function($query) use ($startDate, $endDate) { $query->where('invoice_date', '>=', $startDate) ->where('invoice_date', '<=', $endDate) - ->where('is_quote', '=', false) + ->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('is_recurring', '=', false) ->withArchived(); }]); diff --git a/app/Http/routes.php b/app/Http/routes.php index 84ec2552bb..4b1a8e10ad 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -358,6 +358,9 @@ if (!defined('CONTACT_EMAIL')) { define('ENTITY_BANK_ACCOUNT', 'bank_account'); define('ENTITY_BANK_SUBACCOUNT', 'bank_subaccount'); + define('INVOICE_TYPE_STANDARD', 1); + define('INVOICE_TYPE_QUOTE', 2); + define('PERSON_CONTACT', 'contact'); define('PERSON_USER', 'user'); define('PERSON_VENDOR_CONTACT','vendorcontact'); diff --git a/app/Models/Account.php b/app/Models/Account.php index c489d21b18..208ea19dcd 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -524,7 +524,7 @@ class Account extends Eloquent $invoice = Invoice::createNew(); $invoice->is_recurring = false; - $invoice->is_quote = false; + $invoice->invoice_type_id = INVOICE_TYPE_STANDARD; $invoice->invoice_date = Utils::today(); $invoice->start_date = Utils::today(); $invoice->invoice_design_id = $this->invoice_design_id; @@ -535,7 +535,7 @@ class Account extends Eloquent $invoice->is_recurring = true; } else { if ($entityType == ENTITY_QUOTE) { - $invoice->is_quote = true; + $invoice->invoice_type_id = INVOICE_TYPE_QUOTE; } if ($this->hasClientNumberPattern($invoice) && !$clientId) { @@ -553,34 +553,34 @@ class Account extends Eloquent return $invoice; } - public function getNumberPrefix($isQuote) + public function getNumberPrefix($invoice_type_id) { if ( ! $this->hasFeature(FEATURE_INVOICE_SETTINGS)) { return ''; } - return ($isQuote ? $this->quote_number_prefix : $this->invoice_number_prefix) ?: ''; + return ($invoice_type_id == INVOICE_TYPE_QUOTE ? $this->quote_number_prefix : $this->invoice_number_prefix) ?: ''; } - public function hasNumberPattern($isQuote) + public function hasNumberPattern($invoice_type_id) { if ( ! $this->hasFeature(FEATURE_INVOICE_SETTINGS)) { return false; } - return $isQuote ? ($this->quote_number_pattern ? true : false) : ($this->invoice_number_pattern ? true : false); + return $invoice_type_id == INVOICE_TYPE_QUOTE ? ($this->quote_number_pattern ? true : false) : ($this->invoice_number_pattern ? true : false); } public function hasClientNumberPattern($invoice) { - $pattern = $invoice->is_quote ? $this->quote_number_pattern : $this->invoice_number_pattern; + $pattern = $invoice->invoice_type_id == INVOICE_TYPE_QUOTE ? $this->quote_number_pattern : $this->invoice_number_pattern; return strstr($pattern, '$custom'); } public function getNumberPattern($invoice) { - $pattern = $invoice->is_quote ? $this->quote_number_pattern : $this->invoice_number_pattern; + $pattern = $invoice->invoice_type_id == INVOICE_TYPE_QUOTE ? $this->quote_number_pattern : $this->invoice_number_pattern; if (!$pattern) { return false; @@ -590,7 +590,7 @@ class Account extends Eloquent $replace = [date('Y')]; $search[] = '{$counter}'; - $replace[] = str_pad($this->getCounter($invoice->is_quote), $this->invoice_number_padding, '0', STR_PAD_LEFT); + $replace[] = str_pad($this->getCounter($invoice->invoice_type_id), $this->invoice_number_padding, '0', STR_PAD_LEFT); if (strstr($pattern, '{$userId}')) { $search[] = '{$userId}'; @@ -633,9 +633,9 @@ class Account extends Eloquent return str_replace($search, $replace, $pattern); } - public function getCounter($isQuote) + public function getCounter($invoice_type_id) { - return $isQuote && !$this->share_counter ? $this->quote_number_counter : $this->invoice_number_counter; + return $invoice_type_id == INVOICE_TYPE_QUOTE && !$this->share_counter ? $this->quote_number_counter : $this->invoice_number_counter; } public function previewNextInvoiceNumber($entityType = ENTITY_INVOICE) @@ -646,12 +646,12 @@ class Account extends Eloquent public function getNextInvoiceNumber($invoice) { - if ($this->hasNumberPattern($invoice->is_quote)) { + if ($this->hasNumberPattern($invoice->invoice_type_id)) { return $this->getNumberPattern($invoice); } - $counter = $this->getCounter($invoice->is_quote); - $prefix = $this->getNumberPrefix($invoice->is_quote); + $counter = $this->getCounter($invoice->invoice_type_id); + $prefix = $this->getNumberPrefix($invoice->invoice_type_id); $counterOffset = 0; // confirm the invoice number isn't already taken @@ -664,7 +664,7 @@ class Account extends Eloquent // update the invoice counter to be caught up if ($counterOffset > 1) { - if ($invoice->is_quote && !$this->share_counter) { + if ($invoice->isType(INVOICE_TYPE_QUOTE) && !$this->share_counter) { $this->quote_number_counter += $counterOffset - 1; } else { $this->invoice_number_counter += $counterOffset - 1; @@ -678,7 +678,7 @@ class Account extends Eloquent public function incrementCounter($invoice) { - if ($invoice->is_quote && !$this->share_counter) { + if ($invoice->isType(INVOICE_TYPE_QUOTE) && !$this->share_counter) { $this->quote_number_counter += 1; } else { $default = $this->invoice_number_counter; @@ -1102,7 +1102,7 @@ class Account extends Eloquent 'invoice_items', 'created_at', 'is_recurring', - 'is_quote', + 'invoice_type_id', ]); foreach ($invoice->invoice_items as $invoiceItem) { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 02fdc73f99..f3717e9afa 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -96,7 +96,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function affectsBalance() { - return !$this->is_quote && !$this->is_recurring; + return $this->isType(INVOICE_TYPE_STANDARD) && !$this->is_recurring; } public function getAdjustment() @@ -139,7 +139,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function getAmountPaid($calculate = false) { - if ($this->is_quote || $this->is_recurring) { + if ($this->isType(INVOICE_TYPE_QUOTE) || $this->is_recurring) { return 0; } @@ -230,10 +230,19 @@ class Invoice extends EntityModel implements BalanceAffecting public function scopeInvoices($query) { - return $query->where('is_quote', '=', false) + return $query->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('is_recurring', '=', false); } + public function scopeInvoiceType($query, $typeId) + { + return $query->where('invoice_type_id', '=', $typeId); + } + + public function isType($typeId) { + return $this->invoice_type_id == $typeId; + } + public function markInvitationsSent($notify = false) { foreach ($this->invitations as $invitation) { @@ -256,7 +265,7 @@ class Invoice extends EntityModel implements BalanceAffecting return; } - if ($this->is_quote) { + if ($this->isType(INVOICE_TYPE_QUOTE)) { event(new QuoteInvitationWasEmailed($invitation)); } else { event(new InvoiceInvitationWasEmailed($invitation)); @@ -292,7 +301,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function markApproved() { - if ($this->is_quote) { + if ($this->isType(INVOICE_TYPE_QUOTE)) { $this->invoice_status_id = INVOICE_STATUS_APPROVED; $this->save(); } @@ -341,7 +350,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function getEntityType() { - return $this->is_quote ? ENTITY_QUOTE : ENTITY_INVOICE; + return $this->isType(INVOICE_TYPE_QUOTE) ? ENTITY_QUOTE : ENTITY_INVOICE; } public function isSent() @@ -416,7 +425,7 @@ class Invoice extends EntityModel implements BalanceAffecting 'invoice_design_id', 'invoice_fonts', 'features', - 'is_quote', + 'invoice_type_id', 'custom_value1', 'custom_value2', 'custom_taxes1', @@ -943,7 +952,7 @@ Invoice::creating(function ($invoice) { }); Invoice::created(function ($invoice) { - if ($invoice->is_quote) { + if ($invoice->isType(INVOICE_TYPE_QUOTE)) { event(new QuoteWasCreated($invoice)); } else { event(new InvoiceWasCreated($invoice)); @@ -951,7 +960,7 @@ Invoice::created(function ($invoice) { }); Invoice::updating(function ($invoice) { - if ($invoice->is_quote) { + if ($invoice->isType(INVOICE_TYPE_QUOTE)) { event(new QuoteWasUpdated($invoice)); } else { event(new InvoiceWasUpdated($invoice)); diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 224d48785a..9d4b3c5091 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -96,7 +96,7 @@ class ContactMailer extends Mailer $account->loadLocalizationSettings(); if ($sent === true) { - if ($invoice->is_quote) { + if ($invoice->isType(INVOICE_TYPE_QUOTE)) { event(new QuoteWasEmailed($invoice)); } else { event(new InvoiceWasEmailed($invoice)); diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index 827b171f42..1c77ef1b09 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -19,7 +19,7 @@ class InvoicePresenter extends EntityPresenter { { if ($this->entity->partial > 0) { return 'partial_due'; - } elseif ($this->entity->is_quote) { + } elseif ($this->entity->isType(INVOICE_TYPE_QUOTE)) { return 'total'; } else { return 'balance_due'; diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 979304ed01..6a48c9a749 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -32,9 +32,9 @@ class InvoiceRepository extends BaseRepository public function all() { return Invoice::scope() + ->invoiceType(INVOICE_TYPE_STANDARD) ->with('user', 'client.contacts', 'invoice_status') ->withTrashed() - ->where('is_quote', '=', false) ->where('is_recurring', '=', false) ->get(); } @@ -106,7 +106,7 @@ class InvoiceRepository extends BaseRepository ->join('frequencies', 'frequencies.id', '=', 'invoices.frequency_id') ->join('contacts', 'contacts.client_id', '=', 'clients.id') ->where('invoices.account_id', '=', $accountId) - ->where('invoices.is_quote', '=', false) + ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('contacts.deleted_at', '=', null) ->where('invoices.is_recurring', '=', true) ->where('contacts.is_primary', '=', true) @@ -156,7 +156,7 @@ class InvoiceRepository extends BaseRepository ->join('frequencies', 'frequencies.id', '=', 'invoices.frequency_id') ->where('invitations.contact_id', '=', $contactId) ->where('invitations.deleted_at', '=', null) - ->where('invoices.is_quote', '=', false) + ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('invoices.is_deleted', '=', false) ->where('clients.deleted_at', '=', null) ->where('invoices.is_recurring', '=', true) @@ -203,7 +203,7 @@ class InvoiceRepository extends BaseRepository ->join('contacts', 'contacts.client_id', '=', 'clients.id') ->where('invitations.contact_id', '=', $contactId) ->where('invitations.deleted_at', '=', null) - ->where('invoices.is_quote', '=', $entityType == ENTITY_QUOTE) + ->where('invoices.invoice_type_id', '=', $entityType == ENTITY_QUOTE ? INVOICE_TYPE_QUOTE : INVOICE_TYPE_STANDARD) ->where('invoices.is_deleted', '=', false) ->where('clients.deleted_at', '=', null) ->where('contacts.deleted_at', '=', null) @@ -642,7 +642,7 @@ class InvoiceRepository extends BaseRepository 'tax_name2', 'tax_rate2', 'amount', - 'is_quote', + 'invoice_type_id', 'custom_value1', 'custom_value2', 'custom_taxes1', @@ -654,7 +654,7 @@ class InvoiceRepository extends BaseRepository } if ($quotePublicId) { - $clone->is_quote = false; + $clone->invoice_type_id = INVOICE_TYPE_STANDARD; $clone->quote_id = $quotePublicId; } @@ -838,9 +838,9 @@ class InvoiceRepository extends BaseRepository } $sql = implode(' OR ', $dates); - $invoices = Invoice::whereAccountId($account->id) + $invoices = Invoice::invoiceType(INVOICE_TYPE_STANDARD) + ->whereAccountId($account->id) ->where('balance', '>', 0) - ->where('is_quote', '=', false) ->where('is_recurring', '=', false) ->whereRaw('('.$sql.')') ->get(); diff --git a/app/Ninja/Transformers/InvoiceTransformer.php b/app/Ninja/Transformers/InvoiceTransformer.php index fc17127719..b961dbdfae 100644 --- a/app/Ninja/Transformers/InvoiceTransformer.php +++ b/app/Ninja/Transformers/InvoiceTransformer.php @@ -93,7 +93,7 @@ class InvoiceTransformer extends EntityTransformer 'terms' => $invoice->terms, 'public_notes' => $invoice->public_notes, 'is_deleted' => (bool) $invoice->is_deleted, - 'is_quote' => (bool) $invoice->is_quote, + 'invoice_type_id' => (int) $invoice->invoice_type_id, 'is_recurring' => (bool) $invoice->is_recurring, 'frequency_id' => (int) $invoice->frequency_id, 'start_date' => $invoice->start_date, diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index 950c8bb95f..71a8f91f0f 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -94,7 +94,7 @@ class InvoiceService extends BaseService { $account = $quote->account; - if (!$quote->is_quote || $quote->quote_invoice_id) { + if (!$quote->isType(INVOICE_TYPE_QUOTE) || $quote->quote_invoice_id) { return null; } @@ -121,7 +121,7 @@ class InvoiceService extends BaseService { $datatable = new InvoiceDatatable( ! $clientPublicId, $clientPublicId); $query = $this->invoiceRepo->getInvoices($accountId, $clientPublicId, $entityType, $search) - ->where('invoices.is_quote', '=', $entityType == ENTITY_QUOTE ? true : false); + ->where('invoices.invoice_type_id', '=', $entityType == ENTITY_QUOTE ? INVOICE_TYPE_QUOTE : INVOICE_TYPE_STANDARD); if(!Utils::hasPermission('view_all')){ $query->where('invoices.user_id', '=', Auth::user()->id); diff --git a/app/Services/PushService.php b/app/Services/PushService.php index a96042b924..2edd86af4b 100644 --- a/app/Services/PushService.php +++ b/app/Services/PushService.php @@ -132,7 +132,7 @@ class PushService */ private function entitySentMessage($invoice) { - if($invoice->is_quote) + if($invoice->isType(INVOICE_TYPE_QUOTE)) return trans("texts.notification_quote_sent_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]); else return trans("texts.notification_invoice_sent_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]); @@ -163,7 +163,7 @@ class PushService */ private function entityViewedMessage($invoice) { - if($invoice->is_quote) + if($invoice->isType(INVOICE_TYPE_QUOTE)) return trans("texts.notification_quote_viewed_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]); else return trans("texts.notification_invoice_viewed_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]); diff --git a/database/migrations/2016_05_18_085739_add_invoice_type_support.php b/database/migrations/2016_05_18_085739_add_invoice_type_support.php new file mode 100644 index 0000000000..7b0b928d81 --- /dev/null +++ b/database/migrations/2016_05_18_085739_add_invoice_type_support.php @@ -0,0 +1,31 @@ +renameColumn('is_quote', 'invoice_type_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('invoices', function ($table) { + $table->renameColumn('invoice_type_id', 'is_quote'); + }); + } +} diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index bc1d2bb6e8..b661af7a40 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -150,7 +150,7 @@ @foreach ($upcoming as $invoice) - @if (!$invoice->is_quote) + @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD) {!! \App\Models\Invoice::calcLink($invoice) !!} @can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id]) @@ -185,7 +185,7 @@ @foreach ($pastDue as $invoice) - @if (!$invoice->is_quote) + @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD) {!! \App\Models\Invoice::calcLink($invoice) !!} @can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id]) @@ -224,7 +224,7 @@ @foreach ($upcoming as $invoice) - @if ($invoice->is_quote) + @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD) {!! \App\Models\Invoice::calcLink($invoice) !!} {!! link_to('/clients/'.$invoice->client_public_id, trim($invoice->client_name) ?: (trim($invoice->first_name . ' ' . $invoice->last_name) ?: $invoice->email)) !!} @@ -255,7 +255,7 @@ @foreach ($pastDue as $invoice) - @if ($invoice->is_quote) + @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD) {!! \App\Models\Invoice::calcLink($invoice) !!} {!! link_to('/clients/'.$invoice->client_public_id, trim($invoice->client_name) ?: (trim($invoice->first_name . ' ' . $invoice->last_name) ?: $invoice->email)) !!}