Changeset 2556290
- Timestamp:
- 06/30/2021 10:18:17 AM (5 years ago)
- Location:
- drivefx-woocommerce/trunk
- Files:
-
- 10 edited
-
PHCLibrary/classes/invoice.php (modified) (2 diffs)
-
PHCLibrary/classes/settings.php (modified) (1 diff)
-
PHCLibrary/classes/shipping.php (modified) (1 diff)
-
PHCLibrary/customers.php (modified) (1 diff)
-
PHCLibrary/invoices.php (modified) (8 diffs)
-
PHCLibrary/orders.php (modified) (12 diffs)
-
PHCLibrary/utils.php (modified) (6 diffs)
-
class.DriveFxWoocommerce.php (modified) (22 diffs)
-
settings/backend.php (modified) (1 diff)
-
settings/syncro_gate.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
drivefx-woocommerce/trunk/PHCLibrary/classes/invoice.php
r2526532 r2556290 2 2 class Invoice { 3 3 public $country; 4 public $shipping_country;5 4 public $cart; 6 public $shipping_name;7 public $shipping_value;8 public $fees;9 5 public $billing_name; 10 6 public $billing_email; … … 14 10 public $billing_postcode; 15 11 public $billing_nif; 12 public $shipping_name; 13 public $shipping_value; 14 public $shipping_country; 15 public $shipping_taxValue; 16 public $shipping_tax; 17 public $fees; 16 18 } -
drivefx-woocommerce/trunk/PHCLibrary/classes/settings.php
r2526532 r2556290 3 3 public $createInvoice; 4 4 public $typeOfInvoice; 5 public $typeOf_EU_Invoice; 5 6 public $toSignInvoice; 6 7 public $fieldNif; -
drivefx-woocommerce/trunk/PHCLibrary/classes/shipping.php
r2526532 r2556290 1 1 <?php 2 2 class Shipping { 3 public $cl_name; 4 public $ncont; 3 5 public $paisto; 4 6 public $moradato; -
drivefx-woocommerce/trunk/PHCLibrary/customers.php
r2526532 r2556290 90 90 #If have Generic Customer 91 91 if(is_array($response['result'][0])){ 92 //reset NIF 93 //$response['result'][0]['ncont'] = ""; 94 92 95 //Return object 93 96 return (object) $response['result'][0]; -
drivefx-woocommerce/trunk/PHCLibrary/invoices.php
r2526532 r2556290 19 19 } 20 20 21 public function getInvoiceSerieToUse($ch, $credentials, $dataPack){ 22 23 //Obtain the shop country abbreviation acording to PHC 24 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nome', $dataPack->shop->country); 25 26 if (curl_error($ch)) { 27 $this->logs->writeFileLog('getInvoiceSerieToUse', $ch); 28 } else if(empty($response)){ 29 $this->logs->writeFileLog('getInvoiceSerieToUse', 'EMPTY RESPONSE'); 30 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 31 $this->logs->writeFileLog('getInvoiceSerieToUse', $response['messages'][0]['messageCodeLocale']); 32 } else { 33 // The shop country abbreviation 34 $companyCountry = $response['result'][0]['nomeabrv']; 35 // the order tax country 36 $taxCountry = $dataPack->shop->taxCountry; 37 38 if(!empty($companyCountry && $taxCountry)){ 39 if($companyCountry == $taxCountry){ 40 //use the normal invoice serie 41 $invoiceSerie = $dataPack->settings->typeOfInvoice; 42 } else { 43 if(!empty($dataPack->settings->typeOf_EU_Invoice)){ 44 //use the invoice serie with with foreign VAT 45 $invoiceSerie = $dataPack->settings->typeOf_EU_Invoice; 46 } else { 47 //use the normal invoice serie 48 $invoiceSerie = $dataPack->settings->typeOfInvoice; 49 $this->logs->writeFileLog('notice:', 'The invoice series by default is used, because the series for foreign VAT was not detected.'); 50 } 51 } 52 } else { 53 //use the normal invoice serie 54 $invoiceSerie = $dataPack->settings->typeOfInvoice; 55 $this->logs->writeFileLog('getInvoiceSerieToUse1.1', 'Can not obtain Country Tax or Company Tax, so we use the default doc. serie: ' .$invoiceSerie.''); 56 } 57 } 58 return $invoiceSerie; 59 } 60 21 61 public function addSimpleInvoice($ch, $credentials, $dataPack){ 22 62 ### … … 25 65 $shipping = $dataPack->shipping; 26 66 27 if(empty($settings->typeOfInvoice) || $settings->typeOfInvoice == 0){ 67 # get the invoice serie to use 68 $invoiceSerie = $this->getInvoiceSerieToUse($ch, $credentials, $dataPack); 69 70 //$this->logs->writeFileLog('invoiceSerie1 response:', $invoiceSerie); 71 72 if(empty($invoiceSerie) || $invoiceSerie == 0){ 28 73 $this->logs->writeFileLog('addSimpleFT', 'Empty type of invoice'); 29 74 } else { 75 30 76 ### 31 77 $_billing_country = $ft->country; … … 67 113 } 68 114 115 #Get taxes from Phc 116 $responseTaxes = $this->utils_services->getTaxes($ch, $credentials); 117 118 //$this->logs->writeFileLog('Get Taxes:', $responseTaxes['result']); 119 120 if (curl_error($ch)) { 121 $this->logs->writeFileLog('addSimpleFT3.1.1', $ch); 122 } else if(empty($responseTaxes)){ 123 $this->logs->writeFileLog('addSimpleFT3.1.1', 'EMPTY RESPONSE'); 124 } else if(isset($responseTaxes['messages'][0]['messageCodeLocale'])){ 125 $this->logs->writeFileLog('addSimpleFT3.1.1', $responseTaxes['messages'][0]['messageCodeLocale']); 126 } 127 69 128 # get current customer data 70 129 $newCustomer = $this->customers_services->processCustomer($ch, $credentials, $dataPack, $tip_button); … … 85 144 if($createClientSuccess == 1){ 86 145 //Obtain new instance of invoice 87 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'FtWS', $ settings->typeOfInvoice);146 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'FtWS', $invoiceSerie); 88 147 89 148 //Clear the product lines … … 170 229 $fi->qtt = 1; 171 230 172 // IVA173 231 if($settings->includeTaxonSendCost == "true") { 174 232 $fi->ivaincl=true; 175 233 } 234 235 ### [Query] - Obtain type of IVA 236 $responseTax = $this->utils_services->doubleFilter($ch, $credentials, 'taxasiva', 'taxa', $ft->shipping_tax, 'regiao', $ft->shipping_country); 237 //$this->logs->writeFileLog('OrderType response:', $response); 238 239 if (curl_error($ch)) { 240 $this->logs->writeFileLog('responseTax', $ch); 241 } else if(empty($response)){ 242 $this->logs->writeFileLog('responseTax', 'EMPTY RESPONSE'); 243 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 244 $this->logs->writeFileLog('responseTax', $response['messages'][0]['messageCodeLocale']); 245 } else { 246 //set IVA for Shipping 247 $fi->iva = $responseTax['result'][0]['taxa']; 248 $fi->tabiva = $responseTax['result'][0]['codigo']; 249 } 250 176 251 if($fi->etiliquido == 0){ 177 252 $fi->qtt = 0; … … 182 257 //actEntity 183 258 $response2 = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); 259 260 //$this->logs->writeFileLog('response2:', $response2['result'][0]['fis']); 184 261 185 262 // shipping value … … 246 323 } 247 324 325 #Obtain taxes 326 if (is_array($cart)){ 327 //get tax rate & tax rate country 328 foreach ($cart as $key => $value){ 329 if( $value['qtt']*$value['epv']!=0){ 330 $taxCountry = $value['tax_country']; 331 $taxRate = $value['tax_rate']; 332 $refProd = $value['ref']; 333 334 //obtain tax from Phc 335 foreach ($responseTaxes['result'] as $tax) { 336 337 if($taxRate == $tax['taxa'] && $taxCountry == $tax['regiao'] && $refProd == $response['result'][0]['fis'][$key]['ref']) { 338 339 $response['result'][0]['fis'][$key]['iva'] = $tax['taxa']; 340 $response['result'][0]['fis'][$key]['tabiva'] = $tax['codigo']; 341 if($settings->includeTaxonSendCost == "true") { 342 $response['result'][0]['fis'][$key]['ivaincl'] = true; 343 } 344 break; 345 } 346 } 347 } 348 } 349 } 350 248 351 #actEntity 249 352 $response = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); … … 314 417 $settings = $dataPack->settings; 315 418 316 if(empty($settings->typeOfInvoice) || $settings->typeOfInvoice == 0){ 419 # get the invoice serie to use 420 $invoiceSerie = $this->getInvoiceSerieToUse($ch, $credentials, $dataPack); 421 422 //$this->logs->writeFileLog('invoiceSerie response:', $invoiceSerie); 423 424 if(empty($invoiceSerie) || $invoiceSerie == 0){ 317 425 $this->logs->writeFileLog('addInternalDocumentInvoice', 'Empty type of invoice'); 318 426 } else { 427 319 428 //Obtain new instance of FT based in Bo(bostamp) 320 $response = $this->utils_services->paramsNewInstanceFromReference($ch, $credentials, $response['bostamp'] );429 $response = $this->utils_services->paramsNewInstanceFromReference($ch, $credentials, $response['bostamp'], $invoiceSerie); 321 430 322 431 //$this->logs->writeFileLog('instanceFromReference:', $response); -
drivefx-woocommerce/trunk/PHCLibrary/orders.php
r2526532 r2556290 147 147 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', $filterItem, $valueItem); 148 148 149 //$this->logs->writeFileLog('Response ', $response);149 //$this->logs->writeFileLog('Responses', $response); 150 150 151 151 if (curl_error($ch)) { … … 360 360 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'BoWS', $settings->typeOfOrder); 361 361 362 //$this->logs->writeFileLog('BoWs NewInstance', $response); 363 362 364 //Clear the product lines 363 365 $response['result'][0]['bis'] = []; 364 365 //$this->logs->writeFileLog('BoWs Response', $response);366 366 367 367 if (curl_error($ch)) { … … 375 375 //Obtain number of customer 376 376 $response['result'][0]['no'] = $newCustomer->no; 377 378 //$this->logs->writeFileLog('newCustomer:', $newCustomer); 379 377 380 #actEntity 378 381 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); … … 387 390 $this->logs->writeFileLog('addNewOrder13.1', $response['messages'][0]['messageCodeLocale']); 388 391 } else { 392 $response['result'][0]['no'] = $newCustomer->no; 393 $response['result'][0]['nome'] = $newCustomer->nome; 394 $response['result'][0]['ncont'] = $newCustomer->ncont; 389 395 390 396 #Put the same number of order in PHC … … 404 410 $responseTaxes = $this->utils_services->getTaxes($ch, $credentials); 405 411 406 //$this->logs->writeFileLog('Get Taxes:', $responseTaxes );412 //$this->logs->writeFileLog('Get Taxes:', $responseTaxes['result']); 407 413 408 414 if (curl_error($ch)) { … … 445 451 //IVA for shipping 446 452 foreach ($responseTaxes['result'] as $tax) { 453 447 454 if ($shipping->shipping_tax == $tax['taxa'] && 448 455 $shipping->shipping_country == $tax['regiao']) { … … 453 460 } 454 461 } 462 455 463 if($bi->edebito == 0){ 456 464 $bi->qtt = 0; … … 462 470 $response2 = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 463 471 464 //$this->logs->writeFileLog('actEntity.0.1:', $response2 );472 //$this->logs->writeFileLog('actEntity.0.1:', $response2['result'][0]['bis']); 465 473 466 474 // Update shipping value … … 477 485 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response2); 478 486 479 // $this->logs->writeFileLog('actEntity1:', $response);487 //$this->logs->writeFileLog('actEntity1:', $response['result']); 480 488 481 489 if (curl_error($ch)) { … … 566 574 $response['result'][0]['ncont'] = $bill->ncont; 567 575 576 568 577 #Obtain taxes 569 578 if (is_array($order->cart)){ … … 574 583 $taxRate = $value['tax_rate']; 575 584 $refProd = $value['ref']; 585 576 586 //obtain tax from Phc 577 587 foreach ($responseTaxes['result'] as $tax) { 578 if($taxRate == $tax['taxa'] && $taxCountry == $tax['regiao'] && $refProd == $response['result'][0]['ref']) { 588 589 if($taxRate == $tax['taxa'] && $taxCountry == $tax['regiao'] && $refProd == $response['result'][0]['bis'][$key]['ref']) { 590 579 591 $response['result'][0]['bis'][$key]['iva'] = $tax['taxa']; 580 592 $response['result'][0]['bis'][$key]['tabiva'] = $tax['codigo']; … … 588 600 } 589 601 } 590 //$this->logs->writeFileLog('Obtain taxes:', $response['result'][0]);602 //$this->logs->writeFileLog('Obtain taxes:', $response['result'][0]['bis']); 591 603 ### 592 604 $fees = $order->fees; -
drivefx-woocommerce/trunk/PHCLibrary/utils.php
r2547407 r2556290 108 108 //Build Http query using params 109 109 $this->query = http_build_query ($this->params); 110 111 //Called webservice that make a request 112 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 113 110 //Called webservice that make a request 111 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 114 112 return $response; 115 113 } … … 334 332 ********************************************************************/ 335 333 /** Header to create Query of webservice called **/ 336 public function paramsQuery5($ch, $credentials, $entityName, $comparison , $filterItem = null, $valueItem = null, $comparisonTwo, $filterItemTwo = null, $valueItemTwo = null){334 public function paramsQuery5($ch, $credentials, $entityName, $comparison = null, $filterItem = null, $valueItem = null, $comparisonTwo = null, $filterItemTwo = null, $valueItemTwo = null){ 337 335 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 338 336 //Create map with request parameters … … 368 366 //Called webservice that make a request 369 367 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 370 371 368 return $response; 372 369 } … … 472 469 ********************************************************************/ 473 470 //Header to create a new instance from reference of webservice called 474 public function paramsNewInstanceFromReference($ch, $credentials, $boStamp ){471 public function paramsNewInstanceFromReference($ch, $credentials, $boStamp, $invoiceType){ 475 472 $this->url = $credentials->backendUrl."/REST/FtWS/getNewInstanceFromReference"; 476 473 // Create map with request parameters … … 482 479 }, 483 480 {"key":"docid", 484 "value":"'.$ credentials->invoiceType.'"481 "value":"'.$invoiceType.'" 485 482 } 486 483 ]' … … 757 754 } 758 755 759 760 761 762 756 } 763 757 ?> -
drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php
r2547408 r2556290 33 33 'sendInvoice' => array('label' => 'Send Invoice', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Send the client an e-mail with the order invoice attached', 'notice' => ''), 34 34 'emailBody' => array('label' => 'E-mail body content', 'type' => 'text', 'required' => false, 'descr' => 'Enter the text to be attached to the e-mails sent to the client.', 'notice' => ''), 35 'typeOfInvoice' => array('label' => 'Type of Invoice Document', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the type of invoice document', 'notice' => ''), 35 'typeOfInvoice' => array('label' => 'Type of Invoice Document (PT)', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the type of invoice document', 'notice' => ''), 36 'typeOf_EU_Invoice' => array('label' => 'Type of Invoice Document (EU)', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the type of invoice document', 'notice' => ''), 36 37 'toSignInvoice' => array('label' => 'Sign Invoice', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Sign Invoice document after its creation.', 'notice' => ''), 37 38 'fieldNif' => array('label' => 'NIF Field in Woocommerce', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the nif field of woocommerce', 'notice' => ''), … … 655 656 // send response as JSON 656 657 $response = json_decode($response, true); 657 // get the temporarytoken and insert in credentials object658 // get the new token and insert in credentials object 658 659 $credentials->token = $response['result'][0]['token']; 659 660 … … 678 679 $selected_dropdown = ''; 679 680 $_SESSION['fieldNif'] = ''; 680 681 682 681 $_SESSION['includeTaxonSendCost']="<option value='true'"; 682 683 683 if($settings['backend']['includeTaxonSendCost'] == 'true') 684 $_SESSION['includeTaxonSendCost'].=" selected ";685 $_SESSION['includeTaxonSendCost'].=">Yes</option>";686 $_SESSION['includeTaxonSendCost'].="<option value='false'";684 $_SESSION['includeTaxonSendCost'].=" selected "; 685 $_SESSION['includeTaxonSendCost'].=">Yes</option>"; 686 $_SESSION['includeTaxonSendCost'].="<option value='false'"; 687 687 if($settings['backend']['includeTaxonSendCost'] == 'false') 688 $_SESSION['includeTaxonSendCost'].=" selected "; 689 $_SESSION['includeTaxonSendCost'].=">No</option>"; 690 691 688 $_SESSION['includeTaxonSendCost'].=" selected "; 689 $_SESSION['includeTaxonSendCost'].=">No</option>"; 692 690 693 691 if($settings['backend']['fieldNif'] == "company"){ 694 $_SESSION['fieldNif'] .= "<option value='company' selected >Company</option><br>";695 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>";696 $_SESSION['fieldNif'] .= "<option value='state'>State</option><br>";697 $_SESSION['fieldNif'] .= "<option value='nif'>Billing Nif (Plugin)</option><br>";692 $_SESSION['fieldNif'] .= "<option value='company' selected >Company</option><br>"; 693 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>"; 694 $_SESSION['fieldNif'] .= "<option value='state'>State</option><br>"; 695 $_SESSION['fieldNif'] .= "<option value='nif'>Billing Nif (Plugin)</option><br>"; 698 696 } else if($settings['backend']['fieldNif'] == "address_2"){ 699 $_SESSION['fieldNif'] .= "<option value='company'>Company</option><br>";700 $_SESSION['fieldNif'] .= "<option value='address_2' selected >Address 2</option><br>";701 $_SESSION['fieldNif'] .= "<option value='state'>State</option><br>";702 $_SESSION['fieldNif'] .= "<option value='nif'>Billing Nif (Plugin)</option><br>";697 $_SESSION['fieldNif'] .= "<option value='company'>Company</option><br>"; 698 $_SESSION['fieldNif'] .= "<option value='address_2' selected >Address 2</option><br>"; 699 $_SESSION['fieldNif'] .= "<option value='state'>State</option><br>"; 700 $_SESSION['fieldNif'] .= "<option value='nif'>Billing Nif (Plugin)</option><br>"; 703 701 } else if($settings['backend']['fieldNif'] == "state") { 704 $_SESSION['fieldNif'] .= "<option value='company'>Company</option><br>";705 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>";706 $_SESSION['fieldNif'] .= "<option value='state' selected >State</option><br>";707 $_SESSION['fieldNif'] .= "<option value='nif'>Billing Nif (Plugin)</option><br>";702 $_SESSION['fieldNif'] .= "<option value='company'>Company</option><br>"; 703 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>"; 704 $_SESSION['fieldNif'] .= "<option value='state' selected >State</option><br>"; 705 $_SESSION['fieldNif'] .= "<option value='nif'>Billing Nif (Plugin)</option><br>"; 708 706 }else{ 709 $_SESSION['fieldNif'] .= "<option value='company'>Company</option><br>";710 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>";711 $_SESSION['fieldNif'] .= "<option value='state' >State</option><br>";712 $_SESSION['fieldNif'] .= "<option value='nif' selected >Billing Nif (Plugin)</option><br>";713 } 714 715 //Obtain gama of PHC707 $_SESSION['fieldNif'] .= "<option value='company'>Company</option><br>"; 708 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>"; 709 $_SESSION['fieldNif'] .= "<option value='state' >State</option><br>"; 710 $_SESSION['fieldNif'] .= "<option value='nif' selected >Billing Nif (Plugin)</option><br>"; 711 } 712 713 ### [Query] - Obtain gama of PHC 716 714 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 717 718 715 //$this->logs->writeFileLog('BackEnd response:', $response); 719 716 … … 728 725 } 729 726 730 //Obtain parameter of manage stock727 ### [Query] - Obtain parameter of manage stock 731 728 $response = $this->utils_services->paramsGetFrontendInfo($ch, $credentials); 732 733 729 //$this->logs->writeFileLog('FrontEnd response:', $response); 734 730 … … 747 743 } 748 744 749 //Obtain type invoices 750 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Td', 'inactivo', 0); 751 752 //$this->logs->writeFileLog('TypeInvoice response:', $response); 745 ### [Query] - Obtain type invoices for PT 746 $response = $this->utils_services->paramsQuery5($ch, $credentials, 'Td', '0','inactivo', 0, '0','isNotTaxRegionPT', 0); 747 //$this->logs->writeFileLog('TypeInvoicePT response:', $response); 753 748 754 749 if (curl_error($ch)) { … … 759 754 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 760 755 $this->logs->writeFileLog('setCommunicationFx3', $response['messages'][0]['messageCodeLocale']); 761 $this->messagesError(" obtaindropdown with type of invoices! Message from Backend: " . $response['messages'][0]['messageCodeLocale']);756 $this->messagesError("Error getting dropdown with type of invoices! Message from Backend: " . $response['messages'][0]['messageCodeLocale']); 762 757 } else { 763 //Create options of dropdownlist invoices 758 759 #1.1 - Create options of dropdownlist invoices for PT 764 760 $i = 0; 765 761 $typeInvoice = array(); 766 $_SESSION['typeOfInvoice'] = ' ';762 $_SESSION['typeOfInvoice'] = ' '; 767 763 768 764 foreach ($response['result'] as $key => $value){ … … 773 769 $selected_dropdown = ''; 774 770 } 775 776 771 $_SESSION['typeOfInvoice'] .= "<option value=" . $value['ndoc'] . " " . $selected_dropdown . ">" . $value['nmdoc'] ."</option><br>"; 777 772 ++$i; 778 773 } 779 774 } 780 #Obtain tax free reason list (for outside of PT) 775 776 ### [Query] - Obtain type invoices for EU 777 $responseEu = $this->utils_services->paramsQuery5($ch, $credentials, 'Td', '0','inactivo', 0, '0','isNotTaxRegionPT', 1); 778 //$this->logs->writeFileLog('TypeInvoiceEU response:', $responseEu); 779 780 if (curl_error($ch)) { 781 $this->logs->writeFileLog('setCommunicationFx3.1', $ch); 782 } else if(empty($response)){ 783 $this->logs->writeFileLog('setCommunicationFx3.1', 'EMPTY RESPONSE'); 784 $this->messagesError("Can't connect to webservice!! There's an empty response for EU series of invoice"); 785 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 786 $this->logs->writeFileLog('setCommunicationFx3.1', $response['messages'][0]['messageCodeLocale']); 787 $this->messagesError("Error getting dropdown with type of invoices for EU! Message from Backend: " . $response['messages'][0]['messageCodeLocale']); 788 } else { 789 790 #1.2 - Create options of dropdownlist invoices for EU 791 $i = 0; 792 $_SESSION['typeOf_EU_Invoice'] = ' '; 793 794 foreach ($responseEu['result'] as $key => $value){ 795 if($value['tiposaft'] == 'FT' || $value['tiposaft'] == 'FS' || $value['tiposaft'] == 'FR'){ 796 if($settings['backend']['typeOf_EU_Invoice'] == $value['ndoc']){ 797 $selected_dropdown = 'selected'; 798 } else { 799 $selected_dropdown = ''; 800 } 801 $_SESSION['typeOf_EU_Invoice'] .= "<option value=" . $value['ndoc'] . " " . $selected_dropdown . ">" . $value['nmdoc'] ."</option><br>"; 802 ++$i; 803 } 804 } 805 } 806 807 ### [Query] - Obtain tax free reason list 781 808 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Miseimp'); 782 783 809 //$this->logs->writeFileLog('Miseimp response:', $response); 784 810 … … 792 818 $this->messagesError(" obtain dropdown with tax free reason list! Message from Backend: " . $response['messages'][0]['messageCodeLocale']); 793 819 } else { 794 //Create options of dropdownlist reasons list 820 821 #2.1 - Create options of dropdownlist reasons list (for outside of PT) 795 822 $i = 0; 796 823 $typeInvoice = array(); … … 803 830 $selected_dropdown = ''; 804 831 } 805 806 832 $_SESSION['typeOfReason'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 807 833 ++$i; 808 834 } 809 } 810 #Obtain tax free reason list (for outside of EU) 811 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Miseimp'); 812 813 //$this->logs->writeFileLog('Miseimp response:', $response); 814 815 if (curl_error($ch)) { 816 $this->logs->writeFileLog('setCommunication3.2.1', $ch); 817 } else if(empty($response)){ 818 $this->logs->writeFileLog('setCommunication3.2.1', 'EMPTY RESPONSE'); 819 $this->messagesError("Can't connect to webservice!! There's an empty response"); 820 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 821 $this->logs->writeFileLog('setCommunication3.2.1', $response['messages'][0]['messageCodeLocale']); 822 $this->messagesError(" obtain dropdown with tax free reason list! Message from Backend: " . $response['messages'][0]['messageCodeLocale']); 823 } else { 824 //Create options of dropdownlist reasons list 835 836 #2.2 - Create options of dropdownlist reasons list (for outside of EU) 825 837 $i = 0; 826 838 $typeInvoice = array(); … … 833 845 $selected_dropdown = ''; 834 846 } 835 836 847 $_SESSION['typeOfReasonEU'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 837 848 ++$i; 838 849 } 839 } 840 #Obtain tax free reason list (for EU Companies) 841 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Miseimp'); 842 843 //$this->logs->writeFileLog('Miseimp response:', $response); 844 845 if (curl_error($ch)) { 846 $this->logs->writeFileLog('setCommunication3.2.2', $ch); 847 } else if(empty($response)){ 848 $this->logs->writeFileLog('setCommunication3.2.2', 'EMPTY RESPONSE'); 849 $this->messagesError("Can't connect to webservice!! There's an empty response"); 850 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 851 $this->logs->writeFileLog('setCommunication3.2.2', $response['messages'][0]['messageCodeLocale']); 852 $this->messagesError(" obtain dropdown with tax free reason list! Message from Backend: " . $response['messages'][0]['messageCodeLocale']); 853 } else { 854 //Create options of dropdownlist reasons list 850 851 #2.3 - Create options of dropdownlist reasons list (for EU Companies) 855 852 $i = 0; 856 853 $typeInvoice = array(); … … 863 860 $selected_dropdown = ''; 864 861 } 865 866 862 $_SESSION['typeOfReasonCO'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 867 863 ++$i; 868 864 } 869 865 } 870 #Obtain services name list 866 867 ### [Query] - Obtain services name list 871 868 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0', 'stns', '1'); 869 //$this->logs->writeFileLog('Services response:', $response); 872 870 873 871 if (curl_error($ch)) { … … 880 878 $this->messagesError(" obtain dropdown with tax free reason list! Message from Backend: " . $response['messages'][0]['messageCodeLocale']); 881 879 } else { 882 //Create options of dropdownlist services list for shipping reference 880 881 #3.1 - Create options of dropdownlist services list for shipping reference 883 882 $i = 0; 884 883 $_SESSION['shippingName'] = ''; … … 894 893 ++$i; 895 894 } 896 //Create options of dropdownlist services list for fees reference 895 896 #3.2 - Create options of dropdownlist services list for fees reference 897 897 $i = 0; 898 898 $_SESSION['feesName'] = ''; … … 910 910 } 911 911 912 #If gama is equal or higher of STAR912 //If gama is equal or higher of STAR 913 913 if($_SESSION['gamaDRIVEFX'] >= 9){ 914 //Obtain type orders 914 915 ### [Query] - Obtain type orders 915 916 $response = $this->utils_services->doubleFilter($ch, $credentials, 'Ts', 'bdempresas', 'CL', 'trfa', '0'); 916 917 917 //$this->logs->writeFileLog('OrderType response:', $response); 918 918 … … 941 941 } 942 942 } else if ($key == "nmdos"){ 943 //Obtain type orders 943 944 ### [Query] - Obtain type orders 944 945 $response2 = $this->utils_services->getInternalDoc($ch, $credentials, 'Bo', 'nmdos', $value); 945 946 946 // $this->logs->writeFileLog('InternalDoc response:', $response2); 947 947 … … 958 958 global $wpdb; 959 959 $table_name = $wpdb->prefix."postmeta"; 960 //Obtain next post_id of order in MySQL 960 961 ### [Query] - Obtain next post_id of order in MySQL 961 962 $query = "SELECT MAX(post_id)+1 as nextPostId FROM %s"; 962 963 $docid = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); … … 982 983 } 983 984 984 //Obtain warehouses985 ### [Query] - Obtain warehouses 985 986 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Sa'); 986 987 987 //$this->logs->writeFileLog('Warehouses response:', $response); 988 988 … … 1033 1033 //Verify if are selected type of internal document and send invoice checkbox 1034 1034 if(isset($settings['backend']['typeOfInvoice']) && $settings['backend']['createInvoice'] == 'on' && $settings['backend']['typeOfInvoice'] > 0 && isset($settings['backend']['sendInvoice'])){ 1035 //Obtain type invoices 1035 1036 ### [Query] - Obtain type invoices 1036 1037 $response = $this->utils_services->paramsGetReportForPrint($ch, $credentials); 1037 1038 1038 //$this->logs->writeFileLog('ReportPrint response:', $response); 1039 1039 … … 1069 1069 } 1070 1070 1071 //Obtain currency coin of company1071 ### [Query] - Obtain currency coin of company 1072 1072 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1073 1074 1073 //$this->logs->writeFileLog('E1 response:', $response); 1075 1074 … … 1816 1815 1817 1816 // Products with VAT included in price 1818 if(($woocommerce_calc_taxes == "no") || ($woocommerce_calc_taxes == "yes" && $woocommerce_prices_include_tax == "yes")) { 1817 if(($woocommerce_calc_taxes == "no") || ($woocommerce_calc_taxes == "yes" && $settings['backend']['includeTaxonSendCost'] == "true")) { 1818 //if(($woocommerce_calc_taxes == "no") || ($woocommerce_calc_taxes == "yes" && $woocommerce_prices_include_tax == "yes")) { 1819 1819 1820 1820 if ($settings['backend']['positiveStock'] == 'on'){ … … 1824 1824 } 1825 1825 1826 //$this->logs->writeFileLog('StList response1:', $response);1826 //$this->logs->writeFileLog('StList with tax:', $response); 1827 1827 1828 1828 } 1829 1829 // Products without VAT included in price 1830 else if($woocommerce_calc_taxes == "yes" && $woocommerce_prices_include_tax == 'no'){ 1830 else if($woocommerce_calc_taxes == "yes" && $settings['backend']['includeTaxonSendCost'] == "false"){ 1831 //else if($woocommerce_calc_taxes == "yes" && $woocommerce_prices_include_tax == 'no'){ 1831 1832 1832 1833 if ($settings['backend']['positiveStock'] == 'on'){ … … 1836 1837 } 1837 1838 1838 //$this->logs->writeFileLog('StList response2:', $response);1839 //$this->logs->writeFileLog('StList without tax:', $response); 1839 1840 1840 1841 } -
drivefx-woocommerce/trunk/settings/backend.php
r2526532 r2556290 180 180 </tr> 181 181 <?php } break; 182 // Type of Invoice 182 // Type of Invoice PT 183 183 case 'typeOfInvoice': 184 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 185 <tr> 186 <th scope="row"> 187 <label for="<?php echo $id ?>"><?php echo $opts['label'] ?></label> 188 </th> 189 <td> 190 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 191 <?php if(!empty($_SESSION[$id])){ ?> 192 <option value="0">Select one...</option> 193 <?php } 194 echo $_SESSION[$id]; ?> 195 </td> 196 </tr> 197 <?php } break; 198 case 'typeOf_EU_Invoice': 184 199 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 185 200 <tr> -
drivefx-woocommerce/trunk/settings/syncro_gate.php
r2547406 r2556290 1 1 <?php 2 2 require_once __DIR__.'/../includes/class-wc-order-item-tax.php'; 3 3 require_once __DIR__.'/../PHCLibrary/log.php'; 4 4 require_once __DIR__.'/../PHCLibrary/utils.php'; … … 22 22 } 23 23 24 /***************************************************************** 25 * --- CREDENTIALS --- *24 /****************************************************************** 25 * --- CREDENTIALS --- * 26 26 ******************************************************************/ 27 public function fetchCredentials(){ 28 29 $credentials = new stdClass(); 30 31 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 32 33 // get token 34 global $wpdb; 35 $table_name = $wpdb->prefix."postmeta"; 36 $query = "SELECT meta_value FROM %s WHERE meta_key = %s"; 37 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token'))); 38 39 // build our web service full URL 40 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 41 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 42 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 43 44 // build credencials 45 $credentials->backendUrl = $settings['backend']['url'].$this->extraurl; 46 $credentials->userCode = $settings['backend']['username']; 47 $credentials->password = $settings['backend']['password']; 48 $credentials->appId = $resultDB->meta_value; 49 $credentials->company = $settings['backend']['dbname']; 50 $credentials->invoiceType = $settings['backend']['typeOfInvoice']; 51 52 return $credentials; 53 54 } 27 public function fetchCredentials(){ 28 29 $credentials = new stdClass(); 30 31 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 32 33 // get token 34 global $wpdb; 35 $table_name = $wpdb->prefix."postmeta"; 36 $query = "SELECT meta_value FROM %s WHERE meta_key = %s"; 37 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token'))); 38 39 // build our web service full URL 40 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 41 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 42 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 43 44 // build credencials 45 $credentials->backendUrl = $settings['backend']['url'].$this->extraurl; 46 $credentials->userCode = $settings['backend']['username']; 47 $credentials->password = $settings['backend']['password']; 48 $credentials->appId = $resultDB->meta_value; 49 $credentials->company = $settings['backend']['dbname']; 50 $credentials->invoiceType = $settings['backend']['typeOfInvoice']; 51 $credentials->invoiceType_EU = $settings['backend']['typeOf_EU_Invoice']; 52 53 return $credentials; 54 55 } 55 56 56 57 … … 59 60 * --- Collect Data --- * 60 61 *******************************************************************/ 61 public function fetchOrderData($order_id) { 62 //get backendinfo from woocommerce 63 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 64 65 #Get billind data query 66 global $wpdb; 67 $table_name = $wpdb->prefix."postmeta"; 68 $query = "SELECT meta_key, meta_value FROM %s where post_id = %d"; 69 $raw_order = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($order_id)))); 70 71 //get NIF name field from backendinfo 72 $nifName = '_billing_'.$settings['backend']['fieldNif']; 73 //get price column field from backendinfo 74 $preco = intval(str_replace('epv', '', $settings['backend']['productPriceColumn'])); 75 76 $syncroData = new stdClass(); 77 78 /******************************************************************* 79 * --- billing data --- * 80 ********************************************************************/ 81 82 foreach ($raw_order as $key => $value) { 83 if($value->meta_key == '_billing_country'){ 84 $syncroData->billing_country = $value->meta_value; 85 } else if($value->meta_key == '_billing_first_name') { 86 $syncroData->billing_first_name = $value->meta_value; 87 } else if($value->meta_key == '_billing_last_name') { 88 $syncroData->billing_last_name = $value->meta_value; 89 } else if($value->meta_key == '_billing_address_1') { 90 $syncroData->billing_address_1 = $value->meta_value; 91 } else if($value->meta_key == '_billing_city') { 92 $syncroData->billing_city = $value->meta_value; 93 } else if($value->meta_key == '_billing_postcode') { 94 $syncroData->billing_postcode = $value->meta_value; 95 } else if($value->meta_key == $nifName) { 96 $syncroData->$nifName = $value->meta_value; 97 } else if($value->meta_key == '_billing_email') { 98 $syncroData->billing_email = $value->meta_value; 99 } else if($value->meta_key == '_billing_phone') { 100 $syncroData->billing_phone = $value->meta_value; 101 } else if($value->meta_key == '_shipping_country') { 102 $syncroData->shipping_country = $value->meta_value; 103 } else if($value->meta_key == '_shipping_address_1') { 104 $syncroData->shipping_address_1 = $value->meta_value; 105 } else if($value->meta_key == '_shipping_city') { 106 $syncroData->shipping_city = $value->meta_value; 107 } else if($value->meta_key == '_shipping_postcode') { 108 $syncroData->shipping_postcode = $value->meta_value; 109 } else if($value->meta_key == '_customer_user') { 110 $syncroData->customer_user = $value->meta_value; 111 } 112 } 113 114 /******************************************************************* 115 * --- settings backend Data --- * 116 ********************************************************************/ 117 118 if(isset($settings['backend']['createInvoice'])){ 119 $createInvoice = $settings['backend']['createInvoice']; 120 if($createInvoice == 'on'){ 121 $syncroData->createInvoice = true; 122 } 123 } 124 if(isset($settings['backend']['typeOfInvoice'])) { 125 $syncroData->typeOfInvoice = $settings['backend']['typeOfInvoice']; 126 } 127 if(isset($settings['backend']['toSignInvoice'])) { 128 $toSignInvoice = $settings['backend']['toSignInvoice']; 129 if($toSignInvoice == 'on'){ 130 $syncroData->toSignInvoice = true; 131 } 132 } 133 if(isset($settings['backend']['fieldNif'])) { 134 $syncroData->fieldNif = $settings['backend']['fieldNif']; 135 } 136 if(isset($settings['backend']['includeTaxonSendCost'])) { 137 $syncroData->includeTaxonSendCost = $settings['backend']['includeTaxonSendCost']; 138 } 139 if(isset($settings['backend']['createExemptPT'])) { 140 $createExemptPT = $settings['backend']['createExemptPT']; 141 if($createExemptPT == 'on'){ 142 $syncroData->createExemptPT = true; 143 } 144 } 145 if(isset($settings['backend']['createExemptEU'])) { 146 $createExemptEU = $settings['backend']['createExemptEU']; 147 if($createExemptEU == 'on'){ 148 $syncroData->createExemptEU = true; 149 } 150 } 151 if(isset($settings['backend']['createExemptCO'])) { 152 $createExemptCO = $settings['backend']['createExemptCO']; 153 if($createExemptCO == 'on'){ 154 $syncroData->createExemptCO = true; 155 } 156 } 157 if(isset($settings['backend']['typeOfCountry'])) { 158 $syncroData->typeOfCountry = $settings['backend']['typeOfCountry']; 159 } 160 if(isset($settings['backend']['typeOfReason'])) { 161 $syncroData->typeOfReason = $settings['backend']['typeOfReason']; 162 } 163 if(isset($settings['backend']['typeOfReasonEU'])) { 164 $syncroData->typeOfReasonEU = $settings['backend']['typeOfReasonEU']; 165 } 166 if(isset($settings['backend']['typeOfReasonCO'])) { 167 $syncroData->typeOfReasonCO = $settings['backend']['typeOfReasonCO']; 168 } 169 if(isset($settings['backend']['warehouseOrder'])) { 170 $syncroData->warehouseOrder = $settings['backend']['warehouseOrder']; 171 } 172 if(isset($settings['backend']['typeOfOrder'])) { 173 $syncroData->typeOfOrder = $settings['backend']['typeOfOrder']; 174 } 175 if(isset($settings['backend']['toSignOrder'])) { 176 $toSignOrder = $settings['backend']['toSignOrder']; 177 if($toSignOrder == 'on'){ 178 $syncroData->toSignOrder = true; 179 } 180 } 181 if(isset($settings['backend']['numberOfOrder'])) { 182 $syncroData->numberOfOrder = $settings['backend']['numberOfOrder']; 183 } 184 if(isset($settings['backend']['statusOfOrder'])) { 185 $syncroData->statusOfOrder = $settings['backend']['statusOfOrder']; 186 } 187 if(isset($settings['backend']['shippingName'])) { 188 $syncroData->shippingName = $settings['backend']['shippingName']; 189 } 190 if(isset($settings['backend']['feesName'])) { 191 $syncroData->feesName = $settings['backend']['feesName']; 192 } 193 if(isset($settings['backend']['manageStock'])) { 194 $manageStock = $settings['backend']['manageStock']; 195 if($manageStock == 'on'){ 196 $syncroData->manageStock = true; 197 } 198 } 199 if(isset($settings['backend']['productPriceColumn'])) { 200 $syncroData->productPriceColumn = $preco; 201 } 202 if(isset($settings['backend']['warehouse'])) { 203 $syncroData->warehouse = $settings['backend']['warehouse']; 204 } 205 if(isset($settings['backend']['sendInvoice'])) { 206 $syncroData->sendInvoice = $settings['backend']['sendInvoice']; 207 } 208 209 210 /******************************************************************* 211 * --- Users Data --- * 212 ********************************************************************/ 213 #Get users data query 214 //Obtain customer ID to obtain email in Woocommerce Users 215 global $wpdb; 216 $table_name = $wpdb->prefix."users"; 217 //Obtain next post_id of order in MySQL 218 $query = "SELECT user_email FROM %s WHERE id = %d"; 219 $docid = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($syncroData->customer_user)))); 220 $syncroData->user_email = $docid[0]->user_email; 221 222 #Get POST Id for current order 62 public function fetchOrderData($order_id) { 63 //get backendinfo from woocommerce 64 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 65 66 #Get billind data query 223 67 global $wpdb; 224 68 $table_name = $wpdb->prefix."postmeta"; 225 //Obtain post_id of order in MySQL 226 $query = "SELECT MAX(post_id) as postId FROM %s"; 227 $post_docid = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 228 //Post Id 229 $syncroData->post_ID = sanitize_text_field($post_docid->postId); 230 231 if($syncroData->post_ID == ''){ 232 $post_ID = sanitize_text_field($order_id); 233 } 234 235 //Obtain doc ID based in order 236 $docid = get_post_meta($syncroData->post_ID); 237 238 $syncroData->docId = $docid['_docid'][0]; 239 $syncroData->orderId = sanitize_text_field($order_id); 240 241 #Customer notes 242 $syncroData->obs = $_REQUEST['order_comments']; 243 244 #Get Currency from woocommerce 245 $syncroData->wooCurrency = get_option('woocommerce_currency'); 246 247 #get order received endpoint from woocommerce 248 $syncroData->order_received = get_option('woocommerce_checkout_order_received_endpoint'); 249 250 251 #nextPostId 252 global $wpdb; 253 $table_name = $wpdb->prefix."postmeta"; 254 //Obtain next post_id of order in MySQL 255 $query = "SELECT MAX(post_id) as nextPostId FROM %s"; 256 $packDocId = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 257 258 //Save nextPostId 259 $syncroData->nextPostId = $packDocId->nextPostId; 260 261 /******************************************************************* 262 * --- Order Shipping Data --- * 263 ********************************************************************/ 264 265 # shipping data (Queries) 266 267 $table_name = $wpdb->prefix."woocommerce_order_items"; 268 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'shipping'"; 269 $resultShipping = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 270 //get tax value for shipping 271 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 272 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'total_tax'"; 273 $resultTax = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 274 //get shipping tax rate 275 $getShippingTax = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_shipping='1'" ) ); 276 //get shipping tax rate country 277 //$getShippingCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_shipping='1'" ) ); 278 //get value 279 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 280 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'cost'"; 281 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 282 283 284 # Fetch shipping data 285 286 if(isset($resultShipping)) { 287 $syncroData->shipping_name = $resultShipping->order_item_name; 288 } 289 if(isset($resultTax)) { 290 $syncroData->shipping_taxValue = $resultTax->meta_value; 291 } 292 if(isset($getShippingTax)) { 293 $syncroData->shipping_tax = $getShippingTax; 294 } 295 /* if(isset($getShippingCountry)) { 296 $syncroData->shipping_country = $getShippingCountry; 297 } */ 298 if(isset($resultDB)) { 299 $syncroData->shipping_value = $resultDB->meta_value; 300 } 301 302 #Find the type of shipment 303 $post = get_post( $_REQUEST['shipping_method'][0] ); 304 305 $syncroData->post_title = isset( $post->post_title ) ? $post->post_title : ''; 306 $syncroData->edescc = WC()->cart->coupon_discount_amounts['saco']; 307 308 309 310 /******************************************************************* 311 * --- Order Fees Data --- * 312 ********************************************************************/ 313 //build common object 314 $boFeesPack = new stdClass(); 315 $bofees = []; 316 317 # fees data (Queries) 318 319 //get fee from mysql 320 $table_name = $wpdb->prefix."woocommerce_order_items"; 321 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'fee'"; 322 $resultsFee_bo = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 323 //get fee value from mysql 324 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 325 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = '_line_total'"; 326 327 #Obtain name and price of fees 328 foreach ($resultsFee_bo as $resultFee_bo) { 329 $resulBoDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFee_bo->order_item_id))); 330 331 $boFee_name = $resultFee_bo->order_item_name; 332 $boFee_value = $resulBoDB->meta_value; 333 334 array_push($bofees,[ 335 'name' => $boFee_name, 336 'value' => $boFee_value 337 ]); 338 339 } 340 $boFeesPack = $bofees; 341 $syncroData->fees_bo = $boFeesPack; 342 343 # Fetch fees data 344 345 if(isset($resultFee)) { 346 $syncroData->fee_name = $resultFee->order_item_name; 347 } 348 if(isset($resultFeeValue)) { 349 $syncroData->fee_value = $resultFeeValue->meta_value; 350 } 351 352 353 354 /******************************************************************* 355 * --- Invoice Data --- * 356 ********************************************************************/ 357 358 #get country for Ft 359 $order_meta = get_post_meta($order_id); 360 361 $syncroData->$bill_country_ft = $order_meta['_billing_country'][0]; 362 363 if($syncroData->billing_country != ''){ 364 $syncroData->billing_country_ft = $syncroData->billing_country; 365 } else { 366 $syncroData->billing_country_ft = sanitize_text_field( $_REQUEST['_billing_country'] ); 367 } 368 369 #get Billing data 370 $syncroData->billing_first_name_ft = $order_meta['_billing_first_name'][0]; 371 $syncroData->billing_last_name_ft = $order_meta['_billing_last_name'][0]; 372 $syncroData->billing_email_ft = $order_meta['_billing_email'][0]; 373 $syncroData->billing_address_1_ft = $order_meta['_billing_address_1'][0]; 374 $syncroData->billing_city_ft = $order_meta['_billing_city'][0]; 375 $syncroData->billing_phone_ft = $order_meta['_billing_phone'][0]; 376 $syncroData->billing_postcode_ft = $order_meta['_billing_postcode'][0]; 377 $syncroData->billing_nif_ft = $order_meta['_billing_'.$settings['backend']['fieldNif']][0]; 378 379 380 /******************************************************************* 381 * --- Invoice Shipping Data --- * 382 ********************************************************************/ 383 //Obtain id of order and products 384 $order = new WC_Order($orderid); 385 $syncroData->nOrder = $order->post->ID; 386 387 # shipping data (Queries) 388 global $wpdb; 389 $table_name = $wpdb->prefix."woocommerce_order_items"; 390 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'shipping'"; 391 $resultsFtShipping = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $syncroData->nOrder))); 392 393 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 394 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'cost'"; 395 //Obtain name and price of delivery 396 foreach ($resultsFtShipping as $resultFtShipping) { 397 $resultFtDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFtShipping->order_item_id))); 398 399 $syncroData->ftShipping_name = $resultFtShipping->order_item_name; 400 $syncroData->ftShipping_value = $resultFtDB->meta_value; 401 } 402 403 #get shipping country for ft 404 if($syncroData->shipping_country != ''){ 405 $syncroData->shipping_country_ft = $syncroData->shipping_country; 406 } else { 407 $syncroData->shipping_country_ft = $order_meta['_shipping_country'][0]; 408 if($syncroData->shipping_country_ft == ''){ 409 $syncroData->shipping_country_ft = $syncroData->$bill_country_ft; 410 } 411 } 412 413 /******************************************************************* 414 * --- Invoice Addicional Fees Data --- * 415 ********************************************************************/ 416 417 //Obtain id of order and products 418 $order = new WC_Order($orderid); 419 $orderPostId = $order->post->ID; 420 //build common object 421 $addPack = new stdClass(); 422 $fees = []; 423 424 # fees data (Queries) 425 global $wpdb; 426 $table_name = $wpdb->prefix."woocommerce_order_items"; 427 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type='fee'"; 428 $resultsFees_ft = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $orderPostId))); 429 430 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 431 $query = "SELECT * FROM %s WHERE order_item_id = %s and (meta_key = 'cost' or meta_key='_line_total')"; 432 433 #Obtain name and price of fees 434 foreach ($resultsFees_ft as $resultFees_ft) { 435 $resultFtDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFees_ft->order_item_id))); 436 437 $fee_name = $resultFees_ft->order_item_name; 438 $fee_value = $resultFtDB->meta_value; 439 440 array_push($fees,[ 441 'name' => $fee_name, 442 'value' => $fee_value 443 ]); 444 445 } 446 447 $addPack = $fees; 448 $syncroData->fees_ft = $addPack; 449 450 //$this->logs->writeFileLog('syncroData', $syncroData); 451 452 return $syncroData; 453 } 69 $query = "SELECT meta_key, meta_value FROM %s where post_id = %d"; 70 $raw_order = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($order_id)))); 71 72 //$this->logs->writeFileLog('raw_order', $raw_order); 73 74 //get NIF name field (billing) from backendinfo 75 $ft_nifName = '_billing_'.$settings['backend']['fieldNif']; 76 77 //get NIF name field (shipping) from backendinfo 78 $ship_nifName = '_shipping_'.$settings['backend']['fieldNif']; 79 80 //get price column field from backendinfo 81 $preco = intval(str_replace('epv', '', $settings['backend']['productPriceColumn'])); 82 83 $syncroData = new stdClass(); 84 85 /******************************************************************* 86 * --- billing data --- * 87 ********************************************************************/ 88 89 foreach ($raw_order as $key => $value) { 90 if($value->meta_key == '_billing_country'){ 91 $syncroData->billing_country = $value->meta_value; 92 } else if($value->meta_key == '_billing_first_name') { 93 $syncroData->billing_first_name = $value->meta_value; 94 } else if($value->meta_key == '_billing_last_name') { 95 $syncroData->billing_last_name = $value->meta_value; 96 } else if($value->meta_key == '_billing_address_1') { 97 $syncroData->billing_address_1 = $value->meta_value; 98 } else if($value->meta_key == '_billing_city') { 99 $syncroData->billing_city = $value->meta_value; 100 } else if($value->meta_key == '_billing_postcode') { 101 $syncroData->billing_postcode = $value->meta_value; 102 } else if($value->meta_key == $ft_nifName) { 103 $syncroData->ft_nifName = $value->meta_value; 104 } else if($value->meta_key == '_billing_email') { 105 $syncroData->billing_email = $value->meta_value; 106 } else if($value->meta_key == '_billing_phone') { 107 $syncroData->billing_phone = $value->meta_value; 108 } else if($value->meta_key == '_shipping_country') { 109 $syncroData->shipping_country = $value->meta_value; 110 } else if($value->meta_key == '_shipping_first_name') { 111 $syncroData->shipping_first_name = $value->meta_value; 112 } else if($value->meta_key == '_shipping_last_name') { 113 $syncroData->shipping_last_name = $value->meta_value; 114 } else if($value->meta_key == $ship_nifName) { 115 $syncroData->ship_nifName = $value->meta_value; 116 } else if($value->meta_key == '_shipping_address_1') { 117 $syncroData->shipping_address_1 = $value->meta_value; 118 } else if($value->meta_key == '_shipping_city') { 119 $syncroData->shipping_city = $value->meta_value; 120 } else if($value->meta_key == '_shipping_postcode') { 121 $syncroData->shipping_postcode = $value->meta_value; 122 } else if($value->meta_key == '_customer_user') { 123 $syncroData->customer_user = $value->meta_value; 124 } 125 } 126 127 /******************************************************************* 128 * --- settings backend Data --- * 129 ********************************************************************/ 130 131 if(isset($settings['backend']['createInvoice'])){ 132 $createInvoice = $settings['backend']['createInvoice']; 133 if($createInvoice == 'on'){ 134 $syncroData->createInvoice = true; 135 } 136 } 137 if(isset($settings['backend']['typeOfInvoice'])) { 138 $syncroData->typeOfInvoice = $settings['backend']['typeOfInvoice']; 139 } 140 if(isset($settings['backend']['typeOf_EU_Invoice'])) { 141 $syncroData->typeOf_EU_Invoice = $settings['backend']['typeOf_EU_Invoice']; 142 } 143 if(isset($settings['backend']['toSignInvoice'])) { 144 $toSignInvoice = $settings['backend']['toSignInvoice']; 145 if($toSignInvoice == 'on'){ 146 $syncroData->toSignInvoice = true; 147 } 148 } 149 if(isset($settings['backend']['fieldNif'])) { 150 $syncroData->fieldNif = $settings['backend']['fieldNif']; 151 } 152 if(isset($settings['backend']['includeTaxonSendCost'])) { 153 $syncroData->includeTaxonSendCost = $settings['backend']['includeTaxonSendCost']; 154 } 155 if(isset($settings['backend']['createExemptPT'])) { 156 $createExemptPT = $settings['backend']['createExemptPT']; 157 if($createExemptPT == 'on'){ 158 $syncroData->createExemptPT = true; 159 } 160 } 161 if(isset($settings['backend']['createExemptEU'])) { 162 $createExemptEU = $settings['backend']['createExemptEU']; 163 if($createExemptEU == 'on'){ 164 $syncroData->createExemptEU = true; 165 } 166 } 167 if(isset($settings['backend']['createExemptCO'])) { 168 $createExemptCO = $settings['backend']['createExemptCO']; 169 if($createExemptCO == 'on'){ 170 $syncroData->createExemptCO = true; 171 } 172 } 173 if(isset($settings['backend']['typeOfCountry'])) { 174 $syncroData->typeOfCountry = $settings['backend']['typeOfCountry']; 175 } 176 if(isset($settings['backend']['typeOfReason'])) { 177 $syncroData->typeOfReason = $settings['backend']['typeOfReason']; 178 } 179 if(isset($settings['backend']['typeOfReasonEU'])) { 180 $syncroData->typeOfReasonEU = $settings['backend']['typeOfReasonEU']; 181 } 182 if(isset($settings['backend']['typeOfReasonCO'])) { 183 $syncroData->typeOfReasonCO = $settings['backend']['typeOfReasonCO']; 184 } 185 if(isset($settings['backend']['warehouseOrder'])) { 186 $syncroData->warehouseOrder = $settings['backend']['warehouseOrder']; 187 } 188 if(isset($settings['backend']['typeOfOrder'])) { 189 $syncroData->typeOfOrder = $settings['backend']['typeOfOrder']; 190 } 191 if(isset($settings['backend']['toSignOrder'])) { 192 $toSignOrder = $settings['backend']['toSignOrder']; 193 if($toSignOrder == 'on'){ 194 $syncroData->toSignOrder = true; 195 } 196 } 197 if(isset($settings['backend']['numberOfOrder'])) { 198 $syncroData->numberOfOrder = $settings['backend']['numberOfOrder']; 199 } 200 if(isset($settings['backend']['statusOfOrder'])) { 201 $syncroData->statusOfOrder = $settings['backend']['statusOfOrder']; 202 } 203 if(isset($settings['backend']['shippingName'])) { 204 $syncroData->shippingName = $settings['backend']['shippingName']; 205 } 206 if(isset($settings['backend']['feesName'])) { 207 $syncroData->feesName = $settings['backend']['feesName']; 208 } 209 if(isset($settings['backend']['manageStock'])) { 210 $manageStock = $settings['backend']['manageStock']; 211 if($manageStock == 'on'){ 212 $syncroData->manageStock = true; 213 } 214 } 215 if(isset($settings['backend']['productPriceColumn'])) { 216 $syncroData->productPriceColumn = $preco; 217 } 218 if(isset($settings['backend']['warehouse'])) { 219 $syncroData->warehouse = $settings['backend']['warehouse']; 220 } 221 if(isset($settings['backend']['sendInvoice'])) { 222 $syncroData->sendInvoice = $settings['backend']['sendInvoice']; 223 } 224 225 226 /******************************************************************* 227 * --- Company/Users Data --- * 228 ********************************************************************/ 229 #Get users data query 230 //Obtain customer ID to obtain email in Woocommerce Users 231 global $wpdb; 232 $table_name = $wpdb->prefix."users"; 233 //Obtain next post_id of order in MySQL 234 $query = "SELECT user_email FROM %s WHERE id = %d"; 235 $docid = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($syncroData->customer_user)))); 236 $syncroData->user_email = $docid[0]->user_email; 237 238 #Get POST Id for current order 239 global $wpdb; 240 $table_name = $wpdb->prefix."postmeta"; 241 //Obtain post_id of order in MySQL 242 $query = "SELECT MAX(post_id) as postId FROM %s"; 243 $post_docid = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 244 //Post Id 245 $syncroData->post_ID = sanitize_text_field($post_docid->postId); 246 247 if($syncroData->post_ID == ''){ 248 $post_ID = sanitize_text_field($order_id); 249 } 250 251 //Obtain doc ID based in order 252 $docid = get_post_meta($syncroData->post_ID); 253 254 $syncroData->docId = $docid['_docid'][0]; 255 $syncroData->orderId = sanitize_text_field($order_id); 256 257 #Customer notes 258 $syncroData->obs = $_REQUEST['order_comments']; 259 260 #Get Currency from woocommerce 261 $syncroData->wooCurrency = get_option('woocommerce_currency'); 262 263 #get order received endpoint from woocommerce 264 $syncroData->order_received = get_option('woocommerce_checkout_order_received_endpoint'); 265 266 #get company country from woocommerce 267 $syncroData->companyCountry = WC()->countries->countries[WC()->countries->get_base_country()]; 268 269 #get order tax rate country 270 $getTaxName = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM ".$wpdb->prefix."woocommerce_order_itemmeta WHERE meta_key='label' ORDER BY order_item_id DESC " ) ); 271 $syncroData->taxCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_name='".$getTaxName."' LIMIT 1" ) ); 272 273 #nextPostId 274 global $wpdb; 275 $table_name = $wpdb->prefix."postmeta"; 276 //Obtain next post_id of order in MySQL 277 $query = "SELECT MAX(post_id) as nextPostId FROM %s"; 278 $packDocId = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 279 280 //Save nextPostId 281 $syncroData->nextPostId = $packDocId->nextPostId; 282 283 /******************************************************************* 284 * --- Order Shipping Data --- * 285 ********************************************************************/ 286 287 # shipping data (Queries) 288 289 $table_name = $wpdb->prefix."woocommerce_order_items"; 290 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'shipping'"; 291 $resultShipping = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 292 //get tax value for shipping 293 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 294 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'total_tax'"; 295 $resultTax = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 296 //get shipping tax value 297 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 298 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'cost'"; 299 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 300 301 #Shipping Tax Rate 302 $shipping_tax_rate_id; 303 foreach ( WC()->shipping->get_packages() as $key => $package) { 304 // Loop through Shipping rates 305 foreach($package['rates'] as $rate_id => $rate ){ 306 // get shipping taxes array 307 $shipping_taxes = $rate->get_taxes(); 308 309 foreach ($shipping_taxes as $key => $value){ 310 if(!empty($value)){ 311 // get shipping tax rate ID 312 $shipping_tax_rate_id = $key; 313 } 314 } 315 } 316 } 317 318 if(!empty($shipping_tax_rate_id)){ 319 // order shipping tax rate 320 $getShippingTax = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$shipping_tax_rate_id."' LIMIT 1")); 321 } else { 322 //$this->logs->writeFileLog('Warning', 'Can not obtain the tax rate ID for shipping, so we apply manual calculation'); 323 } 324 325 # Fetch shipping data 326 if(isset($resultShipping)) { 327 $syncroData->shipping_name = $resultShipping->order_item_name; 328 } 329 if(isset($resultTax)) { 330 $syncroData->shipping_taxValue = $resultTax->meta_value; 331 } 332 if(isset($getShippingTax)) { 333 $syncroData->shipping_tax = $getShippingTax; 334 } else { 335 $syncroData->shipping_tax = $syncroData->shipping_taxValue / $resultDB->meta_value * 100; 336 } 337 if($settings['backend']['includeTaxonSendCost']=="true"){ 338 if(isset($resultDB)) { 339 $syncroData->shipping_value = $resultDB->meta_value + $resultTax->meta_value; 340 } 341 } else { 342 if(isset($resultDB)) { 343 $syncroData->shipping_value = $resultDB->meta_value; 344 } 345 } 346 347 348 #Find the type of shipment 349 $post = get_post( $_REQUEST['shipping_method'][0] ); 350 351 $syncroData->post_title = isset( $post->post_title ) ? $post->post_title : ''; 352 $syncroData->edescc = WC()->cart->coupon_discount_amounts['saco']; 353 354 355 /******************************************************************* 356 * --- Order Fees Data --- * 357 ********************************************************************/ 358 //build common object 359 $boFeesPack = new stdClass(); 360 $bofees = []; 361 362 # fees data (Queries) 363 364 //get fee from mysql 365 $table_name = $wpdb->prefix."woocommerce_order_items"; 366 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'fee'"; 367 $resultsFee_bo = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 368 //get fee value from mysql 369 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 370 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = '_line_total'"; 371 372 #Obtain name and price of fees 373 foreach ($resultsFee_bo as $resultFee_bo) { 374 $resulBoDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFee_bo->order_item_id))); 375 376 $boFee_name = $resultFee_bo->order_item_name; 377 $boFee_value = $resulBoDB->meta_value; 378 379 array_push($bofees,[ 380 'name' => $boFee_name, 381 'value' => $boFee_value 382 ]); 383 384 } 385 $boFeesPack = $bofees; 386 $syncroData->fees_bo = $boFeesPack; 387 388 # Fetch fees data 389 390 if(isset($resultFee)) { 391 $syncroData->fee_name = $resultFee->order_item_name; 392 } 393 if(isset($resultFeeValue)) { 394 $syncroData->fee_value = $resultFeeValue->meta_value; 395 } 396 397 398 399 /******************************************************************* 400 * --- Invoice Data --- * 401 ********************************************************************/ 402 403 #get country for Ft 404 $order_meta = get_post_meta($order_id); 405 406 $syncroData->$bill_country_ft = $order_meta['_billing_country'][0]; 407 408 if($syncroData->billing_country != ''){ 409 $syncroData->billing_country_ft = $syncroData->billing_country; 410 } else { 411 $syncroData->billing_country_ft = sanitize_text_field( $_REQUEST['_billing_country'] ); 412 } 413 414 #get Billing data 415 $syncroData->billing_first_name_ft = $order_meta['_billing_first_name'][0]; 416 $syncroData->billing_last_name_ft = $order_meta['_billing_last_name'][0]; 417 $syncroData->billing_email_ft = $order_meta['_billing_email'][0]; 418 $syncroData->billing_address_1_ft = $order_meta['_billing_address_1'][0]; 419 $syncroData->billing_city_ft = $order_meta['_billing_city'][0]; 420 $syncroData->billing_phone_ft = $order_meta['_billing_phone'][0]; 421 $syncroData->billing_postcode_ft = $order_meta['_billing_postcode'][0]; 422 $syncroData->billing_nif_ft = $order_meta['_billing_'.$settings['backend']['fieldNif']][0]; 423 424 425 /******************************************************************* 426 * --- Invoice Shipping Data --- * 427 ********************************************************************/ 428 429 /* To avoid repetitive code, 430 data is taken from "Order Shipping Data" */ 431 432 /******************************************************************* 433 * --- Invoice Addicional Fees Data --- * 434 ********************************************************************/ 435 436 //Obtain id of order and products 437 $order = new WC_Order($orderid); 438 $orderPostId = $order->post->ID; 439 //build common object 440 $addPack = new stdClass(); 441 $fees = []; 442 443 # fees data (Queries) 444 global $wpdb; 445 $table_name = $wpdb->prefix."woocommerce_order_items"; 446 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type='fee'"; 447 $resultsFees_ft = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $orderPostId))); 448 449 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 450 $query = "SELECT * FROM %s WHERE order_item_id = %s and (meta_key = 'cost' or meta_key='_line_total')"; 451 452 #Obtain name and price of fees 453 foreach ($resultsFees_ft as $resultFees_ft) { 454 $resultFtDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFees_ft->order_item_id))); 455 456 $fee_name = $resultFees_ft->order_item_name; 457 $fee_value = $resultFtDB->meta_value; 458 459 array_push($fees,[ 460 'name' => $fee_name, 461 'value' => $fee_value 462 ]); 463 464 } 465 466 $addPack = $fees; 467 $syncroData->fees_ft = $addPack; 468 469 //$this->logs->writeFileLog('syncroData', $syncroData); 470 471 return $syncroData; 472 } 454 473 455 474 /******************************************************************* … … 546 565 $product['design'] = $wc_product->get_name(); 547 566 548 549 # get product tax rate country & order tax rate 550 // product id 551 $getProductId = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $product['ref'] ) ); 552 // product From id 553 $getProduct = wc_get_product($getProductId); 554 // product tax rate country 555 $getTaxCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_class='%s' LIMIT 1", $getProduct->get_tax_class() ) ); 556 // order tax rate 557 $getTaxOrder = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM ".$wpdb->prefix."woocommerce_order_itemmeta WHERE meta_key='rate_percent' ORDER BY order_item_id DESC " ) ); 567 // order tax rate country 568 $getTaxID = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM ".$wpdb->prefix."woocommerce_order_itemmeta WHERE meta_key='rate_id' ORDER BY order_item_id DESC LIMIT 1" ) ); 569 $getTaxCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$getTaxID."' LIMIT 1" ) ); 570 571 //order Item ID 572 $getOrderItemID = $wpdb->get_var( $wpdb->prepare("SELECT order_item_id FROM ".$wpdb->prefix."woocommerce_order_items WHERE order_item_name ='".$product['design']."' and order_item_type = 'line_item' and order_id = '".$orderid."' LIMIT 1" ) ); 573 //order Item product by order Item ID 574 $item = new WC_Order_Item_Product($getOrderItemID); 575 576 //$this->logs->writeFileLog('item', $item); 577 578 // The product name 579 $item_name = $item->get_name(); 580 581 if($item_name == $product['design']){ 582 //get taxes array for item 583 $taxes = $item->get_taxes(); 584 $taxes_total = $taxes['total']; 585 586 foreach ($taxes_total as $key => $value){ 587 if(isset($value)){ 588 // get tax rate ID 589 $tax_rate_id = $key; 590 } 591 } 592 593 if(!empty($tax_rate_id)){ 594 // order item tax rate 595 $getTaxOrder = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$tax_rate_id."' LIMIT 1")); 596 } else { 597 $this->logs->writeFileLog('Warning', 'check the way to obtain the tax rate for items'); 598 } 599 } else { 600 $this->logs->writeFileLog('Warning', 'problem to find the products for check tax rates'); 601 } 558 602 559 603 if (isset($getTaxCountry)){ 560 604 $product['tax_country'] = $getTaxCountry; 561 605 } 562 if (isset($getTaxCountry)){606 if (isset($getTaxOrder)){ 563 607 $product['tax_rate'] = $getTaxOrder; 564 608 } 565 609 } 566 610 } 567 568 611 569 612 //fulfill "prodpack" with all data … … 627 670 'epv' => $valueItem, 628 671 'design' => '', 629 'etiliquido' => '' 672 'etiliquido' => '', 673 'tax_country' => '', 674 'tax_rate' => '' 630 675 ]); 631 676 } 632 677 //Save items of cart 633 678 $this->setFtProductsSession($ftProducts); 634 635 679 636 680 //FT from Backend if is clicked "button tip" … … 653 697 'design' => '', 654 698 'etiliquido' => '', 655 699 'tax_country' => '', 700 'tax_rate' => '' 656 701 ]); 657 702 } … … 663 708 foreach ($ftProducts as &$product) { 664 709 if($product['qtt']*$product['epv'] != 0){ 665 # get product ref & design666 global $wpdb;710 # get product ref & design 711 global $wpdb; 667 712 $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $product['ref'])); 668 713 $getproducttype = wc_get_product($product_id); … … 676 721 677 722 $product['design'] = $wc_prod->get_name(); 723 724 global $wpdb; 725 // order tax rate country 726 $getTaxID = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM ".$wpdb->prefix."woocommerce_order_itemmeta WHERE meta_key='rate_id' ORDER BY order_item_id DESC LIMIT 1" ) ); 727 $getTaxCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$getTaxID."' LIMIT 1" ) ); 728 729 //order Item ID 730 $getOrderItemID = $wpdb->get_var( $wpdb->prepare("SELECT order_item_id FROM ".$wpdb->prefix."woocommerce_order_items WHERE order_item_name ='".$product['design']."' and order_item_type = 'line_item' and order_id = '".$orderid."' LIMIT 1" ) ); 731 //order Item product by order Item ID 732 $item = new WC_Order_Item_Product($getOrderItemID); 733 734 //$this->logs->writeFileLog('item', $item); 735 736 // The product name 737 $item_name = $item->get_name(); 738 739 if($item_name == $product['design']){ 740 //get taxes array for item 741 $taxes = $item->get_taxes(); 742 $taxes_total = $taxes['total']; 743 744 foreach ($taxes_total as $key => $value){ 745 if(is_numeric($value)){ 746 // get tax rate ID 747 $tax_rate_id = $key; 748 } 749 } 750 // order item tax rate 751 $getTaxProduct = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_id='".$tax_rate_id."' LIMIT 1")); 752 } 753 754 if (isset($getTaxCountry)){ 755 $product['tax_country'] = $getTaxCountry; 756 } 757 if (isset($getTaxProduct)){ 758 $product['tax_rate'] = $getTaxProduct; 759 } 678 760 } 679 761 } … … 690 772 $key++; 691 773 } 692 693 774 //fulfill "prodpack" with all data 694 775 $ftproductPack = $ftProducts; … … 716 797 717 798 /******************************************************************* 718 * --- Object PackData ---*799 * --- Object PackData --- * 719 800 ********************************************************************/ 720 public function transformWcToPhcData($wooOrder, $prodPack, $ftprodPack) { 721 722 $dataPack = new stdClass(); 723 724 $settings = new Settings(); 725 $shop = new stdClass(); 726 $bill = new Bill(); 727 $shipping = new Shipping(); 728 $customer = new Customer(); 729 $order = new Order(); 730 $ft = new Invoice(); 731 732 #settings data 733 $settings->createInvoice = $wooOrder->createInvoice; 734 $settings->typeOfInvoice = $wooOrder->typeOfInvoice; 735 $settings->toSignInvoice = $wooOrder->toSignInvoice; 736 $settings->fieldNif = $wooOrder->fieldNif; 737 $settings->includeTaxonSendCost = $wooOrder->includeTaxonSendCost; 738 $settings->createExemptPT = $wooOrder->createExemptPT; 739 $settings->typeOfReason = $wooOrder->typeOfReason; 740 $settings->createExemptEU = $wooOrder->createExemptEU; 741 $settings->typeOfReasonEU = $wooOrder->typeOfReasonEU; 742 $settings->createExemptCO = $wooOrder->createExemptCO; 743 $settings->typeOfReasonCO = $wooOrder->typeOfReasonCO; 744 $settings->warehouseOrder = $wooOrder->warehouseOrder; 745 $settings->typeOfOrder = $wooOrder->typeOfOrder; 746 $settings->toSignOrder = $wooOrder->toSignOrder; 747 $settings->numberOfOrder = $wooOrder->numberOfOrder; 748 $settings->statusOfOrder = $wooOrder->statusOfOrder; 749 $settings->shippingName = $wooOrder->shippingName; 750 $settings->feesName = $wooOrder->feesName; 751 $settings->manageStock = $wooOrder->manageStock; 752 $settings->productPriceColumn = $wooOrder->productPriceColumn; 753 $settings->warehouse = $wooOrder->warehouse; 754 $settings->sendInvoice = $wooOrder->sendInvoice; 755 756 #shop data 757 $shop->currency = $wooOrder->wooCurrency; 758 759 # bill data 760 $bill->country = $wooOrder->billing_country; 761 $bill->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name; 762 $bill->email = $wooOrder->billing_email; 763 $bill->morada = $wooOrder->billing_address_1; 764 $bill->local = $wooOrder->billing_city; 765 $bill->provincia = $wooOrder->billing_city; 766 $bill->telefone = $wooOrder->billing_phone; 767 $bill->codpost = $wooOrder->billing_postcode; 768 $bill->ncont = $wooOrder->billing_nif_ft; 769 770 # shipping data 771 $shipping->paisto = $wooOrder->shipping_country; 772 $shipping->moradato = $wooOrder->shipping_address_1; 773 $shipping->localto = $wooOrder->shipping_city; 774 $shipping->codpostto = $wooOrder->shipping_postcode; 775 $shipping->shipping_name = $wooOrder->shipping_name; 776 $shipping->shipping_taxValue = $wooOrder->shipping_taxValue; 777 $shipping->shipping_tax = $wooOrder->shipping_tax; 778 $shipping->shipping_country = $wooOrder->shipping_country; 779 $shipping->shipping_value = $wooOrder->shipping_value; 780 781 # customer data 782 $customer->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name; 783 $customer->email = $wooOrder->billing_email; 784 $customer->morada = !empty($wooOrder->shipping_address_1) ? $wooOrder->shipping_address_1 : $wooOrder->billing_address_1; 785 $customer->local = !empty($wooOrder->shipping_city) ? $wooOrder->shipping_city : $wooOrder->billing_city; 786 $customer->provincia = !empty($wooOrder->shipping_city) ? $wooOrder->shipping_city : $wooOrder->billing_city; 787 $customer->telefone = $wooOrder->billing_phone; 788 $customer->codpost = !empty($wooOrder->shipping_postcode) ? $wooOrder->shipping_postcode : $wooOrder->billing_postcode; 789 $customer->ncont = $wooOrder->billing_nif_ft; 790 $customer->preco = $wooOrder->productPriceColumn; 791 $customer->country = !empty($wooOrder->shipping_country) ? $wooOrder->shipping_country : $wooOrder->billing_country; 792 $customer->user_email = $wooOrder->user_email; 793 794 /* $customer->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name; 795 $customer->email = $wooOrder->billing_email; 796 $customer->morada = $wooOrder->billing_address_1; 797 $customer->local = $wooOrder->billing_city; 798 $customer->provincia = $wooOrder->billing_city; 799 $customer->telefone = $wooOrder->billing_phone; 800 $customer->codpost = $wooOrder->billing_postcode; 801 $customer->ncont = $wooOrder->billing_nif_ft; 802 $customer->preco = $wooOrder->productPriceColumn; 803 $customer->country = $wooOrder->billing_country; 804 $customer->user_email = $wooOrder->user_email; */ 805 806 # order 807 $order->post_Id = $wooOrder->post_ID; 808 $order->doc_Id = $wooOrder->docId; 809 $order->order_Id = $wooOrder->orderId; 810 $order->cart = $prodPack; 811 $order->post_title = $wooOrder->post_title; 812 $order->edescc = $wooOrder->edescc; 813 $order->obs = $wooOrder->obs; 814 $order->order_received = $wooOrder->order_received; 815 $order->nextPostId = $wooOrder->nextPostId; 816 $order->fees = $wooOrder->fees_bo; 817 818 # invoice 819 $ft->country = $wooOrder->billing_country_ft; 820 $ft->shipping_country = $wooOrder->shipping_country_ft; 821 $ft->cart = $ftprodPack; 822 $ft->shipping_name = $wooOrder->ftShipping_name; 823 $ft->shipping_value = $wooOrder->ftShipping_value; 824 $ft->fees = $wooOrder->fees_ft; 825 $ft->billing_name = $wooOrder->billing_first_name_ft. " " .$wooOrder->billing_last_name_ft; 826 $ft->billing_email = $wooOrder->billing_email_ft; 827 $ft->billing_address_1 = $wooOrder->billing_address_1_ft; 828 $ft->billing_city = $wooOrder->billing_city_ft; 829 $ft->billing_phone = $wooOrder->billing_phone_ft; 830 $ft->billing_postcode = $wooOrder->billing_postcode_ft; 831 $ft->billing_nif = $wooOrder->billing_nif_ft; 832 833 834 835 836 837 /******************************************/ 838 839 #build dataPack object 840 $dataPack->settings = $settings; 841 $dataPack->shop = $shop; 842 $dataPack->bill = $bill; 843 $dataPack->shipping = $shipping; 844 $dataPack->customer = $customer; 845 $dataPack->order = $order; 846 $dataPack->ft = $ft; 847 848 849 //$this->logs->writeFileLog('dataPack', $dataPack); 850 851 return $dataPack; 852 } 801 public function transformWcToPhcData($wooOrder, $prodPack, $ftprodPack) { 802 803 $dataPack = new stdClass(); 804 805 $settings = new Settings(); 806 $shop = new stdClass(); 807 $bill = new Bill(); 808 $shipping = new Shipping(); 809 $customer = new Customer(); 810 $order = new Order(); 811 $ft = new Invoice(); 812 813 #settings data 814 $settings->createInvoice = $wooOrder->createInvoice; 815 $settings->typeOfInvoice = $wooOrder->typeOfInvoice; 816 $settings->typeOf_EU_Invoice = $wooOrder->typeOf_EU_Invoice; 817 $settings->toSignInvoice = $wooOrder->toSignInvoice; 818 $settings->fieldNif = $wooOrder->fieldNif; 819 $settings->includeTaxonSendCost = $wooOrder->includeTaxonSendCost; 820 $settings->createExemptPT = $wooOrder->createExemptPT; 821 $settings->typeOfReason = $wooOrder->typeOfReason; 822 $settings->createExemptEU = $wooOrder->createExemptEU; 823 $settings->typeOfReasonEU = $wooOrder->typeOfReasonEU; 824 $settings->createExemptCO = $wooOrder->createExemptCO; 825 $settings->typeOfReasonCO = $wooOrder->typeOfReasonCO; 826 $settings->warehouseOrder = $wooOrder->warehouseOrder; 827 $settings->typeOfOrder = $wooOrder->typeOfOrder; 828 $settings->toSignOrder = $wooOrder->toSignOrder; 829 $settings->numberOfOrder = $wooOrder->numberOfOrder; 830 $settings->statusOfOrder = $wooOrder->statusOfOrder; 831 $settings->shippingName = $wooOrder->shippingName; 832 $settings->feesName = $wooOrder->feesName; 833 $settings->manageStock = $wooOrder->manageStock; 834 $settings->productPriceColumn = $wooOrder->productPriceColumn; 835 $settings->warehouse = $wooOrder->warehouse; 836 $settings->sendInvoice = $wooOrder->sendInvoice; 837 838 #shop data 839 $shop->currency = $wooOrder->wooCurrency; 840 $shop->country = $wooOrder->companyCountry; 841 $shop->taxCountry = $wooOrder->taxCountry; 842 843 # bill data 844 $bill->country = $wooOrder->billing_country; 845 $bill->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name; 846 $bill->email = $wooOrder->billing_email; 847 $bill->morada = $wooOrder->billing_address_1; 848 $bill->local = $wooOrder->billing_city; 849 $bill->provincia = $wooOrder->billing_city; 850 $bill->telefone = $wooOrder->billing_phone; 851 $bill->codpost = $wooOrder->billing_postcode; 852 $bill->ncont = $wooOrder->billing_nif_ft; 853 854 # shipping data 855 $shipping->cl_name = $wooOrder->shipping_first_name. " " .$wooOrder->shipping_last_name; 856 $shipping->ncont = $wooOrder->ship_nifName; 857 $shipping->paisto = $wooOrder->shipping_country; 858 $shipping->moradato = $wooOrder->shipping_address_1; 859 $shipping->localto = $wooOrder->shipping_city; 860 $shipping->codpostto = $wooOrder->shipping_postcode; 861 $shipping->shipping_name = $wooOrder->shipping_name; 862 $shipping->shipping_taxValue = $wooOrder->shipping_taxValue; 863 $shipping->shipping_tax = $wooOrder->shipping_tax; 864 $shipping->shipping_country = $wooOrder->shipping_country; 865 $shipping->shipping_value = $wooOrder->shipping_value; 866 867 # customer data (billing data) 868 $customer->nome = $wooOrder->billing_first_name. " " .$wooOrder->billing_last_name; 869 $customer->email = $wooOrder->billing_email; 870 $customer->morada = $wooOrder->billing_address_1; 871 $customer->local = $wooOrder->billing_city; 872 $customer->provincia = $wooOrder->billing_city; 873 $customer->telefone = $wooOrder->billing_phone; 874 $customer->codpost = $wooOrder->billing_postcode; 875 $customer->ncont = $wooOrder->billing_nif_ft; 876 $customer->preco = $wooOrder->productPriceColumn; 877 $customer->country = $wooOrder->billing_country; 878 $customer->user_email = $wooOrder->user_email; 879 880 # order 881 $order->post_Id = $wooOrder->post_ID; 882 $order->doc_Id = $wooOrder->docId; 883 $order->order_Id = $wooOrder->orderId; 884 $order->cart = $prodPack; 885 $order->post_title = $wooOrder->post_title; 886 $order->edescc = $wooOrder->edescc; 887 $order->obs = $wooOrder->obs; 888 $order->order_received = $wooOrder->order_received; 889 $order->nextPostId = $wooOrder->nextPostId; 890 $order->fees = $wooOrder->fees_bo; 891 892 # invoice 893 $ft->country = $wooOrder->billing_country_ft; 894 $ft->cart = $ftprodPack; 895 $ft->billing_name = $wooOrder->billing_first_name_ft. " " .$wooOrder->billing_last_name_ft; 896 $ft->billing_email = $wooOrder->billing_email_ft; 897 $ft->billing_address_1 = $wooOrder->billing_address_1_ft; 898 $ft->billing_city = $wooOrder->billing_city_ft; 899 $ft->billing_phone = $wooOrder->billing_phone_ft; 900 $ft->billing_postcode = $wooOrder->billing_postcode_ft; 901 $ft->billing_nif = $wooOrder->billing_nif_ft; 902 $ft->shipping_name = $wooOrder->shipping_name; 903 $ft->shipping_value = $wooOrder->shipping_value; 904 $ft->shipping_country = $wooOrder->shipping_country;; 905 $ft->shipping_taxValue = $wooOrder->shipping_taxValue; 906 $ft->shipping_tax = $wooOrder->shipping_tax; 907 $ft->fees = $wooOrder->fees_ft; 908 909 910 /******************************************************/ 911 912 #build dataPack object 913 $dataPack->settings = $settings; 914 $dataPack->shop = $shop; 915 $dataPack->bill = $bill; 916 $dataPack->shipping = $shipping; 917 $dataPack->customer = $customer; 918 $dataPack->order = $order; 919 $dataPack->ft = $ft; 920 921 //$this->logs->writeFileLog('dataPack', $dataPack); 922 923 return $dataPack; 924 } 853 925 }
Note: See TracChangeset
for help on using the changeset viewer.