118 lines
3.4 KiB
PHP
Executable File
118 lines
3.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace IpSupply\QuoteIn\Api;
|
|
|
|
use IpSupply\QuoteIn\Api\Api;
|
|
|
|
class QuoteInApi extends Api
|
|
{
|
|
const HOST = 'https://api.nswteam.net';
|
|
const API_LOGIN_URL = self::HOST.'/api/login';
|
|
const API_GET_DATA_URL = self::HOST.'/api/magento/get-listwtb-by-email?';
|
|
const API_POST_DATA_QUOTE_IN = self::HOST.'/api/transferPostData';
|
|
const FILTER = '{"limit":100,"skip":0,"order":"expectedDate ASC","where":{"email":""}}';
|
|
|
|
protected $limit = 200;
|
|
protected $offset = 0;
|
|
protected $time_from = null;
|
|
protected $time_to = null;
|
|
protected $logHelper;
|
|
protected $email;
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function setLogHelper($logHelper)
|
|
{
|
|
$this->logHelper = $logHelper;
|
|
}
|
|
|
|
public function setEmail($email)
|
|
{
|
|
$this->email = $email;
|
|
}
|
|
|
|
public function increaseOffset($number) {
|
|
$this->offset = $this->offset + $number;
|
|
}
|
|
|
|
public function setTimefromAndTo($time_from, $time_to) {
|
|
$this->time_from = $time_from;
|
|
$this->time_to = $time_to;
|
|
}
|
|
|
|
public function getOffset() {
|
|
return $this->offset;
|
|
}
|
|
|
|
public function setOffset($offset) {
|
|
$this->offset = $offset;
|
|
}
|
|
|
|
public function login()
|
|
{
|
|
$response = $this->post(self::API_LOGIN_URL, array("userEmail" => "admin@apactech.io",
|
|
"password" => "work1234@ct")
|
|
);
|
|
if ($response->getStatusCode() == 200) {
|
|
$data = json_decode($response->getBody()->getContents(), true);
|
|
if (is_array($data) && array_key_exists("token", $data) ) {
|
|
$this->setToken($data["token"]);
|
|
return true;
|
|
}
|
|
}
|
|
//$this->logHelper->write(" Can not login ");
|
|
//$this->logHelper->write($response->getStatusCode());
|
|
//$this->logHelper->write($response->getBody());
|
|
return false;
|
|
}
|
|
|
|
public function saveQuoteInToERP($data) {
|
|
|
|
// $this->logHelper->write(self::API_POST_DATA_QUOTE_IN);
|
|
// $this->logHelper->write(json_encode($data));
|
|
// $this->logHelper->write(json_encode($this->getHeaders()));
|
|
$response = $this->postV2(self::API_POST_DATA_QUOTE_IN, $data);
|
|
//$this->logHelper($response->getBody()->getContents());
|
|
if ($response->getStatusCode() == 200) {
|
|
$data = json_decode($response->getBody()->getContents(), true);
|
|
if (is_array($data) && array_key_exists("Status", $data) && $data["Status"] == "OK") {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function buildParamForTime(){
|
|
if ($this->time_from != null) {
|
|
//1 year
|
|
//$year = 60*60*24*365;
|
|
$param = "&timefrom=".$this->time_from."&timeto=".$this->time_to;
|
|
return $param;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public function buildParamUrl(){
|
|
$paramUrl = json_decode(self::FILTER, true);
|
|
$paramUrl["skip"] = $this->offset*$this->limit;
|
|
$paramUrl["limit"] = $this->limit;
|
|
$paramUrl["where"]["email"] = $this->email;
|
|
|
|
return urlencode(json_encode($paramUrl));
|
|
}
|
|
|
|
public function getData($email) {
|
|
$this->setEmail($email);
|
|
//$this->logHelper->write("offset :".$this->offset);
|
|
$url = self::API_GET_DATA_URL."filter=".$this->buildParamUrl();
|
|
//$this->logHelper->write($url);
|
|
$response = $this->get(
|
|
$url
|
|
);
|
|
return $response;
|
|
}
|
|
|
|
}
|