Merge pull request #7112 from turbo124/v5-develop

Fixes for project filters
This commit is contained in:
David Bomba 2022-01-11 09:31:36 +11:00 committed by GitHub
commit 6a1942be08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 124 additions and 32 deletions

View File

@ -112,7 +112,8 @@ class PaymentTermFilters extends QueryFilters
*/ */
public function entityFilter() public function entityFilter()
{ {
return $this->builder->company();
//return $this->builder->whereCompanyId(auth()->user()->company()->id); //return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null); // return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
} }
} }

View File

@ -107,7 +107,6 @@ class ProjectFilters extends QueryFilters
$query = DB::table('projects') $query = DB::table('projects')
->join('companies', 'companies.id', '=', 'projects.company_id') ->join('companies', 'companies.id', '=', 'projects.company_id')
->where('projects.company_id', '=', $company_id) ->where('projects.company_id', '=', $company_id)
//->whereRaw('(projects.name != "" or contacts.first_name != "" or contacts.last_name != "" or contacts.email != "")') // filter out buy now invoices
->select( ->select(
'projects.id', 'projects.id',
'projects.name', 'projects.name',
@ -140,6 +139,8 @@ class ProjectFilters extends QueryFilters
public function entityFilter() public function entityFilter()
{ {
//return $this->builder->whereCompanyId(auth()->user()->company()->id); //return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null); // return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
return $this->builder->company();
} }
} }

View File

@ -88,6 +88,8 @@ abstract class QueryFilters
} }
} }
// nlog('[Search] SQL: ' . $this->builder->toSql() . " Bindings: " . implode(', ', $this->builder->getBindings()));
return $this->builder->withTrashed(); return $this->builder->withTrashed();
} }

View File

@ -58,7 +58,7 @@ class RecurringExpenseFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
$table = 'expenses'; $table = 'recurring_expenses';
$filters = explode(',', $filter); $filters = explode(',', $filter);
return $this->builder->where(function ($query) use ($filters, $table) { return $this->builder->where(function ($query) use ($filters, $table) {

View File

@ -53,7 +53,7 @@ class RecurringInvoiceFilters extends QueryFilters
return $this->builder; return $this->builder;
} }
$table = 'recurring_'; $table = 'recurring_invoices';
$filters = explode(',', $filter); $filters = explode(',', $filter);
return $this->builder->where(function ($query) use ($filters, $table) { return $this->builder->where(function ($query) use ($filters, $table) {

View File

@ -22,6 +22,7 @@ use App\Utils\Traits\AppSetup;
use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str;
use League\Fractal\Manager; use League\Fractal\Manager;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection; use League\Fractal\Resource\Collection;
@ -619,7 +620,9 @@ class BaseController extends Controller
$query->with($includes); $query->with($includes);
if (auth()->user() && ! auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) { // 10-01-2022 need to ensure we snake case properly here to ensure permissions work as expected
// if (auth()->user() && ! auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) {
if (auth()->user() && ! auth()->user()->hasPermission('view'.lcfirst(class_basename(Str::snake($this->entity_type))))) {
$query->where('user_id', '=', auth()->user()->id); $query->where('user_id', '=', auth()->user()->id);
} }

View File

@ -401,7 +401,7 @@ class InvoiceController extends BaseController
$invoice = $this->invoice_repo->save($request->all(), $invoice); $invoice = $this->invoice_repo->save($request->all(), $invoice);
$invoice->service()->triggeredActions($request)->deletePdf(); $invoice->service()->triggeredActions($request)->deletePdf()->touchPdf();
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
@ -708,7 +708,7 @@ class InvoiceController extends BaseController
} }
break; break;
case 'cancel': case 'cancel':
$invoice = $invoice->service()->handleCancellation()->deletePdf()->save(); $invoice = $invoice->service()->handleCancellation()->deletePdf()->touchPdf()->save();
if (! $bulk) { if (! $bulk) {
$this->itemResponse($invoice); $this->itemResponse($invoice);

View File

@ -95,7 +95,7 @@ class SendRecurring implements ShouldQueue
$invoice = $this->createRecurringInvitations($invoice); $invoice = $this->createRecurringInvitations($invoice);
/* 09-01-2022 ensure we create the PDFs at this point in time! */ /* 09-01-2022 ensure we create the PDFs at this point in time! */
$invoice->service()->touchPdf(); $invoice->service()->touchPdf(true);
nlog("updating recurring invoice dates"); nlog("updating recurring invoice dates");
/* Set next date here to prevent a recurring loop forming */ /* Set next date here to prevent a recurring loop forming */

View File

@ -80,6 +80,8 @@ class ReminderJob implements ShouldQueue
$invoice->service()->touchReminder($reminder_template)->save(); $invoice->service()->touchReminder($reminder_template)->save();
$invoice = $this->calcLateFee($invoice, $reminder_template); $invoice = $this->calcLateFee($invoice, $reminder_template);
$invoice->service()->touchPdf();
//check if this reminder needs to be emailed //check if this reminder needs to be emailed
if(in_array($reminder_template, ['reminder1','reminder2','reminder3','reminder_endless']) && $invoice->client->getSetting("enable_".$reminder_template)) if(in_array($reminder_template, ['reminder1','reminder2','reminder3','reminder_endless']) && $invoice->client->getSetting("enable_".$reminder_template))
{ {

View File

@ -43,7 +43,7 @@ class InvoiceArchivedActivity implements ShouldQueue
{ {
MultiDB::setDb($event->company->db); MultiDB::setDb($event->company->db);
$event->invoice->service()->deletePdf(); // $event->invoice->service()->deletePdf();
$fields = new stdClass; $fields = new stdClass;

View File

@ -195,7 +195,10 @@ class BaseModel extends Model
// Remove any runs of periods (thanks falstro!) // Remove any runs of periods (thanks falstro!)
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number); $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
$formatted_number = str_replace(" ", "_", $formatted_number); // $formatted_number = str_replace(" ", "_", $formatted_number);
//11-01-2021 fixes for multiple spaces
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
return $formatted_number; return $formatted_number;
} }

View File

@ -442,7 +442,7 @@ class BaseDriver extends AbstractPaymentDriver
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
$invoice->service()->deletePdf(); $invoice->service()->touchPdf();
}); });
@ -494,7 +494,7 @@ class BaseDriver extends AbstractPaymentDriver
$invoices->each(function ($invoice){ $invoices->each(function ($invoice){
$invoice->service()->deletePdf(); $invoice->service()->touchPdf();
}); });

View File

@ -234,6 +234,15 @@ class GoCardlessPaymentDriver extends BaseDriver
$this->init(); $this->init();
if(!is_array($request->events) || !is_object($request->events)){
nlog("No GoCardless events to process in response?");
return response()->json([], 200);
}
foreach ($request->events as $event) { foreach ($request->events as $event) {
if ($event['action'] === 'confirmed') { if ($event['action'] === 'confirmed') {
$payment = Payment::query() $payment = Payment::query()

View File

@ -321,7 +321,7 @@ class MolliePaymentDriver extends BaseDriver
// we may not have a payment record - in these cases we need to re-construct the payment // we may not have a payment record - in these cases we need to re-construct the payment
// record from the meta data in the payment hash. // record from the meta data in the payment hash.
if($payment && property_exists($payment->metadata, 'payment_hash') && $payment->metadata->payment_hash){ if($payment && property_exists($payment->metadata, 'hash') && $payment->metadata->hash){
/* Harvest Payment Hash*/ /* Harvest Payment Hash*/
$payment_hash = PaymentHash::where('hash', $payment->metadata->hash)->first(); $payment_hash = PaymentHash::where('hash', $payment->metadata->hash)->first();

View File

@ -194,13 +194,18 @@ class BrowserPay implements MethodInterface
return; return;
} }
$domain = config('ninja.app_url'); // $domain = config('ninja.app_url');
if (Ninja::isHosted()) { // if (Ninja::isHosted()) {
$domain = isset($this->stripe->company_gateway->company->portal_domain) // $domain = isset($this->stripe->company_gateway->company->portal_domain)
? $this->stripe->company_gateway->company->portal_domain // ? $this->stripe->company_gateway->company->portal_domain
: $this->stripe->company_gateway->company->domain(); // : $this->stripe->company_gateway->company->domain();
} // }
$domain = $this->getAppleDomain();
if(!$domain)
throw new PaymentFailed('Unable to register Domain with Apple Pay', 500);
$response = ApplePayDomain::create([ $response = ApplePayDomain::create([
'domain_name' => $domain, 'domain_name' => $domain,
@ -212,4 +217,36 @@ class BrowserPay implements MethodInterface
$this->stripe->company_gateway->save(); $this->stripe->company_gateway->save();
} }
private function getAppleDomain()
{
$domain = '';
if(Ninja::isHosted())
{
if($this->company_gateway->company->portal_mode == 'domain'){
$domain = $this->company_gateway->company->portal_domain;
}
else{
$domain = $this->company_gateway->company->subdomain . '.' . config('ninja.app_domain');
}
}
else {
$domain = config('ninja.app_url');
}
$parsed_url = parse_url($domain);
if(array_key_exists('host', $parsed_url))
return $parsed_url['host'];
return false;
}
} }

View File

@ -390,6 +390,8 @@ class InvoiceService
*/ */
public function touchPdf($force = false) public function touchPdf($force = false)
{ {
try {
if($force){ if($force){
$this->invoice->invitations->each(function ($invitation) { $this->invoice->invitations->each(function ($invitation) {
@ -403,6 +405,13 @@ class InvoiceService
CreateEntityPdf::dispatch($invitation); CreateEntityPdf::dispatch($invitation);
}); });
}
catch(\Exception $e){
nlog("failed creating invoices in Touch PDF");
}
return $this; return $this;
} }

View File

@ -89,6 +89,7 @@ class MarkPaid extends AbstractService
->service() ->service()
->applyNumber() ->applyNumber()
->deletePdf() ->deletePdf()
->touchPdf()
->save(); ->save();
$payment->ledger() $payment->ledger()

View File

@ -87,7 +87,7 @@ class UpdateInvoicePayment
$invoice->refresh(); $invoice->refresh();
$invoice->service() $invoice->service()
->deletePdf() ->touchPdf(true)
->workFlow() ->workFlow()
->save(); ->save();

View File

@ -214,7 +214,7 @@ trait ClientGroupSettingsSaver
case 'double': case 'double':
return is_float($value) || is_numeric(strval($value)); return is_float($value) || is_numeric(strval($value));
case 'string': case 'string':
return method_exists($value, '__toString') || is_null($value) || is_string($value); return ( is_string( $value ) && method_exists($value, '__toString') ) || is_null($value) || is_string($value);
case 'bool': case 'bool':
case 'boolean': case 'boolean':
return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN);

View File

@ -61,7 +61,7 @@ trait CompanyGatewayFeesAndLimitsSaver
case 'double': case 'double':
return is_float($value) || is_numeric(strval($value)); return is_float($value) || is_numeric(strval($value));
case 'string': case 'string':
return method_exists($value, '__toString') || is_null($value) || is_string($value); return ( is_string( $value ) && method_exists($value, '__toString') ) || is_null($value) || is_string($value);
case 'bool': case 'bool':
case 'boolean': case 'boolean':
return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN);

View File

@ -232,7 +232,6 @@ trait CompanySettingsSaver
return is_float($value) || is_numeric(strval($value)); return is_float($value) || is_numeric(strval($value));
case 'string': case 'string':
return (is_string($value) && method_exists($value, '__toString')) || is_null($value) || is_string($value); return (is_string($value) && method_exists($value, '__toString')) || is_null($value) || is_string($value);
//return is_null($value) || is_string($value);
case 'bool': case 'bool':
case 'boolean': case 'boolean':
return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN);

View File

@ -94,7 +94,7 @@ trait SettingsSaver
case 'double': case 'double':
return is_float($value) || is_numeric(strval($value)); return is_float($value) || is_numeric(strval($value));
case 'string': case 'string':
return method_exists($value, '__toString') || is_null($value) || is_string($value); return !is_int($value) || ( is_string( $value ) && method_exists($value, '__toString') ) || is_null($value) || is_string($value);
case 'bool': case 'bool':
case 'boolean': case 'boolean':
return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); return is_bool($value) || (int) filter_var($value, FILTER_VALIDATE_BOOLEAN);

View File

@ -84,10 +84,35 @@ class ProjectApiTest extends TestCase
$response->assertStatus(302); $response->assertStatus(302);
} }
}
public function testProjectPostFilters()
{
$data = [
'name' => "Sherlock",
'client_id' => $this->client->hashed_id,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/projects', $data);
$response->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/projects?filter=Sherlock');
$arr = $response->json();
$this->assertEquals(1, count($arr['data']));
} }
public function testProjectPut() public function testProjectPut()
{ {
$data = [ $data = [