1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Fixes for self-update (#3514)

* minor fix for payment notifications

* styleci

* Limit Self updating to self hosters only
:

* Fixes for designs

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,7 +46,6 @@ class CreateTestQuoteJob implements ShouldQueue
public function __construct(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->date = $faker->date();
$quote->line_items = $this->buildLineItems(rand(1,10));
$quote->line_items = $this->buildLineItems(rand(1, 10));
$quote->uses_inclusive_taxes = false;
if (rand(0, 1)) {
@ -88,7 +87,6 @@ class CreateTestQuoteJob implements ShouldQueue
$quote->service()->markSent()->save();
CreateQuoteInvitations::dispatch($quote, $quote->company);
}
@ -97,8 +95,7 @@ class CreateTestQuoteJob implements ShouldQueue
{
$line_items = [];
for($x=0; $x<$count; $x++)
{
for ($x=0; $x<$count; $x++) {
$item = InvoiceItemFactory::create();
$item->quantity = 1;
//$item->cost = 10;
@ -118,15 +115,15 @@ class CreateTestQuoteJob implements ShouldQueue
$item->tax_rate1 = 5;
}
$product = Product::all()->random();
$product = Product::all()->random();
$item->cost = (float)$product->cost;
$item->product_key = $product->product_key;
$item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4;
$item->cost = (float)$product->cost;
$item->product_key = $product->product_key;
$item->notes = $product->notes;
$item->custom_value1 = $product->custom_value1;
$item->custom_value2 = $product->custom_value2;
$item->custom_value3 = $product->custom_value3;
$item->custom_value4 = $product->custom_value4;
@ -135,5 +132,4 @@ class CreateTestQuoteJob implements ShouldQueue
return $line_items;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -57,7 +57,7 @@ class CreditFilters extends QueryFilters
$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);
}

View File

@ -138,6 +138,6 @@ class DesignFilters extends QueryFilters
public function entityFilter()
{
//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;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Utils\Number;
class InvoiceEmail extends EmailBuilder
{
public function build(InvoiceInvitation $invitation, $reminder_template)
{
$client = $invitation->contact->client;
$invoice = $invitation->invoice;
$contact = $invitation->contact;
if(!$reminder_template)
if (!$reminder_template) {
$reminder_template = $invoice->calculateTemplate();
}
$body_template = $client->getSetting('email_template_' . $reminder_template);
/* Use default translations if a custom message has not been set*/
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(),
'amount' => Number::formatMoney($invoice->balance, $invoice->client),
],
],
null,
$invoice->client->locale());
$invoice->client->locale()
);
}
$subject_template = $client->getSetting('email_subject_' . $reminder_template);
if (iconv_strlen($subject_template) == 0) {
if ($reminder_template == 'quote') {
$subject_template = trans('texts.invoice_subject',
$subject_template = trans(
'texts.invoice_subject',
[
'invoice' => $invoice->present()->invoice_number(),
'account' => $invoice->company->present()->name()
],
null, $invoice->client->locale());
null,
$invoice->client->locale()
);
} else {
$subject_template = trans('texts.reminder_subject',
$subject_template = trans(
'texts.reminder_subject',
[
'invoice' => $invoice->present()->invoice_number(),
'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;
class EmailPayment extends EmailBuilder
{
public function build(Payment $payment, $contact = null) {
public function build(Payment $payment, $contact = null)
{
$client = $payment->client;
$body_template = $client->getSetting('email_template_payment');
/* Use default translations if a custom message has not been set*/
if (iconv_strlen($body_template) == 0) {
$body_template = trans('texts.payment_message',
['amount' => $payment->amount, 'company' => $payment->company->present()->name()], null,
$this->client->locale());
$body_template = trans(
'texts.payment_message',
['amount' => $payment->amount, 'company' => $payment->company->present()->name()],
null,
$this->client->locale()
);
}
$subject_template = $client->getSetting('email_subject_payment');
if (iconv_strlen($subject_template) == 0) {
$subject_template = trans('texts.payment_subject',
['number' => $payment->number, 'company' => $payment->company->present()->name()], null,
$payment->client->locale());
$subject_template = trans(
'texts.payment_subject',
['number' => $payment->number, 'company' => $payment->company->present()->name()],
null,
$payment->client->locale()
);
}
$this->setTemplate($payment->client->getSetting('email_style'))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -461,41 +461,30 @@ class CompanyController extends BaseController
{
$company_count = $company->account->companies->count();
if($company_count == 1){
if ($company_count == 1) {
$company->company_users->each(function ($company_user) {
$company_user->user->forceDelete();
});
$company->account->delete();
}
else {
} else {
$account = $company->account;
$company_id = $company->id;
$company->delete();
//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();
$account->default_company_id = $new_default_company->id;
$account->save();
}
}
//@todo delete documents also!!
//@todo in the hosted version deleting the last
//account will trigger an account refund.
//account will trigger an account refund.
return response()->json(['message' => 'success'], 200);
}
}

View File

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

View File

@ -33,8 +33,9 @@ class Controller extends BaseController
if (array_key_exists('root', $options)) {
return view(
sprintf('%s.%s.%s', $options['root'], $theme, $path)
, $options);
sprintf('%s.%s.%s', $options['root'], $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)
{
if($request->entityIsDeleted($credit))
if ($request->entityIsDeleted($credit)) {
return $request->disallowUpdate();
}
$credit = $this->credit_repository->save($request->all(), $credit);
@ -572,16 +573,14 @@ class CreditController extends BaseController
}
}
public function downloadPdf($invitation_key)
public function downloadPdf($invitation_key)
{
$invitation = $this->credit_repository->getInvitationByKey($invitation_key);
$contact = $invitation->contact;
$credit = $invitation->credit;
$file_path = $credit->service()->getCreditPdf($contact);
$file_path = $credit->service()->getCreditPdf($contact);
return response()->download($file_path);
}
}

View File

@ -255,8 +255,9 @@ class DesignController extends BaseController
*/
public function update(UpdateDesignRequest $request, Design $design)
{
if($request->entityIsDeleted($design))
if ($request->entityIsDeleted($design)) {
return $request->disallowUpdate();
}
$design->fill($request->all());
$design->save();
@ -485,6 +486,4 @@ class DesignController extends BaseController
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)
{
if($request->entityIsDeleted($expense))
if ($request->entityIsDeleted($expense)) {
return $request->disallowUpdate();
}
$expense = $this->client_repo->save($request->all(), $expense);

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -226,7 +226,9 @@ class MigrationController extends BaseController
$migration_file = $request->file('migration')
->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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,6 @@ use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use Illuminate\Support\Facades\Storage;
class PreviewController extends BaseController
{
use MakesHash;
@ -88,16 +87,14 @@ class PreviewController extends BaseController
*/
public function show()
{
if (request()->has('entity') &&
request()->has('entity_id') &&
request()->has('body'))
{
if (request()->has('entity') &&
request()->has('entity_id') &&
request()->has('body')) {
$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);
}
$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();
if(!$entity_obj)
if (!$entity_obj) {
return $this->blankEntity();
}
$entity_obj->load('client');
@ -119,21 +117,19 @@ class PreviewController extends BaseController
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
return response()->download($file_path)->deleteFileAfterSend(true);
}
return $this->blankEntity();
}
private function blankEntity()
{
$client = factory(\App\Models\Client::class)->create([
$client = factory(\App\Models\Client::class)->create([
'user_id' => auth()->user()->id,
'company_id' => auth()->user()->company()->id,
]);
$contact = factory(\App\Models\ClientContact::class)->create([
$contact = factory(\App\Models\ClientContact::class)->create([
'user_id' => auth()->user()->id,
'company_id' => auth()->user()->company()->id,
'client_id' => $client->id,
@ -141,35 +137,32 @@ class PreviewController extends BaseController
'send_email' => true,
]);
$invoice = factory(\App\Models\Invoice::class)->create([
$invoice = factory(\App\Models\Invoice::class)->create([
'user_id' => auth()->user()->id,
'company_id' => auth()->user()->company()->id,
'client_id' => $client->id,
]);
$invoice->setRelation('client', $client);
$invoice->setRelation('company', auth()->user()->company());
$invoice->load('client');
$invoice->setRelation('client', $client);
$invoice->setRelation('company', auth()->user()->company());
$invoice->load('client');
$design_object = json_decode(json_encode(request()->input('design')));
$design_object = json_decode(json_encode(request()->input('design')));
if(!is_object($design_object))
return response()->json(['message' => 'Invalid custom design object'], 400);
if (!is_object($design_object)) {
return response()->json(['message' => 'Invalid custom design object'], 400);
}
$designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
$designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
$html = $this->generateEntityHtml($designer, $invoice, $contact);
$html = $this->generateEntityHtml($designer, $invoice, $contact);
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
$invoice->forceDelete();
$contact->forceDelete();
$client->forceDelete();
return response()->file($file_path, array('content-type' => 'application/pdf'));
$invoice->forceDelete();
$contact->forceDelete();
$client->forceDelete();
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)
{
if($request->entityIsDeleted($product))
if ($request->entityIsDeleted($product)) {
return $request->disallowUpdate();
}
$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)
{
if($request->entityIsDeleted($quote))
if ($request->entityIsDeleted($quote)) {
return $request->disallowUpdate();
}
$quote = $this->quote_repo->save($request->all(), $quote);
@ -516,31 +517,25 @@ class QuoteController extends BaseController
* Download Invoice/s
*/
if($action == 'download' && $quotes->count() > 1)
{
if ($action == 'download' && $quotes->count() > 1) {
$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]);
}
});
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
*/
$quotes->each(function ($quote, $key) use ($action) {
if (auth()->user()->can('edit', $quote)) {
$this->performAction($quote, $action, true);
}
});
/* 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);
}
@ -642,8 +638,9 @@ class QuoteController extends BaseController
break;
case 'approve':
//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 $this->itemResponse($quote->service()->approve()->save());
break;
@ -679,23 +676,21 @@ class QuoteController extends BaseController
if (!$bulk) {
return $this->itemResponse($quote);
}
// no break
default:
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
break;
}
}
public function downloadPdf($invitation_key)
public function downloadPdf($invitation_key)
{
$invitation = $this->quote_repo->getInvitationByKey($invitation_key);
$contact = $invitation->contact;
$quote = $invitation->quote;
$file_path = $quote->service()->getQuotePdf($contact);
$file_path = $quote->service()->getQuotePdf($contact);
return response()->download($file_path);
}
}

View File

@ -377,8 +377,9 @@ class RecurringInvoiceController extends BaseController
*/
public function update(UpdateRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
{
if($request->entityIsDeleted($recurring_invoice))
if ($request->entityIsDeleted($recurring_invoice)) {
return $request->disallowUpdate();
}
$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)
{
if($request->entityIsDeleted($recurring_quote))
if ($request->entityIsDeleted($recurring_quote)) {
return $request->disallowUpdate();
}
$recurring_quote = $this->recurring_quote_repo->save(request(), $recurring_quote);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,6 @@ class PasswordProtection
return response()->json($error, 403);
}
} elseif (Cache::get(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));

View File

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

View File

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

View File

@ -28,7 +28,6 @@ class TokenAuth
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())) {
$user = $company_token->user;
$error = [
@ -51,8 +50,8 @@ class TokenAuth
config(['ninja.company_id' => $company_token->company->id]);
app('queue')->createPayloadUsing(function () use($company_token) {
return ['db' => $company_token->company->db];
app('queue')->createPayloadUsing(function () use ($company_token) {
return ['db' => $company_token->company->db];
});
//user who once existed, but has been soft deleted

View File

@ -69,72 +69,56 @@ class StoreClientRequest extends Request
protected function prepareForValidation()
{
$input = $this->all();
//@todo implement feature permissions for > 100 clients
//
$settings = ClientSettings::defaults();
if(array_key_exists('settings', $input) && !empty($input['settings']))
{
foreach($input['settings'] as $key => $value)
{
if (array_key_exists('settings', $input) && !empty($input['settings'])) {
foreach ($input['settings'] as $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!!
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']);
$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;
else
} else {
$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;
}
$input['settings'] = $settings;
if(isset($input['contacts']))
{
foreach($input['contacts'] as $key => $contact)
{
if(array_key_exists('id', $contact) && is_numeric($contact['id']))
if (isset($input['contacts'])) {
foreach ($input['contacts'] as $key => $contact) {
if (array_key_exists('id', $contact) && is_numeric($contact['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']);
}
//Filter the client contact password - if it is sent with ***** we should ignore it!
if(isset($contact['password']))
{
if(strlen($contact['password']) == 0){
if (isset($contact['password'])) {
if (strlen($contact['password']) == 0) {
$input['contacts'][$key]['password'] = '';
}
else {
} else {
$contact['password'] = str_replace("*", "", $contact['password']);
if(strlen($contact['password']) == 0){
if (strlen($contact['password']) == 0) {
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']);
}
if(isset($input['contacts']))
{
foreach($input['contacts'] as $key => $contact)
{
if(array_key_exists('id', $contact) && is_numeric($contact['id']))
if (isset($input['contacts'])) {
foreach ($input['contacts'] as $key => $contact) {
if (array_key_exists('id', $contact) && is_numeric($contact['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']);
}
//Filter the client contact password - if it is sent with ***** we should ignore it!
if(isset($contact['password']))
{
if(strlen($contact['password']) == 0){
if (isset($contact['password'])) {
if (strlen($contact['password']) == 0) {
$input['contacts'][$key]['password'] = '';
}
else {
} else {
$contact['password'] = str_replace("*", "", $contact['password']);
if(strlen($contact['password']) == 0){
if (strlen($contact['password']) == 0) {
unset($input['contacts'][$key]['password']);
}
}
}
}
}
$this->replace($input);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -45,8 +45,9 @@ class StoreRecurringInvoiceRequest extends Request
{
$input = $this->all();
if($input['client_id'])
if ($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'] = json_encode($input['line_items']);

View File

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

View File

@ -45,12 +45,12 @@ class StoreRecurringQuoteRequest extends Request
{
$input = $this->all();
if($input['client_id'])
if ($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'] = json_encode($input['line_items']);
$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']) : [];
$this->replace($input);
}
}

View File

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

View File

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

View File

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

View File

@ -44,47 +44,41 @@ class ValidInvoicesRules implements Rule
public function passes($attribute, $value)
{
return $this->checkInvoicesAreHomogenous();
return $this->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";
return false;
}
$unique_array = [];
foreach($this->input['invoices'] as $invoice)
{
$unique_array[] = $invoice['invoice_id'];
foreach ($this->input['invoices'] as $invoice) {
$unique_array[] = $invoice['invoice_id'];
$inv = Invoice::whereId($invoice['invoice_id'])->first();
if(!$inv){
if (!$inv) {
$this->error_msg = "Invoice not found ";
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";
return false;
return false;
}
}
}
if(!(array_unique($unique_array) == $unique_array))
{
if (!(array_unique($unique_array) == $unique_array)) {
$this->error_msg = "Duplicate invoices submitted.";
return false;
}
return true;
}
@ -95,6 +89,4 @@ class ValidInvoicesRules implements Rule
{
return $this->error_msg;
}
}

View File

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

View File

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

View File

@ -23,7 +23,7 @@ use Illuminate\Contracts\Validation\Rule;
*/
class PaymentAppliedValidAmount implements Rule
{
use MakesHash;
use MakesHash;
/**
* @param string $attribute
@ -32,7 +32,7 @@ class PaymentAppliedValidAmount implements Rule
*/
public function passes($attribute, $value)
{
return $this->calculateAmounts();
return $this->calculateAmounts();
}
/**
@ -45,34 +45,29 @@ class PaymentAppliedValidAmount implements Rule
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;
}
$payment_amounts = 0;
$invoice_amounts = 0;
$payment_amounts = $payment->amount - $payment->applied;
if(request()->input('credits') && is_array(request()->input('credits')))
{
foreach(request()->input('credits') as $credit)
{
if (request()->input('credits') && is_array(request()->input('credits'))) {
foreach (request()->input('credits') as $credit) {
$payment_amounts += $credit['amount'];
}
}
if(request()->input('invoices') && is_array(request()->input('invoices')))
{
foreach(request()->input('invoices') as $invoice)
{
if (request()->input('invoices') && is_array(request()->input('invoices'))) {
foreach (request()->input('invoices') as $invoice) {
$invoice_amounts += $invoice['amount'];
}
}
return $payment_amounts >= $invoice_amounts;
}
}

View File

@ -32,7 +32,7 @@ class ValidCreditsPresentRule implements Rule
*/
public function passes($attribute, $value)
{
return $this->validCreditsPresent();
return $this->validCreditsPresent();
}
/**
@ -47,20 +47,18 @@ class ValidCreditsPresentRule implements Rule
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')))
{
foreach(request()->input('credits') as $credit)
{
if (request()->input('credits') && is_array(request()->input('credits'))) {
foreach (request()->input('credits') as $credit) {
$cred = Credit::find($this->decodePrimaryKey($credit['credit_id']));
if($cred->balance == 0)
return false;
if ($cred->balance == 0) {
return false;
}
}
}
return true;
}
}

View File

@ -43,15 +43,14 @@ class ValidRefundableInvoices implements Rule
public function passes($attribute, $value)
{
$payment = Payment::whereId($this->input['id'])->first();
if(!$payment){
if (!$payment) {
$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;
return false;
}
@ -61,9 +60,9 @@ class ValidRefundableInvoices implements Rule
if (is_array($value)) {
$invoices = Invoice::whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get();
}
else
} else {
return true;
}
foreach ($invoices as $invoice) {
if (! $invoice->isRefundable()) {
@ -73,18 +72,17 @@ class ValidRefundableInvoices implements Rule
foreach ($this->input['invoices'] as $val) {
if ($val['invoice_id'] == $invoice->id) {
if ($val['invoice_id'] == $invoice->id) {
//$pivot_record = $invoice->payments->where('id', $invoice->id)->first();
$pivot_record = $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";
return false;
}
}
}
}
}
return true;

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