Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. <?php
  2.  
  3. function order_check_by_number($order_custom_number) {
  4. global $api;
  5. $docSearchValue = array (
  6. 'number' => (INTEGER) $order_custom_number,
  7. );
  8. $documentSearch = $api->sendRequest("getSalesDocuments", $docSearchValue);
  9. return json_decode($documentSearch);
  10. }
  11.  
  12. $xml = file_get_contents("http://store.bredenkids.com/wp-content/uploads/wpallexport/exports/4084483bc00eb0b623869fe8394565b0/current-orders.xml");
  13.  
  14.  
  15.  
  16. $order = new SimpleXMLElement($xml);
  17. $order = json_decode(json_encode($order),true);
  18.  
  19. // Order basic infrmation
  20. $OrderID = $order->OrderID;
  21. $OrderDate = $order->OrderDate;
  22. $PaymentMethodTitle = $order->PaymentMethodTitle;
  23. $OrderTotal = $order->OrderTotal;
  24. $BillingFirstName = $order->BillingFirstName;
  25. $BillingLastName = $order->BillingLastName;
  26. $BillingAddress1 = $order->BillingAddress1;
  27. $BillingAddress2 = $order->BillingAddress2;
  28. $BillingCity = $order->BillingCity;
  29. $BillingPostcode = $order->BillingPostcode;
  30. $BillingCountry = $order->BillingCountry;
  31. $BillingPhone = $order->BillingPhone;
  32. $BillingState = $order->BillingState;
  33. $BillingEmailAddress = $order->BillingEmailAddress;
  34. $ShippingFirstName = $order->ShippingFirstName;
  35. $ShippingLastName = $order->ShippingLastName;
  36. $ShippingCompany = $order->ShippingCompany;
  37. $ShippingAddress1 = $order->ShippingAddress1;
  38. $ShippingAddress2 = $order->ShippingAddress2;
  39. $ShippingCity = $order->ShippingCity;
  40. $ShippingPostcode = $order->ShippingPostcode;
  41. $ShippingCountry = $order->ShippingCountry;
  42. $ShippingState = $order->ShippingState;
  43.  
  44. // Ordered products
  45. $ProductID = $order->OrderItems->Item->ProductID;
  46. $SKU = $order->OrderItems->Item->SKU;
  47. $ProductName = $order->OrderItems->Item->ProductName;
  48. $Quantity = $order->OrderItems->Item->Quantity;
  49. $ItemCost = $order->OrderItems->Item->ItemCost;
  50. $ItemTotal = $order->OrderItems->Item->ItemTotal;
  51. $ItemTax = $order->OrderItems->Item->ItemTax;
  52. $ItemTaxTotal = $order->OrderItems->Item->ItemTaxTotal;
  53. $OrderLineID = $order->OrderItems->Item->OrderLineID;
  54.  
  55.  
  56. // Order TAX amounts, coupon usage, order note and total discount
  57. $TotalTaxAmount = $order->TotalTaxAmount;
  58. $CouponsUsed = $order->CouponsUsed;
  59. $TotalDiscountAmount = $order->TotalDiscountAmount;
  60. $CustomerNote = $order->CustomerNote;
  61.  
  62.  
  63. // alustame sessioni
  64. session_start([
  65. 'cookie_lifetime' => 15,
  66. 'read_and_close' => true,
  67. ]);
  68.  
  69.  
  70. // include ERPLY API class
  71. include("EAPI.class.php");
  72.  
  73. // Initialise class
  74. $api = new EAPI();
  75.  
  76. // Configuration settings
  77. $api->clientCode = "";
  78. $api->username = "kristo.meerits";
  79. $api->password = "Bredentugi";
  80. $api->url = "https://".$api->clientCode.".erply.com/api/";
  81.  
  82.  
  83.  
  84. // Salvestame kliendi aadressi ERPLYsse
  85.  
  86.  
  87. //$inputParameters_aadress = array(
  88. //"addressID" => "",
  89. //"ownerID" => "",
  90. //"typeID" => "",
  91. //"street" => $tanav,
  92. //"city" => $linn,
  93. //"postalCode" => $indeks,
  94. //"state" => $maakond,
  95. //"country" => $riik,
  96. //);
  97.  
  98. //$result = $api->sendRequest("saveAddress", $inputParameters_aadress);
  99.  
  100.  
  101.  
  102. // Salvestame kliendi info ERPLYsse
  103. $inputParameters_kliendid = array(
  104.  
  105.  
  106. "customerID" => "",
  107. "groupID" => "17",
  108. "fullname" => $BillingFirstName,
  109. "name" => $BillingLastName,
  110. "email" => $BillingEmailAddress,
  111. "mobile" => $BillingPhone
  112.  
  113.  
  114.  
  115. );
  116.  
  117. $searchValues = array(
  118. 'searchName' => $BillingEmailAddress
  119. );
  120.  
  121. // Teeme päringu ERPLYsse ja otsime emaili järgi kliendi
  122. $searchResult = $api->sendRequest("getCustomers", $searchValues);
  123. $searchResult = json_decode($searchResult, TRUE);
  124.  
  125. $params = array (
  126. 'parameterName' => "search_invoice_by_regular_and_custom_number",
  127. 'parameterValue' => 1,
  128. );
  129. $api->sendRequest("saveConfParameter", $params);
  130.  
  131.  
  132.  
  133. if(order_check_by_number($number)->status->recordsTotal > 0) {
  134. die("Sellise tellimuse numbriga on andmebaasis juba kirje olemas!");
  135. }
  136.  
  137. // kui klient on olemas salvestame tema ID
  138. if($searchResult['status']['recordsInResponse'] > 0 && ($searchResult['status']['errorCode'] == 0))
  139. {
  140. $customerID = $searchResult['records'][0]['id'];
  141. }
  142. // kui klienti olemas ei ole siis salvestame kliendi ning jätame ID alles
  143. else
  144. {
  145. $result_klientidega = $api->sendRequest("saveCustomer", $inputParameters_kliendid);
  146. $output2 = json_decode($result_klientidega, true);
  147. $customerID = $output2['records'][0]['clientID'];
  148. }
  149.  
  150. // Tellimuse info, mis tuli e-poest sisestus
  151. $inputParameters = array(
  152.  
  153.  
  154. // Tellimuse ID number e-poest
  155. "id" => "",
  156. "invoiceNo" => "",
  157. "customNumber" => $OrderID,
  158. "allowDuplicateNumbers" => "0",
  159.  
  160. // Tellimuse tüüp (arve, pakkumine, tellimus, saateleht)
  161. "type" => "ORDER",
  162.  
  163. // Valuuta kood
  164. "currencyCode" => "EUR",
  165.  
  166. // ERPLY lao ID ( 1 on põhiladu)
  167. "warehouseID" => "1",
  168.  
  169. // Kuupäev Y-m-d formaadis
  170. "date" => $OrderDate, // Ajutine manuaalne
  171.  
  172. // Kellaaeg H:m:s formaadis
  173. "time" => date('H:m:s'), // Ajutine manuaalne
  174.  
  175. // Kas kinnitame tellimuse/arve/saatelehe automaatselt?
  176. "confirmInvoice" => "1",
  177.  
  178. // Kliendi ID ERPLY'S & Maksja ID ERPLY'S
  179. "customerID" => $customerID,
  180. "payerID" => "",
  181.  
  182. // Saaja Addressi ID ERPLY'S & Maksja aadressi ID ERPLY'S
  183. "addressID" => "",
  184. "payerAddressID" => "",
  185.  
  186. // Tellimuse lisainformatsioon väljatrükil
  187. "notes" => $CustomerNote,
  188.  
  189. // Lisainformatsioon, mis on nähtav vaid adminnile.
  190. "internalNotes" => CustomerNote,
  191.  
  192. // Tellimuse kogusumma?
  193. "externalNetTotal" => "",
  194.  
  195. // Makseviis, kood ERPLY'st (CARD; TRANSFER, CASH...)
  196. "paymentType" => "TRANSFER",
  197.  
  198. // Maksetingimus
  199. "paymentDays" => "1",
  200.  
  201. // Makse staatus (PAID; UNPAID)
  202. "paymentStatus" => "PAID",
  203.  
  204. );
  205.  
  206.  
  207. $i = 1;
  208. foreach ($post['OrderItems']['Item'] as $product) {
  209. $inputParameters["productID".$i] = $product["SKU"];
  210. $inputParameters["amount".$i] = $product["Quantity"];
  211. $inputParameters["vatrateID".$i] = "1";
  212. $inputParameters["price".$i] = $product["ItemCost"];
  213. $inputParameters["discount".$i] = "";
  214. $i++;
  215. }
  216.  
  217. $result = $api->sendRequest("saveSalesDocument", $inputParameters);
  218.  
  219. $output = json_decode($result, true);
  220.  
  221. print "<pre>";
  222. print_r($output);
  223. echo "Kliendi ID: ".$customerID;
  224. print "</pre>";
  225. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement