document.addEventListener(`DOMContentLoaded`,function(){let e=document.getElementById(`employee_id`),t=document.getElementById(`current-balance-display`),n=document.getElementById(`type`),r=document.getElementById(`order_number_group`);function i(){let e=n.value.toLowerCase();e===`refund`||e.includes(`payment`)||e.includes(`payment_made`)?r.style.display=`none`:r.style.display=`block`}i(),n.addEventListener(`change`,i),e.addEventListener(`change`,function(){let e=this.value;if(!e){t.innerHTML=`<span class="text-muted">Select an employee to see current balance</span>`;return}let n=e.split(`|`)[0];t.innerHTML=`<span class="text-muted"><i class="fas fa-spinner fa-spin"></i> Loading balance...</span>`,fetch(`/deductions/get-balance/${n}`).then(e=>{if(!e.ok)throw Error(`Network response was not ok`);return e.json()}).then(e=>{if(e.success){let n=parseFloat(e.current_balance);t.innerHTML=`
                        <span class="${n<0?`text-danger`:n>0?`text-success`:`text-muted`} fw-bold">
                            ${n<0?`-$${Math.abs(n).toFixed(2)}`:`$${n.toFixed(2)}`}
                        </span>
                        ${n<0?`(Amount Owed)`:n>0?`(Credit Balance)`:`(Zero Balance)`}
                    `}else t.innerHTML=`<span class="text-danger">${e.message||`Error loading balance`}</span>`}).catch(e=>{console.error(`Error:`,e),t.innerHTML=`<span class="text-danger">Error loading balance</span>`})})}),document.getElementById(`employee_id`).addEventListener(`change`,function(){let e=this.options[this.selectedIndex].getAttribute(`data-station-id`);document.getElementById(`station_id`).value=e});