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

@ -48,34 +48,25 @@ class ArtisanUpgrade extends Command
// 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,8 +136,7 @@ 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);
@ -158,10 +157,7 @@ class CreateTestData extends Command
$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,45 +220,51 @@ 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);
} }
} }
}
private function createLargeAccount() private function createLargeAccount()
{ {
@ -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,8 +327,7 @@ 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);
@ -348,7 +349,6 @@ class CreateTestData extends Command
$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)
@ -374,25 +374,19 @@ class CreateTestData extends Command
'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;

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

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

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;
} }
/** /**
@ -55,16 +54,15 @@ class CreateTestInvoiceJob implements ShouldQueue
*/ */
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;

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;
@ -135,5 +132,4 @@ class CreateTestQuoteJob implements ShouldQueue
return $line_items; return $line_items;
} }
} }

View File

@ -18,8 +18,8 @@ use App\Utils\Traits\MakesHash;
* CompanySettings * CompanySettings
*/ */
class CompanySettings extends BaseSettings { class CompanySettings extends BaseSettings
{
use MakesHash; use MakesHash;
/*Group settings based on functionality*/ /*Group settings based on functionality*/
@ -144,8 +144,8 @@ class CompanySettings extends BaseSettings {
public $pdf_email_attachment = false; public $pdf_email_attachment = false;
public $ubl_email_attachment = false; public $ubl_email_attachment = false;
public $email_style = 'plain';//plain, light, dark, custom public $email_style = 'plain'; //plain, light, dark, custom
public $email_style_custom = '';//the template itself public $email_style_custom = ''; //the template itself
public $email_subject_invoice = ''; public $email_subject_invoice = '';
public $email_subject_quote = ''; public $email_subject_quote = '';
public $email_subject_payment = ''; public $email_subject_payment = '';
@ -404,7 +404,8 @@ class CompanySettings extends BaseSettings {
* *
* @return \stdClass * @return \stdClass
*/ */
public function __construct($obj) { public function __construct($obj)
{
// parent::__construct($obj); // parent::__construct($obj);
} }
@ -412,11 +413,11 @@ class CompanySettings extends BaseSettings {
* Provides class defaults on init * Provides class defaults on init
* @return object * @return object
*/ */
public static function defaults():\stdClass { public static function defaults():\stdClass
{
$config = json_decode(config('ninja.settings')); $config = json_decode(config('ninja.settings'));
$data = (object) get_class_vars(CompanySettings::class ); $data = (object) get_class_vars(CompanySettings::class);
unset($data->casts); unset($data->casts);
unset($data->protected_fields); unset($data->protected_fields);
@ -441,8 +442,9 @@ class CompanySettings extends BaseSettings {
* *
* @param object $data The settings object to be checked * @param object $data The settings object to be checked
*/ */
public static function setProperties($settings):\stdClass { public static function setProperties($settings):\stdClass
$company_settings = (object) get_class_vars(CompanySettings::class ); {
$company_settings = (object) get_class_vars(CompanySettings::class);
foreach ($company_settings as $key => $value) { foreach ($company_settings as $key => $value) {
if (!property_exists($settings, $key)) { if (!property_exists($settings, $key)) {
@ -453,16 +455,16 @@ class CompanySettings extends BaseSettings {
return $settings; return $settings;
} }
public static function notificationDefaults() { public static function notificationDefaults()
{
$notification = new \stdClass; $notification = new \stdClass;
$notification->email = ['all_notifications']; $notification->email = ['all_notifications'];
return $notification; return $notification;
} }
private static function getEntityVariableDefaults() { private static function getEntityVariableDefaults()
{
$variables = [ $variables = [
'client_details' => [ 'client_details' => [
'$client.name' => ctrans('texts.client_name'), '$client.name' => ctrans('texts.client_name'),

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Bold extends AbstractDesign class Bold extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
public function includes() public function includes()
@ -33,8 +33,8 @@ 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">
@ -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,8 +13,8 @@ namespace App\Designs;
class Clean extends AbstractDesign class Clean extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -39,8 +39,8 @@ 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">
@ -57,8 +57,8 @@ class Clean extends AbstractDesign
</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,7 +95,6 @@ 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,8 +16,8 @@ namespace App\Designs;
*/ */
class Creative extends AbstractDesign class Creative extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -42,8 +42,8 @@ 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">
@ -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>
@ -96,7 +95,8 @@ margin-top: 6mm;
</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

@ -43,5 +43,4 @@ class Custom extends AbstractDesign
$this->footer = $design->design->footer; $this->footer = $design->design->footer;
} }
} }

View File

@ -14,8 +14,8 @@ 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;
@ -57,10 +57,9 @@ class Designer {
$this->design = $design->design; $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;
} }
/** /**
@ -70,7 +69,6 @@ class Designer {
*/ */
public function build():Designer public function build():Designer
{ {
$this->setHtml() $this->setHtml()
->exportVariables() ->exportVariables()
->setDesign($this->getSection('includes')) ->setDesign($this->getSection('includes'))
@ -79,7 +77,6 @@ class Designer {
->setDesign($this->getSection('footer')); ->setDesign($this->getSection('footer'));
return $this; return $this;
} }
public function init() public function init()
@ -99,7 +96,6 @@ class Designer {
public function getHeader() public function getHeader()
{ {
$this->setDesign($this->getSection('header')); $this->setDesign($this->getSection('header'));
return $this; return $this;
@ -107,7 +103,6 @@ class Designer {
public function getFooter() public function getFooter()
{ {
$this->setDesign($this->getSection('footer')); $this->setDesign($this->getSection('footer'));
return $this; return $this;
@ -115,7 +110,6 @@ class Designer {
public function getBody() public function getBody()
{ {
$this->setDesign($this->getSection('body')); $this->setDesign($this->getSection('body'));
return $this; return $this;
@ -135,7 +129,6 @@ class Designer {
private function setDesign($section) private function setDesign($section)
{ {
$this->html .= $section; $this->html .= $section;
return $this; return $this;
@ -155,7 +148,6 @@ class Designer {
private function exportVariables() private function exportVariables()
{ {
$company = $this->entity->company; $company = $this->entity->company;
$this->exported_variables['$app_url'] = $this->entity->generateAppUrl(); $this->exported_variables['$app_url'] = $this->entity->generateAppUrl();
@ -163,18 +155,13 @@ class Designer {
$this->exported_variables['$company_details'] = $this->processVariables($this->input_variables['company_details'], $this->companyDetails($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)); $this->exported_variables['$company_address'] = $this->processVariables($this->input_variables['company_address'], $this->companyAddress($company));
if($this->entity_string == 'invoice') if ($this->entity_string == 'invoice') {
{
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['invoice_details'], $this->invoiceDetails($company)); $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)); $this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['invoice_details'], $this->invoiceDetails($company));
} } elseif ($this->entity_string == 'credit') {
elseif($this->entity_string == 'credit')
{
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['credit_details'], $this->creditDetails($company)); $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)); $this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['credit_details'], $this->creditDetails($company));
} } elseif ($this->entity_string == 'quote') {
elseif($this->entity_string == 'quote')
{
$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['quote_details'], $this->quoteDetails($company)); $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['$entity_details'] = $this->processVariables($this->input_variables['quote_details'], $this->quoteDetails($company));
} }
@ -184,11 +171,13 @@ class Designer {
$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;
} }
@ -197,20 +186,18 @@ class Designer {
{ {
$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 private function processLabels($input_variables, $variables):string
{ {
$output = ''; $output = '';
foreach (array_keys($input_variables) as $value) { foreach (array_keys($input_variables) as $value) {
$tmp = str_replace("</span>", "_label</span>", $variables[$value]); $tmp = str_replace("</span>", "_label</span>", $variables[$value]);
//$output .= $variables[$value]; //$output .= $variables[$value];
$output .= $tmp; $output .= $tmp;
@ -221,7 +208,6 @@ class Designer {
private function clientDetails(Company $company) private function clientDetails(Company $company)
{ {
$data = [ $data = [
'$client.name' => '<p>$client.name</p>', '$client.name' => '<p>$client.name</p>',
'$client.id_number' => '<p>$client.id_number</p>', '$client.id_number' => '<p>$client.id_number</p>',
@ -247,7 +233,6 @@ class Designer {
private function companyDetails(Company $company) private function companyDetails(Company $company)
{ {
$data = [ $data = [
'$company.company_name' => '<span>$company.company_name</span>', '$company.company_name' => '<span>$company.company_name</span>',
'$company.id_number' => '<span>$company.id_number</span>', '$company.id_number' => '<span>$company.id_number</span>',
@ -262,12 +247,10 @@ class Designer {
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
} }
private function companyAddress(Company $company) private function companyAddress(Company $company)
{ {
$data = [ $data = [
'$company.address1' => '<span>$company.address1</span>', '$company.address1' => '<span>$company.address1</span>',
'$company.address2' => '<span>$company.address2</span>', '$company.address2' => '<span>$company.address2</span>',
@ -281,12 +264,10 @@ class Designer {
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
} }
private function invoiceDetails(Company $company) private function invoiceDetails(Company $company)
{ {
$data = [ $data = [
'$invoice.invoice_number' => '<span>$invoice_number_label</span><span>$invoice_number</span>', '$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.po_number' => '<span>$po_number_label</span><span>$po_number</span>',
@ -306,12 +287,10 @@ class Designer {
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
} }
private function quoteDetails(Company $company) private function quoteDetails(Company $company)
{ {
$data = [ $data = [
'$quote.quote_number' => '<span>$quote_number</span>', '$quote.quote_number' => '<span>$quote_number</span>',
'$quote.po_number' => '<span>$po_number</span>', '$quote.po_number' => '<span>$po_number</span>',
@ -331,12 +310,10 @@ class Designer {
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
} }
private function creditDetails(Company $company) private function creditDetails(Company $company)
{ {
$data = [ $data = [
'$credit.credit_number' => '<span>$credit_number</span>', '$credit.credit_number' => '<span>$credit_number</span>',
'$credit.po_number' => '<span>$po_number</span>', '$credit.po_number' => '<span>$po_number</span>',
@ -355,12 +332,10 @@ class Designer {
]; ];
return $this->processCustomFields($company, $data); return $this->processCustomFields($company, $data);
} }
private function processCustomFields(Company $company, $data) private function processCustomFields(Company $company, $data)
{ {
$custom_fields = $company->custom_fields; $custom_fields = $company->custom_fields;
if (!$custom_fields) { if (!$custom_fields) {
@ -368,15 +343,12 @@ class Designer {
} }
foreach (self::$custom_fields as $cf) { foreach (self::$custom_fields as $cf) {
if (!property_exists($custom_fields, $cf) || (strlen($custom_fields->{$cf}) == 0)) { if (!property_exists($custom_fields, $cf) || (strlen($custom_fields->{$cf}) == 0)) {
unset($data[$cf]); unset($data[$cf]);
} }
} }
return $data; return $data;
} }
// private function processInputVariables($company, $variables) // private function processInputVariables($company, $variables)
@ -403,5 +375,4 @@ class Designer {
// return $variables; // return $variables;
// } // }
} }

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Elegant extends AbstractDesign class Elegant extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -39,8 +39,8 @@ 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">
@ -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,10 +87,10 @@ class Elegant extends AbstractDesign
$product_table_body $product_table_body
</tbody> </tbody>
</table>'; </table>';
} }
public function task() { public function task()
{
return ''; return '';
} }
@ -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,8 +13,8 @@ namespace App\Designs;
class Hipster extends AbstractDesign class Hipster extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -40,8 +40,8 @@ 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">
@ -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,10 +101,10 @@ body {font-size:90%}
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
} }
public function task() { public function task()
{
return ''; return '';
} }
@ -114,8 +113,8 @@ body {font-size:90%}
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,8 +13,8 @@ namespace App\Designs;
class Modern extends AbstractDesign class Modern extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -61,8 +61,8 @@ 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>
@ -76,11 +76,10 @@ 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">
@ -112,10 +111,10 @@ class Modern extends AbstractDesign
$task_table_body $task_table_body
</tbody> </tbody>
</table>'; </table>';
} }
public function task() { public function task()
{
return ''; return '';
} }
@ -124,8 +123,8 @@ 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">
@ -181,7 +180,5 @@ class Modern extends AbstractDesign
</footer> </footer>
</html> </html>
'; ';
} }
} }

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Photo extends AbstractDesign class Photo extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -44,8 +44,8 @@ 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">
@ -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,8 +13,8 @@ namespace App\Designs;
class Plain extends AbstractDesign class Plain extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -38,8 +38,8 @@ 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
@ -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>
</body>
</html>';
} }
public function task()
{
return '';
}
public function product()
{
return '';
}
public function footer()
{
return '';
}
} }

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Playful extends AbstractDesign class Playful extends AbstractDesign
{ {
public function __construct()
public function __construct() { {
} }
@ -39,8 +39,8 @@ 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">
@ -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>
</body>
</html>';
} }
public function task()
{
return '';
}
public function product()
{
return '';
}
public function footer()
{
return '';
}
} }

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,7 +67,8 @@ 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),
function ($user, $password) {
$this->resetPassword($user, $password); $this->resetPassword($user, $password);
} }
); );

View File

@ -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?
@ -169,40 +147,33 @@ class BaseController extends Controller
$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,25 +276,13 @@ 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) {
if (auth()->user()->getCompany()->invoices->count() > 1000)
{
$data = $mini_load; $data = $mini_load;
} else {
}
else
{
$data = $first_load; $data = $first_load;
} }
} } else {
else
{
$included = request()->input('include'); $included = request()->input('include');
$included = explode(',', $included); $included = explode(',', $included);
@ -340,20 +293,16 @@ class BaseController extends Controller
$data[] = $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,33 +461,23 @@ 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!!
@ -496,6 +486,5 @@ class CompanyController extends BaseController
//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)
{ {
} }
/** /**
@ -132,15 +130,14 @@ class CompanyUserController extends BaseController
$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']);
} }

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);
@ -574,7 +575,6 @@ 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;
@ -582,6 +582,5 @@ class CreditController extends BaseController
$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);

View File

@ -45,8 +45,8 @@ use Illuminate\Support\Facades\Storage;
* @package App\Http\Controllers\InvoiceController * @package App\Http\Controllers\InvoiceController
*/ */
class InvoiceController extends BaseController { class InvoiceController extends BaseController
{
use MakesHash; use MakesHash;
protected $entity_type = Invoice::class ; protected $entity_type = Invoice::class ;
@ -63,12 +63,11 @@ class InvoiceController extends BaseController {
* *
* @param \App\Repositories\InvoiceRepository $invoice_repo The invoice repo * @param \App\Repositories\InvoiceRepository $invoice_repo The invoice repo
*/ */
public function __construct(InvoiceRepository $invoice_repo) { public function __construct(InvoiceRepository $invoice_repo)
{
parent::__construct(); parent::__construct();
$this->invoice_repo = $invoice_repo; $this->invoice_repo = $invoice_repo;
} }
/** /**
@ -112,7 +111,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function index(InvoiceFilters $filters) { public function index(InvoiceFilters $filters)
{
$invoices = Invoice::filter($filters); $invoices = Invoice::filter($filters);
return $this->listResponse($invoices); return $this->listResponse($invoices);
@ -158,8 +158,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function create(CreateInvoiceRequest $request) { public function create(CreateInvoiceRequest $request)
{
$invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id); $invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
@ -205,8 +205,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function store(StoreInvoiceRequest $request) { public function store(StoreInvoiceRequest $request)
{
$client = Client::find($request->input('client_id')); $client = Client::find($request->input('client_id'));
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id)); $invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
@ -270,7 +270,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function show(ShowInvoiceRequest $request, Invoice $invoice) { public function show(ShowInvoiceRequest $request, Invoice $invoice)
{
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -325,7 +326,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function edit(EditInvoiceRequest $request, Invoice $invoice) { public function edit(EditInvoiceRequest $request, Invoice $invoice)
{
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -381,7 +383,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function update(UpdateInvoiceRequest $request, Invoice $invoice) { public function update(UpdateInvoiceRequest $request, Invoice $invoice)
{
if ($request->entityIsDeleted($invoice)) { if ($request->entityIsDeleted($invoice)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
} }
@ -443,7 +446,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function destroy(DestroyInvoiceRequest $request, Invoice $invoice) { public function destroy(DestroyInvoiceRequest $request, Invoice $invoice)
{
$invoice->delete(); $invoice->delete();
return response()->json([], 200); return response()->json([], 200);
@ -500,7 +504,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function bulk() { public function bulk()
{
/* /*
* WIP! * WIP!
@ -519,31 +524,25 @@ class InvoiceController extends BaseController {
* Download Invoice/s * Download Invoice/s
*/ */
if($action == 'download' && $invoices->count() > 1) if ($action == 'download' && $invoices->count() > 1) {
{
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
if (auth()->user()->cannot('view', $invoice)) {
if(auth()->user()->cannot('view', $invoice)){
return response()->json(['message'=>'Insufficient privileges to access invoice '. $invoice->number]); return response()->json(['message'=>'Insufficient privileges to access invoice '. $invoice->number]);
} }
}); });
ZipInvoices::dispatch($invoices, $invoices->first()->company, auth()->user()->email); ZipInvoices::dispatch($invoices, $invoices->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
*/ */
$invoices->each(function ($invoice, $key) use ($action) { $invoices->each(function ($invoice, $key) use ($action) {
if (auth()->user()->can('edit', $invoice)) { if (auth()->user()->can('edit', $invoice)) {
$this->performAction($invoice, $action, true); $this->performAction($invoice, $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 */
@ -619,11 +618,13 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action) { public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
{
return $this->performAction($invoice, $action); return $this->performAction($invoice, $action);
} }
private function performAction(Invoice $invoice, $action, $bulk = false) { private function performAction(Invoice $invoice, $action, $bulk = false)
{
/*If we are using bulk actions, we don't want to return anything */ /*If we are using bulk actions, we don't want to return anything */
switch ($action) { switch ($action) {
case 'clone_to_invoice': case 'clone_to_invoice':
@ -679,15 +680,13 @@ class InvoiceController extends BaseController {
$this->reminder_template = $invoice->calculateTemplate(); $this->reminder_template = $invoice->calculateTemplate();
$invoice->invitations->each(function ($invitation) use($invoice){ $invoice->invitations->each(function ($invitation) use ($invoice) {
$email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template); $email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template);
EmailInvoice::dispatch($email_builder, $invitation, $invoice->company); EmailInvoice::dispatch($email_builder, $invitation, $invoice->company);
}); });
if($invoice->invitations->count() > 0){ if ($invoice->invitations->count() > 0) {
\Log::error("more than one invitation to send"); \Log::error("more than one invitation to send");
event(new InvoiceWasEmailed($invoice->invitations->first())); event(new InvoiceWasEmailed($invoice->invitations->first()));
} }
@ -747,8 +746,8 @@ class InvoiceController extends BaseController {
* ) * )
* *
*/ */
public function downloadPdf($invitation_key) { public function downloadPdf($invitation_key)
{
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key); $invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
$contact = $invitation->contact; $contact = $invitation->contact;
$invoice = $invitation->invoice; $invoice = $invitation->invoice;
@ -756,6 +755,5 @@ class InvoiceController extends BaseController {
$file_path = $invoice->service()->getInvoicePdf($contact); $file_path = $invoice->service()->getInvoicePdf($contact);
return response()->download($file_path); return response()->download($file_path);
} }
} }

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

@ -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,11 +117,9 @@ 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()
@ -153,8 +149,9 @@ class PreviewController extends BaseController
$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')));
@ -167,9 +164,5 @@ class PreviewController extends BaseController
$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,6 +676,7 @@ 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;
@ -687,7 +685,6 @@ class QuoteController extends BaseController
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;
@ -695,7 +692,5 @@ class QuoteController extends BaseController
$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())
return response()->json(['message' => 'Self update not available on this system.'], 403);
$res = $updater->update(); $res = $updater->update();
return response()->json(['message'=>$res], 200); return response()->json(['message'=>$res], 200);
} }
public function checkVersion(UpdaterManager $updater)
{
}
} }

View File

@ -17,25 +17,20 @@ 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() public function index()
{ {
$system_health = SystemHealth::check(); $system_health = SystemHealth::check();
return view(); 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';
@ -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,7 +501,6 @@ 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');
@ -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

@ -51,7 +51,6 @@ class QueryLogging
// 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,7 +50,7 @@ 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];
}); });

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']) 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'])) if (isset($input['client_contacts'])) {
{ foreach ($input['client_contacts'] as $key => $contact) {
foreach($input['client_contacts'] as $key => $contact) if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) {
{
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
{
unset($input['client_contacts'][$key]); unset($input['client_contacts'][$key]);
} }
} }
} }
if(isset($input['invitations'])) if (isset($input['invitations'])) {
{ foreach ($input['invitations'] as $key => $value) {
if (isset($input['invitations'][$key]['id']) && is_numeric($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']); unset($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 (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']);
}
}
} }
$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'])) {
foreach($input['invitations'] as $key => $value)
{
if(is_numeric($input['invitations'][$key]['id']))
unset($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]['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']);
}
}
} }
$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

@ -39,11 +39,13 @@ class UpdateDesignRequest 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

@ -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'])) if (array_key_exists('client_id', $input) && is_string($input['client_id'])) {
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
}
if(isset($input['client_contacts'])) if (isset($input['client_contacts'])) {
{ foreach ($input['client_contacts'] as $key => $contact) {
foreach($input['client_contacts'] as $key => $contact) if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) {
{
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
{
unset($input['client_contacts'][$key]); unset($input['client_contacts'][$key]);
} }
} }
} }
if(isset($input['invitations'])) if (isset($input['invitations'])) {
{ foreach ($input['invitations'] as $key => $value) {
if (isset($input['invitations'][$key]['id']) && is_numeric($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']); unset($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 (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']);
}
}
} }
$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'])) {
foreach($input['invitations'] as $key => $value)
{
if(is_numeric($input['invitations'][$key]['id']))
unset($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]['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']);
}
}
} }
$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

@ -33,32 +33,30 @@ 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']))
$input['send_email'] = false;
if(isset($input['id']))
$input['id'] = $this->decodePrimaryKey($input['id']);
if(isset($input['invoices']))
{
foreach($input['invoices'] as $key => $invoice)
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']);
} }
if(isset($input['credits'])) if (!isset($input['send_email'])) {
{ $input['send_email'] = false;
}
if (isset($input['id'])) {
$input['id'] = $this->decodePrimaryKey($input['id']);
}
if (isset($input['invoices'])) {
foreach ($input['invoices'] as $key => $invoice) {
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']);
}
}
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);

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'])) if (isset($input['client_contacts'])) {
{ foreach ($input['client_contacts'] as $key => $contact) {
foreach($input['client_contacts'] as $key => $contact) if (!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact)) {
{
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
{
unset($input['client_contacts'][$key]); unset($input['client_contacts'][$key]);
} }
} }
} }
if(isset($input['invitations'])) if (isset($input['invitations'])) {
{ foreach ($input['invitations'] as $key => $value) {
if (isset($input['invitations'][$key]['id']) && is_numeric($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']); unset($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 (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']);
}
}
} }
$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

@ -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,11 +61,11 @@ 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,19 +108,14 @@ 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;
} }
@ -136,33 +125,25 @@ class ValidRefundableRequest implements Rule
{ {
$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

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

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

@ -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()) {
@ -78,13 +77,12 @@ class ValidRefundableInvoices implements Rule
//$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;

View File

@ -1,2 +1,54 @@
<?php <?php
namespace App\Jobs\Account; use App\Events\Account\AccountCreated; use App\Jobs\Company\CreateCompany; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\User\CreateUser; use App\Models\Account; use App\Models\User; use App\Notifications\Ninja\NewAccountCreated; use App\Utils\Ninja; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; use Symfony\Component\HttpFoundation\Response; class CreateAccount { use Dispatchable; protected $request; public function __construct(array $sp660339) { $this->request = $sp660339; } public function handle() { if (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { return response()->json(array('message' => Ninja::selfHostedMessage()), 400); } elseif (Ninja::boot()) { return response()->json(array('message' => Ninja::parse()), 401); } $sp794f3f = Account::create($this->request); $sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f); $sp035a66->load('account'); $sp794f3f->default_company_id = $sp035a66->id; $sp794f3f->save(); $spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true); if ($spaa9f78) { auth()->login($spaa9f78, false); } $spaa9f78->setCompany($sp035a66); $spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); if ($spaa9f78) { event(new AccountCreated($spaa9f78)); } $spaa9f78->fresh(); $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); return $sp794f3f; } } namespace App\Jobs\Account;
use App\Events\Account\AccountCreated;
use App\Jobs\Company\CreateCompany;
use App\Jobs\Company\CreateCompanyToken;
use App\Jobs\User\CreateUser;
use App\Models\Account;
use App\Models\User;
use App\Notifications\Ninja\NewAccountCreated;
use App\Utils\Ninja;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Symfony\Component\HttpFoundation\Response;
class CreateAccount
{
use Dispatchable;
protected $request;
public function __construct(array $sp660339)
{
$this->request = $sp660339;
}
public function handle()
{
if (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) {
return response()->json(array('message' => Ninja::selfHostedMessage()), 400);
} elseif (Ninja::boot()) {
return response()->json(array('message' => Ninja::parse()), 401);
}
$sp794f3f = Account::create($this->request);
$sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f);
$sp035a66->load('account');
$sp794f3f->default_company_id = $sp035a66->id;
$sp794f3f->save();
$spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true);
if ($spaa9f78) {
auth()->login($spaa9f78, false);
}
$spaa9f78->setCompany($sp035a66);
$spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT');
$sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e);
if ($spaa9f78) {
event(new AccountCreated($spaa9f78));
}
$spaa9f78->fresh();
$sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja();
return $sp794f3f;
}
}

View File

@ -70,7 +70,7 @@ class ApplyCreditPayment implements ShouldQueue
if ($this->amount == $credit_balance) { //total credit applied. if ($this->amount == $credit_balance) { //total credit applied.
$this->credit->setStatus(Credit::STATUS_APPLIED); $this->credit->setStatus(Credit::STATUS_APPLIED);
$this->credit->updateBalance($this->amount*-1); $this->credit->updateBalance($this->amount*-1);
} elseif($this->amount < $credit_balance) { //compare number appropriately } elseif ($this->amount < $credit_balance) { //compare number appropriately
$this->credit->setStatus(Credit::PARTIAL); $this->credit->setStatus(Credit::PARTIAL);
$this->credit->updateBalance($this->amount*-1); $this->credit->updateBalance($this->amount*-1);
} }
@ -78,6 +78,4 @@ class ApplyCreditPayment implements ShouldQueue
/* Update Payment Applied Amount*/ /* Update Payment Applied Amount*/
$this->payment->save(); $this->payment->save();
} }
} }

View File

@ -32,8 +32,8 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Spatie\Browsershot\Browsershot; use Spatie\Browsershot\Browsershot;
class CreateCreditPdf implements ShouldQueue { class CreateCreditPdf implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
public $credit; public $credit;
@ -51,7 +51,6 @@ class CreateCreditPdf implements ShouldQueue {
*/ */
public function __construct($credit, Company $company, ClientContact $contact = null) public function __construct($credit, Company $company, ClientContact $contact = null)
{ {
$this->credit = $credit; $this->credit = $credit;
$this->company = $company; $this->company = $company;
@ -59,17 +58,17 @@ class CreateCreditPdf implements ShouldQueue {
$this->contact = $contact; $this->contact = $contact;
$this->disk = $disk ?? config('filesystems.default'); $this->disk = $disk ?? config('filesystems.default');
} }
public function handle() { public function handle()
{
MultiDB::setDB($this->company->db); MultiDB::setDB($this->company->db);
$this->credit->load('client'); $this->credit->load('client');
if(!$this->contact) if (!$this->contact) {
$this->contact = $this->credit->client->primary_contact()->first(); $this->contact = $this->credit->client->primary_contact()->first();
}
App::setLocale($this->contact->preferredLocale()); App::setLocale($this->contact->preferredLocale());
@ -82,7 +81,7 @@ class CreateCreditPdf implements ShouldQueue {
$designer = new Designer($this->credit, $design, $this->credit->client->getSetting('pdf_variables'), 'credit'); $designer = new Designer($this->credit, $design, $this->credit->client->getSetting('pdf_variables'), 'credit');
//get invoice design //get invoice design
// $html = $this->generateInvoiceHtml($designer->build()->getHtml(), $this->credit, $this->contact); // $html = $this->generateInvoiceHtml($designer->build()->getHtml(), $this->credit, $this->contact);
$html = $this->generateEntityHtml($designer, $this->credit, $this->contact); $html = $this->generateEntityHtml($designer, $this->credit, $this->contact);
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily //todo - move this to the client creation stage so we don't keep hitting this unnecessarily
@ -97,5 +96,4 @@ class CreateCreditPdf implements ShouldQueue {
// //
return $file_path; return $file_path;
} }
} }

View File

@ -32,8 +32,8 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Spatie\Browsershot\Browsershot; use Spatie\Browsershot\Browsershot;
class CreateInvoicePdf implements ShouldQueue { class CreateInvoicePdf implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
public $invoice; public $invoice;
@ -51,7 +51,6 @@ class CreateInvoicePdf implements ShouldQueue {
*/ */
public function __construct($invoice, Company $company, ClientContact $contact = null) public function __construct($invoice, Company $company, ClientContact $contact = null)
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
$this->company = $company; $this->company = $company;
@ -59,15 +58,15 @@ class CreateInvoicePdf implements ShouldQueue {
$this->contact = $contact; $this->contact = $contact;
$this->disk = $disk ?? config('filesystems.default'); $this->disk = $disk ?? config('filesystems.default');
} }
public function handle() { public function handle()
{
$this->invoice->load('client'); $this->invoice->load('client');
if(!$this->contact) if (!$this->contact) {
$this->contact = $this->invoice->client->primary_contact()->first(); $this->contact = $this->invoice->client->primary_contact()->first();
}
App::setLocale($this->contact->preferredLocale()); App::setLocale($this->contact->preferredLocale());
@ -93,8 +92,5 @@ class CreateInvoicePdf implements ShouldQueue {
$instance = Storage::disk($this->disk)->put($file_path, $pdf); $instance = Storage::disk($this->disk)->put($file_path, $pdf);
return $file_path; return $file_path;
} }
} }

View File

@ -54,9 +54,10 @@ class EmailInvoice implements ShouldQueue
public function handle() public function handle()
{ {
Mail::to($this->invoice_invitation->contact->email, $this->invoice_invitation->contact->present()->name()) Mail::to($this->invoice_invitation->contact->email, $this->invoice_invitation->contact->present()->name())
->send(new TemplateEmail($this->email_builder, ->send(
new TemplateEmail(
$this->email_builder,
$this->invoice_invitation->contact->user, $this->invoice_invitation->contact->user,
$this->invoice_invitation->contact->client $this->invoice_invitation->contact->client
) )
@ -65,7 +66,6 @@ class EmailInvoice implements ShouldQueue
if (count(Mail::failures()) > 0) { if (count(Mail::failures()) > 0) {
return $this->logMailError(Mail::failures()); return $this->logMailError(Mail::failures());
} }
} }
private function logMailError($errors) private function logMailError($errors)

View File

@ -19,7 +19,8 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class InvoiceNotification implements ShouldQueue { class InvoiceNotification implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $invoice; public $invoice;
@ -29,7 +30,8 @@ class InvoiceNotification implements ShouldQueue {
* *
* @return void * @return void
*/ */
public function __construct(Invoice $invoice) { public function __construct(Invoice $invoice)
{
$this->invoice = $invoice; $this->invoice = $invoice;
} }
@ -39,7 +41,8 @@ class InvoiceNotification implements ShouldQueue {
* *
* @return void * @return void
*/ */
public function handle() { public function handle()
{
//notification for the invoice. //notification for the invoice.
// //

View File

@ -59,7 +59,6 @@ class ZipInvoices implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
$tempStream = fopen('php://memory', 'w+'); $tempStream = fopen('php://memory', 'w+');
$options = new Archive(); $options = new Archive();

View File

@ -52,7 +52,6 @@ class EmailPayment implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
if ($this->contact->email) { if ($this->contact->email) {
Mail::to($this->contact->email, $this->contact->present()->name()) Mail::to($this->contact->email, $this->contact->present()->name())
->send(new TemplateEmail($this->email_builder, $this->contact->user, $this->contact->customer)); ->send(new TemplateEmail($this->email_builder, $this->contact->user, $this->contact->customer));
@ -68,7 +67,6 @@ class EmailPayment implements ShouldQueue
//sleep(5); //sleep(5);
} }
} }
private function logMailError($errors) private function logMailError($errors)

View File

@ -32,8 +32,8 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Spatie\Browsershot\Browsershot; use Spatie\Browsershot\Browsershot;
class CreateQuotePdf implements ShouldQueue { class CreateQuotePdf implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
public $quote; public $quote;
@ -51,7 +51,6 @@ class CreateQuotePdf implements ShouldQueue {
*/ */
public function __construct($quote, Company $company, ClientContact $contact = null) public function __construct($quote, Company $company, ClientContact $contact = null)
{ {
$this->quote = $quote; $this->quote = $quote;
$this->company = $company; $this->company = $company;
@ -59,19 +58,19 @@ class CreateQuotePdf implements ShouldQueue {
$this->contact = $contact; $this->contact = $contact;
$this->disk = $disk ?? config('filesystems.default'); $this->disk = $disk ?? config('filesystems.default');
} }
public function handle() { public function handle()
{
MultiDB::setDB($this->company->db); MultiDB::setDB($this->company->db);
$settings = $this->quote->client->getMergedSettings(); $settings = $this->quote->client->getMergedSettings();
$this->quote->load('client'); $this->quote->load('client');
if(!$this->contact) if (!$this->contact) {
$this->contact = $this->quote->client->primary_contact()->first(); $this->contact = $this->quote->client->primary_contact()->first();
}
App::setLocale($this->contact->preferredLocale()); App::setLocale($this->contact->preferredLocale());
@ -115,7 +114,7 @@ class CreateQuotePdf implements ShouldQueue {
//get invoice design //get invoice design
// $html = $this->generateInvoiceHtml($design_body, $this->quote, $this->contact); // $html = $this->generateInvoiceHtml($design_body, $this->quote, $this->contact);
$html = $this->generateEntityHtml($designer, $this->quote, $this->contact); $html = $this->generateEntityHtml($designer, $this->quote, $this->contact);
$pdf = $this->makePdf($all_pages_header, $all_pages_footer, $html); $pdf = $this->makePdf($all_pages_header, $all_pages_footer, $html);
@ -127,5 +126,4 @@ class CreateQuotePdf implements ShouldQueue {
// //
return $file_path; return $file_path;
} }
} }

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