@@ -14,28 +14,18 @@ $(() => {
1414 const quantityInput = section . find ( 'input[name*="[quantity]"]' ) ;
1515 const itemQuantity = parseInt ( quantityInput . val ( ) ) || 0 ;
1616 const barcodeValue = section . find ( '.__barcode_item_lookup' ) . val ( ) || '' ;
17+
1718 if ( ! itemId || itemText === "Choose an item" || itemQuantity === 0 ) {
19+ section . remove ( ) ;
1820 return ;
1921 }
22+
2023 itemCounts [ itemId ] = ( itemCounts [ itemId ] || 0 ) + 1 ;
2124 itemNames [ itemId ] = itemText ;
2225 if ( ! itemQuantities [ itemId ] ) itemQuantities [ itemId ] = [ ] ;
2326 itemQuantities [ itemId ] . push ( { qty : itemQuantity , barcode : barcodeValue } ) ;
2427 } ) ;
2528
26- // Remove rows with zero quantity or no item selected
27- form . find ( 'select[name$="[item_id]"]' ) . each ( function ( ) {
28- const itemId = $ ( this ) . val ( ) ;
29- const itemText = $ ( this ) . find ( 'option:selected' ) . text ( ) ;
30- const section = $ ( this ) . closest ( '.line_item_section' ) ;
31- const quantityInput = section . find ( 'input[name*="[quantity]"]' ) ;
32- const itemQuantity = parseInt ( quantityInput . val ( ) ) || 0 ;
33-
34- if ( ! itemId || itemText === "Choose an item" || itemQuantity === 0 ) {
35- section . remove ( ) ;
36- }
37- } ) ;
38-
3929 // Check for duplicates
4030 const duplicates = Object . keys ( itemCounts )
4131 . filter ( itemId => itemCounts [ itemId ] > 1 )
@@ -45,10 +35,8 @@ $(() => {
4535 // Show modal with duplicate items
4636 showDuplicateModal ( duplicates , itemQuantities , form , buttonName ) ;
4737 e . preventDefault ( ) ;
48- } else {
49- // No duplicates, let the form submit normally
50- // Don't prevent default - let the button's natural submit behavior work
51- }
38+ }
39+ // else, allow form submission to proceed
5240 }
5341
5442 $ ( "button[name='save_progress']" ) . on ( 'click' , function ( e ) {
@@ -64,33 +52,33 @@ $(() => {
6452 const entries = duplicateQuantities [ item . id ] || [ ] ;
6553 const total = entries . reduce ( ( sum , entry ) => sum + entry . qty , 0 ) ;
6654 const rows = entries . map ( ( entry , i ) => {
67- const barcodeLine = entry . barcode ? `<div style="font-size: 0.85em; color: #666; margin-top: 2px;">Barcode: ${ entry . barcode } </div>` : '' ;
68- if ( i === 0 ) {
69- return `<div style="padding: 8px; margin: 4px 0; background-color: #f8f9fa; border-left: 3px solid #6c757d;">${ item . name } - Quantity: ${ entry . qty } ${ barcodeLine } </div>` ;
70- } else {
71- return `<div style="padding: 8px; margin: 4px 0; background-color: #fff3cd; border-left: 3px solid #ffc107;"><strong>⚠ Duplicate:</strong> ${ item . name } - Quantity: ${ entry . qty } ${ barcodeLine } </div>` ;
72- }
55+ const barcodeLine = entry . barcode ? `<div class="duplicate-barcode">Barcode: ${ entry . barcode } </div>` : '' ;
56+ return `<div class="duplicate-entry">❐ ${ item . name } : ${ entry . qty } ${ barcodeLine } </div>` ;
7357 } ) . join ( '' ) ;
74- return `<div style="margin-bottom: 20px; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 5px; ">${ rows } <div style="padding: 10px; margin: 10px 0 0 0; background-color: #d1ecf1; border: 2px solid #0c5460; border-radius: 4px; font-weight: bold;">✓ Merged Result - Quantity : ${ total } </div></div>` ;
58+ return `<div class="duplicate-container ">${ rows } <div class="duplicate-merged">→ Merged Result: ${ item . name } : ${ total } </div></div>` ;
7559 } ) . join ( '' ) ;
7660 const modalHtml = `
7761 <div class="modal fade" id="duplicateItemsModal" tabindex="-1">
7862 <div class="modal-dialog modal-dialog-scrollable">
7963 <div class="modal-content">
8064 <div class="modal-header">
81- <h5 class="modal-title">Duplicate Items Detected</h5>
65+ <h5 class="modal-title">Multiple Item Entries Detected</h5>
8266 <button type="button" class="close" data-bs-dismiss="modal">
8367 <span>×</span>
8468 </button>
8569 </div>
8670 <div class="modal-body">
8771 <p><strong>The following items have multiple entries:</strong></p>
88- <div>${ itemRows } </div>
89- <p style="margin-top: 15px; padding: 10px; background-color: #f8f9fa; border-left: 3px solid #6c757d;">Choose <strong>Merge Items</strong> to combine quantities and continue, or <strong>Review Entries</strong> to go back and make changes.</p>
72+ <div class="duplicate-items-list">${ itemRows } </div>
9073 </div>
91- <div class="modal-footer">
92- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Review Entries</button>
93- <button type="button" class="btn btn-warning" id="confirmMerge">Merge Items</button>
74+ <div class="modal-footer duplicate-modal-footer">
75+ <p class="duplicate-modal-text">
76+ Choose <strong>Merge Items</strong> to combine quantities and continue, or <strong>Make Changes</strong> to go back and edit.
77+ </p>
78+ <div class="duplicate-modal-buttons">
79+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Make Changes</button>
80+ <button type="button" class="btn btn-success" id="confirmMerge">Merge Items</button>
81+ </div>
9482 </div>
9583 </div>
9684 </div>
@@ -109,12 +97,7 @@ $(() => {
10997 $ ( '#duplicateItemsModal' ) . modal ( 'hide' ) ;
11098 } ) ;
11199
112- // Handle review button
113- $ ( '#duplicateItemsModal .btn-secondary' ) . on ( 'click' , function ( ) {
114- $ ( '#duplicateItemsModal' ) . modal ( 'hide' ) ;
115- } ) ;
116-
117- // Handle confirm button
100+ // Handle Merge Items button
118101 $ ( '#confirmMerge' ) . on ( 'click' , function ( ) {
119102 $ ( '#duplicateItemsModal' ) . modal ( 'hide' ) ;
120103
@@ -126,7 +109,7 @@ $(() => {
126109 form . append ( hiddenBtn ) ;
127110
128111 // Click the hidden button to submit with the correct parameter
129- hiddenBtn . click ( ) ;
112+ hiddenBtn . trigger ( 'click' ) ;
130113 } ) ;
131114 }
132115
0 commit comments