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

Fix for placeholder replacements in invoices

This commit is contained in:
David Bomba 2022-10-21 09:05:37 +11:00
parent 1f0a6725f7
commit cc84f9eb2e
3 changed files with 33 additions and 33 deletions

View File

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

View File

@ -19,6 +19,7 @@ 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;
@ -108,32 +109,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 +146,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 +183,19 @@ 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;
$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 +363,8 @@ class BaseRepository
$model->save();
// nlog("save time = ". microtime(true) - $start);
return $model->fresh();
}
}

View File

@ -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", "<br>"], ["\r", "<br>"], $value);
// return $x;
}
/**