1/** 2 * NOTICE OF LICENSE 3 * 4 * This file is licenced under the Software License Agreement. 5 * With the purchase or the installation of the software in your application 6 * you accept the licence agreement. 7 * 8 * You must not modify, adapt or create derivative works of this source code 9 * 10 * @author Ilenia Amadori <[email protected]> 11 * @copyright Copyright (c) 2018 Studio ITC Srl - www.studioitc.com 12 * @license You only can use module, nothing more! 13 */ 14 15 16$(document).ready(function () { 17 18 prestashop.on('updatedAddressForm', function (event) { 19 var respHtml = new DOMParser().parseFromString(event.resp.address_form, "text/html"); 20 var needDni = respHtml.getElementsByName('need_dni')[0].value; 21 $('input[name=need_dni]').val(needDni); 22 //document.querySelectorAll('input[value="private"]').attr("checked", true); 23 24 alertAddressNotComplete(); 25 26 initJSAddress(); 27 }); 28 alertAddressNotComplete(); 29 initJSAddress(); 30}); 31// 32// Alert message in if not exists El invoice data for address customer 33// 34 35function alertAddressNotComplete() { 36 if (typeof show_warning_info !== "undefined" && show_warning_info) { 37 if ($('body').attr("id") === "addresses") { 38 console.log($('body').attr("id")); 39 $('#content').before('<div class="alert alert-danger">' + show_warning_text + '</div>'); 40 } 41 else if ($('body').attr("id") === "checkout") { 42 $('#delivery-addresses').before('<div class="alert alert-danger">' + show_warning_text + '</div>'); 43 $('#invoice-addresses').before('<div class="alert alert-danger">' + show_warning_text + '</div>'); 44 } 45 } 46} 47 48function initJSAddress() { 49 50 if (($('body').attr("id") === "address") || ($('body').attr("id") === "checkout") || ($('body').attr("id") === "authentication")) { 51 52 let type_address = $('input[name=type_address]'); 53 let value_type_address = $('input[name=value_type_address]'); 54 let enable_private = $('input[name=enable_private]').val(); 55 let enable_business = $('input[name=enable_business]').val(); 56 let enable_pubadm = $('input[name=enable_pubadm]').val(); 57 let enable_association = $('input[name=enable_association]').val(); 58 let val = []; 59 60 if (enable_private == 1) { 61 val.push("private"); 62 } 63 if (enable_business == 1) { 64 val.push("business"); 65 } 66 if (enable_pubadm == 1) { 67 val.push("pubadm"); 68 } 69 if (enable_association == 1) { 70 val.push("association"); 71 } 72 let count = 0; 73 74 $(type_address).each(function () { 75 $(this).val(val[count++]); 76 }); 77 78 if (value_type_address.val() == '') { 79 type_address.filter('[value=private]').prop('checked', true); 80 value_type_address.val("private"); 81 } 82 if (value_type_address.val() == 'business') { 83 type_address.filter('[value=business]').prop('checked', true); 84 } else if (value_type_address.val() == 'private') { 85 type_address.filter('[value=private]').prop('checked', true); 86 } else if (value_type_address.val() == 'pubadm') { 87 type_address.filter('[value=pubadm]').prop('checked', true); 88 } else if (value_type_address.val() == 'association') { 89 type_address.filter('[value=association]').prop('checked', true); 90 } 91 92 setFieldsTypeAddress(value_type_address); 93 94 type_address.on('change', function () { 95 value_type_address.val($(this).val()); 96 setFieldsTypeAddress(value_type_address); 97 }); 98 $("form").submit(function (e) { 99 if ($('select[name=id_country]').val() === $('input[name=id_ita]').val()) { 100 var valid = true; 101 if (!$('input[name=sdi_code]').val() == '') { 102 103 let result_SDI = ControllaSDI($('input[name=sdi_code]').val(), value_type_address.val()); 104 if (result_SDI !== '') { 105 if (value_type_address.val() === 'business' || value_type_address.val() === 'association') { 106 notifyError($('input[name=sdi_code]'), "Questo campo non è valido per la t
106ipologia di indirizzo scelta"); 107 valid = false; 108 } else if (value_type_address.val() === 'pubadm') { 109 notifyError($('input[name=sdi_code]'), "Questo campo non è valido per la tipologia di indirizzo scelta"); 110 valid = false; 111 } 112 } 113 } 114 // Italian DNI Validity 115 116 if (valid && !$('input[name=dni]').is('[value=""]')) { 117 let result_CF = ControllaCF($('input[name=dni]').val(), value_type_address.val()); 118 if (result_CF !== '') { 119 notifyError($('input[name=dni]'), errorDni); 120 valid = false; 121 } 122 } 123 // Italian Vat Validity 124 125 if (valid && !$('input[name=vat_number]').is('[value=""]')) { 126 let result_PIVA = ControllaPIVA($('input[name=vat_number]').val()); 127 if (result_PIVA !== '') { 128 notifyError($('input[name=vat_number]'), errorVat); 129 valid = false; 130 } 131 } 132 if (!valid) { 133 134 e.preventDefault(); 135 } 136 return valid; 137 } 138 }); 139 } 140} 141 142function notifyError(inputEl, msg) { 143 144 inputEl.focus(); 145// Italian SDI Validity 146 147 148 inputEl.popover({ 149 placement: 'right', 150 trigger : 'manual', 151 html : true, 152 content : msg 153 }); 154 inputEl.popover('show'); 155 setTimeout(function () { 156 inputEl.popover('hide'); 157 }, 10000); 158} 159 160function setFieldsTypeAddress(value_type_address) { 161 let dni = $('input[name=dni]').parent('div').parent('div.form-group'); 162 let company = $('input[name=company]').parent('div').parent('div.form-group'); 163 let vat_number = $('input[name=vat_number]').parent('div').parent('div.form-group'); 164 let pec = $('input[name=email_pec]').parent('div').parent('div.form-group'); 165 let sdi = $('input[name=sdi_code]').parent('div').parent('div.form-group'); 166 let enable_only_business = $('input[name=enable_only_business]').val(); 167 let enable_type_address_all = $('input[name=enable_type_address_all]').val(); 168 let requested_vat_ita = $('input[name=requested_vat_ita]').val(); 169 let requested_company_ita = $('input[name=requested_company_ita]').val(); 170 let id_country = $('select[name=id_country]').val(); 171 let id_itc = $('input[name=id_ita]').val(); 172 let manage_dni = $('input[name=manage_dni]').val(); 173 let need_dni = $('input[name=need_dni]').val(); 174 175 if (value_type_address.val() === 'private') { 176 177 if ((enable_only_business == 0) && (id_country == id_itc)) { 178 pec.css("display", "block"); 179 sdi.css("display", "block"); 180 181 } 182 else { 183 184 // PEC 185 pec.find('label').removeAttr("required"); 186 pec.find('input').removeAttr("required"); 187 pec.find('input').val(""); 188 pec.find('input').attr('value', ''); 189 pec.css("display", "none"); 190 191 // SDI 192 sdi.find('label').removeAttr("required"); 193 sdi.find('input').removeAttr("required"); 194 sdi.find('input').val(""); 195 sdi.find('input').attr('value', ''); 196 sdi.css("display", "none"); 197 } 198 199 // DNI 200 if (manage_dni) { 201 dni.css("display", "block"); 202 203 if (need_dni == 1) { 204 dni.find("div.form-control-comment").css("display", "none"); 205 dni.find('label').attr("required", true); 206 dni.find('input').attr("required", true); 207 } 208 else { 209 dni.find("div.form-control-comment").val('Opzionale'); 210 dni.find("div.form-control-comment").css("display", "block"); 211 dni.find('label').removeAttr("required"); 212 dni.find('input').removeAttr("required"); 213 } 214 } 215 216 // COMPANY 217 company.find('label').removeAttr("required"); 218 company.find('input').removeAttr("required"); 219 company.find('input').val(""); 220 company.find('input').attr('value', ''); 221 company.css("display", "none"); 222 223 // VAT 224 vat_number.find('label').removeAttr("required"); 225 vat_number.find('input').removeAttr("required"); 226 vat_number.find('input').val(""); 227 vat_number.find('input').attr('value', ''); 228 vat_number.css("display", "none"); 229 230 } else if (value_type_address.val() === 'business' || value_type_address.val() === 'pubadm') { 231 if (id_country == id_itc) { 232 // Comment pre box pec/SDI 233 pec.find("div.itc-comment-box").remove(); 234 let text = pec.html(); 235 let newText = '<div class="itc-comment-box col-md-12" style="margin-bottom:20px;">'; 236 if ($('body').attr("id") === "checkout") { 237 newText += '<div style="color: red;" class="itc-comment col-md-12"'; 238 } else if ($('body').attr("id") === "address") { 239 newText += '<div style="color: red;" class="itc-comment col-md-8 offset-md-2"'; 240 } 241 newText += '>'; 242 newText += 'Per l\'invio della fattura elettronica è necessario indicare il canale di ricezione: Pec e/o codice SDI. Per le aziende che non specificano la Pec, lasciando i sette zeri (0000000), la fattura verrà recapitata nel proprio cassetto fiscale e sarà scaricabile dal sito dell\'Agenzia delle Entrate. Nel caso di Pubblica Amministrazione è obbligatorio il codice SDI di 6 caratteri alfanumerici.'; 243 newText += '</div></div>'; 244 newText += text; 245 pec.html(newText); 246 247 // PEC 248 pec.css("display", "block"); 249 250 // SDI 251 sdi.css("display", "block"); 252 sdi.find('label').attr("required", true); 253 sdi.find('input').attr("required", true); 254 sdi.find("div.form-control-comment").css("display", "none"); 255 if (value_type_address.val() === 'business') { 256 if (sdi.find('input')) { 257 var inputVal = sdi.find('input').val(); 258 if (inputVal.trim() === '') { 259 sdi.find('input').val('0000000'); 260 } 261 } 262 } else if (value_type_address.val() === 'pubadm') { 263 if (sdi.find('input')) { 264 var inputVal = sdi.find('input').val(); 265 if (inputVal.trim() === '0000000') { 266 sdi.find('input').val(''); 267 } 268 } 269 } 270 271 sdi.focusout(function () { 272 if (sdi.find('input')) { 273 var inputVal = sdi.find('input').val(); 274 if (inputVal.trim() === '') { 275 if (value_type_address.val() === 'business') { 276 sdi.find('input').val('0000000'); 277 } 278 } 279 } 280 }); 281 282 // COMPANY 283 if (requested_company_ita == 1 || enable_type_address_all) { 284 company.find('label').attr("required", true); 285 company.find('input').attr("required", true); 286 company.find("div.form-control-comment").css("display", "none"); 287 } else { 288 company.find('label').removeAttr("required"); 289 company.find('input').removeAttr("required"); 290 company.find('input').val(""); 291 company.find('input').attr('value', ''); 292 company.find("div.form-control-comment").css("display", "block"); 293 } 294 company.css("display", "block"); 295 296 // VAT 297 if (requested_vat_ita == 1 || enable_type_address_all) { 298 vat_number.find('label').attr("required", true); 299 vat_number.find('input').attr("required", true); 300 vat_number.find("div.form-control-comment").css("display", "none"); 301 } else { 302 vat_number.find('label').removeAttr("required"); 303 vat_number.find('input').removeAttr("required"); 304 vat_number.find('input').val(""); 305 vat_number.find('input').attr('value', ''); 306 vat_number.find("div.form-control-comment").css("display", "block"); 307 } 308 vat_number.css("display", "block"); 309 } else { 310 // PEC 311 pec.find('label').removeAttr("required"); 312 pec.find('input').removeAttr("required"); 313 pec.find('input').val(""); 314 pec.find('input').attr('value', ''); 315 pec.css("display", "none"); 316 317 // SDI 318 sdi.find('label').removeAttr("required"); 319 sdi.find('input').removeAttr("required"); 320 sdi.find('input').val(""); 321 sdi.find('input').attr('value', ''); 322 sdi.css("display", "none"); 323 324 // COMPANY 325 company.find('label').removeAttr("required"); 326 company.find('input').removeAttr("required"); 327 company.find('input').val(""); 328 company.find('input').attr('value', ''); 329 company.find("div.form-control-comment").css("display", "block"); 330 company.css("display", "block"); 331 332 // VAT 333 vat_number.find('label').removeAttr("required"); 334 vat_number.find('input').removeAttr("required"); 335 vat_number.find('input').val(""); 336 vat_number.find('input').attr('value', ''); 337 vat_number.find("div.form-control-comment").css("display", "block"); 338 vat_number.css("display", "block"); 339 } 340 341 if (manage_dni) { 342 dni.find("div.form-control-comment").val('Opzionale'); 343 dni.find("div.form-control-comment").css("display", "block"); 344 dni.find('label').removeAttr("required"); 345 dni.find('input').removeAttr("required"); 346 } 347 } else if (value_type_address.val() === 'association') { 348 if (id_country == id_itc) { 349 // PEC 350 pec.find("div.itc-comment-box").remove(); 351 pec.css("display", "block"); 352 // SDI 353 sdi.css("display", "block"); 354 sdi.find('label').attr("required", false); 355 sdi.find('input').attr("required", false); 356 sdi.find("div.form-control-comment").css("display", "block"); 357 if (sdi.find('input')) { 358 var inputVal = sdi.find('input').val(); 359 if (inputVal !== 'undefined' && inputVal.trim() === '') { 360 sdi.find('input').val('0000000'); 361 } 362 } 363 } 364 // COMPANY 365 company.find('label').attr("required", true); 366 company.find('input').attr("required", true); 367 company.find('input').val(""); 368 company.find('input').attr('value', ''); 369 company.find("div.form-control-comment").css("display", "block"); 370 company.css("display", "block"); 371 // VAT 372 vat_number.find('label').removeAttr("required"); 373 vat_number.find('input').removeAttr("required"); 374 vat_number.find('input').val(""); 375 vat_number.find('input').attr('value', ''); 376 vat_number.find("div.form-control-comment").css("display", "block"); 377 vat_number.css("display", "block"); 378 379 // DNI REQUIRED FOR ASSOCIATION 380 dni.find("div.form-control-comment").css("display", "none"); 381 dni.find('label').attr("required", true); 382 dni.find('input').attr("required", true); 383 384 } else { 385 // PEC 386 pec.find('label').removeAttr("required"); 387 pec.find('input').removeAttr("required"); 388 pec.find('input').val(""); 389 pec.find('input').attr('value', ''); 390 pec.css("display", "none"); 391 392 // SDI 393 sdi.find('label').removeAttr("required"); 394 sdi.find('input').removeAttr("required"); 395 sdi.find('input').val(""); 396 sdi.find('input').attr('value', ''); 397 sdi.css("display", "none"); 398 399 // COMPANY 400 company.find('label').removeAttr("required"); 401 company.find('input').removeAttr("required"); 402 company.find('input').val(""); 403 company.find('input').attr('value', ''); 404 company.css("display", "none"); 405 406 // VAT 407 vat_number.find('label').removeAttr("required"); 408 vat_number.find('input').removeAttr("required"); 409 vat_number.find('input').val(""); 410 vat_number.find('input').attr('value', ''); 411 vat_number.css("display", "none"); 412 } 413} 414 415/** 416 * @return {string} 417 */ 418function ControllaCF(cf, type_addr) { 419 if (typeof cf !== "undefined") { 420 if (!type_addr == 'association' && type_addr == 'private') { 421 let i; 422 cf = cf.toUpperCase(); 423 let set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 424 let set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ"; 425 let setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 426 let setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX"; 427 let s = 0; 428 for (i = 1; i <= 13; i += 2) { 429 s += setpari.indexOf(set2.charAt(set1.indexOf(cf.charAt(i)))); 430 } 431 for (i = 0; i <= 14; i += 2) { 432 s += setdisp.indexOf(set2.charAt(set1.indexOf(cf.charAt(i)))); 433 } 434 if (s % 26 !== cf.charCodeAt(15) - 'A'.charCodeAt(0)) { 435 return "Il codice fiscale non risulta corretto."; 436 } 437 return ""; 438 } 439 else { 440 if (type_addr == 'association' && cf.length != 11) { 441 return "Il codice fiscale non risulta corretto."; 442 } 443 return ""; 444 } 445 } else { 446 return ""; 447 } 448} 449 450/** 451 * @return {string} 452 */ 453function ControllaPIVA(pi) { 454 if (typeof pi !== "undefined") { 455 let i; 456 let s = 0; 457 for (i = 0; i <= 9; i += 2) { 458 s += pi.charCodeAt(i) - '0'.charCodeAt(0); 459 } 460 let c; 461 for (i = 1; i <= 9; i += 2) { 462 c = 2 * ( pi.charCodeAt(i) - '0'.charCodeAt(0) ); 463 if (c > 9) { 464 c = c - 9; 465 } 466 s += c; 467 } 468 if (( 10 - s % 10 ) % 10 !== pi.charCodeAt(10) - '0'.charCodeAt(0)) { 469 return "La partita IVA non risulta valida."; 470 } 471 return ''; 472 } else { 473 return ''; 474 } 475} 476 477 478/** 479 * @return {string} 480 */ 481function ControllaSDI(sdi, type_addr) { 482 if (typeof sdi !== "undefined") { 483 if (type_addr === 'business' || type_addr === 'association') { 484 if (sdi.length == 7) { 485 if (/^[0-9A-z]+$/.test(sdi)) { 486 return ''; 487 } else {
488 return "Questo campo non è valido per la tipologia di indirizzo scelta"; 489 } 490 } else { 491 return "Questo campo non è valido per la tipologia di indirizzo scelta"; 492 } 493 } else if (type_addr === 'pubadm') { 494 if (sdi.length == 6) { 495 if (/^[0-9A-z]+$/.test(sdi)) { 496 return ''; 497 } else { 498 return "Questo campo non è valido per la tipologia di indirizzo scelta"; 499 } 500 } else { 501 return "Questo campo non è valido per la tipologia di indirizzo scelta"; 502 } 503 } 504 } else { 505 return ''; 506 } 507} 508
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.