<?php
namespace App\Controller;
use App\Configs\Constants;
use App\Service\HelloService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
use Twig\Environment;
use Symfony\Component\HttpFoundation\Cookie;
class SoapApiController extends AbstractController
{
var $session;
var $twig_values;
var $respond;
var $db;
//private $wsdl = "http://flx.2bp.ru/itt/WS/api.1cws?wsdl"; //Рабочий
private $wsdl = "http://api.i-t-trade.ru:8585/itt/WS/api.1cws?wsdl"; //Рабочий
private $client;
function __construct()
{
$this->session = new Session();
$this->twig_values = new TwigValuesController();
$this->db = new DBController();
//$this->session->start();
try{
//ini_set("soap.wsdl_cache_ttl", 43200);
ini_set("soap.wsdl_cache_ttl", 43200);
try{
$this->client = new \SoapClient($this->wsdl, array('login' => "api",
'password' => "0ne@P1@1Tt_dEX"));
}catch (\Exception $e){
$this->session->set('error', $e->getMessage());
//return $this->getSoapErr($twig);
dump($e->getMessage());
exit();
}
}catch (\Exception $e){
dump($e);
exit();
}
}
function getSoapErr(Environment $twig)
{
return new Response($twig->render('flex/login.html',[
"error" => $this->session->get('error'),]
));
}
/**
* @Route("/auth")
*/
function auth(Request $request, Environment $twig){
$login = $request->request->get('login') ?? "";
$password = $request->request->get('password') ?? "";
$remember = $request->request->get('remember') ?? "off";
if($login == "" || $password == "") {
$login = "test";
$password = "test";
}
$response = $this->authentication($login, $password, "", "");
if($this->getError($response)) {
return new Response($twig->render('flex/login.html',
$this->twig_values->getTwigTemplate($request),
));
}
if(!isset($response["return"]["Token"]) || !isset($response["return"]["CustomerGuid"]))
{
return new Response($twig->render('flex/login.html',
$this->twig_values->getTwigTemplate($request),
));
}
$Token = $response["return"]["Token"];
$CustomerGUID = $response["return"]["CustomerGuid"];
$ChangePasswordAtFirstLogon = $response["return"]["ChangePasswordAtFirstLogon"];
$AccessLevel = $response["return"]["AccessLevel"] ?? 1;
if($login == "Bot0ne" || strtolower($login) == "e.panova@i-t-trade.ru"){
$AccessLevel = "admin";
}
$this->session->set("AccessLevel", $AccessLevel);
$bonus_list = $this->getBonusList($Token, $CustomerGUID);
if(isset($bonus_list["return"]["Companys"])){
if(isset($bonus_list["return"]["Companys"]["GUID"])){
$bonus_list = [$bonus_list["return"]["Companys"]];
}else{
$bonus_list = $bonus_list["return"]["Companys"];
}
$bonus_list_bool = 'true';
}else{
$bonus_list = [];
$bonus_list_bool = 'false';
}
$this->session->set("bonus_list", $bonus_list);
$this->session->set("bonus_list_bool", $bonus_list_bool);
$contact_info = $this->getContactInfo($Token, $CustomerGUID);
$persons = [];
$address = [];
if(isset($contact_info["return"]["ContactInfo"]["Person"])){
if(isset($contact_info["return"]["ContactInfo"]["Person"]["GUID"])){
$temp_contact_info[0] = $contact_info["return"]["ContactInfo"]["Person"];
$persons = $temp_contact_info;
}else{
$persons = $contact_info["return"]["ContactInfo"]["Person"];
}
}else{
$persons = [];
}
if(isset($contact_info["return"]["ContactInfo"]["Address"])){
if(isset($contact_info["return"]["ContactInfo"]["Address"]["GUID"])){
$temp_contact_info[0] = $contact_info["return"]["ContactInfo"]["Address"];
$address = $temp_contact_info;
}else{
$address = $contact_info["return"]["ContactInfo"]["Address"];
}
}else{
$address = [];
}
$contacts["Person"] = $persons;
$contacts["Address"] = $address;
$this->session->set("contact_info", $contacts);
$get_manager = $this->getManager($Token, $CustomerGUID);
if(isset($get_manager["return"]["ManagerInfo"]["GUID"])){
$temp_get_manager_info[0] = $get_manager["return"]["ManagerInfo"];
$get_manager = $temp_get_manager_info;
}else{
$get_manager = $get_manager["return"]["ManagerInfo"] ?? "false";
}
//ToDo this is a hard fix photo link
if($get_manager != "false"){
if(isset($get_manager["FIO"])){
$get_manager = [$get_manager];
}
$i = 0;
foreach ($get_manager as $manager){
$get_manager[$i]["Photo"] = str_replace("http://", "https://", $get_manager[$i]["Photo"]);
if($get_manager[$i]["Photo"] == ""){
$get_manager[$i]["Photo"] = "/img/non_img_manager.png";
}
$i++;
}
}
$this->session->set("manager_info", $get_manager);
$this->session->set("Token", $Token);
$this->session->set("Login", $login);
$this->session->set("CustomerGUID", $CustomerGUID);
$response = $this->getCompanysList($Token, $CustomerGUID);
if($this->getError($response)) {
return new Response($twig->render('flex/login.html',
$this->twig_values->getTwigTemplate($request),
));
}
$CompanysList = $response["return"]["Companys"];
if(isset($CompanysList["GUID"])){
$CompanysList = [$CompanysList];
}
$this->session->set("CompanyGUID", $CompanysList[0]["GUID"]);
$this->session->set("CompanyDescription", $CompanysList[0]["Description"]);
$this->session->set("CompanysList", $CompanysList);
$this->getCustomerMessage();
$user_db = $this->db->getOneWhereArr(["login" => $login], "users");
if($user_db == null){
$this->db->insert("users", ["login" => $login, "company_guid" => $CompanysList[0]["GUID"]]);
}else{
if($user_db["company_guid"] != null && $user_db["company_guid"] != ""){
$this->session->set("CompanyGUID", $user_db["company_guid"]);
foreach ($CompanysList as $value){
if($value["GUID"] == $user_db["company_guid"]){
$this->session->set("CompanyDescription", $value["Description"]);
}
}
}
}
$page_number = $user_db["main_page"] ?? 0;
$this->session->set("user_main_page", $page_number);
$page_name = $this->getUserMainPage($page_number);
$date = new \DateTime();
$date->modify('-1 month');
$DateBegin = $date->format('Y-m-d');
$date = new \DateTime();
$DateEnd = $date->format('Y-m-d');
$delivery = $this->getCustomerAttributes($Token, $CustomerGUID);
if(isset($delivery["return"]["DeliveryLimit"])){
$this->session->set("DeliveryLimit", $delivery["return"]["DeliveryLimit"]);
//$this->session->set("DeliveryLimit", ["FreeDeliveryMin" => "500", "DeliveryPrice" => "500"]);
}else{
$this->session->set("DeliveryLimit", ["FreeDeliveryMin" => "0", "DeliveryPrice" => "0"]);
}
$response = $this->getAccountingInformation($Token, $CustomerGUID, $CompanysList[0]["GUID"], $DateBegin, $DateEnd);
$this->session->set("SumDebit", 0);
if(isset($response["return"]["AccountingInformation"]["AccountingInformationCompanys"])){
if(isset($response["return"]["AccountingInformation"]["AccountingInformationCompanys"]["DebtAtTheEnd"])){
$account = [$response["return"]["AccountingInformation"]["AccountingInformationCompanys"]];
}else{
$account = $response["return"]["AccountingInformation"]["AccountingInformationCompanys"];
}
foreach ($account as $acc){
if($acc["СompanyGUID"] == $CompanysList[0]["GUID"]){
$this->session->set("SumDebit", $acc["DebtAtTheEnd"]);
}
}
}
// return new Response($twig->render('flex/index.html', $this->twig_values->getTwigTemplate($request) +
// ["page_name" => $page_name]
// ));
$account_info = $this->getLoginProperties($Token);
$LoginProperties = $account_info["return"]["LoginProperties"] ?? false;
$this->session->set("LoginProperties", $LoginProperties);
if($ChangePasswordAtFirstLogon){
$response = new Response($twig->render('flex/change_pass_first.html', $this->twig_values->getTwigTemplate($request) +
["page_name" => $page_name, "password" => $password, "Reg" => ["status" => "true", "reg" => ""]]
));
if($remember == "on"){
$response->headers->setCookie(Cookie::create('login', $login));
$response->headers->setCookie(Cookie::create('password', $password));
}
return $response;
}else{
$response = $this->redirect("/".$page_name, 301);
if($remember == "on"){
$response->headers->setCookie(Cookie::create('login', $login));
$response->headers->setCookie(Cookie::create('password', $password));
}
return $response;
}
return new Response($twig->render('flex/'.$page_name.'.html',
$this->twig_values->getTwigTemplate($request)
));
}
/**
* @Route("/auth_demo", name="demo")
*/
function auth_demo(Request $request, Environment $twig){
$login = Constants::DEMO_LOGIN;
$password = Constants::DEMO_PASSWORD;
$response = $this->authentication($login, $password, "", "");
if($this->getError($response)) {
return new Response($twig->render('flex/login.html',
$this->twig_values->getTwigTemplate($request),
));
}
if(!isset($response["return"]["Token"]) || !isset($response["return"]["CustomerGuid"]))
{
return new Response($twig->render('flex/login.html',
$this->twig_values->getTwigTemplate($request),
));
}
$Token = $response["return"]["Token"];
$CustomerGUID = $response["return"]["CustomerGuid"];
$ChangePasswordAtFirstLogon = $response["return"]["ChangePasswordAtFirstLogon"];
$AccessLevel = "demo";
$this->session->set("AccessLevel", $AccessLevel);
$bonus_list = $this->getBonusList($Token, $CustomerGUID);
if(isset($bonus_list["return"]["Companys"])){
if(isset($bonus_list["return"]["Companys"]["GUID"])){
$temp_bonus_list[0] = $bonus_list["return"]["Companys"];
$bonus_list = $temp_bonus_list;
}else{
$bonus_list = $bonus_list["return"]["Companys"];
}
}else{
$bonus_list = [];
}
$this->session->set("bonus_list", $bonus_list);
$contact_info = $this->getContactInfo($Token, $CustomerGUID);
$persons = [];
$address = [];
if(isset($contact_info["return"]["ContactInfo"]["Person"])){
if(isset($contact_info["return"]["ContactInfo"]["Person"]["GUID"])){
$temp_contact_info[0] = $contact_info["return"]["ContactInfo"]["Person"];
$persons = $temp_contact_info;
}else{
$persons = $contact_info["return"]["ContactInfo"]["Person"];
}
}else{
$persons = [];
}
if(isset($contact_info["return"]["ContactInfo"]["Address"])){
if(isset($contact_info["return"]["ContactInfo"]["Address"]["GUID"])){
$temp_contact_info[0] = $contact_info["return"]["ContactInfo"]["Address"];
$address = $temp_contact_info;
}else{
$address = $contact_info["return"]["ContactInfo"]["Address"];
}
}else{
$address = [];
}
$contacts["Person"] = $persons;
$contacts["Address"] = $address;
$this->session->set("contact_info", $contacts);
$get_manager = [];
$get_manager[0] = [];
$get_manager[0]["Photo"] = "/img/boss.png";
$get_manager[0]["FIO"] = "demo";
$get_manager[0]["Phone"] = "demo";
$get_manager[0]["Mail"] = "demo";
$get_manager[0]["ChatID"] = "demo";
$this->session->set("manager_info", $get_manager);
$this->session->set("Token", $Token);
$this->session->set("Login", $login);
$this->session->set("CustomerGUID", $CustomerGUID);
$response = $this->getCompanysList($Token, $CustomerGUID);
if($this->getError($response)) {
return new Response($twig->render('flex/login.html',
$this->twig_values->getTwigTemplate($request),
));
}
$CompanysList = $response["return"]["Companys"];
if(isset($CompanysList["GUID"])){
$arr[0]= $CompanysList;
$CompanysList = $arr;
}
$this->session->set("CompanyGUID", $CompanysList[0]["GUID"]);
$this->session->set("CompanyDescription", $CompanysList[0]["Description"]);
$this->session->set("CompanysList", $CompanysList);
$this->getCustomerMessage();
$user_db = $this->db->getOneWhereArr(["login" => $login], "users");
if($user_db == null){
$this->db->insert("users", ["login" => $login]);
}
$page_number = $user_db["main_page"] ?? 0;
$this->session->set("user_main_page", $page_number);
$page_name = $this->getUserMainPage($page_number);
$date = new \DateTime();
$date->modify('-1 month');
$DateBegin = $date->format('Y-m-d');
$date = new \DateTime();
$DateEnd = $date->format('Y-m-d');
//$response = $this->getCustomerAttributes($Token, $CustomerGUID);
$response = $this->getAccountingInformation($Token, $CustomerGUID, $CompanysList[0]["GUID"], $DateBegin, $DateEnd);
$this->session->set("SumDebit", 0);
if(isset($response["return"]["AccountingInformation"]["AccountingInformationCompanys"])){
if(isset($response["return"]["AccountingInformation"]["AccountingInformationCompanys"]["DebtAtTheEnd"])){
$account = [$response["return"]["AccountingInformation"]["AccountingInformationCompanys"]];
}else{
$account = $response["return"]["AccountingInformation"]["AccountingInformationCompanys"];
}
foreach ($account as $acc){
if($acc["СompanyGUID"] == $CompanysList[0]["GUID"]){
$this->session->set("SumDebit", $acc["DebtAtTheEnd"]);
}
}
}
// return new Response($twig->render('flex/index.html', $this->twig_values->getTwigTemplate($request) +
// ["page_name" => $page_name]
// ));
$account_info = $this->getLoginProperties($Token);
$LoginProperties = $account_info["return"]["LoginProperties"] ?? false;
$this->session->set("LoginProperties", $LoginProperties);
if($ChangePasswordAtFirstLogon){
return new Response($twig->render('flex/change_pass_first.html', $this->twig_values->getTwigTemplate($request) +
["page_name" => $page_name, "password" => $password, "Reg" => ["status" => "true", "reg" => ""]]
));
}else{
return $this->redirect("/".$page_name, 301);
}
return new Response($twig->render('flex/'.$page_name.'.html',
$this->twig_values->getTwigTemplate($request)
));
}
function getUserMainPage($page_number = 0){
$page_name = "";
switch ($page_number){
case 0:
$page_name = "";
break;
case 1:
$page_name = "catalog";
break;
case 2:
$page_name = "news";
break;
default:
break;
}
return $page_name;
}
/**
* @Route("/soap")
*/
function getRequest(Request $request, Environment $twig){
$method = $request->request->get('method');
switch ($method){
case "getItemList":
$CompanyGUID = $this->session->get("CompanyGUID");
$Token = $this->session->get('Token');
$CustomerGUID = $this->session->get("CustomerGUID");
$OnlyAvailable = $request->request->get("OnlyAvailable") ?? 0;
$GroupGUID = $request->request->get('GUID') ?? "";
$this->session->set("search_guid", $GroupGUID);
$this->session->set("Checked", $request->request->get("Checked"));
$Property = $request->request->get('Property') ?? "";
$search_select = $request->request->get('search_select') ?? "Description";
$click = $request->request->get('click') ?? "group";
$search_item_guid = $request->request->get('search_item_guid') ?? "";
$last_page = $request->request->get('last_page') ?? 1;
if($last_page < 1){
$last_page = 1;
}
$VendorGUID = $request->request->get('VendorGUID') ?? "";
$VendorGUIDList = "";
$Code = "";
$Description = $request->request->get('Description') ?? "";
$Description = trim($Description);
if($Description == "" && $VendorGUID == ""){
$click = "group";
}
$PartNumber = "";
$NumberOfItems = $request->request->get('NumberOfItems') ?? 20;
if($NumberOfItems == ""){
$NumberOfItems = 20;
}
$Offset = ($last_page - 1) * $NumberOfItems;
$price_range = $request->request->get('price_range') ?? "500 ₽ - 1500 ₽";
$price_range = str_replace(" ", "", $price_range);
$price_range = str_replace("₽", "", $price_range);
$price_range = explode("-", $price_range);
if($click == "search"){
$price_range[0] = 0;
$price_range[1] = 1000000000;
//$price_range = [];
}
$Sorting = $request->request->get('Sorting') ?? "ASC_Description";
$sort_arr = explode("_", $Sorting);
$sort_method = $sort_arr[0];
$sort_field = $sort_arr[1];
$FoundProdsCount = 0;
//$vendor_list = [];
$elastic = new ElasticController();
if($GroupGUID != ""){
$group_guids = $elastic->get_doc("group_tree", $GroupGUID);
if(isset($group_guids["_source"]["GUID"])){
$group_guids = $group_guids["_source"]["GUID"];
}else{
$group_guids = $GroupGUID;
}
}else{
$group_guids = $GroupGUID;
}
// if($sort_field == "Description"){
// $sort_field = "Description.key_word";
// }
if ($search_select != "All" && $Description != ""){
$sort_field = $search_select;
}
$sort = [$sort_field => $sort_method];
if($click == "search"){
$sort = [];
}
// $Property = [];
// $Property["GUIDS"] = ["57f85d51-c875-11eb-8156-001b21bc2180"];
$query = [];
$query["bool"] = [];
if($click == "search"){
$query["bool"]["minimum_should_match"] = 1;
}
$query["bool"]["must"] = [];
$query["bool"]["filter"] = [];
$query["bool"]["should"] = [];
if($group_guids != ""){
//$query["bool"]["must"][0] = ["terms" => ["GUIDGroup" => $group_guids]];
array_push($query["bool"]["must"], ["terms" => ["GUIDGroup" => $group_guids]]);
}
if($VendorGUID != ""){
array_push($query["bool"]["must"], ["term" => ["VendorGUID" => $VendorGUID]]);
}
if($search_item_guid != ""){
array_push($query["bool"]["must"], ["term" => ["GUID" => $search_item_guid]]);
}
if($Description != ""){
//$query["bool"]["must"][1] = ["term" => [$search_select => $Description]];
if($search_select != "All"){
array_push($query["bool"]["must"], ["term" => [$search_select => $Description]]);
}else{
// array_push($query["bool"]["must"], ["term" => ["Description" => $Description,
// "Code" => $Description, "PartNumber" => $Description]]);
// array_push($query["bool"]["must"], ["multi_match" => ["query" => $Description,
// "fields" => ["Description", "Code", "PartNumber"]]]);
array_push($query["bool"]["should"], ["term" => ["Description2" => $Description]]);
array_push($query["bool"]["should"], ["term" => ["Code" => $Description]]);
array_push($query["bool"]["should"], ["term" => ["PartNumber" => $Description]]);
}
}
if($OnlyAvailable > 0){
$query["bool"]["must_not"] = ["term" => ["Available" => 0]];
}
// if($Description != ""){
// $query = [
// "bool" => [
// "must" => [
// [
// "terms" => [
// "GUIDGroup" => $group_guids
// ],
// ],
// [
// "range" => [
// "Price" => [
// "gte" => floatval($price_range[0]),
// "lte" => floatval($price_range[1])
// ]
// ]
// ]
//
// ],
// ],
// ];
// }else{
// $query = [
// "bool" => [
// "must" => [
// [
// "terms" => [
// "GUIDGroup" => $group_guids
// ],
// ],
// [
// "range" => [
// "Price" => [
// "gte" => floatval($price_range[0]),
// "lte" => floatval($price_range[1])
// ]
// ]
// ]
//
// ],
// ],
// ];
// }
if($Property != ""){
$query = [
"nested" => [
"path" => "Property",
"query" => [
"bool" => [
"must" => [
"terms" => [
"Property.SpecificationGUID" => $Property,
],
],
],
],
],
];
}
// $query["nested"]["query"]["bool"]["must"][3] = ["term" => ["Property.SpecificationGUID" => "57f85d51-c875-11eb-8156-001b21bc2180"]];
// if($click !== "group" && $click == "All" && $Description !== ""){
// $elastic_result = $elastic->search_doc_query_string("item_tree", "*".$Description."*",
// "Description2", 0, $NumberOfItems);
// dump($elastic_result);
// }else{
// $elastic_result = $elastic->search_doc_custom("item_tree", $query, $sort, $Offset, $NumberOfItems);
// dump($elastic_result);
// }
if($search_select == "All"){
$fields = ["Description2", "Code", "PartNumber"];
}else{
if($search_select == "Description"){
$fields = [$search_select."2"];
}else{
$fields = [$search_select];
}
}
if($Description == ""){
// $elastic_result = $elastic->search_doc_query_string("item_tree", addslashes("*".$Description."*"),
// $search_select, $Offset, $NumberOfItems, $sort);
$aggs = $elastic->search_doc_custom("item_tree", $query, $sort, $Offset,
$NumberOfItems);
if(isset($aggs["aggregations"]["max_price"]["value"]) &&
$aggs["aggregations"]["max_price"]["value"] != null){
$max_price = intval($aggs["aggregations"]["max_price"]["value"]) + 1;
}else{
$max_price = 25000;
}
array_push($query["bool"]["must"], ["range" => ["Price" => [
"gte" => floatval($price_range[0]),
"lte" => floatval($price_range[1])
]]]);
$elastic_result = $elastic->search_doc_custom("item_tree", $query, $sort, $Offset,
$NumberOfItems);
}else{
$aggs = $elastic->search_doc_query_string_free("item_tree", $group_guids, $fields,
$Description, [], $VendorGUID, $sort, $Offset, $NumberOfItems, $OnlyAvailable);
if(isset($aggs["aggregations"]["max_price"]["value"]) &&
$aggs["aggregations"]["max_price"]["value"] != null){
$max_price = ceil($aggs["aggregations"]["max_price"]["value"]) + 1;
}else{
$max_price = 25000;
}
$elastic_result = $elastic->search_doc_query_string_free("item_tree", $group_guids, $fields,
$Description, $price_range, $VendorGUID, $sort, $Offset, $NumberOfItems, $OnlyAvailable);
//$elastic_result = $elastic->search_doc_custom("item_tree", $query, $sort, $Offset, $NumberOfItems);
}
//Поиск
// if($Description == ""){
// $group_guids = $elastic->get_doc("group_tree", $GroupGUID);
// if(isset($group_guids["_source"]["GUID"])){
// //$vendor_list = $group_guids["_source"]["Vendors"];
// $group_guids = $group_guids["_source"]["GUID"];
// $elastic_result = $elastic->search_doc_terms("item_tree", $group_guids, "GUIDGroup", $Offset, $NumberOfItems);
// }else{
// $elastic_result = $elastic->search_doc_term("item_tree", $GroupGUID, "GUIDGroup", $Offset, $NumberOfItems);
// }
// }else{
// $elastic_result = $elastic->search_doc_query_string("item_tree", "*".$Description."*", "Description", $Offset, $NumberOfItems);
// }
$total_count = $elastic_result["hits"]["total"]["value"] ?? 0;
if($total_count > 0){
$temp_items = array_column($elastic_result["hits"]["hits"], "_source");
$ItemGuidList = array_column($temp_items, "GUID");
$Items_source = array_column($temp_items, "AdditionalItemGUID", "GUID");
$ItemImagesList = array_column($temp_items, "Images", "GUID");
$ItemList = $this->getItems($Token, $CompanyGUID, $CustomerGUID, $ItemGuidList);
//$this->getError($ItemList);
if(isset($ItemList["return"]["Items"]))
{
if(isset($ItemList["return"]["Items"]["GUID"]))
{
$ItemList["return"]["Items"] = [$ItemList["return"]["Items"]];
}
$ItemList = $ItemList["return"]["Items"];
$ItemList = array_column($ItemList, null, "GUID");
//Сортировка
foreach ($ItemGuidList as $k=>$v) {
if(!isset($ItemList[$v])){
continue;
}
$ItemGuidList[$k] = $ItemList[$v];
$ItemGuidList[$k]["Images"] = [];
if(isset($ItemImagesList[$v])){
$ItemGuidList[$k]["Images"] = $ItemImagesList[$v];
}
$ItemGuidList[$k]["AdditionalItemGUID"] = [];
$ItemGuidList[$k]["AdditionalItems"] = [];
if(isset($Items_source[$v]) && $Items_source[$v] != []){
$ItemGuidList[$k]["AdditionalItemGUID"] = $Items_source[$v];
$elastic_ad_item = $this->getItems($Token,
$CompanyGUID, $CustomerGUID, $ItemGuidList[$k]["AdditionalItemGUID"]);
if(isset($elastic_ad_item["return"]["Items"])) {
if(isset($elastic_ad_item["return"]["Items"]["GUID"])){
$elastic_ad_item = [$elastic_ad_item["return"]["Items"]];
}else{
$elastic_ad_item = $elastic_ad_item["return"]["Items"];
}
$elastic_ad_item[1] = $elastic_ad_item[0];
$elastic_ad_item[2] = $elastic_ad_item[0];
}else{
$elastic_ad_item = [];
}
$ItemGuidList[$k]["AdditionalItems"] = $elastic_ad_item;
// foreach ($Items_source[$v] as $ad_item){
// dump($ad_item);
// $elastic_ad_item = $elastic->get_doc("item_tree", $ad_item);
// dump($elastic_ad_item);
// if(isset($elastic_ad_item["_source"])){
// $ItemGuidList[$k]["AdditionalItems"][$ad_item] = $elastic_ad_item["_source"];
// }
// }
}
// if($ItemGuidList[$k]["AdditionalItems"] == []){
// $ItemGuidList[$k]["AdditionalItems"] = [$ItemGuidList[$k]];
// }
$ItemGuidList[$k]["countAdditionalItems"] = count($ItemGuidList[$k]["AdditionalItems"]);
}
$ItemList = $ItemGuidList;
$FoundProdsCount = $total_count;
$pagination["max_item"] = $NumberOfItems;
$pagination["last_page"] = $last_page;
$pagination["all_page"] = round($FoundProdsCount / $pagination["max_item"]) ?? 1;
$pagination["arr_page"] = [$pagination["last_page"] - 1, $pagination["last_page"], $pagination["all_page"] - 1, $pagination["all_page"]];
//Разрезать массив
//$ItemList = array_slice($ItemList, ($pagination["last_page"] - 1)*$NumberOfItems, $NumberOfItems);
}else{
return new Response($twig->render('flex/ajax/products_table.html', $this->twig_values->getTwigTemplate($request)+[
"error" => $this->session->get('error'),
"ItemList" => $ItemList,
"CountItemList" => count($ItemList),
"GroupGUID" => $GroupGUID,
"PageTitle" => Constants::SITENAME,
"MaxPrice" => $max_price,
"FoundProdsCount" => $FoundProdsCount,
"Checked" => $request->request->get('Checked'),
"search_item_guid" => $search_item_guid,
"search_vendor_guid" => "",
"search_vendor_name" => "",
]));
}
}else{
$ItemList = [];
return new Response($twig->render('flex/ajax/products_table.html', $this->twig_values->getTwigTemplate($request)+[
"error" => $this->session->get('error'),
"ItemList" => [$ItemList],
"CountItemList" => count($ItemList),
"GroupGUID" => $GroupGUID,
"PageTitle" => Constants::SITENAME,
"MaxPrice" => $max_price,
"FoundProdsCount" => $FoundProdsCount,
"Checked" => $request->request->get('Checked'),
"search_item_guid" => $search_item_guid,
"search_vendor_guid" => "",
"search_vendor_name" => "",
]));
$ItemList = $this->getItemList($Token, $CompanyGUID, $CustomerGUID, $OnlyAvailable, $GroupGUID, $VendorGUIDList,
$Code, $Description, $PartNumber, $NumberOfItems, $Offset, $Sorting);
$this->getError($ItemList);
if(isset($ItemList["return"]["Items"]))
{
// if(isset($ItemList["return"]["Items"]["GUID"]))
// {
// $array[0] = $ItemList["return"]["Items"];
// $ItemList["return"]["Items"] = $array;
// }
//
// $ItemList = $ItemList["return"]["Items"];
// $FoundProdsCount = count($ItemList) ?? 0;
//
// $pagination["max_item"] = $NumberOfItems;
// $pagination["last_page"] = $last_page;
// $pagination["all_page"] = round($FoundProdsCount / $pagination["max_item"]) ?? 1;
// $pagination["arr_page"] = [$pagination["last_page"] - 1, $pagination["last_page"], $pagination["all_page"] - 1, $pagination["all_page"]];
//
// //Разрезать массив
// $ItemList = array_slice($ItemList, ($pagination["last_page"] - 1)*$NumberOfItems, $NumberOfItems);
return new Response($twig->render('flex/ajax/products_table.html', $this->twig_values->getTwigTemplate($request)+[
"error" => $this->session->get('error'),
"ItemList" => $ItemList,
"CountItemList" => count($ItemList),
"GroupGUID" => $GroupGUID,
"PageTitle" => Constants::SITENAME,
"MaxPrice" => $max_price,
"FoundProdsCount" => $FoundProdsCount,
"Checked" => $request->request->get('Checked'),
"search_item_guid" => $search_item_guid,
"search_vendor_guid" => "",
"search_vendor_name" => "",
]));
}
else
{
return new Response($twig->render('flex/ajax/products_table.html', $this->twig_values->getTwigTemplate($request)+[
"error" => $this->session->get('error'),
"ItemList" => $ItemList,
"CountItemList" => count($ItemList),
"GroupGUID" => $GroupGUID,
"PageTitle" => Constants::SITENAME,
"MaxPrice" => $max_price,
"FoundProdsCount" => $FoundProdsCount,
"Checked" => $request->request->get('Checked'),
"search_item_guid" => $search_item_guid,
"search_vendor_guid" => "",
"search_vendor_name" => "",
]));
}
}
return new Response($twig->render('flex/ajax/products_table.html', $this->twig_values->getTwigTemplate($request)+[
"error" => $this->session->get('error'),
"ItemList" => $ItemList,
"CountItemList" => count($ItemList),
"pagination" => $pagination,
"GroupGUID" => $GroupGUID,
"MaxPrice" => $max_price,
"PageTitle" => Constants::SITENAME,
"FoundProdsCount" => $FoundProdsCount,
"Checked" => $request->request->get('Checked'),
"search_item_guid" => $search_item_guid,
"search_vendor_guid" => "",
"search_vendor_name" => "",
]));
break;
default:
if ($request->isXMLHttpRequest()) {
$parametersAsArray = [];
if ($content = $request->getContent()) {
$parametersAsArray = json_decode($content, true);
}
}
return new Response($request->getContent());
}
}
/**
* @Route ("/get_manager", name="get_manager")
*/
function get_manager(Environment $twig, Request $request){
$AccessLevel = $this->session->get("AccessLevel");
if($AccessLevel === "demo"){
$this->respond["status"] = "false";
$this->respond["error"] = "У демо-доступа ограничены права";
return new Response($twig->render('flex/respond.html', ["Respond" => $this->getRespond()]));
}
$Token = $this->session->get('Token');
$CustomerGUID = $this->session->get("CustomerGUID");
$result = $this->getManager($Token, $CustomerGUID);
$this->respond["status"] = "true";
$this->respond["result"] = $result;
return new Response($twig->render('flex/respond.html', ["Respond" => $this->getRespond()]));
}
/**
* @Route ("/get_deadline", name="get_deadline")
*/
function get_deadline(Environment $twig, Request $request){
$Token = $this->session->get('Token');
$CustomerGUID = $this->session->get("CustomerGUID");
$dead_pop = $this->session->get("dead_pop") ?? "false";
$this->respond["dead_pop"] = "false";
$result = $this->getApprovingDeadLine($Token, $CustomerGUID);
if(isset($result["return"]["DeadLineTS"])){
$this->respond["status"] = "true";
$date_end = new \DateTime();
$date_end->setTimestamp($result["return"]["DeadLineTS"]);
$date1 = date_create($date_end->format("Y-m-d H:i:s"));
$date_now = new \DateTime();
$date2 = date_create($date_now->format("Y-m-d H:i:s"));
if($date2<$date1) {
$diff = date_diff($date1,$date2);
$this->respond["result"] = ["day" => $diff->d, "hour" => $diff->h, "minutes" => $diff->i];
if($this->respond["result"]["day"] == "0" && $this->respond["result"]["hour"] == "0" && $this->respond["result"]["minutes"] <= "30"){
if($dead_pop == "false"){
$this->session->set("dead_pop", "true");
$this->respond["dead_pop"] = "true";
}else{
$this->respond["dead_pop"] = "false";
}
}else{
$this->respond["dead_pop"] = "false";
}
}else{
$this->respond["result"] = [ "finished" => "true" ];
}
}else{
$this->respond["status"] = "false";
$this->respond["result"] = ["day" => "0", "hour" => "0", "minutes" => "00"];
}
// $this->respond["result"]["day"] = "0";
// $this->respond["result"]["hour"] = "0";
// $this->respond["result"]["minutes"] = "29";
return new Response($twig->render('flex/respond.html', ["Respond" => $this->getRespond()]));
}
/**
* @Route ("/get_delivery_dates", name="get_delivery_dates")
*/
function get_delivery_dates(Environment $twig, Request $request){
$Token = $this->session->get('Token');
$ShippingAddress = $request->request->get("ShippingAddress") ?? ["GUID" => "", "Address" => ""];
$result = $this->getDeliveryDates($Token, $ShippingAddress);
if(isset($result['return']["Error"]['ErrorCode']) && $result['return']["Error"]['ErrorCode'] != 0) {
$this->respond["status"] = "false";
} else {
if(isset($result['return']['DeliveryDates']['Lines'])){
if(isset($result['return']['DeliveryDates']['Lines']['Data'])){
$result['return']['DeliveryDates']['Lines'] = [$result['return']['DeliveryDates']['Lines']];
}
$this->respond['Lines'] = $result['return']['DeliveryDates']['Lines'];
$this->respond["status"] = "true";
}else{
$this->respond["status"] = "false";
}
}
return new Response($twig->render('flex/ajax/delivery_date.html',
$this->twig_values->getTwigTemplate($request) + ["Dates" => $this->respond]));
// return new Response($twig->render('flex/respond.html', ["Respond" => $this->getRespond()]));
}
function getBonusList($Token, $CustomerGUID){
try{
$name = "GetBonusList";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getDeliveryDates($Token, $ShippingAddress){
try{
$name = "GetDeliveryDates";
$params = ["Token" => $Token, "ShippingAdress" => $ShippingAddress];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function updateOrder($Token, $Order, $CompanyGUID, $CustomerGUID)
{
try{
$name = "UpdateOrder";
$params = ["Token" => $Token, "Order" => $Order, "CustomerGUID" => $CustomerGUID, "CompanyGUID" => $CompanyGUID];
// var_dump($params);
// dump($params);
$response = $this->soapCall($name, $params);
//var_dump($response);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getOrder($Token, $GUID)
{
try{
$name = "GetOrder";
$params = ["Token" => $Token, "OrderGUID" => $GUID];
// var_dump($params);
$response = $this->soapCall($name, $params);
// var_dump($response);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getWishList($Token, $CustomerGUID, $GUID)
{
try{
$name = "GetWishList";
$params = ["Token" => $Token, "WishListGUID" => $GUID, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function updateWishList($Token, $CustomerGUID, $CompanyGUID, $WishList, $GUID = "")
{
try{
$name = "UpdateWishList";
$params = ["Token" => $Token, "WishList" => $WishList, "CustomerGUID" => $CustomerGUID,
"CompanyGUID" => $CompanyGUID, "GUID" => $GUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getItemList($Token, $CompanyGUID, $CustomerGUID, $OnlyAvailable, $GroupGUID, $VendorGUIDList, $Code,
$Description, $PartNumber, $NumberOfItems, $Offset, $Sorting)
{
try{
$name = "GetItemListVersion2";
$params = ["Token" => $Token, "СompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"OnlyAvailable" => $OnlyAvailable, "GroupGUID" => $GroupGUID, "VendorGUIDList" => $VendorGUIDList,
"Code" => $Code, "Description" => $Description, "PartNumber" => $PartNumber,
"NumberOfItems" => $NumberOfItems, "Offset" => $Offset, "Sorting" => $Sorting];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getItem($Token, $CompanyGUID, $CustomerGUID, $ItemGUID)
{
try{
$name = "GetItem";
$params = ["Token" => $Token, "СompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"ItemGUID" => $ItemGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getItems($Token, $CompanyGUID, $CustomerGUID, $ItemGuidList)
{
try{
$name = "GetItems";
$params = ["Token" => $Token, "СompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"ItemGuidList" => $ItemGuidList];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getBoundedItems($Token, $CompanyGUID, $CustomerGUID){
try{
$name = "GetBoundedItems";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "CompanyGUID" => $CompanyGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getBundles($Token){
try{
$name = "GetBundles";
$params = ["Token" => $Token];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getItemsSpecification($Token, $ItemGuidList)
{
try{
$name = "GetItemsSpecification";
$params = ["Token" => $Token, "ItemGuidList" => $ItemGuidList];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getCustomerMessages($Token, $CustomerGUID, $OnlyNew = 0)
{
try{
$name = "GetCustomerMessages";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "OnlyNew" => $OnlyNew];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getSpecificationList($Token)
{
try{
$name = "GetSpecificationList";
$params = ["Token" => $Token];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getLoginProperties($Token)
{
try{
$name = "GetLoginProperties";
$params = ["Token" => $Token];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function setLoginProperties($Token, $LoginProperties)
{
try{
$name = "SetLoginProperties";
$params = ["Token" => $Token, "LoginProperties" => $LoginProperties];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getApprovingDeadLine($Token, $CustomerGUID)
{
try{
$name = "GetApprovingDeadLine";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function resetPassword($Login, $Mail)
{
try{
$name = "ResetPassword";
$params = ["Login" => $Login, "Mail" => $Mail];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getPricesDefinition($Token, $CustomerGUID)
{
try{
$name = "GetPricesDefinition";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function itemsInWarranty($Token, $CustomerGUID)
{
try{
$name = "ItemsInWarranty";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function setContactInfo($Token, $ContactPerson)
{
try{
$name = "SetContactInfo";
$params = ["Token" => $Token, "ContactPerson" => $ContactPerson];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getPicturesList($Token, $ItemGUID)
{
try{
$name = "GetPicturesList";
$params = ["Token" => $Token, "ItemGUID" => $ItemGUID];
$response = $this->soapCall($name, $params);
//$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getOrderList($Token, $CustomerGUID, $CompanyGUID, $FillOrderLines, $Mode, $DateBegin, $DateEnd,
$DeletionMark, $OrderStatusForCustomer, $ModeForCustomer)
{
try{
$name = "GetOrderList";
$params = ["Token" => $Token, "CompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"Mode" => $Mode, "DateBegin" => $DateBegin, "DateEnd" => $DateEnd,
"FillOrderLines" => $FillOrderLines, "DeletionMark" => $DeletionMark,
"OrderStatusForCustomer" => intval($OrderStatusForCustomer), "ModeForCustomer" => intval($ModeForCustomer)];
// var_dump($params);
// die(0);
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getFilteredOrderList($Token, $CustomerGUID, $CompanyGUID, $FillOrderLines, $Mode, $DateBegin, $DateEnd,
$DeletionMark, $OrderStatusForCustomer, $ModeForCustomer, $NumberString, $GoodsString)
{
$order_status = ["1" => "New", "2" => "Reserved", "3" => "ReservedPartly", "4" => "NotAvailable",
"5" => "WaitingForShipment", "6" => "Shipped", "7" => "Canceled", "8" => "Confirmed"];
$order_status = $order_status[$OrderStatusForCustomer] ?? "All";
try{
$name = "GetFilteredOrderList";
$params = ["Token" => $Token, "CompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"Mode" => $Mode, "DateBegin" => $DateBegin, "DateEnd" => $DateEnd,
"FillOrderLines" => $FillOrderLines, "DeletionMark" => $DeletionMark,
"ModeForCustomer" => intval($ModeForCustomer), "NumberString" => $NumberString,
"GoodsString" => $GoodsString];
if($order_status != "All"){
$params["Status"] = $order_status;
}else{
$params["Status"] = "ALL";
}
// var_dump($params);
// die(0);
$response = $this->soapCall($name, $params);
// var_dump($response);
// die(0);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getAccountingInformation($Token, $CustomerGUID, $CompanyGUID, $DateBegin, $DateEnd)
{
try{
$name = "GetAccountingInformation";
$params = ["Token" => $Token, "CompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd,];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getBalance($Token, $CustomerGUID, $CompanyGUID, $DateBegin, $DateEnd)
{
try{
$name = "GetBalance";
$params = ["Token" => $Token, "CompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd,];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getShipmentsList($Token, $CustomerGUID, $CompanyGUID, $FillOrderLines, $DateBegin, $DateEnd,
$DeletionMark)
{
try{
$name = "GetShipmentsList";
$params = ["Token" => $Token, "CompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd,
"FillOrderLines" => $FillOrderLines, "DeletionMark" => $DeletionMark,];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getFilteredShipmentsList($Token, $CustomerGUID, $CompanyGUID, $FillOrderLines, $DateBegin, $DateEnd,
$DeletionMark, $NumberString, $GoodsString)
{
try{
$name = "GetFilteredShipmentsList";
$params = ["Token" => $Token, "CompanyGUID" => $CompanyGUID, "CustomerGUID" => $CustomerGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd,
"FillOrderLines" => $FillOrderLines, "DeletionMark" => $DeletionMark,
"NumberString" => $NumberString, "GoodsString" => $GoodsString];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getReturnList2($Token, $CustomerGUID, $DateBegin, $DateEnd,
$WithLines = 1)
{
try{
$name = "GetReturnList2";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd, "WithLines" => $WithLines,];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getReturnPrintForms($Token, $ReturnGUID, $FormNumber = "")
{
try{
$name = "GetReturnPrintForms";
$params = ["Token" => $Token, "ReturnGUID" => $ReturnGUID,
"FormNumber" => $FormNumber];
$response = $this->soapCall($name, $params);
//$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getFilteredReturnList2($Token, $CustomerGUID, $DateBegin, $DateEnd, $NumberString, $GoodsString)
{
try{
$name = "GetFilteredReturnList";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd, "WithLines" => 1,
"NumberString" => $NumberString, "GoodsString" => $GoodsString];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getReturn($Token, $ReturnGUID)
{
try{
$name = "GetReturn";
$params = ["Token" => $Token, "ReturnGUID" => $ReturnGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getReturn2($Token, $CustomerGUID, $ReturnGUID)
{
try{
$name = "GetReturn2";
$params = ["Token" => $Token, "ReturnGUID" => $ReturnGUID, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function updateReturn2($Token, $CustomerGUID, $Return)
{
try{
$name = "UpdateReturn2";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID,
"Return" => $Return];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getItemR2($Token, $CustomerGUID, $SerialNumber, $Code, $PartNumber)
{
try{
$name = "GetItemR2";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID,
'SerialNumber' => $SerialNumber, 'Code' => $Code, 'PartNumber' => $PartNumber];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function mergeOrders($Token, $OrderGUIDList)
{
try{
$name = "MergeOrders";
$params = ["Token" => $Token, "OrderGUIDList" => $OrderGUIDList];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getManager($Token, $CustomerGUID)
{
try{
$name = "GetManager";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getWishLists($Token, $CustomerGUID, $CompanyGUID, $DateBegin, $DateEnd, $FillLines = 1)
{
try{
$name = "GetWishLists";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "CompanyGUID" => $CompanyGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd, "FillLines" => $FillLines];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getFilteredWishLists($Token, $CustomerGUID, $CompanyGUID, $DateBegin, $DateEnd, $FillLines,
$NumberString, $GoodsString)
{
try{
$name = "GetFilteredWishLists";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "CompanyGUID" => $CompanyGUID,
"DateBegin" => $DateBegin, "DateEnd" => $DateEnd, "FillLines" => $FillLines,
"NumberString" => $NumberString, "GoodsString" => $GoodsString];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getChatWishList($Token, $CustomerGUID, $GUID)
{
try{
$name = "GetChatWishList";
$params = ["Token" => $Token, "WishListGUID" => $GUID, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getChat($Token, $CustomerGUID, $DocumentGUID, $DocumentType = "wishlist")
{
try{
$name = "GetChat";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID,
"DocumentType" => $DocumentType, "DocumentGUID" => $DocumentGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function sendChatWishList($Token, $CustomerGUID, $DocGUID, $Answer)
{
try{
$name = "SendChatWishList";
$params = ["Token" => $Token, "Chat" => ["DocGUID" => $DocGUID, "Answer" => $Answer],
"CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getOrderPrintForm($Token, $OrderGUID, $DataFormat = "PDF")
{
try{
$name = "GetOrderPrintForm";
$params = ["Token" => $Token, "OrderGUID" => $OrderGUID, "DataFormat" => $DataFormat];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getOrderPrintGoods($Token, $OrderGUID, $DataFormat = "PDF")
{
try{
$name = "GetOrderPrintGoods";
$params = ["Token" => $Token, "OrderGUID" => $OrderGUID, "DataFormat" => $DataFormat];
$response = $this->soapCall($name, $params);
//$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getShipmentPrintForms($Token, $ShipmentGUID, $DataFormat = "PDF", $FormNumber = "")
{
try{
$name = "GetShipmentPrintForms";
$params = ["Token" => $Token, "ShipmentGUID" => $ShipmentGUID, "FormNumber" => $FormNumber,
"DataFormat" => $DataFormat];
$response = $this->soapCall($name, $params);
//$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getContactInfo($Token, $CustomerGUID){
try{
$name = "GetContactInfo";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getGroupTree($Token)
{
try{
$name = "GetGroupTree";
$params = ["Token" => $Token];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getCompanysList($Token, $CustomerGUID)
{
try{
$name = "GetCompanysList";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function selectionGoods($Token, $CustomerGUID, $CompanyGUID, $SearchString)
{
try{
$name = "SelectionGoods";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "CompanyGUID" => $CompanyGUID,
"SearchString" => $SearchString];
// var_dump($params);
// die(0);
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function setModeOrder($Token, $OrderGUID, $Mode)
{
try{
$name = "SetModeOrder";
$params = ["Token" => $Token, "OrderGUID" => $OrderGUID, "Mode" => $Mode];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function changePassword($Token, $Login, $OldPassword, $NewPassword)
{
try{
$name = "ChangePassword";
$params = ["Token" => $Token, "Login" => $Login,
"OldPassword" => $OldPassword, "NewPassword" => $NewPassword];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getPasswordSample()
{
try{
$name = "GetPasswordSample";
$params = [];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function confirmOrder($Token, $OrderGUID, $Mode, $AccessLevel = 0)
{
try{
$name = "ConfirmOrder";
// vassa
//$params = ["Token" => $Token, "OrderGUID" => $OrderGUID, "Mode" => $Mode,
// "CustomerGUID" => $AccessLevel];
$params = ["Token" => $Token, "OrderGUID" => $OrderGUID, "Mode" => $Mode,
"AccessLevel" => $AccessLevel];
// var_dump($params);
$response = $this->soapCall($name, $params);
// var_dump($response);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getVendorList($Token)
{
try{
$name = "GetVendorList";
$params = ["Token" => $Token];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getCustomerAttributes($Token, $CustomerGUID)
{
try{
$name = "GetCustomerAttributes";
$params = ["Token" => $Token, "CustomerGuid" => $CustomerGUID];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function getPrices($Token, $CustomerGUID)
{
try{
$name = "GetPrices";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID];
$response = $this->soapCall($name, $params);
//$response = $this->objectToArray($response);
//$response["source"] = $params;
return $response;
}catch (\Exception $e){
dump($e);
}
}
function confirmViewingMessage($Token, $CustomerGUID, $Number)
{
try{
$name = "ConfirmViewingMessage";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "Number" => $Number];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function confirmViewingChatMessage($Token, $CustomerGUID, $DocumentGUID, $DocumentType = "wishlist", $Number = "")
{
try{
$name = "ConfirmViewingChatMessage";
$params = ["Token" => $Token, "CustomerGUID" => $CustomerGUID, "DocumentGUID" => $DocumentGUID,
"DocumentType" => $DocumentType, "Number" => $Number];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function authentication($login, $password, $ip, $browser_info)
{
try{
$name = "Authentication";
$params = ["Login" => $login, "Password" => $password, "IPAddress" => $ip, "BrowserInfo" => $browser_info];
$response = $this->soapCall($name, $params);
$response = $this->objectToArray($response);
return $response;
}catch (\Exception $e){
dump($e);
}
}
function soapCall($name, $params)
{
try
{
$response = $this->client->__soapCall($name, array($params));
}
catch (\Exception $e)
{
$response["Error"] = $e->getMessage();
}
return $response;
}
function objectToArray($object) {
//$arr = json_decode(json_encode($object), true);
$json = json_encode($object);
$arr = json_decode($json,true);
return $arr;
}
function getError($response)
{
if(is_array($response) && isset($response["Error"]))
{
$this->session->set('error', $response["Error"]);
return true;
}
// if(!is_object($response))
// {
// return false;
// }
if(isset($response['return']['Error']['ErrorCode']) && $response['return']['Error']['ErrorCode'] != 0) {
$this->session->set('error', $response['return']['Error']['ErrorDescription']);
return true;
} else {
$this->session->set('error', "");
return false;
}
}
function getRespond()
{
$respond = json_encode($this->respond, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
echo $respond;
}
function getCustomerMessage($type = "main"){
$Items = [];
$Token = $this->session->get("Token");
$CustomerGUID = $this->session->get("CustomerGUID");
$CustomerMessage = $this->session->get("CustomerMessage") ?? "";
$CustomerMessage_count = $this->session->get("CustomerMessage_count") ?? 0;
$CustomerMessage_count_unread = $this->session->get("CustomerMessage_count_unread") ?? 0;
if($CustomerMessage == "" || $type == "renew"){
$result = $this->getCustomerMessages($Token, $CustomerGUID);
if(isset($result['return']['Error']['ErrorCode']) && $result['return']['Error']['ErrorCode'] != 0) {
$this->session->set("CustomerMessage", "false");
$this->session->set("CustomerMessage_count", 0);
$this->session->set("CustomerMessage_count_unread", 0);
// $Items['error'] = $result['return']['Error']['ErrorDescription'];
// $Items["message_count"] = 'false';
} else {
$messages_arr = [];
//Приватные сообщения
$CustomerMessagesPrivate = $result['return']['CustomerMessagesPrivate'] ?? [];
if(isset($CustomerMessagesPrivate["Number"])){
$CustomerMessagesPrivate = [$CustomerMessagesPrivate];
}
foreach ($CustomerMessagesPrivate as $value){
array_push($messages_arr, $value);
}
//Публичные сообщения
$CustomerMessagesPublic = $result['return']['CustomerMessagesPublic'] ?? [];
if(isset($CustomerMessagesPublic["Number"])){
$CustomerMessagesPublic = [$CustomerMessagesPublic];
}
foreach ($CustomerMessagesPublic as $value){
array_push($messages_arr, $value);
}
if($messages_arr == []){
$CustomerMessage = 'false';
$CustomerMessage_count = 0;
}else{
$CustomerMessage = $messages_arr;
$CustomerMessage_count = count($CustomerMessage);
}
$this->session->set("CustomerMessage", $CustomerMessage);
$this->session->set("CustomerMessage_count", $CustomerMessage_count);
$CustomerMessage_count_unread = 0;
if(is_array($CustomerMessage)){
foreach ($CustomerMessage as $value){
if(isset($value["DateOfConfirmingView"]) && $value["DateOfConfirmingView"] != ""){
}else{
$CustomerMessage_count_unread++;
}
}
}
$this->session->set("CustomerMessage_count_unread", $CustomerMessage_count_unread);
// $Items['error'] = "";
// $Items["status"] = 'true';
// $Items["item"] = $result['return']['Item'];
}
}
// return ["CustomerMessage_count" => $CustomerMessage_count,
// "CustomerMessage_count_unread" => $CustomerMessage_count_unread];
}
function reLogin($request){
if($this->session->get("Token") != "" && $this->session->get("CompanyGUID") != ""){
return true;
}
$login = $request->cookies->get('login');
$password = $request->cookies->get('password');
if($login == "" || $password == "") {
return false;
}
$response = $this->authentication($login, $password, "", "");
if($this->getError($response)) {
return false;
}
if(!isset($response["return"]["Token"]) || !isset($response["return"]["CustomerGuid"]))
{
return false;
}
$Token = $response["return"]["Token"];
$CustomerGUID = $response["return"]["CustomerGuid"];
$ChangePasswordAtFirstLogon = $response["return"]["ChangePasswordAtFirstLogon"];
$AccessLevel = $response["return"]["AccessLevel"] ?? 1;
if($login == "vassa" || strtolower($login) == "e.panova@i-t-trade.ru"){
$AccessLevel = "admin";
}
$this->session->set("AccessLevel", $AccessLevel);
$bonus_list = $this->getBonusList($Token, $CustomerGUID);
if(isset($bonus_list["return"]["Companys"])){
if(isset($bonus_list["return"]["Companys"]["GUID"])){
$bonus_list = [$bonus_list["return"]["Companys"]];
}else{
$bonus_list = $bonus_list["return"]["Companys"];
}
$bonus_list_bool = 'true';
}else{
$bonus_list = [];
$bonus_list_bool = 'false';
}
$this->session->set("bonus_list", $bonus_list);
$this->session->set("bonus_list_bool", $bonus_list_bool);
$contact_info = $this->getContactInfo($Token, $CustomerGUID);
$persons = [];
$address = [];
if(isset($contact_info["return"]["ContactInfo"]["Person"])){
if(isset($contact_info["return"]["ContactInfo"]["Person"]["GUID"])){
$temp_contact_info[0] = $contact_info["return"]["ContactInfo"]["Person"];
$persons = $temp_contact_info;
}else{
$persons = $contact_info["return"]["ContactInfo"]["Person"];
}
}else{
$persons = [];
}
if(isset($contact_info["return"]["ContactInfo"]["Address"])){
if(isset($contact_info["return"]["ContactInfo"]["Address"]["GUID"])){
$temp_contact_info[0] = $contact_info["return"]["ContactInfo"]["Address"];
$address = $temp_contact_info;
}else{
$address = $contact_info["return"]["ContactInfo"]["Address"];
}
}else{
$address = [];
}
$contacts["Person"] = $persons;
$contacts["Address"] = $address;
$this->session->set("contact_info", $contacts);
$get_manager = $this->getManager($Token, $CustomerGUID);
if(isset($get_manager["return"]["ManagerInfo"]["GUID"])){
$temp_get_manager_info[0] = $get_manager["return"]["ManagerInfo"];
$get_manager = $temp_get_manager_info;
}else{
$get_manager = $get_manager["return"]["ManagerInfo"] ?? "false";
}
//ToDo this is a hard fix photo link
if($get_manager != "false"){
if(isset($get_manager["FIO"])){
$get_manager = [$get_manager];
}
$i = 0;
foreach ($get_manager as $manager){
$get_manager[$i]["Photo"] = str_replace("http://", "https://", $get_manager[$i]["Photo"]);
if($get_manager[$i]["Photo"] == ""){
$get_manager[$i]["Photo"] = "/img/non_img_manager.png";
}
$i++;
}
}
$this->session->set("manager_info", $get_manager);
$this->session->set("Token", $Token);
$this->session->set("Login", $login);
$this->session->set("CustomerGUID", $CustomerGUID);
$response = $this->getCompanysList($Token, $CustomerGUID);
if($this->getError($response)) {
return false;
}
$CompanysList = $response["return"]["Companys"];
if(isset($CompanysList["GUID"])){
$arr[0]= $CompanysList;
$CompanysList = $arr;
}
$this->session->set("CompanyGUID", $CompanysList[0]["GUID"]);
$this->session->set("CompanyDescription", $CompanysList[0]["Description"]);
$this->session->set("CompanysList", $CompanysList);
$this->getCustomerMessage();
$user_db = $this->db->getOneWhereArr(["login" => $login], "users");
if($user_db == null){
$this->db->insert("users", ["login" => $login]);
}
$page_number = $user_db["main_page"] ?? 0;
$this->session->set("user_main_page", $page_number);
$page_name = $this->getUserMainPage($page_number);
$date = new \DateTime();
$date->modify('-1 month');
$DateBegin = $date->format('Y-m-d');
$date = new \DateTime();
$DateEnd = $date->format('Y-m-d');
$delivery = $this->getCustomerAttributes($Token, $CustomerGUID);
if(isset($delivery["return"]["DeliveryLimit"])){
$this->session->set("DeliveryLimit", $delivery["return"]["DeliveryLimit"]);
//$this->session->set("DeliveryLimit", ["FreeDeliveryMin" => "500", "DeliveryPrice" => "500"]);
}else{
$this->session->set("DeliveryLimit", ["FreeDeliveryMin" => "0", "DeliveryPrice" => "0"]);
}
$response = $this->getAccountingInformation($Token, $CustomerGUID, $CompanysList[0]["GUID"], $DateBegin, $DateEnd);
$this->session->set("SumDebit", 0);
if(isset($response["return"]["AccountingInformation"]["AccountingInformationCompanys"])){
if(isset($response["return"]["AccountingInformation"]["AccountingInformationCompanys"]["DebtAtTheEnd"])){
$account = [$response["return"]["AccountingInformation"]["AccountingInformationCompanys"]];
}else{
$account = $response["return"]["AccountingInformation"]["AccountingInformationCompanys"];
}
foreach ($account as $acc){
if($acc["СompanyGUID"] == $CompanysList[0]["GUID"]){
$this->session->set("SumDebit", $acc["DebtAtTheEnd"]);
}
}
}
// return new Response($twig->render('flex/index.html', $this->twig_values->getTwigTemplate($request) +
// ["page_name" => $page_name]
// ));
$account_info = $this->getLoginProperties($Token);
$LoginProperties = $account_info["return"]["LoginProperties"] ?? false;
$this->session->set("LoginProperties", $LoginProperties);
return true;
}
}