1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Merge pull request #878 from benb969/invoices_types

add support to multiple invoice types
This commit is contained in:
Hillel Coren 2016-05-29 12:21:57 +03:00
commit cca6dcfc4a
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'));
} 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;

View File

@ -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();

View File

@ -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

View File

@ -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));

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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',

View File

@ -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();
}]);

View File

@ -359,6 +359,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');

View File

@ -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) {

View File

@ -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));

View File

@ -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));

View File

@ -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';

View File

@ -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();

View File

@ -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,

View File

@ -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);

View File

@ -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]);

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>
<tbody>
@foreach ($upcoming as $invoice)
@if (!$invoice->is_quote)
@if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr>
<td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td>
@can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id])
@ -185,7 +185,7 @@
</thead>
<tbody>
@foreach ($pastDue as $invoice)
@if (!$invoice->is_quote)
@if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr>
<td>{!! \App\Models\Invoice::calcLink($invoice) !!}</td>
@can('viewByOwner', [ENTITY_CLIENT, $invoice->client_user_id])
@ -224,7 +224,7 @@
</thead>
<tbody>
@foreach ($upcoming as $invoice)
@if ($invoice->is_quote)
@if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr>
<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>
@ -255,7 +255,7 @@
</thead>
<tbody>
@foreach ($pastDue as $invoice)
@if ($invoice->is_quote)
@if ($invoice->invoice_type_id == INVOICE_TYPE_STANDARD)
<tr>
<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>