mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fix for placeholder replacements in invoices
This commit is contained in:
parent
1f0a6725f7
commit
cc84f9eb2e
@ -83,9 +83,23 @@ class UpdateOrCreateProduct implements ShouldQueue
|
|||||||
|
|
||||||
$product = Product::withTrashed()->firstOrNew(['product_key' => $item->product_key, 'company_id' => $this->invoice->company->id]);
|
$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->product_key = $item->product_key;
|
||||||
$product->notes = isset($item->notes) ? $item->notes : '';
|
$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;
|
$product->price = isset($item->cost) ? $item->cost : 0;
|
||||||
|
|
||||||
if (! $product->id) {
|
if (! $product->id) {
|
||||||
|
@ -19,6 +19,7 @@ use App\Models\Credit;
|
|||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
|
use App\Utils\Helpers;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\SavesDocuments;
|
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*/
|
/* Returns an invoice if defined as a key in the $resource array*/
|
||||||
public function getInvitation($invitation, $resource)
|
public function getInvitation($invitation, $resource)
|
||||||
{
|
{
|
||||||
@ -171,7 +146,7 @@ class BaseRepository
|
|||||||
* @throws \ReflectionException
|
* @throws \ReflectionException
|
||||||
*/
|
*/
|
||||||
protected function alternativeSave($data, $model)
|
protected function alternativeSave($data, $model)
|
||||||
{
|
{ //$start = microtime(true);
|
||||||
//forces the client_id if it doesn't exist
|
//forces the client_id if it doesn't exist
|
||||||
if(array_key_exists('client_id', $data))
|
if(array_key_exists('client_id', $data))
|
||||||
$model->client_id = $data['client_id'];
|
$model->client_id = $data['client_id'];
|
||||||
@ -208,9 +183,19 @@ class BaseRepository
|
|||||||
$model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3;
|
$model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3;
|
||||||
$model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4;
|
$model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4;
|
||||||
|
|
||||||
if(!$model->id)
|
if(!$model->id){
|
||||||
$this->new_model = true;
|
$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->saveQuietly();
|
||||||
|
|
||||||
/* Model now persisted, now lets do some child tasks */
|
/* Model now persisted, now lets do some child tasks */
|
||||||
@ -378,6 +363,8 @@ class BaseRepository
|
|||||||
|
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
|
// nlog("save time = ". microtime(true) - $start);
|
||||||
|
|
||||||
return $model->fresh();
|
return $model->fresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ class Helpers
|
|||||||
|
|
||||||
if(!$string_hit)
|
if(!$string_hit)
|
||||||
return $value;
|
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());
|
Carbon::setLocale($entity->locale());
|
||||||
|
|
||||||
@ -296,8 +296,7 @@ class Helpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
// $x = str_replace(["\n", "<br>"], ["\r", "<br>"], $value);
|
|
||||||
// return $x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user