mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for tests (#3184)
* fix typo * php-cs traits * CS fixer pass * Password protect User routes * Implement checks to prevent editing a deleted record * Clean up payment flows * Fixes for tests
This commit is contained in:
parent
167b503fa1
commit
f712b789ca
@ -51,8 +51,6 @@ class CreateTestData extends Command
|
||||
parent::__construct();
|
||||
|
||||
$this->invoice_repo = $invoice_repo;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,13 +70,11 @@ class CreateTestData extends Command
|
||||
$this->createSmallAccount();
|
||||
$this->createMediumAccount();
|
||||
$this->createLargeAccount();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function createSmallAccount()
|
||||
{
|
||||
|
||||
$this->info('Creating Small Account and Company');
|
||||
|
||||
$account = factory(\App\Models\Account::class)->create();
|
||||
@ -91,8 +87,7 @@ class CreateTestData extends Command
|
||||
|
||||
$user = User::whereEmail('small@example.com')->first();
|
||||
|
||||
if(!$user)
|
||||
{
|
||||
if (!$user) {
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
// 'account_id' => $account->id,
|
||||
'email' => 'small@example.com',
|
||||
@ -123,13 +118,12 @@ class CreateTestData extends Command
|
||||
$this->info('Creating '.$this->count. ' clients');
|
||||
|
||||
|
||||
for($x=0; $x<$this->count; $x++) {
|
||||
for ($x=0; $x<$this->count; $x++) {
|
||||
$z = $x+1;
|
||||
$this->info("Creating client # ".$z);
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createMediumAccount()
|
||||
@ -146,8 +140,7 @@ class CreateTestData extends Command
|
||||
|
||||
$user = User::whereEmail('medium@example.com')->first();
|
||||
|
||||
if(!$user)
|
||||
{
|
||||
if (!$user) {
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
// 'account_id' => $account->id,
|
||||
'email' => 'medium@example.com',
|
||||
@ -179,13 +172,12 @@ class CreateTestData extends Command
|
||||
$this->info('Creating '.$this->count. ' clients');
|
||||
|
||||
|
||||
for($x=0; $x<$this->count; $x++) {
|
||||
for ($x=0; $x<$this->count; $x++) {
|
||||
$z = $x+1;
|
||||
$this->info("Creating client # ".$z);
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createLargeAccount()
|
||||
@ -202,8 +194,7 @@ class CreateTestData extends Command
|
||||
|
||||
$user = User::whereEmail('large@example.com')->first();
|
||||
|
||||
if(!$user)
|
||||
{
|
||||
if (!$user) {
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
// 'account_id' => $account->id,
|
||||
'email' => 'large@example.com',
|
||||
@ -235,13 +226,12 @@ class CreateTestData extends Command
|
||||
$this->info('Creating '.$this->count. ' clients');
|
||||
|
||||
|
||||
for($x=0; $x<$this->count; $x++) {
|
||||
for ($x=0; $x<$this->count; $x++) {
|
||||
$z = $x+1;
|
||||
$this->info("Creating client # ".$z);
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createClient($company, $user)
|
||||
@ -252,25 +242,24 @@ class CreateTestData extends Command
|
||||
]);
|
||||
|
||||
|
||||
factory(\App\Models\ClientContact::class,1)->create([
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id,
|
||||
'is_primary' => 1
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class,rand(1,5))->create([
|
||||
factory(\App\Models\ClientContact::class, rand(1, 5))->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id
|
||||
]);
|
||||
|
||||
$y = $this->count * rand(1,5);
|
||||
$y = $this->count * rand(1, 5);
|
||||
|
||||
$this->info("Creating {$y} invoices & quotes");
|
||||
|
||||
for($x=0; $x<$y; $x++){
|
||||
|
||||
for ($x=0; $x<$y; $x++) {
|
||||
$this->createInvoice($client);
|
||||
$this->createQuote($client);
|
||||
}
|
||||
@ -280,27 +269,24 @@ class CreateTestData extends Command
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$invoice = InvoiceFactory::create($client->company->id,$client->user->id);//stub the company and user_id
|
||||
$invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id
|
||||
$invoice->client_id = $client->id;
|
||||
$invoice->date = $faker->date();
|
||||
|
||||
$invoice->line_items = $this->buildLineItems();
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
||||
if(rand(0,1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name1 = 'GST';
|
||||
$invoice->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if(rand(0,1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name2 = 'VAT';
|
||||
$invoice->tax_rate2 = 17.50;
|
||||
}
|
||||
|
||||
if(rand(0,1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name3 = 'CA Sales Tax';
|
||||
$invoice->tax_rate3 = 5;
|
||||
}
|
||||
@ -322,13 +308,12 @@ class CreateTestData extends Command
|
||||
|
||||
CreateInvoiceInvitations::dispatch($invoice, $invoice->company);
|
||||
|
||||
if(rand(0, 1)) {
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$payment = PaymentFactory::create($client->company->id, $client->user->id);
|
||||
$payment->date = now();
|
||||
$payment->client_id = $client->id;
|
||||
$payment->amount = $invoice->balance;
|
||||
$payment->transaction_reference = rand(0,500);
|
||||
$payment->transaction_reference = rand(0, 500);
|
||||
$payment->type_id = PaymentType::CREDIT_CARD_OTHER;
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->save();
|
||||
@ -346,27 +331,24 @@ class CreateTestData extends Command
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$quote = QuoteFactory::create($client->company->id,$client->user->id);//stub the company and user_id
|
||||
$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id
|
||||
$quote->client_id = $client->id;
|
||||
$quote->date = $faker->date();
|
||||
|
||||
$quote->line_items = $this->buildLineItems();
|
||||
$quote->uses_inclusive_taxes = false;
|
||||
|
||||
if(rand(0,1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name1 = 'GST';
|
||||
$quote->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if(rand(0,1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name2 = 'VAT';
|
||||
$quote->tax_rate2 = 17.50;
|
||||
}
|
||||
|
||||
if(rand(0,1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name3 = 'CA Sales Tax';
|
||||
$quote->tax_rate3 = 5;
|
||||
}
|
||||
@ -381,8 +363,6 @@ class CreateTestData extends Command
|
||||
$quote->save();
|
||||
|
||||
CreateQuoteInvitations::dispatch($quote, $quote->company);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function buildLineItems()
|
||||
@ -393,20 +373,17 @@ class CreateTestData extends Command
|
||||
$item->quantity = 1;
|
||||
$item->cost =10;
|
||||
|
||||
if(rand(0, 1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'GST';
|
||||
$item->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if(rand(0, 1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'VAT';
|
||||
$item->tax_rate1 = 17.50;
|
||||
}
|
||||
|
||||
if(rand(0, 1))
|
||||
{
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'Sales Tax';
|
||||
$item->tax_rate1 = 5;
|
||||
}
|
||||
@ -414,7 +391,6 @@ class CreateTestData extends Command
|
||||
$line_items[] = $item;
|
||||
|
||||
return $line_items;
|
||||
|
||||
}
|
||||
|
||||
private function warmCache()
|
||||
|
@ -64,7 +64,7 @@ class SendTestEmails extends Command
|
||||
$user = User::whereEmail('user@example.com')->first();
|
||||
$client = Client::all()->first();
|
||||
|
||||
if(!$user){
|
||||
if (!$user) {
|
||||
$user = factory(\App\Models\User::class)->create([
|
||||
'confirmation_code' => '123',
|
||||
'email' => 'admin@business.com',
|
||||
@ -73,12 +73,11 @@ class SendTestEmails extends Command
|
||||
]);
|
||||
}
|
||||
|
||||
if(!$client) {
|
||||
|
||||
if (!$client) {
|
||||
$client = ClientFactory::create($user->company()->id, $user->id);
|
||||
$client->save();
|
||||
|
||||
factory(\App\Models\ClientContact::class,1)->create([
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id,
|
||||
@ -87,7 +86,7 @@ class SendTestEmails extends Command
|
||||
'email' => 'exy@example.com',
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class,1)->create([
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id,
|
||||
@ -99,11 +98,10 @@ class SendTestEmails extends Command
|
||||
$cc_emails = [config('ninja.testvars.test_email')];
|
||||
$bcc_emails = [config('ninja.testvars.test_email')];
|
||||
|
||||
Mail::to(config('ninja.testvars.test_email'),'Mr Test')
|
||||
Mail::to(config('ninja.testvars.test_email'), 'Mr Test')
|
||||
->cc($cc_emails)
|
||||
->bcc($bcc_emails)
|
||||
//->replyTo(also_available_if_needed)
|
||||
->send(new TemplateEmail($message, $template, $user, $client));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,8 +38,6 @@ class Kernel extends ConsoleKernel
|
||||
// ->hourly();
|
||||
|
||||
$schedule->job(new RecurringInvoicesCron)->hourly();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,25 +16,25 @@ namespace App\DataMapper;
|
||||
*/
|
||||
class BaseSettings
|
||||
{
|
||||
|
||||
public function __construct($obj)
|
||||
{
|
||||
foreach($obj as $key => $value)
|
||||
foreach ($obj as $key => $value) {
|
||||
$obj->{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public static function setCasts($obj, $casts)
|
||||
{
|
||||
foreach ($casts as $key => $value)
|
||||
foreach ($casts as $key => $value) {
|
||||
$obj->{$key} = self::castAttribute($key, $obj->{$key});
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public static function castAttribute($key, $value)
|
||||
{
|
||||
switch ($key)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'int':
|
||||
case 'integer':
|
||||
return (int) $value;
|
||||
@ -59,7 +59,5 @@ class BaseSettings
|
||||
|
||||
public static function castSingleAttribute($key, $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -62,7 +62,6 @@ class ClientSettings extends BaseSettings
|
||||
*/
|
||||
public static function defaults() : \stdClass
|
||||
{
|
||||
|
||||
$data = (object)[
|
||||
'entity' => (string)Client::class,
|
||||
'industry_id' => '',
|
||||
@ -70,7 +69,6 @@ class ClientSettings extends BaseSettings
|
||||
];
|
||||
|
||||
return self::setCasts($data, self::$casts);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -83,25 +81,21 @@ class ClientSettings extends BaseSettings
|
||||
*/
|
||||
public static function buildClientSettings($company_settings, $client_settings)
|
||||
{
|
||||
|
||||
if(!$client_settings)
|
||||
if (!$client_settings) {
|
||||
return $company_settings;
|
||||
}
|
||||
|
||||
foreach($company_settings as $key => $value)
|
||||
{
|
||||
foreach ($company_settings as $key => $value) {
|
||||
/* pseudo code
|
||||
if the property exists and is a string BUT has no length, treat it as TRUE
|
||||
*/
|
||||
if( ( (property_exists($client_settings, $key) && is_string($client_settings->{$key}) && (iconv_strlen($client_settings->{$key}) <1)))
|
||||
if (((property_exists($client_settings, $key) && is_string($client_settings->{$key}) && (iconv_strlen($client_settings->{$key}) <1)))
|
||||
|| !isset($client_settings->{$key})
|
||||
&& property_exists($company_settings, $key)) {
|
||||
$client_settings->{$key} = $company_settings->{$key};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $client_settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,6 @@ class CompanySettings extends BaseSettings
|
||||
*/
|
||||
public static function defaults() : \stdClass
|
||||
{
|
||||
|
||||
$config = json_decode(config('ninja.settings'));
|
||||
|
||||
$data = (object)get_class_vars(CompanySettings::class);
|
||||
@ -432,7 +431,6 @@ class CompanySettings extends BaseSettings
|
||||
// $data->email_template_reminder_endless = EmailTemplateDefaults::emailReminderEndlessTemplate();
|
||||
|
||||
return self::setCasts($data, self::$casts);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,19 +442,14 @@ class CompanySettings extends BaseSettings
|
||||
*/
|
||||
public static function setProperties($settings) :\stdClass
|
||||
{
|
||||
|
||||
$company_settings = (object)get_class_vars(CompanySettings::class);
|
||||
|
||||
foreach($company_settings as $key => $value)
|
||||
{
|
||||
|
||||
if(!property_exists($settings, $key))
|
||||
foreach ($company_settings as $key => $value) {
|
||||
if (!property_exists($settings, $key)) {
|
||||
$settings->{$key} = self::castAttribute($key, $company_settings->{$key});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,11 +43,8 @@ class DefaultSettings extends BaseSettings
|
||||
*/
|
||||
private static function userSettingsObject() : \stdClass
|
||||
{
|
||||
|
||||
return (object)[
|
||||
'per_page' => self::$per_page,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -108,5 +108,3 @@ class EmailTemplateDefaults
|
||||
return str_replace(":", "$", ctrans('texts.'.$string));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,7 +13,6 @@ namespace App\DataMapper;
|
||||
|
||||
class InvoiceItem
|
||||
{
|
||||
|
||||
public $quantity = 0;
|
||||
|
||||
public $cost = 0;
|
||||
|
@ -13,7 +13,6 @@ namespace App\DataMapper;
|
||||
|
||||
class PaymentTransaction
|
||||
{
|
||||
|
||||
public $transaction_id;
|
||||
|
||||
public $gateway_response;
|
||||
@ -25,5 +24,4 @@ class PaymentTransaction
|
||||
public $status; // prepayment|payment|response|completed
|
||||
|
||||
public $invoices;
|
||||
|
||||
}
|
@ -19,6 +19,7 @@ use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
/**
|
||||
* Class ClientWasArchived.
|
||||
*/
|
||||
|
@ -40,9 +40,7 @@ class ContactLoggedIn
|
||||
*/
|
||||
public function __construct(ClientContact $client_contact)
|
||||
{
|
||||
|
||||
$this->client_contact = $client_contact;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Events\Invoice;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
@ -26,13 +27,15 @@ class InvoiceWasUpdated
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
public $company;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Invoice $invoice)
|
||||
public function __construct(Invoice $invoice, Company $company)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
$this->company = $company;
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,7 @@ class UserLoggedIn
|
||||
*/
|
||||
public function __construct($user)
|
||||
{
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,47 +70,32 @@ class Handler extends ExceptionHandler
|
||||
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
|
||||
if ($exception instanceof ModelNotFoundException && $request->expectsJson())
|
||||
{
|
||||
return response()->json(['message'=>'Record not found'],400);
|
||||
}
|
||||
else if($exception instanceof ThrottleRequestsException && $request->expectsJson())
|
||||
{
|
||||
return response()->json(['message'=>'Too many requests'],429);
|
||||
}
|
||||
else if($exception instanceof FatalThrowableError && $request->expectsJson())
|
||||
{
|
||||
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Record not found'], 400);
|
||||
} elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Too many requests'], 429);
|
||||
} elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Fatal error'], 500);
|
||||
}
|
||||
else if($exception instanceof AuthorizationException)
|
||||
{
|
||||
return response()->json(['message'=>'You are not authorized to view or perform this action'],401);
|
||||
}
|
||||
else if ($exception instanceof \Illuminate\Session\TokenMismatchException)
|
||||
{
|
||||
} elseif ($exception instanceof AuthorizationException) {
|
||||
return response()->json(['message'=>'You are not authorized to view or perform this action'], 401);
|
||||
} elseif ($exception instanceof \Illuminate\Session\TokenMismatchException) {
|
||||
return redirect()
|
||||
->back()
|
||||
->withInput($request->except('password', 'password_confirmation', '_token'))
|
||||
->with([
|
||||
'message' => ctrans('texts.token_expired'),
|
||||
'message-type' => 'danger']);
|
||||
}
|
||||
else if ($exception instanceof NotFoundHttpException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Route does not exist'],404);
|
||||
}
|
||||
else if($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()){
|
||||
return response()->json(['message'=>'Method not support for this route'],404);
|
||||
}
|
||||
else if ($exception instanceof ValidationException && $request->expectsJson()) {
|
||||
} elseif ($exception instanceof NotFoundHttpException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Route does not exist'], 404);
|
||||
} elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) {
|
||||
return response()->json(['message'=>'Method not support for this route'], 404);
|
||||
} elseif ($exception instanceof ValidationException && $request->expectsJson()) {
|
||||
return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
|
||||
}
|
||||
else if ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
|
||||
} elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
|
||||
return response()->json(['message' => $exception->getMessage()], 400);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ class CloneInvoiceFactory
|
||||
{
|
||||
$clone_invoice = $invoice->replicate();
|
||||
$clone_invoice->status_id = Invoice::STATUS_DRAFT;
|
||||
$clone_invoice->number = NULL;
|
||||
$clone_invoice->number = null;
|
||||
$clone_invoice->date = null;
|
||||
$clone_invoice->due_date = null;
|
||||
$clone_invoice->partial_due_date = null;
|
||||
@ -30,5 +30,4 @@ class CloneInvoiceFactory
|
||||
|
||||
return $clone_invoice;
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,6 @@ class CloneInvoiceToQuoteFactory
|
||||
{
|
||||
public static function create(Invoice $invoice, $user_id) : ?Quote
|
||||
{
|
||||
|
||||
$quote = new Quote();
|
||||
$quote->client_id = $invoice->client_id;
|
||||
$quote->user_id = $user_id;
|
||||
@ -56,5 +55,4 @@ class CloneInvoiceToQuoteFactory
|
||||
|
||||
return $quote;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,15 +15,12 @@ use App\Models\CompanyGateway;
|
||||
|
||||
class CompanyGatewayFactory
|
||||
{
|
||||
|
||||
public static function create(int $company_id, int $user_id) :CompanyGateway
|
||||
{
|
||||
|
||||
$company_gateway = new CompanyGateway;
|
||||
$company_gateway->company_id = $company_id;
|
||||
$company_gateway->user_id = $user_id;
|
||||
|
||||
return $company_gateway;
|
||||
|
||||
}
|
||||
}
|
@ -15,16 +15,13 @@ use App\Models\CompanyUser;
|
||||
|
||||
class CompanyUserFactory
|
||||
{
|
||||
|
||||
public static function create($user_id, $company_id, $account_id) :CompanyUser
|
||||
{
|
||||
|
||||
$company_user = new CompanyUser;
|
||||
$company_user->user_id = $user_id;
|
||||
$company_user->company_id = $company_id;
|
||||
$company_user->account_id = $account_id;
|
||||
|
||||
return $company_user;
|
||||
|
||||
}
|
||||
}
|
@ -15,10 +15,8 @@ use App\Models\GroupSetting;
|
||||
|
||||
class GroupSettingFactory
|
||||
{
|
||||
|
||||
public static function create(int $company_id, int $user_id) :GroupSetting
|
||||
{
|
||||
|
||||
$gs = new GroupSetting;
|
||||
$gs->name = '';
|
||||
$gs->company_id = $company_id;
|
||||
@ -26,6 +24,5 @@ class GroupSettingFactory
|
||||
$gs->settings = '{}';
|
||||
|
||||
return $gs;
|
||||
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@ use Illuminate\Support\Str;
|
||||
|
||||
class InvoiceInvitationFactory
|
||||
{
|
||||
|
||||
public static function create(int $company_id, int $user_id) :InvoiceInvitation
|
||||
{
|
||||
$ii = new InvoiceInvitation;
|
||||
@ -36,7 +35,4 @@ class InvoiceInvitationFactory
|
||||
|
||||
return $ii;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Factory;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
//use Faker\Generator as Faker;
|
||||
|
||||
class InvoiceItemFactory
|
||||
@ -34,13 +35,12 @@ class InvoiceItemFactory
|
||||
$item->sort_id = 0;
|
||||
$item->line_total = 0;
|
||||
$item->date = Carbon::now();
|
||||
$item->custom_value1 = NULL;
|
||||
$item->custom_value2 = NULL;
|
||||
$item->custom_value3 = NULL;
|
||||
$item->custom_value4 = NULL;
|
||||
$item->custom_value1 = null;
|
||||
$item->custom_value2 = null;
|
||||
$item->custom_value3 = null;
|
||||
$item->custom_value4 = null;
|
||||
|
||||
return $item;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,15 +54,13 @@ class InvoiceItemFactory
|
||||
|
||||
$data = [];
|
||||
|
||||
for($x=0; $x<$items; $x++)
|
||||
{
|
||||
|
||||
for ($x=0; $x<$items; $x++) {
|
||||
$item = self::create();
|
||||
$item->quantity = $faker->numberBetween(1,10);
|
||||
$item->quantity = $faker->numberBetween(1, 10);
|
||||
$item->cost = $faker->randomFloat(2, 1, 1000);
|
||||
$item->line_total = $item->quantity * $item->cost;
|
||||
$item->is_amount_discount = true;
|
||||
$item->discount = $faker->numberBetween(1,10);
|
||||
$item->discount = $faker->numberBetween(1, 10);
|
||||
$item->notes = $faker->realText(20);
|
||||
$item->product_key = $faker->word();
|
||||
$item->custom_value1 = $faker->realText(10);
|
||||
@ -77,5 +75,4 @@ class InvoiceItemFactory
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ use App\Models\RecurringInvoice;
|
||||
|
||||
class InvoiceToRecurringInvoiceFactory
|
||||
{
|
||||
|
||||
public static function create(Invoice $invoice) :RecurringInvoice
|
||||
{
|
||||
$recurring_invoice = new RecurringInvoice;
|
||||
@ -57,5 +56,4 @@ class InvoiceToRecurringInvoiceFactory
|
||||
|
||||
return $recurring_invoice;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,3 @@ class PaymentFactory
|
||||
return $payment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -39,5 +39,3 @@ class ProductFactory
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,7 +16,6 @@ use Illuminate\Support\Str;
|
||||
|
||||
class QuoteInvitationFactory
|
||||
{
|
||||
|
||||
public static function create(int $company_id, int $user_id) :QuoteInvitation
|
||||
{
|
||||
$qi = new QuoteInvitation;
|
||||
@ -36,7 +35,4 @@ class QuoteInvitationFactory
|
||||
|
||||
return $qi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -56,5 +56,4 @@ class RecurringInvoiceFactory
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ use App\Models\RecurringInvoice;
|
||||
|
||||
class recurring_invoiceToInvoiceFactory
|
||||
{
|
||||
|
||||
public static function create(RecurringInvoice $recurring_invoice) :Invoice
|
||||
{
|
||||
$invoice = new Invoice();
|
||||
@ -51,5 +50,4 @@ class recurring_invoiceToInvoiceFactory
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,5 +55,4 @@ class RecurringQuoteFactory
|
||||
|
||||
return $quote;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ use App\Models\TaxRate;
|
||||
|
||||
class TaxRateFactory
|
||||
{
|
||||
|
||||
public static function create($company_id, $user_id) :TaxRate
|
||||
{
|
||||
$tax_rate = new TaxRate;
|
||||
@ -27,5 +26,4 @@ class TaxRateFactory
|
||||
|
||||
return $tax_rate;
|
||||
}
|
||||
|
||||
}
|
@ -59,8 +59,9 @@ class ClientFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('clients.name', 'like', '%'.$filter.'%')
|
||||
@ -68,10 +69,10 @@ class ClientFilters extends QueryFilters
|
||||
->orWhere('client_contacts.first_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('client_contacts.last_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('client_contacts.email', 'like', '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value1', 'like' , '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('clients.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('clients.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -84,8 +85,9 @@ class ClientFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'clients';
|
||||
$filters = explode(',', $filter);
|
||||
@ -190,7 +192,5 @@ class ClientFilters extends QueryFilters
|
||||
|
||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
return $this->builder->company();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -41,26 +41,31 @@ class InvoiceFilters extends QueryFilters
|
||||
|
||||
public function client_status(string $value = '') :Builder
|
||||
{
|
||||
if(strlen($value) == 0)
|
||||
if (strlen($value) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$status_parameters = explode(",", $value);
|
||||
|
||||
if (in_array('all', $status_parameters))
|
||||
if (in_array('all', $status_parameters)) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if(in_array('paid', $status_parameters))
|
||||
if (in_array('paid', $status_parameters)) {
|
||||
$this->builder->where('status_id', Invoice::STATUS_PAID);
|
||||
}
|
||||
|
||||
if(in_array('unpaid', $status_parameters))
|
||||
if (in_array('unpaid', $status_parameters)) {
|
||||
$this->builder->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
|
||||
}
|
||||
//->where('due_date', '>', Carbon::now())
|
||||
//->orWhere('partial_due_date', '>', Carbon::now());
|
||||
|
||||
if(in_array('overdue', $status_parameters))
|
||||
if (in_array('overdue', $status_parameters)) {
|
||||
$this->builder->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('due_date', '<', Carbon::now())
|
||||
->orWhere('partial_due_date', '<', Carbon::now());
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
@ -75,8 +80,9 @@ class InvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('invoices.number', 'like', '%'.$filter.'%')
|
||||
@ -85,9 +91,9 @@ class InvoiceFilters extends QueryFilters
|
||||
->orWhere('invoices.amount', 'like', '%'.$filter.'%')
|
||||
->orWhere('invoices.balance', 'like', '%'.$filter.'%')
|
||||
->orWhere('invoices.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('invoices.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('invoices.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('invoices.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('invoices.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('invoices.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('invoices.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -100,8 +106,9 @@ class InvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'invoices';
|
||||
$filters = explode(',', $filter);
|
||||
@ -150,7 +157,6 @@ class InvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,14 +170,13 @@ class InvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
if(auth('contact')->user())
|
||||
if (auth('contact')->user()) {
|
||||
return $this->contactViewFilter();
|
||||
else
|
||||
} else {
|
||||
return $this->builder->company();
|
||||
}
|
||||
|
||||
// return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,13 +187,8 @@ class InvoiceFilters extends QueryFilters
|
||||
*/
|
||||
private function contactViewFilter() : Builder
|
||||
{
|
||||
|
||||
return $this->builder
|
||||
->whereCompanyId(auth('contact')->user()->company->id)
|
||||
->whereNotIn('status_id', [Invoice::STATUS_DRAFT, Invoice::STATUS_CANCELLED]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -32,16 +32,17 @@ class PaymentFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('payments.amount', 'like', '%'.$filter.'%')
|
||||
->orWhere('payments.date', 'like', '%'.$filter.'%')
|
||||
->orWhere('payments.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('payments.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('payments.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('payments.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('payments.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('payments.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('payments.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -54,8 +55,9 @@ class PaymentFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'payments';
|
||||
$filters = explode(',', $filter);
|
||||
@ -104,7 +106,6 @@ class PaymentFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,12 +116,12 @@ class PaymentFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
if(auth('contact')->user())
|
||||
if (auth('contact')->user()) {
|
||||
return $this->contactViewFilter();
|
||||
else
|
||||
} else {
|
||||
return $this->builder->company();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -132,10 +133,8 @@ class PaymentFilters extends QueryFilters
|
||||
*/
|
||||
private function contactViewFilter() : Builder
|
||||
{
|
||||
|
||||
return $this->builder
|
||||
->whereCompanyId(auth('contact')->user()->company->id)
|
||||
->whereIsDeleted(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -31,16 +31,17 @@ class ProductFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('products.product_key', 'like', '%'.$filter.'%')
|
||||
->orWhere('products.notes', 'like', '%'.$filter.'%')
|
||||
->orWhere('products.custom_value1', 'like' , '%'.$filter.'%')
|
||||
->orWhere('products.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('products.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('products.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('products.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('products.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('products.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('products.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -53,8 +54,9 @@ class ProductFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'products';
|
||||
$filters = explode(',', $filter);
|
||||
@ -103,7 +105,6 @@ class ProductFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,9 +115,6 @@ class ProductFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
return $this->builder->company();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -59,9 +59,7 @@ abstract class QueryFilters
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
|
||||
$this->request = $request;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,9 +98,7 @@ abstract class QueryFilters
|
||||
*/
|
||||
public function filters()
|
||||
{
|
||||
|
||||
return $this->request->all();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,7 +109,6 @@ abstract class QueryFilters
|
||||
*/
|
||||
public function split($value) : stdClass
|
||||
{
|
||||
|
||||
$exploded_array = explode(":", $value);
|
||||
|
||||
$parts = new stdClass;
|
||||
@ -122,7 +117,6 @@ abstract class QueryFilters
|
||||
$parts->operator = $this->operatorConvertor($exploded_array[1]);
|
||||
|
||||
return $parts;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,7 +127,6 @@ abstract class QueryFilters
|
||||
*/
|
||||
private function operatorConvertor(string $operator) : string
|
||||
{
|
||||
|
||||
switch ($operator) {
|
||||
case 'lt':
|
||||
return '<';
|
||||
@ -167,7 +160,8 @@ abstract class QueryFilters
|
||||
*/
|
||||
public function clientFilter()
|
||||
{
|
||||
if(auth('contact')->user())
|
||||
if (auth('contact')->user()) {
|
||||
return $this->builder->whereClientId(auth('contact')->user()->client->id);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,14 +31,15 @@ class QuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('quotes.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('quotes.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('quotes.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('quotes.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('quotes.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('quotes.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('quotes.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,8 +52,9 @@ class QuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'quotes';
|
||||
$filters = explode(',', $filter);
|
||||
@ -101,7 +103,6 @@ class QuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,9 +113,6 @@ class QuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
return $this->builder->company();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -31,14 +31,15 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('recurring_invoices.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('recurring_invoices.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('recurring_invoices.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('recurring_invoices.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('recurring_invoices.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('recurring_invoices.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('recurring_invoices.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,8 +52,9 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'recurring_';
|
||||
$filters = explode(',', $filter);
|
||||
@ -101,7 +103,6 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,9 +113,6 @@ class RecurringInvoiceFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
return $this->builder->company();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -31,14 +31,15 @@ class RecurringQuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('recurring_quotes.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('recurring_quotes.custom_value2', 'like' , '%'.$filter.'%')
|
||||
->orWhere('recurring_quotes.custom_value3', 'like' , '%'.$filter.'%')
|
||||
->orWhere('recurring_quotes.custom_value4', 'like' , '%'.$filter.'%');
|
||||
->orWhere('recurring_quotes.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('recurring_quotes.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('recurring_quotes.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,8 +52,9 @@ class RecurringQuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'recurring_';
|
||||
$filters = explode(',', $filter);
|
||||
@ -101,7 +103,6 @@ class RecurringQuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,9 +113,6 @@ class RecurringQuoteFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
return $this->builder->company();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -31,14 +31,15 @@ class UserFilters extends QueryFilters
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('users.first_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('users.last_name', 'like' , '%'.$filter.'%')
|
||||
->orWhere('users.email', 'like' , '%'.$filter.'%')
|
||||
->orWhere('users.signature', 'like' , '%'.$filter.'%');
|
||||
->orWhere('users.last_name', 'like', '%'.$filter.'%')
|
||||
->orWhere('users.email', 'like', '%'.$filter.'%')
|
||||
->orWhere('users.signature', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,8 +52,9 @@ class UserFilters extends QueryFilters
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if(strlen($filter) == 0)
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'users';
|
||||
$filters = explode(',', $filter);
|
||||
@ -101,7 +103,6 @@ class UserFilters extends QueryFilters
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,11 +115,8 @@ class UserFilters extends QueryFilters
|
||||
{
|
||||
//return $this->builder->user_companies()->whereCompanyId(auth()->user()->company()->id);
|
||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
return $this->builder->whereHas('company_users', function($q)
|
||||
{
|
||||
return $this->builder->whereHas('company_users', function ($q) {
|
||||
$q->where('company_id', '=', auth()->user()->company()->id);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -16,17 +16,12 @@ namespace App\Helpers\Invoice;
|
||||
*/
|
||||
trait Balancer
|
||||
{
|
||||
|
||||
public function balance($total, $invoice)
|
||||
{
|
||||
|
||||
if(isset($this->invoice->id) && $this->invoice->id >= 1)
|
||||
{
|
||||
if (isset($this->invoice->id) && $this->invoice->id >= 1) {
|
||||
return round($total - ($this->invoice->amount - $this->invoice->balance), 2);
|
||||
}
|
||||
|
||||
return $total;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,23 +16,21 @@ namespace App\Helpers\Invoice;
|
||||
*/
|
||||
trait CustomValuer
|
||||
{
|
||||
|
||||
public function valuer($custom_value)
|
||||
{
|
||||
|
||||
if(isset($custom_value) && is_numeric($custom_value))
|
||||
if (isset($custom_value) && is_numeric($custom_value)) {
|
||||
return $custom_value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function valuerTax($custom_value, $has_custom_invoice_taxes)
|
||||
{
|
||||
if(isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes === true)
|
||||
return round($custom_value * ($this->invoice->tax_rate1/100) ,2) + round($custom_value * ($this->invoice->tax_rate2/100) ,2) + round($custom_value * ($this->invoice->tax_rate3/100) ,2);
|
||||
if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes === true) {
|
||||
return round($custom_value * ($this->invoice->tax_rate1/100), 2) + round($custom_value * ($this->invoice->tax_rate2/100), 2) + round($custom_value * ($this->invoice->tax_rate3/100), 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,18 +16,13 @@ namespace App\Helpers\Invoice;
|
||||
*/
|
||||
trait Discounter
|
||||
{
|
||||
|
||||
public function discount($amount)
|
||||
{
|
||||
|
||||
if($this->invoice->is_amount_discount == true){
|
||||
if ($this->invoice->is_amount_discount == true) {
|
||||
return $this->invoice->discount;
|
||||
}
|
||||
|
||||
|
||||
return round($amount * ($this->invoice->discount / 100), 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
class InvoiceItemSum
|
||||
{
|
||||
|
||||
use NumberFormatter;
|
||||
use Discounter;
|
||||
use Taxer;
|
||||
@ -48,7 +47,6 @@ class InvoiceItemSum
|
||||
|
||||
public function __construct($invoice)
|
||||
{
|
||||
|
||||
$this->tax_collection = collect([]);
|
||||
|
||||
$this->invoice = $invoice;
|
||||
@ -60,8 +58,7 @@ class InvoiceItemSum
|
||||
|
||||
public function process()
|
||||
{
|
||||
|
||||
if(!$this->invoice->line_items || !isset($this->invoice->line_items) || count($this->invoice->line_items) == 0){
|
||||
if (!$this->invoice->line_items || !isset($this->invoice->line_items) || count($this->invoice->line_items) == 0) {
|
||||
$this->items = [];
|
||||
return $this;
|
||||
}
|
||||
@ -73,8 +70,7 @@ class InvoiceItemSum
|
||||
|
||||
private function calcLineItems()
|
||||
{
|
||||
foreach($this->invoice->line_items as $this->item)
|
||||
{
|
||||
foreach ($this->invoice->line_items as $this->item) {
|
||||
$this->cleanLineItem()
|
||||
->sumLineItem()
|
||||
->setDiscount()
|
||||
@ -87,7 +83,6 @@ class InvoiceItemSum
|
||||
|
||||
private function push()
|
||||
{
|
||||
|
||||
$this->sub_total += $this->getLineTotal();
|
||||
|
||||
$this->line_items[] = $this->item;
|
||||
@ -103,25 +98,19 @@ class InvoiceItemSum
|
||||
|
||||
private function setDiscount()
|
||||
{
|
||||
|
||||
if($this->invoice->is_amount_discount)
|
||||
{
|
||||
if ($this->invoice->is_amount_discount) {
|
||||
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100),2), $this->currency->precision));
|
||||
} else {
|
||||
$this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100), 2), $this->currency->precision));
|
||||
}
|
||||
|
||||
$this->item->is_amount_discount = $this->invoice->is_amount_discount;
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
private function calcTaxes()
|
||||
{
|
||||
|
||||
$item_tax = 0;
|
||||
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/100));
|
||||
@ -129,22 +118,25 @@ class InvoiceItemSum
|
||||
|
||||
$item_tax += $item_tax_rate1_total;
|
||||
|
||||
if($item_tax_rate1_total > 0)
|
||||
if ($item_tax_rate1_total > 0) {
|
||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||
}
|
||||
|
||||
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate2_total;
|
||||
|
||||
if($item_tax_rate2_total > 0)
|
||||
if ($item_tax_rate2_total > 0) {
|
||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||
}
|
||||
|
||||
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate3_total;
|
||||
|
||||
if($item_tax_rate3_total > 0)
|
||||
if ($item_tax_rate3_total > 0) {
|
||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||
}
|
||||
|
||||
|
||||
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
||||
@ -161,7 +153,6 @@ class InvoiceItemSum
|
||||
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate.'%'];
|
||||
|
||||
$this->tax_collection->push(collect($group_tax));
|
||||
|
||||
}
|
||||
|
||||
public function getTotalTaxes()
|
||||
@ -234,39 +225,38 @@ class InvoiceItemSum
|
||||
|
||||
$item_tax = 0;
|
||||
|
||||
foreach($this->line_items as $this->item)
|
||||
{
|
||||
|
||||
if($this->item->line_total == 0)
|
||||
foreach ($this->line_items as $this->item) {
|
||||
if ($this->item->line_total == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/$this->sub_total));
|
||||
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate1_total;
|
||||
|
||||
if($item_tax_rate1_total > 0)
|
||||
if ($item_tax_rate1_total > 0) {
|
||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||
}
|
||||
|
||||
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate2_total;
|
||||
|
||||
if($item_tax_rate2_total > 0)
|
||||
if ($item_tax_rate2_total > 0) {
|
||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||
}
|
||||
|
||||
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate3_total;
|
||||
|
||||
if($item_tax_rate3_total > 0)
|
||||
if ($item_tax_rate3_total > 0) {
|
||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->setTotalTaxes($item_tax);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -278,15 +268,11 @@ class InvoiceItemSum
|
||||
$invoice_item = (object)get_class_vars(InvoiceItem::class);
|
||||
unset($invoice_item->casts);
|
||||
|
||||
foreach($invoice_item as $key => $value)
|
||||
{
|
||||
|
||||
if(!property_exists($this->item, $key) || !isset($this->item->{$key})){
|
||||
foreach ($invoice_item as $key => $value) {
|
||||
if (!property_exists($this->item, $key) || !isset($this->item->{$key})) {
|
||||
$this->item->{$key} = $value;
|
||||
$this->item->{$key} = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
class InvoiceItemSumInclusive
|
||||
{
|
||||
|
||||
use NumberFormatter;
|
||||
use Discounter;
|
||||
use Taxer;
|
||||
@ -47,8 +46,6 @@ class InvoiceItemSumInclusive
|
||||
|
||||
public function __construct($invoice)
|
||||
{
|
||||
|
||||
|
||||
$this->tax_collection = collect([]);
|
||||
|
||||
$this->invoice = $invoice;
|
||||
@ -60,8 +57,7 @@ class InvoiceItemSumInclusive
|
||||
|
||||
public function process()
|
||||
{
|
||||
|
||||
if(!$this->invoice->line_items || count($this->invoice->line_items) == 0){
|
||||
if (!$this->invoice->line_items || count($this->invoice->line_items) == 0) {
|
||||
$this->items = [];
|
||||
return $this;
|
||||
}
|
||||
@ -73,8 +69,7 @@ class InvoiceItemSumInclusive
|
||||
|
||||
private function calcLineItems()
|
||||
{
|
||||
foreach($this->invoice->line_items as $this->item)
|
||||
{
|
||||
foreach ($this->invoice->line_items as $this->item) {
|
||||
$this->sumLineItem()
|
||||
->setDiscount()
|
||||
->calcTaxes()
|
||||
@ -86,7 +81,6 @@ class InvoiceItemSumInclusive
|
||||
|
||||
private function push()
|
||||
{
|
||||
|
||||
$this->sub_total += $this->getLineTotal();
|
||||
|
||||
$this->line_items[] = $this->item;
|
||||
@ -104,20 +98,15 @@ class InvoiceItemSumInclusive
|
||||
|
||||
private function setDiscount()
|
||||
{
|
||||
|
||||
if($this->invoice->is_amount_discount)
|
||||
{
|
||||
if ($this->invoice->is_amount_discount) {
|
||||
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->setLineTotal($this->getLineTotal() - $this->formatValue(($this->item->line_total * ($this->item->discount / 100)), $this->currency->precision));
|
||||
}
|
||||
|
||||
$this->item->is_amount_discount = $this->invoice->is_amount_discount;
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +116,6 @@ class InvoiceItemSumInclusive
|
||||
*/
|
||||
private function calcTaxes()
|
||||
{
|
||||
|
||||
$item_tax = 0;
|
||||
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/100));
|
||||
@ -136,22 +124,25 @@ class InvoiceItemSumInclusive
|
||||
|
||||
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
|
||||
|
||||
if($item_tax_rate1_total > 0)
|
||||
if ($item_tax_rate1_total > 0) {
|
||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||
}
|
||||
|
||||
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
|
||||
|
||||
$item_tax += $this->formatValue($item_tax_rate2_total, $this->currency->precision);
|
||||
|
||||
if($item_tax_rate2_total > 0)
|
||||
if ($item_tax_rate2_total > 0) {
|
||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||
}
|
||||
|
||||
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
|
||||
|
||||
$item_tax += $this->formatValue($item_tax_rate3_total, $this->currency->precision);
|
||||
|
||||
if($item_tax_rate3_total > 0)
|
||||
if ($item_tax_rate3_total > 0) {
|
||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||
}
|
||||
|
||||
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
|
||||
|
||||
@ -167,7 +158,6 @@ class InvoiceItemSumInclusive
|
||||
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate.'%'];
|
||||
|
||||
$this->tax_collection->push(collect($group_tax));
|
||||
|
||||
}
|
||||
|
||||
public function getTotalTaxes()
|
||||
@ -239,35 +229,33 @@ class InvoiceItemSumInclusive
|
||||
|
||||
$item_tax = 0;
|
||||
|
||||
foreach($this->line_items as $this->item)
|
||||
{
|
||||
|
||||
foreach ($this->line_items as $this->item) {
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/$this->sub_total));
|
||||
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate1_total;
|
||||
|
||||
if($item_tax_rate1_total > 0)
|
||||
if ($item_tax_rate1_total > 0) {
|
||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||
}
|
||||
|
||||
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate2_total;
|
||||
|
||||
if($item_tax_rate2_total > 0)
|
||||
if ($item_tax_rate2_total > 0) {
|
||||
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
|
||||
}
|
||||
|
||||
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate3_total;
|
||||
|
||||
if($item_tax_rate3_total > 0)
|
||||
if ($item_tax_rate3_total > 0) {
|
||||
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->setTotalTaxes($item_tax);
|
||||
|
||||
}
|
||||
}
|
@ -52,16 +52,13 @@ class InvoiceSum
|
||||
*/
|
||||
public function __construct($invoice)
|
||||
{
|
||||
|
||||
$this->invoice = $invoice;
|
||||
|
||||
$this->tax_map = new Collection;
|
||||
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$this->calculateLineItems()
|
||||
->calculateDiscount()
|
||||
->calculateCustomValues()
|
||||
@ -115,20 +112,19 @@ class InvoiceSum
|
||||
|
||||
private function calculateInvoiceTaxes()
|
||||
{
|
||||
|
||||
if($this->invoice->tax_rate1 > 0){
|
||||
if ($this->invoice->tax_rate1 > 0) {
|
||||
$tax = $this->taxer($this->total, $this->invoice->tax_rate1);
|
||||
$this->total_taxes += $tax;
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1 . ' ' . $this->invoice->tax_rate1.'%', 'total' => $tax];
|
||||
}
|
||||
|
||||
if($this->invoice->tax_rate2 > 0){
|
||||
if ($this->invoice->tax_rate2 > 0) {
|
||||
$tax = $this->taxer($this->total, $this->invoice->tax_rate2);
|
||||
$this->total_taxes += $tax;
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2. ' ' . $this->invoice->tax_rate2.'%', 'total' => $tax];
|
||||
}
|
||||
|
||||
if($this->invoice->tax_rate3 > 0){
|
||||
if ($this->invoice->tax_rate3 > 0) {
|
||||
$tax = $this->taxer($this->total, $this->invoice->tax_rate3);
|
||||
$this->total_taxes += $tax;
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3 . ' ' . $this->invoice->tax_rate3.'%', 'total' => $tax];
|
||||
@ -152,7 +148,7 @@ class InvoiceSum
|
||||
|
||||
private function calculatePartial()
|
||||
{
|
||||
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
|
||||
if (!isset($this->invoice->id) && isset($this->invoice->partial)) {
|
||||
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
|
||||
}
|
||||
|
||||
@ -183,14 +179,13 @@ class InvoiceSum
|
||||
private function setCalculatedAttributes()
|
||||
{
|
||||
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
||||
if($this->invoice->amount != $this->invoice->balance)
|
||||
{
|
||||
if ($this->invoice->amount != $this->invoice->balance) {
|
||||
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
||||
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
}
|
||||
|
||||
/* Set new calculated total */
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
@ -233,8 +228,9 @@ class InvoiceSum
|
||||
|
||||
public function setTaxMap()
|
||||
{
|
||||
if($this->invoice->is_amount_discount == true)
|
||||
if ($this->invoice->is_amount_discount == true) {
|
||||
$this->invoice_items->calcTaxesWithAmountDiscount();
|
||||
}
|
||||
|
||||
$this->tax_map = collect();
|
||||
|
||||
@ -242,14 +238,12 @@ class InvoiceSum
|
||||
|
||||
$values = $this->invoice_items->getGroupedTaxes();
|
||||
|
||||
foreach($keys as $key)
|
||||
{
|
||||
|
||||
$tax_name = $values->filter(function ($value, $k) use($key){
|
||||
foreach ($keys as $key) {
|
||||
$tax_name = $values->filter(function ($value, $k) use ($key) {
|
||||
return $value['key'] == $key;
|
||||
})->pluck('tax_name')->first();
|
||||
|
||||
$total_line_tax = $values->filter(function ($value, $k) use($key){
|
||||
$total_line_tax = $values->filter(function ($value, $k) use ($key) {
|
||||
return $value['key'] == $key;
|
||||
})->sum('total');
|
||||
|
||||
@ -261,7 +255,6 @@ class InvoiceSum
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
public function getTaxMap()
|
||||
|
@ -53,12 +53,10 @@ class InvoiceSumInclusive
|
||||
*/
|
||||
public function __construct($invoice)
|
||||
{
|
||||
|
||||
$this->invoice = $invoice;
|
||||
|
||||
|
||||
$this->tax_map = new Collection;
|
||||
|
||||
}
|
||||
|
||||
public function build()
|
||||
@ -118,29 +116,29 @@ class InvoiceSumInclusive
|
||||
{
|
||||
$amount = $this->total;
|
||||
|
||||
if($this->invoice->discount > 0 && $this->invoice->is_amount_discount)
|
||||
$amount = $this->formatValue(($this->sub_total - $this->invoice->discount),2);
|
||||
if ($this->invoice->discount > 0 && $this->invoice->is_amount_discount) {
|
||||
$amount = $this->formatValue(($this->sub_total - $this->invoice->discount), 2);
|
||||
}
|
||||
|
||||
if($this->invoice->discount > 0 && !$this->invoice->is_amount_discount)
|
||||
$amount = $this->formatValue(($this->sub_total - ($this->sub_total * ($this->invoice->discount/100))),2);
|
||||
if ($this->invoice->discount > 0 && !$this->invoice->is_amount_discount) {
|
||||
$amount = $this->formatValue(($this->sub_total - ($this->sub_total * ($this->invoice->discount/100))), 2);
|
||||
}
|
||||
|
||||
if($this->invoice->tax_rate1 > 0){
|
||||
if ($this->invoice->tax_rate1 > 0) {
|
||||
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount);
|
||||
$this->total_taxes += $tax;
|
||||
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1 . ' ' . $this->invoice->tax_rate1.'%', 'total' => $tax];
|
||||
|
||||
}
|
||||
|
||||
|
||||
if($this->invoice->tax_rate2 > 0){
|
||||
if ($this->invoice->tax_rate2 > 0) {
|
||||
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate2, $amount);
|
||||
$this->total_taxes += $tax;
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2. ' ' . $this->invoice->tax_rate2.'%', 'total' => $tax];
|
||||
|
||||
}
|
||||
|
||||
if($this->invoice->tax_rate3 > 0){
|
||||
if ($this->invoice->tax_rate3 > 0) {
|
||||
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate3, $amount);
|
||||
$this->total_taxes += $tax;
|
||||
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3 . ' ' . $this->invoice->tax_rate3.'%', 'total' => $tax];
|
||||
@ -164,7 +162,7 @@ class InvoiceSumInclusive
|
||||
|
||||
private function calculatePartial()
|
||||
{
|
||||
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
|
||||
if (!isset($this->invoice->id) && isset($this->invoice->partial)) {
|
||||
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
|
||||
}
|
||||
|
||||
@ -195,14 +193,13 @@ class InvoiceSumInclusive
|
||||
private function setCalculatedAttributes()
|
||||
{
|
||||
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
|
||||
if($this->invoice->amount != $this->invoice->balance)
|
||||
{
|
||||
if ($this->invoice->amount != $this->invoice->balance) {
|
||||
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
||||
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
}
|
||||
|
||||
/* Set new calculated total */
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
@ -245,8 +242,9 @@ class InvoiceSumInclusive
|
||||
|
||||
public function setTaxMap()
|
||||
{
|
||||
if($this->invoice->is_amount_discount == true)
|
||||
if ($this->invoice->is_amount_discount == true) {
|
||||
$this->invoice_items->calcTaxesWithAmountDiscount();
|
||||
}
|
||||
|
||||
$this->tax_map = collect();
|
||||
|
||||
@ -254,14 +252,12 @@ class InvoiceSumInclusive
|
||||
|
||||
$values = $this->invoice_items->getGroupedTaxes();
|
||||
|
||||
foreach($keys as $key)
|
||||
{
|
||||
|
||||
$tax_name = $values->filter(function ($value, $k) use($key){
|
||||
foreach ($keys as $key) {
|
||||
$tax_name = $values->filter(function ($value, $k) use ($key) {
|
||||
return $value['key'] == $key;
|
||||
})->pluck('tax_name')->first();
|
||||
|
||||
$total_line_tax = $values->filter(function ($value, $k) use($key){
|
||||
$total_line_tax = $values->filter(function ($value, $k) use ($key) {
|
||||
return $value['key'] == $key;
|
||||
})->sum('total');
|
||||
|
||||
@ -273,7 +269,6 @@ class InvoiceSumInclusive
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
public function getTaxMap()
|
||||
@ -290,6 +285,4 @@ class InvoiceSumInclusive
|
||||
{
|
||||
return $this->getTotalTaxes();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -16,7 +16,6 @@ namespace App\Helpers\Invoice;
|
||||
*/
|
||||
trait Taxer
|
||||
{
|
||||
|
||||
public function taxer($amount, $tax_rate)
|
||||
{
|
||||
return round($amount * (($tax_rate ? $tax_rate : 0) / 100), 2);
|
||||
@ -31,6 +30,4 @@ trait Taxer
|
||||
{
|
||||
return $this->formatValue($amount - ($amount / (1 + ($tax_rate/100))), 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,10 +24,9 @@ use Laravel\Socialite\Facades\Socialite;
|
||||
*/
|
||||
class GmailTransportConfig
|
||||
{
|
||||
|
||||
public function test()
|
||||
{
|
||||
/********************* We may need to fetch a new token on behalf of the client ******************************/
|
||||
/********************* We may need to fetch a new token on behalf of the client ******************************/
|
||||
$query = [
|
||||
'email' => 'david@invoiceninja.com',
|
||||
];
|
||||
@ -46,17 +45,4 @@ class GmailTransportConfig
|
||||
Mail::to('david@romulus.com.au')
|
||||
->send(new SupportMessageSent('a cool message'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -15,5 +15,4 @@ class GmailTransportManager extends TransportManager
|
||||
|
||||
return new GmailTransport($mail, $token);
|
||||
}
|
||||
|
||||
}
|
@ -25,5 +25,4 @@ function ctrans(string $string, $replace = [], $locale = null) : string
|
||||
//todo pass through the cached version of the custom strings here else return trans();
|
||||
|
||||
return trans($string, $replace, $locale);
|
||||
|
||||
}
|
@ -44,7 +44,6 @@ class AccountController extends BaseController
|
||||
public function index()
|
||||
{
|
||||
// return view('signup.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,13 +145,11 @@ class AccountController extends BaseController
|
||||
*/
|
||||
public function store(CreateAccountRequest $request)
|
||||
{
|
||||
|
||||
$account = CreateAccount::dispatchNow($request->all());
|
||||
|
||||
$ct = CompanyUser::whereUserId(auth()->user()->id);
|
||||
|
||||
return $this->listResponse($ct);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,14 +11,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Transformers\ActivityTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ActivityController extends BaseController
|
||||
{
|
||||
|
||||
protected $entity_type = Activity::class;
|
||||
|
||||
protected $entity_transformer = ActivityTransformer::class;
|
||||
@ -83,5 +81,4 @@ class ActivityController extends BaseController
|
||||
|
||||
return $this->listResponse($activities);
|
||||
}
|
||||
|
||||
}
|
@ -46,8 +46,9 @@ class ContactForgotPasswordController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showLinkRequestForm(){
|
||||
return view('portal.default.auth.passwords.email',[
|
||||
public function showLinkRequestForm()
|
||||
{
|
||||
return view('portal.default.auth.passwords.email', [
|
||||
'title' => 'Client Password Reset',
|
||||
'passwordEmailRoute' => 'client.password.email'
|
||||
]);
|
||||
|
@ -20,7 +20,6 @@ use Route;
|
||||
|
||||
class ContactLoginController extends Controller
|
||||
{
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
protected $redirectTo = '/client/dashboard';
|
||||
@ -32,9 +31,7 @@ class ContactLoginController extends Controller
|
||||
|
||||
public function showLoginForm()
|
||||
{
|
||||
|
||||
return view('portal.default.auth.login');
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -63,18 +60,17 @@ class ContactLoginController extends Controller
|
||||
|
||||
public function authenticated(Request $request, ClientContact $client)
|
||||
{
|
||||
|
||||
Auth::guard('contact')->login($client, true);
|
||||
|
||||
if(session()->get('url.intended'))
|
||||
if (session()->get('url.intended')) {
|
||||
return redirect(session()->get('url.intended'));
|
||||
}
|
||||
|
||||
return redirect(route('client.dashboard'));
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
|
||||
Auth::guard('contact')->logout();
|
||||
|
||||
return redirect('/client/login');
|
||||
|
@ -115,5 +115,4 @@ class ForgotPasswordController extends Controller
|
||||
? response()->json(['message' => 'Reset link sent to your email.', 'status' => true], 201)
|
||||
: response()->json(['message' => 'Email not found', 'status' => false], 401);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,9 +72,7 @@ class LoginController extends BaseController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,17 +168,13 @@ class LoginController extends BaseController
|
||||
}
|
||||
|
||||
if ($this->attemptLogin($request)) {
|
||||
|
||||
$user = $this->guard()->user();
|
||||
|
||||
$user->setCompany($user->company_user->account->default_company);
|
||||
|
||||
$ct = CompanyUser::whereUserId($user->id);
|
||||
return $this->listResponse($ct);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
$this->incrementLoginAttempts($request);
|
||||
|
||||
return response()
|
||||
@ -188,7 +182,6 @@ class LoginController extends BaseController
|
||||
->header('X-App-Version', config('ninja.app_version'))
|
||||
->header('X-Api-Version', config('ninja.api_version'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,24 +239,23 @@ class LoginController extends BaseController
|
||||
{
|
||||
//'https://www.googleapis.com/auth/gmail.send','email','profile','openid'
|
||||
//
|
||||
if(request()->has('code'))
|
||||
if (request()->has('code')) {
|
||||
return $this->handleProviderCallback($provider);
|
||||
else
|
||||
} else {
|
||||
return Socialite::driver($provider)->scopes('https://www.googleapis.com/auth/gmail.send')->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function redirectToProviderAndCreate(string $provider)
|
||||
{
|
||||
|
||||
$redirect_url = config('services.' . $provider . '.redirect') . '/create';
|
||||
|
||||
if(request()->has('code'))
|
||||
if (request()->has('code')) {
|
||||
return $this->handleProviderCallbackAndCreate($provider);
|
||||
else
|
||||
} else {
|
||||
return Socialite::driver($provider)->scopes('https://www.googleapis.com/auth/gmail.send')->redirectUrl($redirect_url)->redirect();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -278,16 +270,13 @@ class LoginController extends BaseController
|
||||
->user();
|
||||
|
||||
/* Handle existing users who attempt to create another account with existing OAuth credentials */
|
||||
if($user = OAuth::handleAuth($socialite_user, $provider))
|
||||
{
|
||||
if ($user = OAuth::handleAuth($socialite_user, $provider)) {
|
||||
$user->oauth_user_token = $socialite_user->refreshToken;
|
||||
$user->save();
|
||||
Auth::login($user, true);
|
||||
|
||||
return redirect($this->redirectTo);
|
||||
}
|
||||
else if(MultiDB::checkUserEmailExists($socialite_user->getEmail()))
|
||||
{
|
||||
} elseif (MultiDB::checkUserEmailExists($socialite_user->getEmail())) {
|
||||
Session::flash('error', 'User exists in system, but not with this authentication method'); //todo add translations
|
||||
|
||||
return view('auth.login');
|
||||
@ -317,7 +306,6 @@ class LoginController extends BaseController
|
||||
|
||||
return redirect($this->redirectTo)->withCookie($cookie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,7 +315,6 @@ class LoginController extends BaseController
|
||||
*/
|
||||
public function handleProviderCallback(string $provider)
|
||||
{
|
||||
|
||||
$redirect_url = config('services.' . $provider . '.redirect');
|
||||
|
||||
$socialite_user = Socialite::driver($provider)
|
||||
@ -335,16 +322,13 @@ class LoginController extends BaseController
|
||||
->stateless()
|
||||
->user();
|
||||
|
||||
if($user = OAuth::handleAuth($socialite_user, $provider))
|
||||
{
|
||||
if ($user = OAuth::handleAuth($socialite_user, $provider)) {
|
||||
$user->oauth_user_token = $socialite_user->token;
|
||||
$user->save();
|
||||
Auth::login($user, true);
|
||||
|
||||
return redirect($this->redirectTo);
|
||||
}
|
||||
else if(MultiDB::checkUserEmailExists($socialite_user->getEmail()))
|
||||
{
|
||||
} elseif (MultiDB::checkUserEmailExists($socialite_user->getEmail())) {
|
||||
Session::flash('error', 'User exists in system, but not with this authentication method'); //todo add translations
|
||||
|
||||
return view('auth.login');
|
||||
@ -372,8 +356,6 @@ class LoginController extends BaseController
|
||||
|
||||
return redirect($this->redirectTo)->withCookie($cookie);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,7 +372,6 @@ class LoginController extends BaseController
|
||||
*/
|
||||
public function oauthApiLogin()
|
||||
{
|
||||
|
||||
$user = false;
|
||||
|
||||
$oauth = new OAuth();
|
||||
@ -401,11 +382,8 @@ class LoginController extends BaseController
|
||||
$ct = CompanyUser::whereUserId($user);
|
||||
return $this->listResponse($ct);
|
||||
// return $this->itemResponse($user);
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return $this->errorResponse(['message' => 'Invalid credentials'], 401);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -56,26 +56,21 @@ class BaseController extends Controller
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->manager = new Manager();
|
||||
|
||||
$this->forced_includes = [];
|
||||
|
||||
$this->forced_index = 'data';
|
||||
|
||||
}
|
||||
|
||||
private function buildManager()
|
||||
{
|
||||
$include = '';
|
||||
|
||||
if(request()->has('first_load') && request()->input('first_load') == 'true')
|
||||
{
|
||||
if (request()->has('first_load') && request()->input('first_load') == 'true') {
|
||||
|
||||
/* For very large accounts, we reduce the includes automatically */
|
||||
if(auth()->user()->getCompany()->clients->count() > 1000)
|
||||
{
|
||||
|
||||
if (auth()->user()->getCompany()->clients->count() > 1000) {
|
||||
$include = [
|
||||
'account',
|
||||
'user.company_user',
|
||||
@ -91,11 +86,7 @@ class BaseController extends Controller
|
||||
'company.payments',
|
||||
'company.quotes',
|
||||
];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
} else {
|
||||
$include = [
|
||||
'account',
|
||||
'user.company_user',
|
||||
@ -111,48 +102,30 @@ class BaseController extends Controller
|
||||
// 'company.payments',
|
||||
// 'company.quotes',
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$include = array_merge($this->forced_includes, $include);
|
||||
|
||||
$include = implode(",", $include);
|
||||
|
||||
}
|
||||
else if(request()->input('include') !== null)
|
||||
{
|
||||
|
||||
} elseif (request()->input('include') !== null) {
|
||||
$request_include = explode(",", request()->input('include'));
|
||||
|
||||
$include = array_merge($this->forced_includes, $request_include);
|
||||
|
||||
$include = implode(",", $include);
|
||||
|
||||
}
|
||||
else if(count($this->forced_includes) >= 1)
|
||||
{
|
||||
|
||||
} elseif (count($this->forced_includes) >= 1) {
|
||||
$include = implode(",", $this->forced_includes);
|
||||
|
||||
}
|
||||
|
||||
$this->manager->parseIncludes($include);
|
||||
|
||||
$this->serializer = request()->input('serializer') ?: EntityTransformer::API_SERIALIZER_ARRAY;
|
||||
|
||||
if ($this->serializer === EntityTransformer::API_SERIALIZER_JSON)
|
||||
{
|
||||
|
||||
if ($this->serializer === EntityTransformer::API_SERIALIZER_JSON) {
|
||||
$this->manager->setSerializer(new JsonApiSerializer());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
} else {
|
||||
$this->manager->setSerializer(new ArraySerializer());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,34 +134,27 @@ class BaseController extends Controller
|
||||
*/
|
||||
public function notFound()
|
||||
{
|
||||
|
||||
return response()->json(['message' => '404 | Nothing to see here!'], 404)
|
||||
->header('X-API-VERSION', config('ninja.api_version'))
|
||||
->header('X-APP-VERSION', config('ninja.app_version'));
|
||||
|
||||
}
|
||||
|
||||
public function notFoundClient()
|
||||
{
|
||||
|
||||
return abort(404);
|
||||
|
||||
}
|
||||
|
||||
protected function errorResponse($response, $httpErrorCode = 400)
|
||||
{
|
||||
|
||||
$error['error'] = $response;
|
||||
$error = json_encode($error, JSON_PRETTY_PRINT);
|
||||
$headers = self::getApiHeaders();
|
||||
|
||||
return response()->make($error, $httpErrorCode, $headers);
|
||||
|
||||
}
|
||||
|
||||
protected function listResponse($query)
|
||||
{
|
||||
|
||||
$this->buildManager();
|
||||
|
||||
$transformer = new $this->entity_transformer(Input::get('serializer'));
|
||||
@ -199,16 +165,12 @@ class BaseController extends Controller
|
||||
|
||||
$query->with($includes);
|
||||
|
||||
if (auth()->user()->cannot('view_'.$this->entity_type))
|
||||
{
|
||||
|
||||
if($this->entity_type == Company::class){
|
||||
if (auth()->user()->cannot('view_'.$this->entity_type)) {
|
||||
if ($this->entity_type == Company::class) {
|
||||
//no user keys exist on the company table, so we need to skip
|
||||
}
|
||||
else if ($this->entity_type == User::class) {
|
||||
} elseif ($this->entity_type == User::class) {
|
||||
$query->where('id', '=', auth()->user()->id);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$query->where('user_id', '=', auth()->user()->id);
|
||||
}
|
||||
}
|
||||
@ -216,12 +178,10 @@ class BaseController extends Controller
|
||||
$data = $this->createCollection($query, $transformer, $this->entity_type);
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
protected function createCollection($query, $transformer, $entity_type)
|
||||
{
|
||||
|
||||
$this->buildManager();
|
||||
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) {
|
||||
@ -240,12 +200,10 @@ class BaseController extends Controller
|
||||
}
|
||||
|
||||
return $this->manager->createData($resource)->toArray();
|
||||
|
||||
}
|
||||
|
||||
protected function response($response)
|
||||
{
|
||||
|
||||
$index = request()->input('index') ?: $this->forced_index;
|
||||
|
||||
if ($index == 'none') {
|
||||
@ -261,9 +219,9 @@ class BaseController extends Controller
|
||||
unset($response[$index]['meta']);
|
||||
}
|
||||
|
||||
if(request()->include_static)
|
||||
if (request()->include_static) {
|
||||
$response['static'] = Statics::company(auth()->user()->getCompany()->getLocale());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ksort($response);
|
||||
@ -273,42 +231,38 @@ class BaseController extends Controller
|
||||
|
||||
|
||||
return response()->make($response, 200, $headers);
|
||||
|
||||
}
|
||||
|
||||
protected function itemResponse($item)
|
||||
{
|
||||
|
||||
$this->buildManager();
|
||||
|
||||
$transformer = new $this->entity_transformer(Input::get('serializer'));
|
||||
|
||||
$data = $this->createItem($item, $transformer, $this->entity_type);
|
||||
|
||||
if(request()->include_static)
|
||||
if (request()->include_static) {
|
||||
$data['static'] = Statics::company(auth()->user()->getCompany()->getLocale());
|
||||
}
|
||||
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
protected function createItem($data, $transformer, $entity_type)
|
||||
{
|
||||
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON)
|
||||
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) {
|
||||
$entity_type = null;
|
||||
}
|
||||
|
||||
|
||||
$resource = new Item($data, $transformer, $entity_type);
|
||||
|
||||
return $this->manager->createData($resource)->toArray();
|
||||
|
||||
}
|
||||
|
||||
public static function getApiHeaders($count = 0)
|
||||
{
|
||||
|
||||
return [
|
||||
'Content-Type' => 'application/json',
|
||||
//'Access-Control-Allow-Origin' => '*',
|
||||
@ -322,12 +276,10 @@ class BaseController extends Controller
|
||||
//'X-Rate-Limit-Remaining' - The number of remaining requests in the current period
|
||||
//'X-Rate-Limit-Reset' - The number of seconds left in the current period,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
protected function getRequestIncludes($data)
|
||||
{
|
||||
|
||||
$included = request()->input('include');
|
||||
$included = explode(',', $included);
|
||||
|
||||
@ -341,5 +293,4 @@ class BaseController extends Controller
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
@ -70,7 +70,6 @@ class ClientController extends BaseController
|
||||
parent::__construct();
|
||||
|
||||
$this->client_repo = $client_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,11 +110,9 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function index(ClientFilters $filters)
|
||||
{
|
||||
|
||||
$clients = Client::filter($filters);
|
||||
|
||||
return $this->listResponse($clients);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,9 +167,7 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function show(ShowClientRequest $request, Client $client)
|
||||
{
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,9 +222,7 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function edit(EditClientRequest $request, Client $client)
|
||||
{
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,13 +279,14 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function update(UpdateClientRequest $request, Client $client)
|
||||
{
|
||||
if($request->entityIsDeleted($client))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$client = $this->client_repo->save($request->all(), $client);
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
|
||||
|
||||
return $this->itemResponse($client->fresh());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,11 +330,9 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function create(CreateClientRequest $request)
|
||||
{
|
||||
|
||||
$client = ClientFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,7 +377,6 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function store(StoreClientRequest $request)
|
||||
{
|
||||
|
||||
$client = $this->client_repo->save($request->all(), ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$client->load('contacts', 'primary_contact');
|
||||
@ -393,7 +384,6 @@ class ClientController extends BaseController
|
||||
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -507,15 +497,15 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
$clients = Client::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$clients->each(function ($client, $key) use($action){
|
||||
if(auth()->user()->can('edit', $client))
|
||||
$clients->each(function ($client, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $client)) {
|
||||
$this->client_repo->{$action}($client);
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Client::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
@ -530,5 +520,4 @@ class ClientController extends BaseController
|
||||
{
|
||||
//todo
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ class DocumentController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class InvitationController extends Controller
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use MakesDates;
|
||||
|
||||
@ -36,26 +35,22 @@ class InvitationController extends Controller
|
||||
|
||||
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
|
||||
|
||||
if($invitation){
|
||||
|
||||
if((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false)
|
||||
if ($invitation) {
|
||||
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
||||
$this->middleware('auth:contact');
|
||||
else
|
||||
} else {
|
||||
auth()->guard('contact')->login($invitation->contact, false);
|
||||
}
|
||||
|
||||
$invitation->markViewed();
|
||||
|
||||
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
||||
|
||||
}
|
||||
else
|
||||
} else {
|
||||
abort(404);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function routerForIframe(string $entity, string $client_hash, string $invitation_key)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ use ZipStream\ZipStream;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use MakesDates;
|
||||
/**
|
||||
@ -51,18 +50,17 @@ class InvoiceController extends Controller
|
||||
$invoices = Invoice::filter($filters)->with('client', 'client.country');
|
||||
|
||||
if (request()->ajax()) {
|
||||
|
||||
return DataTables::of($invoices)->addColumn('action', function ($invoice) {
|
||||
return $this->buildClientButtons($invoice);
|
||||
})
|
||||
->addColumn('checkbox', function ($invoice){
|
||||
->addColumn('checkbox', function ($invoice) {
|
||||
return '<input type="checkbox" name="hashed_ids[]" value="'. $invoice->hashed_id .'"/>';
|
||||
})
|
||||
->editColumn('status_id', function ($invoice){
|
||||
->editColumn('status_id', function ($invoice) {
|
||||
return Invoice::badgeForStatus($invoice->status);
|
||||
})->editColumn('date', function ($invoice){
|
||||
})->editColumn('date', function ($invoice) {
|
||||
return $this->formatDate($invoice->date, $invoice->client->date_format());
|
||||
})->editColumn('due_date', function ($invoice){
|
||||
})->editColumn('due_date', function ($invoice) {
|
||||
return $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
||||
})->editColumn('balance', function ($invoice) {
|
||||
return Number::formatMoney($invoice->balance, $invoice->client);
|
||||
@ -76,14 +74,13 @@ class InvoiceController extends Controller
|
||||
$data['html'] = $builder;
|
||||
|
||||
return view('portal.default.invoices.index', $data);
|
||||
|
||||
}
|
||||
|
||||
private function buildClientButtons($invoice)
|
||||
{
|
||||
$buttons = '<div>';
|
||||
|
||||
if($invoice->isPayable()){
|
||||
if ($invoice->isPayable()) {
|
||||
$buttons .= "<button type=\"button\" class=\"btn btn-sm btn-info\" onclick=\"payInvoice('".$invoice->hashed_id."')\"><i class=\"glyphicon glyphicon-edit\"></i>".ctrans('texts.pay_now')."</button>";
|
||||
// $buttons .= '<a href="/client/invoices/'. $invoice->hashed_id .'" class="btn btn-sm btn-info"><i class="glyphicon glyphicon-edit"></i>'.ctrans('texts.pay_now').'</a>';
|
||||
}
|
||||
@ -117,34 +114,33 @@ class InvoiceController extends Controller
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
$transformed_ids = $this->transformKeys(explode(",", request()->input('hashed_ids')));
|
||||
|
||||
$transformed_ids = $this->transformKeys(explode(",",request()->input('hashed_ids')));
|
||||
|
||||
if(request()->input('action') == 'payment')
|
||||
if (request()->input('action') == 'payment') {
|
||||
return $this->makePayment($transformed_ids);
|
||||
else if(request()->input('action') == 'download')
|
||||
} elseif (request()->input('action') == 'download') {
|
||||
return $this->downloadInvoicePDF($transformed_ids);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function makePayment(array $ids)
|
||||
{
|
||||
|
||||
$invoices = Invoice::whereIn('id', $ids)
|
||||
->whereClientId(auth()->user()->client->id)
|
||||
->get();
|
||||
|
||||
$total = $invoices->sum('balance');
|
||||
|
||||
$invoices = $invoices->filter(function ($invoice){
|
||||
$invoices = $invoices->filter(function ($invoice) {
|
||||
return $invoice->isPayable();
|
||||
});
|
||||
|
||||
if($invoices->count() == 0)
|
||||
if ($invoices->count() == 0) {
|
||||
return back()->with(['warning' => 'No payable invoices selected']);
|
||||
}
|
||||
|
||||
$invoices->map(function ($invoice){
|
||||
$invoices->map(function ($invoice) {
|
||||
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
|
||||
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
||||
return $invoice;
|
||||
@ -164,7 +160,6 @@ class InvoiceController extends Controller
|
||||
];
|
||||
|
||||
return view('portal.default.invoices.payment', $data);
|
||||
|
||||
}
|
||||
|
||||
private function downloadInvoicePDF(array $ids)
|
||||
@ -174,12 +169,14 @@ class InvoiceController extends Controller
|
||||
->get();
|
||||
|
||||
//generate pdf's of invoices locally
|
||||
if(!$invoices || $invoices->count() == 0)
|
||||
if (!$invoices || $invoices->count() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if only 1 pdf, output to buffer for download
|
||||
if($invoices->count() == 1)
|
||||
if ($invoices->count() == 1) {
|
||||
return response()->download(public_path($invoices->first()->pdf_file_path()));
|
||||
}
|
||||
|
||||
|
||||
# enable output of HTTP headers
|
||||
@ -189,15 +186,11 @@ class InvoiceController extends Controller
|
||||
# create a new zipstream object
|
||||
$zip = new ZipStream(date('Y-m-d') . '_' . str_replace(' ', '_', trans('texts.invoices')).".zip", $options);
|
||||
|
||||
foreach($invoices as $invoice){
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$zip->addFileFromPath(basename($invoice->pdf_file_path()), public_path($invoice->pdf_file_path()));
|
||||
}
|
||||
|
||||
# finish the zip stream
|
||||
$zip->finish();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ use Yajra\DataTables\Html\Builder;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use MakesDates;
|
||||
|
||||
@ -46,19 +45,18 @@ class PaymentController extends Controller
|
||||
public function index(PaymentFilters $filters, Builder $builder)
|
||||
{
|
||||
//$payments = Payment::filter($filters);
|
||||
$payments = Payment::with('type','client');
|
||||
$payments = Payment::with('type', 'client');
|
||||
|
||||
if (request()->ajax()) {
|
||||
|
||||
return DataTables::of($payments)->addColumn('action', function ($payment) {
|
||||
return '<a href="/client/payments/'. $payment->hashed_id .'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i>'.ctrans('texts.view').'</a>';
|
||||
})->editColumn('type_id', function ($payment) {
|
||||
return $payment->type->name;
|
||||
})
|
||||
->editColumn('status_id', function ($payment){
|
||||
->editColumn('status_id', function ($payment) {
|
||||
return Payment::badgeForStatus($payment->status_id);
|
||||
})
|
||||
->editColumn('date', function ($payment){
|
||||
->editColumn('date', function ($payment) {
|
||||
//return $payment->date;
|
||||
return $payment->formatDate($payment->date, $payment->client->date_format());
|
||||
})
|
||||
@ -67,13 +65,11 @@ class PaymentController extends Controller
|
||||
})
|
||||
->rawColumns(['action', 'status_id','type_id'])
|
||||
->make(true);
|
||||
|
||||
}
|
||||
|
||||
$data['html'] = $builder;
|
||||
|
||||
return view('portal.default.payments.index', $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +86,6 @@ class PaymentController extends Controller
|
||||
$data['payment'] = $payment;
|
||||
|
||||
return view('portal.default.payments.show', $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,21 +98,21 @@ class PaymentController extends Controller
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys(explode(",",request()->input('hashed_ids'))))
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys(explode(",", request()->input('hashed_ids'))))
|
||||
->whereClientId(auth()->user()->client->id)
|
||||
->get();
|
||||
|
||||
$amount = $invoices->sum('balance');
|
||||
|
||||
$invoices = $invoices->filter(function ($invoice){
|
||||
$invoices = $invoices->filter(function ($invoice) {
|
||||
return $invoice->isPayable();
|
||||
});
|
||||
|
||||
if($invoices->count() == 0)
|
||||
if ($invoices->count() == 0) {
|
||||
return back()->with(['warning' => 'No payable invoices selected']);
|
||||
}
|
||||
|
||||
$invoices->map(function ($invoice){
|
||||
$invoices->map(function ($invoice) {
|
||||
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
|
||||
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
||||
return $invoice;
|
||||
@ -140,12 +135,11 @@ class PaymentController extends Controller
|
||||
'amount_with_fee' => $amount + $gateway->calcGatewayFee($amount),
|
||||
'token' => auth()->user()->client->gateway_token($gateway->id, $payment_method_id),
|
||||
'payment_method_id' => $payment_method_id,
|
||||
'hashed_ids' => explode(",",request()->input('hashed_ids')),
|
||||
'hashed_ids' => explode(",", request()->input('hashed_ids')),
|
||||
];
|
||||
|
||||
|
||||
return $gateway->driver(auth()->user()->client)->processPaymentView($data);
|
||||
|
||||
}
|
||||
|
||||
public function response(Request $request)
|
||||
@ -153,7 +147,5 @@ class PaymentController extends Controller
|
||||
$gateway = CompanyGateway::find($request->input('company_gateway_id'));
|
||||
|
||||
return $gateway->driver(auth()->user()->client)->processPaymentResponse($request);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,14 +17,10 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PaymentHookController extends Controller
|
||||
{
|
||||
|
||||
public function process($company_gateway_id, $gateway_type_id)
|
||||
{
|
||||
|
||||
$gateway = Gateway::find($company_gateway_id);
|
||||
|
||||
dd(request()->input());
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -36,7 +36,6 @@ class PaymentMethodController extends Controller
|
||||
$payment_methods->with('gateway_type');
|
||||
|
||||
if (request()->ajax()) {
|
||||
|
||||
return DataTables::of($payment_methods)->addColumn('action', function ($payment_method) {
|
||||
return '<a href="/client/payment_methods/' . $payment_method->hashed_id . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i>' . ctrans('texts.view') . '</a>';
|
||||
})
|
||||
@ -47,24 +46,26 @@ class PaymentMethodController extends Controller
|
||||
})->editColumn('is_default', function ($payment_method) {
|
||||
return $payment_method->is_default ? ctrans('texts.default') : '';
|
||||
})->editColumn('meta', function ($payment_method) {
|
||||
if (isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year))
|
||||
if (isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year)) {
|
||||
return "{$payment_method->meta->exp_month}/{$payment_method->meta->exp_year}";
|
||||
else
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
})->addColumn('last4', function ($payment_method) {
|
||||
if (isset($payment_method->meta->last4))
|
||||
if (isset($payment_method->meta->last4)) {
|
||||
return $payment_method->meta->last4;
|
||||
else
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
})->addColumn('brand', function ($payment_method) {
|
||||
if (isset($payment_method->meta->brand))
|
||||
if (isset($payment_method->meta->brand)) {
|
||||
return $payment_method->meta->brand;
|
||||
else
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
})
|
||||
->rawColumns(['action', 'status_id', 'last4', 'brand'])
|
||||
->make(true);
|
||||
|
||||
}
|
||||
|
||||
$data['html'] = $builder;
|
||||
@ -101,7 +102,6 @@ class PaymentMethodController extends Controller
|
||||
$gateway = auth()->user()->client->getCreditCardGateway();
|
||||
|
||||
return $gateway->driver(auth()->user()->client)->authorizeCreditCardResponse($request);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,10 +45,10 @@ class ProfileController extends Controller
|
||||
/* Dropzone configuration */
|
||||
$data = [
|
||||
'params' => [
|
||||
'is_avatar' => TRUE,
|
||||
'is_avatar' => true,
|
||||
],
|
||||
'url' => '/client/document',
|
||||
'multi_upload' => FALSE,
|
||||
'multi_upload' => false,
|
||||
];
|
||||
|
||||
return view('portal.default.profile.index', $data);
|
||||
@ -63,12 +63,12 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function update(UpdateContactRequest $request, ClientContact $client_contact)
|
||||
{
|
||||
|
||||
$client_contact->fill($request->all());
|
||||
|
||||
//update password if needed
|
||||
if($request->input('password'))
|
||||
if ($request->input('password')) {
|
||||
$client_contact->password = Hash::make($request->input('password'));
|
||||
}
|
||||
|
||||
$client_contact->save();
|
||||
|
||||
@ -79,17 +79,15 @@ class ProfileController extends Controller
|
||||
|
||||
public function updateClient(UpdateClientRequest $request, ClientContact $client_contact)
|
||||
{
|
||||
|
||||
$client = $client_contact->client;
|
||||
|
||||
//update avatar if needed
|
||||
if($request->file('logo'))
|
||||
{
|
||||
if ($request->file('logo')) {
|
||||
$path = UploadAvatar::dispatchNow($request->file('logo'), auth()->user()->client->client_hash);
|
||||
|
||||
if($path)
|
||||
if ($path) {
|
||||
$client->logo = $path;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$client->fill($request->all());
|
||||
|
@ -33,7 +33,6 @@ use Yajra\DataTables\Html\Builder;
|
||||
|
||||
class RecurringInvoiceController extends Controller
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use MakesDates;
|
||||
/**
|
||||
@ -52,33 +51,30 @@ class RecurringInvoiceController extends Controller
|
||||
->get();
|
||||
|
||||
if (request()->ajax()) {
|
||||
|
||||
return DataTables::of($invoices)->addColumn('action', function ($invoice) {
|
||||
return '<a href="/client/recurring_invoices/'. $invoice->hashed_id .'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i>'.ctrans('texts.view').'</a>';
|
||||
})->addColumn('frequency_id', function ($invoice) {
|
||||
return RecurringInvoice::frequencyForKey($invoice->frequency_id);
|
||||
})
|
||||
->editColumn('status_id', function ($invoice){
|
||||
->editColumn('status_id', function ($invoice) {
|
||||
return RecurringInvoice::badgeForStatus($invoice->status);
|
||||
})
|
||||
->editColumn('start_date', function ($invoice){
|
||||
->editColumn('start_date', function ($invoice) {
|
||||
return $this->formatDate($invoice->date, $invoice->client->date_format());
|
||||
})
|
||||
->editColumn('next_send_date', function ($invoice){
|
||||
->editColumn('next_send_date', function ($invoice) {
|
||||
return $this->formatDate($invoice->next_send_date, $invoice->client->date_format());
|
||||
})
|
||||
->editColumn('amount', function ($invoice){
|
||||
->editColumn('amount', function ($invoice) {
|
||||
return Number::formatMoney($invoice->amount, $invoice->client);
|
||||
})
|
||||
->rawColumns(['action', 'status_id'])
|
||||
->make(true);
|
||||
|
||||
}
|
||||
|
||||
$data['html'] = $builder;
|
||||
|
||||
return view('portal.default.recurring_invoices.index', $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,19 +86,16 @@ class RecurringInvoiceController extends Controller
|
||||
*/
|
||||
public function show(ShowRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
|
||||
$data = [
|
||||
'invoice' => $recurring_invoice->load('invoices'),
|
||||
];
|
||||
|
||||
return view('portal.default.recurring_invoices.show', $data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function requestCancellation(Request $request, RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
|
||||
$data = [
|
||||
'invoice' => $recurring_invoice
|
||||
];
|
||||
@ -112,7 +105,5 @@ class RecurringInvoiceController extends Controller
|
||||
$recurring_invoice->user->notify(new ClientContactRequestCancellation($recurring_invoice, auth()->user()));
|
||||
|
||||
return view('portal.default.recurring_invoices.request_cancellation', $data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,12 +17,9 @@ namespace App\Http\Controllers;
|
||||
*/
|
||||
class ClientStatementController extends BaseController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,7 +29,6 @@ class ClientStatementController extends BaseController
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,7 +38,5 @@ class ClientStatementController extends BaseController
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -60,11 +60,9 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function __construct(CompanyRepository $company_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->company_repo = $company_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,11 +106,9 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$companies = Company::whereAccountId(auth()->user()->company()->account->id);
|
||||
|
||||
return $this->listResponse($companies);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,7 +152,6 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function create(CreateCompanyRequest $request)
|
||||
{
|
||||
|
||||
$company = CompanyFactory::create(auth()->user()->company()->account->id);
|
||||
|
||||
return $this->itemResponse($company);
|
||||
@ -240,7 +235,6 @@ class CompanyController extends BaseController
|
||||
$ct = CompanyUser::whereUserId(auth()->user()->id)->whereCompanyId($company->id);
|
||||
|
||||
return $this->listResponse($ct);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,9 +289,7 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function show(ShowCompanyRequest $request, Company $company)
|
||||
{
|
||||
|
||||
return $this->itemResponse($company);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -352,9 +344,7 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function edit(EditCompanyRequest $request, Company $company)
|
||||
{
|
||||
|
||||
return $this->itemResponse($company);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -470,7 +460,6 @@ class CompanyController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyCompanyRequest $request, Company $company)
|
||||
{
|
||||
|
||||
$company->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
@ -47,11 +47,9 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function __construct(CompanyRepository $company_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->company_repo = $company_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +98,6 @@ class CompanyGatewayController extends BaseController
|
||||
$company_gateways = CompanyGateway::whereCompanyId(auth()->user()->company()->id);
|
||||
|
||||
return $this->listResponse($company_gateways);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,7 +141,6 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function create(CreateCompanyGatewayRequest $request)
|
||||
{
|
||||
|
||||
$company_gateway = CompanyGatewayFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($company_gateway);
|
||||
@ -192,13 +188,11 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function store(StoreCompanyGatewayRequest $request)
|
||||
{
|
||||
|
||||
$company_gateway = CompanyGatewayFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
$company_gateway->fill($request->all());
|
||||
$company_gateway->save();
|
||||
|
||||
return $this->itemResponse($company_gateway);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,9 +247,7 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function show(ShowCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
||||
{
|
||||
|
||||
return $this->itemResponse($company_gateway);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -310,9 +302,7 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function edit(EditCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
||||
{
|
||||
|
||||
return $this->itemResponse($company_gateway);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -368,11 +358,11 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function update(UpdateCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
||||
{
|
||||
|
||||
$company_gateway->fill($request->all());
|
||||
|
||||
if(!$request->has('fees_and_limits'))
|
||||
if (!$request->has('fees_and_limits')) {
|
||||
$company_gateway->fees_and_limits = '';
|
||||
}
|
||||
|
||||
$company_gateway->save();
|
||||
|
||||
@ -430,10 +420,8 @@ class CompanyGatewayController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyCompanyGatewayRequest $request, CompanyGateway $company_gateway)
|
||||
{
|
||||
|
||||
$company_gateway->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,7 @@ class InvoiceController extends BaseController
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,10 +40,8 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function index(InvoiceFilters $filters)
|
||||
{
|
||||
|
||||
$invoices = Invoice::filter($filters);
|
||||
|
||||
return $this->listResponse($invoices);
|
||||
|
||||
}
|
||||
}
|
@ -54,9 +54,7 @@ class LoginController extends BaseController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +66,6 @@ class LoginController extends BaseController
|
||||
*/
|
||||
public function apiLogin(Request $request)
|
||||
{
|
||||
|
||||
Auth::shouldUse('contact');
|
||||
|
||||
$this->validateLogin($request);
|
||||
@ -79,15 +76,13 @@ class LoginController extends BaseController
|
||||
return response()->json(['message' => 'Too many login attempts, you are being throttled']);
|
||||
}
|
||||
|
||||
if ($this->attemptLogin($request))
|
||||
if ($this->attemptLogin($request)) {
|
||||
return $this->itemResponse($this->guard()->user());
|
||||
else {
|
||||
|
||||
} else {
|
||||
$this->incrementLoginAttempts($request);
|
||||
|
||||
return response()->json(['message' => ctrans('texts.invalid_credentials')]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,24 +94,23 @@ class LoginController extends BaseController
|
||||
{
|
||||
//'https://www.googleapis.com/auth/gmail.send','email','profile','openid'
|
||||
//
|
||||
if(request()->has('code'))
|
||||
if (request()->has('code')) {
|
||||
return $this->handleProviderCallback($provider);
|
||||
else
|
||||
} else {
|
||||
return Socialite::driver($provider)->scopes()->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function redirectToProviderAndCreate(string $provider)
|
||||
{
|
||||
|
||||
$redirect_url = config('services.' . $provider . '.redirect') . '/create';
|
||||
|
||||
if(request()->has('code'))
|
||||
if (request()->has('code')) {
|
||||
return $this->handleProviderCallbackAndCreate($provider);
|
||||
else
|
||||
} else {
|
||||
return Socialite::driver($provider)->redirectUrl($redirect_url)->redirect();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -225,18 +219,17 @@ class LoginController extends BaseController
|
||||
*/
|
||||
public function oauthApiLogin()
|
||||
{
|
||||
|
||||
$user = false;
|
||||
|
||||
$oauth = new OAuth();
|
||||
|
||||
$user = $oauth->getProvider(request()->input('provider'))->getTokenResponse(request()->input('token'));
|
||||
|
||||
if ($user)
|
||||
if ($user) {
|
||||
return $this->itemResponse($user);
|
||||
else
|
||||
} else {
|
||||
return $this->errorResponse(['message' => 'Invalid credentials'], 401);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
class DashboardController extends BaseController
|
||||
{
|
||||
/**
|
||||
@ -22,7 +21,6 @@ class DashboardController extends BaseController
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:user');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,6 +33,4 @@ class DashboardController extends BaseController
|
||||
// dd(json_decode(auth()->user()->permissions(),true));
|
||||
return view('dashboard.index');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Factory\GroupSettingFactory;
|
||||
use App\Http\Requests\GroupSetting\CreateGroupSettingRequest;
|
||||
use App\Http\Requests\GroupSetting\DestroyGroupSettingRequest;
|
||||
@ -189,7 +188,6 @@ class GroupSettingController extends BaseController
|
||||
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,13 +353,11 @@ class GroupSettingController extends BaseController
|
||||
*/
|
||||
public function update(UpdateGroupSettingRequest $request, GroupSetting $group_setting)
|
||||
{
|
||||
|
||||
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -418,6 +414,5 @@ class GroupSettingController extends BaseController
|
||||
$group_setting->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class InvoiceController extends BaseController
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = Invoice::class;
|
||||
@ -62,11 +61,9 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function __construct(InvoiceRepository $invoice_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->invoice_repo = $invoice_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,11 +109,9 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function index(InvoiceFilters $filters)
|
||||
{
|
||||
|
||||
$invoices = Invoice::filter($filters);
|
||||
|
||||
return $this->listResponse($invoices);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,11 +156,9 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function create(CreateInvoiceRequest $request)
|
||||
{
|
||||
|
||||
$invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -211,7 +204,6 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function store(StoreInvoiceRequest $request)
|
||||
{
|
||||
|
||||
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$invoice = StoreInvoice::dispatchNow($invoice, $request->all(), $invoice->company); //todo potentially this may return mixed ie PDF/$invoice... need to revisit when we implement UI
|
||||
@ -219,7 +211,6 @@ class InvoiceController extends BaseController
|
||||
event(new InvoiceWasCreated($invoice, $invoice->company));
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,9 +267,7 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function show(ShowInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -334,9 +323,7 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function edit(EditInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -393,13 +380,14 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function update(UpdateInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
if($request->entityIsDeleted($invoice))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$invoice = $this->invoice_repo->save($request->all(), $invoice);
|
||||
|
||||
event(new InvoiceWasUpdated($invoice, $invoice->company));
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -454,11 +442,9 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyInvoiceRequest $request, Invoice $invoice)
|
||||
{
|
||||
|
||||
$invoice->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -515,27 +501,26 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids));
|
||||
|
||||
if(!$invoices)
|
||||
if (!$invoices) {
|
||||
return response()->json(['message'=>'No Invoices Found']);
|
||||
}
|
||||
|
||||
$invoices->each(function ($invoice, $key) use($action){
|
||||
$invoices->each(function ($invoice, $key) use ($action) {
|
||||
|
||||
// $this->invoice_repo->{$action}($invoice);
|
||||
|
||||
if(auth()->user()->can('edit', $invoice))
|
||||
if (auth()->user()->can('edit', $invoice)) {
|
||||
$this->performAction($invoice, $action, true);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -607,9 +592,7 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
|
||||
{
|
||||
|
||||
return $this->performAction($invoice, $action);
|
||||
|
||||
}
|
||||
|
||||
private function performAction(Invoice $invoice, $action, $bulk = false)
|
||||
@ -631,19 +614,22 @@ class InvoiceController extends BaseController
|
||||
# code...
|
||||
break;
|
||||
case 'mark_paid':
|
||||
if($invoice->balance <= 0 || $invoice->status_id == Invoice::STATUS_PAID)
|
||||
if ($invoice->balance <= 0 || $invoice->status_id == Invoice::STATUS_PAID) {
|
||||
return $this->errorResponse(['message' => 'Invoice has no balance owing'], 400);
|
||||
}
|
||||
|
||||
$invoice = MarkInvoicePaid::dispatchNow($invoice, $invoice->company);
|
||||
|
||||
if(!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->itemResponse($invoice);
|
||||
}
|
||||
break;
|
||||
case 'mark_sent':
|
||||
$invoice->markSent();
|
||||
|
||||
if(!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->itemResponse($invoice);
|
||||
}
|
||||
break;
|
||||
case 'download':
|
||||
return response()->download(public_path($invoice->pdf_file_path()));
|
||||
@ -651,25 +637,27 @@ class InvoiceController extends BaseController
|
||||
case 'archive':
|
||||
$this->invoice_repo->archive($invoice);
|
||||
|
||||
if(!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->listResponse($invoice);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
$this->invoice_repo->delete($invoice);
|
||||
|
||||
if(!$bulk)
|
||||
if (!$bulk) {
|
||||
return $this->listResponse($invoice);
|
||||
}
|
||||
break;
|
||||
case 'email':
|
||||
EmailInvoice::dispatch($invoice, $invoice->company);
|
||||
if(!$bulk)
|
||||
return response()->json(['message'=>'email sent'],200);
|
||||
if (!$bulk) {
|
||||
return response()->json(['message'=>'email sent'], 200);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return response()->json(['message' => "The requested action `{$action}` is not available."],400);
|
||||
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ class MigrationController extends BaseController
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +78,6 @@ class MigrationController extends BaseController
|
||||
*/
|
||||
public function purgeCompany(Company $company)
|
||||
{
|
||||
|
||||
$company->delete();
|
||||
|
||||
return response()->json(['message'=>'Company purged'], 200);
|
||||
@ -137,8 +135,5 @@ class MigrationController extends BaseController
|
||||
$company->save();
|
||||
|
||||
return response()->json(['message'=>'Settings preserved'], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,4 +21,3 @@
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
|
@ -27,4 +27,3 @@
|
||||
* @OA\Property(property="settings",ref="#/components/schemas/CompanySettings"),
|
||||
* )
|
||||
*/
|
||||
|
||||
|
@ -85,5 +85,3 @@
|
||||
* ),
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Filters\PaymentFilters;
|
||||
use App\Http\Requests\Payment\ActionPaymentRequest;
|
||||
@ -37,7 +36,6 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PaymentController extends BaseController
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = Payment::class;
|
||||
@ -57,11 +55,9 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function __construct(PaymentRepository $payment_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->payment_repo = $payment_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,11 +105,9 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function index(PaymentFilters $filters)
|
||||
{
|
||||
|
||||
$payments = Payment::filter($filters);
|
||||
|
||||
return $this->listResponse($payments);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,11 +153,9 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function create(CreatePaymentRequest $request)
|
||||
{
|
||||
|
||||
$payment = PaymentFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -244,11 +236,9 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function store(StorePaymentRequest $request)
|
||||
{
|
||||
|
||||
$payment = $this->payment_repo->save($request, PaymentFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,9 +295,7 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function show(ShowPaymentRequest $request, Payment $payment)
|
||||
{
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,9 +352,7 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function edit(EditPaymentRequest $request, Payment $payment)
|
||||
{
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -423,11 +409,12 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function update(UpdatePaymentRequest $request, Payment $payment)
|
||||
{
|
||||
if($request->entityIsDeleted($payment))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$payment = $this->payment_repo->save(request(), $payment);
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,7 +470,6 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyPaymentRequest $request, Payment $payment)
|
||||
{
|
||||
|
||||
ReverseInvoicePayment::dispatchNow($payment, $payment->company);
|
||||
|
||||
$payment->is_deleted = true;
|
||||
@ -491,7 +477,6 @@ class PaymentController extends BaseController
|
||||
$payment->delete();
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,22 +534,19 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$payments = Payment::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$payments->each(function ($payment, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $payment))
|
||||
$payments->each(function ($payment, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $payment)) {
|
||||
$this->payment_repo->{$action}($payment);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Payment::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -638,7 +620,6 @@ class PaymentController extends BaseController
|
||||
*/
|
||||
public function action(ActionPaymentRequest $request, Payment $payment, $action)
|
||||
{
|
||||
|
||||
switch ($action) {
|
||||
case 'clone_to_invoice':
|
||||
//$payment = CloneInvoiceFactory::create($payment, auth()->user()->id);
|
||||
@ -672,5 +653,4 @@ class PaymentController extends BaseController
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ProductController extends BaseController
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = Product::class;
|
||||
@ -41,7 +40,6 @@ class ProductController extends BaseController
|
||||
*/
|
||||
public function __construct(ProductRepository $product_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->product_repo = $product_repo;
|
||||
@ -86,11 +84,9 @@ class ProductController extends BaseController
|
||||
*/
|
||||
public function index(ProductFilters $filters)
|
||||
{
|
||||
|
||||
$products = Product::filter($filters);
|
||||
|
||||
return $this->listResponse($products);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -349,6 +345,10 @@ class ProductController extends BaseController
|
||||
*/
|
||||
public function update(UpdateProductRequest $request, Product $product)
|
||||
{
|
||||
|
||||
if($request->entityIsDeleted($product))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$product = $this->product_repo->save($request, $product);
|
||||
|
||||
return $this->itemResponse($product);
|
||||
@ -465,21 +465,18 @@ class ProductController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$products = Product::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$products->each(function ($product, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $product))
|
||||
$products->each(function ($product, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $product)) {
|
||||
$this->product_repo->{$action}($product);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Product::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ use Illuminate\Http\Request;
|
||||
|
||||
class QuoteController extends BaseController
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = Quote::class;
|
||||
@ -54,11 +53,9 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function __construct(QuoteRepository $quote_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->quote_repo = $quote_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +101,6 @@ class QuoteController extends BaseController
|
||||
|
||||
public function index(QuoteFilters $filters)
|
||||
{
|
||||
|
||||
$quotes = Quote::filter($filters);
|
||||
|
||||
return $this->listResponse($quotes);
|
||||
@ -151,11 +147,9 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function create(CreateQuoteRequest $request)
|
||||
{
|
||||
|
||||
$quote = QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,11 +195,9 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function store(StoreQuoteRequest $request)
|
||||
{
|
||||
|
||||
$quote = $this->quote_repo->save($request->all(), QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,9 +254,7 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function show(ShowQuoteRequest $request, Quote $quote)
|
||||
{
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,9 +311,7 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function edit(EditQuoteRequest $request, Quote $quote)
|
||||
{
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,11 +368,12 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function update(UpdateQuoteRequest $request, Quote $quote)
|
||||
{
|
||||
if($request->entityIsDeleted($quote))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$quote = $this->quote_repo->save($request->all(), $quote);
|
||||
|
||||
return $this->itemResponse($quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -440,11 +429,9 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyQuoteRequest $request, Quote $quote)
|
||||
{
|
||||
|
||||
$quote->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,22 +489,19 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$quotes = Quote::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$quotes->each(function ($quote, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $quote))
|
||||
$quotes->each(function ($quote, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $quote)) {
|
||||
$this->quote_repo->{$action}($quote);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -592,7 +576,6 @@ class QuoteController extends BaseController
|
||||
*/
|
||||
public function action(ActionQuoteRequest $request, Quote $quote, $action)
|
||||
{
|
||||
|
||||
switch ($action) {
|
||||
case 'clone_to_invoice':
|
||||
//$quote = CloneInvoiceFactory::create($quote, auth()->user()->id);
|
||||
@ -623,12 +606,11 @@ class QuoteController extends BaseController
|
||||
return $this->listResponse($quote);
|
||||
break;
|
||||
case 'email':
|
||||
return response()->json(['message'=>'email sent'],200);
|
||||
return response()->json(['message'=>'email sent'], 200);
|
||||
break;
|
||||
default:
|
||||
return response()->json(['message' => "The requested action `{$action}` is not available."],400);
|
||||
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -38,7 +38,6 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RecurringInvoiceController extends BaseController
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = RecurringInvoice::class;
|
||||
@ -59,11 +58,9 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function __construct(RecurringInvoiceRepository $recurring_invoice_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->recurring_invoice_repo = $recurring_invoice_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,11 +107,9 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function index(RecurringInvoiceFilters $filters)
|
||||
{
|
||||
|
||||
$recurring_invoices = RecurringInvoice::filter($filters);
|
||||
|
||||
return $this->listResponse($recurring_invoices);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,11 +155,9 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function create(CreateRecurringInvoiceRequest $request)
|
||||
{
|
||||
|
||||
$recurring_invoice = RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($recurring_invoice);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -211,11 +204,9 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function store(StoreRecurringInvoiceRequest $request)
|
||||
{
|
||||
|
||||
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
return $this->itemResponse($recurring_invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,9 +263,7 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function show(ShowRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
|
||||
return $this->itemResponse($recurring_invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -331,9 +320,7 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function edit(EditRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
|
||||
return $this->itemResponse($recurring_invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,11 +377,12 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function update(UpdateRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
if($request->entityIsDeleted($recurring_invoice))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), $recurring_invoice);
|
||||
|
||||
return $this->itemResponse($recurring_invoice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -450,11 +438,9 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
|
||||
$recurring_invoice->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -512,22 +498,19 @@ class RecurringInvoiceController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$recurring_invoices = RecurringInvoice::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $recurring_invoice))
|
||||
$recurring_invoices->each(function ($recurring_invoice, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $recurring_invoice)) {
|
||||
$this->recurring_invoice_repo->{$action}($recurring_invoice);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(RecurringInvoice::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -602,7 +585,6 @@ class RecurringInvoiceController extends BaseController
|
||||
|
||||
public function action(ActionRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice, $action)
|
||||
{
|
||||
|
||||
switch ($action) {
|
||||
case 'clone_to_RecurringInvoice':
|
||||
// $recurring_invoice = CloneRecurringInvoiceFactory::create($recurring_invoice, auth()->user()->id);
|
||||
@ -636,5 +618,4 @@ class RecurringInvoiceController extends BaseController
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RecurringQuoteController extends BaseController
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = RecurringQuote::class;
|
||||
@ -59,11 +58,9 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function __construct(RecurringQuoteRepository $recurring_quote_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->recurring_quote_repo = $recurring_quote_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,11 +107,9 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function index(RecurringQuoteFilters $filters)
|
||||
{
|
||||
|
||||
$recurring_quotes = RecurringQuote::filter($filters);
|
||||
|
||||
return $this->listResponse($recurring_quotes);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,11 +154,9 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function create(CreateRecurringQuoteRequest $request)
|
||||
{
|
||||
|
||||
$recurring_quote = RecurringQuoteFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($recurring_quote);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -209,11 +202,9 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function store(StoreRecurringQuoteRequest $request)
|
||||
{
|
||||
|
||||
$recurring_quote = $this->recurring_quote_repo->save($request, RecurringQuoteFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
return $this->itemResponse($recurring_quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,9 +261,7 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function show(ShowRecurringQuoteRequest $request, RecurringQuote $recurring_quote)
|
||||
{
|
||||
|
||||
return $this->itemResponse($recurring_quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,9 +318,7 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function edit(EditRecurringQuoteRequest $request, RecurringQuote $recurring_quote)
|
||||
{
|
||||
|
||||
return $this->itemResponse($recurring_quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -389,10 +376,12 @@ class RecurringQuoteController extends BaseController
|
||||
public function update(UpdateRecurringQuoteRequest $request, RecurringQuote $recurring_quote)
|
||||
{
|
||||
|
||||
if($request->entityIsDeleted($recurring_quote))
|
||||
return $request->disallowUpdate();
|
||||
|
||||
$recurring_quote = $this->recurring_quote_repo->save(request(), $recurring_quote);
|
||||
|
||||
return $this->itemResponse($recurring_quote);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -448,11 +437,9 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyRecurringQuoteRequest $request, RecurringQuote $recurring_quote)
|
||||
{
|
||||
|
||||
$recurring_quote->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -510,22 +497,19 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$recurring_quotes = RecurringQuote::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$recurring_quotes->each(function ($recurring_quote, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $recurring_quote))
|
||||
$recurring_quotes->each(function ($recurring_quote, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $recurring_quote)) {
|
||||
$this->recurring_quote_repo->{$action}($recurring_quote);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(RecurringQuote::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -600,7 +584,6 @@ class RecurringQuoteController extends BaseController
|
||||
*/
|
||||
public function action(ActionRecurringQuoteRequest $request, RecurringQuote $recurring_quote, $action)
|
||||
{
|
||||
|
||||
switch ($action) {
|
||||
case 'clone_to_RecurringQuote':
|
||||
// $recurring_invoice = CloneRecurringQuoteFactory::create($recurring_invoice, auth()->user()->id);
|
||||
@ -634,5 +617,4 @@ class RecurringQuoteController extends BaseController
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ class SettingsController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,5 +76,4 @@ class SendingController extends Controller
|
||||
'success' => true
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ use Illuminate\Http\Request;
|
||||
*/
|
||||
class TaxRateController extends BaseController
|
||||
{
|
||||
|
||||
protected $entity_type = TaxRate::class;
|
||||
|
||||
protected $entity_transformer = TaxRateTransformer::class;
|
||||
@ -36,7 +35,6 @@ class TaxRateController extends BaseController
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +120,6 @@ class TaxRateController extends BaseController
|
||||
{
|
||||
$tax_rate = TaxRateFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
return $this->itemResponse($tax_rate);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,7 +302,6 @@ class TaxRateController extends BaseController
|
||||
$tax_rate->save();
|
||||
|
||||
return $this->itemResponse($tax_rate);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -361,6 +357,5 @@ class TaxRateController extends BaseController
|
||||
$tax_rate->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,9 @@ use Parsedown;
|
||||
|
||||
class TemplateController extends BaseController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,12 +98,9 @@ class TemplateController extends BaseController
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
|
||||
if(request()->has('entity') && request()->has('entity_id')){
|
||||
|
||||
if (request()->has('entity') && request()->has('entity_id')) {
|
||||
$class = 'App\Models\\'.ucfirst(request()->input('entity'));
|
||||
$entity_obj = $class::whereId(request()->input('entity_id'))->company()->first();
|
||||
|
||||
}
|
||||
|
||||
$subject = request()->input('subject');
|
||||
@ -117,7 +112,5 @@ class TemplateController extends BaseController
|
||||
];
|
||||
|
||||
return response()->json($data, 200);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -31,20 +31,17 @@ trait VerifiesUserEmail
|
||||
{
|
||||
//$user = User::where('confirmation_code', $code)->first();
|
||||
|
||||
if ($user = User::whereRaw("BINARY `confirmation_code`= ?",$code)->first()) {
|
||||
|
||||
if ($user = User::whereRaw("BINARY `confirmation_code`= ?", $code)->first()) {
|
||||
$user->email_verified_at = now();
|
||||
$user->confirmation_code = null;
|
||||
$user->save();
|
||||
|
||||
return response()->json(['message' => ctrans('texts.security_confirmation')]);
|
||||
//return redirect()->route('dashboard.index')->with('message', ctrans('texts.security_confirmation'));
|
||||
|
||||
}
|
||||
|
||||
return response()->json(['message' => ctrans('texts.wrong_confirmation')]);
|
||||
|
||||
//return redirect()->route('login')->with('message', ctrans('texts.wrong_confirmation'));
|
||||
|
||||
}
|
||||
}
|
@ -22,9 +22,7 @@ class TranslationController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +51,8 @@ class TranslationController extends BaseController
|
||||
exit();
|
||||
}
|
||||
|
||||
private function easyMinify($javascript){
|
||||
private function easyMinify($javascript)
|
||||
{
|
||||
return preg_replace(array("/\s+\n/", "/\n\s+/", "/ +/"), array("\n", "\n ", " "), $javascript);
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,9 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function __construct(UserRepository $user_repo)
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->user_repo = $user_repo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,11 +103,9 @@ class UserController extends BaseController
|
||||
|
||||
public function index(UserFilters $filters)
|
||||
{
|
||||
|
||||
$users = User::filter($filters);
|
||||
|
||||
return $this->listResponse($users);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,11 +149,9 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function create(CreateUserRequest $request)
|
||||
{
|
||||
|
||||
$user = UserFactory::create();
|
||||
|
||||
return $this->itemResponse($user);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +196,6 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function store(StoreUserRequest $request)
|
||||
{
|
||||
|
||||
$company = auth()->user()->company();
|
||||
|
||||
$user = $this->user_repo->save($request->all(), $request->fetchUser());
|
||||
@ -212,7 +205,6 @@ class UserController extends BaseController
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, $user_agent);
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,9 +259,7 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function show(ShowUserRequest $request, User $user)
|
||||
{
|
||||
|
||||
return $this->itemResponse($user);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,9 +314,7 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function edit(EditUserRequest $request, User $user)
|
||||
{
|
||||
|
||||
return $this->itemResponse($user);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -382,11 +370,9 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function update(UpdateUserRequest $request, User $user)
|
||||
{
|
||||
|
||||
$user = $this->user_repo->save($request->all(), $user);
|
||||
|
||||
return $this->itemResponse($user);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -451,11 +437,9 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyUserRequest $request, User $user)
|
||||
{
|
||||
|
||||
$user->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -514,22 +498,19 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$users = User::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$users->each(function ($user, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $user))
|
||||
$users->each(function ($user, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $user)) {
|
||||
$this->user_repo->{$action}($user);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(User::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -587,7 +568,6 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function attach(AttachCompanyUserRequest $request, User $user)
|
||||
{
|
||||
|
||||
$company = auth()->user()->company();
|
||||
|
||||
$user->companies()->attach($company->id, array_merge($request->all(), ['account_id' => $company->account->id]));
|
||||
@ -595,7 +575,6 @@ class UserController extends BaseController
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->name());
|
||||
|
||||
return $this->itemResponse($user->fresh());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -652,6 +631,5 @@ class UserController extends BaseController
|
||||
$company_user->delete();
|
||||
|
||||
return response()->json(['message' => 'User detached from company'], 200);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,7 @@ class UserProfileController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,21 +25,17 @@ class ApiSecretCheck
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if( $request->header('X-API-SECRET') && ($request->header('X-API-SECRET') == config('ninja.api_secret')) )
|
||||
if ($request->header('X-API-SECRET') && ($request->header('X-API-SECRET') == config('ninja.api_secret'))) {
|
||||
return $next($request);
|
||||
else {
|
||||
|
||||
} else {
|
||||
$error = [
|
||||
'message' => 'Invalid secret',
|
||||
'errors' => []
|
||||
];
|
||||
return response()
|
||||
->json(json_encode($error, JSON_PRETTY_PRINT) ,403)
|
||||
->json(json_encode($error, JSON_PRETTY_PRINT), 403)
|
||||
->header('X-App-Version', config('ninja.app_version'))
|
||||
->header('X-Api-Version', config('ninja.api_version'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,11 @@ class ClientPortalEnabled
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if(auth()->user()->client->getSetting('enable_client_portal') === false)
|
||||
if (auth()->user()->client->getSetting('enable_client_portal') === false) {
|
||||
return redirect()->to('client/dashboard');
|
||||
}
|
||||
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -27,33 +27,19 @@ class ContactSetDb
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
|
||||
$error = [
|
||||
'message' => 'Invalid Token',
|
||||
'errors' => []
|
||||
];
|
||||
|
||||
if( $request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled'))
|
||||
{
|
||||
|
||||
if(! MultiDB::contactFindAndSetDb($request->header('X-API-TOKEN')))
|
||||
{
|
||||
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
|
||||
|
||||
if ($request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled')) {
|
||||
if (! MultiDB::contactFindAndSetDb($request->header('X-API-TOKEN'))) {
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT), 403);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
|
||||
|
||||
} else {
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT), 403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,18 +28,16 @@ class ContactTokenAuth
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if( $request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->whereRaw("BINARY `token`= ?",[$request->header('X-API-TOKEN')])->first() ) )
|
||||
{
|
||||
|
||||
if ($request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first())) {
|
||||
$error = [
|
||||
'message' => 'Authentication disabled for user.',
|
||||
'errors' => []
|
||||
];
|
||||
|
||||
//client_contact who once existed, but has been soft deleted
|
||||
if(!$client_contact)
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
|
||||
if (!$client_contact) {
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT), 403);
|
||||
}
|
||||
|
||||
|
||||
$error = [
|
||||
@ -48,26 +46,23 @@ class ContactTokenAuth
|
||||
];
|
||||
|
||||
//client_contact who has been disabled
|
||||
if($client_contact->is_locked)
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
|
||||
if ($client_contact->is_locked) {
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT), 403);
|
||||
}
|
||||
|
||||
//stateless, don't remember the contact.
|
||||
auth()->guard('contact')->login($client_contact, false);
|
||||
|
||||
event(new ContactLoggedIn($client_contact)); //todo
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
$error = [
|
||||
'message' => 'Invalid token',
|
||||
'errors' => []
|
||||
];
|
||||
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
|
||||
return response()->json(json_encode($error, JSON_PRETTY_PRINT), 403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,11 +8,9 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class Cors
|
||||
{
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if($request->getMethod() == "OPTIONS") {
|
||||
if ($request->getMethod() == "OPTIONS") {
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
// ALLOW OPTIONS METHOD
|
||||
@ -22,7 +20,6 @@ class Cors
|
||||
];
|
||||
|
||||
return Response::make('OK', 200, $headers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -37,12 +34,10 @@ class Cors
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
$response->headers->set('Access-Control-Allow-Origin' , '*');
|
||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
||||
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||
$response->headers->set('Access-Control-Allow-Headers', 'X-API-SECRET,X-API-TOKEN,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -27,9 +27,9 @@ class Locale
|
||||
App::setLocale(auth('contact')->user()->client->locale());
|
||||
} elseif (auth()->user()) {
|
||||
App::setLocale(auth()->user()->company()->getLocale());
|
||||
}
|
||||
else
|
||||
} else {
|
||||
App::setLocale(config('ninja.i18n.locale'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@ -30,36 +30,27 @@ class PasswordProtection
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
$error = [
|
||||
'message' => 'Invalid Password',
|
||||
'errors' => []
|
||||
];
|
||||
|
||||
if( $request->header('X-API-PASSWORD') )
|
||||
{
|
||||
|
||||
if(!Hash::check($request->header('X-API-PASSWORD'), auth()->user()->password))
|
||||
if ($request->header('X-API-PASSWORD')) {
|
||||
if ($request->header('X-API-PASSWORD') != auth()->user()->password) {
|
||||
return response()->json($error, 403);
|
||||
|
||||
}
|
||||
elseif (Cache::get(auth()->user()->email."_logged_in")) {
|
||||
} elseif (Cache::get(auth()->user()->email."_logged_in")) {
|
||||
return $next($request);
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
$error = [
|
||||
'message' => 'Access denied',
|
||||
'errors' => []
|
||||
];
|
||||
return response()->json($error, 412);
|
||||
|
||||
}
|
||||
|
||||
Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ class QueryLogging
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
// Enable query logging for development
|
||||
if(config('ninja.app_env') != 'production') {
|
||||
if (config('ninja.app_env') != 'production') {
|
||||
DB::enableQueryLog();
|
||||
$timeStart = microtime(true);
|
||||
}
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
if(config('ninja.app_env') != 'production') {
|
||||
if (config('ninja.app_env') != 'production') {
|
||||
|
||||
// hide requests made by debugbar
|
||||
if (strstr($request->url(), '_debugbar') === false) {
|
||||
@ -52,7 +52,6 @@ class QueryLogging
|
||||
// if($count > 50)
|
||||
// Log::info($queries);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
@ -27,37 +27,22 @@ class SetDb
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
$error = [
|
||||
'message' => 'Invalid Token',
|
||||
'errors' => []
|
||||
];
|
||||
|
||||
|
||||
if( $request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled'))
|
||||
{
|
||||
|
||||
if(! MultiDB::findAndSetDb($request->header('X-API-TOKEN')))
|
||||
{
|
||||
|
||||
if ($request->header('X-API-TOKEN') && config('ninja.db.multi_db_enabled')) {
|
||||
if (! MultiDB::findAndSetDb($request->header('X-API-TOKEN'))) {
|
||||
return response()->json($error, 403);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(!config('ninja.db.multi_db_enabled')){
|
||||
|
||||
} elseif (!config('ninja.db.multi_db_enabled')) {
|
||||
return $next($request);
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
} else {
|
||||
return response()->json($error, 403);
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user