forked from php-twinfield/twinfield
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added logic for declarations endpiont
- Loading branch information
1 parent
86a4217
commit 75b91e0
Showing
13 changed files
with
465 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield\ApiConnectors; | ||
|
||
use PhpTwinfield\Mappers\DocumentMapper; | ||
|
||
class DeclarationsApiConnector extends BaseApiConnector | ||
{ | ||
public function setOffice($officeCode): void | ||
{ | ||
$headers = $this->getConnection()->getSoapHeaders(); | ||
|
||
$this->getDeclarationService()->setSoapHeadersFromArray([ | ||
...$headers->data, | ||
'CompanyCode' => $officeCode, | ||
]); | ||
} | ||
|
||
public function declarationCount($officeCode): int | ||
{ | ||
$response = $this->getDeclarationService()->declarationCount($officeCode); | ||
|
||
return $response->numberOfVatReturns ?? 0; | ||
} | ||
|
||
public function vatReturnXbrl($documentId): string|null | ||
{ | ||
$response = $this->getDeclarationService()->vatReturnXbrl($documentId); | ||
|
||
return $response->vatReturn->any ?? null; | ||
} | ||
|
||
public function icpReturnXBrl($documentId): string|null | ||
{ | ||
$response = $this->getDeclarationService()->icpReturnXbrl($documentId); | ||
|
||
return $response->vatReturn->any ?? null; | ||
} | ||
|
||
public function summaries($officeCode): array | ||
{ | ||
// this seems redundant, but it is necessary to set the office code | ||
$this->setOffice($officeCode); | ||
|
||
$response = $this->getDeclarationService()->summaries($officeCode); | ||
|
||
if (!isset($response->vatReturn->DeclarationSummary)) { | ||
return []; | ||
} | ||
|
||
$declarations = $response->vatReturn->DeclarationSummary; | ||
|
||
// If there are multiple declarations, map them all | ||
if (is_array($declarations)) { | ||
return array_map(function ($declaration) { | ||
return DocumentMapper::map($declaration); | ||
}, $declarations); | ||
} | ||
|
||
// With XML, if there is only one declaration, it is not an array | ||
return [DocumentMapper::map($declarations)]; | ||
} | ||
|
||
public function setApproved($officeCode, $documentId): bool | ||
{ | ||
$this->setOffice($officeCode); | ||
|
||
$result = $this->getDeclarationService()->setApproved($documentId); | ||
|
||
var_dump($result); | ||
|
||
// @todo implement proper error / success handling | ||
|
||
return false; | ||
} | ||
|
||
public function setRejected($officeCode, $documentId, $reason): bool | ||
{ | ||
$this->setOffice($officeCode); | ||
|
||
$result = $this->getDeclarationService()->setRejected($documentId, $reason); | ||
|
||
var_dump($result); | ||
|
||
// @todo implement proper error / success handling | ||
|
||
return false; | ||
} | ||
|
||
public function setSent($officeCode, $documentId): bool | ||
{ | ||
$this->setOffice($officeCode); | ||
|
||
$result = $this->getDeclarationService()->setSent($documentId); | ||
|
||
var_dump($result); | ||
|
||
// @todo implement proper error / success handling | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield; | ||
|
||
class Document { | ||
private $id; | ||
private $documentCode; | ||
private $name; | ||
private $documentTimeFrame; | ||
private $status; | ||
private $assignee; | ||
private $company; | ||
|
||
public function getId() { | ||
return $this->id; | ||
} | ||
|
||
public function setId($id) { | ||
$this->id = $id; | ||
} | ||
|
||
public function getDocumentCode() { | ||
return $this->documentCode; | ||
} | ||
|
||
public function setDocumentCode($documentCode) { | ||
$this->documentCode = $documentCode; | ||
} | ||
|
||
public function getName() { | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) { | ||
$this->name = $name; | ||
} | ||
|
||
public function getDocumentTimeFrame() { | ||
return $this->documentTimeFrame; | ||
} | ||
|
||
public function setDocumentTimeFrame($documentTimeFrame) { | ||
$this->documentTimeFrame = $documentTimeFrame; | ||
} | ||
|
||
public function getStatus() { | ||
return $this->status; | ||
} | ||
|
||
public function setStatus($status) { | ||
$this->status = $status; | ||
} | ||
|
||
public function getAssignee() { | ||
return $this->assignee; | ||
} | ||
|
||
public function setAssignee($assignee) { | ||
$this->assignee = $assignee; | ||
} | ||
|
||
public function getCompany() { | ||
return $this->company; | ||
} | ||
|
||
public function setCompany($company) { | ||
$this->company = $company; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield; | ||
|
||
class DocumentAssignee { | ||
private $code; | ||
private $name; | ||
|
||
public function getCode() { | ||
return $this->code; | ||
} | ||
|
||
public function setCode($code) { | ||
$this->code = $code; | ||
} | ||
|
||
public function getName() { | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) { | ||
$this->name = $name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield; | ||
|
||
class DocumentCompany { | ||
private $code; | ||
private $name; | ||
|
||
public function getCode() { | ||
return $this->code; | ||
} | ||
|
||
public function setCode($code) { | ||
$this->code = $code; | ||
} | ||
|
||
public function getName() { | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) { | ||
$this->name = $name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield; | ||
|
||
class DocumentStatus { | ||
private $description; | ||
private $stepIndex; | ||
private $extraInformation; | ||
|
||
|
||
public function getDescription() { | ||
// 1 = Created | ||
// 2 = Modified | ||
// 3 = Sending | ||
// 4 = Error while sending | ||
// 5 = Sent | ||
// 6 = Rejected | ||
// 7 = Approved | ||
// 8 = Authorized | ||
|
||
return $this->description; | ||
} | ||
|
||
public function setDescription($description) { | ||
$this->description = $description; | ||
} | ||
|
||
public function getStepIndex() { | ||
return $this->stepIndex; | ||
} | ||
|
||
public function setStepIndex($stepIndex) { | ||
$this->stepIndex = $stepIndex; | ||
} | ||
|
||
public function getExtraInformation() { | ||
return $this->extraInformation; | ||
} | ||
|
||
public function setExtraInformation($extraInformation) { | ||
$this->extraInformation = $extraInformation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield; | ||
|
||
class DocumentTimeFrame { | ||
private $year; | ||
private $period; | ||
|
||
public function getYear() { | ||
return $this->year; | ||
} | ||
|
||
public function setYear($year) { | ||
$this->year = $year; | ||
} | ||
|
||
public function getPeriod() { | ||
return $this->period; | ||
} | ||
|
||
public function setPeriod($period) { | ||
$this->period = $period; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace PhpTwinfield\Mappers; | ||
|
||
use PhpTwinfield\Document; | ||
use PhpTwinfield\DocumentAssignee; | ||
use PhpTwinfield\DocumentCompany; | ||
use PhpTwinfield\DocumentStatus; | ||
use PhpTwinfield\DocumentTimeFrame; | ||
use stdClass; | ||
|
||
class DocumentMapper { | ||
public static function map(stdClass $data) { | ||
$document = new Document(); | ||
|
||
$document->setId($data->Id); | ||
$document->setDocumentCode($data->DocumentCode); | ||
$document->setName($data->Name); | ||
|
||
$documentTimeFrame = new DocumentTimeFrame(); | ||
$documentTimeFrame->setYear($data->DocumentTimeFrame->Year); | ||
$documentTimeFrame->setPeriod($data->DocumentTimeFrame->Period); | ||
$document->setDocumentTimeFrame($documentTimeFrame); | ||
|
||
$status = new DocumentStatus(); | ||
$status->setDescription($data->Status->Description); | ||
$status->setStepIndex($data->Status->StepIndex); | ||
$status->setExtraInformation($data->Status->ExtraInformation); | ||
$document->setStatus($status); | ||
|
||
$assignee = new DocumentAssignee(); | ||
$assignee->setCode($data->Assignee->Code); | ||
$assignee->setName($data->Assignee->Name); | ||
$document->setAssignee($assignee); | ||
|
||
$company = new DocumentCompany(); | ||
$company->setCode($data->Company->Code); | ||
$company->setName($data->Company->Name); | ||
$document->setCompany($company); | ||
|
||
return $document; | ||
} | ||
} |
Oops, something went wrong.