1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 00:53:10 +01:00

add support to multiple invoice types

This commit is contained in:
ben 2016-05-26 17:56:54 +03:00
parent 29bccd650d
commit dadac05532
21 changed files with 118 additions and 75 deletions

View File

@ -154,7 +154,7 @@ class CheckData extends Command {
$clients->where('clients.id', '=', $this->option('client_id')); $clients->where('clients.id', '=', $this->option('client_id'));
} else { } else {
$clients->where('invoices.is_deleted', '=', 0) $clients->where('invoices.is_deleted', '=', 0)
->where('invoices.is_quote', '=', 0) ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('invoices.is_recurring', '=', 0) ->where('invoices.is_recurring', '=', 0)
->havingRaw('abs(clients.balance - sum(invoices.balance)) > .01 and clients.balance != 999999999.9999'); ->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) { if ($activity->invoice_id) {
$invoice = DB::table('invoices') $invoice = DB::table('invoices')
->where('id', '=', $activity->invoice_id) ->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 // Check if this invoice was once set as recurring invoice
if ($invoice && !$invoice->is_recurring && DB::table('invoices') if ($invoice && !$invoice->is_recurring && DB::table('invoices')
@ -221,14 +221,14 @@ class CheckData extends Command {
&& $invoice->amount > 0; && $invoice->amount > 0;
// **Fix for allowing converting a recurring invoice to a normal one without updating the balance** // **Fix for allowing converting a recurring invoice to a normal one without updating the balance**
if ($noAdjustment && !$invoice->is_quote && !$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} isQuote:{$invoice->is_quote} isRecurring:{$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; $foundProblem = true;
$clientFix += $invoice->amount; $clientFix += $invoice->amount;
$activityFix = $invoice->amount; $activityFix = $invoice->amount;
// **Fix for updating balance when creating a quote or recurring invoice** // **Fix for updating balance when creating a quote or recurring invoice**
} elseif ($activity->adjustment != 0 && ($invoice->is_quote || $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} isQuote:{$invoice->is_quote} isRecurring:{$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; $foundProblem = true;
$clientFix -= $activity->adjustment; $clientFix -= $activity->adjustment;
$activityFix = 0; $activityFix = 0;

View File

@ -590,8 +590,8 @@ class AccountController extends BaseController
// sample invoice to help determine variables // sample invoice to help determine variables
$invoice = Invoice::scope() $invoice = Invoice::scope()
->invoiceType(INVOICE_TYPE_STANDARD)
->with('client', 'account') ->with('client', 'account')
->where('is_quote', '=', false)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->first(); ->first();

View File

@ -136,7 +136,7 @@ class ClientController extends BaseController
'credit' => $client->getTotalCredit(), 'credit' => $client->getTotalCredit(),
'title' => trans('texts.view_client'), 'title' => trans('texts.view_client'),
'hasRecurringInvoices' => Invoice::scope()->where('is_recurring', '=', true)->whereClientId($client->id)->count() > 0, '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, 'hasTasks' => Task::scope()->whereClientId($client->id)->count() > 0,
'gatewayLink' => $client->getGatewayLink($accountGateway), 'gatewayLink' => $client->getGatewayLink($accountGateway),
'gateway' => $accountGateway 'gateway' => $accountGateway

View File

@ -62,7 +62,7 @@ class ClientPortalController extends BaseController
if (!Input::has('phantomjs') && !Input::has('silent') && !Session::has($invitationKey) if (!Input::has('phantomjs') && !Input::has('silent') && !Session::has($invitationKey)
&& (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) { && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) {
if ($invoice->is_quote) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
event(new QuoteInvitationWasViewed($invoice, $invitation)); event(new QuoteInvitationWasViewed($invoice, $invitation));
} else { } else {
event(new InvoiceInvitationWasViewed($invoice, $invitation)); event(new InvoiceInvitationWasViewed($invoice, $invitation));

View File

@ -24,7 +24,7 @@ class DashboardApiController extends BaseAPIController
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false)
->where('invoices.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false)
->where('invoices.is_recurring', '=', false) ->where('invoices.is_recurring', '=', false)
->where('invoices.is_quote', '=', false); ->where('invoices.invoice_type_id', '=', false);
if(!$view_all){ if(!$view_all){
$metrics = $metrics->where(function($query) use($user_id){ $metrics = $metrics->where(function($query) use($user_id){
@ -62,7 +62,7 @@ class DashboardApiController extends BaseAPIController
->where('accounts.id', '=', Auth::user()->account_id) ->where('accounts.id', '=', Auth::user()->account_id)
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false)
->where('invoices.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); ->where('invoices.is_recurring', '=', false);
if(!$view_all){ if(!$view_all){
@ -106,7 +106,7 @@ class DashboardApiController extends BaseAPIController
$pastDue = $pastDue->where('invoices.user_id', '=', $user_id); $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') ->orderBy('invoices.due_date', 'asc')
->take(50) ->take(50)
->get(); ->get();
@ -131,7 +131,7 @@ class DashboardApiController extends BaseAPIController
} }
$upcoming = $upcoming->take(50) $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(); ->get();
$payments = DB::table('payments') $payments = DB::table('payments')
@ -157,7 +157,7 @@ class DashboardApiController extends BaseAPIController
$hasQuotes = false; $hasQuotes = false;
foreach ([$upcoming, $pastDue] as $data) { foreach ([$upcoming, $pastDue] as $data) {
foreach ($data as $invoice) { foreach ($data as $invoice) {
if ($invoice->is_quote) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
$hasQuotes = true; $hasQuotes = true;
} }
} }

View File

@ -26,7 +26,7 @@ class DashboardController extends BaseController
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false)
->where('invoices.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false)
->where('invoices.is_recurring', '=', false) ->where('invoices.is_recurring', '=', false)
->where('invoices.is_quote', '=', false); ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD);
if(!$view_all){ if(!$view_all){
$metrics = $metrics->where(function($query) use($user_id){ $metrics = $metrics->where(function($query) use($user_id){
@ -64,7 +64,7 @@ class DashboardController extends BaseController
->where('accounts.id', '=', Auth::user()->account_id) ->where('accounts.id', '=', Auth::user()->account_id)
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false)
->where('invoices.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); ->where('invoices.is_recurring', '=', false);
if(!$view_all){ if(!$view_all){
@ -121,7 +121,7 @@ class DashboardController extends BaseController
$pastDue = $pastDue->where('invoices.user_id', '=', $user_id); $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') ->orderBy('invoices.due_date', 'asc')
->take(50) ->take(50)
->get(); ->get();
@ -147,7 +147,7 @@ class DashboardController extends BaseController
} }
$upcoming = $upcoming->take(50) $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(); ->get();
$payments = DB::table('payments') $payments = DB::table('payments')
@ -173,7 +173,7 @@ class DashboardController extends BaseController
$hasQuotes = false; $hasQuotes = false;
foreach ([$upcoming, $pastDue] as $data) { foreach ([$upcoming, $pastDue] as $data) {
foreach ($data as $invoice) { foreach ($data as $invoice) {
if ($invoice->is_quote) { if ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE) {
$hasQuotes = true; $hasQuotes = true;
} }
} }

View File

@ -134,23 +134,23 @@ class ExportController extends BaseController
if ($request->input(ENTITY_INVOICE)) { if ($request->input(ENTITY_INVOICE)) {
$data['invoices'] = Invoice::scope() $data['invoices'] = Invoice::scope()
->invoiceType(INVOICE_TYPE_STANDARD)
->with('user', 'client.contacts', 'invoice_status') ->with('user', 'client.contacts', 'invoice_status')
->withArchived() ->withArchived()
->where('is_quote', '=', false)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->get(); ->get();
$data['quotes'] = Invoice::scope() $data['quotes'] = Invoice::scope()
->invoiceType(INVOICE_TYPE_QUOTE)
->with('user', 'client.contacts', 'invoice_status') ->with('user', 'client.contacts', 'invoice_status')
->withArchived() ->withArchived()
->where('is_quote', '=', true)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->get(); ->get();
$data['recurringInvoices'] = Invoice::scope() $data['recurringInvoices'] = Invoice::scope()
->invoiceType(INVOICE_TYPE_STANDARD)
->with('user', 'client.contacts', 'invoice_status', 'frequency') ->with('user', 'client.contacts', 'invoice_status', 'frequency')
->withArchived() ->withArchived()
->where('is_quote', '=', false)
->where('is_recurring', '=', true) ->where('is_recurring', '=', true)
->get(); ->get();
} }

View File

@ -567,9 +567,9 @@ class InvoiceController extends BaseController
'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY), 'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY),
'invoice_settings' => Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS), '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) $activities = Activity::scope(false, $invoice->account_id)
->where('activity_type_id', '=', $activityTypeId) ->where('activity_type_id', '=', $activityTypeId)
->where('invoice_id', '=', $invoice->id) ->where('invoice_id', '=', $invoice->id)
@ -589,7 +589,7 @@ class InvoiceController extends BaseController
'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY), 'remove_created_by' => Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY),
'invoice_settings' => Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS), '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(); $backup->account = $invoice->account->toArray();
$versionsJson[$activity->id] = $backup; $versionsJson[$activity->id] = $backup;

View File

@ -77,8 +77,8 @@ class PaymentController extends BaseController
public function create(PaymentRequest $request) public function create(PaymentRequest $request)
{ {
$invoices = Invoice::scope() $invoices = Invoice::scope()
->invoiceType(INVOICE_TYPE_STANDARD)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->where('is_quote', '=', false)
->where('invoices.balance', '>', 0) ->where('invoices.balance', '>', 0)
->with('client', 'invoice_status') ->with('client', 'invoice_status')
->orderBy('invoice_number')->get(); ->orderBy('invoice_number')->get();
@ -108,7 +108,7 @@ class PaymentController extends BaseController
$data = array( $data = array(
'client' => null, 'client' => null,
'invoice' => 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(), ->with('client', 'invoice_status')->orderBy('invoice_number')->get(),
'payment' => $payment, 'payment' => $payment,
'method' => 'PUT', 'method' => 'PUT',

View File

@ -168,7 +168,7 @@ class ReportController extends BaseController
->groupBy($groupBy); ->groupBy($groupBy);
if ($entityType == ENTITY_INVOICE) { if ($entityType == ENTITY_INVOICE) {
$records->where('is_quote', '=', false) $records->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('is_recurring', '=', false); ->where('is_recurring', '=', false);
} elseif ($entityType == ENTITY_PAYMENT) { } elseif ($entityType == ENTITY_PAYMENT) {
$records->join('invoices', 'invoices.id', '=', 'payments.invoice_id') $records->join('invoices', 'invoices.id', '=', 'payments.invoice_id')
@ -374,7 +374,7 @@ class ReportController extends BaseController
$query->where('invoice_date', '>=', $startDate) $query->where('invoice_date', '>=', $startDate)
->where('invoice_date', '<=', $endDate) ->where('invoice_date', '<=', $endDate)
->where('is_deleted', '=', false) ->where('is_deleted', '=', false)
->where('is_quote', '=', false) ->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->with(['payments' => function($query) { ->with(['payments' => function($query) {
$query->withTrashed() $query->withTrashed()
@ -429,7 +429,7 @@ class ReportController extends BaseController
->with(['invoices' => function($query) use ($startDate, $endDate) { ->with(['invoices' => function($query) use ($startDate, $endDate) {
$query->where('invoice_date', '>=', $startDate) $query->where('invoice_date', '>=', $startDate)
->where('invoice_date', '<=', $endDate) ->where('invoice_date', '<=', $endDate)
->where('is_quote', '=', false) ->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->withArchived(); ->withArchived();
}]); }]);

View File

@ -358,6 +358,9 @@ if (!defined('CONTACT_EMAIL')) {
define('ENTITY_BANK_ACCOUNT', 'bank_account'); define('ENTITY_BANK_ACCOUNT', 'bank_account');
define('ENTITY_BANK_SUBACCOUNT', 'bank_subaccount'); define('ENTITY_BANK_SUBACCOUNT', 'bank_subaccount');
define('INVOICE_TYPE_STANDARD', 1);
define('INVOICE_TYPE_QUOTE', 2);
define('PERSON_CONTACT', 'contact'); define('PERSON_CONTACT', 'contact');
define('PERSON_USER', 'user'); define('PERSON_USER', 'user');
define('PERSON_VENDOR_CONTACT','vendorcontact'); define('PERSON_VENDOR_CONTACT','vendorcontact');

View File

@ -524,7 +524,7 @@ class Account extends Eloquent
$invoice = Invoice::createNew(); $invoice = Invoice::createNew();
$invoice->is_recurring = false; $invoice->is_recurring = false;
$invoice->is_quote = false; $invoice->invoice_type_id = INVOICE_TYPE_STANDARD;
$invoice->invoice_date = Utils::today(); $invoice->invoice_date = Utils::today();
$invoice->start_date = Utils::today(); $invoice->start_date = Utils::today();
$invoice->invoice_design_id = $this->invoice_design_id; $invoice->invoice_design_id = $this->invoice_design_id;
@ -535,7 +535,7 @@ class Account extends Eloquent
$invoice->is_recurring = true; $invoice->is_recurring = true;
} else { } else {
if ($entityType == ENTITY_QUOTE) { if ($entityType == ENTITY_QUOTE) {
$invoice->is_quote = true; $invoice->invoice_type_id = INVOICE_TYPE_QUOTE;
} }
if ($this->hasClientNumberPattern($invoice) && !$clientId) { if ($this->hasClientNumberPattern($invoice) && !$clientId) {
@ -553,34 +553,34 @@ class Account extends Eloquent
return $invoice; return $invoice;
} }
public function getNumberPrefix($isQuote) public function getNumberPrefix($invoice_type_id)
{ {
if ( ! $this->hasFeature(FEATURE_INVOICE_SETTINGS)) { if ( ! $this->hasFeature(FEATURE_INVOICE_SETTINGS)) {
return ''; 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)) { if ( ! $this->hasFeature(FEATURE_INVOICE_SETTINGS)) {
return false; 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) 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'); return strstr($pattern, '$custom');
} }
public function getNumberPattern($invoice) 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) { if (!$pattern) {
return false; return false;
@ -590,7 +590,7 @@ class Account extends Eloquent
$replace = [date('Y')]; $replace = [date('Y')];
$search[] = '{$counter}'; $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}')) { if (strstr($pattern, '{$userId}')) {
$search[] = '{$userId}'; $search[] = '{$userId}';
@ -633,9 +633,9 @@ class Account extends Eloquent
return str_replace($search, $replace, $pattern); 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) public function previewNextInvoiceNumber($entityType = ENTITY_INVOICE)
@ -646,12 +646,12 @@ class Account extends Eloquent
public function getNextInvoiceNumber($invoice) public function getNextInvoiceNumber($invoice)
{ {
if ($this->hasNumberPattern($invoice->is_quote)) { if ($this->hasNumberPattern($invoice->invoice_type_id)) {
return $this->getNumberPattern($invoice); return $this->getNumberPattern($invoice);
} }
$counter = $this->getCounter($invoice->is_quote); $counter = $this->getCounter($invoice->invoice_type_id);
$prefix = $this->getNumberPrefix($invoice->is_quote); $prefix = $this->getNumberPrefix($invoice->invoice_type_id);
$counterOffset = 0; $counterOffset = 0;
// confirm the invoice number isn't already taken // confirm the invoice number isn't already taken
@ -664,7 +664,7 @@ class Account extends Eloquent
// update the invoice counter to be caught up // update the invoice counter to be caught up
if ($counterOffset > 1) { 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; $this->quote_number_counter += $counterOffset - 1;
} else { } else {
$this->invoice_number_counter += $counterOffset - 1; $this->invoice_number_counter += $counterOffset - 1;
@ -678,7 +678,7 @@ class Account extends Eloquent
public function incrementCounter($invoice) 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; $this->quote_number_counter += 1;
} else { } else {
$default = $this->invoice_number_counter; $default = $this->invoice_number_counter;
@ -1102,7 +1102,7 @@ class Account extends Eloquent
'invoice_items', 'invoice_items',
'created_at', 'created_at',
'is_recurring', 'is_recurring',
'is_quote', 'invoice_type_id',
]); ]);
foreach ($invoice->invoice_items as $invoiceItem) { foreach ($invoice->invoice_items as $invoiceItem) {

View File

@ -96,7 +96,7 @@ class Invoice extends EntityModel implements BalanceAffecting
public function affectsBalance() public function affectsBalance()
{ {
return !$this->is_quote && !$this->is_recurring; return $this->isType(INVOICE_TYPE_STANDARD) && !$this->is_recurring;
} }
public function getAdjustment() public function getAdjustment()
@ -139,7 +139,7 @@ class Invoice extends EntityModel implements BalanceAffecting
public function getAmountPaid($calculate = false) public function getAmountPaid($calculate = false)
{ {
if ($this->is_quote || $this->is_recurring) { if ($this->isType(INVOICE_TYPE_QUOTE) || $this->is_recurring) {
return 0; return 0;
} }
@ -230,10 +230,19 @@ class Invoice extends EntityModel implements BalanceAffecting
public function scopeInvoices($query) public function scopeInvoices($query)
{ {
return $query->where('is_quote', '=', false) return $query->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('is_recurring', '=', false); ->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) public function markInvitationsSent($notify = false)
{ {
foreach ($this->invitations as $invitation) { foreach ($this->invitations as $invitation) {
@ -256,7 +265,7 @@ class Invoice extends EntityModel implements BalanceAffecting
return; return;
} }
if ($this->is_quote) { if ($this->isType(INVOICE_TYPE_QUOTE)) {
event(new QuoteInvitationWasEmailed($invitation)); event(new QuoteInvitationWasEmailed($invitation));
} else { } else {
event(new InvoiceInvitationWasEmailed($invitation)); event(new InvoiceInvitationWasEmailed($invitation));
@ -292,7 +301,7 @@ class Invoice extends EntityModel implements BalanceAffecting
public function markApproved() public function markApproved()
{ {
if ($this->is_quote) { if ($this->isType(INVOICE_TYPE_QUOTE)) {
$this->invoice_status_id = INVOICE_STATUS_APPROVED; $this->invoice_status_id = INVOICE_STATUS_APPROVED;
$this->save(); $this->save();
} }
@ -341,7 +350,7 @@ class Invoice extends EntityModel implements BalanceAffecting
public function getEntityType() public function getEntityType()
{ {
return $this->is_quote ? ENTITY_QUOTE : ENTITY_INVOICE; return $this->isType(INVOICE_TYPE_QUOTE) ? ENTITY_QUOTE : ENTITY_INVOICE;
} }
public function isSent() public function isSent()
@ -416,7 +425,7 @@ class Invoice extends EntityModel implements BalanceAffecting
'invoice_design_id', 'invoice_design_id',
'invoice_fonts', 'invoice_fonts',
'features', 'features',
'is_quote', 'invoice_type_id',
'custom_value1', 'custom_value1',
'custom_value2', 'custom_value2',
'custom_taxes1', 'custom_taxes1',
@ -943,7 +952,7 @@ Invoice::creating(function ($invoice) {
}); });
Invoice::created(function ($invoice) { Invoice::created(function ($invoice) {
if ($invoice->is_quote) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
event(new QuoteWasCreated($invoice)); event(new QuoteWasCreated($invoice));
} else { } else {
event(new InvoiceWasCreated($invoice)); event(new InvoiceWasCreated($invoice));
@ -951,7 +960,7 @@ Invoice::created(function ($invoice) {
}); });
Invoice::updating(function ($invoice) { Invoice::updating(function ($invoice) {
if ($invoice->is_quote) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
event(new QuoteWasUpdated($invoice)); event(new QuoteWasUpdated($invoice));
} else { } else {
event(new InvoiceWasUpdated($invoice)); event(new InvoiceWasUpdated($invoice));

View File

@ -96,7 +96,7 @@ class ContactMailer extends Mailer
$account->loadLocalizationSettings(); $account->loadLocalizationSettings();
if ($sent === true) { if ($sent === true) {
if ($invoice->is_quote) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) {
event(new QuoteWasEmailed($invoice)); event(new QuoteWasEmailed($invoice));
} else { } else {
event(new InvoiceWasEmailed($invoice)); event(new InvoiceWasEmailed($invoice));

View File

@ -19,7 +19,7 @@ class InvoicePresenter extends EntityPresenter {
{ {
if ($this->entity->partial > 0) { if ($this->entity->partial > 0) {
return 'partial_due'; return 'partial_due';
} elseif ($this->entity->is_quote) { } elseif ($this->entity->isType(INVOICE_TYPE_QUOTE)) {
return 'total'; return 'total';
} else { } else {
return 'balance_due'; return 'balance_due';

View File

@ -32,9 +32,9 @@ class InvoiceRepository extends BaseRepository
public function all() public function all()
{ {
return Invoice::scope() return Invoice::scope()
->invoiceType(INVOICE_TYPE_STANDARD)
->with('user', 'client.contacts', 'invoice_status') ->with('user', 'client.contacts', 'invoice_status')
->withTrashed() ->withTrashed()
->where('is_quote', '=', false)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->get(); ->get();
} }
@ -106,7 +106,7 @@ class InvoiceRepository extends BaseRepository
->join('frequencies', 'frequencies.id', '=', 'invoices.frequency_id') ->join('frequencies', 'frequencies.id', '=', 'invoices.frequency_id')
->join('contacts', 'contacts.client_id', '=', 'clients.id') ->join('contacts', 'contacts.client_id', '=', 'clients.id')
->where('invoices.account_id', '=', $accountId) ->where('invoices.account_id', '=', $accountId)
->where('invoices.is_quote', '=', false) ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('contacts.deleted_at', '=', null) ->where('contacts.deleted_at', '=', null)
->where('invoices.is_recurring', '=', true) ->where('invoices.is_recurring', '=', true)
->where('contacts.is_primary', '=', true) ->where('contacts.is_primary', '=', true)
@ -156,7 +156,7 @@ class InvoiceRepository extends BaseRepository
->join('frequencies', 'frequencies.id', '=', 'invoices.frequency_id') ->join('frequencies', 'frequencies.id', '=', 'invoices.frequency_id')
->where('invitations.contact_id', '=', $contactId) ->where('invitations.contact_id', '=', $contactId)
->where('invitations.deleted_at', '=', null) ->where('invitations.deleted_at', '=', null)
->where('invoices.is_quote', '=', false) ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('invoices.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false)
->where('clients.deleted_at', '=', null) ->where('clients.deleted_at', '=', null)
->where('invoices.is_recurring', '=', true) ->where('invoices.is_recurring', '=', true)
@ -203,7 +203,7 @@ class InvoiceRepository extends BaseRepository
->join('contacts', 'contacts.client_id', '=', 'clients.id') ->join('contacts', 'contacts.client_id', '=', 'clients.id')
->where('invitations.contact_id', '=', $contactId) ->where('invitations.contact_id', '=', $contactId)
->where('invitations.deleted_at', '=', null) ->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('invoices.is_deleted', '=', false)
->where('clients.deleted_at', '=', null) ->where('clients.deleted_at', '=', null)
->where('contacts.deleted_at', '=', null) ->where('contacts.deleted_at', '=', null)
@ -642,7 +642,7 @@ class InvoiceRepository extends BaseRepository
'tax_name2', 'tax_name2',
'tax_rate2', 'tax_rate2',
'amount', 'amount',
'is_quote', 'invoice_type_id',
'custom_value1', 'custom_value1',
'custom_value2', 'custom_value2',
'custom_taxes1', 'custom_taxes1',
@ -654,7 +654,7 @@ class InvoiceRepository extends BaseRepository
} }
if ($quotePublicId) { if ($quotePublicId) {
$clone->is_quote = false; $clone->invoice_type_id = INVOICE_TYPE_STANDARD;
$clone->quote_id = $quotePublicId; $clone->quote_id = $quotePublicId;
} }
@ -838,9 +838,9 @@ class InvoiceRepository extends BaseRepository
} }
$sql = implode(' OR ', $dates); $sql = implode(' OR ', $dates);
$invoices = Invoice::whereAccountId($account->id) $invoices = Invoice::invoiceType(INVOICE_TYPE_STANDARD)
->whereAccountId($account->id)
->where('balance', '>', 0) ->where('balance', '>', 0)
->where('is_quote', '=', false)
->where('is_recurring', '=', false) ->where('is_recurring', '=', false)
->whereRaw('('.$sql.')') ->whereRaw('('.$sql.')')
->get(); ->get();

View File

@ -93,7 +93,7 @@ class InvoiceTransformer extends EntityTransformer
'terms' => $invoice->terms, 'terms' => $invoice->terms,
'public_notes' => $invoice->public_notes, 'public_notes' => $invoice->public_notes,
'is_deleted' => (bool) $invoice->is_deleted, '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, 'is_recurring' => (bool) $invoice->is_recurring,
'frequency_id' => (int) $invoice->frequency_id, 'frequency_id' => (int) $invoice->frequency_id,
'start_date' => $invoice->start_date, 'start_date' => $invoice->start_date,

View File

@ -94,7 +94,7 @@ class InvoiceService extends BaseService
{ {
$account = $quote->account; $account = $quote->account;
if (!$quote->is_quote || $quote->quote_invoice_id) { if (!$quote->isType(INVOICE_TYPE_QUOTE) || $quote->quote_invoice_id) {
return null; return null;
} }
@ -121,7 +121,7 @@ class InvoiceService extends BaseService
{ {
$datatable = new InvoiceDatatable( ! $clientPublicId, $clientPublicId); $datatable = new InvoiceDatatable( ! $clientPublicId, $clientPublicId);
$query = $this->invoiceRepo->getInvoices($accountId, $clientPublicId, $entityType, $search) $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')){ if(!Utils::hasPermission('view_all')){
$query->where('invoices.user_id', '=', Auth::user()->id); $query->where('invoices.user_id', '=', Auth::user()->id);

View File

@ -132,7 +132,7 @@ class PushService
*/ */
private function entitySentMessage($invoice) 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]); return trans("texts.notification_quote_sent_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]);
else else
return trans("texts.notification_invoice_sent_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]); 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) 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]); return trans("texts.notification_quote_viewed_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]);
else else
return trans("texts.notification_invoice_viewed_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]); return trans("texts.notification_invoice_viewed_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->name]);

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddInvoiceTypeSupport extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('invoices', function ($table) {
$table->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');
});
}
}

View File

@ -150,7 +150,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($upcoming as $invoice) @foreach ($upcoming as $invoice)
@if (!$invoice->is_quote) @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr> <tr>
<td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td> <td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td>
@can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id]) @can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id])
@ -185,7 +185,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($pastDue as $invoice) @foreach ($pastDue as $invoice)
@if (!$invoice->is_quote) @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr> <tr>
<td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td> <td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td>
@can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id]) @can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id])
@ -224,7 +224,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($upcoming as $invoice) @foreach ($upcoming as $invoice)
@if ($invoice->is_quote) @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr> <tr>
<td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td> <td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td>
<td>{!! link_to('/clients/'.$invoice->client_public_id, trim($invoice->client_name) ?: (trim($invoice->first_name . ' ' . $invoice->last_name) ?: $invoice->email)) !!}</td> <td>{!! link_to('/clients/'.$invoice->client_public_id, trim($invoice->client_name) ?: (trim($invoice->first_name . ' ' . $invoice->last_name) ?: $invoice->email)) !!}</td>
@ -255,7 +255,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach ($pastDue as $invoice) @foreach ($pastDue as $invoice)
@if ($invoice->is_quote) @if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr> <tr>
<td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td> <td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td>
<td>{!! link_to('/clients/'.$invoice->client_public_id, trim($invoice->client_name) ?: (trim($invoice->first_name . ' ' . $invoice->last_name) ?: $invoice->email)) !!}</td> <td>{!! link_to('/clients/'.$invoice->client_public_id, trim($invoice->client_name) ?: (trim($invoice->first_name . ' ' . $invoice->last_name) ?: $invoice->email)) !!}</td>