Skip to content

Commit

Permalink
Merge pull request #11 from LasseRafn/analysis-q1eogL
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
LasseRafn authored Mar 19, 2018
2 parents bffcd5a + 9304af7 commit f0e9255
Showing 1 changed file with 163 additions and 154 deletions.
317 changes: 163 additions & 154 deletions src/SoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,158 +8,167 @@

class SoapClient
{
public $soap;
protected $secret;
protected $agreement;

public function __construct( $agreement = '', $secret = null ) {
$this->agreement = $agreement ?? config( 'economic.agreement' );
$this->secret = $secret ?? config( 'economic.secret_token' );

$this->soap = new SoapWrapper();
$this->soap->add( 'economic', function ( Service $service ) {
$service->wsdl( 'https://api.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL' )
->trace( true )
->header( 'X', 'EconomicAppIdentifier', 'e-conomic Soap API' );
} );
}

public function auth( $agreement = null, $secret = null ) {
$agreement = $agreement ?? $this->agreement;
$secret = $secret ?? $this->secret;

$this->soap->call( 'economic.ConnectWithToken', [
'ConnectWithToken' => [
'token' => $agreement,
'appSecretToken' => $secret,
'appToken' => $secret,
],
] );

return $this;
}

public function getPayments( $toDate = null ) {
$items = $this->getAllOpenDebtorEntries()->where( 'Type', '=', 'DebtorPayment' );

if ( $toDate !== null ) {
$items = $items->where( 'Date', '<=', $toDate );
}

return $items;
}

public function postOrder( Order $order ) {
return $this->soap->call( 'economic.Order_CreateFromData', [
'Order_CreateFromData' => [
'data' => $order->format(),
],
] )->Order_CreateFromDataResult;
}

public function getAllOpenDebtorEntries() {
$openEntries = $this->soap->call( 'economic.DebtorEntry_GetAllOpenEntries' )->DebtorEntry_GetAllOpenEntriesResult;

$entries = collect( [] );

if ( ! isset( $openEntries->DebtorEntryHandle ) ) {
return $entries;
}

$openEntries = $openEntries->DebtorEntryHandle;

$handles = [];
foreach ( $openEntries as $openEntry ) {
if ( ! isset( $openEntry->SerialNumber ) ) {
continue;
}

$handles[] = [ 'SerialNumber' => $openEntry->SerialNumber ];
}

if ( count( $handles ) > 0 ) {
try {
$entryResponse = $this->soap->call( 'economic.DebtorEntry_GetDataArray', [
'DebtorEntry_GetDataArray' => [
'entityHandles' => $handles,
],
] )->DebtorEntry_GetDataArrayResult;
} catch ( \SoapFault $exception ) {
throw $exception;
}

if ( isset( $entryResponse->DebtorEntryData ) ) {
foreach ( $entryResponse->DebtorEntryData as $item ) {
$entries->push( $item );
}
}
}

return $entries;
}

public function getAllCashbooksEntries() {
$cashbooks = $this->soap->call( 'economic.CashBook_GetAll' )->CashBook_GetAllResult;

$entries = collect( [] );

if ( ! isset( $cashbooks->CashBookHandle ) ) {
return $entries;
}

$cashbooks = $cashbooks->CashBookHandle;

$handles = [];
foreach ( $cashbooks as $cashbook ) {
if ( ! isset( $cashbook->Number ) ) {
continue;
}

$handles[] = [ 'Number' => $cashbook->Number ];
}

if ( count( $handles ) > 0 ) {
try {
$cashbookResponse = $this->soap->call( 'economic.CashBook_GetDataArray', [
'CashBook_GetDataArray' => [
'entityHandles' => $handles,
],
] )->CashBook_GetDataArrayResult;
} catch ( \SoapFault $exception ) {
throw $exception;
}

if ( isset( $cashbookResponse->CashBookData ) ) {
foreach ( $cashbookResponse->CashBookData as $item ) {
$entries->push( $item );
}
}
}

return $entries;
}

public function createCahBookEntryFromData( $data ) {
return $this->soap->call( 'economic.CashBookEntry_CreateFromData', [
'CashBookEntry_CreateFromData' => [
'data' => $data,
],
] )->CashBookEntry_CreateFromDataResult;
}

public function createCashBookEntriesFromArray( $data ) {
return $this->soap->call( 'economic.CashBookEntry_CreateFromDataArray', [
'CashBookEntry_CreateFromDataArray' => [
'dataArray' => $data,
],
] )->CashBookEntry_CreateFromDataArrayResult;
}

public function createProjectsFromArray( $data ) {
return $this->soap->call( 'economic.Project_CreateFromDataArray', [
'Project_CreateFromDataArray' => [
'dataArray' => $data,
],
] )->Project_CreateFromDataArrayResult;
}
public $soap;
protected $secret;
protected $agreement;

public function __construct($agreement = '', $secret = null)
{
$this->agreement = $agreement ?? config('economic.agreement');
$this->secret = $secret ?? config('economic.secret_token');

$this->soap = new SoapWrapper();
$this->soap->add('economic', function (Service $service) {
$service->wsdl('https://api.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL')
->trace(true)
->header('X', 'EconomicAppIdentifier', 'e-conomic Soap API');
});
}

public function auth($agreement = null, $secret = null)
{
$agreement = $agreement ?? $this->agreement;
$secret = $secret ?? $this->secret;

$this->soap->call('economic.ConnectWithToken', [
'ConnectWithToken' => [
'token' => $agreement,
'appSecretToken' => $secret,
'appToken' => $secret,
],
]);

return $this;
}

public function getPayments($toDate = null)
{
$items = $this->getAllOpenDebtorEntries()->where('Type', '=', 'DebtorPayment');

if ($toDate !== null) {
$items = $items->where('Date', '<=', $toDate);
}

return $items;
}

public function postOrder(Order $order)
{
return $this->soap->call('economic.Order_CreateFromData', [
'Order_CreateFromData' => [
'data' => $order->format(),
],
])->Order_CreateFromDataResult;
}

public function getAllOpenDebtorEntries()
{
$openEntries = $this->soap->call('economic.DebtorEntry_GetAllOpenEntries')->DebtorEntry_GetAllOpenEntriesResult;

$entries = collect([]);

if (!isset($openEntries->DebtorEntryHandle)) {
return $entries;
}

$openEntries = $openEntries->DebtorEntryHandle;

$handles = [];
foreach ($openEntries as $openEntry) {
if (!isset($openEntry->SerialNumber)) {
continue;
}

$handles[] = ['SerialNumber' => $openEntry->SerialNumber];
}

if (count($handles) > 0) {
try {
$entryResponse = $this->soap->call('economic.DebtorEntry_GetDataArray', [
'DebtorEntry_GetDataArray' => [
'entityHandles' => $handles,
],
])->DebtorEntry_GetDataArrayResult;
} catch (\SoapFault $exception) {
throw $exception;
}

if (isset($entryResponse->DebtorEntryData)) {
foreach ($entryResponse->DebtorEntryData as $item) {
$entries->push($item);
}
}
}

return $entries;
}

public function getAllCashbooksEntries()
{
$cashbooks = $this->soap->call('economic.CashBook_GetAll')->CashBook_GetAllResult;

$entries = collect([]);

if (!isset($cashbooks->CashBookHandle)) {
return $entries;
}

$cashbooks = $cashbooks->CashBookHandle;

$handles = [];
foreach ($cashbooks as $cashbook) {
if (!isset($cashbook->Number)) {
continue;
}

$handles[] = ['Number' => $cashbook->Number];
}

if (count($handles) > 0) {
try {
$cashbookResponse = $this->soap->call('economic.CashBook_GetDataArray', [
'CashBook_GetDataArray' => [
'entityHandles' => $handles,
],
])->CashBook_GetDataArrayResult;
} catch (\SoapFault $exception) {
throw $exception;
}

if (isset($cashbookResponse->CashBookData)) {
foreach ($cashbookResponse->CashBookData as $item) {
$entries->push($item);
}
}
}

return $entries;
}

public function createCahBookEntryFromData($data)
{
return $this->soap->call('economic.CashBookEntry_CreateFromData', [
'CashBookEntry_CreateFromData' => [
'data' => $data,
],
])->CashBookEntry_CreateFromDataResult;
}

public function createCashBookEntriesFromArray($data)
{
return $this->soap->call('economic.CashBookEntry_CreateFromDataArray', [
'CashBookEntry_CreateFromDataArray' => [
'dataArray' => $data,
],
])->CashBookEntry_CreateFromDataArrayResult;
}

public function createProjectsFromArray($data)
{
return $this->soap->call('economic.Project_CreateFromDataArray', [
'Project_CreateFromDataArray' => [
'dataArray' => $data,
],
])->Project_CreateFromDataArrayResult;
}
}

0 comments on commit f0e9255

Please sign in to comment.