rector fixes + bug fixes

This commit is contained in:
Dennis Eichhorn 2023-05-27 03:06:45 +00:00
parent 9a9aecd785
commit cf73c37e21
5 changed files with 107 additions and 109 deletions

View File

@ -82,9 +82,9 @@ $toCountry = \is_string($countryEnumName) && ($country = ISO3166NameEnum::get
$addressString = \trim( $addressString = \trim(
$bill->billTo . "\n" $bill->billTo . "\n"
. (!empty($bill->billAddress) ? ($bill->billAddress . "\n") : '') . (empty($bill->billAddress) ? '' : ($bill->billAddress . "\n"))
. (!empty($bill->billCity) ? ($bill->billCity . "\n") : '') . (empty($bill->billCity) ? '' : ($bill->billCity . "\n"))
. (!empty($toCountry) ? ($toCountry . "\n") : ''), . (empty($toCountry) ? '' : ($toCountry . "\n")),
"\n " "\n "
); );

View File

@ -39,7 +39,6 @@ use Modules\SupplierManagement\Models\NullSupplier;
use Modules\SupplierManagement\Models\Supplier; use Modules\SupplierManagement\Models\Supplier;
use Modules\SupplierManagement\Models\SupplierMapper; use Modules\SupplierManagement\Models\SupplierMapper;
use phpOMS\Autoloader; use phpOMS\Autoloader;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO4217CharEnum; use phpOMS\Localization\ISO4217CharEnum;
use phpOMS\Localization\ISO639x1Enum; use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\Http\RequestStatusCode;
@ -265,7 +264,7 @@ final class ApiBillController extends Controller
$billLanguage = $accountBillLanguage; $billLanguage = $accountBillLanguage;
} else { } else {
$accountLanguages = ISO639x1Enum::languageFromCountry($account->mainAddress->getCountry()); $accountLanguages = ISO639x1Enum::languageFromCountry($account->mainAddress->getCountry());
$accountLanguage = !empty($accountLanguages) ? $accountLanguages[0] : ''; $accountLanguage = empty($accountLanguages) ? '' : $accountLanguages[0];
if (\in_array($accountLanguage, $validLanguages)) { if (\in_array($accountLanguage, $validLanguages)) {
$billLanguage = $accountLanguage; $billLanguage = $accountLanguage;
@ -350,9 +349,7 @@ final class ApiBillController extends Controller
->execute(); ->execute();
} }
$bill = $this->createBaseBill($account, $request); return $this->createBaseBill($account, $request);
return $bill;
} }
/** /**
@ -867,8 +864,8 @@ final class ApiBillController extends Controller
$path = $this->createBillDir($bill); $path = $this->createBillDir($bill);
$pdfDir = __DIR__ . '/../../../Modules/Media/Files' . $path; $pdfDir = __DIR__ . '/../../../Modules/Media/Files' . $path;
$status = !\is_dir($pdfDir) ? \mkdir($pdfDir, 0755, true) : true; $status = \is_dir($pdfDir) ? true : \mkdir($pdfDir, 0755, true);
if ($status === false) { if (!$status) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$response->set($request->uri->__toString(), new FormValidation(['status' => $status])); $response->set($request->uri->__toString(), new FormValidation(['status' => $status]));
$response->header->status = RequestStatusCode::R_400; $response->header->status = RequestStatusCode::R_400;

View File

@ -167,12 +167,11 @@ final class ApiPriceController extends Controller
&& $price->clientsection->id === 0 && $price->clientsection->id === 0
&& $price->clienttype->id === 0 && $price->clienttype->id === 0
&& $price->promocode === '' && $price->promocode === ''
&& $price->price < ($bestBasePrice?->price ?? \PHP_INT_MAX)
) { ) {
if ($price->price < ($bestBasePrice?->price ?? \PHP_INT_MAX)) {
$bestBasePrice = $price; $bestBasePrice = $price;
} }
} }
}
// @todo: implement prices which cannot be improved even if there are better prices available (i.e. some customer groups may not get better prices, Dentagen Beispiel) // @todo: implement prices which cannot be improved even if there are better prices available (i.e. some customer groups may not get better prices, Dentagen Beispiel)
// alternatively set prices as 'improvable' => which whitelists a price as can be improved or 'alwaysimproces' which always overwrites other prices // alternatively set prices as 'improvable' => which whitelists a price as can be improved or 'alwaysimproces' which always overwrites other prices

View File

@ -113,11 +113,12 @@ final class ApiPurchaseController extends Controller
$this->app->moduleManager->get('Billing', 'Api')->apiBillPdfArchiveCreate($billRequest, $billResponse); $this->app->moduleManager->get('Billing', 'Api')->apiBillPdfArchiveCreate($billRequest, $billResponse);
// Offload bill parsing to cli // Offload bill parsing to cli
$cliPath = \realpath(__DIR__ . '/../../../Cli/cli.php'); $cliPath = \realpath(__DIR__ . '/../../../cli.php');
if ($cliPath === false) { if ($cliPath === false) {
return; return;
} }
try {
SystemUtils::runProc( SystemUtils::runProc(
OperatingSystem::getSystem() === SystemType::WIN ? 'php.exe' : 'php', OperatingSystem::getSystem() === SystemType::WIN ? 'php.exe' : 'php',
\escapeshellarg($cliPath) \escapeshellarg($cliPath)
@ -125,6 +126,9 @@ final class ApiPurchaseController extends Controller
. '-i ' . \escapeshellarg((string) $billId), . '-i ' . \escapeshellarg((string) $billId),
true true
); );
} catch (\Throwable $t) {
$this->app->logger->error($t->getMessage());
}
} }
} }
} }

View File

@ -347,8 +347,6 @@ final class CliController extends Controller
*/ */
private function matchSupplier(string $content, array $suppliers) : int private function matchSupplier(string $content, array $suppliers) : int
{ {
$bestMatch = 0;
// bill_match_pattern // bill_match_pattern
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
// @todo: consider to support regex? // @todo: consider to support regex?
@ -373,16 +371,16 @@ final class CliController extends Controller
// name1 + city || address // name1 + city || address
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
if (\stripos($content, $supplier->account->name1) !== false) { if (\stripos($content, $supplier->account->name1) !== false
if ((!empty($supplier->mainAddress->city) && ((!empty($supplier->mainAddress->city)
&& \stripos($content, $supplier->mainAddress->city) !== false) && \stripos($content, $supplier->mainAddress->city) !== false)
|| (!empty( $supplier->mainAddress->address) || (!empty( $supplier->mainAddress->address)
&& \stripos($content, $supplier->mainAddress->address) !== false) && \stripos($content, $supplier->mainAddress->address) !== false)
)
) { ) {
return $supplier->id; return $supplier->id;
} }
} }
}
// name1 // name1
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
@ -391,7 +389,7 @@ final class CliController extends Controller
} }
} }
return $bestMatch; return 0;
} }
/** /**