Skip to content

Commit

Permalink
update card
Browse files Browse the repository at this point in the history
  • Loading branch information
denicrizz committed Jun 10, 2024
1 parent dfa0ee0 commit 3dba509
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 88 deletions.
8 changes: 4 additions & 4 deletions js/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ fetch('superstore.json')
.then(data => {
// Menghitung total profit
const totalProfit = data.reduce((sum, order) => sum + order['Profit'], 0);
document.getElementById('totalProfit').textContent = `$${totalProfit.toFixed(2)} `;
document.getElementById('totalProfit').textContent = `$${totalProfit.toFixed(0)} `;

// Menghitung total sales
const totalSales = data.reduce((sum, order) => sum + order['Sales'], 0);
document.getElementById('totalSales').textContent = `$${totalSales.toFixed(2)} `;
document.getElementById('totalSales').textContent = `$${totalSales.toFixed(0)} `;

// Menghitung total order
const totalOrders = data.length;
document.getElementById('totalOrders').textContent = `${totalOrders} `;

// Menghitung unit terjual
const unitsSold = data.reduce((sum, order) => sum + order['Quantity'], 0);
document.getElementById('unitsSold').textContent = `${unitsSold.toFixed(1)} `;
document.getElementById('unitsSold').textContent = `${unitsSold.toFixed(0)} `;

// Menghitung jumlah customer
const totalCustomers = new Set(data.map(order => order['Customer ID'])).size;
Expand All @@ -28,4 +28,4 @@ fetch('superstore.json')
})
.catch(error => {
console.error('Error:', error);
});
});
164 changes: 82 additions & 82 deletions js/rank-sub.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
fetch('superstore.json')
.then(response => response.json())
.then(data => {
// Menghitung total penjualan untuk setiap sub-kategori
const salesBySubCategory = data.reduce((acc, order) => {
const category = order['Category'];
const subCategory = order['Sub-Category'];
const key = `${category}-${subCategory}`;
if (!acc[key]) {
acc[key] = {
category: category,
subCategory: subCategory,
sales: 0,
quantity: 0,
discount: 0,
orders: []
};
}
acc[key].sales += order['Sales'];
acc[key].quantity += order['Quantity'];
acc[key].discount += order['Discount'];
acc[key].orders.push(order);
return acc;
}, {});
.then(response => response.json())
.then(data => {
// Menghitung total penjualan untuk setiap sub-kategori
const salesBySubCategory = data.reduce((acc, order) => {
const category = order['Category'];
const subCategory = order['Sub-Category'];
const key = `${category}-${subCategory}`;
if (!acc[key]) {
acc[key] = {
category: category,
subCategory: subCategory,
sales: 0,
quantity: 0,
discount: 0,
orders: []
};
}
acc[key].sales += order['Sales'];
acc[key].quantity += order['Quantity'];
acc[key].discount += order['Discount'];
acc[key].orders.push(order);
return acc;
}, {});

// Mengurutkan sub-kategori berdasarkan total penjualan
const sortedSubCategories = Object.values(salesBySubCategory).sort((a, b) => b.sales - a.sales);
// Mengurutkan sub-kategori berdasarkan total penjualan
const sortedSubCategories = Object.values(salesBySubCategory).sort((a, b) => b.sales - a.sales);

// Menampilkan ranking sub-kategori dalam tabel
const rankTableBody = document.getElementById('rankTableBody');
let totalSales = 0, totalQuantity = 0, totalDiscount = 0;
const orderIds = new Set();
const productIds = new Set();
const categories = new Set();
const subCategories = new Set();
// Menampilkan ranking sub-kategori dalam tabel
const rankTableBody = document.getElementById('rankTableBody');
let totalSales = 0, totalQuantity = 0, totalDiscount = 0;
const orderIds = new Set();
const productIds = new Set();
const categories = new Set();
const subCategories = new Set();

sortedSubCategories.forEach(item => {
item.orders.forEach(order => {
const row = document.createElement('tr');
sortedSubCategories.forEach(item => {
item.orders.forEach(order => {
const row = document.createElement('tr');

const categoryCell = document.createElement('td');
categoryCell.textContent = item.category;
row.appendChild(categoryCell);
const categoryCell = document.createElement('td');
categoryCell.textContent = item.category;
row.appendChild(categoryCell);

const subCategoryCell = document.createElement('td');
subCategoryCell.textContent = item.subCategory;
row.appendChild(subCategoryCell);
const subCategoryCell = document.createElement('td');
subCategoryCell.textContent = item.subCategory;
row.appendChild(subCategoryCell);

const orderIdCell = document.createElement('td');
orderIdCell.textContent = order['Order ID'];
row.appendChild(orderIdCell);
orderIds.add(order['Order ID']);
const orderIdCell = document.createElement('td');
orderIdCell.textContent = order['Order ID'];
row.appendChild(orderIdCell);
orderIds.add(order['Order ID']);

const productIdCell = document.createElement('td');
productIdCell.textContent = order['Product ID'];
row.appendChild(productIdCell);
productIds.add(order['Product ID']);
const productIdCell = document.createElement('td');
productIdCell.textContent = order['Product ID'];
row.appendChild(productIdCell);
productIds.add(order['Product ID']);

const salesCell = document.createElement('td');
salesCell.textContent = order['Sales'].toFixed(2);
row.appendChild(salesCell);
const salesCell = document.createElement('td');
salesCell.textContent = Math.round(order['Sales']); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
row.appendChild(salesCell);

const quantityCell = document.createElement('td');
quantityCell.textContent = order['Quantity'];
row.appendChild(quantityCell);
const quantityCell = document.createElement('td');
quantityCell.textContent = Math.round(order['Quantity']); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
row.appendChild(quantityCell);

const discountCell = document.createElement('td');
discountCell.textContent = order['Discount'].toFixed(2);
row.appendChild(discountCell);
const discountCell = document.createElement('td');
discountCell.textContent = Math.round(order['Discount']); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
row.appendChild(discountCell);

rankTableBody.appendChild(row);
rankTableBody.appendChild(row);

totalSales += order['Sales'];
totalQuantity += order['Quantity'];
totalDiscount += order['Discount'];
categories.add(order['Category']);
subCategories.add(order['Sub-Category']);
});
totalSales += order['Sales'];
totalQuantity += order['Quantity'];
totalDiscount += order['Discount'];
categories.add(order['Category']);
subCategories.add(order['Sub-Category']);
});
});

// Menampilkan total keseluruhan dalam tabel
document.getElementById('totalSales').textContent = totalSales.toFixed(2);
document.getElementById('totalQuantity').textContent = totalQuantity;
document.getElementById('totalDiscount').textContent = totalDiscount.toFixed(2);
// Menampilkan total keseluruhan dalam tabel
document.getElementById('totalSales').textContent = Math.round(totalSales); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
document.getElementById('totalQuantity').textContent = Math.round(totalQuantity); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
document.getElementById('totalDiscount').textContent = Math.round(totalDiscount); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat

// Menampilkan total keseluruhan dalam card
document.getElementById('totalSalesCard').textContent = totalSales.toFixed(2);
document.getElementById('totalQuantityCard').textContent = totalQuantity;
document.getElementById('totalDiscountCard').textContent = totalDiscount.toFixed(2);
// Menampilkan total keseluruhan dalam card
document.getElementById('totalSalesCard').textContent = Math.round(totalSales); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
document.getElementById('totalQuantityCard').textContent = Math.round(totalQuantity); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat
document.getElementById('totalDiscountCard').textContent = Math.round(totalDiscount); // Menggunakan Math.round() untuk membulatkan ke bilangan bulat terdekat

// Menampilkan jumlah kategori, sub-kategori, Order ID, dan Product ID dalam card
document.getElementById('totalCategoriesCard').textContent = categories.size;
document.getElementById('totalSubCategoriesCard').textContent = subCategories.size;
document.getElementById('totalOrderIDsCard').textContent = orderIds.size;
document.getElementById('totalProductIDsCard').textContent = productIds.size;
})
.catch(error => {
console.error('Error:', error);
});
// Menampilkan jumlah kategori, sub-kategori, Order ID, dan Product ID dalam card
document.getElementById('totalCategoriesCard').textContent = categories.size;
document.getElementById('totalSubCategoriesCard').textContent = subCategories.size;
document.getElementById('totalOrderIDsCard').textContent = orderIds.size;
document.getElementById('totalProductIDsCard').textContent = productIds.size;
})
.catch(error => {
console.error('Error:', error);
});
4 changes: 2 additions & 2 deletions rank-sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h5 class="modal-title" id="searchModalLabel">Search Results</h5>
<div class="col-md-4">
<div class="card card-custom">
<div class="card-body">
<h5 class="card-title">Total Sales</h5>
<h5 class="card-title">Total Sales($)</h5>
<p class="card-text" id="totalSalesCard">0.00</p>
</div>
</div>
Expand All @@ -104,7 +104,7 @@ <h5 class="card-title">Total Quantity</h5>
<div class="col-md-4">
<div class="card card-custom">
<div class="card-body">
<h5 class="card-title">Total Discount</h5>
<h5 class="card-title">Total Discount(%)</h5>
<p class="card-text" id="totalDiscountCard">0.00</p>
</div>
</div>
Expand Down

0 comments on commit 3dba509

Please sign in to comment.