diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php
index 75b3b98aac5d..fbcfe2677605 100644
--- a/app/Jobs/Company/CompanyExport.php
+++ b/app/Jobs/Company/CompanyExport.php
@@ -515,8 +515,8 @@ class CompanyExport implements ShouldQueue
$path = 'backups';
- if(!Storage::disk(config('filesystems.default'))->exists($path))
- Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
+ // if(!Storage::disk(config('filesystems.default'))->exists($path))
+ // Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
$zip_path = public_path('storage/backups/'.$file_name);
$zip = new \ZipArchive();
diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php
index 68988da98432..96c6c48edbfd 100644
--- a/app/Jobs/Entity/CreateEntityPdf.php
+++ b/app/Jobs/Entity/CreateEntityPdf.php
@@ -213,11 +213,13 @@ class CreateEntityPdf implements ShouldQueue
if ($pdf) {
try {
- if (! Storage::disk($this->disk)->exists($path)) {
- Storage::disk($this->disk)->makeDirectory($path, 0775);
- }
+ // if (! Storage::disk($this->disk)->exists($path)) {
+ // Storage::disk($this->disk)->makeDirectory($path, 0775);
+ // }
Storage::disk($this->disk)->put($file_path, $pdf, 'public');
+
+//r2 Storage::disk($this->disk)->put($file_path, $pdf);
} catch (\Exception $e) {
throw new FilePermissionsFailure($e->getMessage());
}
diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php
index 8544f8316404..eff3edd8ff12 100644
--- a/app/Jobs/Product/UpdateOrCreateProduct.php
+++ b/app/Jobs/Product/UpdateOrCreateProduct.php
@@ -83,9 +83,23 @@ class UpdateOrCreateProduct implements ShouldQueue
$product = Product::withTrashed()->firstOrNew(['product_key' => $item->product_key, 'company_id' => $this->invoice->company->id]);
+ /* If a user is using placeholders in their descriptions, do not update the products */
+ $string_hit = false;
+
+ foreach ( [':MONTH',':YEAR',':QUARTER',':WEEK'] as $string )
+ {
+
+ if(stripos($product->notes, $string) !== FALSE) {
+ $string_hit = true;
+ }
+
+ }
+
+ if($string_hit)
+ continue;
+
$product->product_key = $item->product_key;
$product->notes = isset($item->notes) ? $item->notes : '';
- //$product->cost = isset($item->cost) ? $item->cost : 0; //this value shouldn't be updated.
$product->price = isset($item->cost) ? $item->cost : 0;
if (! $product->id) {
diff --git a/app/Jobs/Vendor/CreatePurchaseOrderPdf.php b/app/Jobs/Vendor/CreatePurchaseOrderPdf.php
index d11f62e64f0e..b8ff4af3a1d9 100644
--- a/app/Jobs/Vendor/CreatePurchaseOrderPdf.php
+++ b/app/Jobs/Vendor/CreatePurchaseOrderPdf.php
@@ -100,11 +100,13 @@ class CreatePurchaseOrderPdf implements ShouldQueue
try{
- if(!Storage::disk($this->disk)->exists($this->path))
- Storage::disk($this->disk)->makeDirectory($this->path, 0775);
+ // if(!Storage::disk($this->disk)->exists($this->path))
+ // Storage::disk($this->disk)->makeDirectory($this->path, 0775);
Storage::disk($this->disk)->put($this->file_path, $pdf, 'public');
+//r2 Storage::disk($this->disk)->put($this->file_path, $pdf);
+
}
catch(\Exception $e)
{
diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php
index e0ef5317e617..cbf07442c075 100644
--- a/app/Mail/TemplateEmail.php
+++ b/app/Mail/TemplateEmail.php
@@ -146,10 +146,17 @@ class TemplateEmail extends Mailable
}
+ //22-10-2022 - Performance - To improve the performance/reliability of sending emails, attaching as Data is much better, stubs in place
foreach ($this->build_email->getAttachments() as $file) {
if (is_string($file)) {
+ // nlog($file);
+ // $file_data = file_get_contents($file);
+ // $this->attachData($file_data, basename($file));
$this->attach($file);
} elseif (is_array($file)) {
+ // nlog($file['path']);
+ // $file_data = file_get_contents($file['path']);
+ // $this->attachData($file_data, $file['name']);
$this->attach($file['path'], ['as' => $file['name'], 'mime' => null]);
}
}
diff --git a/app/Models/Backup.php b/app/Models/Backup.php
index 2ddc96a685ae..efddb0ab6b1c 100644
--- a/app/Models/Backup.php
+++ b/app/Models/Backup.php
@@ -36,15 +36,15 @@ class Backup extends BaseModel
$filename = now()->format('Y_m_d').'_'.md5(time()).'.html';
$file_path = $path.$filename;
- Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
+ // Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
Storage::disk(config('filesystems.default'))->put($file_path, $html);
- if (Storage::disk(config('filesystems.default'))->exists($file_path)) {
+ // if (Storage::disk(config('filesystems.default'))->exists($file_path)) {
$this->html_backup = '';
$this->filename = $file_path;
$this->save();
- }
+ // }
}
public function deleteFile()
diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php
index f636d21413fa..59deeb53f077 100644
--- a/app/Repositories/ActivityRepository.php
+++ b/app/Repositories/ActivityRepository.php
@@ -59,7 +59,8 @@ class ActivityRepository extends BaseRepository
$activity->save();
- $this->createBackup($entity, $activity);
+ //rate limiter
+ // $this->createBackup($entity, $activity);
}
/**
@@ -82,7 +83,8 @@ class ActivityRepository extends BaseRepository
$backup = new Backup();
$entity->load('client');
$contact = $entity->client->primary_contact()->first();
- $backup->html_backup = $this->generateHtml($entity);
+ $backup->html_backup = '';
+ // $backup->html_backup = $this->generateHtml($entity);
$backup->amount = $entity->amount;
$backup->activity_id = $activity->id;
$backup->json_backup = '';
diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php
index 4611774fdc80..59fcfaf0c6f2 100644
--- a/app/Repositories/BaseRepository.php
+++ b/app/Repositories/BaseRepository.php
@@ -19,9 +19,11 @@ use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Quote;
use App\Models\RecurringInvoice;
+use App\Utils\Helpers;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments;
+use Google\Service\Vision\Property;
use ReflectionClass;
class BaseRepository
@@ -108,32 +110,6 @@ class BaseRepository
}
}
- /**
- * @param $ids
- * @param $action
- *
- * @return int
- * @deprecated - this doesn't appear to be used anywhere?
- */
- // public function bulk($ids, $action)
- // {
- // if (! $ids) {
- // return 0;
- // }
-
- // $ids = $this->transformKeys($ids);
-
- // $entities = $this->findByPublicIdsWithTrashed($ids);
-
- // foreach ($entities as $entity) {
- // if (auth()->user()->can('edit', $entity)) {
- // $this->$action($entity);
- // }
- // }
-
- // return count($entities);
- // }
-
/* Returns an invoice if defined as a key in the $resource array*/
public function getInvitation($invitation, $resource)
{
@@ -171,7 +147,7 @@ class BaseRepository
* @throws \ReflectionException
*/
protected function alternativeSave($data, $model)
- {
+ { //$start = microtime(true);
//forces the client_id if it doesn't exist
if(array_key_exists('client_id', $data))
$model->client_id = $data['client_id'];
@@ -208,9 +184,21 @@ class BaseRepository
$model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3;
$model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4;
- if(!$model->id)
+ if(!$model->id){
$this->new_model = true;
-
+
+ if(is_array($model->line_items))
+ {
+ $model->line_items = (collect($model->line_items))->map(function ($item) use($model,$client) {
+
+ $item->notes = Helpers::processReservedKeywords($item->notes, $client);
+
+ return $item;
+
+ });
+ }
+ }
+
$model->saveQuietly();
/* Model now persisted, now lets do some child tasks */
@@ -378,6 +366,8 @@ class BaseRepository
$model->save();
+// nlog("save time = ". microtime(true) - $start);
+
return $model->fresh();
}
}
diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php
index 6357049122b3..204c0cc345f5 100644
--- a/app/Services/Invoice/GenerateDeliveryNote.php
+++ b/app/Services/Invoice/GenerateDeliveryNote.php
@@ -105,11 +105,14 @@ class GenerateDeliveryNote
info($maker->getCompiledHTML());
}
- if (! Storage::disk($this->disk)->exists($this->invoice->client->invoice_filepath($invitation))) {
- Storage::disk($this->disk)->makeDirectory($this->invoice->client->invoice_filepath($invitation), 0775);
- }
+ // if (! Storage::disk($this->disk)->exists($this->invoice->client->invoice_filepath($invitation))) {
+ // Storage::disk($this->disk)->makeDirectory($this->invoice->client->invoice_filepath($invitation), 0775);
+ // }
+
Storage::disk($this->disk)->put($file_path, $pdf, 'public');
+//r2 Storage::disk($this->disk)->put($file_path, $pdf);
+
return $file_path;
}
}
diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php
index bb76f66b62ef..19586b19d779 100644
--- a/app/Services/Invoice/InvoiceService.php
+++ b/app/Services/Invoice/InvoiceService.php
@@ -218,6 +218,7 @@ class InvoiceService
public function markDeleted()
{
$this->removeUnpaidGatewayFees();
+ $this->deletePdf();
$this->invoice = (new MarkInvoiceDeleted($this->invoice))->run();
@@ -298,6 +299,9 @@ class InvoiceService
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
$this->setStatus(Invoice::STATUS_PARTIAL);
}
+ elseif($this->invoice->balance < 0) {
+ $this->setStatus(Invoice::STATUS_PARTIAL);
+ }
return $this;
}
diff --git a/app/Services/Invoice/MarkInvoiceDeleted.php b/app/Services/Invoice/MarkInvoiceDeleted.php
index b7478f920133..96c03ac92b77 100644
--- a/app/Services/Invoice/MarkInvoiceDeleted.php
+++ b/app/Services/Invoice/MarkInvoiceDeleted.php
@@ -71,10 +71,6 @@ class MarkInvoiceDeleted extends AbstractService
private function adjustPaidToDateAndBalance()
{
- // $client = $this->invoice->client->fresh();
- // $client->paid_to_date += $this->adjustment_amount * -1;
- // $client->balance += $this->balance_adjustment * -1;
- // $client->save();
// 06-09-2022
$this->invoice
diff --git a/app/Utils/Helpers.php b/app/Utils/Helpers.php
index a3ba8bd67038..fee637ec83e7 100644
--- a/app/Utils/Helpers.php
+++ b/app/Utils/Helpers.php
@@ -128,7 +128,7 @@ class Helpers
if(!$string_hit)
return $value;
- // 04-10-2022 Return Early if no reserved keywords are present, this is a very expenseive process
+ // 04-10-2022 Return Early if no reserved keywords are present, this is a very expensive process
Carbon::setLocale($entity->locale());
@@ -296,8 +296,7 @@ class Helpers
}
return $value;
- // $x = str_replace(["\n", "
"], ["\r", "
"], $value);
- // return $x;
+
}
/**
diff --git a/app/Utils/Traits/ClientGroupSettingsSaver.php b/app/Utils/Traits/ClientGroupSettingsSaver.php
index 585b42ee8e99..67c2b6a774b3 100644
--- a/app/Utils/Traits/ClientGroupSettingsSaver.php
+++ b/app/Utils/Traits/ClientGroupSettingsSaver.php
@@ -65,7 +65,17 @@ trait ClientGroupSettingsSaver
}
$entity->settings = $entity_settings;
- $entity->save();
+
+ try{
+ $entity->save();
+ }
+ catch(\Exception $e){
+
+ nlog("client settings failure");
+ nlog($entity_settings);
+ nlog($e->getMessage());
+
+ }
return $entity_settings;
}
diff --git a/config/filesystems.php b/config/filesystems.php
index 5966073f2cba..a7234ef8eb54 100644
--- a/config/filesystems.php
+++ b/config/filesystems.php
@@ -79,6 +79,19 @@ return [
'throw' => false,
],
+ 'r2' => [
+ 'driver' => 's3',
+ 'key' => env('AWS_ACCESS_KEY_ID'),
+ 'secret' => env('AWS_SECRET_ACCESS_KEY'),
+ 'region' => env('AWS_DEFAULT_REGION'),
+ 'bucket' => env('AWS_BUCKET'),
+ 'url' => env('AWS_URL'),
+ 'visibility' => 'private',
+ 'endpoint' => env('AWS_ENDPOINT'),
+ 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
+ 'throw' => false,
+ ],
+
'gcs' => [
'driver' => 'gcs',
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
diff --git a/tests/Feature/RecurringInvoiceTest.php b/tests/Feature/RecurringInvoiceTest.php
index 9170de330c2c..b995bc47e135 100644
--- a/tests/Feature/RecurringInvoiceTest.php
+++ b/tests/Feature/RecurringInvoiceTest.php
@@ -166,11 +166,12 @@ class RecurringInvoiceTest extends TestCase
'company_id' => $this->company->id,
]);
});
- $client = Client::all()->first();
+
+ $client = Client::query()->orderBy('id', 'DESC')->first();
RecurringInvoice::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
- $RecurringInvoice = RecurringInvoice::where('user_id', $this->user->id)->first();
+ $RecurringInvoice = RecurringInvoice::query()->where('user_id', $this->user->id)->orderBy('id', 'DESC')->first();
$RecurringInvoice->save();
$response = $this->withHeaders([
diff --git a/tests/Feature/RecurringQuoteTest.php b/tests/Feature/RecurringQuoteTest.php
index ecde6a5bc0fd..5c3d98718ae6 100644
--- a/tests/Feature/RecurringQuoteTest.php
+++ b/tests/Feature/RecurringQuoteTest.php
@@ -63,7 +63,7 @@ class RecurringQuoteTest extends TestCase
{
RecurringQuote::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
- $RecurringQuote = RecurringQuote::where('user_id', $this->user->id)->first();
+ $RecurringQuote = RecurringQuote::query()->where('user_id', $this->user->id)->orderBy('id','DESC')->first();
$RecurringQuote->save();
$response = $this->withHeaders([
diff --git a/tests/Integration/DownloadHistoricalInvoiceTest.php b/tests/Integration/DownloadHistoricalInvoiceTest.php
index d72c8f84d2c0..5bd475668f29 100644
--- a/tests/Integration/DownloadHistoricalInvoiceTest.php
+++ b/tests/Integration/DownloadHistoricalInvoiceTest.php
@@ -58,37 +58,5 @@ class DownloadHistoricalInvoiceTest extends TestCase
$this->assertNotNull($this->invoice->activities);
}
- public function testBackupExists()
- {
- $this->mockActivity();
- $this->assertNotNull($this->invoice->activities->first()->backup->html_backup);
- }
-
- public function testBackupDownload()
- {
- $this->mockActivity();
-
- $response = $this->withHeaders([
- 'X-API-SECRET' => config('ninja.api_secret'),
- 'X-API-TOKEN' => $this->token,
- ])->get('/api/v1/activities/download_entity/'.$this->encodePrimaryKey($this->invoice->activities->first()->id));
-
- $response->assertStatus(200);
- }
-
- public function testBackupCheckPriorToDownloadWorks()
- {
- $this->mockActivity();
-
- $backup = $this->invoice->activities->first()->backup;
- $backup->forceDelete();
-
- $response = $this->withHeaders([
- 'X-API-SECRET' => config('ninja.api_secret'),
- 'X-API-TOKEN' => $this->token,
- ])->get('/api/v1/activities/download_entity/'.$this->encodePrimaryKey($this->invoice->activities->first()->id));
-
- $response->assertStatus(404);
- }
}