1ACC.returnorderaction = { 2 3 _autoload: [ 4 ["returnOrderForm", $("#submitreturnorderform").length > 0] 5 ], 6 7 returnOrderForm: function () { 8 const SELECTION_TYPE = { 9 PDR_LEVEL: 'PDR_LEVEL', 10 CASE_LEVEL: 'CASE_LEVEL', 11 PART_LEVEL: 'PART_LEVEL', 12 }; 13 const noConsignmentInfoCases = ['MC', 'S']; // Return Reasons which don't require consignment information 14 const customHandledReturnReasons = ['DT','MC']; // Return Reasons that handled as a whole PDR or as a whole Case Group but not as an individual Part 15 16 const getInputValue = (id) => $(`#${id}`)[0]?.value; 17 18 const $rowEntry = $('.rowEntry'); 19 const $selectAllCheckbox = $('.select-all-checkbox'); 20 const $caseNumberCheckboxes = $('.returnorderform-checkbox'); 21 const $productCheckboxes = $('.return-product-checkbox'); 22 const $submitButton = $('#submitreturnorderformvbutton'); 23 const $resetButton = $('#resetreturnorderformvbutton'); 24 const $customFiles = $('.custom-file-upload'); 25 const compulsoryDocumentsJson = $('#compulsoryDocumentsRulesMap')[0]?.value; 26 const compulsoryDocumentsMap = JSON.parse(compulsoryDocumentsJson); 27 const bypassRulesJson = $('#documentsBypassRulesMap')[0]?.value; 28 const bypassRulesMap = JSON.parse(bypassRulesJson); 29 const isBypassInvoice = !!bypassRulesMap.find(rule => rule === 'all'); 30 const bypassMaterials = bypassRulesMap.filter(rule => rule !== 'all'); 31 const maxAllowedUploadsSize = $('#maxAllowedUploadsSize')[0]?.value; 32 const maxAllowedFileSize = $('#maxAllowedFileSize')[0]?.value * 1000000; 33 const allowedFileMimeTypes = $('#allowedFileMimeTypes')[0]?.value; 34 const $errorHint = $('#errorHint'); 35 const returnAutomatedFlowEnabled = $('#returnAutomatedFlowEnabled')[0]?.value === 'true'; 36 let savedFiles; 37 38 ACC.FileValidationService.setupAllowedValues(maxAllowedUploadsSize, maxAllowedFileSize, allowedFileMimeTypes); 39 ACC.returnorderaction.setupFilesErrors(); 40 41 const fileErrorsMap = {}; 42 43 reCalculateBlockedRowsHeight(); 44 45 $(window).resize(function () { 46 reCalculateBlockedRowsHeight(); 47 }); 48 49 $rowEntry.find('.returnableQty').on('change', function () { 50 const $this = $(this); 51 const $closestRowEntry = $this.closest('.rowEntry'); 52 const $cancellationReason = $closestRowEntry.find('.cancellationReasonClass'); 53 if (!$cancellationReason.val()) { 54 addOrRemoveAsterisk($cancellationReason, $this.val() < 1); 55 } 56 if ($this.val() < 1) { 57 addOrRemoveAsterisk($closestRowEntry.find('.returnComments'), true); 58 addOrRemoveAsterisk($closestRowEntry.find('#returnPictureUpload'), true); 59 } 60 checkRowSubmit(); 61 }); 62 63 $rowEntry.find('.returnableQty').on('keyup', function () { 64 const $this = $(this); 65 const $closestRowEntry = $this.closest('.rowEntry'); 66 const $cancellationReason = $closestRowEntry.find('.cancellationReasonClass'); 67 validateReturnableQty($closestRowEntry, +$this.val(), $cancellationReason.val()); 68 }); 69 70 $rowEntry.find('.cancellationReasonClass').on('change', function () { 71 const $this = $(this); 72 const thisVal = $this.val(); 73 const $closestRowEntry = $this.closest('.rowEntry'); 74 const $wrongPartInput = $closestRowEntry.find('.wrongPartMaterialNumber'); 75 76 if (thisVal === 'P') { 77 $wrongPartInput.removeAttr('disabled'); 78 } else { 79 $wrongPartInput.attr('disabled', 'disabled'); 80 } 81 82 adjustMaxReturnableQty($closestRowEntry, thisVal); 83 ACC.FileValidationService.resetAttachments($closestRowEntry, fileErrorsMap); 84 85 if (customHandledReturnReasons.find(reason => reason === thisVal)) { 86 if ($selectAllCheckbox.is(":checked")) { 87 handleCasePartsReset($closestRowEntry); 88 handlePdrSelection(thisVal); 89 toggleFileButtons($rowEntry.first(), thisVal); 90 } else { 91 handleCasePartsReset($closestRowEntry); 92 handleCasePartsSelection($closestRowEntry, thisVal); 93 const [$allCaseParts,] = getRowsInCase($closestRowEntry); 94 toggleFileButtons($allCaseParts.first(), thisVal); 95 } 96 } else { 97 handleCasePartsReset($closestRowEntry); 98 toggleFileButtons($closestRowEntry, thisVal); 99 } 100 101 addOrRemoveAsterisk($closestRowEntry.find('.returnComments'), true); 102 addOrRemoveAsterisk($closestRowEntry.find('#returnPictureUpload'), true); 103 $this.removeClass('focus').blur(); 104 checkRowSubmit(); 105 }); 106 107 $rowEntry.find('.wrongPartMaterialNumber').on('change', function () { 108 checkRowSubmit(); 109 }); 110 111 $selectAllCheckbox.change(function () { 112 const isChecked = $(this).is(':checked'); 113 $.each($caseNumberCheckboxes, (key, caseNumberGroup) => { 114 $(caseNumberGroup).prop('checked', !!isChecked).change(); 115 }); 116 }); 117 118 $caseNumberCheckboxes.change(function () { 119 const $this = $(this); 120 const isChecked = $this.is(':checked'); 121 const groupCaseNumber = $this.attr('data-caseNumber'); 122 123 toggleCaseSelection(groupCaseNumber, isChecked); 124 }); 125 126 $productCheckboxes.change(function () { 127 const $this = $(this); 128 const isChecked = $this.is(':checked'); 129 const $closestRowEntry = $this.closest('.rowEntry'); 130 131 if (isChecked) { 132 $closestRowEntry.removeClass('blocked'); 133 updateGroupSelection($this.attr('data-caseNumber'), isChecked); 134 } else { 135 clearRowData($closestRowEntry); 136 $closestRowEntry.addClass('blocked'); 137 $errorHint.addClass('disabled'); 138 139 const caseHandler = $closestRowEntry.attr('data-case-handler'); 140 if (caseHandler) { 141 enableRowInputs($closestRowEntry, $this); 142 $closestRowEntry.removeAttr('data-case-handler'); 143 144 if (caseHandler === SELECTION_TYPE.CASE_LEVEL) { 145 toggleCaseSelection($this.attr('data-caseNumber'), isChecked); 146 } 147 if (caseHandler === SELECTION_TYPE.PDR_LEVEL) { 148 $caseNumberCheckboxes.each(function () { 149 $(this).prop('readonly', false); 150 }); 151 $selectAllCheckbox.prop('checked', isChecked).change(); 152 } 153 } else { 154 updateGroupSelection($this.attr('data-caseNumber'), isChecked); 155 } 156 } 157 158 const numberChecked = $productCheckboxes.filter(':checked').length; 159 160 if (numberChecked > 0) { 161 checkRowSubmit(); 162 } else { 163 $submitButton.prop('disabled', true); 164 } 165 }); 166 167 $customFiles.on('click', '.file-btn', function () { 168 // Note: Save previously selected files. 169 // It is needed in case when User tries to choose a file but clicks on Cancel. => 170 // It will remove already selected file from the input and such default behavior is incorrect here. 171 savedFiles = this.files; 172 }); 173 174 $customFiles.on('change', '.file-btn', function () { 175 if (!this.files.length) { 176 // User clicked on Cancel.
177 // Input default behavior is to remove current files value. 178 // So, restore pre-saved files. 179 this.files = savedFiles; 180 return; 181 } 182 183 const filesArray = Array.from(this.files); 184 const $errorsContainer = $(this).parent().parent().parent().find('#fileErrorsContainer'); 185 const currAttachmentType = $(this).parent().attr('data-attachmentType'); 186 const rowID = $(this).closest('.rowEntry').attr('id'); 187 188 // Remove existing errors with this type of attachments in this row 189 ACC.FileValidationService.cleanErrorsMap(fileErrorsMap, rowID, currAttachmentType); 190 191 filesArray.forEach((file, index) => { 192 ACC.FileValidationService.validateFile($errorsContainer, fileErrorsMap, index, file, currAttachmentType, rowID); 193 }); 194 195 const names = filesArray.map(item => item ? item.name : ''); 196 ACC.FileValidationService.updateFileLabel($(this), names); 197 checkRowSubmit(); 198 }); 199 200 $customFiles.on('clearAttachments', '.file-btn', function () { 201 ACC.FileValidationService.updateFileLabel($(this), null); 202 }); 203 204 $resetButton.on('click', () => { 205 $.each($rowEntry, (index, entry) => { 206 ACC.FileValidationService.resetAttachments($(entry), fileErrorsMap); 207 }); 208 $selectAllCheckbox.prop('checked', false).change(); 209 $resetButton.blur(); 210 }); 211 212 $submitButton.on('click', function (event) { 213 event.preventDefault(); 214 215 if (!returnAutomatedFlowEnabled) { 216 ACC.returnorderaction.handleReturnOrderFormSubmit(); 217 return; 218 } 219 220 const returnReasons = getSelectedReturnReasons(); 221 const selectedReasonsCounter = returnReasons.size; 222 noConsignmentInfoCases.forEach(item => { 223 returnReasons.delete(item); 224 }); 225 226 if (returnReasons.size) { 227 openConsignmentInfoPopup(returnReasons); 228 } else if (selectedReasonsCounter) { 229 ACC.returnorderaction.handleReturnOrderFormSubmit(); 230 } 231 }); 232 233 function clearRowData($closestRowEntry) { 234 $closestRowEntry.find('input:not([type="file"])').val(''); 235 $closestRowEntry.find('.returnableQty').val('0'); 236 $closestRowEntry.find('.cancellationReasonClass').val(''); 237 $closestRowEntry.find('.wrongPartMaterialNumber').attr('disabled', 'disabled'); 238 ACC.FileValidationService.resetAttachments($closestRowEntry, fileErrorsMap); 239 } 240 241 function enableRowInputs($closestRowEntry, $checkbox) { 242 $checkbox.prop('readonly', false); 243 $closestRowEntry.find('.returnableQty').prop('readonly', false); 244 245 const selectId = $closestRowEntry.find('.cancellationReasonClass').attr('id'); 246 document.getElementById(selectId).removeAttribute('readonly'); 247 } 248 249 function toggleCaseSelection(groupCaseNumber, isChecked) { 250 const $groupedProducts = $(`.return-product-checkbox[data-caseNumber="${groupCaseNumber}"]`); 251 252 $.each($groupedProducts, (key, product) => { 253 $(product).prop('checked', !!isChecked).change(); 254 }); 255 } 256 257 function getSelectedReturnReasons() { 258 const $selector = $('.cancellationReasonClass').first(); 259 const findReturnReasonValue = reasonKey => ($selector.find(`option[value="${reasonKey}"]`)?.text() || reasonKey); 260 const returnReasonsMap = new Map(); 261 262 if ($productCheckboxes.filter(':checked').length) { 263 $('.return-product-checkbox:checked').each(function () { 264 const $this = $(this); 265 const $closestRowEntry = $this.closest('.rowEntry'); 266 const $cancellationReason = $closestRowEntry.find('.cancellationReasonClass'); 267 const returnReasonKey = $cancellationReason.val(); 268 269 returnReasonKey && returnReasonsMap.set(returnReasonKey, findReturnReasonValue(returnReasonKey)); 270 }); 271 } 272 273 return returnReasonsMap; 274 } 275 276 function openConsignmentInfoPopup(returnReasons) { 277 const { title, message, buttonsText: { submit, reset } } = getPopupTexts(); 278 const messageRow = `<p class="consignment-message">${message}</p>`; 279 const formInputs = getInputsGrid(returnReasons); 280 const buttonsRow = getButtonsElement(reset, submit); 281 282 ACC.colorbox.open(title, { 283 html: `${messageRow}${getFormElement(formInputs, buttonsRow)}`, 284 width: '540px', 285 onComplete: function() { 286 $.colorbox.resize(); 287 ACC.common.refreshScreenReaderBuffer(); 288 ACC.returnorderaction.setupConsignmentInfoForm(); 289 }, 290 }); 291 } 292 293 function getPopupTexts() { 294 return { 295 title: getInputValue('consignmentTitle'), 296 message: getInputValue('consignmentMessage'), 297 buttonsText: { 298 submit: getInputValue('consignmentSubmit'), 299 reset: getInputValue('consignmentReset'), 300 }, 301 } 302 } 303 304 function getFormElement(formInputs, buttonsRow) { 305 const submitAttribute = `onsubmit="ACC.returnorderaction.handleReturnOrderFormSubmit(true)"`; 306 const resetAttribute = `onreset="ACC.returnorderaction.resetConsignmentInfo()"`; 307 return `<form action="javascript:;" ${submitAttribute} ${resetAttribute}>${formInputs}<div>${buttonsRow}</div></form>`; 308 } 309 310 function getInputsGrid(returnReasons) { 311 const getLabelEl = (text) => `<div class="return-reason-label"><label>${text}</label></div>`; 312 313 const weightLabel = getLabelEl(getInputValue('consignmentWeightLabel')); 314 const boxesLabel = getLabelEl(getInputValue('consignmentBoxesLabel')); 315 const formHeader = `<div></div>${weightLabel}${boxesLabel}`; 316 let formBody = ``; 317 318 returnReasons.forEach((reasonValue, reasonID) => { 319 const reasonLabel = getLabelEl(reasonValue); 320 const weightInput = `<div><input class="form-control" id="popup-${reasonID}weight" type="number" min="0" max="1000000" step="0.001" /></div>`; 321 const boxesInput = `<div><input class="form-control" id="popup-${reasonID}numberOfBoxes" type="number" min="0" max="1000000" /></div>`; 322 formBody += `${reasonLabel}${weightInput}${boxesInput}`; 323 }); 324 325 return `<div id="consignment-info" class="consignment-inputs-form">${formHeader}${formBody}</div>`; 326 } 327 328 function getButtonsElement(resetText, submitText) { 329 const resetButton = `<button id="consignment-reset" class="btn btn-default" type="reset">${resetText}</button>`; 330 const submitButton = `<button id="consignment-submit" class="btn btn-primary" type="submit" disabled>${submitText}</button>`; 331 return `<div class="row button-row create-return-order-popup-actions">${resetButton}${submitButton}</div>`; 332 } 333 334 function addOrRemoveAsterisk(el, isToRemove) { 335 if (!isToRemove) { 336 el.addClass('focus'); 337 el.focus(); 338 } else { 339 el.removeClass('focus'); 340 } 341 } 342 343 function checkRowSubmit() { 344 let isSubmitDisabled = false;
345 let fileSizeSum = 0; 346 347 if ($productCheckboxes.filter(':checked').length) { 348 $('.return-product-checkbox:checked').each(function () { 349 const $this = $(this); 350 const $closestRowEntry = $this.closest('.rowEntry'); 351 const rowID = $closestRowEntry.attr('id'); 352 const $returnableQty = $closestRowEntry.find('.returnableQty'); 353 const $cancellationReason = $closestRowEntry.find('.cancellationReasonClass'); 354 const $wrongPartInput = $closestRowEntry.find('.wrongPartMaterialNumber'); 355 const returnProductCode = $closestRowEntry.find('#returnProductCode').attr('data-productCode'); 356 357 if (!$cancellationReason.val() || !+$returnableQty.val() || fileErrorsMap[rowID]?.length) { 358 isSubmitDisabled = true; 359 } 360 361 if ($wrongPartInput.attr('disabled') !== 'disabled' && !$wrongPartInput.val().trim()) { 362 isSubmitDisabled = true; 363 } 364 365 // If previous validation were passed AND 366 // If there is no bypass rule for the whole invoice AND 367 // If there are no bypass rules for individual materials OR current material should not be bypassed. 368 if (!isSubmitDisabled && !isBypassInvoice && (!bypassMaterials.length || !bypassMaterials.includes(returnProductCode))) { 369 var documents = $closestRowEntry.find('.upload-attachments').find('.custom-file-upload:not([hidden])'); 370 $.each(documents, (key, document) => { 371 if (!$(document).find('.file-btn')[0].value) { 372 isSubmitDisabled = true; 373 } 374 }); 375 } 376 377 if (!isSubmitDisabled && maxAllowedUploadsSize) { 378 const documents = $closestRowEntry.find('.upload-attachments').find('.custom-file-upload:not([hidden])'); 379 $.each(documents, (key, document) => { 380 if (!isSubmitDisabled) { 381 const filesArray = Array.from($(document).find('.file-btn')[0].files); 382 filesArray.forEach((file => { 383 fileSizeSum += file.size; 384 })); 385 386 if (fileSizeSum >= maxAllowedUploadsSize * 1000000) { 387 isSubmitDisabled = true; 388 } 389 } 390 }); 391 } 392 }); 393 } else { 394 isSubmitDisabled = true; 395 } 396 397 if (isSubmitDisabled) { 398 $submitButton.prop('disabled', true); 399 400 if (fileSizeSum >= maxAllowedUploadsSize * 1000000) { 401 $errorHint.removeClass('disabled'); 402 } else { 403 $errorHint.addClass('disabled'); 404 } 405 } else { 406 $errorHint.addClass('disabled'); 407 $submitButton.removeAttr('disabled'); 408 } 409 } 410 411 function checkedAll(checkboxes) { 412 let checkedAll = true; 413 $.each(checkboxes, (key, elements) => { 414 if (!$(elements).is(':checked')) { 415 checkedAll = false; 416 } 417 }); 418 return checkedAll; 419 } 420 421 function updateGroupSelection(groupNumber, isChecked) { 422 const $caseNumberCheckbox = $(`.returnorderform-checkbox[data-caseNumber="${groupNumber}"]`); 423 const $groupedProducts = $(`.return-product-checkbox[data-caseNumber="${groupNumber}"]`); 424 425 if (isChecked) { 426 if (checkedAll($groupedProducts)) { 427 $caseNumberCheckbox.prop('checked', true); 428 429 if (checkedAll($caseNumberCheckboxes)) { 430 $selectAllCheckbox.prop('checked', true); 431 } 432 } 433 } else { 434 $caseNumberCheckbox.prop('checked', false); 435 $selectAllCheckbox.prop('checked', false); 436 } 437 } 438 439 function toggleFileButtons(rowEntry, thisVal) { 440 const attachments = rowEntry.find('.upload-attachments'); 441 const documentsSettings = compulsoryDocumentsMap[thisVal]; 442 443 if (!documentsSettings) { 444 return; 445 } 446 447 for (var key in documentsSettings) { 448 const currentDoc = attachments.find(`.custom-file-upload[data-attachmentType="${key}"]`); 449 currentDoc.prop('hidden', !documentsSettings[key]); 450 } 451 452 attachments.prop('hidden', !thisVal); 453 } 454 455 function reCalculateBlockedRowsHeight() { 456 $rowEntry.each(function (index) { 457 $('head').append(`<style>.rowEntry.blocked:nth-child(${index + 1}):after{height:${$(this).outerHeight()}px!important;width:${$(this).width()}px!important;}</style>`); 458 }); 459 } 460 461 function validateReturnableQty(rowEntry, returnQty, returnReason) { 462 const invoicedReturnQty = +rowEntry.find('.quantity').val(); 463 464 if (returnQty < 0 || (returnReason !== 'E' && returnQty > invoicedReturnQty)) { 465 rowEntry.find('.returnableQty').val(invoicedReturnQty); 466 } 467 } 468 469 function adjustMaxReturnableQty(rowEntry, returnReason) { 470 const $reasonQtyInput = rowEntry.find('.returnableQty'); 471 472 if (returnReason === 'E') { 473 $reasonQtyInput.removeAttr('max'); 474 } else { 475 const invoicedReturnQty = rowEntry.find('.quantity').val(); 476 477 $reasonQtyInput.attr('max', invoicedReturnQty); 478 479 if (+$reasonQtyInput.val() > +invoicedReturnQty) { 480 $reasonQtyInput.val(invoicedReturnQty); 481 } 482 } 483 } 484 485 function getRowsInCase($closestRowEntry) { 486 const currCaseNumber = $closestRowEntry.data('case-number'); 487 return [$closestRowEntry.parent().find(`tr[data-case-number="${currCaseNumber}"]`), currCaseNumber]; 488 } 489 490 function handleCasePartsSelection($closestRowEntry, returnReasonKey) { 491 const [$allCaseParts, currCaseNumber] = getRowsInCase($closestRowEntry); 492 493 if ($allCaseParts.length > 1) { 494 toggleCaseSelection(currCaseNumber, true); 495 } 496 disableCaseEdit($allCaseParts, returnReasonKey); 497 } 498 499 function handlePdrSelection(returnReasonKey) { 500 $selectAllCheckbox.prop('checked', true).change(); 501 disableCaseEdit($rowEntry, returnReasonKey, true); 502 } 503 504 function handleCasePartsReset($closestRowEntry) { 505 const caseNumber = $closestRowEntry.attr('data-case-number'); 506 const caseHandler = $closestRowEntry.attr('data-case-handler'); 507 if (caseHandler) { 508 let caseSelector = 'tr[data-case-handler]'; 509 if (caseHandler === SELECTION_TYPE.CASE_LEVEL) { 510 caseSelector += `[data-case-number="${caseNumber}"]`; 511 } 512 const $allCaseParts = $closestRowEntry.parent().find(caseSelector); 513 514 $allCaseParts.each(function (index) { 515 const $this = $(this); 516 const $caseCheckbox = $this.find('.returnorderform-checkbox'); 517 518 if (index !== 0) { 519 if (caseHandler === SELECTION_TYPE.PDR_LEVEL) { 520 $caseCheckbox.prop('checked', false).prop('readonly', false).change(); 521 } 522 $this.find('.return-product-checkbox').prop('checked', false).change(); 523 } else { 524 $this.removeAttr('data-case-handler'); 525 $this.find('.returnableQty').prop('readonly', false); 526 $caseCheckbox.prop('checked', false); 527 } 528 }); 529 } 530 } 531 532 function disableCaseEdit($caseRows, returnReasonKey, disableCaseCheckbox = false, disableQty = false) { 533 $caseRows.each(function (index) { 534 const $this = $(this); 535 536 const $qtyInput = $this.find('.returnableQty'); 537 const preFilledQty = $qtyInput.data('returnable-qty'); 538 $qtyInput.val(preFilledQty); 539 if (disableQty) { 540 $qtyInput.prop('readonly', true); 541 } 542 543 // disable return reason 544 const $returnReason = $this.find('.cancellationReasonClass'); 545 $returnReason.val(returnReasonKey); 546 547 const $wrongPartInput = $this.find('.wrongPartMaterialNumber'); 548 $wrongPartInput.val('').attr('disabled', 'disabled'); 549 550 ACC.FileValidationService.resetAttachments($this, fileErrorsMap); 551 552 if (index !== 0) { 553 const selectId = $returnReason.attr('id'); 554 document.getElementById(selectId).setAttribute('readonly', true); 555 556 // disable part checkbox 557 const $rowCheckbox = $this.find('.return-product-checkbox'); 558 $rowCheckbox.prop('readonly', true); 559 560 if (disableCaseCheckbox) { 561 const $caseCheckbox = $this.find('.returnorderform-checkbox'); 562 $caseCheckbox.prop('readonly', true); 563 } 564 565 $this.attr('data-case-handler', SELECTION_TYPE.PART_LEVEL); 566 } else { 567 if (disableCaseCheckbox) { 568 $this.attr('data-case-handler', SELECTION_TYPE.PDR_LEVEL); 569 } else { 570 $this.attr('data-case-handler', SELECTION_TYPE.CASE_LEVEL); 571 } 572 } 573 }); 574 575 $caseRows.first().find('.cancellationReasonClass').focus(); 576 } 577 }, 578 579 setupFilesErrors: function () { 580 const ErrorType = ACC.FileValidationService.ErrorType; 581 const AttachmentType = ACC.FileValidationService.AttachmentType; 582 583 ACC.FileValidationService.setupErrorMessage(AttachmentType.MANIFEST, ErrorType.MAX_SIZE, $('#manifestMaxSizeExceeded')[0]?.value); 584 ACC.FileValidationService.setupErrorMessage(AttachmentType.MANIFEST, ErrorType.FILE_TYPE, $('#manifestInvalidType')[0]?.value); 585 586 ACC.FileValidationService.setupErrorMessage(AttachmentType.WAYBILL, ErrorType.MAX_SIZE, $('#wayBillMaxSizeExceeded')[0]?.value); 587 ACC.FileValidationService.setupErrorMessage(AttachmentType.WAYBILL, ErrorType.FILE_TYPE, $('#wayBillInvalidType')[0]?.value); 588 589 ACC.FileValidationService.setupErrorMessage(AttachmentType.PART_PHOTO, ErrorType.MAX_SIZE, $('#partPhotoMaxSizeExceeded')[0]?.value); 590 ACC.FileValidationService.setupErrorMessage(AttachmentType.PART_PHOTO, ErrorType.FILE_TYPE, $('#partPhotoInvalidType')[0]?.value); 591 592 ACC.FileValidationService.setupErrorMessage(AttachmentType.CARTOON_PHOTO, ErrorType.MAX_SIZE, $('#cartonPhotoMaxSizeExceeded')[0]?.value); 593 ACC.FileValidationService.setupErrorMessage(AttachmentType.CARTOON_PHOTO, ErrorType.FILE_TYPE, $('#cartonPhotoInvalidType')[0]?.value); 594 595 ACC.FileValidationService.setupErrorMessage(AttachmentType.CASE_LABEL_PHOTO, ErrorType.MAX_SIZE, $('#caseLabelPhotoMaxSizeExceeded')[0]?.value); 596 ACC.FileValidationService.setupErrorMessage(AttachmentType.CASE_LABEL_PHOTO, ErrorType.FILE_TYPE, $('#caseLabelPhotoInvalidType')[0]?.value); 597 598 ACC.FileValidationService.setupErrorMessage(AttachmentType.PART_LABEL_PHOTO, ErrorType.MAX_SIZE, $('#partLabelPhotoMaxSizeExceeded')[0]?.value); 599 ACC.FileValidationService.setupErrorMessage(AttachmentType.PART_LABEL_PHOTO, ErrorType.FILE_TYPE, $('#partLabelPhotoInvalidType')[0]?.value); 600 }, 601 602 setupConsignmentInfoForm: function () { 603 const $consignmentInfo = $('#consignment-info'); 604 605 $consignmentInfo.find('.form-control').on('blur', function () { 606 const inputValue = $(this).val(); 607 608 if (!parseFloat(inputValue) || inputValue < 0) { 609 $(this).val(''); 610 } 611 612 checkConsignmentInfo(); 613 }); 614 615 function checkConsignmentInfo() { 616 let isSubmitDisabled = false;
617 618 $('#consignment-info .form-control').each(function () { 619 if (!$(this).val()) { 620 isSubmitDisabled = true; 621 } 622 }); 623 624 if (isSubmitDisabled) { 625 $('#consignment-submit').prop('disabled', true); 626 } else { 627 $('#consignment-submit').removeAttr('disabled'); 628 } 629 } 630 }, 631 632 resetConsignmentInfo: function () { 633 $('#consignment-info .form-control').each(function () { 634 $(this).val(''); 635 $('#consignment-submit').prop('disabled', true); 636 }); 637 638 $('#consignment-reset').blur(); 639 }, 640 641 getSelectedProductsInfo: function () { 642 const selectedProductsInfo = []; 643 if ($('.return-product-checkbox').filter(':checked').length) { 644 $('.return-product-checkbox:checked').each(function () { 645 const $this = $(this); 646 const $closestRowEntry = $this.closest('.rowEntry'); 647 const code = $closestRowEntry.find('#returnProductCode').attr('data-productCode'); 648 const qty = $closestRowEntry.find('.returnableQty').val(); 649 selectedProductsInfo.push({code, qty}); 650 }); 651 } 652 return selectedProductsInfo; 653 }, 654 655 handleReturnOrderFormSubmit: function (transferData) { 656 if (transferData) { 657 $('#consignment-info .form-control').each(function () { 658 const inputValue = $(this).val(); 659 const popupInputID = $(this).attr('id'); 660 const inputID = popupInputID.replace('popup-', ''); 661 662 $(`#${inputID}`).val(inputValue); 663 }); 664 } 665 666 const orderNumber = $('table[data-gaOrderNumber]').data('gaordernumber');
667 GA.ReturnRequests.saveReturnRequestInfo(orderNumber, ACC.returnorderaction.getSelectedProductsInfo()); 668 669 const $submitReturnOrderForm = $('#submitreturnorderform'); 670 $submitReturnOrderForm.submit(); 671 } 672};
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.