Changeset 2526532
- Timestamp:
- 05/05/2021 09:50:42 AM (5 years ago)
- Location:
- drivefx-woocommerce/trunk
- Files:
-
- 18 edited
-
PHCLibrary/authentication.php (modified) (4 diffs)
-
PHCLibrary/classes/bill.php (modified) (2 diffs)
-
PHCLibrary/classes/customer.php (modified) (2 diffs)
-
PHCLibrary/classes/invoice.php (modified) (2 diffs)
-
PHCLibrary/classes/order.php (modified) (2 diffs)
-
PHCLibrary/classes/settings.php (modified) (3 diffs)
-
PHCLibrary/classes/shipping.php (modified) (2 diffs)
-
PHCLibrary/customers.php (modified) (18 diffs)
-
PHCLibrary/invoices.php (modified) (24 diffs)
-
PHCLibrary/log.php (modified) (1 diff)
-
PHCLibrary/orders.php (modified) (55 diffs)
-
PHCLibrary/utils.php (modified) (30 diffs)
-
class.DriveFxWoocommerce.php (modified) (141 diffs)
-
css/style_datatable.css (modified) (3 diffs)
-
js/drivefx-woocommerce.js (modified) (21 diffs)
-
settings/backend.php (modified) (43 diffs)
-
settings/import-products.php (modified) (1 diff)
-
settings/syncro_gate.php (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
drivefx-woocommerce/trunk/PHCLibrary/authentication.php
r2456866 r2526532 18 18 * --- LOGIN --- * 19 19 ********************************************************************/ 20 public function PHCLogin($ch,$credentials){ 21 $this->url = $credentials->backendUrl."/REST/UserLoginWS/userLoginCompany"; 20 public function PHCLogin($ch,$credentials){ 21 $this->url = $credentials->backendUrl."/REST/UserLoginWS/userLoginCompany"; 22 22 23 23 // Create map with request parameters 24 $this->params = array( 'userCode' => $credentials->userCode, 25 'password' => $credentials->password, 24 $this->params = array( 'userCode' => $credentials->userCode, 25 'password' => $credentials->password, 26 26 'applicationType' => $credentials->appId, 27 27 'company' => $credentials->company … … 46 46 curl_setopt($ch, CURLOPT_COOKIESESSION, true); 47 47 curl_setopt($ch, CURLOPT_COOKIEJAR, ''); //could be empty, but cause problems on some hosts 48 curl_setopt($ch, CURLOPT_COOKIEFILE, ''); //could be empty, but cause problems on some hosts 49 48 curl_setopt($ch, CURLOPT_COOKIEFILE, ''); //could be empty, but cause problems on some hosts 49 50 50 return $ch; 51 51 } … … 54 54 * --- LOGOUT --- * 55 55 ********************************************************************/ 56 function PHCLogout($ch, $credentials){ 56 function PHCLogout($ch, $credentials){ 57 57 $this->url = $credentials->backendUrl."/REST/UserLoginWS/userLogout"; 58 58 curl_setopt($ch, CURLOPT_URL, $this->url); … … 63 63 64 64 } 65 66 67 65 } 68 66 ?> -
drivefx-woocommerce/trunk/PHCLibrary/classes/bill.php
r2456866 r2526532 1 2 1 <?php 3 4 5 2 class Bill { 6 7 3 public $country; 8 4 public $nome; … … 13 9 public $telefone; 14 10 public $codpost; 15 public $ncont; 11 public $ncont; 16 12 } 17 18 19 ?> -
drivefx-woocommerce/trunk/PHCLibrary/classes/customer.php
r2456866 r2526532 1 2 1 <?php 3 4 5 2 class Customer { 6 7 3 public $nome; 8 4 public $email; … … 16 12 public $country; 17 13 public $user_email; 18 19 14 } 20 21 22 ?> -
drivefx-woocommerce/trunk/PHCLibrary/classes/invoice.php
r2456866 r2526532 1 2 1 <?php 3 4 5 2 class Invoice { 6 7 3 public $country; 8 4 public $shipping_country; … … 13 9 public $billing_name; 14 10 public $billing_email; 15 public $billing_address_1; 16 public $billing_city; 17 public $billing_phone; 18 public $billing_postcode; 19 public $billing_nif; 11 public $billing_address_1; 12 public $billing_city; 13 public $billing_phone; 14 public $billing_postcode; 15 public $billing_nif; 20 16 } 21 22 23 ?> -
drivefx-woocommerce/trunk/PHCLibrary/classes/order.php
r2456866 r2526532 1 2 1 <?php 3 4 5 2 class Order { 6 7 3 public $post_Id; 8 4 public $doc_Id; … … 13 9 public $obs; 14 10 public $order_received; 15 public $nextPostId; 16 public $fee_name; 17 public $fee_value; 11 public $nextPostId; 12 public $fee_name; 13 public $fee_value; 18 14 } 19 20 21 ?> -
drivefx-woocommerce/trunk/PHCLibrary/classes/settings.php
r2456866 r2526532 1 2 1 <?php 3 4 5 2 class Settings { 6 7 3 public $createInvoice; 8 4 public $typeOfInvoice; … … 10 6 public $fieldNif; 11 7 public $includeTaxonSendCost; 12 public $createExemptCl; 8 public $createExemptPT; 9 public $createExemptEU; 10 public $createExemptCO; 13 11 public $typeOfReason; 12 public $typeOfReasonEU; 13 public $typeOfReasonCO; 14 14 public $warehouseOrder; 15 15 public $typeOfOrder; … … 23 23 public $warehouse; 24 24 public $sendInvoice; 25 26 25 } 27 28 ?> -
drivefx-woocommerce/trunk/PHCLibrary/classes/shipping.php
r2456866 r2526532 1 2 1 <?php 3 4 5 2 class Shipping { 6 7 3 public $paisto; 8 4 public $moradato; … … 13 9 public $shipping_tax; 14 10 public $shipping_country; 15 public $shipping_value; 11 public $shipping_value; 16 12 } 17 18 19 ?> -
drivefx-woocommerce/trunk/PHCLibrary/customers.php
r2456866 r2526532 13 13 $this->logs = new Logs(); 14 14 $this->auth_services = new AuthentificationService(); 15 $this->utils_services = new UtilsServices(); 15 $this->utils_services = new UtilsServices(); 16 16 17 17 } 18 19 public function processCustomer($ch, $credentials, $dataPack, $tip_button) { 18 19 public function processCustomer($ch, $credentials, $dataPack, $tip_button) { 20 20 ### 21 $customer = $dataPack->customer; 22 23 $tip_button = false; 21 $customer = $dataPack->customer; 22 23 $tip_button = false; 24 24 # If Email exists 25 25 if($customer->user_email != ''){ 26 26 27 # Verify if customer already exists in software 28 if( $customer->email != ''){ 27 # Verify if customer already exists in software 28 if( $customer->email != ''){ 29 29 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Cl', 'email', $customer->email); 30 30 } else { … … 32 32 } 33 33 //$this->logs->writeFileLog('Cl Checking:', $response); 34 34 35 35 if (curl_error($ch)) { 36 36 $this->logs->writeFileLog('Cl Checking', $ch); 37 37 } else if(empty($response)){ 38 $this->logs->writeFileLog('Cl Checking', 'EMPTY RESPONSE'); 38 $this->logs->writeFileLog('Cl Checking', 'EMPTY RESPONSE'); 39 39 } else { 40 40 if($tip_button == false){ … … 43 43 44 44 //Save number id of client 45 $customer->no = $response['result'][0]['no']; 46 45 $customer->no = $response['result'][0]['no']; 46 47 47 # Update Customer 48 $updatedCustomer = $this->updateCustomer($ch, $credentials, $dataPack, $response); 48 $updatedCustomer = $this->updateCustomer($ch, $credentials, $dataPack, $response); 49 49 50 50 if (curl_error($ch)) { 51 51 $this->logs->writeFileLog('ClUpdate', $ch); 52 52 } else if(empty($response)){ 53 $this->logs->writeFileLog('ClUpdate', 'EMPTY RESPONSE'); 53 $this->logs->writeFileLog('ClUpdate', 'EMPTY RESPONSE'); 54 54 } else { 55 55 $returnCustomer = $updatedCustomer; 56 } 57 56 } 57 58 58 # If the customer not exists 59 } else{ 59 } else{ 60 60 #Create a new customer 61 61 $createdCustomer = $this->createCustomer($ch, $credentials, $dataPack); … … 66 66 $this->logs->writeFileLog('NewCl', $ch); 67 67 } else if(empty($response)){ 68 $this->logs->writeFileLog('NewCl', 'EMPTY RESPONSE'); 68 $this->logs->writeFileLog('NewCl', 'EMPTY RESPONSE'); 69 69 } else { 70 70 $returnCustomer = $createdCustomer; 71 } 72 73 } 74 } 71 } 72 73 } 74 } 75 75 } 76 76 # If Email not exists … … 84 84 $this->logs->writeFileLog('Gen_Cl Checking', $ch); 85 85 } else if(empty($response)){ 86 $this->logs->writeFileLog('Gen_Cl Checking', 'EMPTY RESPONSE'); 87 } else { 86 $this->logs->writeFileLog('Gen_Cl Checking', 'EMPTY RESPONSE'); 87 } else { 88 88 //return (object) $response['result'][0]; 89 89 … … 102 102 $this->logs->writeFileLog('gen_clNewInstance', $ch); 103 103 } else if(empty($response)){ 104 $this->logs->writeFileLog('gen_clNewInstance', 'EMPTY RESPONSE'); 104 $this->logs->writeFileLog('gen_clNewInstance', 'EMPTY RESPONSE'); 105 105 } else { 106 106 // Generic Customer data … … 108 108 $response['result'][0]['clivd'] = true; 109 109 $response['result'][0]['preco'] = $customer->preco; 110 111 // Save Instance in Software PHC 112 $responseGenCl = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 113 114 //$this->logs->writeFileLog('genCl Save:', $response); 110 111 // Save Instance in Software PHC 112 $responseGenCl = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 113 114 //$this->logs->writeFileLog('genCl Save:', $response); 115 115 116 116 if (curl_error($ch)) { 117 117 $this->logs->writeFileLog('genCl_Save', $ch); 118 118 } else if(empty($responseGenCl)){ 119 $this->logs->writeFileLog('genCl_Save', 'EMPTY RESPONSE'); 119 $this->logs->writeFileLog('genCl_Save', 'EMPTY RESPONSE'); 120 120 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 121 121 $this->writeFileLog('genCl_Save', $responseGenCl['messages'][0]['messageCodeLocale']); 122 122 } else { 123 123 //Return object 124 return (object) $responseGenCl['result'][0]; 124 return (object) $responseGenCl['result'][0]; 125 125 } 126 } 127 } 128 } 129 } 130 131 return $returnCustomer; 126 } 127 } 128 } 129 } 130 131 return $returnCustomer; 132 132 } 133 133 … … 142 142 $this->logs->writeFileLog('clNewInstance', $ch); 143 143 } else if(empty($response)){ 144 $this->logs->writeFileLog('clNewInstance', 'EMPTY RESPONSE'); 144 $this->logs->writeFileLog('clNewInstance', 'EMPTY RESPONSE'); 145 145 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 146 $this->logs->writeFileLog('clNewInstance', $response['messages'][0]['messageCodeLocale']); 146 $this->logs->writeFileLog('clNewInstance', $response['messages'][0]['messageCodeLocale']); 147 147 } else { 148 148 //Save number id of client … … 176 176 $response['result'][0]['preco'] = $customer->preco; 177 177 } 178 179 # get country and country stampin accordance with Phc178 179 # set country in accordance with Phc 180 180 if($customer->country != ''){ 181 $responseCountry = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', $customer->country); 182 }else if($customer->country == "GB") { 183 $responseCountry = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', "UK"); 181 if($customer->country == "GB") { 182 $customerCountry = "UK"; 183 } else { 184 $customerCountry = $customer->country; 185 } 184 186 }else{ 185 $responseCountry = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', "PT"); 186 } 187 $customerCountry = "PT"; 188 } 189 // Get country data 190 $responseCountry = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', $customerCountry); 191 192 //$this->logs->writeFileLog('countries', $responseCountry); 187 193 188 194 if (curl_error($ch)) { … … 194 200 $customer->nomePais = $responseCountry['result'][0]['nome']; 195 201 } 196 202 197 203 if(isset($customer->paisesstamp)) { 198 204 $response['result'][0]['paisesstamp'] = $customer->paisesstamp; … … 201 207 $response['result'][0]['pais'] = $customer->nomePais; 202 208 $response['result'][0]['pncont'] = $responseCountry['result'][0]['pncont']; 203 } 204 # Tax free customer 205 if ($dataPack->settings->createExemptCl){ 209 } 210 211 # Tax free customer outside of PT 212 if ($dataPack->settings->createExemptPT){ 206 213 if($customer->country !="PT") { 207 214 $response['result'][0]['tabiva'] = 4; 208 215 $response['result'][0]['codmotiseimp'] = $dataPack->settings->typeOfReason; 209 210 // GEt table of Free Tax data211 $responseReason = $this->utils_services->filterItem_Query($ch, $credentials, 'Miseimp', 'codigo', $dataPack->settings->typeOfReason);216 217 // GEt table of Free Tax data 218 $responseReason = $this->utils_services->filterItem_Query($ch, $credentials, 'Miseimp', 'codigo', $dataPack->settings->typeOfReason); 212 219 213 220 if(isset($customer->nomePais)) { … … 216 223 } else { 217 224 $this->logs->writeFileLog('responseReason:', 'Erro on receive Free Tax Reason Data'); 218 } 219 } 220 } 221 222 # Save Instance in Software PHC 223 $paramsSaveResponse = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 224 225 //$this->logs->writeFileLog('clSave:', $paramsSaveResponse); 225 } 226 } 227 } 228 # Tax free customer outside of EU 229 if ($dataPack->settings->createExemptEU){ 230 if ($responseCountry['result'][0]['ueMember'] != 1 && $customer->country !="PT"){ 231 $response['result'][0]['tabiva'] = 4; 232 $response['result'][0]['codmotiseimp'] = $dataPack->settings->typeOfReasonEU; 233 234 // GEt table of Free Tax data 235 $responseReason = $this->utils_services->filterItem_Query($ch, $credentials, 'Miseimp', 'codigo', $dataPack->settings->typeOfReasonEU); 236 237 if(isset($customer->nomePais)) { 238 $response['result'][0]['motiseimp'] = $responseReason['result'][0]['descricao']; 239 $response['result'][0]['miseimpstamp'] = $responseReason['result'][0]['miseimpstamp']; 240 } else { 241 $this->logs->writeFileLog('responseReason.1:', 'Erro on receive Free Tax Reason Data'); 242 } 243 } 244 } 245 246 # Tax free companies from EU 247 if ($dataPack->settings->createExemptCO){ 248 // if is from UE mermber Country 249 if ($responseCountry['result'][0]['ueMember'] == 1){ 250 //check if it is a company or a private client (via VIES) 251 $checkVAT = $this->utils_services->viesCheckVAT($responseCountry['result'][0]['nomeabrv'], $customer->ncont); 252 253 if ($checkVAT['valid'] == "true"){ 254 $response['result'][0]['tabiva'] = 4; 255 $response['result'][0]['codmotiseimp'] = $dataPack->settings->typeOfReasonCO; 256 257 // GEt table of Free Tax data 258 $responseReason = $this->utils_services->filterItem_Query($ch, $credentials, 'Miseimp', 'codigo', $dataPack->settings->typeOfReasonCO); 259 260 if(isset($customer->nomePais)) { 261 $response['result'][0]['motiseimp'] = $responseReason['result'][0]['descricao']; 262 $response['result'][0]['miseimpstamp'] = $responseReason['result'][0]['miseimpstamp']; 263 } else { 264 $this->logs->writeFileLog('responseReason.2:', 'Erro on receive Free Tax Reason Data'); 265 } 266 } 267 } 268 } 269 270 # Save Instance in Software PHC 271 $paramsSaveResponse = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 272 273 //$this->logs->writeFileLog('clSave:', $paramsSaveResponse); 226 274 227 275 if (curl_error($ch)) { 228 276 $this->logs->writeFileLog('clSave', $ch); 229 277 } else if(empty($paramsSaveResponse)){ 230 $this->logs->writeFileLog('clSave', 'EMPTY RESPONSE'); 278 $this->logs->writeFileLog('clSave', 'EMPTY RESPONSE'); 231 279 } else { 232 280 233 281 return (object) $paramsSaveResponse['result'][0]; 234 282 } 235 } 283 } 236 284 237 285 } … … 241 289 $customer = $dataPack->customer; 242 290 243 $mustUpdateCl = false; 244 245 #Update customer data 291 $mustUpdateCl = false; 292 293 #Update customer data 246 294 if(isset($customer->nome) && $response['result'][0]['nome'] !== $customer->nome) { 247 295 $response['result'][0]['nome'] = $customer->nome; 248 296 $mustUpdateCl = true; 249 } 297 } 250 298 if(isset($customer->morada) && $response['result'][0]['morada'] !== $customer->morada) { 251 299 $response['result'][0]['morada'] = $customer->morada; … … 263 311 $response['result'][0]['telefone'] = $customer->telefone; 264 312 $mustUpdateCl = true; 265 } 313 } 266 314 if(isset($customer->codpost) && $response['result'][0]['codpost'] !== $customer->codpost) { 267 315 $response['result'][0]['codpost'] = $customer->codpost; … … 272 320 $mustUpdateCl = true; 273 321 } 274 //get country and country stamp 322 //get country and country stamp 275 323 if($customer->country != ''){ 276 324 $responseCountry = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', $customer->country); … … 280 328 $responseCountry = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', "PT"); 281 329 } 282 330 283 331 //check the response 284 332 if (curl_error($ch)) { … … 290 338 $customer->nomePais = $responseCountry['result'][0]['nome']; 291 339 } 292 340 293 341 //fulfill customer data 294 342 if(isset($customer->paisesstamp) && $response['result'][0]['paisesstamp'] !== $customer->paisesstamp) { … … 300 348 $mustUpdateCl = true; 301 349 } 302 350 303 351 if (!$mustUpdateCl) { 304 352 return $customer; 305 353 } 306 354 307 355 //Set Operation to 2 to make the Update 308 $response['result'][0]['Operation']= 2; 309 310 # Save Instance in Software PHC 356 $response['result'][0]['Operation']= 2; 357 358 # Save Instance in Software PHC 311 359 $paramsSaveResponse = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 312 313 //$this->logs->writeFileLog('ClUpdate Save:', $paramsSaveResponse); 360 361 //$this->logs->writeFileLog('ClUpdate Save:', $paramsSaveResponse); 314 362 315 363 if (curl_error($ch)) { 316 364 $this->logs->writeFileLog('Cl_UpdateSave', $ch); 317 365 } else if(empty($paramsSaveResponse)){ 318 $this->logs->writeFileLog('Cl_UpdateSave', 'EMPTY RESPONSE'); 366 $this->logs->writeFileLog('Cl_UpdateSave', 'EMPTY RESPONSE'); 319 367 } else { 320 368 return (object) $paramsSaveResponse['result'][0]; -
drivefx-woocommerce/trunk/PHCLibrary/invoices.php
r2456866 r2526532 1 <?php 1 <?php 2 2 require_once 'log.php'; 3 3 require_once 'authentication.php'; … … 15 15 $this->logs = new Logs(); 16 16 $this->auth_services = new AuthentificationService(); 17 $this->utils_services = new UtilsServices(); 18 $this->customers_services = new CustomersServices(); 17 $this->utils_services = new UtilsServices(); 18 $this->customers_services = new CustomersServices(); 19 19 } 20 20 … … 46 46 $paisesstamp = $response['result'][0]['paisesstamp']; 47 47 $nomePais = $response['result'][0]['nome']; 48 } 48 } 49 49 ### 50 50 $_shipping_country = $ft->shipping_country; … … 55 55 56 56 //$this->logs->writeFileLog('shippingCountry response:', $response); 57 57 58 58 if (curl_error($ch)) { 59 59 $this->logs->writeFileLog('addSimpleFT3', $ch); … … 68 68 69 69 # get current customer data 70 $newCustomer = $this->customers_services->processCustomer($ch, $credentials, $dataPack, $tip_button); 70 $newCustomer = $this->customers_services->processCustomer($ch, $credentials, $dataPack, $tip_button); 71 71 72 72 //$this->logs->writeFileLog('newCustomer:', $newCustomer); … … 75 75 $this->logs->writeFileLog('getCustomer', $ch); 76 76 } else if(empty($newCustomer)){ 77 $this->logs->writeFileLog('getCustomer', 'EMPTY RESPONSE'); 77 $this->logs->writeFileLog('getCustomer', 'EMPTY RESPONSE'); 78 78 } else { 79 if($newCustomer->no != ''){ 79 if($newCustomer->no != ''){ 80 80 //Inserted client in bd 81 81 $createClientSuccess = 1; 82 } 83 } 84 #If client is created/obtained with success 85 if($createClientSuccess == 1){ 82 } 83 } 84 #If client is created/obtained with success 85 if($createClientSuccess == 1){ 86 86 //Obtain new instance of invoice 87 87 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'FtWS', $settings->typeOfInvoice); 88 88 89 //Clear the product lines 90 $response['result'][0]['fis'] = []; 91 89 92 //$this->logs->writeFileLog('FtWs Response', $response); 90 93 … … 92 95 $this->logs->writeFileLog('addSimpleFT11', $ch); 93 96 } else if(empty($response)){ 94 $this->logs->writeFileLog('addSimpleFT11', 'EMPTY RESPONSE'); 97 $this->logs->writeFileLog('addSimpleFT11', 'EMPTY RESPONSE'); 95 98 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 96 $this->logs->writeFileLog('addSimpleFT11', $response['messages'][0]['messageCodeLocale']); 97 } else { 99 $this->logs->writeFileLog('addSimpleFT11', $response['messages'][0]['messageCodeLocale']); 100 } else { 98 101 #Save number of client in FT 99 102 $response['result'][0]['no'] = $newCustomer->no; … … 101 104 #actEntity 102 105 $response = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); 103 106 104 107 //$this->logs->writeFileLog('actEntity:', $response); 105 108 … … 107 110 $this->logs->writeFileLog('addSimpleFT13', $ch); 108 111 } else if(empty($response)){ 109 $this->logs->writeFileLog('addSimpleFT13', 'EMPTY RESPONSE'); 112 $this->logs->writeFileLog('addSimpleFT13', 'EMPTY RESPONSE'); 110 113 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 111 $this->logs->writeFileLog('addSimpleFT13', $response['messages'][0]['messageCodeLocale']); 114 $this->logs->writeFileLog('addSimpleFT13', $response['messages'][0]['messageCodeLocale']); 112 115 } else { 113 116 ### 114 117 $cart = $ft->cart; 115 118 116 119 // Only If have articles to FT 117 120 if(!empty($cart)){ 118 121 foreach ($cart as $product) { 119 122 //product 120 if($product['qtt']*$product['epv'] != 0){ 121 $fi = new stdClass(); 122 123 if($product['qtt']*$product['epv'] != 0){ 124 $fi = new stdClass(); 125 123 126 $fi->ref = $product['ref']; 124 127 $fi->design = $product['design']; … … 143 146 if($settings->feesName != "") { 144 147 $fi->ref = $settings->feesName; 145 } 148 } 146 149 147 150 // IVA 148 151 if ($settings->includeTaxonSendCost == "true") { 149 152 $fi->ivaincl=true; 150 } 153 } 151 154 if ($fi->etiliquido == 0) { 152 155 $fi->qtt = 0; 153 156 $fi->ivaincl = false; 154 } 155 $response['result'][0]['fis'][]= $fi; 157 } 158 $response['result'][0]['fis'][]= $fi; 156 159 } 157 160 } … … 162 165 if($settings->shippingName != "") { 163 166 $fi->ref = $settings->shippingName; 164 } 165 167 } 168 166 169 $fi->design = $ft->shipping_name; 167 170 $fi->qtt = 1; 168 171 169 172 // IVA 170 173 if($settings->includeTaxonSendCost == "true") { 171 174 $fi->ivaincl=true; 172 } 175 } 173 176 if($fi->etiliquido == 0){ 174 177 $fi->qtt = 0; 175 178 $fi->ivaincl = false; 176 } 177 $response['result'][0]['fis'][]= $fi; 179 } 180 $response['result'][0]['fis'][]= $fi; 178 181 } 179 182 //actEntity 180 183 $response2 = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); 181 184 182 185 // shipping value 183 186 foreach ($response2['result'][0]['fis'] as &$delivery) { … … 187 190 $delivery['etiliquido'] = $shipping->shipping_value; 188 191 $delivery['epv'] = $shipping->shipping_value; 189 } 190 } 191 192 } 193 } 194 192 195 #actEntity 193 196 $response = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response2); 194 197 195 198 //$this->logs->writeFileLog('actEntity1:', $response); 196 199 … … 198 201 $this->logs->writeFileLog('addSimpleFT12', $ch); 199 202 } else if(empty($response)){ 200 $this->logs->writeFileLog('addSimpleFT12', 'EMPTY RESPONSE'); 203 $this->logs->writeFileLog('addSimpleFT12', 'EMPTY RESPONSE'); 201 204 } else if(isset($response['messages'][0]['messageCodeLocale']) && $response['messages'][0]['messageCode']!='messages.Business.Stocks.InvalidRefAutoCreate'){ 202 203 $this->logs->writeFileLog('addSimpleFT12', $response['messages'][0]['messageCodeLocale']); 205 206 $this->logs->writeFileLog('addSimpleFT12', $response['messages'][0]['messageCodeLocale']); 204 207 } else { 205 208 # Billing data 206 209 $response['result'][0]['nome2'] = $ft->billing_name; 207 $response['result'][0]['morada'] = $ft->billing_address_1; 210 $response['result'][0]['morada'] = $ft->billing_address_1; 208 211 $response['result'][0]['local'] = $ft->billing_city; 209 212 $response['result'][0]['provincia'] = $ft->billing_city; … … 215 218 $response['result'][0]['codpostto'] = $shipping->codpostto; 216 219 $response['result'][0]['pais'] = $nomePais; 217 $response['result'][0]['paisesstamp'] = $paisesstamp; 220 $response['result'][0]['paisesstamp'] = $paisesstamp; 218 221 $response['result'][0]['paisto'] = $nomePaisShipping; 219 $response['result'][0]['paisesstampto'] = $paisesstampShipping; 222 $response['result'][0]['paisesstampto'] = $paisesstampShipping; 220 223 221 224 # Eliminate comercial discount … … 235 238 //Eliminate discount in field "desc6" 236 239 $response['result'][0]['fis'][$key]['desc6'] = 0; 237 240 238 241 //Eliminate financial discount of client 239 $response['result'][0]['efinv'] = 0; 240 $response['result'][0]['fin'] = 0; 242 $response['result'][0]['efinv'] = 0; 243 $response['result'][0]['fin'] = 0; 241 244 } 242 245 } 243 246 } 244 247 245 248 #actEntity 246 249 $response = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); 247 250 248 251 //$this->logs->writeFileLog('actEntity2:', $response); 249 252 … … 251 254 $this->logs->writeFileLog('addSimpleFT13', $ch); 252 255 } else if(empty($response)){ 253 $this->logs->writeFileLog('addSimpleFT13', 'EMPTY RESPONSE'); 256 $this->logs->writeFileLog('addSimpleFT13', 'EMPTY RESPONSE'); 254 257 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 255 $this->logs->writeFileLog('addSimpleFT13', $response['messages'][0]['messageCodeLocale']); 258 $this->logs->writeFileLog('addSimpleFT13', $response['messages'][0]['messageCodeLocale']); 256 259 } else { 257 260 //Save Invoice 258 261 $response = $this->utils_services->paramsSave($ch, $credentials, 'FtWS', $response); 259 262 260 263 //$this->logs->writeFileLog('saveFt:', $response); 261 264 … … 263 266 $this->logs->writeFileLog('addSimpleFT14', $ch); 264 267 } else if(empty($response)){ 265 $this->logs->writeFileLog('addSimpleFT14', 'EMPTY RESPONSE'); 268 $this->logs->writeFileLog('addSimpleFT14', 'EMPTY RESPONSE'); 266 269 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 267 $this->logs->writeFileLog('addSimpleFT14', $response['messages'][0]['messageCodeLocale']); 270 $this->logs->writeFileLog('addSimpleFT14', $response['messages'][0]['messageCodeLocale']); 268 271 } else { 269 272 //Enable to sign Document 270 if($response['result'][0]['draftRecord'] == 1){ 273 if($response['result'][0]['draftRecord'] == 1){ 271 274 //Save ftstamp of invoice 272 275 $_SESSION['ftstamp'] = $response['result'][0]['ftstamp']; 273 $_SESSION['fno'] = $response['result'][0]['fno']; 276 $_SESSION['fno'] = $response['result'][0]['fno']; 274 277 275 278 //Sign document … … 286 289 $this->logs->writeFileLog('addSimpleFT15', $ch); 287 290 } else if(empty($response)){ 288 $this->logs->writeFileLog('addSimpleFT15', 'EMPTY RESPONSE'); 291 $this->logs->writeFileLog('addSimpleFT15', 'EMPTY RESPONSE'); 289 292 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 290 $this->logs->writeFileLog('addSimpleFT15', $response['messages'][0]['messageCodeLocale']); 293 $this->logs->writeFileLog('addSimpleFT15', $response['messages'][0]['messageCodeLocale']); 291 294 } else { 292 $this->logs->writeFileLog('add NewOrder17', "Signed invoice: ".$response['result'][0]['fno']);295 $this->logs->writeFileLog('addSimpleFT16', "Invoice number: ".$response['result'][0]['fno']." was created!" ); 293 296 294 297 return $response; 295 298 } 296 299 } else { 297 return $response; 298 } 300 return $response; 301 } 299 302 } 300 303 } 301 304 } 302 305 } 303 } 306 } 304 307 } 305 } 308 } 306 309 } 307 310 } … … 310 313 ### 311 314 $settings = $dataPack->settings; 312 315 313 316 if(empty($settings->typeOfInvoice) || $settings->typeOfInvoice == 0){ 314 317 $this->logs->writeFileLog('addInternalDocumentInvoice', 'Empty type of invoice'); … … 316 319 //Obtain new instance of FT based in Bo(bostamp) 317 320 $response = $this->utils_services->paramsNewInstanceFromReference($ch, $credentials, $response['bostamp']); 318 321 319 322 //$this->logs->writeFileLog('instanceFromReference:', $response); 320 323 … … 322 325 $this->logs->writeFileLog('addInternalDocumentInvoice2', $ch); 323 326 } else if(empty($response)){ 324 $this->logs->writeFileLog('addInternalDocumentInvoice2', 'EMPTY RESPONSE'); 325 } else if(isset($response['messages'][0]['messageCodeLocale']) ){326 $this->logs->writeFileLog('addInternalDocumentInvoice2', $response['messages'][0]['messageCodeLocale']); 327 $this->logs->writeFileLog('addInternalDocumentInvoice2', 'EMPTY RESPONSE'); 328 } else if(isset($response['messages'][0]['messageCodeLocale']) && $response['messages'][0]['messageCode'] != "info.Business.Stocks.RefWithoutStock"){ 329 $this->logs->writeFileLog('addInternalDocumentInvoice2', $response['messages'][0]['messageCodeLocale']); 327 330 } else { 328 331 //Save id of customer 329 $_SESSION['numberClient'] = $response['result'][0]['no']; 332 $_SESSION['numberClient'] = $response['result'][0]['no']; 330 333 //Save Invoice 331 334 $response = $this->utils_services->paramsSave($ch, $credentials, 'FtWS', $response); … … 336 339 $this->logs->writeFileLog('addInternalDocumentInvoice3', $ch); 337 340 } else if(empty($response)){ 338 $this->logs->writeFileLog('addInternalDocumentInvoice3', 'EMPTY RESPONSE'); 341 $this->logs->writeFileLog('addInternalDocumentInvoice3', 'EMPTY RESPONSE'); 339 342 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 340 $this->logs->writeFileLog('addInternalDocumentInvoice3', $response['messages'][0]['messageCodeLocale']); 343 $this->logs->writeFileLog('addInternalDocumentInvoice3', $response['messages'][0]['messageCodeLocale']); 341 344 } else { 342 345 //Enable to sign Document … … 346 349 ### 347 350 $ftstamp = $response['result'][0]['ftstamp']; 348 351 349 352 $response = $this->utils_services->paramsSignDocument($ch, $credentials, $ftstamp); 350 353 351 354 //$this->logs->writeFileLog('signing ft: ', $response); 352 } 355 } 353 356 354 357 if (curl_error($ch)) { 355 358 $this->logs->writeFileLog('addInternalDocumentInvoice4', $ch); 356 359 } else if(empty($response)){ 357 $this->logs->writeFileLog('addInternalDocumentInvoice4', 'EMPTY RESPONSE'); 360 $this->logs->writeFileLog('addInternalDocumentInvoice4', 'EMPTY RESPONSE'); 358 361 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 359 $this->logs->writeFileLog('addInternalDocumentInvoice4', $response['messages'][0]['messageCodeLocale']); 362 $this->logs->writeFileLog('addInternalDocumentInvoice4', $response['messages'][0]['messageCodeLocale']); 360 363 } else { 361 $this->logs->writeFileLog('addInternalDocumentInvoice4', " Signed invoice: ".$response['result'][0]['fno']);364 $this->logs->writeFileLog('addInternalDocumentInvoice4', "Invoice number: ".$response['result'][0]['fno']." was created!" ); 362 365 363 366 return $response; … … 365 368 } else { 366 369 return $response; 367 } 370 } 368 371 } 369 372 } -
drivefx-woocommerce/trunk/PHCLibrary/log.php
r2456866 r2526532 1 1 <?php 2 3 class Logs{ 2 class Logs{ 4 3 //Write errors in Log File 5 4 function writeFileLog($text_function, $messageResponse) { 6 5 $myFile = __DIR__.'/../logsErrors/logs.txt'; 7 6 $date = date('Y/m/d H:i:s'); 8 $message = $text_function . " " . $date . ": " . print_r($messageResponse, true) . "\r\n"; 7 $message = $text_function . " " . $date . ": " . print_r($messageResponse, true) . "\r\n"; 9 8 if (file_exists($myFile)) { 10 9 $fh = fopen($myFile, 'a'); 11 10 } else { 12 11 $fh = fopen($myFile, 'w'); 13 } 12 } 14 13 fwrite($fh, $message); 15 14 fclose($fh); -
drivefx-woocommerce/trunk/PHCLibrary/orders.php
r2456866 r2526532 5 5 require_once 'customers.php'; 6 6 7 8 7 class OrdersService { 9 8 10 9 private $logs; 11 10 private $auth_services; … … 16 15 $this->logs = new Logs(); 17 16 $this->auth_services = new AuthentificationService(); 18 $this->utils_services = new UtilsServices(); 19 $this->customers_services = new CustomersServices(); 17 $this->utils_services = new UtilsServices(); 18 $this->customers_services = new CustomersServices(); 20 19 } 21 20 22 21 public function processOrder($credentials, $dataPack, $fieldStatus){ 23 22 # Login 24 $ch = $this->auth_services->PHCLogin($ch, $credentials); 23 $ch = $this->auth_services->PHCLogin($ch, $credentials); 25 24 //initial request with login data 26 25 $response = curl_exec($ch); 27 26 // send response as JSON 28 $response = json_decode($response, true); 29 // get the t emporary token and insert in credentials object27 $response = json_decode($response, true); 28 // get the token and insert in credentials object 30 29 $credentials->token = $response['result'][0]['token']; 31 30 32 31 //$this->logs->writeFileLog('OrderLogin response:', $response); 33 32 34 33 $returnOrder = null; 35 34 ### … … 38 37 $order = $dataPack->order; 39 38 $shipping = $dataPack->shipping; 40 39 41 40 if (curl_error($ch)) { 42 41 $this->logs->writeFileLog('addNewOrder', $ch); … … 46 45 $this->logs->writeFileLog('addNewOrder', $response['messages'][0]['messageCodeLocale']); 47 46 } else { 48 # obtain gama 47 # obtain gama 49 48 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 50 49 51 50 //$this->logs->writeFileLog('BackEnd response:', $response); 52 51 … … 70 69 }else{ 71 70 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', "PT"); 72 } 71 } 73 72 //$this->logs->writeFileLog('billCountry response:', $response); 74 73 … … 83 82 $nomePais = $response['result'][0]['nome']; 84 83 } 85 86 # obtain shipping country 84 85 # obtain shipping country 87 86 if($shipping->paisto != ''){ 88 87 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', $shipping->paisto); … … 91 90 }else{ 92 91 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Countries', 'nomeabrv', "PT"); 93 } 92 } 94 93 //$this->logs->writeFileLog('shippingCountry response:', $response); 95 94 96 95 if (curl_error($ch)) { 97 96 $this->logs->writeFileLog('addNewOrder3', $ch); … … 106 105 107 106 # Obtain currency coin of company 108 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 109 107 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 108 110 109 //$this->logs->writeFileLog('E1 response:', $response); 111 110 … … 116 115 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 117 116 $this->logs->writeFileLog('addNewOrder4', $response['messages'][0]['messageCodeLocale']); 118 } else { 117 } else { 119 118 //Verify if currency of shop corresponds to PHC 120 119 if($response['result'][0]['moeda'] == $dataPack->shop->currency){ 121 120 # get current customer data 122 $newCustomer = $this->customers_services->processCustomer($ch, $credentials, $dataPack, $tip_button); 121 $newCustomer = $this->customers_services->processCustomer($ch, $credentials, $dataPack, $tip_button); 123 122 124 123 //$this->logs->writeFileLog('newCustomer:', $newCustomer); … … 127 126 $this->writeFileLog('getCustomer', $ch); 128 127 } else if(empty($newCustomer)){ 129 $this->writeFileLog('getCustomer', 'EMPTY RESPONSE'); 128 $this->writeFileLog('getCustomer', 'EMPTY RESPONSE'); 130 129 } else { 131 130 if($newCustomer->no != ''){ 132 131 //Inserted client in bd 133 132 $createClientSuccess = 1; 134 } 135 } 136 137 #If client is created/obtained with success 138 if($createClientSuccess == 1){ 139 //If in settings of backoffice is checked option "create invoice" 133 } 134 } 135 136 #If client is created/obtained with success 137 if($createClientSuccess == 1){ 138 //If in settings of backoffice is checked option "create invoice" 140 139 if($settings->createInvoice){ 141 140 //See if type of order is configured 142 141 if(!empty($settings->typeOfOrder) && $settings->typeOfOrder != 0){ 143 142 144 143 //Obtain stamp of internal document based in order 145 144 $filterItem = 'bostamp'; 146 $valueItem = $order->doc_Id; 147 145 $valueItem = $order->doc_Id; 146 148 147 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', $filterItem, $valueItem); 149 148 150 149 //$this->logs->writeFileLog('Response', $response); 151 150 152 151 if (curl_error($ch)) { 153 152 $this->logs->writeFileLog('addNewOrder12', $ch); 154 153 } else if(empty($response)){ 155 $this->logs->writeFileLog('addNewOrder12', 'EMPTY RESPONSE'); 154 $this->logs->writeFileLog('addNewOrder12', 'EMPTY RESPONSE'); 156 155 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 157 $this->logs->writeFileLog('addNewOrder12', $response['messages'][0]['messageCodeLocale']); 156 $this->logs->writeFileLog('addNewOrder12', $response['messages'][0]['messageCodeLocale']); 158 157 } else { 159 158 //If internal document doesn't exists … … 161 160 162 161 # Create Internal Document 163 $getNewInternalDoc = $this->createInternalDoc($ch, $credentials, $dataPack, $fieldStatus, $newCustomer, $paisesstamp Shipping, $nomePaisShipping);162 $getNewInternalDoc = $this->createInternalDoc($ch, $credentials, $dataPack, $fieldStatus, $newCustomer, $paisesstamp, $nomePais, $paisesstampShipping, $nomePaisShipping); 164 163 165 164 if (curl_error($ch)) { 166 165 $this->logs->writeFileLog('createInternalDoc', $ch); 167 166 } else if(empty($getNewInternalDoc)){ 168 $this->logs->writeFileLog('createInternalDoc', 'EMPTY RESPONSE'); 167 $this->logs->writeFileLog('createInternalDoc', 'EMPTY RESPONSE'); 169 168 } else { 170 169 $returnOrder = $getNewInternalDoc; 171 } 170 } 172 171 //If internal document exists in system 173 172 } else if($response['result'][0]['isconfiguredtosign'] == false || ($response['result'][0]['isconfiguredtosign'] == true && $response['result'][0]['draftRecord'] == 1)){ … … 175 174 $response['result'][0]['nome2'] = $bill->nome; 176 175 $response['result'][0]['email'] = $bill->email; 176 $response['result'][0]['pais'] = $nomePais; 177 $response['result'][0]['paisesstamp'] = $paisesstamp; 177 178 $response['result'][0]['morada'] = $bill->morada; 178 179 $response['result'][0]['local'] = $bill->local; … … 182 183 $response['result'][0]['ncont'] = $bill->ncont; 183 184 184 $response['result'][0]['paisto'] = $nomePais ;185 $response['result'][0]['paisesstampto'] = $paisesstamp ;186 185 $response['result'][0]['paisto'] = $nomePaisShipping; 186 $response['result'][0]['paisesstampto'] = $paisesstampShipping; 187 187 188 if($shipping->moradato != ''){ 188 189 $response['result'][0]['moradato'] = $shipping->moradato; … … 198 199 if (is_array($order->cart)){ 199 200 foreach ($order->cart as $key => $value){ 200 if($response['result'][0]['bis'][$key]['qtt'] != $value){ 201 #Discounts 201 if($response['result'][0]['bis'][$key]['qtt'] != $value){ 202 #Discounts 202 203 if (isset($order->discount) && isset($order->discount_tax_excl)){ 203 204 //Introduce new line to add the cart discounts 204 205 $discount = array(); 205 206 206 207 $discount['bistamp'] = ''; 207 208 $discount['ref'] = ''; … … 211 212 $discount['ettdeb'] = 0 - $order->discount; 212 213 $discount['ivaincl'] = true; 213 214 214 215 array_push($response['result'][0]['bis'], $discount); 215 216 } … … 218 219 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 219 220 220 $this->logs->writeFileLog('actEntity3:', $response);221 //$this->logs->writeFileLog('actEntity3:', $response); 221 222 222 223 if (curl_error($ch)) { … … 227 228 $this->logs->writeFileLog('addNewOrder11', $response['messages'][0]['messageCodeLocale']); 228 229 } 229 230 230 231 //Obtain status 231 $statusOrderShop = $this->utils_services->genericFieldsList($settings->statusOfOrder); 232 232 $statusOrderShop = $this->utils_services->genericFieldsList($settings->statusOfOrder); 233 233 234 if(!empty($statusOrderShop)){ 234 235 $response['result'][0][$statusOrderShop] = $fieldStatus; … … 240 241 $response2 = $this->utils_services->filterItem_Query($ch, $credentials, 'Cl', 'no', $newCustomer->no); 241 242 242 $this->logs->writeFileLog('custom_by_no:', $response2);243 // $this->logs->writeFileLog('custom_by_no:', $response2); 243 244 244 245 if (curl_error($ch)) { … … 255 256 #Save internal document 256 257 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 257 258 258 259 //$this->logs->writeFileLog('save2:', $response); 259 260 … … 261 262 $this->logs->writeFileLog('addNewOrder19', $ch); 262 263 } else if(empty($response)){ 263 $this->logs->writeFileLog('addNewOrder19', 'EMPTY RESPONSE'); 264 $this->logs->writeFileLog('addNewOrder19', 'EMPTY RESPONSE'); 264 265 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 265 $this->logs->writeFileLog('addNewOrder19', $response['messages'][0]['messageCodeLocale']); 266 $this->logs->writeFileLog('addNewOrder19', $response['messages'][0]['messageCodeLocale']); 266 267 } else { 267 268 $response = $response['result'][0]; … … 270 271 return $response; 271 272 } 272 } 273 } 273 274 } 274 275 } 275 } 276 } 276 277 } 277 278 } 278 } 279 } 279 280 } 280 281 } else if(($createClientSuccess == '' || $createClientSuccess == 0) && ($tip_button == true || $tip_button == 1)){ 281 282 282 283 $_REQUEST['order_id'] = $order->order_Id; 283 284 //Verify if exists in bd … … 287 288 288 289 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', 'obrano', $_REQUEST['order_id']); 289 290 290 291 //$this->logs->writeFileLog('Response', $response); 291 292 … … 293 294 $this->logs->writeFileLog('addNewOrder20', $ch); 294 295 } else if(empty($response)){ 295 $this->logs->writeFileLog('addNewOrder20', 'EMPTY RESPONSE'); 296 $this->logs->writeFileLog('addNewOrder20', 'EMPTY RESPONSE'); 296 297 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 297 $this->logs->writeFileLog('addNewOrder20', $response['messages'][0]['messageCodeLocale']); 298 $this->logs->writeFileLog('addNewOrder20', $response['messages'][0]['messageCodeLocale']); 298 299 } else { 299 300 $hasBoOrder = false; … … 307 308 308 309 if($hasBoOrder && $response['result'][$hasBoOrderKey]['isconfiguredtosign'] == false|| ($response['result'][$hasBoOrderKey]['isconfiguredtosign'] == true && 309 $response['result'][$hasBoOrderKey]['draftRecord'] == 1)){ 310 $response['result'][$hasBoOrderKey]['draftRecord'] == 1)){ 310 311 //Obtain status 311 312 $statusOrderShop = $this->utils_services->genericFieldsList($settings->statusOfOrder); 312 313 313 314 //write in VO the status 314 315 if(!empty($statusOrderShop)){ … … 316 317 } 317 318 $response['result'][$hasBoOrderKey]['Operation'] = 2; 318 319 319 320 #Save internal document 320 321 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 321 322 322 323 //$this->logs->writeFileLog('save3:', $response); 323 324 324 325 if (curl_error($ch)) { 325 326 $this->logs->writeFileLog('addNewOrder21', $ch); 326 327 } else if(empty($response)){ 327 $this->logs->writeFileLog('addNewOrder21', 'EMPTY RESPONSE'); 328 $this->logs->writeFileLog('addNewOrder21', 'EMPTY RESPONSE'); 328 329 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 329 $this->logs->writeFileLog('addNewOrder21', $response['messages'][0]['messageCodeLocale']); 330 } 330 $this->logs->writeFileLog('addNewOrder21', $response['messages'][0]['messageCodeLocale']); 331 } 331 332 } 332 333 } … … 334 335 } else { 335 336 //Show message with error 336 $this->logs->writeFileLog('coin', 'Please configure currency in shop according to PHC application'); 337 $this->logs->writeFileLog('coin', 'Please configure currency in shop according to PHC application'); 337 338 unset($_SESSION['username']); 338 339 … … 344 345 345 346 return $returnOrder; 346 } 347 } 347 348 } 348 349 349 public function createInternalDoc($ch, $credentials, $dataPack, $fieldStatus, $newCustomer, $paisesstamp Shipping, $nomePaisShipping){350 public function createInternalDoc($ch, $credentials, $dataPack, $fieldStatus, $newCustomer, $paisesstamp, $nomePais, $paisesstampShipping, $nomePaisShipping){ 350 351 351 352 ### … … 355 356 $shipping = $dataPack->shipping; 356 357 357 358 358 359 //Obtain new instance of Bo 359 360 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'BoWS', $settings->typeOfOrder); 360 361 362 //Clear the product lines 363 $response['result'][0]['bis'] = []; 364 361 365 //$this->logs->writeFileLog('BoWs Response', $response); 362 366 … … 364 368 $this->logs->writeFileLog('addNewOrder13', $ch); 365 369 } else if(empty($response)){ 366 $this->logs->writeFileLog('addNewOrder13', 'EMPTY RESPONSE'); 370 $this->logs->writeFileLog('addNewOrder13', 'EMPTY RESPONSE'); 367 371 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 368 $this->logs->writeFileLog('addNewOrder13', $response['messages'][0]['messageCodeLocale']); 372 $this->logs->writeFileLog('addNewOrder13', $response['messages'][0]['messageCodeLocale']); 369 373 } else { 370 374 371 375 //Obtain number of customer 372 376 $response['result'][0]['no'] = $newCustomer->no; 373 377 #actEntity 374 378 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 375 376 //$this->logs->writeFileLog('actEntity:', $response );377 379 380 //$this->logs->writeFileLog('actEntity:', $response['result'][0]); 381 378 382 if (curl_error($ch)) { 379 383 $this->logs->writeFileLog('addNewOrder13.1', $ch); 380 384 } else if(empty($response)){ 381 $this->logs->writeFileLog('addNewOrder13.1', 'EMPTY RESPONSE'); 385 $this->logs->writeFileLog('addNewOrder13.1', 'EMPTY RESPONSE'); 382 386 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 383 $this->logs->writeFileLog('addNewOrder13.1', $response['messages'][0]['messageCodeLocale']); 384 } else { 385 387 $this->logs->writeFileLog('addNewOrder13.1', $response['messages'][0]['messageCodeLocale']); 388 } else { 389 386 390 #Put the same number of order in PHC 387 391 if($response['result'][0]['isconfiguredtosign'] == true){ … … 393 397 } 394 398 else { 395 399 396 400 $response['result'][0]['obrano'] = $order->nextPostId; 397 401 } … … 399 403 #Get taxes from Phc 400 404 $responseTaxes = $this->utils_services->getTaxes($ch, $credentials); 401 405 402 406 //$this->logs->writeFileLog('Get Taxes:', $responseTaxes); 403 407 404 408 if (curl_error($ch)) { 405 409 $this->logs->writeFileLog('addNewOrder13.1.1', $ch); 406 410 } else if(empty($responseTaxes)){ 407 $this->logs->writeFileLog('addNewOrder13.1.1', 'EMPTY RESPONSE'); 411 $this->logs->writeFileLog('addNewOrder13.1.1', 'EMPTY RESPONSE'); 408 412 } else if(isset($responseTaxes['messages'][0]['messageCodeLocale'])){ 409 $this->logs->writeFileLog('addNewOrder13.1.1', $responseTaxes['messages'][0]['messageCodeLocale']); 410 } 411 413 $this->logs->writeFileLog('addNewOrder13.1.1', $responseTaxes['messages'][0]['messageCodeLocale']); 414 } 415 412 416 #Obtain name and price of delivery 413 417 //Obtain VO with updated Bo 414 418 foreach ($order->cart as $product) { 415 419 //product 416 if($product['qtt']*$product['epv'] != 0){ 417 $bi = new stdClass(); 420 if($product['qtt']*$product['epv'] != 0){ 421 $bi = new stdClass(); 418 422 419 423 $bi->ref = $product['ref']; … … 423 427 } 424 428 } 425 429 426 430 #shipping 427 431 if (isset($shipping->shipping_name)){ … … 430 434 if($settings->shippingName != "") { 431 435 $bi->ref = $settings->shippingName; 432 } 436 } 433 437 434 438 $bi->design = $shipping->shipping_name; 435 $bi->qtt = 1; 439 $bi->qtt = 1; 436 440 $bi->edebito = $bi->ettdeb = $shipping->shipping_value; 437 441 438 442 if($settings->includeTaxonSendCost == "true") { 439 443 $bi->ivaincl=true; 440 } 444 } 441 445 //IVA for shipping 442 446 foreach ($responseTaxes['result'] as $tax) { 443 447 if ($shipping->shipping_tax == $tax['taxa'] && 444 448 $shipping->shipping_country == $tax['regiao']) { 445 //get IVA 449 //get IVA 446 450 $bi->iva = $tax['taxa']; 447 451 $bi->tabiva = $tax['codigo']; 448 break; 449 } 450 } 452 break; 453 } 454 } 451 455 if($bi->edebito == 0){ 452 456 $bi->qtt = 0; 453 457 $bi->ivaincl = false; 454 } 455 $response['result'][0]['bis'][]= $bi; 458 } 459 $response['result'][0]['bis'][]= $bi; 456 460 } 457 461 //actEntity … … 459 463 460 464 //$this->logs->writeFileLog('actEntity.0.1:', $response2); 461 465 462 466 // Update shipping value 463 467 foreach ($response2['result'][0]['bis'] as &$delivery) { 464 468 465 if ($delivery[' design'] == $shipping->shipping_name) {469 if ($delivery['ref'] == $settings->shippingName) { 466 470 //replace the price for shipping 467 471 $delivery['edebito'] = $shipping->shipping_value; 468 472 $delivery['ettdeb'] = $shipping->shipping_value; 469 } 470 } 471 473 } 474 } 475 472 476 //actEntity 473 477 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response2); 474 475 //$this->logs->writeFileLog('actEntity1:', $response);478 479 // $this->logs->writeFileLog('actEntity1:', $response); 476 480 477 481 if (curl_error($ch)) { 478 482 $this->logs->writeFileLog('addNewOrder14', $ch); 479 483 } else if(empty($response)){ 480 $this->logs->writeFileLog('addNewOrder14', 'EMPTY RESPONSE'); 484 $this->logs->writeFileLog('addNewOrder14', 'EMPTY RESPONSE'); 481 485 } else if(isset($response['messages'][0]['messageCodeLocale']) && $response['messages'][0]['messageCode']!='messages.Business.Stocks.InvalidRefAutoCreate'){ 482 $this->logs->writeFileLog('addNewOrder14', $response['messages'][0]['messageCodeLocale']); 486 $this->logs->writeFileLog('addNewOrder14', $response['messages'][0]['messageCodeLocale']); 483 487 } else { 484 488 … … 489 493 //Update list of Quantity 490 494 if( $value['qtt']*$value['epv']!=0 && $response['result'][0]['bis'][$key]['qtt'] != $value['qtt']){ 491 //get quantity 495 //get quantity 492 496 $response['result'][0]['bis'][$key]['qtt'] = $value['qtt']; 493 497 } 494 498 //Update list of Value Item (added condition "componente != 1" to skip articles that are part of a composite product.) 495 499 if( $value['qtt']*$value['epv']!=0 && $response['result'][0]['bis'][$key]['ettdeb'] != $value['epv'] && $response['result'][0]['bis'][$key]['componente'] != 1){ 496 //get quantity 500 //get quantity 497 501 $response['result'][0]['bis'][$key]['ettdeb'] = $value['epv']; 498 502 } 499 503 } 500 504 } 501 505 502 506 #Eliminate comercial discount 503 507 if (is_array($order->cart)){ … … 530 534 $response['result'][0][$statusOrderShop] = $fieldStatus; 531 535 } 532 536 533 537 //Find the type of shipment 534 538 $response['result'][0]['trab1']= $order->post_title; … … 553 557 554 558 //billing data 559 $response['result'][0]['pais'] = $nomePais; 560 $response['result'][0]['paisesstamp'] = $paisesstamp; 555 561 $response['result'][0]['morada'] = $bill->morada; 556 562 $response['result'][0]['local'] = $bill->local; … … 559 565 $response['result'][0]['codpost'] = $bill->codpost; 560 566 $response['result'][0]['ncont'] = $bill->ncont; 561 567 562 568 #Obtain taxes 563 569 if (is_array($order->cart)){ 564 //get tax rate & tax rate country 570 //get tax rate & tax rate country 565 571 foreach ($order->cart as $key => $value){ 566 572 if( $value['qtt']*$value['epv']!=0){ … … 569 575 $refProd = $value['ref']; 570 576 //obtain tax from Phc 571 foreach ($responseTaxes['result'] as $tax) { 577 foreach ($responseTaxes['result'] as $tax) { 572 578 if($taxRate == $tax['taxa'] && $taxCountry == $tax['regiao'] && $refProd == $response['result'][0]['ref']) { 573 579 $response['result'][0]['bis'][$key]['iva'] = $tax['taxa']; … … 575 581 if($settings->includeTaxonSendCost == "true") { 576 582 $response['result'][0]['bis'][$key]['ivaincl'] = true; 577 } 583 } 578 584 break; 579 585 } 580 } 581 } 582 } 583 } 584 //$this->logs->writeFileLog('Obtain taxes:', $response['result'][0]); 586 } 587 } 588 } 589 } 590 //$this->logs->writeFileLog('Obtain taxes:', $response['result'][0]); 585 591 ### 586 592 $fees = $order->fees; … … 597 603 if($settings->feesName != "") { 598 604 $bi->ref = $settings->feesName; 599 } 600 601 //IVA 605 } 606 607 //IVA 602 608 foreach ($responseTaxes['result'] as $tax) { 603 609 if ($taxRate == $tax['taxa'] && $taxCountry == $tax['regiao']) { … … 605 611 $bi->tabiva = $tax['codigo']; 606 612 607 break; 608 } 609 } 610 $response['result'][0]['bis'][]= $bi; 611 } 612 } 613 break; 614 } 615 } 616 $response['result'][0]['bis'][]= $bi; 617 } 618 } 613 619 # Discounts 614 620 if (isset($order->discount) && $order->discount > 0){ 615 621 //Introduce new line to add the cart discounts 616 622 $discount = array(); 617 623 618 624 $discount['bistamp'] = ''; 619 625 if($settings->discountRef != "") { … … 621 627 } else { 622 628 $discount['ref'] = ''; 623 } 629 } 624 630 $discount['design'] = "Desconto"; 625 631 $discount['qtt'] = 1; … … 627 633 $discount['ettdeb'] = 0 - $order->discount; 628 634 $discount['ivaincl'] = true; 629 635 630 636 array_push($response['result'][0]['bis'], $discount); 631 } 637 } 632 638 //actEntity 633 639 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); … … 638 644 $this->logs->writeFileLog('addNewOrder14.1', $ch); 639 645 } else if(empty($response)){ 640 $this->logs->writeFileLog('addNewOrder14.1', 'EMPTY RESPONSE'); 646 $this->logs->writeFileLog('addNewOrder14.1', 'EMPTY RESPONSE'); 641 647 } else if(isset($response['messages'][0]['messageCodeLocale']) && $response['messages'][0]['messageCode']!='messages.Business.Stocks.InvalidRefAutoCreate'){ 642 $this->logs->writeFileLog('addNewOrder14.1', $response['messages'][0]['messageCodeLocale']); 648 $this->logs->writeFileLog('addNewOrder14.1', $response['messages'][0]['messageCodeLocale']); 643 649 } else { 644 650 // Update discount value 645 651 foreach ($response['result'][0]['bis'] as &$dDiscount) { 646 652 647 653 if ($dDiscount['design'] == "Desconto") { 648 654 //replace the price for shipping 649 655 $dDiscount['edebito'] = 0 - $order->discount; 650 656 $dDiscount['ettdeb'] = 0 - $order->discount; 651 } 657 } 652 658 } 653 659 //Insert … … 657 663 if($response['result'][0]['isconfiguredtosign'] == true){ 658 664 659 $numberOfOrder = $this->utils_services->genericFieldsList($settings->numberOfOrder); 665 $numberOfOrder = $this->utils_services->genericFieldsList($settings->numberOfOrder); 660 666 661 667 if(!empty($numberOfOrder)){ … … 664 670 } 665 671 else { 666 672 667 673 $response['result'][0]['obrano'] = $order->nextPostId; 668 674 } … … 670 676 #Save internal document 671 677 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 672 678 673 679 //$this->logs->writeFileLog('save1:', $response); 674 680 … … 676 682 $this->logs->writeFileLog('addNewOrder15', $ch); 677 683 } else if(empty($response)){ 678 $this->logs->writeFileLog('addNewOrder15', 'EMPTY RESPONSE'); 684 $this->logs->writeFileLog('addNewOrder15', 'EMPTY RESPONSE'); 679 685 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 680 686 $this->logs->writeFileLog('addNewOrder15', $response['messages'][0]['messageCodeLocale']); … … 683 689 $response['result'][0]['paisesstampto'] = $paisesstampShipping; 684 690 685 //fulfill the second name field with customer name corresponding to the invoice 691 //fulfill the second name field with customer name corresponding to the invoice 686 692 $response['result'][0]['nome2'] = $bill->nome;; 687 693 … … 690 696 } else if ($shipping_address_1_ != ''){ 691 697 $response['result'][0]['moradato'] = $shipping_address_1_; 692 } 698 } 693 699 694 700 if($shipping->moradato != ''){ … … 706 712 #Save internal document 707 713 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 708 714 709 715 // $this->logs->writeFileLog('save2:', $response); 710 716 … … 712 718 $this->logs->writeFileLog('addNewOrder16', $ch); 713 719 } else if(empty($response)){ 714 $this->logs->writeFileLog('addNewOrder16', 'EMPTY RESPONSE'); 720 $this->logs->writeFileLog('addNewOrder16', 'EMPTY RESPONSE'); 715 721 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 716 $this->logs->writeFileLog('addNewOrder16', $response['messages'][0]['messageCodeLocale']); 722 $this->logs->writeFileLog('addNewOrder16', $response['messages'][0]['messageCodeLocale']); 717 723 } else { 718 $response = $response['result'][0]; 724 $response = $response['result'][0]; 719 725 720 726 if($response['isconfiguredtosign'] == true && $response['draftRecord'] == 1 && $settings->toSignOrder){ … … 727 733 $this->logs->writeFileLog('addNewOrder17', $ch); 728 734 } else if(empty($response)){ 729 $this->logs->writeFileLog('addNewOrder17', 'EMPTY RESPONSE'); 735 $this->logs->writeFileLog('addNewOrder17', 'EMPTY RESPONSE'); 730 736 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 731 $this->logs->writeFileLog('addNewOrder17', $response['messages'][0]['messageCodeLocale']); 737 $this->logs->writeFileLog('addNewOrder17', $response['messages'][0]['messageCodeLocale']); 732 738 } else { 733 739 $response = $response['result'][0]; 734 $this->logs->writeFileLog('addNewOrder17 ', "Signed order: " . $response['obrano'] );735 740 $this->logs->writeFileLog('addNewOrder17.1', "Signed order: " . $response['obrano'] ); 741 736 742 } 737 743 //return data of Bo to save FT 738 return $response; 744 return $response; 739 745 } 740 746 } … … 745 751 } 746 752 } 753 $this->logs->writeFileLog('addNewOrder17.2', "Order number: ".$response['obrano']." was created!" ); 754 747 755 return $response; 748 756 } -
drivefx-woocommerce/trunk/PHCLibrary/utils.php
r2456866 r2526532 1 1 <?php 2 DEFINE ( 'VIES_URL', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService'); 2 3 3 4 class UtilsServices { … … 17 18 ********************************************************************/ 18 19 /** Curls builder **/ 19 public function doPhcRequest($ch, $url, $params, $credentials) { 20 public function doPhcRequest($ch, $url, $params, $credentials) { 20 21 21 22 $tokenHeader = array( 'Authorization' => 'Engine-Auth:'.$credentials->token, 'Content-Type' => 'application/json' ); … … 26 27 curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 27 28 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 28 29 29 30 $response = curl_exec($ch); 30 31 31 $response = json_decode($response, true); 32 $response = json_decode($response, true); 32 33 return $response; 33 34 … … 38 39 ********************************************************************/ 39 40 /** Header to create Query of webservice called **/ 40 public function paramsGetBackEndInfo($ch, $credentials){ 41 $this->url = $credentials->backendUrl."/REST/UserLoginWS/getBackEndInfo"; 42 //Create map with request parameters 43 $this->params = array ('loginInfoVO' => '{"userCode": "'.$credentials->userCode.'", 44 "password": "'.$credentials->password.'", 45 "company": "'.$credentials->company.'", 46 "language": "", 47 "hash": "" 41 public function paramsGetBackEndInfo($ch, $credentials){ 42 $this->url = $credentials->backendUrl."/REST/UserLoginWS/getBackEndInfo"; 43 //Create map with request parameters 44 $this->params = array ('loginInfoVO' => '{"userCode": "'.$credentials->userCode.'", 45 "password": "'.$credentials->password.'", 46 "company": "'.$credentials->company.'", 47 "language": "", 48 "hash": "" 48 49 }' 49 ); 50 //Build Http query using params 51 $this->query = http_build_query ($this->params); 52 53 //Called webservice that make a request 54 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 55 56 return $response; 57 } 58 50 ); 51 //Build Http query using params 52 $this->query = http_build_query ($this->params); 53 54 //Called webservice that make a request 55 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 56 57 return $response; 58 } 59 59 60 /******************************************************************* 60 61 * --- Get Frontend Info --- * 61 62 ********************************************************************/ 62 63 /** Header to save information of webservice called **/ 63 public function paramsGetFrontendInfo($ch, $credentials){ 64 public function paramsGetFrontendInfo($ch, $credentials){ 64 65 $this->url = $credentials->backendUrl."/REST/ParameterWS/getFrontEndParameters"; 65 66 //Create map with request parameters 66 $this->$params = array ('loginInfoVO' => '{"userCode": "'.$credentials->userCode.'", 67 "password": "'.$credentials->password.'", 68 "company": "'.$credentials->company.'", 69 "language": "", 70 "hash": "" 67 $this->$params = array ('loginInfoVO' => '{"userCode": "'.$credentials->userCode.'", 68 "password": "'.$credentials->password.'", 69 "company": "'.$credentials->company.'", 70 "language": "", 71 "hash": "" 71 72 }' 72 ); 73 ); 73 74 //Build Http query using params 74 75 $this->$query = http_build_query ($this->$params); … … 77 78 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 78 79 79 return $response; 80 80 return $response; 81 81 82 } 82 83 … … 106 107 ); 107 108 //Build Http query using params 108 $this->query = http_build_query ($this->params); 109 110 //Called webservice that make a request 111 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 112 113 return $response; 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 114 return $response; 114 115 } 115 116 … … 118 119 ********************************************************************/ 119 120 /** Query with a comparison filter **/ 120 121 121 122 public function filterItem_compare($ch, $credentials, $entityName, $comparison, $filterItem = null, $valueItem = null){ 122 123 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; … … 138 139 }]}' 139 140 ); 140 141 //Build Http query using params 142 $this->query = http_build_query ($this->params); 143 144 //Called webservice that make a request 145 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 146 147 return $response; 141 142 //Build Http query using params 143 $this->query = http_build_query ($this->params); 144 145 //Called webservice that make a request 146 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 147 148 return $response; 148 149 } 149 150 … … 152 153 ********************************************************************/ 153 154 /** Query with a comparison filter **/ 154 155 155 156 public function doubleFilter($ch, $credentials, $entityName, $filterItem = null, $valueItem = null,$filterItem2 = null, $valueItem2 = null){ 156 157 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; … … 182 183 ); 183 184 //Build Http query using params 184 $this->query = http_build_query ($this->params); 185 186 //Called webservice that make a request 187 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 188 189 return $response; 185 $this->query = http_build_query ($this->params); 186 187 //Called webservice that make a request 188 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 189 190 return $response; 190 191 } 191 192 … … 208 209 ); 209 210 //Build Http query using params 210 $this->query = http_build_query ($this->params); 211 212 //Called webservice that make a request 213 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 214 215 return $response; 211 $this->query = http_build_query ($this->params); 212 213 //Called webservice that make a request 214 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 215 216 return $response; 216 217 } 217 218 … … 243 244 //Build Http query using params 244 245 $this->query = http_build_query ($this->params); 245 246 //Called webservice that make a request 247 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 248 249 return $response; 246 247 //Called webservice that make a request 248 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 249 250 return $response; 250 251 } 251 252 … … 268 269 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 269 270 270 return $response; 271 return $response; 271 272 } 272 273 … … 293 294 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 294 295 295 return $response; 296 return $response; 296 297 } 297 298 … … 300 301 ********************************************************************/ 301 302 //Header to create Query of webservice called 302 public function paramsQuery4($ch, $entityName, $selectItems, $valueItem){ 303 //get credentials 304 $credentials = $this->configs->fetchCredentials(); 305 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 306 // Create map with request parameters 307 $this->params = array ('itemQuery' => '{"groupByItems":[], 308 "lazyLoaded":false, 309 "joinEntities":[], 310 "orderByItems":[], 311 "SelectItems":["'.$selectItems.'"], 312 "entityName":"'.$entityName.'", 313 "filterItems":[{ 314 "comparison":0, 315 "filterItem":"ndos", 316 "valueItem":'.$valueItem.', 317 "groupItem":1, 318 "checkNull":false, 319 "skipCheckType":false, 320 "type":"Number" 321 }]}' 322 ); 323 324 // Build Http query using params 325 $this->query = http_build_query ($this->params); 326 327 //Called webservice that make a request 328 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 329 330 return $response; 303 public function paramsQuery4($ch, $credentials, $entityName, $selectItems, $valueItem){ 304 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 305 // Create map with request parameters 306 $this->params = array ('itemQuery' => '{"groupByItems":[], 307 "lazyLoaded":false, 308 "joinEntities":[], 309 "orderByItems":[], 310 "SelectItems":["'.$selectItems.'"], 311 "entityName":"'.$entityName.'", 312 "filterItems":[{ 313 "comparison":0, 314 "filterItem":"ndos", 315 "valueItem":'.$valueItem.', 316 "groupItem":1, 317 "checkNull":false, 318 "skipCheckType":false, 319 "type":"Number" 320 }]}' 321 ); 322 323 // Build Http query using params 324 $this->query = http_build_query ($this->params); 325 326 //Called webservice that make a request 327 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 328 329 return $response; 331 330 } 332 331 … … 363 362 }]}' 364 363 ); 365 366 // Build Http query using params 367 $this->query = http_build_query ($this->params); 368 369 //Called webservice that make a request 370 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 371 372 return $response; 364 365 // Build Http query using params 366 $this->query = http_build_query ($this->params); 367 368 //Called webservice that make a request 369 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 370 371 return $response; 373 372 } 374 373 … … 382 381 // Create map with request parameters 383 382 $this->params = array ('ndos' => $ndos); 384 385 // Build Http query using params 386 $this->query = http_build_query ($this->params); 387 388 //Called webservice that make a request 389 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 390 391 return $response; 383 384 // Build Http query using params 385 $this->query = http_build_query ($this->params); 386 387 //Called webservice that make a request 388 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 389 390 return $response; 392 391 } 393 392 … … 401 400 // Create map with request parameters 402 401 $this->params = array ('entity' => json_encode($response['result'][0]), 403 'code' => 0, 402 'code' => 0, 404 403 'newValue' => "{}"); 405 404 … … 410 409 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 411 410 412 return $response; 411 return $response; 413 412 } 414 413 … … 440 439 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 441 440 442 return $response; 441 return $response; 443 442 } 444 443 … … 467 466 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 468 467 469 return $response; 470 } 471 468 return $response; 469 } 470 472 471 /******************************************************************* 473 472 * --- SAVE --- * … … 478 477 // Create map with request parameters 479 478 $this->params = array ('itemVO' => json_encode($response['result'][0]), 480 'runWarningRules' => 'false'); 479 'runWarningRules' => 'false'); 481 480 // Build Http query using params 482 481 $this->query = http_build_query ($this->params); … … 550 549 "stamp":"'.$ftstamp.'"}], 551 550 "reportStamp":"'.$repstamp.'", 552 "sendToType":0,"serie":0}'); 553 554 555 556 // Build Http query using params 557 $this->query = http_build_query ($this->params); 558 551 "sendToType":0,"serie":0}'); 552 553 554 555 // Build Http query using params 556 $this->query = http_build_query ($this->params); 557 559 558 //Called webservice that make a request 560 559 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); … … 570 569 571 570 $tokenHeader = array( 'Authorization' => 'Engine-Auth:'.$credentials->token, 'Content-Type' => 'application/json' ); 572 571 573 572 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 574 573 // Create map with request parameters … … 589 588 // Build Http query using params 590 589 $this->query = http_build_query ($this->params); 591 590 592 591 //Called webservice that make a request 593 592 curl_setopt($ch, CURLOPT_URL, $this->url); … … 598 597 curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); 599 598 $response = curl_exec($ch); 600 599 601 600 $response = json_decode($response, true); 602 601 603 602 return $response; 604 603 } … … 648 647 649 648 $tokenHeader = array( 'Authorization' => 'Engine-Auth:'.$credentials->token, 'Content-Type' => 'application/json' ); 650 649 651 650 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 652 651 // Create map with request parameters … … 661 660 "groupItem": 0 662 661 }], 663 "limit": 1, 662 "limit": 1, 664 663 "offset": 0, 665 664 "orderByItems": [ … … 674 673 // Build Http query using params 675 674 $this->query = http_build_query ($this->params); 676 675 677 676 //Called webservice that make a request 678 677 curl_setopt($ch, CURLOPT_URL, $this->url); … … 683 682 curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); 684 683 $response = curl_exec($ch); 685 684 686 685 $response = json_decode($response, true); 687 686 687 return $response; 688 } 689 690 /******************************************************************* 691 * --- Get Recent Internal Document --- * 692 ********************************************************************/ 693 function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) { 694 $response = array (); 695 $pattern = '/<(%s).*?>([\s\S]*)<\/\1/'; 696 $keys = array ( 697 'countryCode', 698 'vatNumber', 699 'requestDate', 700 'valid', 701 'name', 702 'address' 703 ); 704 705 $content = "<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'> 706 <s11:Body> 707 <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'> 708 <tns1:countryCode>%s</tns1:countryCode> 709 <tns1:vatNumber>%s</tns1:vatNumber> 710 </tns1:checkVat> 711 </s11:Body> 712 </s11:Envelope>"; 713 714 $opts = array ( 715 'http' => array ( 716 'method' => 'POST', 717 'header' => "Content-Type: text/xml; charset=utf-8; SOAPAction: checkVatService", 718 'content' => sprintf ( $content, $countryCode, $vatNumber ), 719 'timeout' => $timeout 720 ) 721 ); 722 723 $ctx = stream_context_create ( $opts ); 724 $result = file_get_contents ( VIES_URL, false, $ctx ); 725 726 if (preg_match ( sprintf ( $pattern, 'checkVatResponse' ), $result, $matches )) { 727 foreach ( $keys as $key ) 728 preg_match ( sprintf ( $pattern, $key ), $matches [2], $value ) && $response [$key] = $value [2]; 729 } 688 730 return $response; 689 731 } -
drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php
r2456862 r2526532 27 27 'backend' => array( 28 28 'username' => array('label' => 'Username', 'type' => 'text', 'required' => true, 'descr' => 'This username allows the backend to accept data sent from this plugin.', 'notice' => 'This can not be empty! Please enter your username...'), 29 'password' => array('label' => 'Password', 'type' => 'password', 'required' => true, 'descr' => 'This password allows the backend to accept data sent from this plugin.', 'notice' => 'This can not be empty! Please enter your password...'), 29 'password' => array('label' => 'Password', 'type' => 'password', 'required' => true, 'descr' => 'This password allows the backend to accept data sent from this plugin.', 'notice' => 'This can not be empty! Please enter your password...'), 30 30 'url' => array('label' => 'Backend URL', 'type' => 'url', 'required' => true, 'descr' => 'The URL of your PHC GO application.<br>Something like, e.g. https://sisXX.phcgo.net/XPTO/html', 'notice' => 'No backend URL! Please define your backend URL...'), 31 31 'dbname' => array('label' => 'Database Name', 'type' => 'text', 'required' => false, 'descr' => 'Enter the name of the PHC GO where you want save your information.<br>You can leave this empty if you only work with one company.', 'notice' => ''), … … 37 37 'fieldNif' => array('label' => 'NIF Field in Woocommerce', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the nif field of woocommerce', 'notice' => ''), 38 38 'includeTaxonSendCost' => array('label' => 'Tax included in products Cost?', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Does the products cost has tax already included in price?', 'notice' => ''), 39 'createExempt Cl' => array('label' => 'Create tax-exempt customers?', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Create tax-free customers (for foreigners)', 'notice' => ''),39 'createExemptPT' => array('label' => 'From outside PT', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Save customers from outside Portugal as tax-exempt', 'notice' => ''), 40 40 'typeOfReason' => array('label' => 'Select tax exempt reason', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the reason for the tax exemption', 'notice' => ''), 41 'createExemptEU' => array('label' => 'From outside EU', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Save customers from outside EU as tax-exempt', 'notice' => ''), 42 'typeOfReasonEU' => array('label' => 'Select tax exempt reason', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the reason for the tax exemption', 'notice' => ''), 43 'createExemptCO' => array('label' => 'From EU', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Save customers companies from EU as tax-exempt', 'notice' => ''), 44 'typeOfReasonCO' => array('label' => 'Select tax exempt reason', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the reason for the tax exemption', 'notice' => ''), 41 45 'warehouseOrder' => array('label' => 'Order Warehouse', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose from warehouse do you want import products', 'notice' => ''), 42 46 'typeOfOrder' => array('label' => 'Type of Order', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose the type of order', 'notice' => ''), … … 58 62 public static function self() { 59 63 if (self::$instance) return $instance; 60 64 61 65 return new DriveFxWoocommerce(); 62 66 } … … 64 68 private function __construct () { 65 69 $this->logs = new Logs(); 66 $this->auth_services = new AuthentificationService(); 67 $this->syncro_services = new SyncroService(); 68 $this->utils_services = new UtilsServices(); 69 $this->orders_services = new OrdersService(); 70 $this->invoices_services = new InvoicesServices(); 70 $this->auth_services = new AuthentificationService(); 71 $this->syncro_services = new SyncroService(); 72 $this->utils_services = new UtilsServices(); 73 $this->orders_services = new OrdersService(); 74 $this->invoices_services = new InvoicesServices(); 71 75 72 76 // call init … … 75 79 // store default BACKEND fields settings 76 80 add_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME, array('backend' => $this->options['backend'])); 77 78 } 79 81 82 } 83 80 84 //Initializes WordPress hooks 81 85 private function init() { … … 92 96 // handler to show notices in admin panel 93 97 add_action('admin_menu', array($this, 'render_notices')); 94 98 95 99 //Obtain status of order in online shop 96 100 add_action( 'woocommerce_order_status_pending', array($this, 'statusPending')); … … 102 106 add_action( 'woocommerce_order_status_failed', array($this, 'statusFailed')); 103 107 104 // HOOKS WOOCOMMERCE - ORDER Status 108 // HOOKS WOOCOMMERCE - ORDER Status 105 109 add_action( 'woocommerce_order_status_pending', array($this, 'addNewOrder')); 106 110 add_action( 'woocommerce_order_status_on-hold', array($this, 'addNewOrder')); 107 111 add_action( 'woocommerce_order_status_processing', array($this, 'addNewOrder')); 108 112 109 113 add_action( 'woocommerce_order_status_completed', array($this, 'completedOrder'),2); 110 114 add_action( 'woocommerce_order_status_cancelled', array($this, 'cancelOrder')); … … 116 120 117 121 // handler for form submission 118 add_action('admin_post_woocommerce_fx', array($this, 'woocommerce_fx')); 122 add_action('admin_post_woocommerce_fx', array($this, 'woocommerce_fx')); 119 123 120 124 //Verify if exists token in mysql db 121 125 global $wpdb; 122 $table_name = $wpdb->prefix."postmeta"; 126 $table_name = $wpdb->prefix."postmeta"; 123 127 124 128 //If exists GET['fxtoken'], so popup is open to obtain key … … 126 130 return; 127 131 $accessToken = filter_var($_GET['accessToken'], FILTER_SANITIZE_STRING); 128 132 129 133 if($accessToken != ''){ 130 134 $accessToken = str_replace(' ', '+', $accessToken); … … 133 137 $query = "SELECT * FROM %s WHERE meta_key = %s"; 134 138 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token'))); 135 139 136 140 //Verify if token already exists 137 141 if($resultDB->meta_id != ''){ 138 142 //Delete value in database mysql 139 delete_post_meta($resultDB->post_id, '_token'); 140 143 delete_post_meta($resultDB->post_id, '_token'); 144 141 145 //Obtain next post_id of order in MySQL 142 146 $query = "SELECT MAX(post_id)+1 as nextPostId FROM %s"; 143 147 $token = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 144 148 145 149 //add to table postmeta a key of order and stamp of internal document 146 add_post_meta($token->nextPostId, '_token', $accessToken); 150 add_post_meta($token->nextPostId, '_token', $accessToken); 147 151 } else { 148 152 //Obtain next post_id of order in MySQL … … 173 177 174 178 } 175 179 176 180 //Obtain info of plugins and save information 177 181 public function init_plugin() { … … 194 198 } 195 199 196 public function register_scripts() { 200 public function register_scripts() { 197 201 ?> <script> 198 202 var pathPlugin = "<?php echo plugins_url('/' , __FILE__ ); ?>"; 199 203 </script> <?php 200 204 201 205 // register scripts that will be used later on 202 206 wp_register_script(DRIVEFXWOOCOMMERCE_PLUGIN_NAME, plugins_url('/js/'.DRIVEFXWOOCOMMERCE_PLUGIN_NAME.'.js' , __FILE__ )); 203 207 wp_register_script('datatable_min', plugins_url('/js/datatable_min.js' , __FILE__ )); 204 208 205 209 // register css that will be used later on 206 210 wp_register_style('style_datatable_jquery', plugins_url('/css/style_datatable_jquery.css' , __FILE__ )); … … 211 215 public function render_settings() { 212 216 include(DRIVEFXWOOCOMMERCE_PLUGIN_DIR.'drivefx-woocommerce-settings.php'); 213 217 214 218 // inject our JS script 215 219 wp_enqueue_script(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 216 220 wp_enqueue_script('datatable_min'); 217 221 218 222 //inject our css of datatable 219 223 wp_enqueue_style('style_datatable_jquery'); 220 224 wp_enqueue_style('datatable_css'); 221 225 222 226 // inject data (settings) and default messages to JS 223 227 wp_localize_script(DRIVEFXWOOCOMMERCE_PLUGIN_NAME, 'settings', $settings); 224 228 225 229 // inject also the server-side script that will handle the form submission 226 230 wp_localize_script(DRIVEFXWOOCOMMERCE_PLUGIN_NAME, 'url', admin_url('admin-post.php')); … … 247 251 if ($_GET["page"] != "drivefx-woocommerce") 248 252 return; 249 253 250 254 $notices = array(); 251 255 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); … … 284 288 <p><strong><?php echo $message ?></strong></p> 285 289 </div><?php 286 } 290 } 287 291 288 292 //Verify if backend configurations are configured … … 295 299 $notices[$opts['label']] = $opts['notice']; 296 300 $verifyWarning = true; 297 } 301 } 298 302 } 299 303 … … 309 313 //Called from "external files" 310 314 public function woocommerce_fx() { 311 315 312 316 $method = sanitize_text_field( $_POST['method'] ); 313 317 314 318 if(is_array($_POST['refs'])){ 315 $refs = filter_var_array($_POST['refs'], FILTER_SANITIZE_STRING); 319 $refs = filter_var_array($_POST['refs'], FILTER_SANITIZE_STRING); 316 320 } else { 317 321 $refs = ''; … … 319 323 320 324 if(isset($_POST['selectItems'])){ 321 $selectItems = filter_var($_POST['selectItems'], FILTER_SANITIZE_STRING); 325 $selectItems = filter_var($_POST['selectItems'], FILTER_SANITIZE_STRING); 322 326 } else { 323 327 $selectItems = ''; … … 325 329 326 330 if(isset($_POST['typeOfOrder'])){ 327 $typeOfOrder = filter_var($_POST['typeOfOrder'], FILTER_SANITIZE_STRING); 331 $typeOfOrder = filter_var($_POST['typeOfOrder'], FILTER_SANITIZE_STRING); 328 332 } else { 329 333 $typeOfOrder = ''; … … 331 335 332 336 if(isset($_POST['nameTypeOfOrder'])){ 333 $nameTypeOfOrder = filter_var($_POST['nameTypeOfOrder'], FILTER_SANITIZE_STRING); 337 $nameTypeOfOrder = filter_var($_POST['nameTypeOfOrder'], FILTER_SANITIZE_STRING); 334 338 } else { 335 339 $nameTypeOfOrder = ''; … … 337 341 338 342 if(isset($_POST['manageStock'])){ 339 $manageStock = filter_var($_POST['manageStock'], FILTER_SANITIZE_STRING); 343 $manageStock = filter_var($_POST['manageStock'], FILTER_SANITIZE_STRING); 340 344 } else { 341 345 $manageStock = ''; … … 343 347 344 348 if(isset($_POST['warehouse'])){ 345 $warehouse = filter_var($_POST['warehouse'], FILTER_SANITIZE_STRING); 349 $warehouse = filter_var($_POST['warehouse'], FILTER_SANITIZE_STRING); 346 350 } else { 347 351 $warehouse = ''; 348 352 } 349 353 350 354 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 351 355 352 356 // get Credentials 353 $credentials = $this->syncro_services->fetchCredentials(); 357 $credentials = $this->syncro_services->fetchCredentials(); 354 358 //Obtain configuration to make login 355 $ch = $this->auth_services->PHCLogin($ch, $credentials); 359 $ch = $this->auth_services->PHCLogin($ch, $credentials); 356 360 //initial request with login data 357 $response = curl_exec($ch); 361 $response = curl_exec($ch); 358 362 // send response as JSON 359 $response = json_decode($response, true); 363 $response = json_decode($response, true); 360 364 // get the temporary token and insert in credentials object 361 $credentials->token = $response['result'][0]['token']; 362 365 $credentials->token = $response['result'][0]['token']; 366 363 367 //$this->logs->writeFileLog('Login response:', $response); 364 368 365 369 if (curl_error($ch)) { 366 370 $this->logs->writeFileLog('setCommunicationFxWooCommerce', $ch); … … 377 381 //Save data of login to show in backend.php the other fields (type of invoice and type of order) 378 382 $_SESSION['username'] = $response['result'][0]['username']; 379 383 380 384 //Obtain gama of PHC 381 385 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 382 386 383 387 //$this->logs->writeFileLog('BackEnd response:', $response); 384 388 … … 392 396 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 393 397 } 394 398 395 399 //Obtain parameter of manage stock 396 $response = $this->utils_services->paramsGetFrontendInfo($ch, $credentials); 400 $response = $this->utils_services->paramsGetFrontendInfo($ch, $credentials); 397 401 398 402 //$this->logs->writeFileLog('FrontEnd response:', $response); 399 403 400 404 if (curl_error($ch)) { 401 405 $this->logs->writeFileLog('setCommunicationFx2WooCommerce.1', $ch); … … 405 409 $this->logs->writeFileLog('setCommunicationFx2WooCommerce.1', $response['messages'][0]['messageCodeLocale']); 406 410 } else { 407 foreach ($response['result'] as $key => $value){ 411 foreach ($response['result'] as $key => $value){ 408 412 if($response['result'][$key]['descricao'] === 'AllowStocks'){ 409 413 $_SESSION['manageStockParameter'] = $response['result'][$key]['valor']; … … 428 432 } 429 433 break; 434 case 'updatePricesProducts': 435 //Update only prices of products 436 return $this->updatePricesProducts($refs); 437 break; 430 438 case 'updateAllFieldsProducts': 431 439 //Update all fields of products 432 440 return $this->updateAllFieldsProducts($refs); 433 break; 441 break; 434 442 case 'statusOfOrder': 435 443 if($_SESSION['gamaDRIVEFX'] >= 9) { … … 452 460 case 'updateTypeOfOrder': 453 461 if($_SESSION['gamaDRIVEFX'] >= 9) { 454 //Update type of order dropdownlist 462 //Update type of order dropdownlist 455 463 $this->updateTypeOfOrders(); 456 464 } … … 538 546 )); 539 547 return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); 540 } 541 542 //Lock System 548 } 549 550 //Lock System 543 551 public function lockStart() { 544 552 $this->logs->writeFileLog('lockStart', "Entrei" ); … … 546 554 547 555 $maxAttempt=10; 548 556 549 557 for($attempt=0;$attempt<$maxAttempt;$attempt++){ 550 558 $lockFilePath = __DIR__.'/logsErrors/tim.lock'; 551 559 $date = new DateTime(); 552 560 $time = $date->getTimestamp(); 553 561 554 562 if (!file_exists($lockFilePath)){ 555 563 @file_put_contents($lockFilePath, $time); … … 558 566 continue; 559 567 } 560 568 561 569 $this->logs->writeFileLog('lockStart', "Sai" ); 562 563 return true; 564 565 } 566 570 571 return true; 572 573 } 574 567 575 $contents = file_get_contents($lockFilePath); 568 576 569 577 $lockedtime = (int)$contents; 570 578 571 579 if($time-$lockedtime>10){ 572 580 573 581 unlink($lockFilePath); 574 582 @file_put_contents($lockFilePath, $time); … … 580 588 return true; 581 589 }else{ 582 590 583 591 sleep(1); 584 592 continue; 585 593 } 586 587 594 595 588 596 } 589 597 $this->logs->writeFileLog('lockStart', "Sair"); 590 598 return true; 591 599 592 600 593 601 } 594 602 … … 600 608 return true; 601 609 } 602 610 603 611 604 612 /** Order Status **/ … … 606 614 public function statusPending() { 607 615 $this->fieldStatus = "Pending"; 608 616 609 617 } 610 618 //Change order status … … 634 642 635 643 636 //Communicate with FX backend and obtain type of invoice document and type of order 644 //Communicate with FX backend and obtain type of invoice document and type of order 637 645 public function setCommunicationFx() { 638 646 session_start(); 639 647 640 648 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 641 649 // get Credentials 642 $credentials = $this->syncro_services->fetchCredentials(); 650 $credentials = $this->syncro_services->fetchCredentials(); 643 651 //Obtain configuration to make login 644 $ch = $this->auth_services->PHCLogin($ch, $credentials); 652 $ch = $this->auth_services->PHCLogin($ch, $credentials); 645 653 //initial request with login data 646 654 $response = curl_exec($ch); 647 655 // send response as JSON 648 $response = json_decode($response, true); 656 $response = json_decode($response, true); 649 657 // get the temporary token and insert in credentials object 650 658 $credentials->token = $response['result'][0]['token']; … … 666 674 //Save data of login to show in backend.php the other fields (type of invoice and type of order) 667 675 $_SESSION['username'] = $response['result'][0]['username']; 668 676 669 677 //Choose Nif Field 670 678 $selected_dropdown = ''; 671 679 $_SESSION['fieldNif'] = ''; 672 673 680 681 674 682 $_SESSION['includeTaxonSendCost']="<option value='true'"; 675 683 if($settings['backend']['includeTaxonSendCost'] == 'true') … … 680 688 $_SESSION['includeTaxonSendCost'].=" selected "; 681 689 $_SESSION['includeTaxonSendCost'].=">No</option>"; 682 683 684 690 691 692 685 693 if($settings['backend']['fieldNif'] == "company"){ 686 694 $_SESSION['fieldNif'] .= "<option value='company' selected >Company</option><br>"; … … 702 710 $_SESSION['fieldNif'] .= "<option value='address_2'>Address 2</option><br>"; 703 711 $_SESSION['fieldNif'] .= "<option value='state' >State</option><br>"; 704 $_SESSION['fieldNif'] .= "<option value='nif' selected >Billing Nif (Plugin)</option><br>"; 712 $_SESSION['fieldNif'] .= "<option value='nif' selected >Billing Nif (Plugin)</option><br>"; 705 713 } 706 714 707 715 //Obtain gama of PHC 708 716 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 709 717 710 718 //$this->logs->writeFileLog('BackEnd response:', $response); 711 719 … … 719 727 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 720 728 } 721 729 722 730 //Obtain parameter of manage stock 723 $response = $this->utils_services->paramsGetFrontendInfo($ch, $credentials); 731 $response = $this->utils_services->paramsGetFrontendInfo($ch, $credentials); 724 732 725 733 //$this->logs->writeFileLog('FrontEnd response:', $response); … … 732 740 $this->logs->writeFileLog('setCommunicationFx2WooCommerce.1', $response['messages'][0]['messageCodeLocale']); 733 741 } else { 734 foreach ($response['result'] as $key => $value){ 742 foreach ($response['result'] as $key => $value){ 735 743 if($response['result'][$key]['descricao'] === 'AllowStocks'){ 736 744 $_SESSION['manageStockParameter'] = $response['result'][$key]['valor']; … … 740 748 741 749 //Obtain type invoices 742 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Td', 'inactivo', 0); 743 750 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Td', 'inactivo', 0); 751 744 752 //$this->logs->writeFileLog('TypeInvoice response:', $response); 745 753 … … 755 763 //Create options of dropdownlist invoices 756 764 $i = 0; 757 $typeInvoice = array(); 765 $typeInvoice = array(); 758 766 $_SESSION['typeOfInvoice'] = ''; 759 767 760 768 foreach ($response['result'] as $key => $value){ 761 769 if($value['tiposaft'] == 'FT' || $value['tiposaft'] == 'FS' || $value['tiposaft'] == 'FR'){ … … 765 773 $selected_dropdown = ''; 766 774 } 767 768 $_SESSION['typeOfInvoice'] .= "<option value=" . $value['ndoc'] . " " . $selected_dropdown . ">" . $value['nmdoc'] ."</option><br>"; 775 776 $_SESSION['typeOfInvoice'] .= "<option value=" . $value['ndoc'] . " " . $selected_dropdown . ">" . $value['nmdoc'] ."</option><br>"; 769 777 ++$i; 770 778 } 771 779 } 772 #Obtain tax free reason list 773 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Miseimp'); 774 780 #Obtain tax free reason list (for outside of PT) 781 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Miseimp'); 782 775 783 //$this->logs->writeFileLog('Miseimp response:', $response); 776 784 … … 786 794 //Create options of dropdownlist reasons list 787 795 $i = 0; 788 $typeInvoice = array(); 796 $typeInvoice = array(); 789 797 $_SESSION['typeOfReason'] = ''; 790 791 foreach ($response['result'] as $key => $value){ 798 799 foreach ($response['result'] as $key => $value){ 792 800 if($settings['backend']['typeOfReason'] == $value['codigo']){ 793 801 $selected_dropdown = 'selected'; … … 795 803 $selected_dropdown = ''; 796 804 } 797 798 $_SESSION['typeOfReason'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 805 806 $_SESSION['typeOfReason'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 799 807 ++$i; 800 808 } 801 809 } 802 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 825 $i = 0; 826 $typeInvoice = array(); 827 $_SESSION['typeOfReasonEU'] = ''; 828 829 foreach ($response['result'] as $key => $value){ 830 if($settings['backend']['typeOfReasonEU'] == $value['codigo']){ 831 $selected_dropdown = 'selected'; 832 } else { 833 $selected_dropdown = ''; 834 } 835 836 $_SESSION['typeOfReasonEU'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 837 ++$i; 838 } 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 855 $i = 0; 856 $typeInvoice = array(); 857 $_SESSION['typeOfReasonCO'] = ''; 858 859 foreach ($response['result'] as $key => $value){ 860 if($settings['backend']['typeOfReasonCO'] == $value['codigo']){ 861 $selected_dropdown = 'selected'; 862 } else { 863 $selected_dropdown = ''; 864 } 865 866 $_SESSION['typeOfReasonCO'] .= "<option value=" . $value['codigo'] . " " . $selected_dropdown . ">" . $value['descricao'] ."</option><br>"; 867 ++$i; 868 } 869 } 803 870 #Obtain services name list 804 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0', 'stns', '1'); 805 871 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0', 'stns', '1'); 872 806 873 if (curl_error($ch)) { 807 874 $this->logs->writeFileLog('setCommunication3.2', $ch); … … 816 883 $i = 0; 817 884 $_SESSION['shippingName'] = ''; 818 819 foreach ($response['result'] as $key => $value){ 885 886 foreach ($response['result'] as $key => $value){ 820 887 if($settings['backend']['shippingName'] == $value['ref']){ 821 888 $selected_dropdown = 'selected'; … … 823 890 $selected_dropdown = ''; 824 891 } 825 826 $_SESSION['shippingName'] .= "<option value=" . $value['ref'] . " " . $selected_dropdown . ">" . $value['design'] ."</option><br>"; 892 893 $_SESSION['shippingName'] .= "<option value=" . $value['ref'] . " " . $selected_dropdown . ">" . $value['design'] ."</option><br>"; 827 894 ++$i; 828 895 } … … 830 897 $i = 0; 831 898 $_SESSION['feesName'] = ''; 832 833 foreach ($response['result'] as $key => $value){ 899 900 foreach ($response['result'] as $key => $value){ 834 901 if($settings['backend']['feesName'] == $value['ref']){ 835 902 $selected_dropdown = 'selected'; … … 837 904 $selected_dropdown = ''; 838 905 } 839 840 $_SESSION['feesName'] .= "<option value=" . $value['ref'] . " " . $selected_dropdown . ">" . $value['design'] ."</option><br>"; 906 907 $_SESSION['feesName'] .= "<option value=" . $value['ref'] . " " . $selected_dropdown . ">" . $value['design'] ."</option><br>"; 841 908 ++$i; 842 909 } … … 845 912 #If gama is equal or higher of STAR 846 913 if($_SESSION['gamaDRIVEFX'] >= 9){ 847 //Obtain type orders 848 $response = $this->utils_services->doubleFilter($ch, $credentials, 'Ts', 'bdempresas', 'CL', 'trfa', '0'); 849 914 //Obtain type orders 915 $response = $this->utils_services->doubleFilter($ch, $credentials, 'Ts', 'bdempresas', 'CL', 'trfa', '0'); 916 850 917 //$this->logs->writeFileLog('OrderType response:', $response); 851 918 … … 861 928 $i = 0; 862 929 $count = count($response['result']); 863 $typeInvoice = array(); 930 $typeInvoice = array(); 864 931 $_SESSION['typeOfOrder'] = ''; 865 932 //Create options of dropdownlist internal documents … … 875 942 } else if ($key == "nmdos"){ 876 943 //Obtain type orders 877 $response2 = $this->utils_services->getInternalDoc($ch, $credentials, 'Bo', 'nmdos', $value); 944 $response2 = $this->utils_services->getInternalDoc($ch, $credentials, 'Bo', 'nmdos', $value); 878 945 879 946 // $this->logs->writeFileLog('InternalDoc response:', $response2); … … 894 961 $query = "SELECT MAX(post_id)+1 as nextPostId FROM %s"; 895 962 $docid = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 896 963 897 964 if(($response2['result'][0]['obrano'] == '' || $response2['result'][0]['obrano'] <= $docid->nextPostId) && $response['result'][$i]['bdempresas'] == 'CL'){ 898 965 $wrongTypeOrder = false; … … 903 970 904 971 if($wrongTypeOrder == false){ 905 $typeInvoice[$i]["nmdos"] = $value; 972 $typeInvoice[$i]["nmdos"] = $value; 906 973 } 907 974 } 908 975 } 909 976 910 977 if($typeInvoice[$i]["nmdos"] != ''){ 911 $_SESSION['typeOfOrder'] .= "<option id=" . $typeInvoice[$i]["nmdos"] . " value=" . $typeInvoice[$i]["ndos"] . " " . $selected_dropdown . ">" . $typeInvoice[$i]["nmdos"] ."</option><br>"; 978 $_SESSION['typeOfOrder'] .= "<option id=" . $typeInvoice[$i]["nmdos"] . " value=" . $typeInvoice[$i]["ndos"] . " " . $selected_dropdown . ">" . $typeInvoice[$i]["nmdos"] ."</option><br>"; 912 979 } 913 980 ++$i; 914 981 } 915 982 } 916 983 917 984 //Obtain warehouses 918 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Sa'); 985 $response = $this->utils_services->entityName_Query($ch, $credentials, 'Sa'); 919 986 920 987 //$this->logs->writeFileLog('Warehouses response:', $response); … … 953 1020 } 954 1021 $_SESSION['warehouse'] .= "<option id=" . $value . " value=" . $value . " " . $selected_dropdown . ">" . $value ."</option><br>"; 955 1022 956 1023 if($settings['backend']['warehouseOrder'] == $value){ 957 1024 $selected_dropdown = 'selected'; … … 962 1029 } 963 1030 } 964 } 1031 } 965 1032 966 1033 //Verify if are selected type of internal document and send invoice checkbox 967 1034 if(isset($settings['backend']['typeOfInvoice']) && $settings['backend']['createInvoice'] == 'on' && $settings['backend']['typeOfInvoice'] > 0 && isset($settings['backend']['sendInvoice'])){ 968 1035 //Obtain type invoices 969 $response = $this->utils_services->paramsGetReportForPrint($ch, $credentials); 1036 $response = $this->utils_services->paramsGetReportForPrint($ch, $credentials); 970 1037 971 1038 //$this->logs->writeFileLog('ReportPrint response:', $response); … … 996 1063 if($sendEmail == false){ 997 1064 $this->logs->writeFileLog('setCommunicationFx5', 'It is not possible to send email. Please verify your configuration reports of PHC'); 998 $this->messagesError(": It is not possible to send email. Please verify your configuration reports of PHC because does not exists any default template");999 } 1000 } 1001 } 1002 } 1003 1065 //$this->messagesError(": It is not possible to send email. Please verify your configuration reports of PHC because does not exists any default template"); 1066 } 1067 } 1068 } 1069 } 1070 1004 1071 //Obtain currency coin of company 1005 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1006 1072 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1073 1007 1074 //$this->logs->writeFileLog('E1 response:', $response); 1008 1075 … … 1022 1089 //Logout 1023 1090 $this->auth_services->PHCLogout($ch, $credentials); 1024 1091 1025 1092 } 1026 1093 1027 1094 //Update dropdownlist of type orders 1028 1095 public function updateTypeOfOrders(){ 1029 1096 1030 1097 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 1031 1098 // get Credentials 1032 $credentials = $this->syncro_services->fetchCredentials(); 1099 $credentials = $this->syncro_services->fetchCredentials(); 1033 1100 //Obtain configuration to make login 1034 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1101 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1035 1102 //initial request with login data 1036 $response = curl_exec($ch); 1103 $response = curl_exec($ch); 1037 1104 // send response as JSON 1038 $response = json_decode($response, true); 1105 $response = json_decode($response, true); 1039 1106 // get the temporary token and insert in credentials object 1040 1107 $credentials->token = $response['result'][0]['token']; 1041 1108 1042 //$this->logs->writeFileLog('completedOrder Login:', $response); 1109 //$this->logs->writeFileLog('completedOrder Login:', $response); 1043 1110 1044 1111 if (curl_error($ch)) { … … 1050 1117 } else { 1051 1118 //Obtain type orders 1052 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Ts', 'inactivo', 0); 1053 1119 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Ts', 'inactivo', 0); 1120 1054 1121 //$this->logs->writeFileLog('OrderType response:', $response); 1055 1122 1056 1123 if (curl_error($ch)) { 1057 1124 $this->logs->writeFileLog('updateTypeOfOrders2', $ch); … … 1065 1132 $i = 0; 1066 1133 $count = count($response['result']); 1067 $typeInvoice = array(); 1068 1134 $typeInvoice = array(); 1135 1069 1136 //Create options of dropdownlist internal documents 1070 1137 while ($i < $count) { … … 1079 1146 } else if ($key == "nmdos"){ 1080 1147 //Obtain type orders 1081 $response2 = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', 'nmdos', $value); 1148 $response2 = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', 'nmdos', $value); 1082 1149 1083 1150 // $this->logs->writeFileLog('Bo response:', $response2); … … 1096 1163 $query = "SELECT MAX(post_id) as nextPostId FROM %s"; 1097 1164 $docid = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 1098 1165 1099 1166 if(($response2['result'][0]['obrano'] == '' || $response2['result'][0]['obrano'] <= $docid->nextPostId) && $response['result'][$i]['bdempresas'] == 'CL'){ 1100 1167 $wrongTypeOrder = false; … … 1105 1172 1106 1173 if($wrongTypeOrder == false){ 1107 $typeInvoice[$i]["nmdos"] = $value; 1174 $typeInvoice[$i]["nmdos"] = $value; 1108 1175 } 1109 1110 } 1111 } 1112 1176 1177 } 1178 } 1179 1113 1180 if($typeInvoice[$i]["nmdos"] != ''){ 1114 echo "<option id=" . $typeInvoice[$i]["nmdos"] . " value=" . $typeInvoice[$i]["ndos"] . " " . $selected_dropdown . ">" . $typeInvoice[$i]["nmdos"] ."</option><br>"; 1181 echo "<option id=" . $typeInvoice[$i]["nmdos"] . " value=" . $typeInvoice[$i]["ndos"] . " " . $selected_dropdown . ">" . $typeInvoice[$i]["nmdos"] ."</option><br>"; 1115 1182 } 1116 1183 ++$i; … … 1119 1186 } 1120 1187 //Logout 1121 $this->auth_services->PHCLogout($ch, $credentials); 1188 $this->auth_services->PHCLogout($ch, $credentials); 1122 1189 } 1123 1190 1124 1191 //Obtain value of field to PHC 1125 1192 public function statusOfOrder($selectItems, $typeOfOrder){ 1126 1193 1127 1194 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 1128 1195 1129 1196 // get Credentials 1130 $credentials = $this->syncro_services->fetchCredentials(); 1197 $credentials = $this->syncro_services->fetchCredentials(); 1131 1198 //Obtain configuration to make login 1132 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1199 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1133 1200 //initial request with login data 1134 $response = curl_exec($ch); 1201 $response = curl_exec($ch); 1135 1202 // send response as JSON 1136 $response = json_decode($response, true); 1203 $response = json_decode($response, true); 1137 1204 // get the temporary token and insert in credentials object 1138 1205 $credentials->token = $response['result'][0]['token']; 1139 1140 //$this->logs->writeFileLog('completedOrder Login:', $response); 1206 1207 //$this->logs->writeFileLog('completedOrder Login:', $response); 1141 1208 1142 1209 if (curl_error($ch)) { … … 1148 1215 } else { 1149 1216 //Obtain type invoices 1150 $response = $this->utils_services->paramsQuery4($ch, $credentials, 'Ts', $selectItems, $typeOfOrder); 1151 1217 $response = $this->utils_services->paramsQuery4($ch, $credentials, 'Ts', $selectItems, $typeOfOrder); 1218 1152 1219 //$this->logs->writeFileLog('Type Invoices:', $response); 1153 1220 … … 1164 1231 //Logout 1165 1232 $this->auth_services->PHCLogout($ch, $credentials); 1166 1233 1167 1234 } 1168 1235 … … 1173 1240 1174 1241 session_start(); 1175 $credentials = $this->syncro_services->fetchCredentials(); 1242 $credentials = $this->syncro_services->fetchCredentials(); 1176 1243 $wooOrder = $this->syncro_services->fetchOrderData($orderid); 1177 1244 $prodPack = $this->syncro_services->processProducts($orderid); … … 1187 1254 1188 1255 } 1189 1256 1190 1257 //If status of order is cancelled or failed 1191 1258 public function cancelOrder($order_id){ … … 1194 1261 1195 1262 // get Credentials 1196 $credentials = $this->syncro_services->fetchCredentials(); 1263 $credentials = $this->syncro_services->fetchCredentials(); 1197 1264 //Obtain configuration to make login 1198 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1265 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1199 1266 //initial request with login data 1200 $response = curl_exec($ch); 1267 $response = curl_exec($ch); 1201 1268 // send response as JSON 1202 $response = json_decode($response, true); 1269 $response = json_decode($response, true); 1203 1270 // get the temporary token and insert in credentials object 1204 1271 $credentials->token = $response['result'][0]['token']; 1205 1206 //$this->logs->writeFileLog('cancelOrder Login:', $response); 1272 1273 //$this->logs->writeFileLog('cancelOrder Login:', $response); 1207 1274 1208 1275 if (curl_error($ch)) { … … 1217 1284 1218 1285 //$this->logs->writeFileLog('cancelOrder BackEnd:', $response); 1219 1286 1220 1287 if (curl_error($ch)) { 1221 1288 $this->logs->writeFileLog('setCommunicationFx2WooCommerce', $ch); … … 1227 1294 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 1228 1295 } 1229 1230 if($_SESSION['gamaDRIVEFX'] >= 9) { 1296 1297 if($_SESSION['gamaDRIVEFX'] >= 9) { 1231 1298 //Obtain currency coin of company 1232 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1233 1299 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1300 1234 1301 //$this->logs->writeFileLog('E1 response:', $response); 1235 1302 1236 1303 1237 1304 if (curl_error($ch)) { … … 1249 1316 $filterItem = "bostamp"; 1250 1317 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1]; 1251 1318 1252 1319 //Verify if exists in bd 1253 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', $filterItem, $valueItem); 1254 1255 //$this->logs->writeFileLog('Bo response:', $response); 1320 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', $filterItem, $valueItem); 1321 1322 //$this->logs->writeFileLog('Bo response:', $response); 1256 1323 1257 1324 if (curl_error($ch)) { … … 1264 1331 1265 1332 //If is not a SAFT document we update the document 1266 if(!empty($response) && $response['result'][0]['isconfiguredtosign'] == false || ($response['result'][0]['isconfiguredtosign'] == true && 1333 if(!empty($response) && $response['result'][0]['isconfiguredtosign'] == false || ($response['result'][0]['isconfiguredtosign'] == true && 1267 1334 $response['result'][0]['draftRecord'] == 1)){ 1268 1335 … … 1276 1343 $response['result'][0]['Operation'] = 2; 1277 1344 1278 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 1279 1280 //$this->logs->writeFileLog('BoWs Save:', $response); 1345 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 1346 1347 //$this->logs->writeFileLog('BoWs Save:', $response); 1281 1348 1282 1349 if (curl_error($ch)) { … … 1291 1358 } 1292 1359 } 1293 1360 1294 1361 } 1295 1362 //Logout … … 1306 1373 1307 1374 // get Credentials 1308 $credentials = $this->syncro_services->fetchCredentials(); 1375 $credentials = $this->syncro_services->fetchCredentials(); 1309 1376 //Obtain configuration to make login 1310 1377 $ch = $this->auth_services->PHCLogin($ch, $credentials); … … 1312 1379 $response = curl_exec($ch); 1313 1380 // send response as JSON 1314 $response = json_decode($response, true); 1381 $response = json_decode($response, true); 1315 1382 // get the temporary token and insert in credentials object 1316 $credentials->token = $response['result'][0]['token']; 1383 $credentials->token = $response['result'][0]['token']; 1317 1384 1318 1385 if (curl_error($ch)) { 1319 1386 $this->logs->writeFileLog('completedOrder', $ch); 1320 1387 } else if(empty($response)){ 1321 $this->logs->writeFileLog('completedOrder', 'EMPTY RESPONSE'); 1388 $this->logs->writeFileLog('completedOrder', 'EMPTY RESPONSE'); 1322 1389 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1323 $this->logs->writeFileLog('completedOrder', $response['messages'][0]['messageCodeLocale']); 1390 $this->logs->writeFileLog('completedOrder', $response['messages'][0]['messageCodeLocale']); 1324 1391 } else { 1325 1392 //Obtain information from company 1326 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1327 1393 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'E1', 'estab', 0); 1394 1328 1395 if (curl_error($ch)) { 1329 1396 $this->logs->writeFileLog('completedOrder2', $ch); … … 1335 1402 //Verify if currency of shop corresponds to PHC 1336 1403 if($response['result'][0]['moeda'] == get_option('woocommerce_currency')){ 1337 1404 1338 1405 //If in settings of backoffice is checked option "create invoice" 1339 1406 if($settings['backend']['createInvoice'] == 'on'){ 1340 1407 //Obtain stamp of internal document based in order 1341 1408 $docid = get_post_meta($order_id); 1342 1409 1343 1410 $filterItem = "bostamp"; 1344 1411 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1]; … … 1354 1421 } 1355 1422 if(empty($valueItem)){ 1356 $order_received = sanitize_text_field($order_id ); 1423 $order_received = sanitize_text_field($order_id ); 1357 1424 $docid = get_post_meta($order_received); 1358 1425 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1]; 1359 1426 } 1360 1427 1361 1428 //Obtain gama of PHC 1362 1429 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); … … 1371 1438 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 1372 1439 } 1373 1374 if($_SESSION['gamaDRIVEFX'] >= 9) { 1440 1441 if($_SESSION['gamaDRIVEFX'] >= 9) { 1375 1442 //Verify if exists in bd 1376 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', $filterItem, $valueItem); 1377 1443 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Bo', $filterItem, $valueItem); 1444 1378 1445 if (curl_error($ch)) { 1379 1446 $this->logs->writeFileLog('completedOrder3', $ch); 1380 1447 } else if(empty($response)){ 1381 $this->logs->writeFileLog('completedOrder3', 'EMPTY RESPONSE'); 1448 $this->logs->writeFileLog('completedOrder3', 'EMPTY RESPONSE'); 1382 1449 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1383 $this->logs->writeFileLog('completedOrder3', $response['messages'][0]['messageCodeLocale']); 1384 } else { 1450 $this->logs->writeFileLog('completedOrder3', $response['messages'][0]['messageCodeLocale']); 1451 } else { 1385 1452 1386 1453 … … 1388 1455 $response['result'][0]['draftRecord'] == 1)){ 1389 1456 1390 if(!empty($response['result'][0])){ 1457 if(!empty($response['result'][0])){ 1391 1458 //Obtain status 1392 1459 $statusOrderShop = $this->utils_services->genericFieldsList($settings['backend']['statusOfOrder']); … … 1399 1466 1400 1467 //Save internal document 1401 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 1402 1468 $response = $this->utils_services->paramsSave($ch, $credentials, 'BoWS', $response); 1469 1403 1470 if (curl_error($ch)) { 1404 1471 $this->logs->writeFileLog('completedOrder4', $ch); … … 1410 1477 } 1411 1478 } 1412 1479 1413 1480 $response = $response['result'][0]; 1414 1481 1415 1482 if(!empty($response['bostamp'])){ 1416 1483 //Create Invoice only if is configurated type of invoices … … 1425 1492 } 1426 1493 } else { 1427 //Add Ft 1494 //Add Ft 1428 1495 $this->addSimpleFT($ch,$order_id, $credentials); 1429 1496 } … … 1437 1504 $this->logs->writeFileLog('completedOrder', "Sair" . $order_id); 1438 1505 $this->lockEnd(); 1439 } 1506 } 1440 1507 1441 1508 //Convert internal document to invoice … … 1443 1510 1444 1511 $this->logs->writeFileLog('addInternalDocumentInvoice', "Entrei addInternalDocumentInvoice ft:" . $order_id); 1445 1512 1446 1513 $wooOrder = $this->syncro_services->fetchOrderData($orderid); 1447 1514 $ftprodPack = $this->syncro_services->processFtProducts($orderid); … … 1452 1519 $this->manageStock($ch, $credentials, $response); 1453 1520 $this->sendEmail($ch, $credentials, $response); 1454 1521 1455 1522 $this->logs->writeFileLog('addInternalDocumentInvoice', "sai addInternalDocumentInvoice ft:" . $order_id); 1456 1523 } … … 1460 1527 1461 1528 $this->logs->writeFileLog('addSimpleft', "Entrei simple ft:" . $orderid); 1462 1529 1463 1530 $wooOrder = $this->syncro_services->fetchOrderData($orderid); 1464 1531 $ftprodPack = $this->syncro_services->processFtProducts($orderid); … … 1469 1536 $this->manageStock($ch, $credentials, $response); 1470 1537 $this->sendEmail($ch, $credentials, $response); 1471 1538 1472 1539 $this->logs->writeFileLog('addSimpleft', "Sai simple ft:" . $orderid); 1473 1540 } … … 1475 1542 //Manage stock 1476 1543 public function manageStock($ch, $credentials, $response){ 1477 1544 1478 1545 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 1479 1546 1480 1547 # Manage stock 1481 1548 if($_SESSION['gamaDRIVEFX'] >= 9) { 1482 1549 if($settings['backend']['manageStock'] == 'on'){ 1483 1550 1484 1551 $post_ID = sanitize_text_field( $_REQUEST['post_ID'] ); 1485 1552 $order_received = get_option('woocommerce_checkout_order_received_endpoint'); … … 1490 1557 $order = new WC_Order( $order_received ); 1491 1558 } 1492 1559 1493 1560 $i = 0; 1494 1561 foreach($order->get_items() as $key => $value){ … … 1502 1569 $fisProducts = $_SESSION['voProducts']['fis']; 1503 1570 1504 1571 1505 1572 $i = 0; 1506 1573 $count = count($fisProducts); 1507 //$this->logs->writeFileLog('response:', $count); 1574 //$this->logs->writeFileLog('response:', $count); 1508 1575 while ($i < $count) { 1509 1576 foreach ($fisProducts[$i] as $key => $value){ … … 1516 1583 $this->logs->writeFileLog('addSimpleFT16', $ch); 1517 1584 } else if(empty($response)){ 1518 $this->logs->writeFileLog('addSimpleFT16', 'EMPTY RESPONSE'); 1585 $this->logs->writeFileLog('addSimpleFT16', 'EMPTY RESPONSE'); 1519 1586 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1520 $this->logs->writeFileLog('addSimpleFT16', $response['messages'][0]['messageCodeLocale']); 1587 $this->logs->writeFileLog('addSimpleFT16', $response['messages'][0]['messageCodeLocale']); 1521 1588 } else { 1522 1589 #If find ref, update stock … … 1528 1595 } 1529 1596 } 1530 } 1597 } 1531 1598 } 1532 1599 ++$i; … … 1558 1625 $this->logs->writeFileLog('addSimpleFT17', $ch); 1559 1626 } else if(empty($response)){ 1560 $this->logs->writeFileLog('addSimpleFT17', 'EMPTY RESPONSE'); 1627 $this->logs->writeFileLog('addSimpleFT17', 'EMPTY RESPONSE'); 1561 1628 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1562 $this->logs->writeFileLog('addSimpleFT17', $response['messages'][0]['messageCodeLocale']); 1629 $this->logs->writeFileLog('addSimpleFT17', $response['messages'][0]['messageCodeLocale']); 1563 1630 } else { 1564 1631 //Verify if exists template as default … … 1575 1642 } 1576 1643 ++$i; 1577 } 1644 } 1578 1645 #If exists template as default 1579 if($sendEmail == true){ 1646 if($sendEmail == true){ 1580 1647 //Obtain client 1581 1648 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Cl', 'no', $_SESSION['numberClient']); 1582 1649 1583 1650 //$this->logs->writeFileLog('custom_by_no:', $response); 1584 1651 1585 1652 if (curl_error($ch)) { 1586 1653 $this->logs->writeFileLog('addSimpleFT18', $ch); 1587 1654 } else if(empty($response)){ 1588 $this->logs->writeFileLog('addSimpleFT18', 'EMPTY RESPONSE'); 1655 $this->logs->writeFileLog('addSimpleFT18', 'EMPTY RESPONSE'); 1589 1656 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1590 1657 $this->logs->writeFileLog('addSimpleFT18', $response['messages'][0]['messageCodeLocale']); … … 1595 1662 //Email From 1596 1663 $infoAdmin = $this->get_settingsAdmin(); 1597 $emailAdmin = $infoAdmin[3]['default']; 1664 $emailAdmin = $infoAdmin[3]['default']; 1598 1665 ### 1599 1666 $body = $settings['backend']['emailBody']; … … 1604 1671 $_SESSION['ftstamp'], $_SESSION['emailClient'], 1605 1672 $emailAdmin, $settings['backend']['typeOfInvoice'], '', $body); 1606 1673 1607 1674 //$this->logs->writeFileLog('paramsSendReportEmail:', $response); 1608 1675 1609 1676 if (curl_error($ch)) { 1610 1677 $this->logs->writeFileLog('addSimpleFT19', $ch); 1611 1678 } else if(empty($response)){ 1612 $this->logs->writeFileLog('addSimpleFT19', 'EMPTY RESPONSE'); 1679 $this->logs->writeFileLog('addSimpleFT19', 'EMPTY RESPONSE'); 1613 1680 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1614 $this->logs->writeFileLog('addSimpleFT19', $response['messages'][0]['messageCodeLocale']); 1681 $this->logs->writeFileLog('addSimpleFT19', $response['messages'][0]['messageCodeLocale']); 1615 1682 } else { 1616 1683 $this->logs->writeFileLog('Info:', 'Email sended'); … … 1621 1688 } 1622 1689 } 1623 return $sendedEmail; 1690 return $sendedEmail; 1624 1691 } 1625 1692 … … 1630 1697 $post = array( 1631 1698 'post_title' => $nomeProduct, 1632 'post_status' => "publish", 1699 'post_status' => "publish", 1633 1700 'post_name' => $slugNameProduct, 1634 1701 'post_type' => "product" 1635 1702 ); 1636 1703 1637 1704 //Create product/post: 1638 1705 $new_post_id = wp_insert_post($post, $wp_error); … … 1649 1716 1650 1717 update_post_meta( $new_post_id, '_sku', $sku); 1651 update_post_meta( $new_post_id, '_visibility', $visible); 1718 update_post_meta( $new_post_id, '_visibility', $visible); 1652 1719 update_post_meta( $new_post_id, '_price', $price ); 1653 1720 update_post_meta( $new_post_id, '_regular_price', $price ); … … 1656 1723 update_post_meta( $new_post_id, '_manage_stock', $manageStock); 1657 1724 update_post_meta( $new_post_id, '_stock', $stockUnitsProduct); 1658 } 1725 } 1659 1726 1660 1727 //To return product that can't be inserted … … 1670 1737 1671 1738 // get Credentials 1672 $credentials = $this->syncro_services->fetchCredentials(); 1739 $credentials = $this->syncro_services->fetchCredentials(); 1673 1740 //Obtain configuration to make login 1674 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1741 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1675 1742 //initial request with login data 1676 $response = curl_exec($ch); 1743 $response = curl_exec($ch); 1677 1744 // send response as JSON 1678 $response = json_decode($response, true); 1745 $response = json_decode($response, true); 1679 1746 // get the temporary token and insert in credentials object 1680 1747 $credentials->token = $response['result'][0]['token']; … … 1689 1756 $this->logs->writeFileLog('listProducts', $response['messages'][0]['messageCodeLocale']); 1690 1757 unset($_SESSION['username']); 1691 } else { 1692 1758 } else { 1759 1693 1760 // Get condition of Tax Tab from Woocommerce -> Configuration -> Tax 1694 1761 $woocommerce_calc_taxes = get_option('woocommerce_calc_taxes'); … … 1710 1777 break; 1711 1778 } 1712 1779 1713 1780 //Obtain gama of PHC 1714 1781 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); … … 1725 1792 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 1726 1793 } 1727 1794 1728 1795 //Obtain parameter of manage stock 1729 1796 $response = $this->utils_services->paramsGetFrontendInfo($ch, $credentials); 1730 1797 1731 1798 //$this->logs->writeFileLog('ListProducts FrontEnd:', $response); 1732 1799 1733 1800 if (curl_error($ch)) { 1734 1801 $this->logs->writeFileLog('setCommunicationFx2WooCommerce.1', $ch); … … 1738 1805 $this->logs->writeFileLog('setCommunicationFx2WooCommerce.1', $response['messages'][0]['messageCodeLocale']); 1739 1806 } else { 1740 foreach ($response['result'] as $key => $value){ 1807 foreach ($response['result'] as $key => $value){ 1741 1808 if($response['result'][$key]['descricao'] === 'AllowStocks'){ 1742 1809 $_SESSION['manageStockParameter'] = $response['result'][$key]['valor']; … … 1744 1811 } 1745 1812 } 1746 1813 1747 1814 if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){ 1748 1815 1749 1816 // Products with VAT included in price 1750 if(($woocommerce_calc_taxes == "no") || ($woocommerce_calc_taxes == "yes" && $woocommerce_prices_include_tax == "yes")) { 1817 if(($woocommerce_calc_taxes == "no") || ($woocommerce_calc_taxes == "yes" && $woocommerce_prices_include_tax == "yes")) { 1751 1818 1752 1819 if ($settings['backend']['positiveStock'] == 'on'){ 1753 1820 $response = $this->utils_services->paramsQuery5($ch, $credentials, 'St', '2', 'stock', '0', '0', $columnIva, '1'); 1754 1821 } else { 1755 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0' , $columnIva, '1'); 1756 } 1757 1822 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0' , $columnIva, '1'); 1823 } 1824 1758 1825 //$this->logs->writeFileLog('StList response1:', $response); 1759 1826 … … 1765 1832 $response = $this->utils_services->paramsQuery5($ch, $credentials, 'St', '2', 'stock', '0', '0', $columnIva, '0'); 1766 1833 } else { 1767 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0' , $columnIva, '0'); 1768 } 1769 1770 //$this->logs->writeFileLog('StList response2:', $response); 1771 1834 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '0' , $columnIva, '0'); 1835 } 1836 1837 //$this->logs->writeFileLog('StList response2:', $response); 1838 1772 1839 } 1773 1840 } else { 1774 1841 $response = $this->utils_services->entityName_Query($ch, $credentials, 'St'); 1775 } 1776 1842 } 1843 1777 1844 1778 1845 if (curl_error($ch)) { 1779 1846 $this->logs->writeFileLog('listProducts2', $ch); 1780 1847 } else if(empty($response)){ 1781 $this->logs->writeFileLog('listProducts2', 'EMPTY RESPONSE'); 1848 $this->logs->writeFileLog('listProducts2', 'EMPTY RESPONSE'); 1782 1849 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1783 $this->logs->writeFileLog('listProducts2', $response['messages'][0]['messageCodeLocale']); 1784 } else { 1850 $this->logs->writeFileLog('listProducts2', $response['messages'][0]['messageCodeLocale']); 1851 } else { 1785 1852 1786 1853 foreach ($response['result'] as $key => $value){ … … 1791 1858 if ($settings['backend']['filterStock'] == 'on'){ 1792 1859 // Get all the stock (entries) 1793 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $value['ref'], 'entrada', '1'); 1794 1860 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $value['ref'], 'entrada', '1'); 1861 1795 1862 $totalStock = array_reduce( 1796 1863 $responseFilter['result'], … … 1799 1866 }, 1800 1867 0 1801 ); 1802 1868 ); 1869 1803 1870 if ($settings['backend']['positiveStock'] == 'on'){ 1804 //Extract the customer ordrers from total stock 1871 //Extract the customer ordrers from total stock 1805 1872 if ($totalStock - $value['qttcli'] > 0){ 1806 $arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 1807 } 1873 $arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 1874 } 1808 1875 } else { 1809 $arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 1810 } 1876 $arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 1877 } 1811 1878 } else{ 1812 1879 $arrayRef[$value['ref']] = $value['stock']; 1813 } 1880 } 1814 1881 $refArray .= '{ 1815 1882 "comparison":0, … … 1820 1887 "skipCheckType":false, 1821 1888 "type":"Number" 1822 }'; 1823 } 1824 1825 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 1826 1889 }'; 1890 } 1891 1892 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 1893 1827 1894 //$this->logs->writeFileLog('StList response:', $response); 1828 1895 … … 1830 1897 $this->logs->writeFileLog('listProducts3', $ch); 1831 1898 } else if(empty($response)){ 1832 $this->logs->writeFileLog('listProducts3', 'EMPTY RESPONSE'); 1899 $this->logs->writeFileLog('listProducts3', 'EMPTY RESPONSE'); 1833 1900 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1834 $this->logs->writeFileLog('listProducts3', $response['messages'][0]['messageCodeLocale']); 1901 $this->logs->writeFileLog('listProducts3', $response['messages'][0]['messageCodeLocale']); 1835 1902 } else { 1836 1903 1837 1904 //Create rows with information of products 1838 1905 $tableProducts = ''; 1839 $tableProducts .= "<thead><tr><th style='text-align: left;'><input type='checkbox' onClick='toggle(this)'/> Select all</th><th style='text-align: left;'>Ref</th><th style='text-align: left;'>Product Name</th><th style='text-align: left;'>Family</th>"; 1906 $tableProducts .= "<thead><tr><th style='text-align: left;'><input type='checkbox' onClick='toggle(this)'/> Select all</th><th style='text-align: left;'>Ref</th><th style='text-align: left;'>Product Name</th><th style='text-align: left;'>Family</th>"; 1840 1907 1841 1908 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ … … 1844 1911 $tableProducts .= "</tr></thead>"; 1845 1912 } 1846 1913 1847 1914 if(is_array($response['result'])){ 1848 1915 if(!empty($settings['backend']['productPriceColumn']) && $settings['backend']['productPriceColumn'] != 'epv0'){ 1849 1916 foreach ($response['result'] as $key => $value) { 1850 1917 1851 //Create Table 1918 //Create Table 1852 1919 $tableProducts .= "<tr>"; 1853 1920 if(wc_get_product_id_by_sku( $response['result'][$key]['ref'] )== ""){ … … 1861 1928 } 1862 1929 1863 $tableProducts .= "<td style='text-align: left;'>". $response['result'][$key]['ref']. 1930 $tableProducts .= "<td style='text-align: left;'>". $response['result'][$key]['ref']. 1864 1931 "</td><td style='text-align: left;'>". $response['result'][$key]['design']. 1865 1932 "</td><td style='text-align: left;'>". $response['result'][$key]['familia']."</td>"; 1866 1933 1867 1934 //Only exists stocks after Star GAMA 1868 1935 if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ … … 1872 1939 $tableProducts .= "<td style='text-align: right;'>".$arrayRef[$response['result'][$key]['ref']]."</td></tr>"; 1873 1940 } 1874 } 1941 } 1875 1942 } 1876 1943 echo $tableProducts; 1877 1944 } else { 1878 1945 $this->logs->writeFileLog('listProducts4', 'Products: Empty productPriceColumn'); 1879 } 1880 } 1881 } 1882 } 1883 } 1946 } 1947 } 1948 } 1949 } 1950 } 1884 1951 //Logout 1885 1952 $this->auth_services->PHCLogout($ch, $credentials); … … 1893 1960 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 1894 1961 // get Credentials 1895 $credentials = $this->syncro_services->fetchCredentials(); 1962 $credentials = $this->syncro_services->fetchCredentials(); 1896 1963 // Obtain configuration to make login 1897 1964 $ch = $this->auth_services->PHCLogin($ch, $credentials); 1898 1965 //initial request with login data 1899 $response = curl_exec($ch); 1966 $response = curl_exec($ch); 1900 1967 // send response as JSON 1901 $response = json_decode($response, true); 1968 $response = json_decode($response, true); 1902 1969 // get the temporary token and insert in credentials object 1903 1970 $credentials->token = $response['result'][0]['token']; 1904 1905 //$this->logs->writeFileLog('SaveProducts Login:', $response); 1971 1972 //$this->logs->writeFileLog('SaveProducts Login:', $response); 1906 1973 1907 1974 if (curl_error($ch)) { … … 1914 1981 $this->logs->writeFileLog('saveProducts', $response['messages'][0]['messageCodeLocale']); 1915 1982 unset($_SESSION['username']); 1916 } else { 1917 1983 } else { 1984 1918 1985 //Obtain gama of PHC 1919 1986 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); … … 1930 1997 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 1931 1998 } 1932 1999 1933 2000 //Verify GAMA or value choose in warehouse dropdown 1934 2001 if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){ … … 1936 2003 $response = $this->utils_services->filterItem_compare($ch, $credentials, 'St', '2', 'stock', '0'); 1937 2004 } else { 1938 $response = $this->utils_services->entityName_Query($ch, $credentials, 'St'); 2005 $response = $this->utils_services->entityName_Query($ch, $credentials, 'St'); 1939 2006 } 1940 2007 } else { 1941 2008 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Sa', 'armazem', $settings['backend']['warehouse']); 1942 2009 } 1943 2010 1944 2011 //$this->logs->writeFileLog('SaveProducts St ou Sa:', $response); 1945 2012 … … 1947 2014 $this->logs->writeFileLog('saveProducts2', $ch); 1948 2015 } else if(empty($response)){ 1949 $this->logs->writeFileLog('saveProducts2', 'EMPTY RESPONSE'); 2016 $this->logs->writeFileLog('saveProducts2', 'EMPTY RESPONSE'); 1950 2017 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1951 $this->logs->writeFileLog('saveProducts2', $response['messages'][0]['messageCodeLocale']); 2018 $this->logs->writeFileLog('saveProducts2', $response['messages'][0]['messageCodeLocale']); 1952 2019 } else { 1953 2020 $i = 0; … … 1964 2031 } 1965 2032 $arrayRef[$value] = $response['result'][$i]['stock']; 1966 2033 1967 2034 $refArray .= '{ 1968 2035 "comparison":0, … … 1973 2040 "skipCheckType":false, 1974 2041 "type":"Number" 1975 }'; 1976 } 2042 }'; 2043 } 1977 2044 } 1978 2045 } … … 1982 2049 1983 2050 //Obtain products from st 1984 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 1985 1986 //$this->logs->writeFileLog('SaveList St:', $response); 2051 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2052 2053 //$this->logs->writeFileLog('SaveList St:', $response); 1987 2054 1988 2055 if (curl_error($ch)) { 1989 2056 $this->logs->writeFileLog('saveProducts3', $ch); 1990 2057 } else if(empty($response)){ 1991 $this->logs->writeFileLog('saveProducts3', 'EMPTY RESPONSE'); 2058 $this->logs->writeFileLog('saveProducts3', 'EMPTY RESPONSE'); 1992 2059 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1993 $this->logs->writeFileLog('saveProducts3', $response['messages'][0]['messageCodeLocale']); 2060 $this->logs->writeFileLog('saveProducts3', $response['messages'][0]['messageCodeLocale']); 1994 2061 } else { 1995 //If exists selected products 2062 //If exists selected products 1996 2063 if(is_array($refs)){ 1997 2064 $i = 0; 1998 2065 $count = count($response['result']); 1999 2066 2000 2067 while ($i < $count) { 2001 2068 foreach ($refs as $key => $value) { … … 2003 2070 //Obtain url of image to save in shop 2004 2071 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 2005 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 2072 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 2006 2073 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 2007 2074 2008 2075 $thumb_url = ''; 2009 2010 2076 2077 2011 2078 //Add Product 2012 $this->addProduct($response['result'][$i]['design'], 2013 $response['result'][$i]['design'], 2014 $response['result'][$i]['desctec'], 2015 $response['result'][$i]['design'], 2016 $arrayRef[$response['result'][$i]['ref']], 2079 $this->addProduct($response['result'][$i]['design'], 2080 $response['result'][$i]['design'], 2081 $response['result'][$i]['desctec'], 2082 $response['result'][$i]['design'], 2083 $arrayRef[$response['result'][$i]['ref']], 2017 2084 $response['result'][$i][$settings['backend']['productPriceColumn']], 2018 $response['result'][$i]['ref'], 2085 $response['result'][$i]['ref'], 2019 2086 'yes', 2020 'visible', 2087 'visible', 2021 2088 $thumb_url); 2022 2089 } 2023 2090 } 2024 2091 ++$i; 2025 } 2026 } 2027 } 2092 } 2093 } 2094 } 2028 2095 } 2029 2096 } … … 2033 2100 } else { 2034 2101 echo "empty_refs"; 2035 } 2102 } 2036 2103 } 2037 2104 … … 2041 2108 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 2042 2109 // get Credentials 2043 $credentials = $this->syncro_services->fetchCredentials(); 2110 $credentials = $this->syncro_services->fetchCredentials(); 2044 2111 // Obtain configuration to make login 2045 $ch = $this->auth_services->PHCLogin($ch, $credentials); 2112 $ch = $this->auth_services->PHCLogin($ch, $credentials); 2046 2113 //initial request with login data 2047 $response = curl_exec($ch); 2114 $response = curl_exec($ch); 2048 2115 // send response as JSON 2049 $response = json_decode($response, true); 2116 $response = json_decode($response, true); 2050 2117 // get the temporary token and insert in credentials object 2051 2118 $credentials->token = $response['result'][0]['token']; … … 2062 2129 $this->logs->writeFileLog('updateStocksProducts', $response['messages'][0]['messageCodeLocale']); 2063 2130 unset($_SESSION['username']); 2064 } else { 2065 2131 } else { 2132 2066 2133 //Obtain gama of PHC 2067 2134 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); … … 2078 2145 $_SESSION['gamaDRIVEFX'] = $response['result'][0]["gama"]; 2079 2146 } 2080 2147 2081 2148 //Verify GAMA or value choose in warehouse dropdown 2082 2149 if($_SESSION['gamaDRIVEFX'] < 9 || $settings['backend']['warehouse'] == -1 || $settings['backend']['warehouse'] == ''){ … … 2087 2154 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Sa', 'armazem', $settings['backend']['warehouse']); 2088 2155 } 2089 2156 2090 2157 if (curl_error($ch)) { 2091 2158 $this->logs->writeFileLog('updateStocksProducts2', $ch); 2092 2159 } else if(empty($response)){ 2093 $this->logs->writeFileLog('updateStocksProducts2', 'EMPTY RESPONSE'); 2160 $this->logs->writeFileLog('updateStocksProducts2', 'EMPTY RESPONSE'); 2094 2161 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2095 $this->logs->writeFileLog('updateStocksProducts2', $response['messages'][0]['messageCodeLocale']); 2162 $this->logs->writeFileLog('updateStocksProducts2', $response['messages'][0]['messageCodeLocale']); 2096 2163 } else { 2097 2098 $count = count($response['result']); 2164 2165 $count = count($response['result']); 2099 2166 $refArray = array(); 2100 2167 $i=0; 2101 2168 while ($i < $count) { 2102 foreach ($response['result'][$i] as $key => $value){ 2169 foreach ($response['result'][$i] as $key => $value){ 2103 2170 $refArray[$i]=array(); 2104 2171 // filter stock - uninvoiced order 2105 2172 if ($settings['backend']['filterStock'] == 'on'){ 2106 2173 // Get all the stock (entries) 2107 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $response['result'][$i]['ref'], 'entrada', '1'); 2108 2174 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $response['result'][$i]['ref'], 'entrada', '1'); 2175 2109 2176 $totalStock = array_reduce( 2110 2177 $responseFilter['result'], … … 2113 2180 }, 2114 2181 0 2115 ); 2116 //Extract the customer ordrers from total stock 2182 ); 2183 //Extract the customer ordrers from total stock 2117 2184 $arrayRef[$value] = $totalStock - $response['result'][$i]['qttcli']; 2118 2185 2119 2186 } else { 2120 2187 $refArray[$i]['stock'] = $response['result'][$i]['stock']; 2121 } 2122 $refArray[$i]['sku'] = $response['result'][$i]['ref']; 2188 } 2189 $refArray[$i]['sku'] = $response['result'][$i]['ref']; 2123 2190 } 2124 2191 ++$i; 2125 } 2126 //If exists selected products2127 foreach ($refArray as $prod) { 2192 } 2193 //If exists selected products 2194 foreach ($refArray as $prod) { 2128 2195 //Obtain post_id of postmeta table 2129 2196 $productID = wc_get_product_id_by_sku($prod['sku']); 2130 2197 2131 2198 //Obtain products 2132 2199 if(!empty($productID)){ 2133 if($settings['backend']['manageStock'] == 'on'){ 2134 update_post_meta($productID,'_stock',$prod['stock']); 2135 2200 if($settings['backend']['manageStock'] == 'on'){ 2201 update_post_meta($productID,'_stock',$prod['stock']); 2202 2136 2203 if($prod['stock'] > 0){ 2137 2204 update_post_meta( $productID, '_stock_status', 'instock'); 2138 2205 2139 2206 } else { 2140 2207 //update_post_meta( $productID, '_stock_status', 'outofstock'); 2141 2208 } 2142 } 2209 } 2143 2210 } 2144 2145 2146 } 2147 2148 2211 2212 2213 } 2214 2215 2149 2216 } 2150 2217 } … … 2154 2221 } else { 2155 2222 echo "empty_refs"; 2156 } 2157 } 2158 2159 //Update all fieldof products2160 public function update AllFieldsProducts($refs){2161 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 2162 //If exists selected products 2163 if(is_array($refs)){ 2223 } 2224 } 2225 2226 //Update only prices of products 2227 public function updatePricesProducts($refs){ 2228 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 2229 //If exists selected products 2230 if(is_array($refs)){ 2164 2231 // get Credentials 2165 $credentials = $this->syncro_services->fetchCredentials(); 2232 $credentials = $this->syncro_services->fetchCredentials(); 2166 2233 // Obtain configuration to make login 2167 2234 $ch = $this->auth_services->PHCLogin($ch, $credentials); 2168 2235 //initial request with login data 2169 $response = curl_exec($ch); 2236 $response = curl_exec($ch); 2170 2237 // send response as JSON 2171 $response = json_decode($response, true); 2238 $response = json_decode($response, true); 2172 2239 // get the temporary token and insert in credentials object 2173 2240 $credentials->token = $response['result'][0]['token']; 2174 2241 2175 2242 //$this->logs->writeFileLog('Login response:', $response); 2176 2243 2244 if (curl_error($ch)) { 2245 $this->logs->writeFileLog('updatePricesProducts', $ch); 2246 unset($_SESSION['username']); 2247 } else if(empty($response)){ 2248 $this->logs->writeFileLog('updatePricesProducts', 'EMPTY RESPONSE'); 2249 unset($_SESSION['username']); 2250 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2251 $this->logs->writeFileLog('updatePricesProducts', $response['messages'][0]['messageCodeLocale']); 2252 unset($_SESSION['username']); 2253 } else { 2254 $values_touse = array(); 2255 $i=0; 2256 2257 foreach ($refs as $key => $value) { 2258 if($i > 0){ 2259 $refArray .= ","; 2260 } 2261 $refArray .= '{ 2262 "comparison":0, 2263 "filterItem":"ref", 2264 "valueItem":"'.$value.'", 2265 "groupItem":9, 2266 "checkNull":false, 2267 "skipCheckType":false, 2268 "type":"Number" 2269 }'; 2270 $i++; 2271 } 2272 2273 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2274 2275 //$this->logs->writeFileLog('StList response:', $response); 2276 2277 if (curl_error($ch)) { 2278 $this->logs->writeFileLog('updatePricesProducts2', $ch); 2279 } else if(empty($response)){ 2280 $this->logs->writeFileLog('updatePricesProducts2', 'EMPTY RESPONSE'); 2281 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2282 $this->logs->writeFileLog('updatePricesProducts2', $response['messages'][0]['messageCodeLocale']); 2283 } else { 2284 2285 for($i=0;$i<sizeof($response['result']);$i++){ 2286 $values_touse[$response['result'][$i]['ref']]=array(); 2287 $values_touse[$response['result'][$i]['ref']][$settings['backend']['productPriceColumn']]=$response['result'][$i][$settings['backend']['productPriceColumn']]; 2288 } 2289 2290 //Update all prices in Woocommerce 2291 foreach($values_touse as $key => $values){ 2292 $productID = wc_get_product_id_by_sku($key); 2293 update_post_meta( $productID, '_price', $values[$settings['backend']['productPriceColumn']] ); 2294 update_post_meta( $productID, '_regular_price', $values[$settings['backend']['productPriceColumn']]); 2295 } 2296 } 2297 } 2298 //Logout 2299 $this->auth_services->PHCLogout($ch, $credentials); 2300 } else { 2301 echo "empty_refs"; 2302 } 2303 } 2304 2305 //Update all field of products 2306 public function updateAllFieldsProducts($refs){ 2307 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 2308 //If exists selected products 2309 if(is_array($refs)){ 2310 // get Credentials 2311 $credentials = $this->syncro_services->fetchCredentials(); 2312 // Obtain configuration to make login 2313 $ch = $this->auth_services->PHCLogin($ch, $credentials); 2314 //initial request with login data 2315 $response = curl_exec($ch); 2316 // send response as JSON 2317 $response = json_decode($response, true); 2318 // get the temporary token and insert in credentials object 2319 $credentials->token = $response['result'][0]['token']; 2320 2321 //$this->logs->writeFileLog('Login response:', $response); 2322 2177 2323 if (curl_error($ch)) { 2178 2324 $this->logs->writeFileLog('updateAllFieldsProducts', $ch); … … 2184 2330 $this->logs->writeFileLog('updateAllFieldsProducts', $response['messages'][0]['messageCodeLocale']); 2185 2331 unset($_SESSION['username']); 2186 } else { 2187 2332 } else { 2333 2188 2334 //Obtain gama of PHC 2189 2335 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); … … 2191 2337 //$this->logs->writeFileLog('Get Gama:', $response); 2192 2338 2193 if (curl_error($ch)) { 2339 if (curl_error($ch)) { 2194 2340 $this->logs->writeFileLog('setCommunicationFx2WooCommerce', $ch); 2195 2341 } else if(empty($response)){ … … 2201 2347 $values_touse = array(); 2202 2348 $i=0; 2203 2204 2205 foreach ($refs as $key => $value) { 2349 2350 2351 foreach ($refs as $key => $value) { 2206 2352 if($i > 0){ 2207 2353 $refArray .= ","; … … 2215 2361 "skipCheckType":false, 2216 2362 "type":"Number" 2217 }'; 2363 }'; 2218 2364 $i++; 2219 } 2220 2221 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2222 2365 } 2366 2367 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2368 2223 2369 //$this->logs->writeFileLog('StList response:', $response); 2224 2370 2225 2371 if (curl_error($ch)) { 2226 2372 $this->logs->writeFileLog('updateAllFieldsProducts2', $ch); 2227 2373 } else if(empty($response)){ 2228 $this->logs->writeFileLog('updateAllFieldsProducts2', 'EMPTY RESPONSE'); 2374 $this->logs->writeFileLog('updateAllFieldsProducts2', 'EMPTY RESPONSE'); 2229 2375 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2230 $this->logs->writeFileLog('updateAllFieldsProducts2', $response['messages'][0]['messageCodeLocale']); 2376 $this->logs->writeFileLog('updateAllFieldsProducts2', $response['messages'][0]['messageCodeLocale']); 2231 2377 } else { 2232 2378 for($i=0;$i<sizeof($response['result']);$i++){ … … 2236 2382 $values_touse[$response['result'][$i]['ref']]['design'] = $response['result'][$i]['design']; 2237 2383 } 2238 2239 2384 2385 2240 2386 if( $settings['backend']['warehouse'] != -1 && $settings['backend']['warehouse'] != ''){ 2241 2387 2242 2388 $refArray = '{ 2243 2389 "comparison":0, … … 2249 2395 "type":"Number" 2250 2396 },'; 2251 2252 foreach ($refs as $key => $value) { 2253 2397 2398 foreach ($refs as $key => $value) { 2399 2254 2400 $refArray .= '{ 2255 2401 "comparison":0, … … 2260 2406 "skipCheckType":false, 2261 2407 "type":"Number" 2262 },'; 2263 } 2264 2408 },'; 2409 } 2410 2265 2411 $refArray .='{ 2266 2412 "comparison":0, … … 2271 2417 "skipCheckType":false, 2272 2418 "type":"Number" 2273 }'; 2274 2275 2276 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'Sa', $refArray); 2277 2278 //$this->logs->writeFileLog('Update All Sa:', $refArray); 2419 }'; 2420 2421 2422 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'Sa', $refArray); 2423 2424 //$this->logs->writeFileLog('Update All Sa:', $refArray); 2279 2425 2280 2426 if (curl_error($ch)) { 2281 2427 $this->logs->writeFileLog('updateAllFieldsProducts2', $ch); 2282 2428 } else if(empty($response)){ 2283 $this->logs->writeFileLog('updateAllFieldsProducts2', 'EMPTY RESPONSE'); 2429 $this->logs->writeFileLog('updateAllFieldsProducts2', 'EMPTY RESPONSE'); 2284 2430 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 2285 $this->logs->writeFileLog('updateAllFieldsProducts2', $response['messages'][0]['messageCodeLocale']); 2286 } else { 2431 $this->logs->writeFileLog('updateAllFieldsProducts2', $response['messages'][0]['messageCodeLocale']); 2432 } else { 2287 2433 for($i=0;$i<sizeof($response['result']);$i++){ 2288 2434 2289 2435 $values_touse[$response['result'][$i]['ref']]['stock']=$response['result'][$i]['stock']; 2290 } 2436 } 2291 2437 } 2292 2438 }else{ 2293 2439 for($i=0;$i<sizeof($response['result']);$i++){ 2294 2440 2295 2441 $values_touse[$response['result'][$i]['ref']]['stock']=$response['result'][$i]['stock']; 2296 2442 2297 2443 } 2298 } 2299 } 2300 2444 } 2445 } 2446 2301 2447 foreach($values_touse as $key => $values){ 2302 2448 $productID = wc_get_product_id_by_sku($key); 2303 2449 update_post_meta($productID,'_stock',$values['stock']); 2304 2450 2305 2451 $my_post = array('ID' => $productID, 2306 2452 'post_title' => $values['design'] … … 2309 2455 wp_update_post( $my_post ); 2310 2456 update_post_meta( $productID, '_price', $values[$settings['backend']['productPriceColumn']] ); 2311 update_post_meta( $productID, '_regular_price', $values[$settings['backend']['productPriceColumn']]); 2312 2313 } 2314 2315 2316 } 2457 update_post_meta( $productID, '_regular_price', $values[$settings['backend']['productPriceColumn']]); 2458 2459 } 2460 2461 2462 } 2317 2463 } 2318 2464 //Logout … … 2320 2466 } else { 2321 2467 echo "empty_refs"; 2322 } 2468 } 2323 2469 } 2324 2470 } -
drivefx-woocommerce/trunk/css/style_datatable.css
r1487316 r2526532 2 2 * Table styles 3 3 */ 4 table.dataTable {4 table.dataTable { 5 5 width: 100%; 6 6 margin: 0 auto; … … 498 498 } 499 499 500 #updateStocks, #update AllFields {500 #updateStocks, #updateStocks, #updatePrices, #updateAllFields { 501 501 margin-left: 10px; 502 502 cursor: pointer; … … 554 554 right: 0; 555 555 } 556 557 558 -
drivefx-woocommerce/trunk/js/drivefx-woocommerce.js
r2456862 r2526532 2 2 3 3 jQuery(document).ready(function() { 4 4 5 5 //Initialize plugin 6 6 jQuery('#backend_url_initialize').click(function (){ 7 7 if(jQuery('#url').val() != ''){ 8 8 jQuery('#invalidBackendUrl').remove(); 9 9 10 10 var urlBackend = jQuery('#url').val(); 11 11 urlBackend = urlBackend.replace(/html\/+$/g,""); 12 12 urlBackend = urlBackend.replace(/html+$/g,""); 13 13 urlBackend = urlBackend.replace(/\/+$/g,""); 14 14 15 15 //Open popup 16 window.open("https://sis05.drivefx.net/OAuthCallbackPHCGo/oauth2callback_phcfx.aspx?backendUrl="+urlBackend+"&appName=PHC GO Woocommerce&redirectUri="+window.location.href, "yyyyy", "width=580,height=580,resizable=no,toolbar=no,menubar=no,location=no,status=no"); 17 //window.open("https://trial.phcfx.com/OauthCallback/oauth2callback_phcfx.aspx?backendUrl="+urlBackend+"&appName=PHC GO Woocommerce&redirectUri="+window.location.href, "yyyyy", "width=580,height=550,resizable=no,toolbar=no,menubar=no,location=no,status=no"); 18 //window.open("http://sis.phc.pt/OauthCallback/oauth2callback_phcfx.aspx?backendUrl="+urlBackend+"&appName=PHC GO Woocommerce&redirectUri="+window.location.href, "yyyyy", "width=580,height=580,resizable=no,toolbar=no,menubar=no,location=no,status=no"); 19 //window.open("http://phc201412002/FX/OAuthCallback/oauth2callback_phcfx.aspx?backendUrl="+urlBackend+"&appName=PHC GO Woocommerce&redirectUri="+window.location.href, "yyyyy", "width=580,height=550,resizable=no,toolbar=no,menubar=no,location=no,status=no"); 16 window.open("https://sis05.drivefx.net/OAuthCallbackPHCGo/oauth2callback_phcfx.aspx?backendUrl="+urlBackend+"&appName=PHC GO Woocommerce&redirectUri="+window.location.href, "yyyyy", "width=580,height=580,resizable=no,toolbar=no,menubar=no,location=no,status=no"); 20 17 return false; 21 18 } else { … … 24 21 } 25 22 }); 26 23 27 24 if(jQuery('#typeOfOrder').val() == 0){ 28 25 jQuery('#statusOfOrder').parent('td').parent('tr').hide(); 29 26 } 30 27 31 28 jQuery('#updateStocks').hide(); 32 29 jQuery('#saveProductInShop').hide(); 33 30 jQuery('#updateStocks').hide(); 31 jQuery('#updatePrices').hide(); 34 32 jQuery('#updateAllFields').hide(); 35 33 … … 51 49 action: 'woocommerce_fx', 52 50 method: 'statusOfOrder', 53 selectItems: jQuery('#statusOfOrder').val(), 54 typeOfOrder: jQuery('#typeOfOrder').val() 51 selectItems: jQuery('#statusOfOrder').val(), 52 typeOfOrder: jQuery('#typeOfOrder').val() 55 53 }) 56 54 .done(function (data) { … … 64 62 }) 65 63 }); 66 64 67 65 //Run to show list of products 68 66 jQuery('#importToShop').click(function (event){ … … 89 87 }); 90 88 jQuery('#updateStocks').show(); 89 jQuery('#updatePrices').show(); 91 90 jQuery('#updateAllFields').show(); 92 91 jQuery('#saveProductInShop').show(); … … 98 97 jQuery('#loader').html(''); 99 98 jQuery('#updateStocks').hide(); 99 jQuery('#updatePrices').hide(); 100 100 jQuery('#updateAllFields').hide(); 101 101 jQuery('#saveProductInShop').hide(); … … 116 116 jQuery('#saveProductInShop').hide(); 117 117 jQuery('#updateStocks').hide(); 118 jQuery('#updatePrices').hide(); 118 119 jQuery('#updateAllFields').hide(); 119 120 … … 129 130 .done(function (data) { 130 131 jQuery('.alignleft #messageSuccess').html(''); 131 132 132 133 if(data.length != 0 && data != 'empty_refs'){ 133 134 jQuery('.alignleft h2').before('<div id="messageSuccess"><div class="error"><p><strong>Please fill description of selected products to import them successfully: ' + data + ' </strong></p></div></div>'); 134 135 } 135 136 136 137 if(data != 'empty_refs'){ 137 138 jQuery('.alignleft h2').before('<div id="messageSuccess"><div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Import successfull</strong></p></div></div>'); 138 139 } 139 140 140 141 jQuery('#saveProductInShop').show(); 141 142 jQuery('#updateStocks').show(); 143 jQuery('#updatePrices').show(); 142 144 jQuery('#updateAllFields').show(); 143 145 jQuery('#loader2').html(''); … … 161 163 }); 162 164 jQuery('#updateStocks').show(); 165 jQuery('#updatePrices').show(); 163 166 jQuery('#updateAllFields').show(); 164 167 jQuery('#saveProductInShop').show(); … … 170 173 jQuery('#loader').html(''); 171 174 jQuery('#updateStocks').hide(); 175 jQuery('#updatePrices').hide(); 172 176 jQuery('#updateAllFields').hide(); 173 177 jQuery('#saveProductInShop').hide(); … … 176 180 }) 177 181 }) 178 }); 182 }); 179 183 180 184 //Update stocks of products presented in PHC GO … … 189 193 jQuery('#saveProductInShop').hide(); 190 194 jQuery('#updateStocks').hide(); 195 jQuery('#updatePrices').hide(); 191 196 jQuery('#updateAllFields').hide(); 192 197 … … 202 207 .done(function (data) { 203 208 jQuery('.alignleft #messageSuccess').html(''); 204 209 205 210 if(data != 'empty_refs'){ 206 211 jQuery('.alignleft h2').before('<div id="messageSuccess"><div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Update of selected products successfull</strong></p></div></div>'); 207 212 } 208 213 209 214 jQuery('#saveProductInShop').show(); 210 215 jQuery('#updateStocks').show(); 216 jQuery('#updatePrices').show(); 211 217 jQuery('#updateAllFields').show(); 212 218 jQuery('#loader2').html(''); … … 230 236 }); 231 237 jQuery('#updateStocks').show(); 238 jQuery('#updatePrices').show(); 232 239 jQuery('#updateAllFields').show(); 233 240 jQuery('#saveProductInShop').show(); … … 239 246 jQuery('#loader').html(''); 240 247 jQuery('#updateStocks').hide(); 248 jQuery('#updatePrices').hide(); 241 249 jQuery('#updateAllFields').hide(); 242 250 jQuery('#saveProductInShop').hide(); … … 247 255 }); 248 256 249 //Update all fields odproducts presented in PHC GO250 jQuery('#updateAllFields').click(function (event) {257 //Update prices of products presented in PHC GO 258 jQuery('#updatePrices').click(function (event) { 251 259 //Update products 252 260 var arr = new Array(); … … 258 266 jQuery('#saveProductInShop').hide(); 259 267 jQuery('#updateStocks').hide(); 268 jQuery('#updatePrices').hide(); 260 269 jQuery('#updateAllFields').hide(); 261 270 // stop normal form submission handler … … 264 273 jQuery.post(url, { 265 274 action: 'woocommerce_fx', 266 method: 'update AllFieldsProducts',275 method: 'updatePricesProducts', 267 276 refs: arr 268 277 }) 269 278 .done(function (data) { 270 279 jQuery('.alignleft #messageSuccess').html(''); 271 280 272 281 if(data != 'empty_refs'){ 273 282 jQuery('.alignleft h2').before('<div id="messageSuccess"><div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Update of selected products successfull</strong></p></div></div>'); 274 283 } 275 284 276 285 jQuery('#saveProductInShop').show(); 277 286 jQuery('#updateStocks').show(); 287 jQuery('#updatePrices').show(); 278 288 jQuery('#updateAllFields').show(); 279 289 jQuery('#loader2').html(''); … … 297 307 }); 298 308 jQuery('#updateStocks').show(); 309 jQuery('#updatePrices').show(); 299 310 jQuery('#updateAllFields').show(); 300 311 jQuery('#saveProductInShop').show(); … … 306 317 jQuery('#loader').html(''); 307 318 jQuery('#updateStocks').hide(); 319 jQuery('#updatePrices').hide(); 320 jQuery('#updateAllFields').hide(); 321 jQuery('#saveProductInShop').hide(); 322 } 323 jQuery("#tableOfProducts_previous").after(" "); 324 }) 325 }) 326 }); 327 328 //Update all fields od products presented in PHC GO 329 jQuery('#updateAllFields').click(function (event) { 330 //Update products 331 var arr = new Array(); 332 jQuery(".updateStockShop").each(function() { 333 arr.push(jQuery(this).attr('id')); 334 }); 335 336 jQuery('#loader2').html('<img style="margin-top: 10px; margin-left: 20px;" src="'+pathPlugin+'images/ajax-loader.gif" title="Loading..">'); 337 jQuery('#saveProductInShop').hide(); 338 jQuery('#updateStocks').hide(); 339 jQuery('#updatePrices').hide(); 340 jQuery('#updateAllFields').hide(); 341 // stop normal form submission handler 342 event.preventDefault(); 343 //save products in MySQL 344 jQuery.post(url, { 345 action: 'woocommerce_fx', 346 method: 'updateAllFieldsProducts', 347 refs: arr 348 }) 349 .done(function (data) { 350 jQuery('.alignleft #messageSuccess').html(''); 351 352 if(data != 'empty_refs'){ 353 jQuery('.alignleft h2').before('<div id="messageSuccess"><div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Update of selected products successfull</strong></p></div></div>'); 354 } 355 356 jQuery('#saveProductInShop').show(); 357 jQuery('#updateStocks').show(); 358 jQuery('#updatePrices').show(); 359 jQuery('#updateAllFields').show(); 360 jQuery('#loader2').html(''); 361 362 //Refresh of list of products 363 jQuery.post(url, { 364 action: 'woocommerce_fx', 365 method: 'listOfProducts' 366 }) 367 .done(function (data) { 368 jQuery("#tableOfProducts").html(""); 369 jQuery('#tableOfProducts').append(data); 370 try{ 371 jQuery('#tableOfProducts').DataTable({ 372 "iDisplayLength": 10, 373 "bDestroy":true, 374 "aoColumnDefs": [{ 375 'bSortable': false, 376 'aTargets': [ 0 ] 377 }] 378 }); 379 jQuery('#updateStocks').show(); 380 jQuery('#updatePrices').show(); 381 jQuery('#updateAllFields').show(); 382 jQuery('#saveProductInShop').show(); 383 jQuery('#importToShop').show(); 384 jQuery('#loader').html(''); 385 } catch(err) { 386 jQuery('#descriptionPlugin').html('<div class="error" style="width: 96%;"><b><p>Incomplete configurations.<br/>Please verify if you fill "Create Invoice" and "Field to obtain product price in PHC GO".</p></b></div>'); 387 jQuery('#importToShop').show(); 388 jQuery('#loader').html(''); 389 jQuery('#updateStocks').hide(); 390 jQuery('#updatePrices').hide(); 308 391 jQuery('#updateAllFields').hide(); 309 392 jQuery('#saveProductInShop').hide(); … … 329 412 }); 330 413 414 //Update Tax-Exempt param 415 if(jQuery('#createExemptPT')[0].checked == true){ 416 jQuery('#createExemptEU')[0].checked = false; 417 jQuery('#createExemptEU').css('pointer-events', 'none'); 418 } 419 jQuery('#createExemptPT').click(function (event){ 420 if(jQuery('#createExemptPT')[0].checked == true){ 421 jQuery('#createExemptEU')[0].checked = false; 422 jQuery('#createExemptEU').css('pointer-events', 'none'); 423 } else{ 424 jQuery('#createExemptEU')[0].checked = false; 425 jQuery('#createExemptEU').css('pointer-events', 'auto'); 426 } 427 }); 428 if(jQuery('#createExemptEU')[0].checked == true){ 429 jQuery('#createExemptPT')[0].checked = false; 430 jQuery('#createExemptPT').css('pointer-events', 'none'); 431 } 432 jQuery('#createExemptEU').click(function (event){ 433 if(jQuery('#createExemptEU')[0].checked == true){ 434 jQuery('#createExemptPT')[0].checked = false; 435 jQuery('#createExemptPT').css('pointer-events', 'none'); 436 } else{ 437 jQuery('#createExemptPT')[0].checked = false; 438 jQuery('#createExemptPT').css('pointer-events', 'auto'); 439 } 440 }); 441 331 442 }); 332 443 -
drivefx-woocommerce/trunk/settings/backend.php
r2456862 r2526532 4 4 5 5 global $wpdb; 6 7 $table_name = $wpdb->prefix."postmeta"; 6 7 $table_name = $wpdb->prefix."postmeta"; 8 8 $query = "SELECT meta_value FROM %s WHERE meta_key = %s"; 9 9 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token'))); … … 21 21 ?><p>Provide the info bellow so that the plugin can talk to your PHC Software backend installation.<br> 22 22 <?php echo implode(', ', $required) ?> are required to be setup!</p> 23 24 <div id="box"> 23 24 <div id="box"> 25 25 <div id="cab"> 26 26 Initialize Plugin Settings 27 27 </div> 28 28 <table class="form-table"> 29 <tbody> 29 <tbody> 30 30 <tr> 31 31 <th scope="row"> … … 33 33 </th> 34 34 <td> 35 <?php 36 if(is_array($settings['backend']['url'])){ 35 <?php 36 if(is_array($settings['backend']['url'])){ 37 37 $settings['backend']['url'] = ''; 38 38 } ?> 39 39 <input class="regular-text" id="url" type="text" name="drivefx-woocommerce[backend][url]" value="<?php echo $settings['backend']['url'] ?>"> 40 40 41 41 <?php if($resultDB->meta_value != ''){ ?> 42 42 <div id="backend_url_initialize" class="button button-primary" title="Autenticate plugin"> 43 <img id="plus" src="<?php echo plugins_url('/../images/plus.png', __FILE__) ?>" title="Autenticate plugin"> 43 <img id="plus" src="<?php echo plugins_url('/../images/plus.png', __FILE__) ?>" title="Autenticate plugin"> 44 44 <span id="autenticatePlugin">Re-Autenticate</span> 45 45 </div> 46 46 47 47 <?php } else if($settings['backend']['url'] == '' && $resultDB->meta_value == '') { ?> 48 48 49 49 <?php } else { ?> 50 50 <div id="backend_url_initialize" class="button button-primary" title="Autenticate plugin"> 51 <img id="plus" src="<?php echo plugins_url('/../images/plus.png', __FILE__) ?>" title="Autenticate plugin"> 51 <img id="plus" src="<?php echo plugins_url('/../images/plus.png', __FILE__) ?>" title="Autenticate plugin"> 52 52 <span id="autenticatePlugin">Autenticate</span> 53 53 </div> 54 54 <?php } ?> 55 55 56 56 <p class="description">The URL of your PHC application.<br>Something like, e.g. https://sisXX.phcgo.net/XPTO/</p> 57 57 </td> … … 59 59 </tbody> 60 60 </table> 61 </div><?php 61 </div><?php 62 62 63 63 foreach ($this->options['backend'] as $id => $opts): 64 64 65 65 $name = sprintf(DRIVEFXWOOCOMMERCE_PLUGIN_NAME.'[backend][%s]', $id); 66 66 $value = isset($settings['backend'][$id]) ? $settings['backend'][$id] : null; … … 75 75 switch ($id) { 76 76 case 'username': 77 ?><div id="box"> 77 ?><div id="box"> 78 78 <div id="cab"> 79 79 Backend Settings 80 80 </div> 81 81 <table class="form-table"> 82 <tbody> 82 <tbody> 83 83 <tr> 84 84 <th scope="row"> … … 102 102 <p class="description"><?php echo $opts['descr'] ?></p> 103 103 </td> 104 </tr> 104 </tr> 105 105 <?php break; 106 106 case 'dbname': … … 113 113 <p class="description"><?php echo $opts['descr'] ?></p> 114 114 </td> 115 </tr> 115 </tr> 116 116 <?php break; 117 117 … … 119 119 ?></tbody> 120 120 </table> 121 </div> <?php 121 </div> <?php 122 122 if($_SESSION['username'] != ''){ ?> 123 123 124 124 <div id="box"> 125 125 <div id="cab"> … … 127 127 </div> 128 128 <table class="form-table"> 129 <tbody> 129 <tbody> 130 130 <tr> 131 131 <th scope="row"> … … 149 149 <?php } break; 150 150 case 'sendInvoice': 151 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 152 151 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 152 153 153 <tr> 154 154 <th scope="row"> … … 169 169 // Text for email body 170 170 case 'emailBody': 171 if($settings['backend']['createInvoice'] != '' && $settings['backend']['sendInvoice'] != ''){ ?> 171 if($settings['backend']['createInvoice'] != '' && $settings['backend']['sendInvoice'] != ''){ ?> 172 172 <tr> 173 173 <th scope="row"> … … 178 178 <p class="description"><?php echo $opts['descr'] ?></p> 179 179 </td> 180 </tr> 180 </tr> 181 181 <?php } break; 182 182 // Type of Invoice 183 183 case 'typeOfInvoice': 184 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 184 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 185 185 <tr> 186 186 <th scope="row"> … … 188 188 </th> 189 189 <td> 190 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 190 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 191 191 <?php if(!empty($_SESSION[$id])){ ?> 192 192 <option value="0">Select one...</option> 193 <?php } 193 <?php } 194 194 echo $_SESSION[$id]; ?> 195 195 </td> 196 196 </tr> 197 <?php } break; 197 <?php } break; 198 198 case 'toSignInvoice': 199 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 199 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 200 200 <tr> 201 201 <th scope="row"> … … 217 217 218 218 case 'fieldNif': 219 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 219 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 220 220 <tr> 221 221 <th scope="row"> … … 223 223 </th> 224 224 <td> 225 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 225 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 226 226 <?php echo $_SESSION[$id];?> 227 227 228 228 </td> 229 229 </tr> … … 231 231 232 232 case 'includeTaxonSendCost': 233 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 233 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 234 234 <tr> 235 235 <th scope="row"> … … 237 237 </th> 238 238 <td> 239 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 239 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 240 240 <?php echo $_SESSION[$id];?> 241 241 </select> … … 243 243 </tr> 244 244 <?php } break; 245 //Customer free-tax246 case 'createExempt Cl':245 //Customer from outside Portugal as free-tax 246 case 'createExemptPT': 247 247 ?></tbody> 248 248 </table> 249 </div><?php 249 </div><?php 250 250 if($_SESSION['username'] != ''){ ?> 251 251 <div id="box"> 252 252 <div id="cab"> 253 Tax- exempt customersSettings253 Tax-Exempt Settings 254 254 </div> 255 255 <table class="form-table"> 256 <tbody> 256 <tbody> 257 257 <tr> 258 258 <th scope="row"> 259 259 <?php if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '') { ?> 260 <label for="<?php echo $id ?>"> Create tax-exempt customers?</label>260 <label for="<?php echo $id ?>">From outside PT</label> 261 261 <?php } ?> 262 262 </th> … … 273 273 </tr> 274 274 <?php } break; 275 //The reason for the tax exemption .275 //The reason for the tax exemption PT. 276 276 case 'typeOfReason': 277 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['createExempt Cl'] != ''){ ?>277 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['createExemptPT'] != ''){ ?> 278 278 <tr> 279 279 <th scope="row"> … … 281 281 </th> 282 282 <td> 283 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 283 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 284 284 <?php if(!empty($_SESSION[$id])){ ?> 285 285 <option value="0">Select one...</option> 286 <?php } 286 <?php } 287 287 echo $_SESSION[$id]; ?> 288 288 </td> 289 289 </tr> 290 290 <?php } break; 291 292 case 'warehouseOrder': 291 //Customer from outside EU as free-tax 292 case 'createExemptEU': 293 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 294 <tr> 295 <th scope="row"> 296 <label for="<?php echo $id ?>">From outside EU</label> 297 </th> 298 <td> 299 <?php if($value == 'on'){ 300 $checkedBox = 'checked'; 301 } else { 302 $checkbox = ''; 303 } ?> 304 <input style="width: 0;" class="regular-text" <?php echo $checkedBox ?> id="<?php echo $id ?>" type="<?php echo $opts['type'] ?>" name="<?php echo $name ?>"> 305 <span><?php echo $opts['checkboxDescription'] ?></span> 306 <p class="description"><?php echo $opts['descr'] ?></p> 307 </td> 308 </tr> 309 <?php } break; 310 //The reason for the tax exemption EU. 311 case 'typeOfReasonEU': 312 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['createExemptEU'] != ''){ ?> 313 <tr> 314 <th scope="row"> 315 <label for="<?php echo $id ?>"><?php echo $opts['label'] ?></label> 316 </th> 317 <td> 318 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 319 <?php if(!empty($_SESSION[$id])){ ?> 320 <option value="0">Select one...</option> 321 <?php } 322 echo $_SESSION[$id]; ?> 323 </td> 324 </tr> 325 <?php } break; 326 //Companies from EU as free-tax 327 case 'createExemptCO': 328 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 329 <tr> 330 <th scope="row"> 331 <label for="<?php echo $id ?>">From EU (Co)</label> 332 </th> 333 <td> 334 <?php if($value == 'on'){ 335 $checkedBox = 'checked'; 336 } else { 337 $checkbox = ''; 338 } ?> 339 <input style="width: 0;" class="regular-text" <?php echo $checkedBox ?> id="<?php echo $id ?>" type="<?php echo $opts['type'] ?>" name="<?php echo $name ?>"> 340 <span><?php echo $opts['checkboxDescription'] ?></span> 341 <p class="description"><?php echo $opts['descr'] ?></p> 342 </td> 343 </tr> 344 <?php } break; 345 //The reason for the tax exemption EU companies. 346 case 'typeOfReasonCO': 347 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['createExemptCO'] != ''){ ?> 348 <tr> 349 <th scope="row"> 350 <label for="<?php echo $id ?>"><?php echo $opts['label'] ?></label> 351 </th> 352 <td> 353 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 354 <?php if(!empty($_SESSION[$id])){ ?> 355 <option value="0">Select one...</option> 356 <?php } 357 echo $_SESSION[$id]; ?> 358 </td> 359 </tr> 360 <?php } break; 361 case 'warehouseOrder': 293 362 // Show gama >= star 294 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 363 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 295 364 </tbody> 296 365 </table> 297 366 </div> 298 <div id="box"> 367 <div id="box"> 299 368 <div id="cab"> 300 369 Order Settings 301 370 </div> 302 371 <table class="form-table"> 303 <tbody> 372 <tbody> 304 373 <tr> 305 374 <th scope="row"> … … 307 376 </th> 308 377 <td> 309 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 378 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 310 379 <?php if(!empty($_SESSION[$id])){ ?> 311 380 <option value="1">Default Warehouse</option> 312 <?php } 381 <?php } 313 382 echo $_SESSION[$id]; ?> 314 383 </td> … … 316 385 <?php } break; 317 386 case 'typeOfOrder': 318 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 387 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 319 388 <tr> 320 389 <th scope="row"> … … 322 391 </th> 323 392 <td> 324 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 393 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 325 394 <?php if(!empty($_SESSION[$id])){ ?> 326 395 <option value="0">Select one...</option> 327 <?php } 396 <?php } 328 397 echo $_SESSION[$id]; ?> 329 398 </td> 330 399 </tr> 331 332 <?php } break; 400 401 <?php } break; 333 402 case 'toSignOrder': 334 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 403 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 335 404 <tr> 336 405 <th scope="row"> … … 351 420 <?php } break; 352 421 case 'numberOfOrder': 353 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != '' && $settings['backend']['toSignOrder'] != ''){ ?> 422 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != '' && $settings['backend']['toSignOrder'] != ''){ ?> 354 423 <tr> 355 424 <th scope="row"> … … 357 426 </th> 358 427 <td> 359 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 428 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 360 429 <?php $fieldsStatus = array('notSelected' => 'Select one...', 361 430 'nmdesc' => 'Main Description', … … 373 442 } ?> 374 443 <option id="<?php echo $key ?>" <?php echo $selected_dropdown ?> value="<?php echo $key ?>"><?php echo $value ?></option> 375 <?php 444 <?php 376 445 } ?> 377 446 </td> … … 380 449 <?php } break; 381 450 case 'statusOfOrder': 382 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 451 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 383 452 <tr> 384 453 <th scope="row"> … … 386 455 </th> 387 456 <td> 388 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 457 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 389 458 <?php $fieldsStatus = array('notSelected' => 'Select one...', 390 459 'nmdesc' => 'Main Description', … … 402 471 } ?> 403 472 <option id="<?php echo $key ?>" <?php echo $selected_dropdown ?> value="<?php echo $key ?>"><?php echo $value ?></option> 404 <?php 473 <?php 405 474 } ?> 406 475 </td> … … 409 478 // Select reference for shipping 410 479 case 'shippingName': 411 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 480 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 412 481 <tr> 413 482 <th scope="row"> … … 415 484 </th> 416 485 <td> 417 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 486 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 418 487 <?php if(!empty($_SESSION[$id])){ ?> 419 488 <option value="0">Select one...</option> 420 <?php } 489 <?php } 421 490 echo $_SESSION[$id]; ?> 422 491 </td> … … 425 494 // Select reference for fees 426 495 case 'feesName': 427 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 496 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 428 497 <tr> 429 498 <th scope="row"> … … 431 500 </th> 432 501 <td> 433 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 502 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 434 503 <?php if(!empty($_SESSION[$id])){ ?> 435 504 <option value="0">Select one...</option> 436 <?php } 505 <?php } 437 506 echo $_SESSION[$id]; ?> 438 507 </td> … … 441 510 //Manage stock 442 511 case 'manageStock': 443 if($_SESSION['username'] != ''){ ?> 512 if($_SESSION['username'] != ''){ ?> 444 513 </tbody> 445 514 </table> … … 450 519 </div> 451 520 <table class="form-table"> 452 <tbody> 521 <tbody> 453 522 <?php if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ ?> 454 523 <tr> … … 470 539 // Select produtcs that have a positive stock 471 540 case 'positiveStock': 472 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 473 541 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != ''){ ?> 542 474 543 <tr> 475 544 <th scope="row"> … … 488 557 </tr> 489 558 <?php } break; 490 // Filter stock (stock - orders) 559 // Filter stock (stock - orders) 491 560 case 'filterStock': 492 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['warehouse'] == "-1"){ ?> 493 561 if($_SESSION['username'] != '' && $settings['backend']['createInvoice'] != '' && $settings['backend']['warehouse'] == "-1"){ ?> 562 494 563 <tr> 495 564 <th scope="row"> … … 510 579 // Product price column 511 580 case 'productPriceColumn': 512 if($_SESSION['username'] != ''){ ?> 581 if($_SESSION['username'] != ''){ ?> 513 582 <tr> 514 583 <th scope="row"> … … 516 585 </th> 517 586 <td> 518 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 587 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 519 588 <?php $fieldsStatus = array('epv0' => 'Select one...', 520 589 'epv1' => 'Retail price 1 (epv1)', … … 529 598 } ?> 530 599 <option id="<?php echo $key ?>" <?php echo $selected_dropdown ?> value="<?php echo $key ?>"><?php echo $value ?></option> 531 <?php 600 <?php 532 601 } ?> 533 602 </td> … … 535 604 <?php } break; 536 605 case 'warehouse': 537 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 606 if($_SESSION['gamaDRIVEFX'] >= 9 && $_SESSION['username'] != ''){ ?> 538 607 <tr> 539 608 <th scope="row"> … … 541 610 </th> 542 611 <td> 543 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 612 <select id="<?php echo $id ?>" name="<?php echo $name ?>"> 544 613 <?php if(!empty($_SESSION[$id])){ ?> 545 614 <option value="-1">All Warehouses</option> 546 <?php } 615 <?php } 547 616 echo $_SESSION[$id]; ?> 548 617 </td> … … 556 625 </table> 557 626 </div> 558 <?php } break; 627 <?php } break; 559 628 default: 560 629 break; 561 630 } 562 631 } 563 564 565 endforeach; 566 632 633 634 endforeach; 635 567 636 if($showErrorsLogin == true && (empty($settings['backend']['username']) || empty($settings['backend']['password']) || empty($settings['backend']['url']))){ 568 637 $this->messagesInformation("Incomplete configurations.<br>Please fill Username, Password and Backend URL"); 569 } 638 } 570 639 ?> -
drivefx-woocommerce/trunk/settings/import-products.php
r2456862 r2526532 23 23 </div> 24 24 25 <?php if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ ?> 25 <?php if($_SESSION['manageStockParameter'] === 'S' && $_SESSION['gamaDRIVEFX'] >= 9){ ?> 26 26 <div id="updateStocks" class="button button-primary" title="Update stocks in your online store"> 27 <img id="plus" src="<?php echo plugins_url('/../images/update.png', __FILE__) ?>" title=" Save selected product in yout online store"> Update Stocks27 <img id="plus" src="<?php echo plugins_url('/../images/update.png', __FILE__) ?>" title="Update all stocks of products from PHC"> Update Stocks 28 28 </div> 29 29 <?php } ?> 30 31 <div id="updatePrices" class="button button-primary" title="Update prices in your online store"> 32 <img id="plus" src="<?php echo plugins_url('/../images/update.png', __FILE__) ?>" title="Update all prices of products from PHC"> Update Prices 33 </div> 34 30 35 <div id="updateAllFields" class="button button-primary" title="Update all fields of products from PHC"> 31 36 <img id="plus" src="<?php echo plugins_url('/../images/update.png', __FILE__) ?>" title="Update all fields of products in your online store"> Update all fields -
drivefx-woocommerce/trunk/settings/syncro_gate.php
r2465114 r2526532 19 19 public function __construct () { 20 20 $this->logs = new Logs(); 21 $this->utils_services = new UtilsServices(); 21 $this->utils_services = new UtilsServices(); 22 22 } 23 23 … … 33 33 // get token 34 34 global $wpdb; 35 $table_name = $wpdb->prefix."postmeta"; 35 $table_name = $wpdb->prefix."postmeta"; 36 36 $query = "SELECT meta_value FROM %s WHERE meta_key = %s"; 37 37 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token'))); … … 68 68 $query = "SELECT meta_key, meta_value FROM %s where post_id = %d"; 69 69 $raw_order = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($order_id)))); 70 70 71 71 //get NIF name field from backendinfo 72 72 $nifName = '_billing_'.$settings['backend']['fieldNif']; 73 73 //get price column field from backendinfo 74 74 $preco = intval(str_replace('epv', '', $settings['backend']['productPriceColumn'])); 75 75 76 76 $syncroData = new stdClass(); 77 77 … … 79 79 * --- billing data --- * 80 80 ********************************************************************/ 81 81 82 82 foreach ($raw_order as $key => $value) { 83 83 if($value->meta_key == '_billing_country'){ 84 84 $syncroData->billing_country = $value->meta_value; 85 85 } else if($value->meta_key == '_billing_first_name') { 86 $syncroData->billing_first_name = $value->meta_value; 86 $syncroData->billing_first_name = $value->meta_value; 87 87 } else if($value->meta_key == '_billing_last_name') { 88 $syncroData->billing_last_name = $value->meta_value; 88 $syncroData->billing_last_name = $value->meta_value; 89 89 } else if($value->meta_key == '_billing_address_1') { 90 $syncroData->billing_address_1 = $value->meta_value; 90 $syncroData->billing_address_1 = $value->meta_value; 91 91 } else if($value->meta_key == '_billing_city') { 92 $syncroData->billing_city = $value->meta_value; 92 $syncroData->billing_city = $value->meta_value; 93 93 } else if($value->meta_key == '_billing_postcode') { 94 $syncroData->billing_postcode = $value->meta_value; 94 $syncroData->billing_postcode = $value->meta_value; 95 95 } else if($value->meta_key == $nifName) { 96 96 $syncroData->$nifName = $value->meta_value; 97 97 } else if($value->meta_key == '_billing_email') { 98 $syncroData->billing_email = $value->meta_value; 98 $syncroData->billing_email = $value->meta_value; 99 99 } else if($value->meta_key == '_billing_phone') { 100 $syncroData->billing_phone = $value->meta_value; 100 $syncroData->billing_phone = $value->meta_value; 101 101 } else if($value->meta_key == '_shipping_country') { 102 $syncroData->shipping_country = $value->meta_value; 102 $syncroData->shipping_country = $value->meta_value; 103 103 } else if($value->meta_key == '_shipping_address_1') { 104 $syncroData->shipping_address_1 = $value->meta_value; 104 $syncroData->shipping_address_1 = $value->meta_value; 105 105 } else if($value->meta_key == '_shipping_city') { 106 $syncroData->shipping_city = $value->meta_value; 106 $syncroData->shipping_city = $value->meta_value; 107 107 } else if($value->meta_key == '_shipping_postcode') { 108 108 $syncroData->shipping_postcode = $value->meta_value; … … 115 115 * --- settings backend Data --- * 116 116 ********************************************************************/ 117 117 118 118 if(isset($settings['backend']['createInvoice'])){ 119 119 $createInvoice = $settings['backend']['createInvoice']; … … 121 121 $syncroData->createInvoice = true; 122 122 } 123 } 123 } 124 124 if(isset($settings['backend']['typeOfInvoice'])) { 125 125 $syncroData->typeOfInvoice = $settings['backend']['typeOfInvoice']; 126 } 126 } 127 127 if(isset($settings['backend']['toSignInvoice'])) { 128 128 $toSignInvoice = $settings['backend']['toSignInvoice']; … … 137 137 $syncroData->includeTaxonSendCost = $settings['backend']['includeTaxonSendCost']; 138 138 } 139 if(isset($settings['backend']['createExemptCl'])) { 140 $createExemptCl = $settings['backend']['createExemptCl']; 141 if($createExemptCl == 'on'){ 142 $syncroData->createExemptCl = true; 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; 143 155 } 144 156 } … … 148 160 if(isset($settings['backend']['typeOfReason'])) { 149 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']; 150 168 } 151 169 if(isset($settings['backend']['warehouseOrder'])) { … … 188 206 $syncroData->sendInvoice = $settings['backend']['sendInvoice']; 189 207 } 190 208 191 209 192 210 /******************************************************************* 193 211 * --- Users Data --- * 194 212 ********************************************************************/ 195 #Get users data query 213 #Get users data query 196 214 //Obtain customer ID to obtain email in Woocommerce Users 197 215 global $wpdb; … … 199 217 //Obtain next post_id of order in MySQL 200 218 $query = "SELECT user_email FROM %s WHERE id = %d"; 201 $docid = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($syncroData->customer_user)))); 219 $docid = $wpdb->get_results(str_replace("'", "", $wpdb->prepare($query, $table_name, sanitize_text_field($syncroData->customer_user)))); 202 220 $syncroData->user_email = $docid[0]->user_email; 203 221 204 222 #Get POST Id for current order 205 global $wpdb; 223 global $wpdb; 206 224 $table_name = $wpdb->prefix."postmeta"; 207 225 //Obtain post_id of order in MySQL … … 213 231 if($syncroData->post_ID == ''){ 214 232 $post_ID = sanitize_text_field($order_id); 215 } 216 233 } 234 217 235 //Obtain doc ID based in order 218 236 $docid = get_post_meta($syncroData->post_ID); 219 237 220 $syncroData->docId = $docid['_docid'][0]; 238 $syncroData->docId = $docid['_docid'][0]; 221 239 $syncroData->orderId = sanitize_text_field($order_id); 222 240 … … 232 250 233 251 #nextPostId 234 global $wpdb; 252 global $wpdb; 235 253 $table_name = $wpdb->prefix."postmeta"; 236 254 //Obtain next post_id of order in MySQL 237 255 $query = "SELECT MAX(post_id) as nextPostId FROM %s"; 238 $packDocId = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 256 $packDocId = $wpdb->get_row(str_replace("'", "", $wpdb->prepare($query, $table_name))); 239 257 240 258 //Save nextPostId 241 259 $syncroData->nextPostId = $packDocId->nextPostId; 242 260 243 261 /******************************************************************* 244 262 * --- Order Shipping Data --- * … … 247 265 # shipping data (Queries) 248 266 249 $table_name = $wpdb->prefix."woocommerce_order_items"; 267 $table_name = $wpdb->prefix."woocommerce_order_items"; 250 268 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'shipping'"; 251 $resultShipping = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 269 $resultShipping = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 252 270 //get tax value for shipping 253 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 271 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 254 272 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'total_tax'"; 255 $resultTax = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 256 //get shipping tax rate 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 257 275 $getShippingTax = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_shipping='1'" ) ); 258 276 //get shipping tax rate country 259 $getShippingCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_shipping='1'" ) );277 //$getShippingCountry = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_country FROM ".$wpdb->prefix."woocommerce_tax_rates WHERE tax_rate_shipping='1'" ) ); 260 278 //get value 261 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 279 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 262 280 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'cost'"; 263 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 281 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultShipping->order_item_id))); 264 282 265 283 … … 275 293 $syncroData->shipping_tax = $getShippingTax; 276 294 } 277 if(isset($getShippingCountry)) {295 /* if(isset($getShippingCountry)) { 278 296 $syncroData->shipping_country = $getShippingCountry; 279 } 297 } */ 280 298 if(isset($resultDB)) { 281 299 $syncroData->shipping_value = $resultDB->meta_value; 282 300 } 283 301 284 302 #Find the type of shipment 285 303 $post = get_post( $_REQUEST['shipping_method'][0] ); … … 287 305 $syncroData->post_title = isset( $post->post_title ) ? $post->post_title : ''; 288 306 $syncroData->edescc = WC()->cart->coupon_discount_amounts['saco']; 289 307 290 308 291 309 … … 293 311 * --- Order Fees Data --- * 294 312 ********************************************************************/ 295 //build common object 313 //build common object 296 314 $boFeesPack = new stdClass(); 297 315 $bofees = []; … … 300 318 301 319 //get fee from mysql 302 $table_name = $wpdb->prefix."woocommerce_order_items"; 320 $table_name = $wpdb->prefix."woocommerce_order_items"; 303 321 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'fee'"; 304 $resultsFee_bo = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 322 $resultsFee_bo = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $packDocId->nextPostId))); 305 323 //get fee value from mysql 306 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 324 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 307 325 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = '_line_total'"; 308 326 309 327 #Obtain name and price of fees 310 foreach ($resultsFee_bo as $resultFee_bo) { 328 foreach ($resultsFee_bo as $resultFee_bo) { 311 329 $resulBoDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFee_bo->order_item_id))); 312 330 313 331 $boFee_name = $resultFee_bo->order_item_name; 314 332 $boFee_value = $resulBoDB->meta_value; 315 333 316 334 array_push($bofees,[ 317 335 'name' => $boFee_name, 318 336 'value' => $boFee_value 319 ]); 320 337 ]); 338 321 339 } 322 340 $boFeesPack = $bofees; … … 324 342 325 343 # Fetch fees data 326 344 327 345 if(isset($resultFee)) { 328 346 $syncroData->fee_name = $resultFee->order_item_name; … … 331 349 $syncroData->fee_value = $resultFeeValue->meta_value; 332 350 } 333 351 334 352 335 353 … … 355 373 $syncroData->billing_address_1_ft = $order_meta['_billing_address_1'][0]; 356 374 $syncroData->billing_city_ft = $order_meta['_billing_city'][0]; 357 $syncroData->billing_phone_ft = $order_meta['_billing_phone'][0]; 358 $syncroData->billing_postcode_ft = $order_meta['_billing_postcode'][0]; 375 $syncroData->billing_phone_ft = $order_meta['_billing_phone'][0]; 376 $syncroData->billing_postcode_ft = $order_meta['_billing_postcode'][0]; 359 377 $syncroData->billing_nif_ft = $order_meta['_billing_'.$settings['backend']['fieldNif']][0]; 360 378 … … 369 387 # shipping data (Queries) 370 388 global $wpdb; 371 $table_name = $wpdb->prefix."woocommerce_order_items"; 389 $table_name = $wpdb->prefix."woocommerce_order_items"; 372 390 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type = 'shipping'"; 373 391 $resultsFtShipping = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $syncroData->nOrder))); 374 392 375 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 393 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 376 394 $query = "SELECT * FROM %s WHERE order_item_id = %s and meta_key = 'cost'"; 377 395 //Obtain name and price of delivery 378 foreach ($resultsFtShipping as $resultFtShipping) { 379 $resultFtDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFtShipping->order_item_id))); 380 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 381 399 $syncroData->ftShipping_name = $resultFtShipping->order_item_name; 382 400 $syncroData->ftShipping_value = $resultFtDB->meta_value; 383 401 } 384 402 385 403 #get shipping country for ft 386 404 if($syncroData->shipping_country != ''){ 387 $syncroData->shipping_country_ft = $syncroData->shipping_country; 405 $syncroData->shipping_country_ft = $syncroData->shipping_country; 388 406 } else { 389 407 $syncroData->shipping_country_ft = $order_meta['_shipping_country'][0]; … … 396 414 * --- Invoice Addicional Fees Data --- * 397 415 ********************************************************************/ 398 416 399 417 //Obtain id of order and products 400 418 $order = new WC_Order($orderid); 401 419 $orderPostId = $order->post->ID; 402 //build common object 420 //build common object 403 421 $addPack = new stdClass(); 404 422 $fees = []; 405 423 406 424 # fees data (Queries) 407 global $wpdb; 408 $table_name = $wpdb->prefix."woocommerce_order_items"; 425 global $wpdb; 426 $table_name = $wpdb->prefix."woocommerce_order_items"; 409 427 $query = "SELECT * FROM %s WHERE order_id = %s and order_item_type='fee'"; 410 428 $resultsFees_ft = $wpdb->get_results(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $orderPostId))); 411 429 412 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 430 $table_name = $wpdb->prefix."woocommerce_order_itemmeta"; 413 431 $query = "SELECT * FROM %s WHERE order_item_id = %s and (meta_key = 'cost' or meta_key='_line_total')"; 414 432 415 433 #Obtain name and price of fees 416 foreach ($resultsFees_ft as $resultFees_ft) { 434 foreach ($resultsFees_ft as $resultFees_ft) { 417 435 $resultFtDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, $resultFees_ft->order_item_id))); 418 436 419 437 $fee_name = $resultFees_ft->order_item_name; 420 438 $fee_value = $resultFtDB->meta_value; 421 439 422 440 array_push($fees,[ 423 441 'name' => $fee_name, 424 442 'value' => $fee_value 425 ]); 426 443 ]); 444 427 445 } 428 446 429 447 $addPack = $fees; 430 448 $syncroData->fees_ft = $addPack; 431 449 432 450 //$this->logs->writeFileLog('syncroData', $syncroData); 433 451 434 452 return $syncroData; 435 453 } 436 437 /****************************************************************** 438 * --- Order Cart Data --- * 439 *******************************************************************/ 440 public function processProducts($orderid) { 441 442 $this->clearProductsSession(); 443 444 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 445 446 $prodPack = new stdClass(); 447 448 $products = []; 449 $cart_contents = WC()->cart->cart_contents; 450 451 if (is_array($cart_contents)){ 452 foreach (WC()->cart->cart_contents as $key => $value){ 453 //Obtain info about products in cart 454 $productData = WC()->cart->cart_contents[$key]; 455 456 //obtain reference items in cart 457 if($productData['variation_id']!='' && $productData['variation_id'] != 0){ 458 $productReference = wc_get_product( $productData['variation_id'] ); 459 } else { 460 $productReference = wc_get_product( $productData['product_id'] ); 461 } 462 463 $valueItem = $productData['line_total']; 464 465 if ($settings['backend']['includeTaxonSendCost']=="true") { 466 $valueItem += $productData['line_tax']; 467 } 468 469 array_push($products, [ 470 'ref' => $productReference->get_sku(), 471 'qtt' => $productData['quantity'], 472 'epv' => $valueItem, 473 'design' => '', 474 'tax_country' => '', 475 'tax_rate' => '' 476 ]); 477 } 478 // $this->logs->writeFileLog('products_1', $products); 454 455 /******************************************************************* 456 * --- Order Cart Data --- * 457 ********************************************************************/ 458 public function processProducts($orderid) { 459 460 $this->clearProductsSession(); 461 462 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 463 464 $prodPack = new stdClass(); 465 466 $products = []; 467 $cart_contents = WC()->cart->cart_contents; 468 469 if (is_array($cart_contents)){ 470 foreach (WC()->cart->cart_contents as $key => $value){ 471 //Obtain info about products in cart 472 $productData = WC()->cart->cart_contents[$key]; 473 474 //obtain reference items in cart 475 if($productData['variation_id']!='' && $productData['variation_id'] != 0){ 476 $productReference = wc_get_product( $productData['variation_id'] ); 477 } else { 478 $productReference = wc_get_product( $productData['product_id'] ); 479 } 480 481 $valueItem = $productData['line_total']; 482 483 if ($settings['backend']['includeTaxonSendCost']=="true") { 484 $valueItem += $productData['line_tax']; 485 } 486 487 array_push($products, [ 488 'ref' => $productReference->get_sku(), 489 'qtt' => $productData['quantity'], 490 'epv' => $valueItem, 491 'design' => '', 492 'tax_country' => '', 493 'tax_rate' => '' 494 ]); 495 } 496 // $this->logs->writeFileLog('products_1', $products); 497 } 498 499 $this->setProductsSession($products); 500 501 if(empty($products[0]['ref'])){ 502 //Obtain id of order and products 503 $order = new WC_Order($orderid); 504 505 foreach($order->get_items() as $key => $value){ 506 //obtain reference items in cart 507 if($value['variation_id'] != '' && $value['variation_id'] != 0){ 508 $prod = new WC_Product_Variation($value['variation_id']); 509 } else { 510 $prod = new WC_Product($value['product_id']); 511 } 512 513 $valueItem = $value['line_total']; 514 515 if ($settings['backend']['includeTaxonSendCost']=="true") { 516 $valueItem += $value['line_tax']; 517 } 518 519 array_push($products, [ 520 'ref' => $prod->get_sku(), 521 'qtt' => $value['qty'], 522 'epv' => $valueItem, 523 'design' => '', 524 'tax_country' => '', 525 'tax_rate' => '' 526 ]); 527 } 528 $this->setProductsSession($products); 529 } 530 531 # get product ref & design + product tax rate country & order tax rate 532 foreach ($products as &$product) { 533 if($product['qtt']*$product['epv'] != 0){ 534 # get product ref & design 535 global $wpdb; 536 $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'] ) ); 537 $getproducttype = wc_get_product($product_id); 538 $typeproduct = $getproducttype->get_type(); 539 if ($typeproduct == 'variation'){ 540 if ( $product_id ) $wc_product = new WC_Product_Variation( $product_id ); 541 } 542 else { 543 if ( $product_id ) $wc_product = new WC_Product( $product_id ); 544 } 545 546 $product['design'] = $wc_product->get_name(); 547 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 " ) ); 558 559 if (isset($getTaxCountry)){ 560 $product['tax_country'] = $getTaxCountry; 561 } 562 if (isset($getTaxCountry)){ 563 $product['tax_rate'] = $getTaxOrder; 564 } 565 } 566 } 567 568 569 //fulfill "prodpack" with all data 570 $prodPack = $products; 571 572 //$this->logs->writeFileLog('prodPack', $prodPack); 573 574 return $prodPack; 479 575 } 480 576 481 $this->setProductsSession($products); 482 483 if(empty($products[0]['ref'])){ 484 //Obtain id of order and products 485 $order = new WC_Order($orderid); 486 487 foreach($order->get_items() as $key => $value){ 488 //obtain reference items in cart 489 if($value['variation_id'] != '' && $value['variation_id'] != 0){ 490 $prod = new WC_Product_Variation($value['variation_id']); 491 } else { 492 $prod = new WC_Product($value['product_id']); 493 } 494 495 $valueItem = $value['line_total']; 496 497 if ($settings['backend']['includeTaxonSendCost']=="true") { 498 $valueItem += $value['line_tax']; 499 } 500 501 array_push($products, [ 502 'ref' => $prod->get_sku(), 503 'qtt' => $value['qty'], 504 'epv' => $valueItem, 505 'design' => '', 506 'tax_country' => '', 507 'tax_rate' => '' 508 ]); 509 } 510 $this->setProductsSession($products); 577 public function clearProductsSession() { 578 unset($_SESSION['listOfSku']); 579 unset($_SESSION['listOfQuantity']); 580 unset($_SESSION['listOfValueItem']); 511 581 } 512 582 513 # get product ref & design + product tax rate country & order tax rate 514 foreach ($products as &$product) { 515 if($product['qtt']*$product['epv'] != 0){ 516 # get product ref & design 517 global $wpdb; 518 $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'] ) ); 519 $getproducttype = wc_get_product($product_id); 520 $typeproduct = $getproducttype->get_type(); 521 if ($typeproduct == 'variation'){ 522 if ( $product_id ) $wc_product = new WC_Product_Variation( $product_id ); 523 } 524 else { 525 if ( $product_id ) $wc_product = new WC_Product( $product_id ); 526 } 527 528 $product['design'] = $wc_product->get_name(); 529 530 531 # get product tax rate country & order tax rate 532 // product id 533 $getProductId = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $product['ref'] ) ); 534 // product From id 535 $getProduct = wc_get_product($getProductId); 536 // product tax rate country 537 $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() ) ); 538 // order tax rate 539 $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 " ) ); 540 541 if (isset($getTaxCountry)){ 542 $product['tax_country'] = $getTaxCountry; 543 } 544 if (isset($getTaxCountry)){ 545 $product['tax_rate'] = $getTaxOrder; 546 } 547 } 548 } 549 550 551 //fulfill "prodpack" with all data 552 $prodPack = $products; 553 554 //$this->logs->writeFileLog('prodPack', $prodPack); 555 556 return $prodPack; 557 } 558 559 public function clearProductsSession() { 560 unset($_SESSION['listOfSku']); 561 unset($_SESSION['listOfQuantity']); 562 unset($_SESSION['listOfValueItem']); 563 } 564 565 public function setProductsSession($products){ 566 //Save items of cart 567 $_SESSION['listOfSku'] = []; 568 $_SESSION['listOfQuantity'] = []; 569 $_SESSION['listOfValueItem'] = []; 570 571 foreach( $products as $product ) { 572 array_push($_SESSION['listOfSku'], $product->sku); 573 array_push($_SESSION['listOfQuantity'], $product->quantity); 574 array_push($_SESSION['listOfValueItem'], $product->value); 583 public function setProductsSession($products){ 584 //Save items of cart 585 $_SESSION['listOfSku'] = []; 586 $_SESSION['listOfQuantity'] = []; 587 $_SESSION['listOfValueItem'] = []; 588 589 foreach( $products as $product ) { 590 array_push($_SESSION['listOfSku'], $product->sku); 591 array_push($_SESSION['listOfQuantity'], $product->quantity); 592 array_push($_SESSION['listOfValueItem'], $product->value); 593 } 594 return $products; 575 595 } 576 return $products; 577 } 578 596 579 597 /******************************************************************* 580 598 * --- Invoice Cart Data --- * 581 599 ********************************************************************/ 582 public function processFtProducts($orderid) { 583 584 $this->clearProductsSession(); 585 586 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 587 588 $ftproductPack = new stdClass(); 589 590 $ftProducts = []; 591 592 //Obtain id of order and products 593 $order = new WC_Order($orderid); 594 595 foreach($order->get_items() as $key => $value){ 596 //obtain reference items in cart 597 if($value['variation_id'] != '' && $value['variation_id'] != 0){ 598 $prod = new WC_Product_Variation($value['variation_id']); 599 } else { 600 $prod = new WC_Product($value['product_id']); 601 } 602 $sku = $prod->get_sku(); 603 $quantity = $value['qty']; 604 $valueItem = $value['line_total'] + $value['line_tax']; 605 606 array_push($ftProducts, [ 607 'ref' => $sku, 608 'qtt' => $quantity, 609 'epv' => $valueItem, 610 'design' => '', 611 'etiliquido' => '' 612 ]); 613 } 614 //Save items of cart 615 $this->setFtProductsSession($ftProducts); 616 617 618 //FT from Backend if is clicked "button tip" 619 if(empty($ftProducts[0]['ref'])){ 600 public function processFtProducts($orderid) { 601 602 $this->clearProductsSession(); 603 604 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 605 606 $ftproductPack = new stdClass(); 607 608 $ftProducts = []; 609 610 //Obtain id of order and products 611 $order = new WC_Order($orderid); 612 620 613 foreach($order->get_items() as $key => $value){ 621 614 //obtain reference items in cart … … 624 617 } else { 625 618 $prod = new WC_Product($value['product_id']); 626 } 619 } 627 620 $sku = $prod->get_sku(); 628 621 $quantity = $value['qty']; 629 622 $valueItem = $value['line_total'] + $value['line_tax']; 630 623 631 624 array_push($ftProducts, [ 632 625 'ref' => $sku, … … 634 627 'epv' => $valueItem, 635 628 'design' => '', 636 'etiliquido' => '', 637 638 ]); 629 'etiliquido' => '' 630 ]); 639 631 } 640 632 //Save items of cart 641 633 $this->setFtProductsSession($ftProducts); 634 635 636 //FT from Backend if is clicked "button tip" 637 if(empty($ftProducts[0]['ref'])){ 638 foreach($order->get_items() as $key => $value){ 639 //obtain reference items in cart 640 if($value['variation_id'] != '' && $value['variation_id'] != 0){ 641 $prod = new WC_Product_Variation($value['variation_id']); 642 } else { 643 $prod = new WC_Product($value['product_id']); 644 } 645 $sku = $prod->get_sku(); 646 $quantity = $value['qty']; 647 $valueItem = $value['line_total'] + $value['line_tax']; 648 649 array_push($ftProducts, [ 650 'ref' => $sku, 651 'qtt' => $quantity, 652 'epv' => $valueItem, 653 'design' => '', 654 'etiliquido' => '', 655 656 ]); 657 } 658 //Save items of cart 659 $this->setFtProductsSession($ftProducts); 660 } 661 662 # get ft product ref & design 663 foreach ($ftProducts as &$product) { 664 if($product['qtt']*$product['epv'] != 0){ 665 # get product ref & design 666 global $wpdb; 667 $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 $getproducttype = wc_get_product($product_id); 669 $typeproduct = $getproducttype->get_type(); 670 if ($typeproduct == 'variation'){ 671 if ( $product_id ) $wc_prod = new WC_Product_Variation( $product_id ); 672 } 673 else { 674 if ( $product_id ) $wc_prod = new WC_Product( $product_id ); 675 } 676 677 $product['design'] = $wc_prod->get_name(); 678 } 679 } 680 681 $items = $order->get_items(); 682 683 $key=0; 684 foreach($items as $item => $values) { 685 $ftProducts[$key]['etiliquido'] = $values['line_total']; 686 687 if($settings['backend']['includeTaxonSendCost']=="true"){ 688 $ftProducts[$key]['etiliquido'] = $values['line_total'] + $values['line_tax']; 689 } 690 $key++; 691 } 692 693 //fulfill "prodpack" with all data 694 $ftproductPack = $ftProducts; 695 696 //$this->logs->writeFileLog('prodPackft', $ftproductPack); 697 698 return $ftproductPack; 642 699 } 643 644 # get ft product ref & design 645 foreach ($ftProducts as &$product) { 646 if($product['qtt']*$product['epv'] != 0){ 647 # get product ref & design 648 global $wpdb; 649 $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'])); 650 $getproducttype = wc_get_product($product_id); 651 $typeproduct = $getproducttype->get_type(); 652 if ($typeproduct == 'variation'){ 653 if ( $product_id ) $wc_prod = new WC_Product_Variation( $product_id ); 654 } 655 else { 656 if ( $product_id ) $wc_prod = new WC_Product( $product_id ); 657 } 658 659 $product['design'] = $wc_prod->get_name(); 660 } 700 701 public function setFtProductsSession($ftProducts){ 702 //Save items of cart 703 $_SESSION['listOfSku'] = []; 704 $_SESSION['listOfQuantity'] = []; 705 $_SESSION['listOfValueItem'] = []; 706 707 foreach( $ftProducts as $ftProduct ) { 708 array_push($_SESSION['listOfSku'], $ftProduct->sku); 709 array_push($_SESSION['listOfQuantity'], $ftProduct->quantity); 710 array_push($_SESSION['listOfValueItem'], $ftProduct->value); 711 } 712 return $ftproductPack; 661 713 } 662 714 663 $items = $order->get_items();664 665 $key=0;666 foreach($items as $item => $values) {667 $ftProducts[$key]['etiliquido'] = $values['line_total'];668 669 if($settings['backend']['includeTaxonSendCost']=="true"){670 $ftProducts[$key]['etiliquido'] = $values['line_total'] + $values['line_tax'];671 }672 $key++;673 }674 675 //fulfill "prodpack" with all data676 $ftproductPack = $ftProducts;677 678 //$this->logs->writeFileLog('prodPackft', $ftproductPack);679 680 return $ftproductPack;681 }682 683 public function setFtProductsSession($ftProducts){684 //Save items of cart685 $_SESSION['listOfSku'] = [];686 $_SESSION['listOfQuantity'] = [];687 $_SESSION['listOfValueItem'] = [];688 689 foreach( $ftProducts as $ftProduct ) {690 array_push($_SESSION['listOfSku'], $ftProduct->sku);691 array_push($_SESSION['listOfQuantity'], $ftProduct->quantity);692 array_push($_SESSION['listOfValueItem'], $ftProduct->value);693 }694 return $ftproductPack;695 }696 697 715 698 716 … … 711 729 $order = new Order(); 712 730 $ft = new Invoice(); 713 731 714 732 #settings data 715 733 $settings->createInvoice = $wooOrder->createInvoice; … … 718 736 $settings->fieldNif = $wooOrder->fieldNif; 719 737 $settings->includeTaxonSendCost = $wooOrder->includeTaxonSendCost; 720 $settings->createExempt Cl = $wooOrder->createExemptCl;738 $settings->createExemptPT = $wooOrder->createExemptPT; 721 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; 722 744 $settings->warehouseOrder = $wooOrder->warehouseOrder; 723 745 $settings->typeOfOrder = $wooOrder->typeOfOrder; … … 756 778 $shipping->shipping_country = $wooOrder->shipping_country; 757 779 $shipping->shipping_value = $wooOrder->shipping_value; 758 759 # customer data 780 781 # customer data 760 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; 761 795 $customer->email = $wooOrder->billing_email; 762 796 $customer->morada = $wooOrder->billing_address_1; … … 768 802 $customer->preco = $wooOrder->productPriceColumn; 769 803 $customer->country = $wooOrder->billing_country; 770 $customer->user_email = $wooOrder->user_email; 771 804 $customer->user_email = $wooOrder->user_email; */ 805 772 806 # order 773 $order->post_Id = $wooOrder->post_ID; 807 $order->post_Id = $wooOrder->post_ID; 774 808 $order->doc_Id = $wooOrder->docId; 775 809 $order->order_Id = $wooOrder->orderId; … … 786 820 $ft->shipping_country = $wooOrder->shipping_country_ft; 787 821 $ft->cart = $ftprodPack; 788 $ft->shipping_name = $wooOrder->ftShipping_name; 822 $ft->shipping_name = $wooOrder->ftShipping_name; 789 823 $ft->shipping_value = $wooOrder->ftShipping_value; 790 824 $ft->fees = $wooOrder->fees_ft; 791 $ft->billing_name = $wooOrder->billing_first_name_ft. " " .$wooOrder->billing_last_name_ft; 825 $ft->billing_name = $wooOrder->billing_first_name_ft. " " .$wooOrder->billing_last_name_ft; 792 826 $ft->billing_email = $wooOrder->billing_email_ft; 793 827 $ft->billing_address_1 = $wooOrder->billing_address_1_ft; … … 812 846 $dataPack->ft = $ft; 813 847 814 848 815 849 //$this->logs->writeFileLog('dataPack', $dataPack); 816 850 817 851 return $dataPack; 818 } 852 } 819 853 } 820 ?>
Note: See TracChangeset
for help on using the changeset viewer.