Fixes for self-update (#3514)

* minor fix for payment notifications

* styleci

* Limit Self updating to self hosters only
:

* Fixes for designs

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

View File

@ -48,34 +48,25 @@ class ArtisanUpgrade extends Command
// call `composer install` command programmatically
$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) {
\Log::error("I wasn't able to migrate the data.");
}
try {
Artisan::call('optimize');
} catch (Exception $e) {
\Log::error("I wasn't able to optimize.");
}
try {
Artisan::call('queue:restart');
} catch (Exception $e) {
\Log::error("I wasn't able to restart the queue");
}
}

View File

@ -137,7 +137,6 @@ class CreateTestData extends Command
}
foreach ($company->clients as $client) {
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
@ -158,10 +157,7 @@ class CreateTestData extends Command
$this->info('creating project for client #'.$client->id);
$this->createProject($client);
}
}
private function createMediumAccount()
@ -225,44 +221,50 @@ class CreateTestData extends Command
}
foreach ($company->clients as $client) {
$this->info('creating invoice for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createInvoice($client);
}
$this->info('creating credit for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createCredit($client);
}
$this->info('creating quote for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createQuote($client);
}
$this->info('creating expense for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createExpense($client);
}
$this->info('creating vendor for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createVendor($client);
}
$this->info('creating task for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createTask($client);
}
$this->info('creating project for client #'.$client->id);
for($i=0; $i<$this->count; $i++)
for ($i=0; $i<$this->count; $i++) {
$this->createProject($client);
}
}
}
private function createLargeAccount()
{
@ -326,7 +328,6 @@ class CreateTestData extends Command
}
foreach ($company->clients as $client) {
$this->info('creating invoice for client #'.$client->id);
$this->createInvoice($client);
@ -348,7 +349,6 @@ class CreateTestData extends Command
$this->info('creating project for client #'.$client->id);
$this->createProject($client);
}
}
private function createClient($company, $user)
@ -374,25 +374,19 @@ class CreateTestData extends Command
'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
@ -548,7 +539,6 @@ class CreateTestData extends Command
$credit->save();
$credit->service()->markSent()->save();
$credit->service()->createInvitations();
}
private function createQuote($client)
@ -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;

View File

@ -38,9 +38,7 @@ class DesignUpdate extends Command
*/
public function handle()
{
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();

View File

@ -46,7 +46,6 @@ class CreateTestCreditJob implements ShouldQueue
public function __construct(Client $client)
{
$this->client = $client;
}
/**
@ -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;

View File

@ -45,7 +45,6 @@ class CreateTestInvoiceJob implements ShouldQueue
public function __construct(Client $client)
{
$this->client = $client;
}
/**
@ -55,7 +54,6 @@ class CreateTestInvoiceJob implements ShouldQueue
*/
public function handle()
{
$faker = \Faker\Factory::create();
$invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);//stub the company and user_id
@ -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;

View File

@ -46,7 +46,6 @@ class CreateTestQuoteJob implements ShouldQueue
public function __construct(Client $client)
{
$this->client = $client;
}
/**
@ -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;
@ -135,5 +132,4 @@ class CreateTestQuoteJob implements ShouldQueue
return $line_items;
}
}

View File

@ -18,8 +18,8 @@ use App\Utils\Traits\MakesHash;
* CompanySettings
*/
class CompanySettings extends BaseSettings {
class CompanySettings extends BaseSettings
{
use MakesHash;
/*Group settings based on functionality*/
@ -404,7 +404,8 @@ class CompanySettings extends BaseSettings {
*
* @return \stdClass
*/
public function __construct($obj) {
public function __construct($obj)
{
// parent::__construct($obj);
}
@ -412,8 +413,8 @@ class CompanySettings extends BaseSettings {
* Provides class defaults on init
* @return object
*/
public static function defaults():\stdClass {
public static function defaults():\stdClass
{
$config = json_decode(config('ninja.settings'));
$data = (object) get_class_vars(CompanySettings::class);
@ -441,7 +442,8 @@ class CompanySettings extends BaseSettings {
*
* @param object $data The settings object to be checked
*/
public static function setProperties($settings):\stdClass {
public static function setProperties($settings):\stdClass
{
$company_settings = (object) get_class_vars(CompanySettings::class);
foreach ($company_settings as $key => $value) {
@ -453,16 +455,16 @@ class CompanySettings extends BaseSettings {
return $settings;
}
public static function notificationDefaults() {
public static function notificationDefaults()
{
$notification = new \stdClass;
$notification->email = ['all_notifications'];
return $notification;
}
private static function getEntityVariableDefaults() {
private static function getEntityVariableDefaults()
{
$variables = [
'client_details' => [
'$client.name' => ctrans('texts.client_name'),

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Bold extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
public function includes()
@ -33,8 +33,8 @@ class Bold extends AbstractDesign
</style>';
}
public function header() {
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">
@ -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,8 +13,8 @@ namespace App\Designs;
class Clean extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -39,8 +39,8 @@ class Clean extends AbstractDesign
}
public function header() {
public function header()
{
return '<div class="px-12 my-10">
<div class="flex items-center">
<div class="w-1/3">
@ -57,8 +57,8 @@ class Clean extends AbstractDesign
</div>';
}
public function body() {
public function body()
{
return '<h1 class="mt-12 uppercase text-2xl text-blue-500 ml-4">
$entity_label
</h1>
@ -95,7 +95,6 @@ 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,8 +16,8 @@ namespace App\Designs;
*/
class Creative extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -42,8 +42,8 @@ margin-top: 6mm;
}
public function header() {
public function header()
{
return '<div class="py-16 mx-16">
<div class="flex justify-between">
<div class="w-2/3 flex">
@ -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>
@ -96,7 +95,8 @@ margin-top: 6mm;
</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

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

View File

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

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Elegant extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -39,8 +39,8 @@ class Elegant extends AbstractDesign
}
public function header() {
public function header()
{
return '<div class="py-16 px-8">
<div class="flex flex justify-between border-b-4 border-black">
<div style="margin-bottom: 15px">
@ -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,10 +87,10 @@ class Elegant extends AbstractDesign
$product_table_body
</tbody>
</table>';
}
public function task() {
public function task()
{
return '';
}
@ -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,8 +13,8 @@ namespace App\Designs;
class Hipster extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -40,8 +40,8 @@ body {font-size:90%}
}
public function header() {
public function header()
{
return '<div class="px-12 py-16">
<div class="flex">
<div class="w-1/2 border-l pl-4 border-black mr-4">
@ -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,10 +101,10 @@ body {font-size:90%}
$task_table_body
</tbody>
</table>';
}
public function task() {
public function task()
{
return '';
}
@ -114,8 +113,8 @@ body {font-size:90%}
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,8 +13,8 @@ namespace App\Designs;
class Modern extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -61,8 +61,8 @@ class Modern extends AbstractDesign
}
public function header() {
public function header()
{
return '<div class="div_header bg-orange-600 flex justify-between py-12 px-12" style="page-break-inside: avoid;">
<div class="w-1/2">
<h1 class="text-white font-bold text-5xl">$company.name</h1>
@ -76,11 +76,10 @@ class Modern extends AbstractDesign
</div>
</div>
</div>';
}
public function body() {
public function body()
{
return '<section>
<div class="flex justify-between px-12 pt-12">
<div class="w-1/2">
@ -112,10 +111,10 @@ class Modern extends AbstractDesign
$task_table_body
</tbody>
</table>';
}
public function task() {
public function task()
{
return '';
}
@ -124,8 +123,8 @@ class Modern extends AbstractDesign
return '';
}
public function footer() {
public function footer()
{
return '
<div class="flex px-4 mt-6 w-full" style="page-break-inside: avoid;">
<div class="w-1/2">
@ -181,7 +180,5 @@ class Modern extends AbstractDesign
</footer>
</html>
';
}
}

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Photo extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -44,8 +44,8 @@ body {font-size:90%}
public function header() {
public function header()
{
return '<div class="px-16 py-10">
<div class="flex items-center justify-between mt-2s">
<div ref="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,8 +13,8 @@ namespace App\Designs;
class Plain extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -38,8 +38,8 @@ body {font-size:90%}
}
public function header() {
public function header()
{
return ' <div class="px-12 py-8">
<div class="flex justify-between">
$company_logo
@ -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>
</body>
</html>';
</div>';
}
public function task()
{
return '';
}
public function product()
{
return '';
}
public function footer()
{
return '';
}
}

View File

@ -13,8 +13,8 @@ namespace App\Designs;
class Playful extends AbstractDesign
{
public function __construct() {
public function __construct()
{
}
@ -39,8 +39,8 @@ body {font-size:90%}
}
public function header() {
public function header()
{
return '<div class="my-12 mx-16">
<div class="flex items-center justify-between">
<div class="w-1/2">
@ -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>
</body>
</html>';
</div>';
}
public function task()
{
return '';
}
public function product()
{
return '';
}
public function footer()
{
return '';
}
}

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,
'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,6 +9,9 @@ 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.
*
@ -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,7 +67,8 @@ 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->credentials($request),
function ($user, $password) {
$this->resetPassword($user, $password);
}
);

View File

@ -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) {
} 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'));
@ -169,40 +147,33 @@ class BaseController extends Controller
$data = $this->createCollection($query, $transformer, $this->entity_type);
return $this->response($data);
}
protected function createCollection($query, $transformer, $entity_type)
{
$this->buildManager();
if ($this->serializer && $this->serializer != EntityTransformer::API_SERIALIZER_JSON)
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,25 +276,13 @@ 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)
{
if (request()->has('first_load') && request()->input('first_load') == 'true') {
if (auth()->user()->getCompany()->invoices->count() > 1000) {
$data = $mini_load;
}
else
{
} else {
$data = $first_load;
}
}
else
{
} else {
$included = request()->input('include');
$included = explode(',', $included);
@ -340,20 +293,16 @@ class BaseController extends Controller
$data[] = $include;
}
}
}
return $data;
}
public function flutterRoute()
{
if (!$this->checkAppSetup());
return redirect('/setup');
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,7 +38,6 @@ 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 {
@ -46,18 +45,15 @@ class InvitationController extends Controller
}
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

@ -462,32 +462,22 @@ class CompanyController extends BaseController
$company_count = $company->account->companies->count();
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) {
$new_default_company = Company::whereAccountId($account->id)->first();
$account->default_company_id = $new_default_company->id;
$account->save();
}
}
//@todo delete documents also!!
@ -496,6 +486,5 @@ class CompanyController extends BaseController
//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)
{
}
/**
@ -139,8 +137,7 @@ class CompanyUserController extends BaseController
if (auth()->user()->isAdmin()) {
$company_user->fill($request->input('company_user'));
}
else {
} else {
$company_user->fill($request->input('company_user')['settings']);
$company_user->fill($request->input('company_user')['notifications']);
}

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);
@ -574,7 +575,6 @@ class CreditController extends BaseController
public function downloadPdf($invitation_key)
{
$invitation = $this->credit_repository->getInvitationByKey($invitation_key);
$contact = $invitation->contact;
$credit = $invitation->credit;
@ -582,6 +582,5 @@ class CreditController extends BaseController
$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);

View File

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

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 = [
'message' => trans('texts.white_label_license_error'),
'errors' => []
];
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

@ -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'))
{
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,11 +117,9 @@ 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()
@ -153,8 +149,9 @@ class PreviewController extends BaseController
$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);
}
$designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
@ -167,9 +164,5 @@ class PreviewController extends BaseController
$client->forceDelete();
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,15 +517,11 @@ 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)) {
return response()->json(['message'=>'Insufficient privileges to access quote '. $quote->number]);
}
});
ZipInvoices::dispatch($quotes, $quotes->first()->company, auth()->user()->email);
@ -536,11 +533,9 @@ class QuoteController extends BaseController
* 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,6 +676,7 @@ 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;
@ -687,7 +685,6 @@ class QuoteController extends BaseController
public function downloadPdf($invitation_key)
{
$invitation = $this->quote_repo->getInvitationByKey($invitation_key);
$contact = $invitation->contact;
$quote = $invitation->quote;
@ -695,7 +692,5 @@ class QuoteController extends BaseController
$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)
{
if(Ninja::isNinja())
return response()->json(['message' => 'Self update not available on this system.'], 403);
$res = $updater->update();
return response()->json(['message'=>$res], 200);
}
public function checkVersion(UpdaterManager $updater)
{
}
}

View File

@ -17,25 +17,20 @@ use App\Utils\SystemHealth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
/**
* Class SetupController
*/
class SetupController extends Controller
{
public function index()
{
$system_health = SystemHealth::check();
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';
@ -82,11 +77,10 @@ class SetupController extends Controller
Artisan::call('migrate');
Artisan::call('db:seed');
if(Account::count() == 0)
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,7 +501,6 @@ class UserController extends BaseController
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
@ -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

@ -51,7 +51,6 @@ class QueryLogging
// 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 = [

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

View File

@ -39,11 +39,13 @@ class UpdateDesignRequest extends Request
{
$input = $this->all();
if(!array_key_exists('product', $input['design']) || is_null($input['design']['product']))
if (!array_key_exists('product', $input['design']) || is_null($input['design']['product'])) {
$input['design']['product'] = '';
}
if(!array_key_exists('task', $input['design']) || is_null($input['design']['task']))
if (!array_key_exists('task', $input['design']) || is_null($input['design']['task'])) {
$input['design']['task'] = '';
}
$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']))
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']))
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))
{
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']))
{
foreach($input['invitations'] as $key => $value)
{
if(isset($input['invitations'][$key]['id']) && is_numeric($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']))
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']))
{
foreach($input['invitations'] as $key => $value)
{
if(is_numeric($input['invitations'][$key]['id']))
if (isset($input['invitations'])) {
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

@ -33,32 +33,30 @@ class RefundPaymentRequest extends Request
protected function prepareForValidation()
{
$input = $this->all();
if(!isset($input['gateway_refund']))
if (!isset($input['gateway_refund'])) {
$input['gateway_refund'] = false;
if(!isset($input['send_email']))
$input['send_email'] = false;
if(isset($input['id']))
$input['id'] = $this->decodePrimaryKey($input['id']);
if(isset($input['invoices']))
{
foreach($input['invoices'] as $key => $invoice)
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']);
}
if(isset($input['credits']))
{
if (!isset($input['send_email'])) {
$input['send_email'] = false;
}
if (isset($input['id'])) {
$input['id'] = $this->decodePrimaryKey($input['id']);
}
if (isset($input['invoices'])) {
foreach ($input['invoices'] as $key => $invoice) {
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']);
}
}
if (isset($input['credits'])) {
unset($input['credits']);
// foreach($input['credits'] as $key => $credit)
// $input['credits'][$key]['credit_id'] = $this->decodePrimaryKey($credit['credit_id']);
}
$this->replace($input);

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'];
}

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

@ -36,41 +36,36 @@ protected function prepareForValidation()
{
$input = $this->all();
if(array_key_exists('design_id', $input) && is_string($input['design_id']))
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
}
if($input['client_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))
{
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']))
{
foreach($input['invitations'] as $key => $value)
{
if(isset($input['invitations'][$key]['id']) && is_numeric($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']) : [];
@ -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']))
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

@ -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,14 +44,11 @@ class ValidInvoicesRules implements Rule
public function passes($attribute, $value)
{
return $this->checkInvoicesAreHomogenous();
}
private function checkInvoicesAreHomogenous()
{
if (!array_key_exists('client_id', $this->input)) {
$this->error_msg = "Client id is required";
return false;
@ -59,8 +56,7 @@ class ValidInvoicesRules implements Rule
$unique_array = [];
foreach($this->input['invoices'] as $invoice)
{
foreach ($this->input['invoices'] as $invoice) {
$unique_array[] = $invoice['invoice_id'];
$inv = Invoice::whereId($invoice['invoice_id'])->first();
@ -76,15 +72,13 @@ class ValidInvoicesRules implements Rule
}
}
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,11 +61,11 @@ 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) {
$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,19 +108,14 @@ 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) {
$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;
}
@ -136,33 +125,25 @@ class ValidRefundableRequest implements Rule
{
$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) {
$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) {
$credit = $paymentable;
$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

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

@ -45,34 +45,29 @@ class PaymentAppliedValidAmount implements Rule
private function calculateAmounts() :bool
{
$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

@ -49,18 +49,16 @@ class ValidCreditsPresentRule implements Rule
{
//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)
if ($cred->balance == 0) {
return false;
}
}
}
return true;
}
}

View File

@ -43,7 +43,6 @@ class ValidRefundableInvoices implements Rule
public function passes($attribute, $value)
{
$payment = Payment::whereId($this->input['id'])->first();
if (!$payment) {
@ -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()) {
@ -84,7 +83,6 @@ class ValidRefundableInvoices implements Rule
}
}
}
}
return true;

View File

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

View File

@ -78,6 +78,4 @@ class ApplyCreditPayment implements ShouldQueue
/* Update Payment Applied Amount*/
$this->payment->save();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -47,9 +47,10 @@ class EmailQuote implements ShouldQueue
*/
public function handle()
{
Mail::to($this->quote_invitation->contact->email, $this->quote_invitation->contact->present()->name())
->send(new TemplateEmail($this->email_builder,
->send(
new TemplateEmail(
$this->email_builder,
$this->quote_invitation->contact->user,
$this->quote_invitation->contact->client
)
@ -58,7 +59,6 @@ class EmailQuote implements ShouldQueue
if (count(Mail::failures()) > 0) {
return $this->logMailError(Mail::failures());
}
}
private function logMailError($errors)

View File

@ -161,14 +161,14 @@ class Import implements ShouldQueue
throw new MigrationValidatorFailed(json_encode($validator->errors()));
}
if (isset($data['account_id']))
if (isset($data['account_id'])) {
unset($data['account_id']);
}
$company_repository = new CompanyRepository();
$company_repository->save($data, $this->company);
Company::reguard();
}
/**
@ -192,16 +192,17 @@ class Import implements ShouldQueue
}
foreach ($data as $resource) {
$modified = $resource;
$company_id = $this->company->id;
$user_id = $this->processUserId($resource);
if (isset($resource['user_id']))
if (isset($resource['user_id'])) {
unset($resource['user_id']);
}
if (isset($resource['company_id']))
if (isset($resource['company_id'])) {
unset($resource['company_id']);
}
$tax_rate = TaxRateFactory::create($this->company->id, $user_id);
$tax_rate->fill($resource);
@ -210,7 +211,6 @@ class Import implements ShouldQueue
}
TaxRate::reguard();
}
/**
@ -240,7 +240,6 @@ class Import implements ShouldQueue
$user_repository = new UserRepository();
foreach ($data as $resource) {
$modified = $resource;
unset($modified['id']);
@ -259,7 +258,6 @@ class Import implements ShouldQueue
}
User::reguard();
}
/**
@ -275,7 +273,6 @@ class Import implements ShouldQueue
$client_repository = new ClientRepository($contact_repository);
foreach ($data as $key => $resource) {
$modified = $resource;
$modified['company_id'] = $this->company->id;
$modified['user_id'] = $this->processUserId($resource);
@ -283,8 +280,12 @@ class Import implements ShouldQueue
unset($modified['id']);
unset($modified['contacts']);
$client = $client_repository->save($modified, ClientFactory::create(
$this->company->id, $modified['user_id'])
$client = $client_repository->save(
$modified,
ClientFactory::create(
$this->company->id,
$modified['user_id']
)
);
if (array_key_exists('contacts', $resource)) { // need to remove after importing new migration.json
@ -310,7 +311,6 @@ class Import implements ShouldQueue
}
Client::reguard();
}
private function processProducts(array $data): void
@ -333,25 +333,26 @@ class Import implements ShouldQueue
$product_repository = new ProductRepository();
foreach ($data as $resource) {
$modified = $resource;
$modified['company_id'] = $this->company->id;
$modified['user_id'] = $this->processUserId($resource);
unset($modified['id']);
$product_repository->save($modified, ProductFactory::create(
$this->company->id, $modified['user_id'])
$product_repository->save(
$modified,
ProductFactory::create(
$this->company->id,
$modified['user_id']
)
);
}
Product::reguard();
}
private function processInvoices(array $data): void
{
Invoice::unguard();
$rules = [
@ -367,7 +368,6 @@ class Import implements ShouldQueue
$invoice_repository = new InvoiceRepository();
foreach ($data as $resource) {
$modified = $resource;
if (array_key_exists('client_id', $resource) && !array_key_exists('clients', $this->ids)) {
@ -381,7 +381,8 @@ class Import implements ShouldQueue
unset($modified['id']);
$invoice = $invoice_repository->save(
$modified, InvoiceFactory::create($this->company->id, $modified['user_id'])
$modified,
InvoiceFactory::create($this->company->id, $modified['user_id'])
);
$key = "invoices_{$resource['id']}";
@ -390,11 +391,9 @@ class Import implements ShouldQueue
'old' => $resource['id'],
'new' => $invoice->id,
];
}
Invoice::reguard();
}
private function processCredits(array $data): void
@ -414,7 +413,6 @@ class Import implements ShouldQueue
$credit_repository = new CreditRepository();
foreach ($data as $resource) {
$modified = $resource;
if (array_key_exists('client_id', $resource) && !array_key_exists('clients', $this->ids)) {
@ -428,7 +426,8 @@ class Import implements ShouldQueue
unset($modified['id']);
$credit = $credit_repository->save(
$modified, CreditFactory::create($this->company->id, $modified['user_id'])
$modified,
CreditFactory::create($this->company->id, $modified['user_id'])
);
$key = "credits_{$resource['id']}";
@ -440,7 +439,6 @@ class Import implements ShouldQueue
}
Credit::reguard();
}
private function processQuotes(array $data): void
@ -460,7 +458,6 @@ class Import implements ShouldQueue
$quote_repository = new QuoteRepository();
foreach ($data as $resource) {
$modified = $resource;
if (array_key_exists('client_id', $resource) && !array_key_exists('clients', $this->ids)) {
@ -475,7 +472,8 @@ class Import implements ShouldQueue
unset($modified['id']);
$invoice = $quote_repository->save(
$modified, QuoteFactory::create($this->company->id, $modified['user_id'])
$modified,
QuoteFactory::create($this->company->id, $modified['user_id'])
);
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
@ -486,11 +484,9 @@ class Import implements ShouldQueue
'old' => $resource['id'],
'new' => $invoice->id,
];
}
Quote::reguard();
}
private function processPayments(array $data): void
@ -511,7 +507,6 @@ class Import implements ShouldQueue
$payment_repository = new PaymentRepository(new CreditRepository());
foreach ($data as $resource) {
$modified = $resource;
if (array_key_exists('client_id', $resource) && !array_key_exists('clients', $this->ids)) {
@ -527,12 +522,14 @@ class Import implements ShouldQueue
unset($modified['invoice_id']);
if (isset($modified['invoices'])) {
foreach ($modified['invoices'] as $invoice)
foreach ($modified['invoices'] as $invoice) {
$invoice['invoice_id'] = $this->transformId('invoices', $invoice['invoice_id']);
}
}
$payment = $payment_repository->save(
$modified, PaymentFactory::create($this->company->id, $modified['user_id'])
$modified,
PaymentFactory::create($this->company->id, $modified['user_id'])
);
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
@ -543,11 +540,9 @@ class Import implements ShouldQueue
'new' => $payment->id,
]
];
}
Payment::reguard();
}
private function processDocuments(array $data): void
@ -556,7 +551,6 @@ class Import implements ShouldQueue
/** No validators since data provided by database is already valid. */
foreach ($data as $resource) {
$modified = $resource;
if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && !array_key_exists('invoices', $this->ids)) {
@ -618,7 +612,6 @@ class Import implements ShouldQueue
}
foreach ($data as $resource) {
$modified = $resource;
$modified['user_id'] = $this->processUserId($resource);
@ -647,7 +640,6 @@ class Import implements ShouldQueue
}
CompanyGateway::reguard();
}
private function processClientGatewayTokens(array $data) :void
@ -655,7 +647,6 @@ class Import implements ShouldQueue
ClientGatewayToken::unguard();
foreach ($data as $resource) {
$modified = $resource;
unset($modified['id']);
@ -676,7 +667,6 @@ class Import implements ShouldQueue
}
ClientGatewayToken::reguard();
}
/**
@ -733,7 +723,6 @@ class Import implements ShouldQueue
*/
public function processUserId(array $resource)
{
if (!array_key_exists('user_id', $resource)) {
return $this->user->id;
}

View File

@ -31,8 +31,8 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Storage;
use Spatie\Browsershot\Browsershot;
class PreviewPdf implements ShouldQueue {
class PreviewPdf implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
public $invoice;
@ -52,18 +52,15 @@ class PreviewPdf implements ShouldQueue {
*/
public function __construct($design_string, Company $company)
{
$this->company = $company;
$this->design_string = $design_string;
$this->disk = $disk ?? config('filesystems.default');
}
public function handle() {
public function handle()
{
$path = $this->company->company_key;
//Storage::makeDirectory($path, 0755);
@ -76,6 +73,4 @@ class PreviewPdf implements ShouldQueue {
return storage_path('app') .'/'. $file_path;
}
}

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