ÿØÿà JFIF ÿÛ „ ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /proc/self/root/var/www/html/tien-dien/layout/visahp/js/ |
$(document).ready(function() { const inputContainer = $('#inputContainer'); let roomCounter = 1; $('#addRoomButton').on('click', function () { roomCounter++; const newRoomDiv = $('<div>').addClass('form-group mb-3'); const newLabel = $('<label>') .attr('for', 'so_dien_phong_' + roomCounter) .addClass('form-label') .text('Số Ä‘iện Phòng ' + roomCounter + ' (kWh):'); const newInput = $('<input>') .attr('type', 'number') .addClass('form-control') .attr('id', 'so_dien_phong_' + roomCounter) .attr('name', 'so_dien_phong[]') .attr('placeholder', 'Nháºp số kWh') .attr('min', '0'); const costDisplayDiv = $('<div>') .addClass('room-cost mt-1 text-muted') .html('<div>Thà nh tiá»n (chưa VAT): <span class="cost-value-pre-tax fw-bold">0</span> VNÄ</div>' + '<div>Thà nh tiá»n (đã VAT 8%): <span class="cost-value-post-tax fw-bold">0</span> VNÄ</div>' + '<div>Phải đóng: <span class="tien_dong_thuc fw-bold">0</span> VNÄ</div>'); newRoomDiv.append(newLabel).append(newInput).append(costDisplayDiv); inputContainer.append(newRoomDiv); }); $('#calculateButton').on('click', function () { const kwhInputs = $('input[name="so_dien_phong[]"]'); let kwhValues = []; kwhInputs.each(function () { const val = $(this).val(); const kwh = parseFloat(val); kwhValues.push((val === '' || isNaN(kwh) || kwh < 0) ? 0 : kwh); }); const tien_dong = parseFloat($('#tien_dong').val()) || 0; $.ajax({ url: '?act=tiendien2&code=tinh_tiendien', type: 'POST', data: { so_dien_phong: kwhValues, tien_dong: tien_dong }, dataType: 'json', beforeSend: function () { $('#calculateButton').prop('disabled', true).text('Äang tÃnh...'); $('.cost-value-pre-tax, .cost-value-post-tax, .tien_dong_thuc').text('0'); $('.room-explanation, .room-breakdown-table').remove(); }, success: function (response) { if (response && response.room_costs && response.room_costs.length === kwhInputs.length) { kwhInputs.each(function (index) { const roomData = response.room_costs[index]; const costGroup = $(this).closest('.form-group'); const preTaxSpan = costGroup.find('.cost-value-pre-tax'); const postTaxSpan = costGroup.find('.cost-value-post-tax'); const postTaxSpan2 = costGroup.find('.tien_dong_thuc'); preTaxSpan.text(Math.round(roomData.pre_tax).toLocaleString('vi-VN')); postTaxSpan.text(Math.round(roomData.post_tax).toLocaleString('vi-VN')); if (tien_dong > 0 && response.result_tien) { const roomData2 = response.result_tien[index]; postTaxSpan2.text(Math.round(roomData2.tien_dong_thuc).toLocaleString('vi-VN')); } // Giai Ä‘oạn giải thÃch if (roomData.explanation) { const explainDiv = $('<div class="room-explanation text-info">'); roomData.explanation.forEach(line => { explainDiv.append($('<div>').text(line)); }); costGroup.append(explainDiv); } // Bảng breakdown chi tiết từng báºc if (roomData.breakdown && Array.isArray(roomData.breakdown)) { const table = $('<table>').addClass('table table-sm table-bordered room-breakdown-table mt-2'); const thead = $('<thead>').html('<tr><th>Báºc</th><th>Khoảng kWh</th><th>Số kWh</th><th>ÄÆ¡n giá</th><th>Thà nh tiá»n</th></tr>'); const tbody = $('<tbody>'); let tongTien = 0; roomData.breakdown.forEach((item, idx) => { tongTien += item.cost; const row = $('<tr>'); row.append($('<td>').text('Báºc ' + (idx + 1))); row.append($('<td>').text(item.range)); row.append($('<td>').text(item.used)); row.append($('<td>').text(Number(item.price).toLocaleString('vi-VN') + ' Ä‘')); row.append($('<td>').text(Number(item.cost).toLocaleString('vi-VN') + ' Ä‘')); tbody.append(row); }); // Tổng cá»™ng const totalRow = $('<tr>').addClass('fw-bold bg-light'); totalRow.append('<td colspan=\"4\" class=\"text-end\">Tổng cá»™ng</td>'); totalRow.append('<td>' + tongTien.toLocaleString('vi-VN') + ' Ä‘</td>'); tbody.append(totalRow); table.append(thead).append(tbody); costGroup.append(table); } }); $('#total_cost_vat').text(Math.round(response.total_cost_vat).toLocaleString('vi-VN')); } else { alert('Lá»—i khi nháºn dữ liệu từ server.'); console.error("Phản hồi không hợp lệ từ server:", response); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Có lá»—i xảy ra khi tÃnh tiá»n Ä‘iện.'); console.error("Lá»—i AJAX:", textStatus, errorThrown, jqXHR.responseText); }, complete: function () { $('#calculateButton').prop('disabled', false).text('TÃnh tiá»n Ä‘iện'); } }); }); $('#exportPdfAll').on('click', async function () { const { jsPDF } = window.jspdf; const pdf = new jsPDF(); const pdfContainer = $('#pdfContainer'); pdfContainer.empty(); // reset const kwhInputs = $('input[name="so_dien_phong[]"]'); kwhInputs.each(function (index) { const roomDiv = $(this).closest('.form-group'); const clone = roomDiv.clone(); // Bá» input để nhìn đẹp clone.find('input').remove(); clone.find('button').remove(); clone.find('.form-label').prepend(`<h3>Phòng ${index + 1}</h3>`); pdfContainer.append(clone); }); // Bắt đầu render từng khối thà nh PDF const pages = pdfContainer.children(); for (let i = 0; i < pages.length; i++) { const canvas = await html2canvas(pages[i][0], { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; if (i > 0) pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); } pdf.save('hoa_don_tien_dien_tat_ca.pdf'); }); let waterRoomCounter = 1; $('#addRoomWater').on('click', function () { waterRoomCounter++; const newDiv = $('<div>').addClass('form-group mb-3'); const label = $('<label>').text(`Số nước Phòng ${waterRoomCounter} (m³):`); const input = $('<input type="number" min="0" required>') .addClass('form-control') .attr('name', 'so_nuoc_phong[]') .attr('placeholder', 'Nháºp số m³'); const result = $('<div>').addClass('result-nuoc mt-1 text-muted') .html('Tiá»n nước phòng: <span class="tien_nuoc_phong fw-bold">0</span> VNÄ'); newDiv.append(label).append(input).append(result); $('#inputContainerWater').append(newDiv); }); $('#calculateWater').on('click', function () { const soNuoc = $('input[name="so_nuoc_phong[]"]').map(function () { return parseFloat($(this).val()) || 0; }).get(); const tongTien = parseFloat($('#tong_tien_nuoc').val()) || 0; $.ajax({ url: '?act=tiennuoc&code=tinh_tien_nuoc', method: 'POST', data: { so_nuoc_phong: soNuoc, tong_tien_nuoc: tongTien }, dataType: 'json', success: function (res) { if (res && res.tien_phong && res.tien_phong.length) { $('input[name="so_nuoc_phong[]"]').each(function (i) { const tien = Math.round(res.tien_phong[i]).toLocaleString('vi-VN'); $(this).closest('.form-group').find('.tien_nuoc_phong').text(tien); }); } }, error: function (xhr) { alert('Lá»—i khi tÃnh tiá»n nước!'); console.error(xhr.responseText); } }); }); // Star Rating functionality function initStarRating() { const stars = document.querySelectorAll('.star-rating .star'); const selectedRating = document.getElementById('selected-rating'); const messageDiv = document.getElementById('rating-message'); if (!stars.length || !selectedRating || !messageDiv) { return; // Exit if elements don't exist on this page } const productId = selectedRating.getAttribute('data-product-id'); // Add event listeners to stars stars.forEach(star => { star.addEventListener('click', function() { const rating = this.getAttribute('data-rating'); selectedRating.value = rating; // Reset all stars stars.forEach(s => s.classList.remove('active')); // Highlight selected stars (accounting for RTL direction) // With direction:rtl, stars are in reverse order visually but not in the DOM for (let i = 0; i < rating; i++) { // In RTL, we need to highlight stars from the end stars[stars.length - 1 - i].classList.add('active'); } // Submit rating immediately if (rating < 1) { messageDiv.textContent = 'Vui lòng chá»n số sao đánh giá'; messageDiv.className = 'mt-1 error'; return; } // Show loading message messageDiv.textContent = 'Äang gá»i...'; messageDiv.className = 'mt-1'; // Send AJAX request fetch('?act=ajax&code=product_rating', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `product_id=${productId}&rating=${rating}` }) .then(response => response.json()) .then(data => { if (data.status === 'success') { // Update display messageDiv.textContent = data.message; messageDiv.className = 'mt-1 success'; // Update average rating display document.querySelector('.rating-value').textContent = data.average; document.querySelector('.rating-count').textContent = `(${data.count} đánh giá)`; document.querySelector('.stars-inner').style.width = `${(data.average / 5) * 100}%`; } else { messageDiv.textContent = data.message; messageDiv.className = 'mt-1 error'; } }) .catch(error => { console.error('Error:', error); messageDiv.textContent = 'Có lá»—i xảy ra, vui lòng thá» lại sau'; messageDiv.className = 'mt-1 error'; }); }); }); } // Initialize star rating when DOM is ready initStarRating(); });