mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge pull request #8449 from turbo124/v5-develop
Updates for design filters
This commit is contained in:
commit
3b15a4f45e
@ -68,7 +68,7 @@ class TaxModel
|
||||
$this->regions->AU = new \stdClass();
|
||||
$this->regions->AU->has_sales_above_threshold = false;
|
||||
$this->regions->AU->tax_all_subregions = false;
|
||||
$this->regions->AU->vat_threshold = 75000;
|
||||
$this->regions->AU->tax_threshold = 75000;
|
||||
$this->auSubRegions();
|
||||
|
||||
return $this;
|
||||
@ -115,7 +115,7 @@ class TaxModel
|
||||
|
||||
$this->regions->EU->has_sales_above_threshold = false;
|
||||
$this->regions->EU->tax_all_subregions = false;
|
||||
$this->regions->EU->vat_threshold = 10000;
|
||||
$this->regions->EU->tax_threshold = 10000;
|
||||
$this->euSubRegions();
|
||||
|
||||
return $this;
|
||||
|
@ -106,7 +106,7 @@ region:
|
||||
apply_tax: false
|
||||
EU:
|
||||
tax_all: false
|
||||
vat_threshold: 10000
|
||||
tax_threshold: 10000
|
||||
has_sales_above_threshold: false
|
||||
subregions:
|
||||
AT:
|
||||
|
@ -24,7 +24,6 @@ class DesignFilters extends QueryFilters
|
||||
* @param string $filter
|
||||
* @return Builder
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
@ -33,7 +32,7 @@ class DesignFilters extends QueryFilters
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('designs.name', 'like', '%'.$filter.'%');
|
||||
$query->where('name', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,17 +57,22 @@ class DesignFilters extends QueryFilters
|
||||
/**
|
||||
* Filters the query by the users company ID.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return Builder
|
||||
*/
|
||||
public function entityFilter(): Builder
|
||||
{
|
||||
return $this->builder->where('company_id', auth()->user()->company()->id)->orWhere('company_id', null)->orderBy('id', 'asc');
|
||||
//19-03-2023 change the scope for the design filters
|
||||
return $this->builder->where(function ($query) {
|
||||
$query->where('company_id', auth()->user()->company()->id)->orWhere('company_id', null)->orderBy('id', 'asc');
|
||||
// return $this->builder->where('company_id', auth()->user()->company()->id)->orWhere('company_id', null)->orderBy('id', 'asc');
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the designs by `is_custom` column.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return Builder
|
||||
*/
|
||||
public function custom(string $custom): Builder
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ class InvoiceFilters extends QueryFilters
|
||||
* - overdue
|
||||
* - reversed
|
||||
*
|
||||
* @param string client_status The invoice status as seen by the client
|
||||
* @param string $value The invoice status as seen by the client
|
||||
* @return Builder
|
||||
*/
|
||||
public function client_status(string $value = ''): Builder
|
||||
@ -88,7 +88,7 @@ class InvoiceFilters extends QueryFilters
|
||||
/**
|
||||
* Filter based on search text.
|
||||
*
|
||||
* @param string query filter
|
||||
* @param string $filter
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
@ -126,6 +126,7 @@ class InvoiceFilters extends QueryFilters
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
* @return Builder
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@ -141,6 +142,7 @@ class InvoiceFilters extends QueryFilters
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @return Builder
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function overdue(): Builder
|
||||
@ -174,7 +176,7 @@ class InvoiceFilters extends QueryFilters
|
||||
/**
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
* @param string $sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort = ''): Builder
|
||||
@ -194,9 +196,9 @@ class InvoiceFilters extends QueryFilters
|
||||
* We need to ensure we are using the correct company ID
|
||||
* as we could be hitting this from either the client or company auth guard
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder
|
||||
* @return Builder
|
||||
*/
|
||||
public function entityFilter()
|
||||
public function entityFilter(): Builder
|
||||
{
|
||||
if (auth()->guard('contact')->user()) {
|
||||
return $this->contactViewFilter();
|
||||
@ -210,7 +212,7 @@ class InvoiceFilters extends QueryFilters
|
||||
* @return Builder
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function private_notes($filter = '') :Builder
|
||||
public function private_notes($filter = ''): Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
|
@ -23,9 +23,8 @@ class ProductFilters extends QueryFilters
|
||||
/**
|
||||
* Filter based on search text.
|
||||
*
|
||||
* @param string query filter
|
||||
* @param string $filter
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = ''): Builder
|
||||
{
|
||||
@ -55,7 +54,7 @@ class ProductFilters extends QueryFilters
|
||||
/**
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
* @param string $sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort = ''): Builder
|
||||
@ -72,9 +71,9 @@ class ProductFilters extends QueryFilters
|
||||
/**
|
||||
* Filters the query by the users company ID.
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder
|
||||
* @return Builder
|
||||
*/
|
||||
public function entityFilter()
|
||||
public function entityFilter(): Builder
|
||||
{
|
||||
return $this->builder->company();
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ abstract class QueryFilters
|
||||
* Explodes the value by delimiter.
|
||||
*
|
||||
* @param string $value
|
||||
* @return stdClass
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function split($value) : \stdClass
|
||||
{
|
||||
@ -133,7 +133,7 @@ abstract class QueryFilters
|
||||
* Filters the list based on the status
|
||||
* archived, active, deleted.
|
||||
*
|
||||
* @param string filter
|
||||
* @param string $filter
|
||||
* @return Builder
|
||||
*/
|
||||
public function status(string $filter = ''): Builder
|
||||
@ -196,13 +196,15 @@ abstract class QueryFilters
|
||||
*
|
||||
* -Can only be used on contact routes
|
||||
*
|
||||
* @return
|
||||
* @return Builder
|
||||
*/
|
||||
public function clientFilter()
|
||||
public function clientFilter(): Builder
|
||||
{
|
||||
if (auth()->guard('contact')->user()) {
|
||||
return $this->builder->where('client_id', auth()->guard('contact')->user()->client->id);
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
public function created_at($value = '')
|
||||
@ -244,7 +246,7 @@ abstract class QueryFilters
|
||||
}
|
||||
|
||||
|
||||
public function is_deleted($value)
|
||||
public function is_deleted($value = 'true')
|
||||
{
|
||||
if ($value == 'true') {
|
||||
return $this->builder->where('is_deleted', $value)->withTrashed();
|
||||
|
@ -23,7 +23,7 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
/**
|
||||
* Filter based on search text.
|
||||
*
|
||||
* @param string query filter
|
||||
* @param string $filter
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
@ -50,7 +50,7 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
* - paused
|
||||
* - completed
|
||||
*
|
||||
* @param string client_status The invoice status as seen by the client
|
||||
* @param string $value The invoice status as seen by the client
|
||||
* @return Builder
|
||||
*/
|
||||
public function client_status(string $value = ''): Builder
|
||||
@ -99,7 +99,7 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
/**
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
* @param string $sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort = ''): Builder
|
||||
@ -116,9 +116,9 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
/**
|
||||
* Filters the query by the users company ID.
|
||||
*
|
||||
* @return Illuminate\Eloquent\Builder
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function entityFilter()
|
||||
public function entityFilter(): Builder
|
||||
{
|
||||
return $this->builder->company();
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ class InvoiceItemSum
|
||||
|
||||
private function shouldCalculateTax(): self
|
||||
{
|
||||
if (!$this->invoice->company->calculate_taxes) {
|
||||
if (!$this->invoice->company?->calculate_taxes) {
|
||||
$this->calc_tax = false;
|
||||
return $this;
|
||||
}
|
||||
|
@ -11,13 +11,14 @@
|
||||
|
||||
namespace App\Jobs\Cron;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Invoice;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use App\Jobs\Entity\EmailEntity;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AutoBill implements ShouldQueue
|
||||
{
|
||||
@ -25,19 +26,13 @@ class AutoBill implements ShouldQueue
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public int $invoice_id;
|
||||
|
||||
public string $db;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $invoice_id, ?string $db)
|
||||
public function __construct(public int $invoice_id, public ?string $db, public bool $send_email_on_failure = false)
|
||||
{
|
||||
$this->invoice_id = $invoice_id;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,6 +56,24 @@ class AutoBill implements ShouldQueue
|
||||
$invoice->service()->autoBill();
|
||||
} catch (\Exception $e) {
|
||||
nlog("Failed to capture payment for {$this->invoice_id} ->".$e->getMessage());
|
||||
|
||||
if($this->send_email_on_failure)
|
||||
{
|
||||
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice) {
|
||||
if ($invitation->contact && ! $invitation->contact->trashed() && strlen($invitation->contact->email) >= 1 && $invoice->client->getSetting('auto_email_invoice')) {
|
||||
try {
|
||||
EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(1, 2));
|
||||
} catch (\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
nlog("Firing email for invoice {$invoice->number}");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +84,13 @@ class SendRecurring implements ShouldQueue
|
||||
}
|
||||
|
||||
//12-01-2023 i moved this block after fillDefaults to handle if standard invoice auto bill config has been enabled, recurring invoice should override.
|
||||
if ($this->recurring_invoice->auto_bill === 'always') {
|
||||
if ($this->recurring_invoice->auto_bill == 'always') {
|
||||
$invoice->auto_bill_enabled = true;
|
||||
} elseif ($this->recurring_invoice->auto_bill === 'optout' || $this->recurring_invoice->auto_bill === 'optin') {
|
||||
} elseif ($this->recurring_invoice->auto_bill === 'off') {
|
||||
$invoice->saveQuietly();
|
||||
} elseif ($this->recurring_invoice->auto_bill == 'optout' || $this->recurring_invoice->auto_bill == 'optin') {
|
||||
} elseif ($this->recurring_invoice->auto_bill == 'off') {
|
||||
$invoice->auto_bill_enabled = false;
|
||||
$invoice->saveQuietly();
|
||||
}
|
||||
|
||||
$invoice = $this->createRecurringInvitations($invoice);
|
||||
@ -111,7 +113,16 @@ class SendRecurring implements ShouldQueue
|
||||
|
||||
event('eloquent.created: App\Models\Invoice', $invoice);
|
||||
|
||||
if ($invoice->client->getSetting('auto_email_invoice')) {
|
||||
//auto bill, BUT NOT DRAFTS!!
|
||||
if ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->client->getSetting('auto_email_invoice')) {
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db, true)->delay(rand(1, 2));
|
||||
}
|
||||
elseif ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->client->getSetting('auto_email_invoice') && ($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay()))) {
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db, true)->delay(rand(1, 2));
|
||||
}
|
||||
elseif ($invoice->client->getSetting('auto_email_invoice')) {
|
||||
//Admin notification for recurring invoice sent.
|
||||
if ($invoice->invitations->count() >= 1) {
|
||||
$invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice');
|
||||
@ -130,16 +141,7 @@ class SendRecurring implements ShouldQueue
|
||||
});
|
||||
}
|
||||
|
||||
//auto bill, BUT NOT DRAFTS!!
|
||||
if ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->client->getSetting('auto_email_invoice')) {
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2));
|
||||
} elseif ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->client->getSetting('auto_email_invoice')) {
|
||||
if ($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay())) {
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -873,6 +873,7 @@ class Company extends BaseModel
|
||||
'convert_expense_currency',
|
||||
'notify_vendor_when_paid',
|
||||
'calculate_taxes',
|
||||
'tax_data',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
@ -103,7 +103,7 @@ class ExpenseRepository extends BaseRepository
|
||||
public function delete($expense) :Expense
|
||||
{
|
||||
|
||||
if ($expense->transaction_id) {
|
||||
if ($expense->transaction()->exists()) {
|
||||
|
||||
$exp_ids = collect(explode(',', $expense->transaction->expense_id))->filter(function ($id) use ($expense) {
|
||||
return $id != $expense->hashed_id;
|
||||
|
@ -63,7 +63,7 @@ class PdfMock
|
||||
$pdf_config->entity_design_id = $pdf_config->settings->{"{$pdf_config->entity_string}_design_id"};
|
||||
$pdf_config->setPdfVariables();
|
||||
$pdf_config->setCurrency(Currency::find($this->settings->currency_id));
|
||||
$pdf_config->setCountry(Country::find($this->settings->country_id));
|
||||
$pdf_config->setCountry(Country::find($this->settings->country_id ?: 840));
|
||||
$pdf_config->design = Design::find($this->decodePrimaryKey($pdf_config->entity_design_id));
|
||||
$pdf_config->currency_entity = $this->mock->client;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user