From b22825bf17acfee2e2393ebb951a3103f6c37122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Feb 2021 17:01:01 +0100 Subject: [PATCH] wip --- app/Utils/Traits/MakesInvoiceValues.php | 31 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index c808e05aa554..789d5b352723 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -655,9 +655,8 @@ trait MakesInvoiceValues * @param string $value * @return string|null */ - private function processReservedKeywords(string $value): ?string + private function processReservedKeywords(string $value): ?string { - $replacements = [ 'literal' => [ ':MONTH' => now()->localeMonth, @@ -671,9 +670,33 @@ trait MakesInvoiceValues ], ]; - preg_match_all('/:([^:\s]+)/', $value, $m); + // First case, with ranges. + preg_match_all('/\[(.*?)]/', $value, $ranges); - $matches = array_shift($m); + $matches = array_shift($ranges); + + foreach ($matches as $match) { + if (!Str::contains($match, '|')) { + continue; + } + + if (Str::contains($match, '|')) { + $replacement = 'PLACEHOLDER FOR REPLACEMENT!'; + $parts = explode('|', $match); + + info($parts); + info($parts[0]); + + $value = preg_replace( + sprintf('/%s/', preg_quote($match)), $replacement, $value, 1 + ); + } + } + + // Second case with more common calculations. + preg_match_all('/:([^:\s]+)/', $value, $common); + + $matches = array_shift($common); foreach ($matches as $match) { $matches = collect($replacements['literal'])->filter(function ($value, $key) use ($match) {