diff --git a/myproject/pos/static/pos/js/terminal.js b/myproject/pos/static/pos/js/terminal.js index 2390c11..7b3dab3 100644 --- a/myproject/pos/static/pos/js/terminal.js +++ b/myproject/pos/static/pos/js/terminal.js @@ -87,6 +87,7 @@ function formatMoney(v) { * - Кнопку "Выбрать клиента" в модалке продажи (показывает имя клиента) * - Видимость кнопок сброса в обоих местах (показываем только для не-системного клиента) * - Ссылку на анкету клиента (показываем только для не-системного клиента) + * - Баланс кошелька в модальном окне продажи (если оно открыто) */ function updateCustomerDisplay() { // Обновляем текст кнопки в корзине @@ -122,6 +123,28 @@ function updateCustomerDisplay() { profileLink.style.display = 'block'; } } + + // Обновляем баланс кошелька в модальном окне продажи (если оно открыто) + updateCheckoutWalletBalance(); +} + +/** + * Обновляет баланс кошелька клиента в модальном окне продажи + */ +function updateCheckoutWalletBalance() { + const walletDiv = document.getElementById('checkoutWalletBalance'); + if (!walletDiv) return; // Модалка еще не инициализирована + + const customer = selectedCustomer || SYSTEM_CUSTOMER; + const walletBalance = customer.wallet_balance || 0; + const isSystemCustomer = Number(customer.id) === Number(SYSTEM_CUSTOMER.id); + + if (!isSystemCustomer) { + document.getElementById('checkoutWalletBalanceAmount').textContent = walletBalance.toFixed(2); + walletDiv.style.display = 'block'; + } else { + walletDiv.style.display = 'none'; + } } /** @@ -1761,7 +1784,7 @@ document.getElementById('customerSelectBtn').addEventListener('click', () => { // Кнопка сброса клиента на системного (в корзине) document.getElementById('resetCustomerBtn').addEventListener('click', () => { - selectCustomer(SYSTEM_CUSTOMER.id, SYSTEM_CUSTOMER.name); + selectCustomer(SYSTEM_CUSTOMER.id, SYSTEM_CUSTOMER.name, SYSTEM_CUSTOMER.wallet_balance || 0); }); // Кнопка "Выбрать клиента" в модалке продажи @@ -1772,7 +1795,7 @@ document.getElementById('checkoutCustomerSelectBtn').addEventListener('click', ( // Кнопка сброса клиента на системного (в модалке продажи) document.getElementById('checkoutResetCustomerBtn').addEventListener('click', () => { - selectCustomer(SYSTEM_CUSTOMER.id, SYSTEM_CUSTOMER.name); + selectCustomer(SYSTEM_CUSTOMER.id, SYSTEM_CUSTOMER.name, SYSTEM_CUSTOMER.wallet_balance || 0); }); // Кнопка "Создать нового клиента" в модалке выбора @@ -1787,7 +1810,7 @@ document.getElementById('createNewCustomerBtn').addEventListener('click', () => // Кнопка "Выбрать системного клиента" document.getElementById('selectSystemCustomerBtn').addEventListener('click', () => { - selectCustomer(SYSTEM_CUSTOMER.id, SYSTEM_CUSTOMER.name); + selectCustomer(SYSTEM_CUSTOMER.id, SYSTEM_CUSTOMER.name, SYSTEM_CUSTOMER.wallet_balance || 0); // Закрываем модалку const modal = bootstrap.Modal.getInstance(document.getElementById('selectCustomerModal'));