Skip to content
This repository was archived by the owner on Jul 29, 2020. It is now read-only.

Commit 38668b1

Browse files
committed
add link to advance tax document rewrited
1 parent 44ea3c0 commit 38668b1

1 file changed

Lines changed: 32 additions & 49 deletions

File tree

src/FlexiPeeHP/FakturaVydana.php

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -146,64 +146,47 @@ public function odpocetZDD($invoice, $odpocet = [])
146146
/**
147147
* add link to advance tax document
148148
*
149+
* @link https://www.flexibee.eu/api/dokumentace/ref/vazby-zdd/ vazby-zdd
150+
*
149151
* @param Banka|PokladniPohyb $income Income payment document
150152
*
151153
* @return boolean success
152-
*
153-
* @throws Exception
154154
*/
155155
public function vytvorVazbuZDD($income)
156156
{
157-
switch (get_class($income)) {
158-
case 'FlexiPeeHP\\Banka':
159-
$modul = 'banka';
160-
break;
161-
case 'FlexiPeeHP\\PokladniPohyb':
162-
$modul = 'pokladna';
163-
break;
164-
default :
165-
throw new \Ease\Exception(_('Unsupported $income parameter type'));
166-
}
167-
168-
$incomeId = $income->getRecordID();
169-
$myId = $this->getRecordID();
170-
171-
$headersBackup = $this->defaultHttpHeaders;
172-
173-
$this->defaultHttpHeaders['Accept'] = 'text/html';
174-
$this->setPostFields(http_build_query(['modul' => $modul,
175-
'submit' => 'OK']));
176-
$this->performRequest($myId.'/vytvor-vazbu-zdd/'.$incomeId, 'GET',
177-
'json');
178-
179-
$responseArr = explode("\n", $this->lastCurlResponse);
180-
$result = true;
181-
$message = '';
182-
foreach ($responseArr as $lineNo => $responseLine) {
183-
if (strstr($responseLine, '<ul class = "flexibee-errors">')) {
184-
$message = trim($responseArr[$lineNo + 1]);
185-
$result = false;
186-
}
187-
if (strstr($responseLine, '<div class = "alert alert-success">')) {
188-
$message = strip_tags(html_entity_decode(trim($responseArr[$lineNo
189-
+ 1])));
190-
$result = true;
191-
}
192-
}
193-
194-
if ($result === true) {
195-
$this->addStatusMessage(empty($message) ? $this->getDataValue('kod').'/vytvor-vazbu-zdd/'.$income->getRecordCode()
196-
: $message, 'success');
197-
} else {
198-
$this->addStatusMessage($this->getDataValue('kod').'/vytvor-vazbu-zdd/'.$incomeId,
199-
'warning');
200-
}
157+
$classHelper = explode('\\', get_class($income));
158+
$bondRequest = [
159+
'id' => $this->getRecordIdent(),
160+
'vytvor-vazbu-zdd' => [
161+
'uhrada' => $income->getRecordIdent(),
162+
'uhrada@type' => strtolower(end($classHelper))
163+
]
164+
];
165+
$this->insertToFlexiBee($bondRequest);
166+
return $this->lastResponseCode == 201;
167+
}
201168

202-
$this->defaultHttpHeaders = $headersBackup;
169+
/**
170+
* Remove Advance tax document bondig
171+
*
172+
* @link https://www.flexibee.eu/api/dokumentace/ref/vazby-zdd/ vazby-zdd
173+
*
174+
* @param int|string $id Invoice record identifier
175+
*
176+
* @return boolean operation success
177+
*/
178+
public function zrusVazbuZdd( $id = null )
179+
{
180+
$unbondRequest = [
181+
'id' => is_null($id) ? $this->getRecordIent() : $id ,
182+
'zrus-vazbu-zdd'
183+
];
203184

204-
return $result;
185+
$this->insertToFlexiBee($unbondRequest);
186+
return $this->lastResponseCode == 201;
205187
}
206-
188+
189+
207190
/**
208191
*
209192
* @param int $size requested of image

0 commit comments

Comments
 (0)