1// /** 2// * External dependencies 3// */ 4// import { useEffect, useState } from '@wordpress/element'; 5// import { __ } from '@wordpress/i18n'; 6// import apiFetch from '@wordpress/api-fetch'; 7 8// export const Block = ({ checkoutExtensionData }) => { 9 10// //update code 11// jQuery(document).ready(function($){ 12// $(document).on('focus','#aftax-vat-number',function(){ 13// $('.tax_exempt_vat_inner_div').addClass('is-active') 14// }) 15// }) 16 17// let isHandleCheckoxAjaxProcessing = false; 18 19// useEffect(() => { 20// const handleCheckboxDisplay = (billingCountry, billingState) => { 21 22// if (isHandleCheckoxAjaxProcessing) { 23// return; 24// } 25// isHandleCheckoxAjaxProcessing = true; 26 27// jQuery.ajax({ 28// type: 'POST', 29// url: aftax_php_vars.admin_url, 30// dataType: 'json', 31// data: { 32// action: 'aftax_handle_tax_exemption_on_billing_address_checkout_block', 33// nonce: aftax_php_vars.aftax_nonce, 34// aftax_billing_country: billingCountry, 35// aftax_billing_state: billingState, 36// }, 37// success: function(response) { 38 39// if (response.data.status === 'pass') { 40// jQuery('.wp-block-af_vat_tax_exempt_block-tax-exempt').show(); 41 42// jQuery('.wp-block-af_vat_tax_exempt_block-tax-exempt').insertAfter('.wp-block-woocommerce-checkout-order-note-block'); 43 44// if (response.data.exemption_method === 'auto') { 45// refreshCheckoutPage(true); 46// } 47 48// } else { 49// refreshCheckoutPage(false); 50 51// if((is_user_logged_in && enable_message_for_logged_in_user ) || (!is_user_logged_in && enable_message_for_guest_user) ){ 52 53// jQuery('.wp-block-af_vat_tax_exempt_block-tax-exempt').insertAfter('.wp-block-woocommerce-checkout-order-note-block'); 54// jQuery('.wp-block-af_vat_tax_exempt_block-tax-exempt').show(); 55// jQuery('.taxExemptInnerDiv').show(); 56// jQuery('#removeTaxExemptNotification').hide(); 57// } 58// else{ 59// jQuery('.wp-block-af_vat_tax_exempt_block-tax-exempt').hide(); 60// } 61 62// if (jQuery('#tax_exemption_checkbox').is(":checked")) { 63// jQuery('#tax_exemption_checkbox').prop('checked', false); 64// } 65// } 66// }, 67// error: function(error) { 68// console.error('Error:', error); 69// }, 70// complete: function() { 71// setTimeout(function() { 72// if (jQuery('.wp-block-woocommerce-checkout-order-summary-taxes-block').length > 1) { 73// jQuery('.wp-block-woocommerce-checkout-order-summary-taxes-block').not(':first').hide(); 74// } 75// }, 3000); 76// isHandleCheckoxAjaxProcessing = false; 77// } 78// }); 79// }; 80 81// let isHandleVatAjaxProcessing =false; 82 83// const handleVatFieldChange = () =>{ 84 85// if(jQuery('#aftax-vat-number') && jQuery('#aftax-vat-number').length){ 86// var vat_number =jQuery('#aftax-vat-number').val(); 87 88// if(jQuery("#aftax-vat-number").val() != ''){ 89// jQuery('.tax_exempt_vat_inner_div').addClass('is-active') 90// } 91// else{ 92// jQuery('.tax_exempt_vat_inner_div').removeClass('is-active') 93// } 94 95 96// if (isHandleCheckoxAjaxProcessing) { 97// setTimeout(handleVatFieldChange, 1000); 98// return; 99// } 100 101// if('' != vat_number){ 102 103// if (isHandleVatAjaxProcessing) { 104// return; 105// } 106// isHandleVatAjaxProcessing = true; 107 108// jQuery('.wc-block-components-checkout-place-order-button') 109// .prop('disabled', true); 110 111// jQuery.ajax({ 112// type: 'POST', 113// url: aftax_php_vars.admin_url, 114// data: { 115// action: 'aftax_validate_vat_number_checkout_block', 116// aftax_vat_number: vat_number, 117// nonce: aftax_php_vars.nonce, 118// }, 119// success: function(response) { 120 121// if (response.data.status == 'pass') { 122// refreshCheckoutPage(true); 123// setTimeout(function(){ 124// jQuery('#aftax-vat-number').attr('data-validated', '1'); 125// },2000); 126 127// jQuery('#invalidVatNotice').remove(); 128// } 129// else{ 130// jQuery('#aftax-vat-number').attr('data-validated', '0'); 131// refreshCheckoutPage(false); 132 133// if(vat_number != ''){
134// if (jQuery('#invalidVatNotice').length === 0) { 135// jQuery('#main').before( 136// '<div class="wc-block-components-notice-banner is-error" id="invalidVatNotice" role="alert">' + 137// '<div class="wc-block-components-notice-banner__content">' + 138// aftax_php_vars.aftax_invalid_vat_notice + 139// '</div></div>' 140// ); 141// // window.scrollTo(0, 0); 142// window.scrollTo({ 143// top: 0, 144// behavior: 'smooth' 145// }); 146 147// } 148 149// } 150// } 151// }, 152// error: function(error) { 153// // Handle the error if needed 154// }, 155// complete: function() { 156// isHandleVatAjaxProcessing = false; 157// jQuery('.wc-block-components-checkout-place-order-button') 158// .prop('disabled', false); 159// } 160// }); 161// } 162// else{ 163// refreshCheckoutPage(false); 164// jQuery('#invalidVatNotice').remove(); 165// } 166// } 167 168 169// }; 170 171// wp.hooks.addAction('experimental__woocommerce_blocks-checkout-set-billing-address', 'a-cm-cart-block', triggerChangeEvent); 172 173// function triggerChangeEvent(){ 174// bindEventsAndDisplay(); 175// } 176 177// const bindEventsAndDisplay = () => { 178 179 180// if(jQuery('#billing-country') && jQuery('#billing-country').length){ 181// jQuery(document).on('change','billing-country',function(){ 182// showHideEUOnly(jQuery('#billing-country').val()); 183// handleCheckboxDisplay(jQuery(this).val(), jQuery('#billing-state').val()); 184// handleVatFieldChange(); 185 186// }); 187 188 189// jQuery(document).on('change','#billing-state',function(){ 190// handleCheckboxDisplay(jQuery('#billing-country').val(), jQuery(this).val()); 191// }) 192 193// jQuery(document).on('input','#billing-company',function(){ 194// showHideEUOnly(jQuery('#billing-country').val()); 195// }); 196 197// jQuery(document).on('blur', '#aftax-vat-number', function(){ 198// handleVatFieldChange(); 199// }) 200// handleCheckboxDisplay(jQuery('#billing-country').val(), jQuery('#billing-state').val()); 201// showHideEUOnly(jQuery('#billing-country').val()); 202 203 204// } 205// else{ 206// jQuery(document).on('change','#shipping-country',function(){ 207// showHideEUOnly(jQuery('#shipping-country').val()); 208// handleVatFieldChange(); 209// handleCheckboxDisplay(jQuery(this).val(), jQuery('#shipping-state').val()); 210 211// }); 212 213 214// jQuery(document).on('change','#shiping-state',function(){ 215// handleCheckboxDisplay(jQuery('#shipping-country').val(), jQuery(this).val()); 216// }) 217 218// jQuery(document).on('input','#shipping-company',function(){ 219// showHideEUOnly(jQuery('#shipping-country').val()); 220// }); 221 222// jQuery(document).on('blur', '#aftax-vat-number', function(){ 223// handleVatFieldChange(); 224// }) 225 226// handleCheckboxDisplay(jQuery('#shipping-country').val(), jQuery('#shipping-state').val()); 227// showHideEUOnly(jQuery('#shipping-country').val()); 228 229// } 230 231// handleVatFieldChange(); 232// }; 233 234// setTimeout(function(){ 235// jQuery('.wc-block-checkout__use-address-for-billing input[type="checkbox"]').on('change', function () { 236// bindEventsAndDisplay(); 237 238// }); 239// },500); 240 241// setTimeout(bindEventsAndDisplay, 1000); 242 243 244// }, []); 245 246 247// function showHideEUOnly(countryName) { 248 249// var eu = ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'ES', 'SE', 'GB']; 250// if (eu.indexOf(countryName) != -1 ) { 251// if(jQuery('.aftax_dependable') && jQuery('.aftax_dependable').length>0){ 252 253// if(jQuery('.wc-block-checkout__use-address-for-billing').length && !jQuery('.wc-block-checkout__use-address-for-billing input[type="checkbox"]').is(':checked')){ 254// if(jQuery('#billing-company')&& jQuery('#billing-company').length){ 255// if(jQuery('#billing-company') && jQuery('#billing-company').val().length >0){ 256// jQuery('.aftax-eu-only').show(); 257// jQuery('.aftax-eu-only').insertAfter( 258// '.wp-block-woocommerce-checkout-order-note-block' 259// ); 260// } 261// else{ 262// jQuery('.aftax-eu-only').hide(); 263// setVatNumber(''); 264// } 265// } 266// }
267// else if(jQuery('.wc-block-checkout__use-address-for-billing') && jQuery('.wc-block-checkout__use-address-for-billing').length && jQuery('.wc-block-checkout__use-address-for-billing input[type="checkbox"]').is(':checked')){ 268// if(jQuery('#shipping-company')&& jQuery('#shipping-company').length){ 269// if(jQuery('#shipping-company') && jQuery('#shipping-company').val().length >0){ 270// jQuery('.aftax-eu-only').show(); 271// jQuery('.aftax-eu-only').insertAfter( 272// '.wp-block-woocommerce-checkout-order-note-block' 273// ); 274// } 275// else{ 276// jQuery('.aftax-eu-only').hide(); 277// setVatNumber(''); 278 279// } 280// } 281// } 282// } 283// else{ 284// jQuery('.aftax-eu-only').show(); 285// jQuery('.aftax-eu-only').insertAfter( 286// '.wp-block-woocommerce-checkout-order-note-block' 287// ); 288// } 289// } 290// else { 291 292// jQuery('.aftax-eu-only').hide(); 293// setVatNumber(''); 294// // jQuery('body').trigger('update_checkout'); 295 296// } 297// } 298 299// const aftax_vat_filed_label = aftax_php_vars.vat_field_label; 300// const dependable_class_name = aftax_php_vars.dependable_class_name; 301// const aftax_vat_number_block = aftax_php_vars.aftax_vat_number_block; 302 303// const is_user_logged_in = aftax_php_vars.is_user_logged_in; 304// const enable_checkbox_for_logged_in_user = aftax_php_vars.enable_checkbox_for_logged_in_user; 305// const enable_message_for_logged_in_user = aftax_php_vars.enable_message_for_logged_in_user; 306// const enable_vat_for_logged_in_user = aftax_php_vars.enable_vat_for_logged_in_user; 307// const enable_checkbox_for_guest_user = aftax_php_vars.enable_checkbox_for_guest_user; 308// const enable_message_for_guest_user = aftax_php_vars.enable_message_for_guest_user; 309// const enable_vat_for_guest_user = aftax_php_vars.enable_vat_for_guest_user; 310// const aftax_guest_message = aftax_php_vars.aftax_guest_message; 311// const aftax_logged_in_user_message = aftax_php_vars.aftax_logged_in_user_message; 312 313// const aftax_translation_tax_exempt_message = aftax_php_vars.aftax_translation_tax_exempt_message; 314// const aftax_translation_tax_exempt_heading = aftax_php_vars.aftax_translation_tax_exempt_heading; 315// const aftax_translation_tax_exempt_notification = aftax_php_vars.aftax_translation_tax_exempt_notification; 316// const aftax_currency_symbol_data = aftax_php_vars.aftax_currency_symbol_data; 317 318 319 320 321 322// jQuery(document).ready(function () { 323// if ( 324// is_user_logged_in && enable_message_for_logged_in_user 325// ) { 326// jQuery('.taxExemptInnerDiv').html( 327// '<div class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox wc-block-components-checkout-step__container">' + 328// aftax_logged_in_user_message + 329// '</div>' 330// ); 331// } else if ( 332// !is_user_logged_in && enable_message_for_guest_user 333// ) { 334// jQuery('.taxExemptInnerDiv').html( 335// '<div class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox wc-block-components-checkout-step__container">' + 336// aftax_guest_message + 337// '</div>' 338// ); 339// } 340// }); 341 342 343// const { setExtensionData } = checkoutExtensionData; 344 345// const [vatNumber, setVatNumber] = useState(aftax_vat_number_block); 346 347 348 349// const [taxExemptCheckboxIsChecked, setTaxExemptCheckboxIsChecked] =useState(false); 350 351// const handleCheckboxChange = (event) => { 352// const isChecked = event.target.checked; 353 354// const stringValue = isChecked ? 'checked' : 'not checked'; 355 356// var billing_country = ''; 357// var billing_state = ''; 358 359// setTimeout(function(){ 360// //billing 361// if(jQuery('.wc-block-checkout__use-address-for-billing') && jQuery('.wc-block-checkout__use-address-for-billing').length && !jQuery('.wc-block-checkout__use-address-for-billing input[type="checkbox"]').is(':checked')){ 362// billing_country = jQuery('#billing-country').val(); 363// billing_state = jQuery('#billing-state').val(); 364// } 365// //shipping
366// else if(jQuery('.wc-block-checkout__use-address-for-billing') && jQuery('.wc-block-checkout__use-address-for-billing').length && jQuery('.wc-block-checkout__use-address-for-billing input[type="checkbox"]').is(':checked')){ 367// billing_country = jQuery('#shipping-country').val(); 368// billing_state = jQuery('#shipping-state').val(); 369// } 370 371 372// jQuery.ajax({ 373// type: 'POST', 374// url: aftax_php_vars.admin_url, 375// data: { 376// action: 'set_tax_exempt_val', 377// af_tax_checkbox_is_checked: stringValue, 378// nonce: aftax_php_vars.nonce, 379// billing_country:billing_country, 380// billing_state:billing_state 381// }, 382// success: function (response) { 383// if (response.data.status === 'pass') { 384// refreshCheckoutPage(); 385// } 386 387// }, 388// error: function (error) {}, 389// }); 390 391// },100); 392 393 394 395// }; 396 397// useEffect(() => { 398// setExtensionData( 399// 'af_vat_tax_exempt_block', 400// 'addifyIsTaxExemptChecked', 401// taxExemptCheckboxIsChecked 402// ); 403 404// //trigger checkbox on page load so that tax is added if it removed before 405// if(jQuery('#tax_exemption_checkbox') && jQuery('#tax_exemption_checkbox').length){ 406// handleCheckboxChange({ target: { checked: jQuery('#tax_exemption_checkbox').checked } }); 407// } 408 409 410// }, [setExtensionData, taxExemptCheckboxIsChecked]); 411 412 413 414 415// function makePriceFormatable(value){ 416// var value = value.toString(); 417// var decimal_position = value.length - aftax_currency_symbol_data.aftax_num_decimals; 418 419// if(decimal_position != value.length){ 420// value = value.slice(0, decimal_position) + "." + value.slice(decimal_position); 421// }else{ 422// value = value; 423// } 424 425// //thousand seperator 426// let parts = value.toString().split("."); 427// parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, aftax_currency_symbol_data.aftax_thousand_sep); 428// value = parts.join("."); 429 430// var value_with_currency_symbol; 431// switch (aftax_currency_symbol_data.aftax_currency_pos) { 432// case 'left': 433// value_with_currency_symbol = `${aftax_currency_symbol_data.aftax_currency_symbol}${value}`; 434// break; 435// case 'right': 436// value_with_currency_symbol = `${value}${aftax_currency_symbol_data.aftax_currency_symbol}`; 437// break; 438// case 'left_space': 439// value_with_currency_symbol = `${aftax_currency_symbol_data.aftax_currency_symbol} ${value}`; 440// break; 441// case 'right_space': 442// value_with_currency_symbol = `${value} ${aftax_currency_symbol_data.aftax_currency_symbol}`; 443// break; 444// default: 445// value_with_currency_symbol = `${aftax_currency_symbol_data.aftax_currency_symbol}${value}`; 446// } 447 448// return value_with_currency_symbol.toString().replace('.', aftax_currency_symbol_data.aftax_decimal_sep) 449// } 450 451 452// function refreshCheckoutPage(refresh_anyway = false){ 453// jQuery('.wc-block-components-totals-footer-item') 454// .find('.wc-block-components-totals-item__value') 455// .each(function () { 456// apiFetch({ path: '/wc/store/v1/cart' }).then( 457// (posts) => { 458 459// jQuery(this).text(makePriceFormatable(posts.totals.total_price)); 460 461 462// if (jQuery('#tax_exemption_checkbox').is(':checked') || refresh_anyway) { 463 464// var findtaxesBlocks = jQuery( 465// '.wp-block-woocommerce-checkout-order-summary-taxes-block' 466// ); 467 468// if (findtaxesBlocks.length > 1) { 469// // findtaxesBlocks.first().remove(); 470// findtaxesBlocks.first().hide(); 471// } 472 473// if (jQuery('#removeTaxExemptNotification') && jQuery('#removeTaxExemptNotification').length === 0) { 474 475// jQuery('#main').before( 476// '<div class="wc-block-components-notice-banner is-info" id="removeTaxExemptNotification" role="alert">' + 477// '<div class="wc-block-components-notice-banner__content">' + 478// aftax_translation_tax_exempt_notification + 479// '</div></div>' 480// ); 481// // window.scrollTo(0, 0); 482// if(jQuery('#tax_exemption_checkbox').is(':checked')){ 483// window.scrollTo({ 484// top: 0, 485// behavior: 'smooth' 486// }); 487// } 488 489// if('1' != jQuery('#aftax-vat-number').attr('data-validated')){ 490// window.scrollTo({ 491// top: 0, 492// behavior: 'smooth' 493// }); 494// } 495 496// } 497 498// jQuery( 499// '.wp-block-woocommerce-checkout-order-summary-taxes-block' 500// ).hide(); 501// } else { 502// jQuery( 503// '#removeTaxExemptNotification' 504// ).remove(); 505 506// var taxesBlock = jQuery(document).find( 507// '.wp-block-woocommerce-checkout-order-summary-taxes-block' 508// ); 509 510// if (!(taxesBlock.length > 0)) { 511 512// jQuery( 513// '.wp-block-woocommerce-checkout-order-summary-taxes-block' 514// ).hide(); 515 516// var innerTaxDiv = 517// '<div class="wp-block-woocommerce-checkout-order-summary-taxes-block wc-block-components-totals-wrapper">'; 518 519
520// posts.totals.tax_lines.forEach( 521// function (taxLine) { 522// innerTaxDiv += 523// '<div class="wc-block-components-totals-item wc-block-components-totals-taxes"><span class="wc-block-components-totals-item__label">' + 524// taxLine.name + 525// '</span><span class="wc-block-formatted-money-amount wc-block-components-formatted-money-amount wc-block-components-totals-item__value">' + 526// makePriceFormatable(taxLine.price) + 527// '</span><div class="wc-block-components-totals-item__description"></div></div>'; 528 529// } 530// ); 531// innerTaxDiv += '</div>'; 532 533// if(jQuery('.wp-block-woocommerce-checkout-order-summary-shipping-block') && jQuery('.wp-block-woocommerce-checkout-order-summary-shipping-block').length){ 534// jQuery( 535// '.wp-block-woocommerce-checkout-order-summary-shipping-block' 536// ).after(innerTaxDiv); 537// } 538// else{ 539// jQuery( 540// '.wp-block-woocommerce-checkout-order-summary-totals-block' 541// ).after(innerTaxDiv); 542// } 543// } else { 544// jQuery( 545// '.wp-block-woocommerce-checkout-order-summary-taxes-block' 546// ).show(); 547// } 548// } 549// } 550// ); 551// }); 552 553// } 554 555// const aftaxVatNumberChange = (e) => { 556// const { id, value } = e.target; 557// setVatNumber(value); 558// }; 559 560 561// return ( 562// <> 563// {((is_user_logged_in && (enable_checkbox_for_logged_in_user || enable_message_for_logged_in_user)) || (!is_user_logged_in && (enable_checkbox_for_guest_user || enable_message_for_guest_user))) ? ( 564 565// <div className="wc-block-components-checkout-step wc-block-components-checkout-step--with-step-number wp-block-af_vat_tax_exempt_block-tax-exempt" 566// style={{ display: "none", marginBottom: "10px" }} 567// > 568// <div className="wc-block-components-checkout-step__container"> 569// <div className="wc-block-components-checkout-step__heading"> 570// <h2 571// className="wc-block-components-title wc-block-components-checkout-step__title" 572// aria-hidden="true" 573// > 574// {aftax_translation_tax_exempt_heading} 575// </h2> 576// </div> 577// <div className="wc-block-components-checkout-step__content"> 578// <div className="taxExemptInnerDiv"> 579// <div className="wc-block-components-checkbox"> 580// {((is_user_logged_in && enable_checkbox_for_logged_in_user) || (!is_user_logged_in && enable_checkbox_for_guest_user)) ? ( 581 582// <label htmlFor="tax_exemption_checkbox"> 583// <input 584// className="wc-block-components-checkbox__input woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" 585// id="tax_exemption_checkbox" 586// type="checkbox" 587// name="tax_exemption_checkbox" 588// onChange={handleCheckboxChange} 589// /> 590// <svg 591// className="wc-block-components-checkbox__mark" 592// aria-hidden="true" 593// xmlns="http://www.w3.org/2000/svg" 594// viewBox="0 0 24 20" 595// > 596// <path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"></path> 597// </svg> 598// <span className="wc-block-components-checkbox__label"> 599// {aftax_translation_tax_exempt_message} 600// </span> 601// </label> 602// ) : null} 603// </div> 604// </div> 605// </div> 606// </div> 607// </div> 608 609 610 611// ) : null} 612 613 614// {((is_user_logged_in && enable_vat_for_logged_in_user) || (!is_user_logged_in && enable_vat_for_guest_user)) ? ( 615// <fieldset 616// className={`wc-block-components-checkout-step wc-block-components-checkout-step--with-step-number wp-block-af_vat_tax_exempt aftax-eu-only ${dependable_class_name}`} 617// style={{ display: 'none' }} 618// > 619 620// <div className="wc-block-components-text-input tax_exempt_vat_inner_div"> 621// <input type="text" 622// id="aftax-vat-number" 623// value={vatNumber} 624// onChange = {aftaxVatNumberChange} 625// /> 626// <label htmlFor="vat-number">{aftax_vat_filed_label}</label> 627// </div> 628// </fieldset> 629// ) : null} 630 631// </> 632 633// ); 634// }; 635 636 637 638 639
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.