0

我曾将PHP 客户端库用于 Exact Online

我需要根据条件存储记录是否存在。由于记录已成功保存。但不幸的是,记录没有更新。

$customer = [
        'address'       => 'No.22/N, 91 Cross, XYZ Street, ABC Road',
        'address2'      => 'DEF',
        'city'          => 'GHI',
        'customerid'    => '999',
        'country'       => 'DE',
        'name'          => 'Nishanth',
        'zipcode'       => '123456'
];

// Create a new account
$account->AddressLine1 = $customer['address'];
$account->AddressLine2 = $customer['address2'];
$account->City = $customer['city'];
$account->Code = $customer['customerid'];
$account->Country = $customer['country'];
$account->IsSales = 'true';
$account->Name = $customer['name'];
$account->Postcode = $customer['zipcode'];
$account->Email = 'nishanth@gmail.com';
$account->Status = 'C';

从上面的代码中,根据需要从下面的代码片段更新或保存记录的条件。遵循了两种方法:

我的方法:

if($AccInfo)
{ // Update
    $AccInfo->AddressLine1 = $customer['address'];
    $AccInfo->AddressLine2 = $customer['address2'];
    $AccInfo->City = $customer['city'];
    $updateAcc = $AccInfo->update();
}
else 
{ // Save
    $savedAcc = $Accounts->save();
}

结果:

Warning: Attempt to assign property 'AddressLine1' of non-object in E:\xampp\htdocs\exact-php-client-master\example\example.php on line 506

Warning: Attempt to assign property 'AddressLine2' of non-object in E:\xampp\htdocs\exact-php-client-master\example\example.php on line 507

Warning: Attempt to assign property 'City' of non-object in E:\xampp\htdocs\exact-php-client-master\example\example.php on line 508

Fatal error: Uncaught Error: Call to a member function update() on array in E:\xampp\htdocs\exact-php-client-master\example\example.php:510 Stack trace: #0 {main} thrown in E:\..\..\exact-php-client-master\example\example.php on line 510


二方法:

if($AccInfo)
{ // Update
    $updateAcc = $Accounts->update();
}
else 
{ // Save
    $savedAcc = $Accounts->save();
}

结果:

Picqer\Financials\Exact\ApiException : Error 400: Bad Request - Error in query syntax.

我们应该如何将记录更新到 Exact Online Dashboard?

4

1 回答 1

1

最后我通过编写自定义方法解决了这个问题

$AccInfo = $Accounts->filter("Email eq 'nishanthjay@gmail.com'");

if($AccInfo)
{ // Update
    $updateAcc = $Accounts->customUpdate($AccInfo[0]->ID);
    echo '<pre>'; print_r($updateAcc);
}
else 
{ // Save
    $savedAcc = $Accounts->save();
}

我写了我自己的方法..\src\Picqer\Financials\Exact\Persistance\Storable.php

public function customUpdate($primaryKey='')
{
    $this->fill($this->update2($primaryKey));
    return $this;
}

public function update2($primaryKey='')
{
    return $this->connection()->put($this->url() . "(guid'$primaryKey')", $this->json());
}

对于确切知道如何更新到 ExactOnline 的任何人。随时欢迎您通过内置函数调用(称为update().

于 2019-04-23T12:52:45.123 回答