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

Fixes for self-update (#3514)

* minor fix for payment notifications

* styleci

* Limit Self updating to self hosters only
:

* Fixes for designs

* Minor fixes for self-update
This commit is contained in:
David Bomba 2020-03-21 16:37:30 +11:00 committed by GitHub
parent d631a4954c
commit 43e57d0117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
356 changed files with 7607 additions and 8713 deletions

View File

@ -41,41 +41,32 @@ class ArtisanUpgrade extends Command
public function handle() public function handle()
{ {
set_time_limit(0); set_time_limit(0);
// Composer\Factory::getHomeDir() method // Composer\Factory::getHomeDir() method
// needs COMPOSER_HOME environment variable set // needs COMPOSER_HOME environment variable set
putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer'); putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer');
// call `composer install` command programmatically // call `composer install` command programmatically
$input = new ArrayInput(array('command' => 'install')); $input = new ArrayInput(array('command' => 'install'));
$application = new Application(); $application = new Application();
$application->setAutoExit(false); // prevent `$application->run` method from exitting the script //$application->setAutoExit(false); // prevent `$application->run` method from exitting the script
$application->run($input); $application->run($input);
try { try {
Artisan::call('migrate'); Artisan::call('migrate');
} catch (Exception $e) {
}catch(Exception $e) {
\Log::error("I wasn't able to migrate the data."); \Log::error("I wasn't able to migrate the data.");
} }
try { try {
Artisan::call('optimize'); Artisan::call('optimize');
} catch (Exception $e) {
}catch(Exception $e) {
\Log::error("I wasn't able to optimize."); \Log::error("I wasn't able to optimize.");
} }
try { try {
Artisan::call('queue:restart'); Artisan::call('queue:restart');
} catch (Exception $e) {
}catch(Exception $e) {
\Log::error("I wasn't able to restart the queue"); \Log::error("I wasn't able to restart the queue");
} }
} }

View File

@ -122,7 +122,7 @@ class CreateTestData extends Command
'settings' => null, 'settings' => null,
]); ]);
factory(\App\Models\Product::class,50)->create([ factory(\App\Models\Product::class, 50)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $company->id, 'company_id' => $company->id,
]); ]);
@ -136,32 +136,28 @@ class CreateTestData extends Command
$this->createClient($company, $user); $this->createClient($company, $user);
} }
foreach($company->clients as $client) { foreach ($company->clients as $client) {
$this->info('creating invoice for client #'.$client->id); $this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client); $this->createInvoice($client);
$this->info('creating credit for client #'.$client->id); $this->info('creating credit for client #'.$client->id);
$this->createCredit($client); $this->createCredit($client);
$this->info('creating quote for client #'.$client->id); $this->info('creating quote for client #'.$client->id);
$this->createQuote($client); $this->createQuote($client);
$this->info('creating expense for client #'.$client->id); $this->info('creating expense for client #'.$client->id);
$this->createExpense($client); $this->createExpense($client);
$this->info('creating vendor for client #'.$client->id); $this->info('creating vendor for client #'.$client->id);
$this->createVendor($client); $this->createVendor($client);
$this->info('creating task for client #'.$client->id); $this->info('creating task for client #'.$client->id);
$this->createTask($client); $this->createTask($client);
$this->info('creating project for client #'.$client->id); $this->info('creating project for client #'.$client->id);
$this->createProject($client); $this->createProject($client);
} }
} }
private function createMediumAccount() private function createMediumAccount()
@ -208,7 +204,7 @@ class CreateTestData extends Command
]); ]);
factory(\App\Models\Product::class,50)->create([ factory(\App\Models\Product::class, 50)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $company->id, 'company_id' => $company->id,
]); ]);
@ -224,43 +220,49 @@ class CreateTestData extends Command
$this->createClient($company, $user); $this->createClient($company, $user);
} }
foreach($company->clients as $client) { foreach ($company->clients as $client) {
$this->info('creating invoice for client #'.$client->id); $this->info('creating invoice for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createInvoice($client); $this->createInvoice($client);
}
$this->info('creating credit for client #'.$client->id); $this->info('creating credit for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createCredit($client); $this->createCredit($client);
}
$this->info('creating quote for client #'.$client->id); $this->info('creating quote for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createQuote($client); $this->createQuote($client);
}
$this->info('creating expense for client #'.$client->id); $this->info('creating expense for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createExpense($client); $this->createExpense($client);
}
$this->info('creating vendor for client #'.$client->id); $this->info('creating vendor for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createVendor($client); $this->createVendor($client);
}
$this->info('creating task for client #'.$client->id); $this->info('creating task for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createTask($client); $this->createTask($client);
}
$this->info('creating project for client #'.$client->id); $this->info('creating project for client #'.$client->id);
for($i=0; $i<$this->count; $i++) for ($i=0; $i<$this->count; $i++) {
$this->createProject($client); $this->createProject($client);
}
} }
} }
@ -308,7 +310,7 @@ class CreateTestData extends Command
]); ]);
factory(\App\Models\Product::class,50)->create([ factory(\App\Models\Product::class, 50)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $company->id, 'company_id' => $company->id,
]); ]);
@ -325,30 +327,28 @@ class CreateTestData extends Command
$this->createClient($company, $user); $this->createClient($company, $user);
} }
foreach($company->clients as $client) { foreach ($company->clients as $client) {
$this->info('creating invoice for client #'.$client->id); $this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client); $this->createInvoice($client);
$this->info('creating credit for client #'.$client->id); $this->info('creating credit for client #'.$client->id);
$this->createCredit($client); $this->createCredit($client);
$this->info('creating quote for client #'.$client->id); $this->info('creating quote for client #'.$client->id);
$this->createQuote($client); $this->createQuote($client);
$this->info('creating expense for client #'.$client->id); $this->info('creating expense for client #'.$client->id);
$this->createExpense($client); $this->createExpense($client);
$this->info('creating vendor for client #'.$client->id); $this->info('creating vendor for client #'.$client->id);
$this->createVendor($client); $this->createVendor($client);
$this->info('creating task for client #'.$client->id); $this->info('creating task for client #'.$client->id);
$this->createTask($client); $this->createTask($client);
$this->info('creating project for client #'.$client->id); $this->info('creating project for client #'.$client->id);
$this->createProject($client); $this->createProject($client);
} }
} }
private function createClient($company, $user) private function createClient($company, $user)
@ -357,42 +357,36 @@ class CreateTestData extends Command
// dispatch(function () use ($company, $user) { // dispatch(function () use ($company, $user) {
// }); // });
$client = factory(\App\Models\Client::class)->create([ $client = factory(\App\Models\Client::class)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $company->id 'company_id' => $company->id
]); ]);
factory(\App\Models\ClientContact::class, 1)->create([ factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'client_id' => $client->id, 'client_id' => $client->id,
'company_id' => $company->id, 'company_id' => $company->id,
'is_primary' => 1 '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, 'user_id' => $user->id,
'client_id' => $client->id, 'client_id' => $client->id,
'company_id' => $company->id 'company_id' => $company->id
]); ]);
} }
private function createExpense($client) private function createExpense($client)
{ {
factory(\App\Models\Expense::class, rand(1, 5))->create([ factory(\App\Models\Expense::class, rand(1, 5))->create([
'user_id' => $client->user->id, 'user_id' => $client->user->id,
'client_id' => $client->id, 'client_id' => $client->id,
'company_id' => $client->company->id 'company_id' => $client->company->id
]); ]);
} }
private function createVendor($client) private function createVendor($client)
{ {
$vendor = factory(\App\Models\Vendor::class)->create([ $vendor = factory(\App\Models\Vendor::class)->create([
'user_id' => $client->user->id, 'user_id' => $client->user->id,
'company_id' => $client->company->id 'company_id' => $client->company->id
@ -412,12 +406,10 @@ class CreateTestData extends Command
'company_id' => $client->company->id, 'company_id' => $client->company->id,
'is_primary' => 0 'is_primary' => 0
]); ]);
} }
private function createTask($client) private function createTask($client)
{ {
$vendor = factory(\App\Models\Task::class)->create([ $vendor = factory(\App\Models\Task::class)->create([
'user_id' => $client->user->id, 'user_id' => $client->user->id,
'company_id' => $client->company->id 'company_id' => $client->company->id
@ -426,7 +418,6 @@ class CreateTestData extends Command
private function createProject($client) private function createProject($client)
{ {
$vendor = factory(\App\Models\Project::class)->create([ $vendor = factory(\App\Models\Project::class)->create([
'user_id' => $client->user->id, 'user_id' => $client->user->id,
'company_id' => $client->company->id 'company_id' => $client->company->id
@ -444,10 +435,10 @@ class CreateTestData extends Command
$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->client_id = $client->id;
// $invoice->date = $faker->date(); // $invoice->date = $faker->date();
$dateable = Carbon::now()->subDays(rand(0,90)); $dateable = Carbon::now()->subDays(rand(0, 90));
$invoice->date = $dateable; $invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1,10)); $invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false; $invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) { if (rand(0, 1)) {
@ -517,10 +508,10 @@ class CreateTestData extends Command
$credit = factory(\App\Models\Credit::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); $credit = factory(\App\Models\Credit::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
$dateable = Carbon::now()->subDays(rand(0,90)); $dateable = Carbon::now()->subDays(rand(0, 90));
$credit->date = $dateable; $credit->date = $dateable;
$credit->line_items = $this->buildLineItems(rand(1,10)); $credit->line_items = $this->buildLineItems(rand(1, 10));
$credit->uses_inclusive_taxes = false; $credit->uses_inclusive_taxes = false;
if (rand(0, 1)) { if (rand(0, 1)) {
@ -548,7 +539,6 @@ class CreateTestData extends Command
$credit->save(); $credit->save();
$credit->service()->markSent()->save(); $credit->service()->markSent()->save();
$credit->service()->createInvitations(); $credit->service()->createInvitations();
} }
private function createQuote($client) private function createQuote($client)
@ -566,7 +556,7 @@ class CreateTestData extends Command
$quote->setRelation('client', $client); $quote->setRelation('client', $client);
$quote->line_items = $this->buildLineItems(rand(1,10)); $quote->line_items = $this->buildLineItems(rand(1, 10));
$quote->uses_inclusive_taxes = false; $quote->uses_inclusive_taxes = false;
if (rand(0, 1)) { if (rand(0, 1)) {
@ -595,15 +585,13 @@ class CreateTestData extends Command
$quote->service()->markSent()->save(); $quote->service()->markSent()->save();
$quote->service()->createInvitations(); $quote->service()->createInvitations();
} }
private function buildLineItems($count = 1) private function buildLineItems($count = 1)
{ {
$line_items = []; $line_items = [];
for($x=0; $x<$count; $x++) for ($x=0; $x<$count; $x++) {
{
$item = InvoiceItemFactory::create(); $item = InvoiceItemFactory::create();
$item->quantity = 1; $item->quantity = 1;
//$item->cost = 10; //$item->cost = 10;
@ -623,15 +611,15 @@ class CreateTestData extends Command
$item->tax_rate1 = 5; $item->tax_rate1 = 5;
} }
$product = Product::all()->random(); $product = Product::all()->random();
$item->cost = (float)$product->cost; $item->cost = (float)$product->cost;
$item->product_key = $product->product_key; $item->product_key = $product->product_key;
$item->notes = $product->notes; $item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1; $item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2; $item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3; $item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4; $item->custom_value4 = $product->custom_value4;

View File

@ -38,9 +38,7 @@ class DesignUpdate extends Command
*/ */
public function handle() public function handle()
{ {
foreach (Design::whereIsCustom(false)->get() as $design) {
foreach(Design::whereIsCustom(false)->get() as $design){
$class = 'App\Designs\\'.$design->name; $class = 'App\Designs\\'.$design->name;
$invoice_design = new $class(); $invoice_design = new $class();
@ -55,7 +53,5 @@ class DesignUpdate extends Command
$design->design = $design_object; $design->design = $design_object;
$design->save(); $design->save();
} }
} }
} }

View File

@ -40,7 +40,6 @@ class ImportMigrations extends Command
*/ */
public function __construct() public function __construct()
{ {
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
parent::__construct(); parent::__construct();

View File

@ -72,7 +72,6 @@ class SendTestEmails extends Command
if (!$user) { if (!$user) {
$user = factory(\App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
'confirmation_code' => '123', 'confirmation_code' => '123',
'email' => $faker->safeEmail, 'email' => $faker->safeEmail,
@ -97,10 +96,7 @@ class SendTestEmails extends Command
//'settings' => DefaultSettings::userSettings(), //'settings' => DefaultSettings::userSettings(),
'settings' => null, 'settings' => null,
]); ]);
} else {
}
else
{
$company = $user->company_users->first()->company; $company = $user->company_users->first()->company;
$account = $company->account; $account = $company->account;
} }
@ -111,7 +107,6 @@ class SendTestEmails extends Command
if (!$client) { if (!$client) {
$client = ClientFactory::create($company->id, $user->id); $client = ClientFactory::create($company->id, $user->id);
$client->save(); $client->save();
@ -138,10 +133,10 @@ class SendTestEmails extends Command
$invoice->setRelation('client', $client); $invoice->setRelation('client', $client);
$invoice->save(); $invoice->save();
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id); $ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
$ii->invoice_id = $invoice->id; $ii->invoice_id = $invoice->id;
$ii->client_contact_id = $client->primary_contact()->first()->id; $ii->client_contact_id = $client->primary_contact()->first()->id;
$ii->save(); $ii->save();
$invoice->setRelation('invitations', $ii); $invoice->setRelation('invitations', $ii);
$invoice->service()->markSent()->save(); $invoice->service()->markSent()->save();

View File

@ -46,7 +46,6 @@ class CreateTestCreditJob implements ShouldQueue
public function __construct(Client $client) public function __construct(Client $client)
{ {
$this->client = $client; $this->client = $client;
} }
/** /**
@ -54,7 +53,7 @@ class CreateTestCreditJob implements ShouldQueue
* *
* @return void * @return void
*/ */
public function handle() public function handle()
{ {
$faker = \Faker\Factory::create(); $faker = \Faker\Factory::create();
@ -63,10 +62,10 @@ class CreateTestCreditJob implements ShouldQueue
//$invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);//stub the company and user_id //$invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);//stub the company and user_id
//$invoice->client_id = $this->client->id; //$invoice->client_id = $this->client->id;
// $invoice->date = $faker->date(); // $invoice->date = $faker->date();
$dateable = Carbon::now()->subDays(rand(0,90)); $dateable = Carbon::now()->subDays(rand(0, 90));
$credit->date = $dateable; $credit->date = $dateable;
$credit->line_items = $this->buildLineItems(rand(1,10)); $credit->line_items = $this->buildLineItems(rand(1, 10));
$credit->uses_inclusive_taxes = false; $credit->uses_inclusive_taxes = false;
if (rand(0, 1)) { if (rand(0, 1)) {
@ -101,8 +100,7 @@ class CreateTestCreditJob implements ShouldQueue
{ {
$line_items = []; $line_items = [];
for($x=0; $x<$count; $x++) for ($x=0; $x<$count; $x++) {
{
$item = InvoiceItemFactory::create(); $item = InvoiceItemFactory::create();
$item->quantity = 1; $item->quantity = 1;
//$item->cost = 10; //$item->cost = 10;
@ -122,15 +120,15 @@ class CreateTestCreditJob implements ShouldQueue
$item->tax_rate1 = 5; $item->tax_rate1 = 5;
} }
$product = Product::all()->random(); $product = Product::all()->random();
$item->cost = (float)$product->cost; $item->cost = (float)$product->cost;
$item->product_key = $product->product_key; $item->product_key = $product->product_key;
$item->notes = $product->notes; $item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1; $item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2; $item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3; $item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4; $item->custom_value4 = $product->custom_value4;

View File

@ -45,7 +45,6 @@ class CreateTestInvoiceJob implements ShouldQueue
public function __construct(Client $client) public function __construct(Client $client)
{ {
$this->client = $client; $this->client = $client;
} }
/** /**
@ -53,18 +52,17 @@ class CreateTestInvoiceJob implements ShouldQueue
* *
* @return void * @return void
*/ */
public function handle() public function handle()
{ {
$faker = \Faker\Factory::create(); $faker = \Faker\Factory::create();
$invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);//stub the company and user_id $invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);//stub the company and user_id
$invoice->client_id = $this->client->id; $invoice->client_id = $this->client->id;
// $invoice->date = $faker->date(); // $invoice->date = $faker->date();
$dateable = Carbon::now()->subDays(rand(0,90)); $dateable = Carbon::now()->subDays(rand(0, 90));
$invoice->date = $dateable; $invoice->date = $dateable;
$invoice->line_items = $this->buildLineItems(rand(1,10)); $invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false; $invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) { if (rand(0, 1)) {
@ -127,8 +125,7 @@ class CreateTestInvoiceJob implements ShouldQueue
{ {
$line_items = []; $line_items = [];
for($x=0; $x<$count; $x++) for ($x=0; $x<$count; $x++) {
{
$item = InvoiceItemFactory::create(); $item = InvoiceItemFactory::create();
$item->quantity = 1; $item->quantity = 1;
//$item->cost = 10; //$item->cost = 10;
@ -148,15 +145,15 @@ class CreateTestInvoiceJob implements ShouldQueue
$item->tax_rate1 = 5; $item->tax_rate1 = 5;
} }
$product = Product::all()->random(); $product = Product::all()->random();
$item->cost = (float)$product->cost; $item->cost = (float)$product->cost;
$item->product_key = $product->product_key; $item->product_key = $product->product_key;
$item->notes = $product->notes; $item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1; $item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2; $item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3; $item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4; $item->custom_value4 = $product->custom_value4;

View File

@ -46,7 +46,6 @@ class CreateTestQuoteJob implements ShouldQueue
public function __construct(Client $client) public function __construct(Client $client)
{ {
$this->client = $client; $this->client = $client;
} }
/** /**
@ -61,7 +60,7 @@ class CreateTestQuoteJob implements ShouldQueue
$quote =factory(\App\Models\Quote::class)->create(['user_id' => $this->client->user->id, 'company_id' => $this->client->company->id, 'client_id' => $this->client->id]); $quote =factory(\App\Models\Quote::class)->create(['user_id' => $this->client->user->id, 'company_id' => $this->client->company->id, 'client_id' => $this->client->id]);
$quote->date = $faker->date(); $quote->date = $faker->date();
$quote->line_items = $this->buildLineItems(rand(1,10)); $quote->line_items = $this->buildLineItems(rand(1, 10));
$quote->uses_inclusive_taxes = false; $quote->uses_inclusive_taxes = false;
if (rand(0, 1)) { if (rand(0, 1)) {
@ -88,7 +87,6 @@ class CreateTestQuoteJob implements ShouldQueue
$quote->service()->markSent()->save(); $quote->service()->markSent()->save();
CreateQuoteInvitations::dispatch($quote, $quote->company); CreateQuoteInvitations::dispatch($quote, $quote->company);
} }
@ -97,8 +95,7 @@ class CreateTestQuoteJob implements ShouldQueue
{ {
$line_items = []; $line_items = [];
for($x=0; $x<$count; $x++) for ($x=0; $x<$count; $x++) {
{
$item = InvoiceItemFactory::create(); $item = InvoiceItemFactory::create();
$item->quantity = 1; $item->quantity = 1;
//$item->cost = 10; //$item->cost = 10;
@ -118,15 +115,15 @@ class CreateTestQuoteJob implements ShouldQueue
$item->tax_rate1 = 5; $item->tax_rate1 = 5;
} }
$product = Product::all()->random(); $product = Product::all()->random();
$item->cost = (float)$product->cost; $item->cost = (float)$product->cost;
$item->product_key = $product->product_key; $item->product_key = $product->product_key;
$item->notes = $product->notes; $item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1; $item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2; $item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3; $item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4; $item->custom_value4 = $product->custom_value4;
@ -135,5 +132,4 @@ class CreateTestQuoteJob implements ShouldQueue
return $line_items; return $line_items;
} }
} }

View File

@ -18,519 +18,521 @@ use App\Utils\Traits\MakesHash;
* CompanySettings * CompanySettings
*/ */
class CompanySettings extends BaseSettings { class CompanySettings extends BaseSettings
{
use MakesHash;
/*Group settings based on functionality*/
use MakesHash; /*Invoice*/
/*Group settings based on functionality*/ public $auto_archive_invoice = false;
public $lock_sent_invoices = false;
/*Invoice*/ public $enable_client_portal_tasks = false;
public $auto_archive_invoice = false; public $enable_client_portal_password = false;
public $lock_sent_invoices = false; public $enable_client_portal = true;//implemented
public $enable_client_portal_dashboard = true;//implemented
public $signature_on_pdf = false;
public $document_email_attachment = false;
public $send_portal_password = false;
public $enable_client_portal_tasks = false; public $portal_design_id = '1';
public $enable_client_portal_password = false;
public $enable_client_portal = true;//implemented
public $enable_client_portal_dashboard = true;//implemented
public $signature_on_pdf = false;
public $document_email_attachment = false;
public $send_portal_password = false;
public $portal_design_id = '1'; public $timezone_id = '';
public $date_format_id = '';
public $military_time = false;
public $timezone_id = ''; public $language_id = '';
public $date_format_id = ''; public $show_currency_code = false;
public $military_time = false;
public $language_id = ''; public $company_gateway_ids = '';
public $show_currency_code = false;
public $company_gateway_ids = ''; public $currency_id = '1';
public $currency_id = '1'; public $custom_value1 = '';
public $custom_value2 = '';
public $custom_value3 = '';
public $custom_value4 = '';
public $custom_value1 = ''; public $default_task_rate = 0;
public $custom_value2 = '';
public $custom_value3 = '';
public $custom_value4 = '';
public $default_task_rate = 0; public $payment_terms = -1;
public $send_reminders = false;
public $payment_terms = -1; public $custom_message_dashboard = '';
public $send_reminders = false; public $custom_message_unpaid_invoice = '';
public $custom_message_paid_invoice = '';
public $custom_message_unapproved_quote = '';
public $auto_archive_quote = false;
public $auto_convert_quote = true;
public $auto_email_invoice = true;
public $custom_message_dashboard = ''; public $inclusive_taxes = false;
public $custom_message_unpaid_invoice = ''; public $quote_footer = '';
public $custom_message_paid_invoice = '';
public $custom_message_unapproved_quote = '';
public $auto_archive_quote = false;
public $auto_convert_quote = true;
public $auto_email_invoice = true;
public $inclusive_taxes = false; public $translations;
public $quote_footer = '';
public $translations; public $counter_number_applied = 'when_saved';// when_saved , when_sent , when_paid
public $quote_number_applied = 'when_saved';// when_saved , when_sent
public $counter_number_applied = 'when_saved';// when_saved , when_sent , when_paid /* Counters */
public $quote_number_applied = 'when_saved';// when_saved , when_sent public $invoice_number_pattern = '';
public $invoice_number_counter = 1;
/* Counters */ public $quote_number_pattern = '';
public $invoice_number_pattern = ''; public $quote_number_counter = 1;
public $invoice_number_counter = 1;
public $quote_number_pattern = ''; public $client_number_pattern = '';
public $quote_number_counter = 1; public $client_number_counter = 1;
public $client_number_pattern = ''; public $credit_number_pattern = '';
public $client_number_counter = 1; public $credit_number_counter = 1;
public $credit_number_pattern = ''; public $task_number_pattern = '';
public $credit_number_counter = 1; public $task_number_counter = 1;
public $task_number_pattern = ''; public $expense_number_pattern = '';
public $task_number_counter = 1; public $expense_number_counter = 1;
public $expense_number_pattern = ''; public $vendor_number_pattern = '';
public $expense_number_counter = 1; public $vendor_number_counter = 1;
public $vendor_number_pattern = ''; public $ticket_number_pattern = '';
public $vendor_number_counter = 1; public $ticket_number_counter = 1;
public $ticket_number_pattern = ''; public $payment_number_pattern = '';
public $ticket_number_counter = 1; public $payment_number_counter = 1;
public $payment_number_pattern = ''; public $shared_invoice_quote_counter = false;
public $payment_number_counter = 1; public $recurring_number_prefix = 'R';
public $reset_counter_frequency_id = '0';
public $reset_counter_date = '';
public $counter_padding = 4;
public $shared_invoice_quote_counter = false; public $design = 'views/pdf/design1.blade.php';
public $recurring_number_prefix = 'R';
public $reset_counter_frequency_id = '0';
public $reset_counter_date = '';
public $counter_padding = 4;
public $design = 'views/pdf/design1.blade.php'; public $invoice_terms = '';
public $quote_terms = '';
public $invoice_taxes = 0;
public $enabled_item_tax_rates = 0;
public $invoice_design_id = 'VolejRejNm';
public $quote_design_id = 'VolejRejNm';
public $credit_design_id = 'VolejRejNm';
public $invoice_footer = '';
public $credit_footer = '';
public $credit_terms = '';
public $invoice_labels = '';
public $tax_name1 = '';
public $tax_rate1 = 0;
public $tax_name2 = '';
public $tax_rate2 = 0;
public $tax_name3 = '';
public $tax_rate3 = 0;
public $payment_type_id = '0';
public $invoice_fields = '';
public $invoice_terms = ''; public $show_accept_invoice_terms = false;
public $quote_terms = ''; public $show_accept_quote_terms = false;
public $invoice_taxes = 0; public $require_invoice_signature = false;
public $enabled_item_tax_rates = 0; public $require_quote_signature = false;
public $invoice_design_id = 'VolejRejNm';
public $quote_design_id = 'VolejRejNm';
public $credit_design_id = 'VolejRejNm';
public $invoice_footer = '';
public $credit_footer = '';
public $credit_terms = '';
public $invoice_labels = '';
public $tax_name1 = '';
public $tax_rate1 = 0;
public $tax_name2 = '';
public $tax_rate2 = 0;
public $tax_name3 = '';
public $tax_rate3 = 0;
public $payment_type_id = '0';
public $invoice_fields = '';
public $show_accept_invoice_terms = false; //email settings
public $show_accept_quote_terms = false; public $email_sending_method = 'default';//enum 'default','gmail'
public $require_invoice_signature = false; public $gmail_sending_user_id = '0';
public $require_quote_signature = false;
//email settings public $reply_to_email = '';
public $email_sending_method = 'default';//enum 'default','gmail' public $bcc_email = '';
public $gmail_sending_user_id = '0'; public $pdf_email_attachment = false;
public $ubl_email_attachment = false;
public $reply_to_email = ''; public $email_style = 'plain'; //plain, light, dark, custom
public $bcc_email = ''; public $email_style_custom = ''; //the template itself
public $pdf_email_attachment = false; public $email_subject_invoice = '';
public $ubl_email_attachment = false; public $email_subject_quote = '';
public $email_subject_payment = '';
public $email_subject_payment_partial = '';
public $email_subject_statement = '';
public $email_template_invoice = '';
public $email_template_quote = '';
public $email_template_payment = '';
public $email_template_payment_partial = '';
public $email_template_statement = '';
public $email_subject_reminder1 = '';
public $email_subject_reminder2 = '';
public $email_subject_reminder3 = '';
public $email_subject_reminder_endless = '';
public $email_template_reminder1 = '';
public $email_template_reminder2 = '';
public $email_template_reminder3 = '';
public $email_template_reminder_endless = '';
public $email_signature = '';
public $enable_email_markup = true;
public $email_style = 'plain';//plain, light, dark, custom public $email_subject_custom1 = '';
public $email_style_custom = '';//the template itself public $email_subject_custom2 = '';
public $email_subject_invoice = ''; public $email_subject_custom3 = '';
public $email_subject_quote = '';
public $email_subject_payment = '';
public $email_subject_payment_partial = '';
public $email_subject_statement = '';
public $email_template_invoice = '';
public $email_template_quote = '';
public $email_template_payment = '';
public $email_template_payment_partial = '';
public $email_template_statement = '';
public $email_subject_reminder1 = '';
public $email_subject_reminder2 = '';
public $email_subject_reminder3 = '';
public $email_subject_reminder_endless = '';
public $email_template_reminder1 = '';
public $email_template_reminder2 = '';
public $email_template_reminder3 = '';
public $email_template_reminder_endless = '';
public $email_signature = '';
public $enable_email_markup = true;
public $email_subject_custom1 = ''; public $email_template_custom1 = '';
public $email_subject_custom2 = ''; public $email_template_custom2 = '';
public $email_subject_custom3 = ''; public $email_template_custom3 = '';
public $email_template_custom1 = ''; public $enable_reminder1 = false;
public $email_template_custom2 = ''; public $enable_reminder2 = false;
public $email_template_custom3 = ''; public $enable_reminder3 = false;
public $enable_reminder1 = false; public $num_days_reminder1 = 0;
public $enable_reminder2 = false; public $num_days_reminder2 = 0;
public $enable_reminder3 = false; public $num_days_reminder3 = 0;
public $num_days_reminder1 = 0; public $schedule_reminder1 = '';// (enum: after_invoice_date, before_due_date, after_due_date)
public $num_days_reminder2 = 0; public $schedule_reminder2 = '';// (enum: after_invoice_date, before_due_date, after_due_date)
public $num_days_reminder3 = 0; public $schedule_reminder3 = '';// (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder1 = '';// (enum: after_invoice_date, before_due_date, after_due_date) public $reminder_send_time = 32400;//number of seconds from UTC +0 to send reminders
public $schedule_reminder2 = '';// (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder3 = '';// (enum: after_invoice_date, before_due_date, after_due_date)
public $reminder_send_time = 32400;//number of seconds from UTC +0 to send reminders public $late_fee_amount1 = 0;
public $late_fee_amount2 = 0;
public $late_fee_amount3 = 0;
public $late_fee_amount1 = 0; public $endless_reminder_frequency_id = '0';
public $late_fee_amount2 = 0; public $late_fee_endless_amount = 0;
public $late_fee_amount3 = 0; public $late_fee_endless_percent = 0;
public $endless_reminder_frequency_id = '0'; public $client_online_payment_notification = true; //@todo implement in notifications
public $late_fee_endless_amount = 0; public $client_manual_payment_notification = true; //@todo implement in notifications
public $late_fee_endless_percent = 0;
public $client_online_payment_notification = true; //@todo implement in notifications /* Company Meta data that we can use to build sub companies*/
public $client_manual_payment_notification = true; //@todo implement in notifications
/* Company Meta data that we can use to build sub companies*/ public $name = '';
public $company_logo = '';
public $website = '';
public $address1 = '';
public $address2 = '';
public $city = '';
public $state = '';
public $postal_code = '';
public $phone = '';
public $email = '';
public $country_id;
public $vat_number = '';
public $id_number = '';
public $name = ''; public $page_size = 'A4';
public $company_logo = ''; public $font_size = 9;
public $website = ''; public $primary_font = 'Roboto';
public $address1 = ''; public $secondary_font = 'Roboto';
public $address2 = ''; public $hide_paid_to_date = false;
public $city = ''; public $embed_documents = false;
public $state = ''; public $all_pages_header = false;
public $postal_code = ''; public $all_pages_footer = false;
public $phone = ''; public $pdf_variables = '';
public $email = '';
public $country_id;
public $vat_number = '';
public $id_number = '';
public $page_size = 'A4'; public static $casts = [
public $font_size = 9; 'portal_design_id' => 'string',
public $primary_font = 'Roboto'; 'late_fee_endless_percent' => 'float',
public $secondary_font = 'Roboto'; 'late_fee_endless_amount' => 'float',
public $hide_paid_to_date = false; 'auto_email_invoice' => 'bool',
public $embed_documents = false; 'reminder_send_time' => 'int',
public $all_pages_header = false; 'email_sending_method' => 'string',
public $all_pages_footer = false; 'gmail_sending_user_id' => 'string',
public $pdf_variables = ''; 'currency_id' => 'string',
'counter_number_applied' => 'string',
'quote_number_applied' => 'string',
'email_subject_custom1' => 'string',
'email_subject_custom2' => 'string',
'email_subject_custom3' => 'string',
'email_template_custom1' => 'string',
'email_template_custom2' => 'string',
'email_template_custom3' => 'string',
'enable_reminder1' => 'bool',
'enable_reminder2' => 'bool',
'enable_reminder3' => 'bool',
'num_days_reminder1' => 'int',
'num_days_reminder2' => 'int',
'num_days_reminder3' => 'int',
'schedule_reminder1' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder2' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder3' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'late_fee_amount1' => 'float',
'late_fee_amount2' => 'float',
'late_fee_amount3' => 'float',
'endless_reminder_frequency_id' => 'integer',
'client_online_payment_notification' => 'bool',
'client_manual_payment_notification' => 'bool',
'document_email_attachment' => 'bool',
'enable_client_portal_password' => 'bool',
'enable_email_markup' => 'bool',
'enable_client_portal_dashboard' => 'bool',
'enable_client_portal' => 'bool',
'email_template_statement' => 'string',
'email_subject_statement' => 'string',
'signature_on_pdf' => 'bool',
'send_portal_password' => 'bool',
'quote_footer' => 'string',
'page_size' => 'string',
'font_size' => 'int',
'primary_font' => 'string',
'secondary_font' => 'string',
'hide_paid_to_date' => 'bool',
'embed_documents' => 'bool',
'all_pages_header' => 'bool',
'all_pages_footer' => 'bool',
'task_number_pattern' => 'string',
'task_number_counter' => 'int',
'expense_number_pattern' => 'string',
'expense_number_counter' => 'int',
'vendor_number_pattern' => 'string',
'vendor_number_counter' => 'int',
'ticket_number_pattern' => 'string',
'ticket_number_counter' => 'int',
'payment_number_pattern' => 'string',
'payment_number_counter' => 'int',
'reply_to_email' => 'string',
'bcc_email' => 'string',
'pdf_email_attachment' => 'bool',
'ubl_email_attachment' => 'bool',
'email_style' => 'string',
'email_style_custom' => 'string',
'company_gateway_ids' => 'string',
'address1' => 'string',
'address2' => 'string',
'city' => 'string',
'company_logo' => 'string',
'country_id' => 'string',
'client_number_pattern' => 'string',
'client_number_counter' => 'integer',
'credit_number_pattern' => 'string',
'credit_number_counter' => 'integer',
'currency_id' => 'string',
'custom_value1' => 'string',
'custom_value2' => 'string',
'custom_value3' => 'string',
'custom_value4' => 'string',
'custom_message_dashboard' => 'string',
'custom_message_unpaid_invoice' => 'string',
'custom_message_paid_invoice' => 'string',
'custom_message_unapproved_quote' => 'string',
'default_task_rate' => 'float',
'email_signature' => 'string',
'email_subject_invoice' => 'string',
'email_subject_quote' => 'string',
'email_subject_payment' => 'string',
'email_subject_payment_partial' => 'string',
'email_template_invoice' => 'string',
'email_template_quote' => 'string',
'email_template_payment' => 'string',
'email_template_payment_partial' => 'string',
'email_subject_reminder1' => 'string',
'email_subject_reminder2' => 'string',
'email_subject_reminder3' => 'string',
'email_subject_reminder_endless' => 'string',
'email_template_reminder1' => 'string',
'email_template_reminder2' => 'string',
'email_template_reminder3' => 'string',
'email_template_reminder_endless' => 'string',
'enable_client_portal_password' => 'bool',
'inclusive_taxes' => 'bool',
'invoice_number_pattern' => 'string',
'invoice_number_counter' => 'integer',
'invoice_design_id' => 'string',
'invoice_fields' => 'string',
'invoice_taxes' => 'int',
'enabled_item_tax_rates' => 'int',
'invoice_footer' => 'string',
'invoice_labels' => 'string',
'invoice_terms' => 'string',
'credit_footer' => 'string',
'credit_terms' => 'string',
'name' => 'string',
'payment_terms' => 'integer',
'payment_type_id' => 'string',
'phone' => 'string',
'postal_code' => 'string',
'quote_design_id' => 'string',
'credit_design_id' => 'string',
'quote_number_pattern' => 'string',
'quote_number_counter' => 'integer',
'quote_terms' => 'string',
'recurring_number_prefix' => 'string',
'reset_counter_frequency_id' => 'integer',
'reset_counter_date' => 'string',
'require_invoice_signature' => 'bool',
'require_quote_signature' => 'bool',
'state' => 'string',
'email' => 'string',
'vat_number' => 'string',
'id_number' => 'string',
'tax_name1' => 'string',
'tax_name2' => 'string',
'tax_name3' => 'string',
'tax_rate1' => 'float',
'tax_rate2' => 'float',
'tax_rate3' => 'float',
'show_accept_quote_terms' => 'bool',
'show_accept_invoice_terms' => 'bool',
'timezone_id' => 'string',
'date_format_id' => 'string',
'military_time' => 'bool',
'language_id' => 'string',
'show_currency_code' => 'bool',
'send_reminders' => 'bool',
'enable_client_portal_tasks' => 'bool',
'lock_sent_invoices' => 'bool',
'auto_archive_invoice' => 'bool',
'auto_archive_quote' => 'bool',
'auto_convert_quote' => 'bool',
'shared_invoice_quote_counter' => 'bool',
'counter_padding' => 'integer',
'design' => 'string',
'website' => 'string',
'pdf_variables' => 'object',
];
public static $casts = [ /**
'portal_design_id' => 'string', * Array of variables which
'late_fee_endless_percent' => 'float', * cannot be modified client side
'late_fee_endless_amount' => 'float', */
'auto_email_invoice' => 'bool', public static $protected_fields = [
'reminder_send_time' => 'int', // 'credit_number_counter',
'email_sending_method' => 'string', // 'invoice_number_counter',
'gmail_sending_user_id' => 'string', // 'quote_number_counter',
'currency_id' => 'string', ];
'counter_number_applied' => 'string',
'quote_number_applied' => 'string',
'email_subject_custom1' => 'string',
'email_subject_custom2' => 'string',
'email_subject_custom3' => 'string',
'email_template_custom1' => 'string',
'email_template_custom2' => 'string',
'email_template_custom3' => 'string',
'enable_reminder1' => 'bool',
'enable_reminder2' => 'bool',
'enable_reminder3' => 'bool',
'num_days_reminder1' => 'int',
'num_days_reminder2' => 'int',
'num_days_reminder3' => 'int',
'schedule_reminder1' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder2' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder3' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'late_fee_amount1' => 'float',
'late_fee_amount2' => 'float',
'late_fee_amount3' => 'float',
'endless_reminder_frequency_id' => 'integer',
'client_online_payment_notification' => 'bool',
'client_manual_payment_notification' => 'bool',
'document_email_attachment' => 'bool',
'enable_client_portal_password' => 'bool',
'enable_email_markup' => 'bool',
'enable_client_portal_dashboard' => 'bool',
'enable_client_portal' => 'bool',
'email_template_statement' => 'string',
'email_subject_statement' => 'string',
'signature_on_pdf' => 'bool',
'send_portal_password' => 'bool',
'quote_footer' => 'string',
'page_size' => 'string',
'font_size' => 'int',
'primary_font' => 'string',
'secondary_font' => 'string',
'hide_paid_to_date' => 'bool',
'embed_documents' => 'bool',
'all_pages_header' => 'bool',
'all_pages_footer' => 'bool',
'task_number_pattern' => 'string',
'task_number_counter' => 'int',
'expense_number_pattern' => 'string',
'expense_number_counter' => 'int',
'vendor_number_pattern' => 'string',
'vendor_number_counter' => 'int',
'ticket_number_pattern' => 'string',
'ticket_number_counter' => 'int',
'payment_number_pattern' => 'string',
'payment_number_counter' => 'int',
'reply_to_email' => 'string',
'bcc_email' => 'string',
'pdf_email_attachment' => 'bool',
'ubl_email_attachment' => 'bool',
'email_style' => 'string',
'email_style_custom' => 'string',
'company_gateway_ids' => 'string',
'address1' => 'string',
'address2' => 'string',
'city' => 'string',
'company_logo' => 'string',
'country_id' => 'string',
'client_number_pattern' => 'string',
'client_number_counter' => 'integer',
'credit_number_pattern' => 'string',
'credit_number_counter' => 'integer',
'currency_id' => 'string',
'custom_value1' => 'string',
'custom_value2' => 'string',
'custom_value3' => 'string',
'custom_value4' => 'string',
'custom_message_dashboard' => 'string',
'custom_message_unpaid_invoice' => 'string',
'custom_message_paid_invoice' => 'string',
'custom_message_unapproved_quote' => 'string',
'default_task_rate' => 'float',
'email_signature' => 'string',
'email_subject_invoice' => 'string',
'email_subject_quote' => 'string',
'email_subject_payment' => 'string',
'email_subject_payment_partial' => 'string',
'email_template_invoice' => 'string',
'email_template_quote' => 'string',
'email_template_payment' => 'string',
'email_template_payment_partial' => 'string',
'email_subject_reminder1' => 'string',
'email_subject_reminder2' => 'string',
'email_subject_reminder3' => 'string',
'email_subject_reminder_endless' => 'string',
'email_template_reminder1' => 'string',
'email_template_reminder2' => 'string',
'email_template_reminder3' => 'string',
'email_template_reminder_endless' => 'string',
'enable_client_portal_password' => 'bool',
'inclusive_taxes' => 'bool',
'invoice_number_pattern' => 'string',
'invoice_number_counter' => 'integer',
'invoice_design_id' => 'string',
'invoice_fields' => 'string',
'invoice_taxes' => 'int',
'enabled_item_tax_rates' => 'int',
'invoice_footer' => 'string',
'invoice_labels' => 'string',
'invoice_terms' => 'string',
'credit_footer' => 'string',
'credit_terms' => 'string',
'name' => 'string',
'payment_terms' => 'integer',
'payment_type_id' => 'string',
'phone' => 'string',
'postal_code' => 'string',
'quote_design_id' => 'string',
'credit_design_id' => 'string',
'quote_number_pattern' => 'string',
'quote_number_counter' => 'integer',
'quote_terms' => 'string',
'recurring_number_prefix' => 'string',
'reset_counter_frequency_id' => 'integer',
'reset_counter_date' => 'string',
'require_invoice_signature' => 'bool',
'require_quote_signature' => 'bool',
'state' => 'string',
'email' => 'string',
'vat_number' => 'string',
'id_number' => 'string',
'tax_name1' => 'string',
'tax_name2' => 'string',
'tax_name3' => 'string',
'tax_rate1' => 'float',
'tax_rate2' => 'float',
'tax_rate3' => 'float',
'show_accept_quote_terms' => 'bool',
'show_accept_invoice_terms' => 'bool',
'timezone_id' => 'string',
'date_format_id' => 'string',
'military_time' => 'bool',
'language_id' => 'string',
'show_currency_code' => 'bool',
'send_reminders' => 'bool',
'enable_client_portal_tasks' => 'bool',
'lock_sent_invoices' => 'bool',
'auto_archive_invoice' => 'bool',
'auto_archive_quote' => 'bool',
'auto_convert_quote' => 'bool',
'shared_invoice_quote_counter' => 'bool',
'counter_padding' => 'integer',
'design' => 'string',
'website' => 'string',
'pdf_variables' => 'object',
];
/** /**
* Array of variables which * Cast object values and return entire class
* cannot be modified client side * prevents missing properties from not being returned
*/ * and always ensure an up to date class is returned
public static $protected_fields = [ *
// 'credit_number_counter', * @return \stdClass
// 'invoice_number_counter', */
// 'quote_number_counter', public function __construct($obj)
]; {
// parent::__construct($obj);
}
/** /**
* Cast object values and return entire class * Provides class defaults on init
* prevents missing properties from not being returned * @return object
* and always ensure an up to date class is returned */
* public static function defaults():\stdClass
* @return \stdClass {
*/ $config = json_decode(config('ninja.settings'));
public function __construct($obj) {
// parent::__construct($obj);
}
/** $data = (object) get_class_vars(CompanySettings::class);
* Provides class defaults on init
* @return object
*/
public static function defaults():\stdClass {
$config = json_decode(config('ninja.settings')); unset($data->casts);
unset($data->protected_fields);
$data = (object) get_class_vars(CompanySettings::class ); $data->timezone_id = (string) config('ninja.i18n.timezone_id');
$data->currency_id = (string) config('ninja.i18n.currency_id');
$data->language_id = (string) config('ninja.i18n.language_id');
$data->payment_terms = (int) config('ninja.i18n.payment_terms');
$data->military_time = (bool) config('ninja.i18n.military_time');
$data->date_format_id = (string) config('ninja.i18n.date_format_id');
$data->country_id = (string) config('ninja.i18n.country_id');
$data->translations = (object) [];
$data->pdf_variables = (object) self::getEntityVariableDefaults();
unset($data->casts); return self::setCasts($data, self::$casts);
unset($data->protected_fields); }
$data->timezone_id = (string) config('ninja.i18n.timezone_id'); /**
$data->currency_id = (string) config('ninja.i18n.currency_id'); * In case we update the settings object in the future we
$data->language_id = (string) config('ninja.i18n.language_id'); * need to provide a fallback catch on old settings objects which will
$data->payment_terms = (int) config('ninja.i18n.payment_terms'); * set new properties to the object prior to being returned.
$data->military_time = (bool) config('ninja.i18n.military_time'); *
$data->date_format_id = (string) config('ninja.i18n.date_format_id'); * @param object $data The settings object to be checked
$data->country_id = (string) config('ninja.i18n.country_id'); */
$data->translations = (object) []; public static function setProperties($settings):\stdClass
$data->pdf_variables = (object) self::getEntityVariableDefaults(); {
$company_settings = (object) get_class_vars(CompanySettings::class);
return self::setCasts($data, self::$casts); foreach ($company_settings as $key => $value) {
} if (!property_exists($settings, $key)) {
$settings->{ $key} = self::castAttribute($key, $company_settings->{ $key});
}
}
/** return $settings;
* In case we update the settings object in the future we }
* need to provide a fallback catch on old settings objects which will
* set new properties to the object prior to being returned.
*
* @param object $data The settings object to be checked
*/
public static function setProperties($settings):\stdClass {
$company_settings = (object) get_class_vars(CompanySettings::class );
foreach ($company_settings as $key => $value) { public static function notificationDefaults()
if (!property_exists($settings, $key)) { {
$settings->{ $key} = self::castAttribute($key, $company_settings->{ $key}); $notification = new \stdClass;
} $notification->email = ['all_notifications'];
}
return $settings; return $notification;
} }
public static function notificationDefaults() { private static function getEntityVariableDefaults()
{
$notification = new \stdClass; $variables = [
$notification->email = ['all_notifications']; 'client_details' => [
'$client.name' => ctrans('texts.client_name'),
return $notification; '$client.id_number' => ctrans('texts.id_number'),
} '$client.vat_number' => ctrans('texts.vat_number'),
'$client.address1' => ctrans('texts.address1'),
private static function getEntityVariableDefaults() { '$client.address2' => ctrans('texts.address2'),
'$client.city_state_postal' => ctrans('texts.city_state_postal'),
$variables = [ '$client.country' => ctrans('texts.country'),
'client_details' => [ '$client.email' => ctrans('texts.email'),
'$client.name' => ctrans('texts.client_name'), ],
'$client.id_number' => ctrans('texts.id_number'), 'company_details' => [
'$client.vat_number' => ctrans('texts.vat_number'), '$company.company_name' => ctrans('texts.company_name'),
'$client.address1' => ctrans('texts.address1'), '$company.id_number' => ctrans('texts.id_number'),
'$client.address2' => ctrans('texts.address2'), '$company.vat_number' => ctrans('texts.vat_number'),
'$client.city_state_postal' => ctrans('texts.city_state_postal'), '$company.website' => ctrans('texts.website'),
'$client.country' => ctrans('texts.country'), '$company.email' => ctrans('texts.email'),
'$client.email' => ctrans('texts.email'), '$company.phone' => ctrans('texts.phone'),
], ],
'company_details' => [ 'company_address' => [
'$company.company_name' => ctrans('texts.company_name'), '$company.address1' => ctrans('texts.address1'),
'$company.id_number' => ctrans('texts.id_number'), '$company.address2' => ctrans('texts.address2'),
'$company.vat_number' => ctrans('texts.vat_number'), '$company.city_state_postal' => ctrans('texts.city_state_postal'),
'$company.website' => ctrans('texts.website'), '$company.country' => ctrans('texts.country'),
'$company.email' => ctrans('texts.email'), ],
'$company.phone' => ctrans('texts.phone'), 'invoice_details' => [
], '$invoice.invoice_number' => ctrans('texts.invoice_number'),
'company_address' => [ '$invoice.po_number' => ctrans('texts.po_number'),
'$company.address1' => ctrans('texts.address1'), '$invoice.invoice_date' => ctrans('texts.invoice_date'),
'$company.address2' => ctrans('texts.address2'), '$invoice.due_date' => ctrans('texts.due_date'),
'$company.city_state_postal' => ctrans('texts.city_state_postal'), '$invoice.balance_due' => ctrans('texts.balance_due'),
'$company.country' => ctrans('texts.country'), '$invoice.invoice_total' => ctrans('texts.invoice_total'),
], ],
'invoice_details' => [ 'quote_details' => [
'$invoice.invoice_number' => ctrans('texts.invoice_number'), '$quote.quote_number' => ctrans('texts.quote_number'),
'$invoice.po_number' => ctrans('texts.po_number'), '$quote.po_number' => ctrans('texts.po_number'),
'$invoice.invoice_date' => ctrans('texts.invoice_date'), '$quote.quote_date' => ctrans('texts.quote_date'),
'$invoice.due_date' => ctrans('texts.due_date'), '$quote.valid_until' => ctrans('texts.valid_until'),
'$invoice.balance_due' => ctrans('texts.balance_due'), '$quote.balance_due' => ctrans('texts.balance_due'),
'$invoice.invoice_total' => ctrans('texts.invoice_total'), '$quote.quote_total' => ctrans('texts.quote_total'),
], ],
'quote_details' => [ 'credit_details' => [
'$quote.quote_number' => ctrans('texts.quote_number'), '$credit.credit_number' => ctrans('texts.credit_number'),
'$quote.po_number' => ctrans('texts.po_number'), '$credit.po_number' => ctrans('texts.po_number'),
'$quote.quote_date' => ctrans('texts.quote_date'), '$credit.credit_date' => ctrans('texts.credit_date'),
'$quote.valid_until' => ctrans('texts.valid_until'), '$credit.credit_balance' => ctrans('texts.credit_balance'),
'$quote.balance_due' => ctrans('texts.balance_due'), '$credit.credit_amount' => ctrans('texts.credit_amount'),
'$quote.quote_total' => ctrans('texts.quote_total'), ],
], 'product_columns' => [
'credit_details' => [ '$product.product_key' => ctrans('texts.product_key'),
'$credit.credit_number' => ctrans('texts.credit_number'), '$product.notes' => ctrans('texts.notes'),
'$credit.po_number' => ctrans('texts.po_number'), '$product.cost' => ctrans('texts.cost'),
'$credit.credit_date' => ctrans('texts.credit_date'), '$product.quantity' => ctrans('texts.quantity'),
'$credit.credit_balance' => ctrans('texts.credit_balance'), '$product.discount' => ctrans('texts.discount'),
'$credit.credit_amount' => ctrans('texts.credit_amount'), '$product.tax_name1' => ctrans('texts.tax_name1'),
], '$product.line_total' => ctrans('texts.line_total'),
'product_columns' => [ ],
'$product.product_key' => ctrans('texts.product_key'), 'task_columns' => [
'$product.notes' => ctrans('texts.notes'), '$task.product_key' => ctrans('texts.product_key'),
'$product.cost' => ctrans('texts.cost'), '$task.notes' => ctrans('texts.notes'),
'$product.quantity' => ctrans('texts.quantity'), '$task.cost' => ctrans('texts.cost'),
'$product.discount' => ctrans('texts.discount'), '$task.quantity' => ctrans('texts.quantity'),
'$product.tax_name1' => ctrans('texts.tax_name1'), '$task.discount' => ctrans('texts.discount'),
'$product.line_total' => ctrans('texts.line_total'), '$task.tax_name1' => ctrans('texts.tax_name1'),
], '$task.line_total' => ctrans('texts.line_total'),
'task_columns' => [ ],
'$task.product_key' => ctrans('texts.product_key'), ];
'$task.notes' => ctrans('texts.notes'),
'$task.cost' => ctrans('texts.cost'), return json_decode(json_encode($variables));
'$task.quantity' => ctrans('texts.quantity'), }
'$task.discount' => ctrans('texts.discount'),
'$task.tax_name1' => ctrans('texts.tax_name1'),
'$task.line_total' => ctrans('texts.line_total'),
],
];
return json_decode(json_encode($variables));
}
} }

View File

@ -69,7 +69,7 @@ class EmailTemplateDefaults
public static function emailReminder1Template() public static function emailReminder1Template()
{ {
// return Parsedown::instance()->line('First Email Reminder Text'); // return Parsedown::instance()->line('First Email Reminder Text');
} }
public static function emailReminder2Subject() public static function emailReminder2Subject()
@ -80,7 +80,7 @@ class EmailTemplateDefaults
public static function emailReminder2Template() public static function emailReminder2Template()
{ {
// return Parsedown::instance()->line('Second Email Reminder Text'); // return Parsedown::instance()->line('Second Email Reminder Text');
} }
public static function emailReminder3Subject() public static function emailReminder3Subject()
@ -91,7 +91,7 @@ class EmailTemplateDefaults
public static function emailReminder3Template() public static function emailReminder3Template()
{ {
// return Parsedown::instance()->line('Third Email Reminder Text'); // return Parsedown::instance()->line('Third Email Reminder Text');
} }
public static function emailReminderEndlessSubject() public static function emailReminderEndlessSubject()

View File

@ -13,15 +13,15 @@ namespace App\Designs;
abstract class AbstractDesign abstract class AbstractDesign
{ {
abstract public function includes(); abstract public function includes();
abstract public function header(); abstract public function header();
abstract public function body(); abstract public function body();
abstract public function product(); abstract public function product();
abstract public function task(); abstract public function task();
abstract public function footer(); abstract public function footer();
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Bold extends AbstractDesign class Bold extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
{ {
@ -33,9 +33,9 @@ class Bold extends AbstractDesign
</style>'; </style>';
} }
public function header() { public function header()
{
return '<div class="flex static bg-gray-800 p-12"> return '<div class="flex static bg-gray-800 p-12">
<div class="w-1/2"> <div class="w-1/2">
<div class="absolute bg-white pt-10 px-10 pb-4 inline-block align-middle"> <div class="absolute bg-white pt-10 px-10 pb-4 inline-block align-middle">
$company_logo $company_logo
@ -50,11 +50,10 @@ class Bold extends AbstractDesign
</div> </div>
</div> </div>
</div>'; </div>';
}
} public function body()
{
public function body() {
return '<div class="flex mt-32 pl-12"> return '<div class="flex mt-32 pl-12">
<div class="w-1/2 mr-40 flex flex-col"> <div class="w-1/2 mr-40 flex flex-col">
<h2 class="text-2xl uppercase font-semibold text-teal-600 tracking-tight">$entity_label</h2> $client_details <h2 class="text-2xl uppercase font-semibold text-teal-600 tracking-tight">$entity_label</h2> $client_details
@ -86,19 +85,20 @@ class Bold extends AbstractDesign
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
}
} public function task()
{
public function task() {
return ''; return '';
} }
public function product() { public function product()
{
return ''; return '';
} }
public function footer() {
public function footer()
{
return '<div class="flex px-4 mt-6 w-full px-12"> return '<div class="flex px-4 mt-6 w-full px-12">
<div class="w-1/2"> <div class="w-1/2">
$entity.public_notes $entity.public_notes
@ -127,7 +127,5 @@ class Bold extends AbstractDesign
</div> </div>
</div> </div>
</div>'; </div>';
}
}
} }

View File

@ -13,7 +13,6 @@ namespace App\Designs;
class Business extends AbstractDesign class Business extends AbstractDesign
{ {
public function __construct() public function __construct()
{ {
} }
@ -48,7 +47,6 @@ class Business extends AbstractDesign
public function header() public function header()
{ {
return '<div class="my-16 mx-10"> return '<div class="my-16 mx-10">
<div class="flex justify-between"> <div class="flex justify-between">
<div class="w-1/2"> <div class="w-1/2">
@ -63,12 +61,10 @@ class Business extends AbstractDesign
</div> </div>
</div> </div>
</div>'; </div>';
} }
public function body() public function body()
{ {
return '<div class="flex items-center justify-between mt-20"> return '<div class="flex items-center justify-between mt-20">
<div class="w-1/2 flex flex-col"> <div class="w-1/2 flex flex-col">
<span>$entity_label</span> <span>$entity_label</span>
@ -103,7 +99,6 @@ class Business extends AbstractDesign
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
} }
public function task() public function task()
@ -118,7 +113,6 @@ class Business extends AbstractDesign
public function footer() public function footer()
{ {
return '<div class="flex items-center justify-between px-4 pb-4 bg-gray-200 rounded py-2"> return '<div class="flex items-center justify-between px-4 pb-4 bg-gray-200 rounded py-2">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
@ -157,7 +151,5 @@ class Business extends AbstractDesign
</div> </div>
</body> </body>
</html>'; </html>';
} }
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Clean extends AbstractDesign class Clean extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -39,9 +39,9 @@ class Clean extends AbstractDesign
} }
public function header() { public function header()
{
return '<div class="px-12 my-10"> return '<div class="px-12 my-10">
<div class="flex items-center"> <div class="flex items-center">
<div class="w-1/3"> <div class="w-1/3">
<div class="h-14 w-14">$company_logo</div> <div class="h-14 w-14">$company_logo</div>
@ -55,10 +55,10 @@ class Clean extends AbstractDesign
</div> </div>
</div> </div>
</div>'; </div>';
} }
public function body() {
public function body()
{
return '<h1 class="mt-12 uppercase text-2xl text-blue-500 ml-4"> return '<h1 class="mt-12 uppercase text-2xl text-blue-500 ml-4">
$entity_label $entity_label
</h1> </h1>
@ -95,8 +95,7 @@ class Clean extends AbstractDesign
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
}
}
public function task() public function task()
{ {
@ -108,8 +107,8 @@ class Clean extends AbstractDesign
return ''; return '';
} }
public function footer() { public function footer()
{
return '<div class="flex px-4 mt-6 w-full"> return '<div class="flex px-4 mt-6 w-full">
<div class="w-1/2"> <div class="w-1/2">
$entity.public_notes $entity.public_notes
@ -145,7 +144,5 @@ class Clean extends AbstractDesign
</div> </div>
</body> </body>
</html>'; </html>';
}
}
} }

View File

@ -16,9 +16,9 @@ namespace App\Designs;
*/ */
class Creative extends AbstractDesign class Creative extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -42,9 +42,9 @@ margin-top: 6mm;
} }
public function header() { public function header()
{
return '<div class="py-16 mx-16"> return '<div class="py-16 mx-16">
<div class="flex justify-between"> <div class="flex justify-between">
<div class="w-2/3 flex"> <div class="w-2/3 flex">
<div class="flex flex-col"> <div class="flex flex-col">
@ -59,11 +59,10 @@ margin-top: 6mm;
</div> </div>
$company_logo $company_logo
</div>'; </div>';
}
} public function body()
{
public function body() {
return '<div class="flex justify-between mt-8"> return '<div class="flex justify-between mt-8">
<div class="w-2/3 flex flex-col"> <div class="w-2/3 flex flex-col">
<h1 class="text-5xl uppercase font-semibold">$entity_label</h1> <h1 class="text-5xl uppercase font-semibold">$entity_label</h1>
@ -94,9 +93,10 @@ margin-top: 6mm;
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
} }
public function task() { public function task()
{
return ''; return '';
} }
@ -106,8 +106,8 @@ margin-top: 6mm;
return ''; return '';
} }
public function footer() { public function footer()
{
return '<div class="border-b-4 border-pink-700"> return '<div class="border-b-4 border-pink-700">
<div class="flex items-center justify-between mt-2 px-4 pb-4"> <div class="flex items-center justify-between mt-2 px-4 pb-4">
<div class="w-1/2"> <div class="w-1/2">
@ -146,7 +146,5 @@ margin-top: 6mm;
</div> </div>
</body> </body>
</html>'; </html>';
}
}
} }

View File

@ -13,35 +13,34 @@ namespace App\Designs;
class Custom extends AbstractDesign class Custom extends AbstractDesign
{ {
public $includes; public $includes;
public $header; public $header;
public $body; public $body;
public $product; public $product;
public $task; public $task;
public $footer; public $footer;
public $name; public $name;
public function __construct($design) public function __construct($design)
{ {
$this->name = $design->name; $this->name = $design->name;
$this->includes = $design->design->includes; $this->includes = $design->design->includes;
$this->header = $design->design->header; $this->header = $design->design->header;
$this->body = $design->design->body; $this->body = $design->design->body;
$this->product = $design->design->product; $this->product = $design->design->product;
$this->task = $design->design->task; $this->task = $design->design->task;
$this->footer = $design->design->footer; $this->footer = $design->design->footer;
} }
}
}

View File

@ -14,394 +14,365 @@ namespace App\Designs;
use App\Models\Company; use App\Models\Company;
use App\Models\Invoice; use App\Models\Invoice;
class Designer { class Designer
{
public $design;
public $design; protected $input_variables;
protected $input_variables; protected $exported_variables;
protected $exported_variables; protected $html;
protected $html; protected $entity_string;
protected $entity_string; protected $entity;
protected $entity; private static $custom_fields = [
'invoice1',
'invoice2',
'invoice3',
'invoice4',
'surcharge1',
'surcharge2',
'surcharge3',
'surcharge4',
'client1',
'client2',
'client3',
'client4',
'contact1',
'contact2',
'contact3',
'contact4',
'company1',
'company2',
'company3',
'company4',
];
private static $custom_fields = [ public function __construct($entity, $design, $input_variables, $entity_string)
'invoice1', {
'invoice2', $this->entity = $entity;
'invoice3',
'invoice4',
'surcharge1',
'surcharge2',
'surcharge3',
'surcharge4',
'client1',
'client2',
'client3',
'client4',
'contact1',
'contact2',
'contact3',
'contact4',
'company1',
'company2',
'company3',
'company4',
];
public function __construct($entity, $design, $input_variables, $entity_string) $this->design = $design->design;
{
$this->entity = $entity;
$this->design = $design->design; $this->input_variables = json_decode(json_encode($input_variables), 1);
$this->input_variables = json_decode(json_encode($input_variables),1); $this->entity_string = $entity_string;
}
$this->entity_string = $entity_string; /**
* Returns the design
* formatted HTML
* @return string The HTML design built
*/
public function build():Designer
{
$this->setHtml()
->exportVariables()
->setDesign($this->getSection('includes'))
->setDesign($this->getSection('header'))
->setDesign($this->getSection('body'))
->setDesign($this->getSection('footer'));
} return $this;
}
/** public function init()
* Returns the design {
* formatted HTML $this->setHtml()
* @return string The HTML design built ->exportVariables();
*/
public function build():Designer
{
$this->setHtml() return $this;
->exportVariables() }
->setDesign($this->getSection('includes'))
->setDesign($this->getSection('header'))
->setDesign($this->getSection('body'))
->setDesign($this->getSection('footer'));
return $this; public function getIncludes()
{
$this->setDesign($this->getSection('includes'));
} return $this;
}
public function init() public function getHeader()
{ {
$this->setHtml() $this->setDesign($this->getSection('header'));
->exportVariables();
return $this; return $this;
} }
public function getIncludes() public function getFooter()
{ {
$this->setDesign($this->getSection('includes')); $this->setDesign($this->getSection('footer'));
return $this; return $this;
} }
public function getHeader() public function getBody()
{ {
$this->setDesign($this->getSection('body'));
return $this;
}
$this->setDesign($this->getSection('header')); public function getHtml():string
{
return $this->html;
}
return $this; public function setHtml()
} {
$this->html = '';
public function getFooter() return $this;
{ }
$this->setDesign($this->getSection('footer')); private function setDesign($section)
{
$this->html .= $section;
return $this; return $this;
} }
public function getBody() /**
{ * Returns the template section on with the
* stacked variables replaced with single variables.
*
* @param string $section the method name to be executed ie header/body/table/footer
* @return string The HTML of the template section
*/
public function getSection($section):string
{
return str_replace(array_keys($this->exported_variables), array_values($this->exported_variables), $this->design->{$section});
}
$this->setDesign($this->getSection('body')); private function exportVariables()
{
return $this; $company = $this->entity->company;
}
$this->exported_variables['$app_url'] = $this->entity->generateAppUrl();
$this->exported_variables['$client_details'] = $this->processVariables($this->input_variables['client_details'], $this->clientDetails($company));
$this->exported_variables['$company_details'] = $this->processVariables($this->input_variables['company_details'], $this->companyDetails($company));
$this->exported_variables['$company_address'] = $this->processVariables($this->input_variables['company_address'], $this->companyAddress($company));
public function getHtml():string if ($this->entity_string == 'invoice') {
{ $this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['invoice_details'], $this->invoiceDetails($company));
return $this->html; $this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['invoice_details'], $this->invoiceDetails($company));
} } elseif ($this->entity_string == 'credit') {
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['credit_details'], $this->creditDetails($company));
public function setHtml() $this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['credit_details'], $this->creditDetails($company));
{ } elseif ($this->entity_string == 'quote') {
$this->html = ''; $this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['quote_details'], $this->quoteDetails($company));
$this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['quote_details'], $this->quoteDetails($company));
return $this; }
}
private function setDesign($section)
{
$this->html .= $section;
return $this;
}
/**
* Returns the template section on with the
* stacked variables replaced with single variables.
*
* @param string $section the method name to be executed ie header/body/table/footer
* @return string The HTML of the template section
*/
public function getSection($section):string
{
return str_replace(array_keys($this->exported_variables), array_values($this->exported_variables), $this->design->{$section});
}
private function exportVariables()
{
$company = $this->entity->company;
$this->exported_variables['$app_url'] = $this->entity->generateAppUrl();
$this->exported_variables['$client_details'] = $this->processVariables($this->input_variables['client_details'], $this->clientDetails($company));
$this->exported_variables['$company_details'] = $this->processVariables($this->input_variables['company_details'], $this->companyDetails($company));
$this->exported_variables['$company_address'] = $this->processVariables($this->input_variables['company_address'], $this->companyAddress($company));
if($this->entity_string == 'invoice')
{
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['invoice_details'], $this->invoiceDetails($company));
$this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['invoice_details'], $this->invoiceDetails($company));
}
elseif($this->entity_string == 'credit')
{
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['credit_details'], $this->creditDetails($company));
$this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['credit_details'], $this->creditDetails($company));
}
elseif($this->entity_string == 'quote')
{
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['quote_details'], $this->quoteDetails($company));
$this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['quote_details'], $this->quoteDetails($company));
}
$this->exported_variables['$product_table_header']= $this->entity->buildTableHeader($this->input_variables['product_columns']); $this->exported_variables['$product_table_header']= $this->entity->buildTableHeader($this->input_variables['product_columns']);
$this->exported_variables['$product_table_body'] = $this->entity->buildTableBody($this->input_variables['product_columns'], $this->design->product, '$product'); $this->exported_variables['$product_table_body'] = $this->entity->buildTableBody($this->input_variables['product_columns'], $this->design->product, '$product');
$this->exported_variables['$task_table_header'] = $this->entity->buildTableHeader($this->input_variables['task_columns']); $this->exported_variables['$task_table_header'] = $this->entity->buildTableHeader($this->input_variables['task_columns']);
$this->exported_variables['$task_table_body'] = $this->entity->buildTableBody($this->input_variables['task_columns'], $this->design->task, '$task'); $this->exported_variables['$task_table_body'] = $this->entity->buildTableBody($this->input_variables['task_columns'], $this->design->task, '$task');
if(strlen($this->exported_variables['$task_table_body']) == 0) if (strlen($this->exported_variables['$task_table_body']) == 0) {
$this->exported_variables['$task_table_header'] = ''; $this->exported_variables['$task_table_header'] = '';
}
if(strlen($this->exported_variables['$product_table_body']) == 0) if (strlen($this->exported_variables['$product_table_body']) == 0) {
$this->exported_variables['$product_table_header'] = ''; $this->exported_variables['$product_table_header'] = '';
}
return $this; return $this;
} }
private function processVariables($input_variables, $variables):string private function processVariables($input_variables, $variables):string
{ {
$output = ''; $output = '';
foreach (array_keys($input_variables) as $value) foreach (array_keys($input_variables) as $value) {
$output .= $variables[$value]; $output .= $variables[$value];
}
return $output; return $output;
}
} private function processLabels($input_variables, $variables):string
{
$output = '';
private function processLabels($input_variables, $variables):string foreach (array_keys($input_variables) as $value) {
{ $tmp = str_replace("</span>", "_label</span>", $variables[$value]);
//$output .= $variables[$value];
$output .= $tmp;
}
$output = ''; return $output;
}
foreach (array_keys($input_variables) as $value) { private function clientDetails(Company $company)
{
$data = [
'$client.name' => '<p>$client.name</p>',
'$client.id_number' => '<p>$client.id_number</p>',
'$client.vat_number' => '<p>$client.vat_number</p>',
'$client.address1' => '<p>$client.address1</p>',
'$client.address2' => '<p>$client.address2</p>',
'$client.city_state_postal' => '<p>$client.city_state_postal</p>',
'$client.postal_city_state' => '<p>$client.postal_city_state</p>',
'$client.country' => '<p>$client.country</p>',
'$client.email' => '<p>$client.email</p>',
'$client.client1' => '<p>$client1</p>',
'$client.client2' => '<p>$client2</p>',
'$client.client3' => '<p>$client3</p>',
'$client.client4' => '<p>$client4</p>',
'$client.contact1' => '<p>$contact1</p>',
'$client.contact2' => '<p>$contact2</p>',
'$client.contact3' => '<p>$contact3</p>',
'$client.contact4' => '<p>$contact4</p>',
];
$tmp = str_replace("</span>", "_label</span>", $variables[$value]); return $this->processCustomFields($company, $data);
//$output .= $variables[$value]; }
$output .= $tmp;
}
return $output; private function companyDetails(Company $company)
} {
$data = [
'$company.company_name' => '<span>$company.company_name</span>',
'$company.id_number' => '<span>$company.id_number</span>',
'$company.vat_number' => '<span>$company.vat_number</span>',
'$company.website' => '<span>$company.website</span>',
'$company.email' => '<span>$company.email</span>',
'$company.phone' => '<span>$company.phone</span>',
'$company.company1' => '<span>$company1</span>',
'$company.company2' => '<span>$company2</span>',
'$company.company3' => '<span>$company3</span>',
'$company.company4' => '<span>$company4</span>',
];
private function clientDetails(Company $company) return $this->processCustomFields($company, $data);
{ }
$data = [ private function companyAddress(Company $company)
'$client.name' => '<p>$client.name</p>', {
'$client.id_number' => '<p>$client.id_number</p>', $data = [
'$client.vat_number' => '<p>$client.vat_number</p>', '$company.address1' => '<span>$company.address1</span>',
'$client.address1' => '<p>$client.address1</p>', '$company.address2' => '<span>$company.address2</span>',
'$client.address2' => '<p>$client.address2</p>', '$company.city_state_postal' => '<span>$company.city_state_postal</span>',
'$client.city_state_postal' => '<p>$client.city_state_postal</p>', '$company.postal_city_state' => '<span>$company.postal_city_state</span>',
'$client.postal_city_state' => '<p>$client.postal_city_state</p>', '$company.country' => '<span>$company.country</span>',
'$client.country' => '<p>$client.country</p>', '$company.company1' => '<span>$company1</span>',
'$client.email' => '<p>$client.email</p>', '$company.company2' => '<span>$company2</span>',
'$client.client1' => '<p>$client1</p>', '$company.company3' => '<span>$company3</span>',
'$client.client2' => '<p>$client2</p>', '$company.company4' => '<span>$company4</span>',
'$client.client3' => '<p>$client3</p>', ];
'$client.client4' => '<p>$client4</p>',
'$client.contact1' => '<p>$contact1</p>',
'$client.contact2' => '<p>$contact2</p>',
'$client.contact3' => '<p>$contact3</p>',
'$client.contact4' => '<p>$contact4</p>',
];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
} }
private function companyDetails(Company $company) private function invoiceDetails(Company $company)
{ {
$data = [
'$invoice.invoice_number' => '<span>$invoice_number_label</span><span>$invoice_number</span>',
'$invoice.po_number' => '<span>$po_number_label</span><span>$po_number</span>',
'$invoice.invoice_date' => '<span>$invoice_date_label</span><span>$invoice_date</span>',
'$invoice.due_date' => '<span>$due_date_label</span><span>$due_date</span>',
'$invoice.balance_due' => '<span>$balance_due_label</span><span>$balance_due</span>',
'$invoice.invoice_total' => '<span>$invoice_total_label</span><span>$invoice_total</span>',
'$invoice.partial_due' => '<span>$partial_due_label</span><span>$partial_due</span>',
'$invoice.invoice1' => '<span>$invoice1_label</span><span>$invoice1</span>',
'$invoice.invoice2' => '<span>$invoice2_label</span><span>$invoice2</span>',
'$invoice.invoice3' => '<span>$invoice3_label</span><span>$invoice3</span>',
'$invoice.invoice4' => '<span>$invoice4_label</span><span>$invoice4</span>',
'$invoice.surcharge1' => '<span>$surcharge1_label</span><span>$surcharge1</span>',
'$invoice.surcharge2' => '<span>$surcharge2_label</span><span>$surcharge2</span>',
'$invoice.surcharge3' => '<span>$surcharge3_label</span><span>$surcharge3</span>',
'$invoice.surcharge4' => '<span>$surcharge4_label</span><span>$surcharge4</span>',
];
$data = [ return $this->processCustomFields($company, $data);
'$company.company_name' => '<span>$company.company_name</span>', }
'$company.id_number' => '<span>$company.id_number</span>',
'$company.vat_number' => '<span>$company.vat_number</span>',
'$company.website' => '<span>$company.website</span>',
'$company.email' => '<span>$company.email</span>',
'$company.phone' => '<span>$company.phone</span>',
'$company.company1' => '<span>$company1</span>',
'$company.company2' => '<span>$company2</span>',
'$company.company3' => '<span>$company3</span>',
'$company.company4' => '<span>$company4</span>',
];
return $this->processCustomFields($company, $data); private function quoteDetails(Company $company)
{
$data = [
'$quote.quote_number' => '<span>$quote_number</span>',
'$quote.po_number' => '<span>$po_number</span>',
'$quote.quote_date' => '<span>$date</span>',
'$quote.valid_until' => '<span>$valid_until</span>',
'$quote.balance_due' => '<span>$balance_due</span>',
'$quote.quote_total' => '<span>$quote_total</span>',
'$quote.partial_due' => '<span>$partial_due</span>',
'$quote.quote1' => '<span>$quote1</span>',
'$quote.quote2' => '<span>$quote2</span>',
'$quote.quote3' => '<span>$quote3</span>',
'$quote.quote4' => '<span>$quote4</span>',
'$quote.surcharge1' => '<span>$surcharge1</span>',
'$quote.surcharge2' => '<span>$surcharge2</span>',
'$quote.surcharge3' => '<span>$surcharge3</span>',
'$quote.surcharge4' => '<span>$surcharge4</span>',
];
} return $this->processCustomFields($company, $data);
}
private function companyAddress(Company $company) private function creditDetails(Company $company)
{ {
$data = [
'$credit.credit_number' => '<span>$credit_number</span>',
'$credit.po_number' => '<span>$po_number</span>',
'$credit.credit_date' => '<span>$date</span>',
'$credit.credit_balance' => '<span>$credit_balance</span>',
'$credit.credit_amount' => '<span>$credit_amount</span>',
'$credit.partial_due' => '<span>$partial_due</span>',
'$credit.invoice1' => '<span>$invoice1</span>',
'$credit.invoice2' => '<span>$invoice2</span>',
'$credit.invoice3' => '<span>$invoice3</span>',
'$credit.invoice4' => '<span>$invoice4</span>',
'$credit.surcharge1' => '<span>$surcharge1</span>',
'$credit.surcharge2' => '<span>$surcharge2</span>',
'$credit.surcharge3' => '<span>$surcharge3</span>',
'$credit.surcharge4' => '<span>$surcharge4</span>',
];
$data = [ return $this->processCustomFields($company, $data);
'$company.address1' => '<span>$company.address1</span>', }
'$company.address2' => '<span>$company.address2</span>',
'$company.city_state_postal' => '<span>$company.city_state_postal</span>',
'$company.postal_city_state' => '<span>$company.postal_city_state</span>',
'$company.country' => '<span>$company.country</span>',
'$company.company1' => '<span>$company1</span>',
'$company.company2' => '<span>$company2</span>',
'$company.company3' => '<span>$company3</span>',
'$company.company4' => '<span>$company4</span>',
];
return $this->processCustomFields($company, $data); private function processCustomFields(Company $company, $data)
{
$custom_fields = $company->custom_fields;
} if (!$custom_fields) {
return $data;
}
private function invoiceDetails(Company $company) foreach (self::$custom_fields as $cf) {
{ if (!property_exists($custom_fields, $cf) || (strlen($custom_fields->{$cf}) == 0)) {
unset($data[$cf]);
}
}
$data = [ return $data;
'$invoice.invoice_number' => '<span>$invoice_number_label</span><span>$invoice_number</span>', }
'$invoice.po_number' => '<span>$po_number_label</span><span>$po_number</span>',
'$invoice.invoice_date' => '<span>$invoice_date_label</span><span>$invoice_date</span>',
'$invoice.due_date' => '<span>$due_date_label</span><span>$due_date</span>',
'$invoice.balance_due' => '<span>$balance_due_label</span><span>$balance_due</span>',
'$invoice.invoice_total' => '<span>$invoice_total_label</span><span>$invoice_total</span>',
'$invoice.partial_due' => '<span>$partial_due_label</span><span>$partial_due</span>',
'$invoice.invoice1' => '<span>$invoice1_label</span><span>$invoice1</span>',
'$invoice.invoice2' => '<span>$invoice2_label</span><span>$invoice2</span>',
'$invoice.invoice3' => '<span>$invoice3_label</span><span>$invoice3</span>',
'$invoice.invoice4' => '<span>$invoice4_label</span><span>$invoice4</span>',
'$invoice.surcharge1' => '<span>$surcharge1_label</span><span>$surcharge1</span>',
'$invoice.surcharge2' => '<span>$surcharge2_label</span><span>$surcharge2</span>',
'$invoice.surcharge3' => '<span>$surcharge3_label</span><span>$surcharge3</span>',
'$invoice.surcharge4' => '<span>$surcharge4_label</span><span>$surcharge4</span>',
];
return $this->processCustomFields($company, $data); // private function processInputVariables($company, $variables)
// {
// if(is_object($variables))
// $variables = json_decode(json_encode($variables),true);
} // $custom_fields = $company->custom_fields;
private function quoteDetails(Company $company) // $matches = array_intersect(self::$custom_fields, $variables);
{
$data = [
'$quote.quote_number' => '<span>$quote_number</span>',
'$quote.po_number' => '<span>$po_number</span>',
'$quote.quote_date' => '<span>$date</span>',
'$quote.valid_until' => '<span>$valid_until</span>',
'$quote.balance_due' => '<span>$balance_due</span>',
'$quote.quote_total' => '<span>$quote_total</span>',
'$quote.partial_due' => '<span>$partial_due</span>',
'$quote.quote1' => '<span>$quote1</span>',
'$quote.quote2' => '<span>$quote2</span>',
'$quote.quote3' => '<span>$quote3</span>',
'$quote.quote4' => '<span>$quote4</span>',
'$quote.surcharge1' => '<span>$surcharge1</span>',
'$quote.surcharge2' => '<span>$surcharge2</span>',
'$quote.surcharge3' => '<span>$surcharge3</span>',
'$quote.surcharge4' => '<span>$surcharge4</span>',
];
return $this->processCustomFields($company, $data); // foreach ($matches as $match) {
} // if (!property_exists($custom_fields, $match) || (strlen($custom_fields->{$match}) == 0)) {
// foreach ($variables as $key => $value) {
// if ($value == $match) {
// unset($variables[$key]);
// }
// }
// }
private function creditDetails(Company $company) // }
{
$data = [ // return $variables;
'$credit.credit_number' => '<span>$credit_number</span>',
'$credit.po_number' => '<span>$po_number</span>',
'$credit.credit_date' => '<span>$date</span>',
'$credit.credit_balance' => '<span>$credit_balance</span>',
'$credit.credit_amount' => '<span>$credit_amount</span>',
'$credit.partial_due' => '<span>$partial_due</span>',
'$credit.invoice1' => '<span>$invoice1</span>',
'$credit.invoice2' => '<span>$invoice2</span>',
'$credit.invoice3' => '<span>$invoice3</span>',
'$credit.invoice4' => '<span>$invoice4</span>',
'$credit.surcharge1' => '<span>$surcharge1</span>',
'$credit.surcharge2' => '<span>$surcharge2</span>',
'$credit.surcharge3' => '<span>$surcharge3</span>',
'$credit.surcharge4' => '<span>$surcharge4</span>',
];
return $this->processCustomFields($company, $data); // }
}
}
private function processCustomFields(Company $company, $data)
{
$custom_fields = $company->custom_fields;
if (!$custom_fields) {
return $data;
}
foreach (self::$custom_fields as $cf) {
if (!property_exists($custom_fields, $cf) || (strlen($custom_fields->{$cf}) == 0)) {
unset($data[$cf]);
}
}
return $data;
}
// private function processInputVariables($company, $variables)
// {
// if(is_object($variables))
// $variables = json_decode(json_encode($variables),true);
// $custom_fields = $company->custom_fields;
// $matches = array_intersect(self::$custom_fields, $variables);
// foreach ($matches as $match) {
// if (!property_exists($custom_fields, $match) || (strlen($custom_fields->{$match}) == 0)) {
// foreach ($variables as $key => $value) {
// if ($value == $match) {
// unset($variables[$key]);
// }
// }
// }
// }
// return $variables;
// }
}

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Elegant extends AbstractDesign class Elegant extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -39,9 +39,9 @@ class Elegant extends AbstractDesign
} }
public function header() { public function header()
{
return '<div class="py-16 px-8"> return '<div class="py-16 px-8">
<div class="flex flex justify-between border-b-4 border-black"> <div class="flex flex justify-between border-b-4 border-black">
<div style="margin-bottom: 15px"> <div style="margin-bottom: 15px">
$company_logo $company_logo
@ -56,11 +56,10 @@ class Elegant extends AbstractDesign
</div> </div>
</div> </div>
<div class="p-px border-b border-black mt-1"></div>'; <div class="p-px border-b border-black mt-1"></div>';
}
} public function body()
{
public function body() {
return '<div class="flex mt-8"> return '<div class="flex mt-8">
<div class="w-1/3 mr-6 flex flex-col pr-2 border-r border-dashed border-black"> <div class="w-1/3 mr-6 flex flex-col pr-2 border-r border-dashed border-black">
$client_details $client_details
@ -88,11 +87,11 @@ class Elegant extends AbstractDesign
$product_table_body $product_table_body
</tbody> </tbody>
</table>'; </table>';
}
} public function task()
{
public function task() { return '';
return '';
} }
public function product() public function product()
@ -100,8 +99,8 @@ class Elegant extends AbstractDesign
return ''; return '';
} }
public function footer() { public function footer()
{
return '<div class="flex items-center justify-between mt-2 px-4 pb-4"> return '<div class="flex items-center justify-between mt-2 px-4 pb-4">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
@ -142,7 +141,5 @@ class Elegant extends AbstractDesign
</div> </div>
<div class="p-px border-b border-black mt-1"></div> <div class="p-px border-b border-black mt-1"></div>
</div>'; </div>';
}
}
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Hipster extends AbstractDesign class Hipster extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -40,9 +40,9 @@ body {font-size:90%}
} }
public function header() { public function header()
{
return '<div class="px-12 py-16"> return '<div class="px-12 py-16">
<div class="flex"> <div class="flex">
<div class="w-1/2 border-l pl-4 border-black mr-4"> <div class="w-1/2 border-l pl-4 border-black mr-4">
<p class="font-semibold uppercase text-yellow-600">From:</p> <p class="font-semibold uppercase text-yellow-600">From:</p>
@ -63,11 +63,10 @@ body {font-size:90%}
$company_logo $company_logo
</div> </div>
</div>'; </div>';
}
} public function body()
{
public function body() {
return '<div class="flex flex-col mx-6 mt-10"> return '<div class="flex flex-col mx-6 mt-10">
<h1 class="font-semibold uppercase text-6xl">$entity_label</h1> <h1 class="font-semibold uppercase text-6xl">$entity_label</h1>
<div class="flex mt-1"> <div class="flex mt-1">
@ -102,20 +101,20 @@ body {font-size:90%}
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
}
} public function task()
{
public function task() { return '';
return '';
} }
public function product() public function product()
{ {
return ''; return '';
} }
public function footer() { public function footer()
{
return '<div class="flex justify-between mt-8"> return '<div class="flex justify-between mt-8">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
@ -148,7 +147,5 @@ body {font-size:90%}
</div> </div>
</body> </body>
</html>'; </html>';
}
}
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Modern extends AbstractDesign class Modern extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -61,9 +61,9 @@ class Modern extends AbstractDesign
} }
public function header() { public function header()
{
return '<div class="div_header bg-orange-600 flex justify-between py-12 px-12" style="page-break-inside: avoid;"> return '<div class="div_header bg-orange-600 flex justify-between py-12 px-12" style="page-break-inside: avoid;">
<div class="w-1/2"> <div class="w-1/2">
<h1 class="text-white font-bold text-5xl">$company.name</h1> <h1 class="text-white font-bold text-5xl">$company.name</h1>
</div> </div>
@ -76,12 +76,11 @@ class Modern extends AbstractDesign
</div> </div>
</div> </div>
</div>'; </div>';
}
} public function body()
{
public function body() { return '<section>
return '<section>
<div class="flex justify-between px-12 pt-12"> <div class="flex justify-between px-12 pt-12">
<div class="w-1/2"> <div class="w-1/2">
$company_logo $company_logo
@ -112,11 +111,11 @@ class Modern extends AbstractDesign
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
}
} public function task()
{
public function task() { return '';
return '';
} }
public function product() public function product()
@ -124,9 +123,9 @@ class Modern extends AbstractDesign
return ''; return '';
} }
public function footer() { public function footer()
{
return ' return '
<div class="flex px-4 mt-6 w-full" style="page-break-inside: avoid;"> <div class="flex px-4 mt-6 w-full" style="page-break-inside: avoid;">
<div class="w-1/2"> <div class="w-1/2">
$entity.public_notes $entity.public_notes
@ -181,7 +180,5 @@ class Modern extends AbstractDesign
</footer> </footer>
</html> </html>
'; ';
}
}
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Photo extends AbstractDesign class Photo extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -44,9 +44,9 @@ body {font-size:90%}
public function header() { public function header()
{
return '<div class="px-16 py-10"> return '<div class="px-16 py-10">
<div class="flex items-center justify-between mt-2s"> <div class="flex items-center justify-between mt-2s">
<div ref="logo"> <div ref="logo">
$company_logo $company_logo
@ -61,11 +61,10 @@ body {font-size:90%}
</div> </div>
</div> </div>
</div>'; </div>';
}
} public function body()
{
public function body() {
return '<div class="flex content-center flex-wrap bg-gray-200 h-auto p-16" id="imageContainer"> return '<div class="flex content-center flex-wrap bg-gray-200 h-auto p-16" id="imageContainer">
<div class="flex flex-col"> <div class="flex flex-col">
<div class="flex"> <div class="flex">
@ -99,10 +98,10 @@ body {font-size:90%}
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
}
} public function task()
{
public function task() {
return ''; return '';
} }
@ -111,8 +110,8 @@ body {font-size:90%}
return ''; return '';
} }
public function footer() { public function footer()
{
return '<div class="flex items-center justify-between mt-2 px-4 pb-4"> return '<div class="flex items-center justify-between mt-2 px-4 pb-4">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
@ -153,7 +152,5 @@ body {font-size:90%}
</div> </div>
</body> </body>
</html>'; </html>';
}
}
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Plain extends AbstractDesign class Plain extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -38,9 +38,9 @@ body {font-size:90%}
} }
public function header() { public function header()
{
return ' <div class="px-12 py-8"> return ' <div class="px-12 py-8">
<div class="flex justify-between"> <div class="flex justify-between">
$company_logo $company_logo
<div class="flex flex-col"> <div class="flex flex-col">
@ -58,11 +58,10 @@ body {font-size:90%}
</section> </section>
</div> </div>
</div>'; </div>';
}
} public function body()
{
public function body() {
return '<div class="flex flex-col mt-8"> return '<div class="flex flex-col mt-8">
$client_details $client_details
</div> </div>
@ -81,22 +80,8 @@ body {font-size:90%}
<tbody> <tbody>
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>
<div class="flex justify-between mt-8">
}
public function task() {
return '';
}
public function product()
{
return '';
}
public function footer() {
return '<div class="flex justify-between mt-8">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
<p>$entity.public_notes</p> <p>$entity.public_notes</p>
@ -124,11 +109,21 @@ body {font-size:90%}
<p class="text-right w-1/2">$balance_due</p> <p class="text-right w-1/2">$balance_due</p>
</section> </section>
</div> </div>
</div>';
}
</div> public function task()
</body> {
</html>'; return '';
}
} public function product()
{
return '';
}
public function footer()
{
return '';
}
} }

View File

@ -13,9 +13,9 @@ namespace App\Designs;
class Playful extends AbstractDesign class Playful extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -39,9 +39,9 @@ body {font-size:90%}
} }
public function header() { public function header()
{
return '<div class="my-12 mx-16"> return '<div class="my-12 mx-16">
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div class="w-1/2"> <div class="w-1/2">
$company_logo $company_logo
@ -57,11 +57,10 @@ body {font-size:90%}
</div> </div>
</div> </div>
</div>'; </div>';
}
} public function body()
{
public function body() {
return '<div class="flex mt-16"> return '<div class="flex mt-16">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
@ -99,22 +98,8 @@ body {font-size:90%}
<tbody> <tbody>
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>
<div class="flex items-center justify-between mt-2 px-4 pb-4">
}
public function task() {
return '';
}
public function product()
{
return '';
}
public function footer() {
return '<div class="flex items-center justify-between mt-2 px-4 pb-4">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
<p>$entity.public_notes</p> <p>$entity.public_notes</p>
@ -134,7 +119,6 @@ body {font-size:90%}
</section> </section>
</div> </div>
</div> </div>
</div>
<div class="flex items-center justify-between mt-4 pb-4 px-4"> <div class="flex items-center justify-between mt-4 pb-4 px-4">
<div class="w-1/2"> <div class="w-1/2">
<div class="flex flex-col"> <div class="flex flex-col">
@ -147,14 +131,21 @@ body {font-size:90%}
<p class="w-1/2">$balance_due_label</p> <p class="w-1/2">$balance_due_label</p>
<p class="text-right w-1/2">$balance_due</p> <p class="text-right w-1/2">$balance_due</p>
</section> </section>
</div> </div>';
</div> }
</div>
</div> public function task()
</body> {
</html>'; return '';
}
} public function product()
{
return '';
}
public function footer()
{
return '';
}
} }

View File

@ -7,13 +7,13 @@ use App\Models\Quote;
class CloneQuoteToInvoiceFactory class CloneQuoteToInvoiceFactory
{ {
public static function create(Quote $quote, $user_id) : ?Invoice public static function create(Quote $quote, $user_id) : ?Invoice
{ {
$invoice = new Invoice(); $invoice = new Invoice();
$invoice->user_id = $user_id; $invoice->user_id = $user_id;
$invoice->po_number = $quote->po_number; $invoice->po_number = $quote->po_number;
$invoice->footer = $quote->footer; $invoice->footer = $quote->footer;
$invoice->line_items = $quote->line_items; $invoice->line_items = $quote->line_items;
return $invoice; return $invoice;
} }
} }

View File

@ -57,7 +57,7 @@ class CreditFilters extends QueryFilters
$this->builder->where('status_id', Credit::STAUTS_PARTIAL); $this->builder->where('status_id', Credit::STAUTS_PARTIAL);
} }
if(in_array('applied', $status_parameters)) { if (in_array('applied', $status_parameters)) {
$this->builder->where('status_id', Credit::STATUS_APPLIED); $this->builder->where('status_id', Credit::STATUS_APPLIED);
} }

View File

@ -138,6 +138,6 @@ class DesignFilters extends QueryFilters
public function entityFilter() public function entityFilter()
{ {
//return $this->builder->whereCompanyId(auth()->user()->company()->id); //return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id',null); return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
} }
} }

View File

@ -8,55 +8,62 @@
namespace App\Helpers\Email; namespace App\Helpers\Email;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\InvoiceInvitation; use App\Models\InvoiceInvitation;
use App\Utils\Number; use App\Utils\Number;
class InvoiceEmail extends EmailBuilder class InvoiceEmail extends EmailBuilder
{ {
public function build(InvoiceInvitation $invitation, $reminder_template) public function build(InvoiceInvitation $invitation, $reminder_template)
{ {
$client = $invitation->contact->client; $client = $invitation->contact->client;
$invoice = $invitation->invoice; $invoice = $invitation->invoice;
$contact = $invitation->contact; $contact = $invitation->contact;
if(!$reminder_template) if (!$reminder_template) {
$reminder_template = $invoice->calculateTemplate(); $reminder_template = $invoice->calculateTemplate();
}
$body_template = $client->getSetting('email_template_' . $reminder_template); $body_template = $client->getSetting('email_template_' . $reminder_template);
/* Use default translations if a custom message has not been set*/ /* Use default translations if a custom message has not been set*/
if (iconv_strlen($body_template) == 0) { if (iconv_strlen($body_template) == 0) {
$body_template = trans('texts.invoice_message', $body_template = trans(
'texts.invoice_message',
[ [
'invoice' => $invoice->number, 'invoice' => $invoice->number,
'company' => $invoice->company->present()->name(), 'company' => $invoice->company->present()->name(),
'amount' => Number::formatMoney($invoice->balance, $invoice->client), 'amount' => Number::formatMoney($invoice->balance, $invoice->client),
], ],
null, null,
$invoice->client->locale()); $invoice->client->locale()
);
} }
$subject_template = $client->getSetting('email_subject_' . $reminder_template); $subject_template = $client->getSetting('email_subject_' . $reminder_template);
if (iconv_strlen($subject_template) == 0) { if (iconv_strlen($subject_template) == 0) {
if ($reminder_template == 'quote') { if ($reminder_template == 'quote') {
$subject_template = trans('texts.invoice_subject', $subject_template = trans(
'texts.invoice_subject',
[ [
'invoice' => $invoice->present()->invoice_number(), 'invoice' => $invoice->present()->invoice_number(),
'account' => $invoice->company->present()->name() 'account' => $invoice->company->present()->name()
], ],
null, $invoice->client->locale()); null,
$invoice->client->locale()
);
} else { } else {
$subject_template = trans('texts.reminder_subject', $subject_template = trans(
'texts.reminder_subject',
[ [
'invoice' => $invoice->present()->invoice_number(), 'invoice' => $invoice->present()->invoice_number(),
'account' => $invoice->company->present()->name() 'account' => $invoice->company->present()->name()
], ],
null, $invoice->client->locale()); null,
$invoice->client->locale()
);
} }
} }

View File

@ -10,28 +10,33 @@ namespace App\Helpers\Email;
use App\Models\Payment; use App\Models\Payment;
class EmailPayment extends EmailBuilder class EmailPayment extends EmailBuilder
{ {
public function build(Payment $payment, $contact = null) { public function build(Payment $payment, $contact = null)
{
$client = $payment->client; $client = $payment->client;
$body_template = $client->getSetting('email_template_payment'); $body_template = $client->getSetting('email_template_payment');
/* Use default translations if a custom message has not been set*/ /* Use default translations if a custom message has not been set*/
if (iconv_strlen($body_template) == 0) { if (iconv_strlen($body_template) == 0) {
$body_template = trans(
$body_template = trans('texts.payment_message', 'texts.payment_message',
['amount' => $payment->amount, 'company' => $payment->company->present()->name()], null, ['amount' => $payment->amount, 'company' => $payment->company->present()->name()],
$this->client->locale()); null,
$this->client->locale()
);
} }
$subject_template = $client->getSetting('email_subject_payment'); $subject_template = $client->getSetting('email_subject_payment');
if (iconv_strlen($subject_template) == 0) { if (iconv_strlen($subject_template) == 0) {
$subject_template = trans('texts.payment_subject', $subject_template = trans(
['number' => $payment->number, 'company' => $payment->company->present()->name()], null, 'texts.payment_subject',
$payment->client->locale()); ['number' => $payment->number, 'company' => $payment->company->present()->name()],
null,
$payment->client->locale()
);
} }
$this->setTemplate($payment->client->getSetting('email_style')) $this->setTemplate($payment->client->getSetting('email_style'))

View File

@ -11,10 +11,8 @@ namespace App\Helpers\Email;
use App\Models\Quote; use App\Models\Quote;
use App\Models\QuoteInvitation; use App\Models\QuoteInvitation;
class QuoteEmail extends EmailBuilder class QuoteEmail extends EmailBuilder
{ {
public function build(QuoteInvitation $invitation, $reminder_template) public function build(QuoteInvitation $invitation, $reminder_template)
{ {
$client = $invitation->contact->client; $client = $invitation->contact->client;
@ -27,22 +25,31 @@ class QuoteEmail extends EmailBuilder
/* Use default translations if a custom message has not been set*/ /* Use default translations if a custom message has not been set*/
if (iconv_strlen($body_template) == 0) { if (iconv_strlen($body_template) == 0) {
$body_template = trans('texts.quote_message', $body_template = trans(
['amount' => $quote->amount, 'company' => $quote->company->present()->name()], null, 'texts.quote_message',
$quote->client->locale()); ['amount' => $quote->amount, 'company' => $quote->company->present()->name()],
null,
$quote->client->locale()
);
} }
$subject_template = $client->getSetting('email_subject_' . $reminder_template); $subject_template = $client->getSetting('email_subject_' . $reminder_template);
if (iconv_strlen($subject_template) == 0) { if (iconv_strlen($subject_template) == 0) {
if ($reminder_template == 'quote') { if ($reminder_template == 'quote') {
$subject_template = trans('texts.quote_subject', $subject_template = trans(
'texts.quote_subject',
['number' => $quote->number, 'company' => $quote->company->present()->name()], ['number' => $quote->number, 'company' => $quote->company->present()->name()],
null, $quote->client->locale()); null,
$quote->client->locale()
);
} else { } else {
$subject_template = trans('texts.reminder_subject', $subject_template = trans(
'texts.reminder_subject',
['number' => $quote->number, 'company' => $quote->company->present()->name()], ['number' => $quote->number, 'company' => $quote->company->present()->name()],
null, $quote->client->locale()); null,
$quote->client->locale()
);
} }
} }

View File

@ -1,8 +1,4 @@
<?php <?php
use App\Models\Document;
use Illuminate\Support\Facades\Storage;
/** /**
* Invoice Ninja (https://invoiceninja.com) * Invoice Ninja (https://invoiceninja.com)
* *
@ -13,7 +9,10 @@ use Illuminate\Support\Facades\Storage;
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
/** use App\Models\Document;
use Illuminate\Support\Facades\Storage;
/**
* Generate url for the asset. * Generate url for the asset.
* *
* @param Document $document * @param Document $document
@ -24,9 +23,13 @@ function generateUrl(Document $document, $absolute = false)
{ {
$url = Storage::disk($document->disk)->url($document->path); $url = Storage::disk($document->disk)->url($document->path);
if($url && $absolute) return url($url); if ($url && $absolute) {
return url($url);
}
if ($url) return $url; if ($url) {
return $url;
}
return null; return null;
} }

View File

@ -173,22 +173,18 @@ class InvoiceSum
public function getQuote() public function getQuote()
{ {
$this->setCalculatedAttributes(); $this->setCalculatedAttributes();
$this->invoice->save(); $this->invoice->save();
return $this->invoice; return $this->invoice;
} }
public function getCredit() public function getCredit()
{ {
$this->setCalculatedAttributes(); $this->setCalculatedAttributes();
$this->invoice->save(); $this->invoice->save();
return $this->invoice; return $this->invoice;
} }
/** /**

View File

@ -147,8 +147,9 @@ class AccountController extends BaseController
{ {
$account = CreateAccount::dispatchNow($request->all()); $account = CreateAccount::dispatchNow($request->all());
if(!($account instanceof Account)) if (!($account instanceof Account)) {
return $account; return $account;
}
$ct = CompanyUser::whereUserId(auth()->user()->id); $ct = CompanyUser::whereUserId(auth()->user()->id);

View File

@ -175,9 +175,7 @@ class LoginController extends BaseController
$ct = CompanyUser::whereUserId($user->id)->with('company'); $ct = CompanyUser::whereUserId($user->id)->with('company');
return $this->listResponse($ct); return $this->listResponse($ct);
} else { } else {
$this->incrementLoginAttempts($request); $this->incrementLoginAttempts($request);
return response() return response()

View File

@ -67,9 +67,10 @@ class ResetPasswordController extends Controller
// will update the password on an actual user model and persist it to the // will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response. // database. Otherwise we will parse the error and return the response.
$response = $this->broker()->reset( $response = $this->broker()->reset(
$this->credentials($request), function ($user, $password) { $this->credentials($request),
$this->resetPassword($user, $password); function ($user, $password) {
} $this->resetPassword($user, $password);
}
); );
// Added this because it collides the session between // Added this because it collides the session between

View File

@ -32,7 +32,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
*/ */
class BaseController extends Controller class BaseController extends Controller
{ {
use AppSetup; use AppSetup;
/** /**
* Passed from the parent when we need to force * Passed from the parent when we need to force
* includes internally rather than externally via * includes internally rather than externally via
@ -58,35 +58,25 @@ class BaseController extends Controller
public function __construct() public function __construct()
{ {
$this->manager = new Manager(); $this->manager = new Manager();
$this->forced_includes = []; $this->forced_includes = [];
$this->forced_index = 'data'; $this->forced_index = 'data';
} }
private function buildManager() private function buildManager()
{ {
$include = ''; $include = '';
if(request()->has('first_load') && request()->input('first_load') == 'true') { if (request()->has('first_load') && request()->input('first_load') == 'true') {
$include = implode(",", array_merge($this->forced_includes, $this->getRequestIncludes([])));
$include = implode("," , array_merge($this->forced_includes, $this->getRequestIncludes([]))); } elseif (request()->input('include') !== null) {
}
else if (request()->input('include') !== null) {
$include = array_merge($this->forced_includes, explode(",", request()->input('include'))); $include = array_merge($this->forced_includes, explode(",", request()->input('include')));
$include = implode(",", $include); $include = implode(",", $include);
} elseif (count($this->forced_includes) >= 1) { } elseif (count($this->forced_includes) >= 1) {
$include = implode(",", $this->forced_includes); $include = implode(",", $this->forced_includes);
} }
$this->manager->parseIncludes($include); $this->manager->parseIncludes($include);
@ -94,15 +84,10 @@ class BaseController extends Controller
$this->serializer = request()->input('serializer') ?: EntityTransformer::API_SERIALIZER_ARRAY; $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()); $this->manager->setSerializer(new JsonApiSerializer());
} else { } else {
$this->manager->setSerializer(new ArraySerializer()); $this->manager->setSerializer(new ArraySerializer());
} }
} }
/** /**
@ -111,23 +96,18 @@ class BaseController extends Controller
*/ */
public function notFound() public function notFound()
{ {
return response()->json(['message' => '404 | Nothing to see here!'], 404) return response()->json(['message' => '404 | Nothing to see here!'], 404)
->header('X-API-VERSION', config('ninja.api_version')) ->header('X-API-VERSION', config('ninja.api_version'))
->header('X-APP-VERSION', config('ninja.app_version')); ->header('X-APP-VERSION', config('ninja.app_version'));
} }
public function notFoundClient() public function notFoundClient()
{ {
return abort(404); return abort(404);
} }
protected function errorResponse($response, $httpErrorCode = 400) protected function errorResponse($response, $httpErrorCode = 400)
{ {
$error['error'] = $response; $error['error'] = $response;
$error = json_encode($error, JSON_PRETTY_PRINT); $error = json_encode($error, JSON_PRETTY_PRINT);
@ -135,12 +115,10 @@ class BaseController extends Controller
$headers = self::getApiHeaders(); $headers = self::getApiHeaders();
return response()->make($error, $httpErrorCode, $headers); return response()->make($error, $httpErrorCode, $headers);
} }
protected function listResponse($query) protected function listResponse($query)
{ {
$this->buildManager(); $this->buildManager();
$transformer = new $this->entity_transformer(Input::get('serializer')); $transformer = new $this->entity_transformer(Input::get('serializer'));
@ -152,7 +130,7 @@ class BaseController extends Controller
$query->with($includes); $query->with($includes);
if (auth()->user()->cannot('view_'.$this->entity_type)) { if (auth()->user()->cannot('view_'.$this->entity_type)) {
if ($this->entity_type == Company::class || $this->entity_type == Design::class ) { if ($this->entity_type == Company::class || $this->entity_type == Design::class) {
//no user keys exist on the company table, so we need to skip //no user keys exist on the company table, so we need to skip
} elseif ($this->entity_type == User::class) { } elseif ($this->entity_type == User::class) {
//$query->where('id', '=', auth()->user()->id); @todo why? //$query->where('id', '=', auth()->user()->id); @todo why?
@ -162,47 +140,40 @@ class BaseController extends Controller
} }
if (request()->has('updated_at') && request()->input('updated_at') > 0) { if (request()->has('updated_at') && request()->input('updated_at') > 0) {
$updated_at = intval(request()->input('updated_at')); $updated_at = intval(request()->input('updated_at'));
$query->where('updated_at', '>=', date('Y-m-d H:i:s', $updated_at)); $query->where('updated_at', '>=', date('Y-m-d H:i:s', $updated_at));
} }
$data = $this->createCollection($query, $transformer, $this->entity_type); $data = $this->createCollection($query, $transformer, $this->entity_type);
return $this->response($data); return $this->response($data);
} }
protected function createCollection($query, $transformer, $entity_type) protected function createCollection($query, $transformer, $entity_type)
{ {
$this->buildManager(); $this->buildManager();
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON) {
$entity_type = null; $entity_type = null;
}
if (is_a($query, "Illuminate\Database\Eloquent\Builder")) { if (is_a($query, "Illuminate\Database\Eloquent\Builder")) {
$limit = Input::get('per_page', 20); $limit = Input::get('per_page', 20);
$paginator = $query->paginate($limit); $paginator = $query->paginate($limit);
$query = $paginator->getCollection(); $query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $entity_type); $resource = new Collection($query, $transformer, $entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
} else { } else {
$resource = new Collection($query, $transformer, $entity_type); $resource = new Collection($query, $transformer, $entity_type);
} }
return $this->manager->createData($resource)->toArray(); return $this->manager->createData($resource)->toArray();
} }
protected function response($response) protected function response($response)
{ {
$index = request()->input('index') ?: $this->forced_index; $index = request()->input('index') ?: $this->forced_index;
if ($index == 'none') { if ($index == 'none') {
@ -230,52 +201,46 @@ class BaseController extends Controller
$headers = self::getApiHeaders(); $headers = self::getApiHeaders();
return response()->make($response, 200, $headers); return response()->make($response, 200, $headers);
} }
protected function itemResponse($item) protected function itemResponse($item)
{ {
$this->buildManager(); $this->buildManager();
$transformer = new $this->entity_transformer(Input::get('serializer')); $transformer = new $this->entity_transformer(Input::get('serializer'));
$data = $this->createItem($item, $transformer, $this->entity_type); $data = $this->createItem($item, $transformer, $this->entity_type);
if (request()->include_static) if (request()->include_static) {
$data['static'] = Statics::company(auth()->user()->getCompany()->getLocale()); $data['static'] = Statics::company(auth()->user()->getCompany()->getLocale());
}
return $this->response($data); return $this->response($data);
} }
protected function createItem($data, $transformer, $entity_type) 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; $entity_type = null;
}
$resource = new Item($data, $transformer, $entity_type); $resource = new Item($data, $transformer, $entity_type);
return $this->manager->createData($resource)->toArray(); return $this->manager->createData($resource)->toArray();
} }
public static function getApiHeaders($count = 0) public static function getApiHeaders($count = 0)
{ {
return [ return [
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
'X-Api-Version' => config('ninja.api_version'), 'X-Api-Version' => config('ninja.api_version'),
'X-App-Version' => config('ninja.app_version'), 'X-App-Version' => config('ninja.app_version'),
]; ];
} }
protected function getRequestIncludes($data) protected function getRequestIncludes($data)
{ {
$first_load = [ $first_load = [
'account', 'account',
'user.company_user', 'user.company_user',
@ -311,49 +276,33 @@ class BaseController extends Controller
/** /**
* Thresholds for displaying large account on first load * Thresholds for displaying large account on first load
*/ */
if (request()->has('first_load') && request()->input('first_load') == 'true') if (request()->has('first_load') && request()->input('first_load') == 'true') {
{ if (auth()->user()->getCompany()->invoices->count() > 1000) {
$data = $mini_load;
if (auth()->user()->getCompany()->invoices->count() > 1000) } else {
{ $data = $first_load;
}
$data = $mini_load; } else {
$included = request()->input('include');
} $included = explode(',', $included);
else
{
$data = $first_load;
}
}
else
{
$included = request()->input('include');
$included = explode(',', $included);
foreach ($included as $include) {
if ($include == 'clients') {
$data[] = 'clients.contacts';
} elseif ($include) {
$data[] = $include;
}
}
foreach ($included as $include) {
if ($include == 'clients') {
$data[] = 'clients.contacts';
} elseif ($include) {
$data[] = $include;
}
}
} }
return $data; return $data;
} }
public function flutterRoute() public function flutterRoute()
{ {
if (!$this->checkAppSetup());
if(!$this->checkAppSetup());
return redirect('/setup'); return redirect('/setup');
return view('index.index'); return view('index.index');
} }
} }

View File

@ -279,8 +279,9 @@ class ClientController extends BaseController
*/ */
public function update(UpdateClientRequest $request, Client $client) public function update(UpdateClientRequest $request, Client $client)
{ {
if($request->entityIsDeleted($client)) if ($request->entityIsDeleted($client)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$client = $this->client_repo->save($request->all(), $client); $client = $this->client_repo->save($request->all(), $client);

View File

@ -38,26 +38,22 @@ class InvitationController extends Controller
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first(); $invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
if ($invitation) { if ($invitation) {
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) { if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
$this->middleware('auth:contact'); $this->middleware('auth:contact');
} else { } else {
auth()->guard('contact')->login($invitation->contact, false); auth()->guard('contact')->login($invitation->contact, false);
} }
if(!request()->has('silent')){ if (!request()->has('silent')) {
$invitation->markViewed(); $invitation->markViewed();
event(new InvitationWasViewed($entity, $invitation)); event(new InvitationWasViewed($entity, $invitation));
} }
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]); return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
} else {
} else
abort(404); abort(404);
}
} }
public function routerForDownload(string $entity, string $invitation_key) public function routerForDownload(string $entity, string $invitation_key)

View File

@ -461,41 +461,30 @@ class CompanyController extends BaseController
{ {
$company_count = $company->account->companies->count(); $company_count = $company->account->companies->count();
if($company_count == 1){ if ($company_count == 1) {
$company->company_users->each(function ($company_user) { $company->company_users->each(function ($company_user) {
$company_user->user->forceDelete(); $company_user->user->forceDelete();
}); });
$company->account->delete(); $company->account->delete();
} else {
}
else {
$account = $company->account; $account = $company->account;
$company_id = $company->id; $company_id = $company->id;
$company->delete(); $company->delete();
//If we are deleting the default companies, we'll need to make a new company the default. //If we are deleting the default companies, we'll need to make a new company the default.
if($account->default_company_id == $company_id){ if ($account->default_company_id == $company_id) {
$new_default_company = Company::whereAccountId($account->id)->first(); $new_default_company = Company::whereAccountId($account->id)->first();
$account->default_company_id = $new_default_company->id; $account->default_company_id = $new_default_company->id;
$account->save(); $account->save();
} }
} }
//@todo delete documents also!! //@todo delete documents also!!
//@todo in the hosted version deleting the last //@todo in the hosted version deleting the last
//account will trigger an account refund. //account will trigger an account refund.
return response()->json(['message' => 'success'], 200); return response()->json(['message' => 'success'], 200);
} }
} }

View File

@ -20,7 +20,6 @@ use Illuminate\Http\Request;
class CompanyUserController extends BaseController class CompanyUserController extends BaseController
{ {
protected $entity_type = CompanyUser::class; protected $entity_type = CompanyUser::class;
protected $entity_transformer = CompanyUserTransformer::class; protected $entity_transformer = CompanyUserTransformer::class;
@ -55,7 +54,6 @@ class CompanyUserController extends BaseController
public function store(CreateAccountRequest $request) public function store(CreateAccountRequest $request)
{ {
} }
/** /**
@ -127,27 +125,26 @@ class CompanyUserController extends BaseController
*/ */
public function update(UpdateCompanyUserRequest $request, User $user) public function update(UpdateCompanyUserRequest $request, User $user)
{ {
$company = auth()->user()->company(); $company = auth()->user()->company();
$company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first(); $company_user = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
if(!$company_user){ if (!$company_user) {
throw new ModelNotFoundException("Company User record not found"); throw new ModelNotFoundException("Company User record not found");
return; return;
} }
if(auth()->user()->isAdmin()){ if (auth()->user()->isAdmin()) {
$company_user->fill($request->input('company_user')); $company_user->fill($request->input('company_user'));
} } else {
else { $company_user->fill($request->input('company_user')['settings']);
$company_user->fill($request->input('company_user')['settings']); $company_user->fill($request->input('company_user')['notifications']);
$company_user->fill($request->input('company_user')['notifications']); }
}
$company_user->save(); $company_user->save();
return $this->itemResponse($company_user->fresh()); return $this->itemResponse($company_user->fresh());
} }
/** /**

View File

@ -33,8 +33,9 @@ class Controller extends BaseController
if (array_key_exists('root', $options)) { if (array_key_exists('root', $options)) {
return view( return view(
sprintf('%s.%s.%s', $options['root'], $theme, $path) sprintf('%s.%s.%s', $options['root'], $theme, $path),
, $options); $options
);
} }
return view("portal.$theme.$path", $options); return view("portal.$theme.$path", $options);

View File

@ -362,8 +362,9 @@ class CreditController extends BaseController
*/ */
public function update(UpdateCreditRequest $request, Credit $credit) public function update(UpdateCreditRequest $request, Credit $credit)
{ {
if($request->entityIsDeleted($credit)) if ($request->entityIsDeleted($credit)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$credit = $this->credit_repository->save($request->all(), $credit); $credit = $this->credit_repository->save($request->all(), $credit);
@ -572,16 +573,14 @@ class CreditController extends BaseController
} }
} }
public function downloadPdf($invitation_key) public function downloadPdf($invitation_key)
{ {
$invitation = $this->credit_repository->getInvitationByKey($invitation_key); $invitation = $this->credit_repository->getInvitationByKey($invitation_key);
$contact = $invitation->contact; $contact = $invitation->contact;
$credit = $invitation->credit; $credit = $invitation->credit;
$file_path = $credit->service()->getCreditPdf($contact); $file_path = $credit->service()->getCreditPdf($contact);
return response()->download($file_path); return response()->download($file_path);
} }
} }

View File

@ -255,8 +255,9 @@ class DesignController extends BaseController
*/ */
public function update(UpdateDesignRequest $request, Design $design) public function update(UpdateDesignRequest $request, Design $design)
{ {
if($request->entityIsDeleted($design)) if ($request->entityIsDeleted($design)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$design->fill($request->all()); $design->fill($request->all());
$design->save(); $design->save();
@ -485,6 +486,4 @@ class DesignController extends BaseController
return $this->listResponse(Design::withTrashed()->whereIn('id', $this->transformKeys($ids))); return $this->listResponse(Design::withTrashed()->whereIn('id', $this->transformKeys($ids)));
} }
} }

View File

@ -267,8 +267,9 @@ class ExpenseController extends BaseController
*/ */
public function update(UpdateExpenseRequest $request, Expense $expense) public function update(UpdateExpenseRequest $request, Expense $expense)
{ {
if($request->entityIsDeleted($expense)) if ($request->entityIsDeleted($expense)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$expense = $this->client_repo->save($request->all(), $expense); $expense = $this->client_repo->save($request->all(), $expense);

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,6 @@ use Illuminate\Http\Request;
class LicenseController extends BaseController class LicenseController extends BaseController
{ {
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -84,9 +83,7 @@ class LicenseController extends BaseController
{ {
/* Catch claim license requests */ /* Catch claim license requests */
if(config('ninja.environment') == 'selfhost' && $request->has('license_key')) if (config('ninja.environment') == 'selfhost' && $request->has('license_key')) {
{
$license_key = $request->input('license_key'); $license_key = $request->input('license_key');
$product_id = 3; $product_id = 3;
@ -94,29 +91,23 @@ class LicenseController extends BaseController
$data = trim(CurlUtils::get($url)); $data = trim(CurlUtils::get($url));
if ($data == Account::RESULT_FAILURE) { if ($data == Account::RESULT_FAILURE) {
$error = [ $error = [
'message' => trans('texts.invalid_white_label_license'), 'message' => trans('texts.invalid_white_label_license'),
'errors' => [] 'errors' => []
]; ];
return response()->json($error, 400); return response()->json($error, 400);
} elseif ($data) { } elseif ($data) {
$date = date_create($data)->modify('+1 year'); $date = date_create($data)->modify('+1 year');
if ($date < date_create()) { if ($date < date_create()) {
$error = [ $error = [
'message' => trans('texts.invalid_white_label_license'), 'message' => trans('texts.invalid_white_label_license'),
'errors' => [] 'errors' => []
]; ];
return response()->json($error, 400); return response()->json($error, 400);
} else { } else {
$account = auth()->user()->company()->account; $account = auth()->user()->company()->account;
$account->plan_term = Account::PLAN_TERM_YEARLY; $account->plan_term = Account::PLAN_TERM_YEARLY;
@ -131,19 +122,15 @@ class LicenseController extends BaseController
]; ];
return response()->json($error, 200); return response()->json($error, 200);
} }
} else { } else {
$error = [
$error = [
'message' => trans('texts.white_label_license_error'), 'message' => trans('texts.white_label_license_error'),
'errors' => [] 'errors' => []
]; ];
return response()->json($error, 400); return response()->json($error, 400);
} }
} }
$error = [ $error = [
@ -153,6 +140,4 @@ class LicenseController extends BaseController
return response()->json($error, 400); return response()->json($error, 400);
} }
} }

View File

@ -226,7 +226,9 @@ class MigrationController extends BaseController
$migration_file = $request->file('migration') $migration_file = $request->file('migration')
->storeAs('migrations', $request->file('migration')->getClientOriginalName()); ->storeAs('migrations', $request->file('migration')->getClientOriginalName());
if (app()->environment() == 'testing') return; if (app()->environment() == 'testing') {
return;
}
StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $company); StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $company);

View File

@ -10,6 +10,6 @@
* @OA\Property(property="routing_number", type="string", example="2", description="______"), * @OA\Property(property="routing_number", type="string", example="2", description="______"),
* @OA\Property(property="company_gateway_id", type="string", example="2", description="______"), * @OA\Property(property="company_gateway_id", type="string", example="2", description="______"),
* @OA\Property(property="is_default", type="boolean", example="true", description="______"), * @OA\Property(property="is_default", type="boolean", example="true", description="______"),
* *
* ) * )
*/ */

View File

@ -5,6 +5,6 @@
* type="object", * type="object",
* @OA\Property(property="credit_id", type="string", example="Opnel5aKBz", description="______"), * @OA\Property(property="credit_id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="amount", type="string", example="2", description="______"), * @OA\Property(property="amount", type="string", example="2", description="______"),
* *
* ) * )
*/ */

View File

@ -5,6 +5,6 @@
* type="object", * type="object",
* @OA\Property(property="invoice_id", type="string", example="Opnel5aKBz", description="______"), * @OA\Property(property="invoice_id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="amount", type="string", example="2", description="______"), * @OA\Property(property="amount", type="string", example="2", description="______"),
* *
* ) * )
*/ */

View File

@ -37,6 +37,6 @@
* ref="#/components/schemas/CreditPaymentable", * ref="#/components/schemas/CreditPaymentable",
* ), * ),
* ), * ),
* *
* ) * )
*/ */

View File

@ -9,6 +9,6 @@
* @OA\Property(property="refunded", type="number", format="float", example="10.00", description="______"), * @OA\Property(property="refunded", type="number", format="float", example="10.00", description="______"),
* @OA\Property(property="amount", type="number", format="float", example="10.00", description="______"), * @OA\Property(property="amount", type="number", format="float", example="10.00", description="______"),
* @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"),
* @OA\Property(property="created_at", type="number", format="integer", example="1434342123", description="Timestamp"),* * @OA\Property(property="created_at", type="number", format="integer", example="1434342123", description="Timestamp"),*
* ) * )
*/ */

View File

@ -381,8 +381,9 @@ class PaymentController extends BaseController
*/ */
public function update(UpdatePaymentRequest $request, Payment $payment) public function update(UpdatePaymentRequest $request, Payment $payment)
{ {
if($request->entityIsDeleted($payment)) if ($request->entityIsDeleted($payment)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$payment = $this->payment_repo->save($request->all(), $payment); $payment = $this->payment_repo->save($request->all(), $payment);
@ -674,12 +675,10 @@ class PaymentController extends BaseController
*/ */
public function refund(RefundPaymentRequest $request) public function refund(RefundPaymentRequest $request)
{ {
$payment = $request->payment(); $payment = $request->payment();
$payment = $payment->refund($request->all()); $payment = $payment->refund($request->all());
return $this->itemResponse($payment); return $this->itemResponse($payment);
} }
} }

View File

@ -20,7 +20,6 @@ use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml; use App\Utils\Traits\MakesInvoiceHtml;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
class PreviewController extends BaseController class PreviewController extends BaseController
{ {
use MakesHash; use MakesHash;
@ -88,16 +87,14 @@ class PreviewController extends BaseController
*/ */
public function show() public function show()
{ {
if (request()->has('entity') &&
if (request()->has('entity') && request()->has('entity_id') &&
request()->has('entity_id') && request()->has('body')) {
request()->has('body'))
{
$design_object = json_decode(json_encode(request()->input('design'))); $design_object = json_decode(json_encode(request()->input('design')));
if(!is_object($design_object)) if (!is_object($design_object)) {
return response()->json(['message' => 'Invalid custom design object'], 400); return response()->json(['message' => 'Invalid custom design object'], 400);
}
$entity = ucfirst(request()->input('entity')); $entity = ucfirst(request()->input('entity'));
@ -107,8 +104,9 @@ class PreviewController extends BaseController
$entity_obj = $class::whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first(); $entity_obj = $class::whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first();
if(!$entity_obj) if (!$entity_obj) {
return $this->blankEntity(); return $this->blankEntity();
}
$entity_obj->load('client'); $entity_obj->load('client');
@ -119,21 +117,19 @@ class PreviewController extends BaseController
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company()); $file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
return response()->download($file_path)->deleteFileAfterSend(true); return response()->download($file_path)->deleteFileAfterSend(true);
} }
return $this->blankEntity(); return $this->blankEntity();
} }
private function blankEntity() private function blankEntity()
{ {
$client = factory(\App\Models\Client::class)->create([ $client = factory(\App\Models\Client::class)->create([
'user_id' => auth()->user()->id, 'user_id' => auth()->user()->id,
'company_id' => auth()->user()->company()->id, 'company_id' => auth()->user()->company()->id,
]); ]);
$contact = factory(\App\Models\ClientContact::class)->create([ $contact = factory(\App\Models\ClientContact::class)->create([
'user_id' => auth()->user()->id, 'user_id' => auth()->user()->id,
'company_id' => auth()->user()->company()->id, 'company_id' => auth()->user()->company()->id,
'client_id' => $client->id, 'client_id' => $client->id,
@ -141,35 +137,32 @@ class PreviewController extends BaseController
'send_email' => true, 'send_email' => true,
]); ]);
$invoice = factory(\App\Models\Invoice::class)->create([ $invoice = factory(\App\Models\Invoice::class)->create([
'user_id' => auth()->user()->id, 'user_id' => auth()->user()->id,
'company_id' => auth()->user()->company()->id, 'company_id' => auth()->user()->company()->id,
'client_id' => $client->id, 'client_id' => $client->id,
]); ]);
$invoice->setRelation('client', $client); $invoice->setRelation('client', $client);
$invoice->setRelation('company', auth()->user()->company()); $invoice->setRelation('company', auth()->user()->company());
$invoice->load('client'); $invoice->load('client');
$design_object = json_decode(json_encode(request()->input('design'))); $design_object = json_decode(json_encode(request()->input('design')));
if(!is_object($design_object)) if (!is_object($design_object)) {
return response()->json(['message' => 'Invalid custom design object'], 400); return response()->json(['message' => 'Invalid custom design object'], 400);
}
$designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity'))); $designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
$html = $this->generateEntityHtml($designer, $invoice, $contact); $html = $this->generateEntityHtml($designer, $invoice, $contact);
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company()); $file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
$invoice->forceDelete(); $invoice->forceDelete();
$contact->forceDelete(); $contact->forceDelete();
$client->forceDelete(); $client->forceDelete();
return response()->file($file_path, array('content-type' => 'application/pdf'));
return response()->file($file_path, array('content-type' => 'application/pdf'));
} }
} }

View File

@ -345,9 +345,9 @@ class ProductController extends BaseController
*/ */
public function update(UpdateProductRequest $request, Product $product) public function update(UpdateProductRequest $request, Product $product)
{ {
if ($request->entityIsDeleted($product)) {
if($request->entityIsDeleted($product))
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$product = $this->product_repo->save($request->all(), $product); $product = $this->product_repo->save($request->all(), $product);

View File

@ -378,8 +378,9 @@ class QuoteController extends BaseController
*/ */
public function update(UpdateQuoteRequest $request, Quote $quote) public function update(UpdateQuoteRequest $request, Quote $quote)
{ {
if($request->entityIsDeleted($quote)) if ($request->entityIsDeleted($quote)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$quote = $this->quote_repo->save($request->all(), $quote); $quote = $this->quote_repo->save($request->all(), $quote);
@ -516,31 +517,25 @@ class QuoteController extends BaseController
* Download Invoice/s * Download Invoice/s
*/ */
if($action == 'download' && $quotes->count() > 1) if ($action == 'download' && $quotes->count() > 1) {
{
$quotes->each(function ($quote) { $quotes->each(function ($quote) {
if (auth()->user()->cannot('view', $quote)) {
if(auth()->user()->cannot('view', $quote)){
return response()->json(['message'=>'Insufficient privileges to access quote '. $quote->number]); return response()->json(['message'=>'Insufficient privileges to access quote '. $quote->number]);
} }
}); });
ZipInvoices::dispatch($quotes, $quotes->first()->company, auth()->user()->email); ZipInvoices::dispatch($quotes, $quotes->first()->company, auth()->user()->email);
return response()->json(['message' => 'Email Sent!'],200); return response()->json(['message' => 'Email Sent!'], 200);
} }
/* /*
* Send the other actions to the switch * Send the other actions to the switch
*/ */
$quotes->each(function ($quote, $key) use ($action) { $quotes->each(function ($quote, $key) use ($action) {
if (auth()->user()->can('edit', $quote)) { if (auth()->user()->can('edit', $quote)) {
$this->performAction($quote, $action, true); $this->performAction($quote, $action, true);
} }
}); });
/* Need to understand which permission are required for the given bulk action ie. view / edit */ /* Need to understand which permission are required for the given bulk action ie. view / edit */
@ -620,7 +615,8 @@ class QuoteController extends BaseController
* *
*/ */
public function action(ActionQuoteRequest $request, Quote $quote, $action) { public function action(ActionQuoteRequest $request, Quote $quote, $action)
{
return $this->performAction($quote, $action); return $this->performAction($quote, $action);
} }
@ -642,8 +638,9 @@ class QuoteController extends BaseController
break; break;
case 'approve': case 'approve':
//make sure it hasn't already been approved!! //make sure it hasn't already been approved!!
if($quote->status_id != Quote::STATUS_SENT) if ($quote->status_id != Quote::STATUS_SENT) {
return response()->json(['message' => 'Unable to approve this quote as it has expired.'], 400); return response()->json(['message' => 'Unable to approve this quote as it has expired.'], 400);
}
return $this->itemResponse($quote->service()->approve()->save()); return $this->itemResponse($quote->service()->approve()->save());
break; break;
@ -679,23 +676,21 @@ class QuoteController extends BaseController
if (!$bulk) { if (!$bulk) {
return $this->itemResponse($quote); return $this->itemResponse($quote);
} }
// no break
default: 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; break;
} }
} }
public function downloadPdf($invitation_key) public function downloadPdf($invitation_key)
{ {
$invitation = $this->quote_repo->getInvitationByKey($invitation_key); $invitation = $this->quote_repo->getInvitationByKey($invitation_key);
$contact = $invitation->contact; $contact = $invitation->contact;
$quote = $invitation->quote; $quote = $invitation->quote;
$file_path = $quote->service()->getQuotePdf($contact); $file_path = $quote->service()->getQuotePdf($contact);
return response()->download($file_path); return response()->download($file_path);
} }
} }

View File

@ -377,8 +377,9 @@ class RecurringInvoiceController extends BaseController
*/ */
public function update(UpdateRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice) public function update(UpdateRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
{ {
if($request->entityIsDeleted($recurring_invoice)) if ($request->entityIsDeleted($recurring_invoice)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), $recurring_invoice); $recurring_invoice = $this->recurring_invoice_repo->save($request->all(), $recurring_invoice);

View File

@ -375,9 +375,9 @@ class RecurringQuoteController extends BaseController
*/ */
public function update(UpdateRecurringQuoteRequest $request, RecurringQuote $recurring_quote) public function update(UpdateRecurringQuoteRequest $request, RecurringQuote $recurring_quote)
{ {
if ($request->entityIsDeleted($recurring_quote)) {
if($request->entityIsDeleted($recurring_quote))
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$recurring_quote = $this->recurring_quote_repo->save(request(), $recurring_quote); $recurring_quote = $this->recurring_quote_repo->save(request(), $recurring_quote);

View File

@ -11,6 +11,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Utils\Ninja;
use Codedge\Updater\UpdaterManager; use Codedge\Updater\UpdaterManager;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
@ -21,7 +22,6 @@ class SelfUpdateController extends BaseController
public function __construct() public function __construct()
{ {
} }
/** /**
@ -58,18 +58,13 @@ class SelfUpdateController extends BaseController
*/ */
public function update(UpdaterManager $updater) public function update(UpdaterManager $updater)
{ {
if(Ninja::isNinja())
$res = $updater->update(); return response()->json(['message' => 'Self update not available on this system.'], 403);
return response()->json(['message'=>$res], 200); $res = $updater->update();
return response()->json(['message'=>$res], 200);
} }
public function checkVersion(UpdaterManager $updater)
{ }
}
}

View File

@ -17,49 +17,44 @@ use App\Utils\SystemHealth;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
/** /**
* Class SetupController * Class SetupController
*/ */
class SetupController extends Controller class SetupController extends Controller
{ {
public function index()
{
$system_health = SystemHealth::check();
public function index() return view();
{ }
$system_health = SystemHealth::check();
return view();
}
public function doSetup(StoreSetupRequest $request)
{
public function doSetup(StoreSetupRequest $request)
{
$_ENV['APP_URL'] = $request->input('url'); $_ENV['APP_URL'] = $request->input('url');
$_ENV['APP_DEBUG'] = $request->input('debug') ? 'true' : 'false'; $_ENV['APP_DEBUG'] = $request->input('debug') ? 'true' : 'false';
$_ENV['REQUIRE_HTTPS'] = $request->input('https') ? 'true' : 'false'; $_ENV['REQUIRE_HTTPS'] = $request->input('https') ? 'true' : 'false';
$_ENV['DB_TYPE'] = 'mysql'; $_ENV['DB_TYPE'] = 'mysql';
$_ENV['DB_HOST1'] = $request->input('host'); $_ENV['DB_HOST1'] = $request->input('host');
$_ENV['DB_DATABASE1'] = $request->input('db_username'); $_ENV['DB_DATABASE1'] = $request->input('db_username');
$_ENV['DB_USERNAME1'] = $request->input('db_password'); $_ENV['DB_USERNAME1'] = $request->input('db_password');
$_ENV['DB_PASSWORD1'] = $request->input('db_password'); $_ENV['DB_PASSWORD1'] = $request->input('db_password');
$_ENV['MAIL_DRIVER'] = $request->input('mail_driver'); $_ENV['MAIL_DRIVER'] = $request->input('mail_driver');
$_ENV['MAIL_PORT'] = $request->input('port'); $_ENV['MAIL_PORT'] = $request->input('port');
$_ENV['MAIL_ENCRYPTION'] = $request->input('encryption'); $_ENV['MAIL_ENCRYPTION'] = $request->input('encryption');
$_ENV['MAIL_HOST'] = $request->input('mail_host'); $_ENV['MAIL_HOST'] = $request->input('mail_host');
$_ENV['MAIL_USERNAME'] = $request->input('mail_username'); $_ENV['MAIL_USERNAME'] = $request->input('mail_username');
$_ENV['MAIL_FROM_NAME'] = $request->input('mail_name'); $_ENV['MAIL_FROM_NAME'] = $request->input('mail_name');
$_ENV['MAIL_FROM_ADDRESS'] = $request->input('mail_address'); $_ENV['MAIL_FROM_ADDRESS'] = $request->input('mail_address');
$_ENV['MAIL_PASSWORD'] = $request->input('mail_password'); $_ENV['MAIL_PASSWORD'] = $request->input('mail_password');
$_ENV['NINJA_ENVIRONMENT'] = 'selfhost'; $_ENV['NINJA_ENVIRONMENT'] = 'selfhost';
$_ENV['SELF_UPDATER_REPO_VENDOR'] = 'invoiceninja'; $_ENV['SELF_UPDATER_REPO_VENDOR'] = 'invoiceninja';
$_ENV['SELF_UPDATER_REPO_NAME'] = 'invoiceninja'; $_ENV['SELF_UPDATER_REPO_NAME'] = 'invoiceninja';
$_ENV['SELF_UPDATER_USE_BRANCH'] = 'v2'; $_ENV['SELF_UPDATER_USE_BRANCH'] = 'v2';
$_ENV['SELF_UPDATER_MAILTO_ADDRESS'] = $request->input('mail_address'); $_ENV['SELF_UPDATER_MAILTO_ADDRESS'] = $request->input('mail_address');
$_ENV['SELF_UPDATER_MAILTO_NAME'] = $request->input('mail_name'); $_ENV['SELF_UPDATER_MAILTO_NAME'] = $request->input('mail_name');
$_ENV['DB_CONNECTION'] = 'db-ninja-01'; $_ENV['DB_CONNECTION'] = 'db-ninja-01';
$_ENV['APP_DEBUG'] = false; $_ENV['APP_DEBUG'] = false;
$config = ''; $config = '';
@ -82,11 +77,10 @@ class SetupController extends Controller
Artisan::call('migrate'); Artisan::call('migrate');
Artisan::call('db:seed'); Artisan::call('db:seed');
if(Account::count() == 0) if (Account::count() == 0) {
$account = CreateAccount::dispatchNow($request->all()); $account = CreateAccount::dispatchNow($request->all());
}
return view('index.index'); return view('index.index');
}
} }
}

View File

@ -71,8 +71,9 @@ class SendingController extends Controller
$send_logs = false; $send_logs = false;
if($request->has('send_logs')) if ($request->has('send_logs')) {
$send_logs = $request->input('send_logs'); $send_logs = $request->input('send_logs');
}
Mail::to(config('ninja.contact.ninja_official_contact')) Mail::to(config('ninja.contact.ninja_official_contact'))
->send(new SupportMessageSent($request->message, $send_logs)); ->send(new SupportMessageSent($request->message, $send_logs));

View File

@ -29,7 +29,6 @@ trait VerifiesUserEmail
*/ */
public function confirm() public function confirm()
{ {
if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->route('confirmation_code'))->first()) { if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->route('confirmation_code'))->first()) {
$user->email_verified_at = now(); $user->email_verified_at = now();
$user->confirmation_code = null; $user->confirmation_code = null;

View File

@ -501,15 +501,14 @@ class UserController extends BaseController
*/ */
public function bulk() public function bulk()
{ {
$action = request()->input('action'); $action = request()->input('action');
$ids = request()->input('ids'); $ids = request()->input('ids');
$users = User::withTrashed()->find($this->transformKeys($ids)); $users = User::withTrashed()->find($this->transformKeys($ids));
/* /*
* In case a user maliciously sends keys which do not belong to them, we push * In case a user maliciously sends keys which do not belong to them, we push
* each user through the Policy sieve and only return users that they * each user through the Policy sieve and only return users that they
* have access to * have access to
*/ */
@ -517,19 +516,14 @@ class UserController extends BaseController
$return_user_collection = collect(); $return_user_collection = collect();
$users->each(function ($user, $key) use ($action, $return_user_collection) { $users->each(function ($user, $key) use ($action, $return_user_collection) {
if (auth()->user()->can('edit', $user)) { if (auth()->user()->can('edit', $user)) {
$user = $this->user_repo->{$action}($user); $user = $this->user_repo->{$action}($user);
$return_user_collection->push($user->id); $return_user_collection->push($user->id);
} }
}); });
return $this->listResponse(User::withTrashed()->whereIn('id', $return_user_collection)); return $this->listResponse(User::withTrashed()->whereIn('id', $return_user_collection));
} }
@ -589,13 +583,16 @@ class UserController extends BaseController
{ {
$company = auth()->user()->company(); $company = auth()->user()->company();
$user->companies()->attach($company->id, $user->companies()->attach(
array_merge($request->all(), $company->id,
array_merge(
$request->all(),
[ [
'account_id' => $company->account->id, 'account_id' => $company->account->id,
'notifications' => CompanySettings::notificationDefaults(), 'notifications' => CompanySettings::notificationDefaults(),
] ]
)); )
);
$ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->name()); $ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->name());

View File

@ -267,8 +267,9 @@ class VendorController extends BaseController
*/ */
public function update(UpdateVendorRequest $request, Vendor $vendor) public function update(UpdateVendorRequest $request, Vendor $vendor)
{ {
if($request->entityIsDeleted($vendor)) if ($request->entityIsDeleted($vendor)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
}
$vendor = $this->client_repo->save($request->all(), $vendor); $vendor = $this->client_repo->save($request->all(), $vendor);

View File

@ -40,7 +40,6 @@ class PasswordProtection
return response()->json($error, 403); return response()->json($error, 403);
} }
} elseif (Cache::get(auth()->user()->email."_logged_in")) { } elseif (Cache::get(auth()->user()->email."_logged_in")) {
Cache::pull(auth()->user()->email."_logged_in"); Cache::pull(auth()->user()->email."_logged_in");
Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10)); Cache::add(auth()->user()->email."_logged_in", Str::random(64), now()->addMinutes(10));

View File

@ -49,9 +49,8 @@ class QueryLogging
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time); Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
// if($count > 50) // if($count > 50)
// Log::info($queries); // Log::info($queries);
} }
} }

View File

@ -35,10 +35,11 @@ class SetInviteDb
**/ **/
$entity = null; $entity = null;
if(!$request->route('entity')) if (!$request->route('entity')) {
$entity = $request->segment(2); $entity = $request->segment(2);
else } else {
$entity = $request->route('entity'); $entity = $request->route('entity');
}
if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByInvitation($entity, $request->route('invitation_key'))) { if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByInvitation($entity, $request->route('invitation_key'))) {
if (request()->json) { if (request()->json) {

View File

@ -28,7 +28,6 @@ class TokenAuth
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user','company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first())) { if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user','company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first())) {
$user = $company_token->user; $user = $company_token->user;
$error = [ $error = [
@ -51,8 +50,8 @@ class TokenAuth
config(['ninja.company_id' => $company_token->company->id]); config(['ninja.company_id' => $company_token->company->id]);
app('queue')->createPayloadUsing(function () use($company_token) { app('queue')->createPayloadUsing(function () use ($company_token) {
return ['db' => $company_token->company->db]; return ['db' => $company_token->company->db];
}); });
//user who once existed, but has been soft deleted //user who once existed, but has been soft deleted

View File

@ -69,72 +69,56 @@ class StoreClientRequest extends Request
protected function prepareForValidation() protected function prepareForValidation()
{ {
$input = $this->all(); $input = $this->all();
//@todo implement feature permissions for > 100 clients //@todo implement feature permissions for > 100 clients
// //
$settings = ClientSettings::defaults(); $settings = ClientSettings::defaults();
if(array_key_exists('settings', $input) && !empty($input['settings'])) if (array_key_exists('settings', $input) && !empty($input['settings'])) {
{ foreach ($input['settings'] as $key => $value) {
foreach($input['settings'] as $key => $value)
{
$settings->{$key} = $value; $settings->{$key} = $value;
} }
}
}
//is no settings->currency_id is set then lets dive in and find either a group or company currency all the below may be redundant!! //is no settings->currency_id is set then lets dive in and find either a group or company currency all the below may be redundant!!
if(!property_exists($settings, 'currency_id') && isset($input['group_settings_id'])) if (!property_exists($settings, 'currency_id') && isset($input['group_settings_id'])) {
{
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']); $input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
$group_settings = GroupSetting::find($input['group_settings_id']); $group_settings = GroupSetting::find($input['group_settings_id']);
if($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id)) if ($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id)) {
$settings->currency_id = (string)$group_settings->settings->currency_id; $settings->currency_id = (string)$group_settings->settings->currency_id;
else } else {
$settings->currency_id = (string)auth()->user()->company()->settings->currency_id; $settings->currency_id = (string)auth()->user()->company()->settings->currency_id;
}
} } elseif (!property_exists($settings, 'currency_id')) {
elseif(!property_exists($settings, 'currency_id'))
{
$settings->currency_id = (string)auth()->user()->company()->settings->currency_id; $settings->currency_id = (string)auth()->user()->company()->settings->currency_id;
} }
$input['settings'] = $settings; $input['settings'] = $settings;
if(isset($input['contacts'])) if (isset($input['contacts'])) {
{ foreach ($input['contacts'] as $key => $contact) {
foreach($input['contacts'] as $key => $contact) if (array_key_exists('id', $contact) && is_numeric($contact['id'])) {
{
if(array_key_exists('id', $contact) && is_numeric($contact['id']))
unset($input['contacts'][$key]['id']); unset($input['contacts'][$key]['id']);
elseif(array_key_exists('id', $contact) && is_string($contact['id'])) } elseif (array_key_exists('id', $contact) && is_string($contact['id'])) {
$input['contacts'][$key]['id'] = $this->decodePrimaryKey($contact['id']); $input['contacts'][$key]['id'] = $this->decodePrimaryKey($contact['id']);
}
//Filter the client contact password - if it is sent with ***** we should ignore it! //Filter the client contact password - if it is sent with ***** we should ignore it!
if(isset($contact['password'])) if (isset($contact['password'])) {
{ if (strlen($contact['password']) == 0) {
if(strlen($contact['password']) == 0){
$input['contacts'][$key]['password'] = ''; $input['contacts'][$key]['password'] = '';
} } else {
else {
$contact['password'] = str_replace("*", "", $contact['password']); $contact['password'] = str_replace("*", "", $contact['password']);
if(strlen($contact['password']) == 0){ if (strlen($contact['password']) == 0) {
unset($input['contacts'][$key]['password']); unset($input['contacts'][$key]['password']);
} }
} }
} }
} }
} }

View File

@ -80,34 +80,27 @@ class UpdateClientRequest extends Request
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']); $input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
} }
if(isset($input['contacts'])) if (isset($input['contacts'])) {
{ foreach ($input['contacts'] as $key => $contact) {
foreach($input['contacts'] as $key => $contact) if (array_key_exists('id', $contact) && is_numeric($contact['id'])) {
{
if(array_key_exists('id', $contact) && is_numeric($contact['id']))
unset($input['contacts'][$key]['id']); unset($input['contacts'][$key]['id']);
elseif(array_key_exists('id', $contact) && is_string($contact['id'])) } elseif (array_key_exists('id', $contact) && is_string($contact['id'])) {
$input['contacts'][$key]['id'] = $this->decodePrimaryKey($contact['id']); $input['contacts'][$key]['id'] = $this->decodePrimaryKey($contact['id']);
}
//Filter the client contact password - if it is sent with ***** we should ignore it! //Filter the client contact password - if it is sent with ***** we should ignore it!
if(isset($contact['password'])) if (isset($contact['password'])) {
{ if (strlen($contact['password']) == 0) {
if(strlen($contact['password']) == 0){
$input['contacts'][$key]['password'] = ''; $input['contacts'][$key]['password'] = '';
} } else {
else {
$contact['password'] = str_replace("*", "", $contact['password']); $contact['password'] = str_replace("*", "", $contact['password']);
if(strlen($contact['password']) == 0){ if (strlen($contact['password']) == 0) {
unset($input['contacts'][$key]['password']); unset($input['contacts'][$key]['password']);
} }
} }
} }
} }
} }
$this->replace($input); $this->replace($input);

View File

@ -52,19 +52,14 @@ class StoreCompanyRequest extends Request
protected function prepareForValidation() protected function prepareForValidation()
{ {
$input = $this->all(); $input = $this->all();
$company_settings = CompanySettings::defaults(); $company_settings = CompanySettings::defaults();
if(array_key_exists('settings', $input) && !empty($input['settings'])) if (array_key_exists('settings', $input) && !empty($input['settings'])) {
{ foreach ($input['settings'] as $key => $value) {
foreach($input['settings'] as $key => $value)
{
$company_settings->{$key} = $value; $company_settings->{$key} = $value;
} }
} }
// $company_settings->invoice_design_id = $this->encodePrimaryKey(1); // $company_settings->invoice_design_id = $this->encodePrimaryKey(1);

View File

@ -52,7 +52,5 @@ class UpdateCompanyRequest extends Request
protected function prepareForValidation() protected function prepareForValidation()
{ {
} }
} }

View File

@ -38,5 +38,4 @@ class UpdateCompanyUserRequest extends Request
{ {
return []; return [];
} }
} }

View File

@ -40,41 +40,36 @@ class StoreCreditRequest extends FormRequest
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id'])) if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']); $input['design_id'] = $this->decodePrimaryKey($input['design_id']);
if($input['client_id'])
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
if(isset($input['client_contacts']))
{
foreach($input['client_contacts'] as $key => $contact)
{
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
{
unset($input['client_contacts'][$key]);
}
}
} }
if(isset($input['invitations'])) if ($input['client_id']) {
{ $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
}
foreach($input['invitations'] as $key => $value) if (isset($input['client_contacts'])) {
{ foreach ($input['client_contacts'] as $key => $contact) {
if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) {
unset($input['client_contacts'][$key]);
}
}
}
if(isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) if (isset($input['invitations'])) {
unset($input['invitations'][$key]['id']); foreach ($input['invitations'] as $key => $value) {
if (isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) {
unset($input['invitations'][$key]['id']);
}
if(isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id'])) if (isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id'])) {
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']); $input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
}
if(is_string($input['invitations'][$key]['client_contact_id']))
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
if (is_string($input['invitations'][$key]['client_contact_id'])) {
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
}
} }
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];

View File

@ -42,30 +42,28 @@ class UpdateCreditRequest extends FormRequest
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id'])) if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']); $input['design_id'] = $this->decodePrimaryKey($input['design_id']);
}
if (isset($input['client_id'])) { if (isset($input['client_id'])) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
} }
if(isset($input['invitations'])) if (isset($input['invitations'])) {
{ foreach ($input['invitations'] as $key => $value) {
if (is_numeric($input['invitations'][$key]['id'])) {
unset($input['invitations'][$key]['id']);
}
foreach($input['invitations'] as $key => $value) if (is_string($input['invitations'][$key]['id'])) {
{ $input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
}
if(is_numeric($input['invitations'][$key]['id']))
unset($input['invitations'][$key]['id']);
if(is_string($input['invitations'][$key]['id']))
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
if(is_string($input['invitations'][$key]['client_contact_id']))
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
if (is_string($input['invitations'][$key]['client_contact_id'])) {
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
}
} }
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];

View File

@ -40,11 +40,13 @@ class StoreDesignRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if(!array_key_exists('product', $input['design']) || is_null($input['design']['product'])) if (!array_key_exists('product', $input['design']) || is_null($input['design']['product'])) {
$input['design']['product'] = ''; $input['design']['product'] = '';
}
if(!array_key_exists('task', $input['design']) || is_null($input['design']['task'])) if (!array_key_exists('task', $input['design']) || is_null($input['design']['task'])) {
$input['design']['task'] = ''; $input['design']['task'] = '';
}
$this->replace($input); $this->replace($input);
} }

View File

@ -35,15 +35,17 @@ class UpdateDesignRequest extends Request
return []; return [];
} }
protected function prepareForValidation() protected function prepareForValidation()
{ {
$input = $this->all(); $input = $this->all();
if(!array_key_exists('product', $input['design']) || is_null($input['design']['product'])) if (!array_key_exists('product', $input['design']) || is_null($input['design']['product'])) {
$input['design']['product'] = ''; $input['design']['product'] = '';
}
if(!array_key_exists('task', $input['design']) || is_null($input['design']['task'])) if (!array_key_exists('task', $input['design']) || is_null($input['design']['task'])) {
$input['design']['task'] = ''; $input['design']['task'] = '';
}
$this->replace($input); $this->replace($input);
} }

View File

@ -44,14 +44,10 @@ class StoreGroupSettingRequest extends Request
$group_settings = ClientSettings::defaults(); $group_settings = ClientSettings::defaults();
if(array_key_exists('settings', $input) && !empty($input['settings'])) if (array_key_exists('settings', $input) && !empty($input['settings'])) {
{ foreach ($input['settings'] as $key => $value) {
foreach($input['settings'] as $key => $value)
{
$group_settings->{$key} = $value; $group_settings->{$key} = $value;
} }
} }
$input['settings'] = $group_settings; $input['settings'] = $group_settings;

View File

@ -26,5 +26,4 @@ class EditInvoiceRequest extends Request
{ {
return auth()->user()->can('edit', $this->invoice); return auth()->user()->can('edit', $this->invoice);
} }
} }

View File

@ -46,41 +46,36 @@ class StoreInvoiceRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id'])) if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']); $input['design_id'] = $this->decodePrimaryKey($input['design_id']);
if(array_key_exists('client_id', $input) && is_string($input['client_id']))
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
if(isset($input['client_contacts']))
{
foreach($input['client_contacts'] as $key => $contact)
{
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
{
unset($input['client_contacts'][$key]);
}
}
} }
if(isset($input['invitations'])) if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
{ $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
}
foreach($input['invitations'] as $key => $value) if (isset($input['client_contacts'])) {
{ foreach ($input['client_contacts'] as $key => $contact) {
if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) {
unset($input['client_contacts'][$key]);
}
}
}
if(isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) if (isset($input['invitations'])) {
unset($input['invitations'][$key]['id']); foreach ($input['invitations'] as $key => $value) {
if (isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) {
unset($input['invitations'][$key]['id']);
}
if(isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id'])) if (isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id'])) {
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']); $input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
}
if(is_string($input['invitations'][$key]['client_contact_id']))
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
if (is_string($input['invitations'][$key]['client_contact_id'])) {
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
}
} }
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];

View File

@ -49,30 +49,28 @@ class UpdateInvoiceRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id'])) if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']); $input['design_id'] = $this->decodePrimaryKey($input['design_id']);
}
if (isset($input['client_id'])) { if (isset($input['client_id'])) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
} }
if(isset($input['invitations'])) if (isset($input['invitations'])) {
{ foreach ($input['invitations'] as $key => $value) {
if (is_numeric($input['invitations'][$key]['id'])) {
unset($input['invitations'][$key]['id']);
}
foreach($input['invitations'] as $key => $value) if (is_string($input['invitations'][$key]['id'])) {
{ $input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
}
if(is_numeric($input['invitations'][$key]['id']))
unset($input['invitations'][$key]['id']);
if(is_string($input['invitations'][$key]['id']))
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
if(is_string($input['invitations'][$key]['client_contact_id']))
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
if (is_string($input['invitations'][$key]['client_contact_id'])) {
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
}
} }
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];

View File

@ -28,7 +28,7 @@ class UploadMigrationFileRequest extends FormRequest
]; ];
/** We'll skip mime validation while running tests. */ /** We'll skip mime validation while running tests. */
if(app()->environment() !== 'testing') { if (app()->environment() !== 'testing') {
$rules['migration'] = ['required', 'file', 'mimes:zip']; $rules['migration'] = ['required', 'file', 'mimes:zip'];
} }

View File

@ -19,7 +19,7 @@ use App\Utils\Traits\MakesHash;
class RefundPaymentRequest extends Request class RefundPaymentRequest extends Request
{ {
use MakesHash; use MakesHash;
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
* *
@ -33,35 +33,33 @@ class RefundPaymentRequest extends Request
protected function prepareForValidation() protected function prepareForValidation()
{ {
$input = $this->all(); $input = $this->all();
if(!isset($input['gateway_refund'])) if (!isset($input['gateway_refund'])) {
$input['gateway_refund'] = false; $input['gateway_refund'] = false;
}
if(!isset($input['send_email'])) if (!isset($input['send_email'])) {
$input['send_email'] = false; $input['send_email'] = false;
}
if(isset($input['id'])) if (isset($input['id'])) {
$input['id'] = $this->decodePrimaryKey($input['id']); $input['id'] = $this->decodePrimaryKey($input['id']);
}
if(isset($input['invoices'])) if (isset($input['invoices'])) {
{ foreach ($input['invoices'] as $key => $invoice) {
foreach($input['invoices'] as $key => $invoice)
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']); $input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']);
}
} }
if(isset($input['credits'])) if (isset($input['credits'])) {
{
unset($input['credits']); unset($input['credits']);
// foreach($input['credits'] as $key => $credit) // foreach($input['credits'] as $key => $credit)
// $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($credit['credit_id']); // $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($credit['credit_id']);
} }
$this->replace($input); $this->replace($input);
} }
public function rules() public function rules()

View File

@ -46,7 +46,6 @@ class StorePaymentRequest extends Request
} }
if (isset($input['invoices']) && is_array($input['invoices']) !== false) { if (isset($input['invoices']) && is_array($input['invoices']) !== false) {
foreach ($input['invoices'] as $key => $value) { foreach ($input['invoices'] as $key => $value) {
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']); $input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']);
$invoices_total += $value['amount']; $invoices_total += $value['amount'];
@ -61,9 +60,7 @@ class StorePaymentRequest extends Request
if (isset($input['credits']) && is_array($input['credits']) !== false) { if (isset($input['credits']) && is_array($input['credits']) !== false) {
foreach ($input['credits'] as $key => $value) { foreach ($input['credits'] as $key => $value) {
if (array_key_exists('credit_id', $input['credits'][$key])) {
if(array_key_exists('credit_id', $input['credits'][$key]))
{
$input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']); $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']);
$credits_total += $value['amount']; $credits_total += $value['amount'];
} }
@ -74,7 +71,7 @@ class StorePaymentRequest extends Request
$input['credits'] = null; $input['credits'] = null;
} }
if(!isset($input['amount']) || $input['amount'] == 0){ if (!isset($input['amount']) || $input['amount'] == 0) {
$input['amount'] = $invoices_total - $credits_total; $input['amount'] = $invoices_total - $credits_total;
} }

View File

@ -46,23 +46,29 @@ class UpdatePaymentRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if(isset($input['client_id'])) if (isset($input['client_id'])) {
unset($input['client_id']); unset($input['client_id']);
}
if(isset($input['amount'])) if (isset($input['amount'])) {
unset($input['amount']); unset($input['amount']);
}
if(isset($input['type_id'])) if (isset($input['type_id'])) {
unset($input['type_id']); unset($input['type_id']);
}
if(isset($input['date'])) if (isset($input['date'])) {
unset($input['date']); unset($input['date']);
}
if(isset($input['transaction_reference'])) if (isset($input['transaction_reference'])) {
unset($input['transaction_reference']); unset($input['transaction_reference']);
}
if(isset($input['number'])) if (isset($input['number'])) {
unset($input['number']); unset($input['number']);
}
if (isset($input['invoices']) && is_array($input['invoices']) !== false) { if (isset($input['invoices']) && is_array($input['invoices']) !== false) {
foreach ($input['invoices'] as $key => $value) { foreach ($input['invoices'] as $key => $value) {

View File

@ -26,6 +26,4 @@ class EditQuoteRequest extends Request
{ {
return auth()->user()->can('edit', $this->quote); return auth()->user()->can('edit', $this->quote);
} }
} }

View File

@ -32,45 +32,40 @@ class StoreQuoteRequest extends Request
return auth()->user()->can('create', Quote::class); return auth()->user()->can('create', Quote::class);
} }
protected function prepareForValidation() protected function prepareForValidation()
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id'])) if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']); $input['design_id'] = $this->decodePrimaryKey($input['design_id']);
}
if($input['client_id']) if ($input['client_id']) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
if(isset($input['client_contacts']))
{
foreach($input['client_contacts'] as $key => $contact)
{
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
{
unset($input['client_contacts'][$key]);
}
}
} }
if(isset($input['invitations'])) if (isset($input['client_contacts'])) {
{ foreach ($input['client_contacts'] as $key => $contact) {
if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) {
unset($input['client_contacts'][$key]);
}
}
}
foreach($input['invitations'] as $key => $value) if (isset($input['invitations'])) {
{ foreach ($input['invitations'] as $key => $value) {
if (isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) {
unset($input['invitations'][$key]['id']);
}
if(isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) if (isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id'])) {
unset($input['invitations'][$key]['id']); $input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
}
if(isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id']))
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
if(is_string($input['invitations'][$key]['client_contact_id']))
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
if (is_string($input['invitations'][$key]['client_contact_id'])) {
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
}
}
} }
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
@ -86,4 +81,3 @@ protected function prepareForValidation()
]; ];
} }
} }

View File

@ -47,8 +47,9 @@ class UpdateQuoteRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id'])) if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']); $input['design_id'] = $this->decodePrimaryKey($input['design_id']);
}
if (isset($input['client_id'])) { if (isset($input['client_id'])) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);

View File

@ -45,8 +45,9 @@ class StoreRecurringInvoiceRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if($input['client_id']) if ($input['client_id']) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
}
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
//$input['line_items'] = json_encode($input['line_items']); //$input['line_items'] = json_encode($input['line_items']);

View File

@ -49,6 +49,4 @@ class UpdateRecurringInvoiceRequest extends Request
//$input['line_items'] = json_encode($input['line_items']); //$input['line_items'] = json_encode($input['line_items']);
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -45,12 +45,12 @@ class StoreRecurringQuoteRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if($input['client_id']) if ($input['client_id']) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
}
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
//$input['line_items'] = json_encode($input['line_items']); //$input['line_items'] = json_encode($input['line_items']);
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -48,5 +48,4 @@ class UpdateRecurringQuoteRequest extends Request
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -29,7 +29,7 @@ class StoreSetupRequest extends Request
public function rules() public function rules()
{ {
return [ return [
/*System*/ /*System*/
'url' => 'required', 'url' => 'required',
'debug' => 'required', 'debug' => 'required',
@ -61,8 +61,8 @@ class StoreSetupRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
$input['user_agent'] = request()->server('HTTP_USER_AGENT'); $input['user_agent'] = request()->server('HTTP_USER_AGENT');
$this->replace($input); $this->replace($input);
} }
} }

View File

@ -44,8 +44,9 @@ class UpdateUserRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if (isset($input['company_user']) && !auth()->user()->isAdmin()) if (isset($input['company_user']) && !auth()->user()->isAdmin()) {
unset($input['company_user']); unset($input['company_user']);
}
$this->replace($input); $this->replace($input);

View File

@ -27,9 +27,7 @@ class ValidCompanyQuantity implements Rule
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
return auth()->user()->company()->account->companies->count() <= 10; return auth()->user()->company()->account->companies->count() <= 10;
} }
/** /**
@ -39,6 +37,4 @@ class ValidCompanyQuantity implements Rule
{ {
return "Limit of 10 companies per account."; return "Limit of 10 companies per account.";
} }
} }

View File

@ -44,47 +44,41 @@ class ValidInvoicesRules implements Rule
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
return $this->checkInvoicesAreHomogenous();
return $this->checkInvoicesAreHomogenous();
} }
private function checkInvoicesAreHomogenous() private function checkInvoicesAreHomogenous()
{ {
if (!array_key_exists('client_id', $this->input)) {
if(!array_key_exists('client_id', $this->input)){
$this->error_msg = "Client id is required"; $this->error_msg = "Client id is required";
return false; return false;
} }
$unique_array = []; $unique_array = [];
foreach($this->input['invoices'] as $invoice) foreach ($this->input['invoices'] as $invoice) {
{ $unique_array[] = $invoice['invoice_id'];
$unique_array[] = $invoice['invoice_id'];
$inv = Invoice::whereId($invoice['invoice_id'])->first(); $inv = Invoice::whereId($invoice['invoice_id'])->first();
if(!$inv){ if (!$inv) {
$this->error_msg = "Invoice not found "; $this->error_msg = "Invoice not found ";
return false; return false;
} }
if($inv->client_id != $this->input['client_id']){ if ($inv->client_id != $this->input['client_id']) {
$this->error_msg = "Selected invoices are not from a single client"; $this->error_msg = "Selected invoices are not from a single client";
return false; return false;
} }
} }
if(!(array_unique($unique_array) == $unique_array)) if (!(array_unique($unique_array) == $unique_array)) {
{
$this->error_msg = "Duplicate invoices submitted."; $this->error_msg = "Duplicate invoices submitted.";
return false; return false;
} }
return true; return true;
} }
@ -95,6 +89,4 @@ class ValidInvoicesRules implements Rule
{ {
return $this->error_msg; return $this->error_msg;
} }
} }

View File

@ -44,11 +44,9 @@ class ValidRefundableRequest implements Rule
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
$payment = Payment::whereId($this->input['id'])->first(); $payment = Payment::whereId($this->input['id'])->first();
if(!$payment) if (!$payment) {
{
$this->error_msg = "Unable to retrieve specified payment"; $this->error_msg = "Unable to retrieve specified payment";
return false; return false;
} }
@ -63,10 +61,10 @@ class ValidRefundableRequest implements Rule
// $request_credits[$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']); // $request_credits[$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']);
if($payment->invoices()->exists()) if ($payment->invoices()->exists()) {
{ foreach ($payment->invoices as $paymentable_invoice) {
foreach($payment->invoices as $paymentable_invoice)
$this->checkInvoice($paymentable_invoice, $request_invoices); $this->checkInvoice($paymentable_invoice, $request_invoices);
}
} }
// if($payment->credits()->exists()) // if($payment->credits()->exists())
@ -75,36 +73,32 @@ class ValidRefundableRequest implements Rule
// $this->checkCredit($paymentable_credit, $request_credits); // $this->checkCredit($paymentable_credit, $request_credits);
// } // }
foreach($request_invoices as $request_invoice) foreach ($request_invoices as $request_invoice) {
$this->checkInvoiceIsPaymentable($request_invoice, $payment); $this->checkInvoiceIsPaymentable($request_invoice, $payment);
}
// foreach($request_credits as $request_credit) // foreach($request_credits as $request_credit)
// $this->checkCreditIsPaymentable($request_credit, $payment); // $this->checkCreditIsPaymentable($request_credit, $payment);
if(strlen($this->error_msg) > 0 ) if (strlen($this->error_msg) > 0) {
return false; return false;
}
return true; return true;
} }
private function checkInvoiceIsPaymentable($invoice, $payment) private function checkInvoiceIsPaymentable($invoice, $payment)
{ {
$invoice = Invoice::whereId($invoice['invoice_id'])->whereCompanyId($payment->company_id)->first(); $invoice = Invoice::whereId($invoice['invoice_id'])->whereCompanyId($payment->company_id)->first();
if($payment->invoices()->exists()) if ($payment->invoices()->exists()) {
{
$paymentable_invoice = $payment->invoices->where('id', $invoice->id)->first(); $paymentable_invoice = $payment->invoices->where('id', $invoice->id)->first();
if(!$paymentable_invoice){ if (!$paymentable_invoice) {
$this->error_msg = "Invoice id ".$invoice->hashed_id." is not related to this payment"; $this->error_msg = "Invoice id ".$invoice->hashed_id." is not related to this payment";
return false; return false;
} }
} else {
}
else
{
$this->error_msg = "Invoice id ".$invoice->hashed_id." is not related to this payment"; $this->error_msg = "Invoice id ".$invoice->hashed_id." is not related to this payment";
return false; return false;
} }
@ -114,55 +108,42 @@ class ValidRefundableRequest implements Rule
{ {
$credit = Credit::whereId($credit['credit_id'])->whereCompanyId($payment->company_id)->first(); $credit = Credit::whereId($credit['credit_id'])->whereCompanyId($payment->company_id)->first();
if($payment->credits()->exists()) if ($payment->credits()->exists()) {
{
$paymentable_credit = $payment->credits->where('id', $credit->id)->first(); $paymentable_credit = $payment->credits->where('id', $credit->id)->first();
if(!$paymentable_invoice){ if (!$paymentable_invoice) {
$this->error_msg = "Credit id ".$credit->hashed_id." is not related to this payment"; $this->error_msg = "Credit id ".$credit->hashed_id." is not related to this payment";
return false; return false;
} }
} else {
}
else
{
$this->error_msg = "Credit id ".$credit->hashed_id." is not related to this payment"; $this->error_msg = "Credit id ".$credit->hashed_id." is not related to this payment";
return false; return false;
} }
} }
private function checkInvoice($paymentable, $request_invoices) private function checkInvoice($paymentable, $request_invoices)
{ {
$record_found = false; $record_found = false;
foreach($request_invoices as $request_invoice) foreach ($request_invoices as $request_invoice) {
{ if ($request_invoice['invoice_id'] == $paymentable->pivot->paymentable_id) {
if($request_invoice['invoice_id'] == $paymentable->pivot->paymentable_id)
{
$record_found = true; $record_found = true;
$refundable_amount = ($paymentable->pivot->amount - $paymentable->pivot->refunded); $refundable_amount = ($paymentable->pivot->amount - $paymentable->pivot->refunded);
if($request_invoice['amount'] > $refundable_amount){ if ($request_invoice['amount'] > $refundable_amount) {
$invoice = $paymentable; $invoice = $paymentable;
$this->error_msg = "Attempting to refund more than allowed for invoice id ".$invoice->hashed_id.", maximum refundable amount is ". $refundable_amount; $this->error_msg = "Attempting to refund more than allowed for invoice id ".$invoice->hashed_id.", maximum refundable amount is ". $refundable_amount;
return false; return false;
} }
} }
} }
if(!$record_found) if (!$record_found) {
{
$this->error_msg = "Attempting to refund a payment with invoices attached, please specify valid invoice/s to be refunded."; $this->error_msg = "Attempting to refund a payment with invoices attached, please specify valid invoice/s to be refunded.";
return false; return false;
} }
} }
@ -170,33 +151,25 @@ class ValidRefundableRequest implements Rule
{ {
$record_found = null; $record_found = null;
foreach($request_credits as $request_credit) foreach ($request_credits as $request_credit) {
{ if ($request_credit['credit_id'] == $paymentable->pivot->paymentable_id) {
if($request_credit['credit_id'] == $paymentable->pivot->paymentable_id)
{
$record_found = true; $record_found = true;
$refundable_amount = ($paymentable->pivot->amount - $paymentable->pivot->refunded); $refundable_amount = ($paymentable->pivot->amount - $paymentable->pivot->refunded);
if($request_credit['amount'] > $refundable_amount){ if ($request_credit['amount'] > $refundable_amount) {
$credit = $paymentable; $credit = $paymentable;
$this->error_msg = "Attempting to refund more than allowed for credit ".$credit->number.", maximum refundable amount is ". $refundable_amount; $this->error_msg = "Attempting to refund more than allowed for credit ".$credit->number.", maximum refundable amount is ". $refundable_amount;
return false; return false;
} }
} }
} }
if(!$record_found) if (!$record_found) {
{
$this->error_msg = "Attempting to refund a payment with credits attached, please specify valid credit/s to be refunded."; $this->error_msg = "Attempting to refund a payment with credits attached, please specify valid credit/s to be refunded.";
return false; return false;
} }
} }
/** /**
@ -206,5 +179,4 @@ class ValidRefundableRequest implements Rule
{ {
return $this->error_msg; return $this->error_msg;
} }
} }

View File

@ -28,8 +28,8 @@ class PaymentAmountsBalanceRule implements Rule
* @return bool * @return bool
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
return $this->calculateAmounts(); return $this->calculateAmounts();
} }
/** /**
@ -48,36 +48,33 @@ class PaymentAmountsBalanceRule implements Rule
* have been presented! * have been presented!
*/ */
if(!request()->has('amount')) if (!request()->has('amount')) {
return true; return true;
}
if(request()->has('amount') && request()->input('amount') == 0) if (request()->has('amount') && request()->input('amount') == 0) {
return true; return true;
}
$payment_amounts = 0; $payment_amounts = 0;
$invoice_amounts = 0; $invoice_amounts = 0;
$payment_amounts += request()->input('amount'); $payment_amounts += request()->input('amount');
if(request()->input('credits') && is_array(request()->input('credits'))) if (request()->input('credits') && is_array(request()->input('credits'))) {
{ foreach (request()->input('credits') as $credit) {
foreach(request()->input('credits') as $credit)
{
$payment_amounts += $credit['amount']; $payment_amounts += $credit['amount'];
} }
} }
if(request()->input('invoices') && is_array(request()->input('invoices'))) if (request()->input('invoices') && is_array(request()->input('invoices'))) {
{ foreach (request()->input('invoices') as $invoice) {
foreach(request()->input('invoices') as $invoice)
{
$invoice_amounts += $invoice['amount']; $invoice_amounts += $invoice['amount'];
} }
} } else {
else return true;
return true; // if no invoices are present, then this is an unapplied payment, let this pass validation! } // if no invoices are present, then this is an unapplied payment, let this pass validation!
return $payment_amounts >= $invoice_amounts; return $payment_amounts >= $invoice_amounts;
} }
} }

View File

@ -23,7 +23,7 @@ use Illuminate\Contracts\Validation\Rule;
*/ */
class PaymentAppliedValidAmount implements Rule class PaymentAppliedValidAmount implements Rule
{ {
use MakesHash; use MakesHash;
/** /**
* @param string $attribute * @param string $attribute
@ -32,7 +32,7 @@ class PaymentAppliedValidAmount implements Rule
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
return $this->calculateAmounts(); return $this->calculateAmounts();
} }
/** /**
@ -45,34 +45,29 @@ class PaymentAppliedValidAmount implements Rule
private function calculateAmounts() :bool private function calculateAmounts() :bool
{ {
$payment = Payment::whereId($this->decodePrimaryKey(request()->segment(4)))->company()->first();
$payment = Payment::whereId($this->decodePrimaryKey(request()->segment(4)))->company()->first(); if (!$payment) {
if(!$payment)
return false; return false;
}
$payment_amounts = 0; $payment_amounts = 0;
$invoice_amounts = 0; $invoice_amounts = 0;
$payment_amounts = $payment->amount - $payment->applied; $payment_amounts = $payment->amount - $payment->applied;
if(request()->input('credits') && is_array(request()->input('credits'))) if (request()->input('credits') && is_array(request()->input('credits'))) {
{ foreach (request()->input('credits') as $credit) {
foreach(request()->input('credits') as $credit)
{
$payment_amounts += $credit['amount']; $payment_amounts += $credit['amount'];
} }
} }
if(request()->input('invoices') && is_array(request()->input('invoices'))) if (request()->input('invoices') && is_array(request()->input('invoices'))) {
{ foreach (request()->input('invoices') as $invoice) {
foreach(request()->input('invoices') as $invoice)
{
$invoice_amounts += $invoice['amount']; $invoice_amounts += $invoice['amount'];
} }
} }
return $payment_amounts >= $invoice_amounts; return $payment_amounts >= $invoice_amounts;
} }
} }

View File

@ -32,7 +32,7 @@ class ValidCreditsPresentRule implements Rule
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
return $this->validCreditsPresent(); return $this->validCreditsPresent();
} }
/** /**
@ -47,20 +47,18 @@ class ValidCreditsPresentRule implements Rule
private function validCreditsPresent() :bool private function validCreditsPresent() :bool
{ {
//todo need to ensure the clients credits are here not random ones! //todo need to ensure the clients credits are here not random ones!
if(request()->input('credits') && is_array(request()->input('credits'))) if (request()->input('credits') && is_array(request()->input('credits'))) {
{ foreach (request()->input('credits') as $credit) {
foreach(request()->input('credits') as $credit)
{
$cred = Credit::find($this->decodePrimaryKey($credit['credit_id'])); $cred = Credit::find($this->decodePrimaryKey($credit['credit_id']));
if($cred->balance == 0) if ($cred->balance == 0) {
return false; return false;
}
} }
} }
return true; return true;
} }
} }

View File

@ -43,15 +43,14 @@ class ValidRefundableInvoices implements Rule
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
$payment = Payment::whereId($this->input['id'])->first(); $payment = Payment::whereId($this->input['id'])->first();
if(!$payment){ if (!$payment) {
$this->error_msg = "Payment couldn't be retrieved cannot be refunded "; $this->error_msg = "Payment couldn't be retrieved cannot be refunded ";
return false; return false;
} }
if(request()->has('amount') && (request()->input('amount') > ($payment->amount - $payment->refunded))){ if (request()->has('amount') && (request()->input('amount') > ($payment->amount - $payment->refunded))) {
$this->error_msg = "Attempting to refunded more than payment amount, enter a value equal to or lower than the payment amount of ". $payment->amount; $this->error_msg = "Attempting to refunded more than payment amount, enter a value equal to or lower than the payment amount of ". $payment->amount;
return false; return false;
} }
@ -61,9 +60,9 @@ class ValidRefundableInvoices implements Rule
if (is_array($value)) { if (is_array($value)) {
$invoices = Invoice::whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get(); $invoices = Invoice::whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get();
} } else {
else
return true; return true;
}
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
if (! $invoice->isRefundable()) { if (! $invoice->isRefundable()) {
@ -73,18 +72,17 @@ class ValidRefundableInvoices implements Rule
foreach ($this->input['invoices'] as $val) { foreach ($this->input['invoices'] as $val) {
if ($val['invoice_id'] == $invoice->id) { if ($val['invoice_id'] == $invoice->id) {
//$pivot_record = $invoice->payments->where('id', $invoice->id)->first(); //$pivot_record = $invoice->payments->where('id', $invoice->id)->first();
$pivot_record = $payment->paymentables->where('paymentable_id', $invoice->id)->first(); $pivot_record = $payment->paymentables->where('paymentable_id', $invoice->id)->first();
if($val['amount'] > ($pivot_record->amount - $pivot_record->refunded)) { if ($val['amount'] > ($pivot_record->amount - $pivot_record->refunded)) {
$this->error_msg = "Attempting to refund ". $val['amount'] ." only ".($pivot_record->amount - $pivot_record->refunded)." available for refund"; $this->error_msg = "Attempting to refund ". $val['amount'] ." only ".($pivot_record->amount - $pivot_record->refunded)." available for refund";
return false; return false;
} }
} }
} }
} }
return true; return true;

Some files were not shown because too many files have changed in this diff Show More