Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Spoje-NET/php-abraflexi
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Jun 4, 2023
2 parents dd413e8 + 8f4cf7a commit b6d0c77
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 216 deletions.
48 changes: 48 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// Pro informace o možných atributech použijte technologii IntelliSense.
// Umístěním ukazatele myši zobrazíte popisy existujících atributů.
// Další informace najdete tady: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug DryRun example",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/Examples/DryRun.php",
"cwd": "${fileDirname}",
"externalConsole": false,
"port": 9003
},
{
"name": "Launch built-in server and debug",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-S",
"localhost:8000",
"-t",
"."
],
"port": 9003,
"serverReadyAction": {
"action": "openExternally"
}
},
{
"name": "Debug current script in console",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"externalConsole": false,
"port": 9003
},
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
},

]
}
29 changes: 23 additions & 6 deletions Examples/DryRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,36 @@
* AbraFlexi - Example how to dry-run request
*
* @author Vítězslav Dvořák <info@vitexsofware.cz>
* @copyright (G) 2018 Vitex Software
* @copyright (G) 2018-2023 Vitex Software
*/

namespace Example\AbraFlexi;

include_once './config.php';
include_once '../vendor/autoload.php';

/**
* Instance of AbraFlexi Invoice in dry-run mode with random code
*/

$invoice = new \AbraFlexi\FakturaVydana();
$invoice = new \AbraFlexi\FakturaVydana([
'kod'=>'DRY_RUN_TEST',
'typDokl' => 'code:FAKTURA',
'poznam' => 'Test ' . time(),
'varSym' => time()], ['dry-run' => true]);

$invoice->defaultUrlParams['dry-run'] = 'true';
/**
* Save invoice to AbraFlexi
*/
try {
$resultInsert = $invoice->insertToAbraFlexi();
} catch (\AbraFlexi\Exception $exc) {
echo $exc->getMessage();
//For example we can get here: "AbraFlexi\FakturaVydana: Pole 'Variabilní symbol' musí být vyplněno. [DRY_RUN_TEST]"
}

$resultHere = $invoice->insertToFlexiBee(['typDokl' => 'code:FAKTURA']);
/**
* Save to AbraFlexi and load result
*/
$resultSync = $invoice->sync();

echo json_encode($resultHere, JSON_PRETTY_PRINT);;
echo $resultSync ? 'OK' : 'Failed';
22 changes: 15 additions & 7 deletions src/AbraFlexi/Adresar.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,24 @@ public function getAnyPhoneNumber() {
$phoneNo = $numbers['tel'];
}
if (array_key_exists('kontakty', $numbers) && !empty($numbers['kontakty'])) {

// Try to use primary contact if present
foreach ($numbers['kontakty'] as $kontakt) {
if ($kontakt['primarni'] == 'true') {

if (strlen(trim($kontakt['mobil']))) {
$phoneNo = $kontakt['mobil'];
break;
}
}
if (strlen(trim($kontakt['mobil']))) {
$phoneNo = $kontakt['mobil'];
break;
} elseif (strlen(trim($kontakt['mobil']))) {
$phoneNo = $kontakt['mobil'];
break;
}

// Use first contact if no primary is set
if (is_null($phoneNo)) {
foreach ($numbers['kontakty'] as $kontakt) {
if (strlen(trim($kontakt['mobil']))) {
$phoneNo = $kontakt['mobil'];
break;
}
}
}
}
Expand Down
Loading

0 comments on commit b6d0c77

Please sign in to comment.