Skip to content

Commit

Permalink
banner management completed
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadakl committed Nov 8, 2023
1 parent 2e31136 commit fc4b535
Show file tree
Hide file tree
Showing 104 changed files with 3,868 additions and 760 deletions.
333 changes: 1 addition & 332 deletions controllers/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,52 +365,7 @@ const generateReport = async (dateRange) => {
}
};

// const generateReport = async (dateRange) => {
// try {
// const currentDate = new Date();
// let startDate;
// let endDate = new Date();

// switch (dateRange) {
// case "daily":
// startDate = new Date(currentDate);
// startDate.setDate(currentDate.getDate() - 1);
// startDate.setHours(24, 0, 0, 0);
// break;
// case "weekly":
// startDate = new Date();
// startDate.setDate(startDate.getDate() - 7);
// break;
// case "yearly":
// startDate = new Date();
// startDate.setFullYear(startDate.getFullYear() - 1);
// break;
// default:
// break;
// }

// // Retrieve orders within the specified date range
// const orders = await OrderDB.find({
// orderDate: { $gte: startDate, $lte: endDate },
// });


// // const totalSalesAmount = calculateTotalSalesAmount(orders);
// const totalSalesProfit = await calculateTotalProfit(orders);
// const totalOrders = orders.length;

// const report = {
// reportDate: endDate,
// totalSalesAmount:totalSalesProfit,
// totalOrders,
// };

// console.log(`Generated ${dateRange} report for ${endDate}`);
// return report;
// } catch (error) {
// console.log(error.message);
// }
// };


async function calculateTotalProfit(orders) {
let totalProfit = 0;
Expand Down Expand Up @@ -526,293 +481,7 @@ const generateExcelReport = async (reportData, fileName) => {
};


// Usage
// const reportData = [
// {
// reportDate: '2023-10-23',
// totalSalesAmount: 1000.0,
// totalOrders: 50,
// },
// // Add more data as needed
// ];

// const filePath = 'salesReport.xlsx'; // Provide the desired file path

// generateExcelReport(reportData, filePath);


//sales report page load
// -------------------------------
// const salesReportPageLoad = async(req,res)=>{
// try {
// const sales = await createSalesReport("2023-10-01", "2023-10-31");
// const WeeklySales = await generateWeeklySalesCount()
// const SoldProducts = await getMostSellingProducts()
// console.log(sales);
// // generateWeeklySalesCount
// res.render('salesreport',{week:WeeklySales,Mproducts:SoldProducts,sales})
// } catch (error) {
// console.log(error.message);
// }
// }

// //generate Sales Report
// const createSalesReport = async (startDate, endDate) => {
// try {
// // Find orders within the date range
// const orders = await OrderDB.find({
// orderDate: {
// $gte: startDate,
// $lte: endDate,
// },
// });

// // Create new objects for total stock sold and product profits
// const transformedTotalStockSold = {};
// const transformedProductProfits = {};

// // Helper function to fetch product details by ID
// const getProductDetails = async (productId) => {
// return await ProductDB.findById(productId);
// };

// // Iterate through each order
// for (const order of orders) {
// // Iterate through each product in the order
// for (const productInfo of order.products) {
// const productId = productInfo.productId;
// const quantity = productInfo.quantity;

// // Fetch product details
// const product = await getProductDetails(productId);
// const productName = product.product_name;
// const image = product.images.image1;
// const shape = product.frame_shape

// // Update the total stock sold
// if (!transformedTotalStockSold[productId]) {
// transformedTotalStockSold[productId] = {
// id: productId,
// name: productName,
// quantity: 0,
// image: image,
// shape:shape
// };
// }
// transformedTotalStockSold[productId].quantity += quantity;

// // Update the product profits
// if (!transformedProductProfits[productId]) {
// transformedProductProfits[productId] = {
// id: productId,
// name: productName,
// profit: 0,
// image: image,
// };
// }
// const productPrice = product.price;
// const productCost = productPrice * 0.3;
// const productProfit = (productPrice - productCost) * quantity;
// transformedProductProfits[productId].profit += productProfit;
// }
// }

// // Convert the transformed objects to arrays
// const totalStockSoldArray = Object.values(transformedTotalStockSold);
// const productProfitsArray = Object.values(transformedProductProfits);

// // Calculate the total sales
// const totalSales = productProfitsArray.reduce(
// (total, product) => total + product.profit,
// 0
// );

// // Create the final sales report object
// const salesReport = {
// totalSales,
// totalStockSold: totalStockSoldArray,
// productProfits: productProfitsArray,
// };

// // Print or return the sales report
// return salesReport;
// } catch (error) {
// console.error("Error generating the sales report:", error.message);
// }
// };
// // const createSalesReport = async (startDate, endDate) => {
// // try {
// // // Find orders within the date range
// // const orders = await OrderDB.find({
// // orderDate: {
// // $gte: startDate,
// // $lte: endDate,
// // },
// // });

// // // Create a data structure to store the report
// // const salesReport = {
// // totalSales: 0,
// // totalStockSold: {},
// // productProfits: {},
// // };

// // // Helper function to fetch product details by ID
// // const getProductDetails = async (productId) => {
// // return await ProductDB.findById(productId);
// // };

// // // Iterate through each order
// // for (const order of orders) {
// // // Iterate through each product in the order
// // for (const productInfo of order.products) {
// // const productId = productInfo.productId;
// // const quantity = productInfo.quantity;

// // // Fetch product details
// // const product = await getProductDetails(productId);
// // const productName = product.product_name; // Get product name
// // const image = product.images.image1

// // // Update the total sales
// // const productPrice = product.price;
// // const productSales = productPrice * quantity;
// // salesReport.totalSales += productSales;

// // // Update the total stock sold
// // if (!salesReport.totalStockSold[productId]) {
// // salesReport.totalStockSold[productId] = {
// // name: productName, // Include product name
// // quantity: 0,
// // image: image,
// // };
// // }
// // salesReport.totalStockSold[productId].quantity += quantity;

// // // Calculate and update the product profits
// // const productCost = productPrice*0.3;
// // const productProfit = (productPrice - productCost) * quantity;

// // if (!salesReport.productProfits[productId]) {
// // salesReport.productProfits[productId] = {
// // name: productName, // Include product name
// // profit: 0,
// // image: image
// // };
// // }
// // salesReport.productProfits[productId].profit += productProfit;
// // }
// // }

// // // Print or return the sales report with product names
// // // console.log("Sales Report:", salesReport);
// // return salesReport;

// // } catch (error) {
// // console.error("Error generating the sales report:", error.message);
// // }
// // };
// // Example usage




// //weekly report chart
// // -----------------------
// const generateWeeklySalesCount = async () => {
// try {
// // Initialize an array to store sales counts for each day
// const weeklySalesCounts = [];

// // Get today's date
// const today = new Date();
// today.setHours(today.getHours() - 5); // Adjust for UTC+5


// // Iterate through the past 7 days
// for (let i = 0; i < 7; i++) {
// const startDate = new Date(today);
// startDate.setDate(today.getDate() - i); // i days ago
// const endDate = new Date(startDate);
// endDate.setDate(startDate.getDate() + 1); // Next day

// // Find orders within the date range
// const orders = await OrderDB.find({
// orderDate: {
// $gte: startDate,
// $lt: endDate,
// },
// });

// // Calculate the sales count for the day
// const salesCount = orders.length;

// // Push the sales count to the weeklySalesCounts array
// weeklySalesCounts.push({
// date: startDate.toISOString().split('T')[0], // Format the date
// sales: salesCount,
// });
// }

// // Log or return the weekly sales counts
// // console.log('Weekly Sales Counts:', weeklySalesCounts);
// return weeklySalesCounts;

// } catch (error) {
// console.error('Error generating the weekly sales counts:', error.message);
// }
// };

// // Call the function to generate the weekly sales count
// // generateWeeklySalesCount();

// //most selling products report
// // -----------------------------------

// const getMostSellingProducts = async () => {
// try {
// const pipeline = [
// {
// $unwind: '$products', // Split order into individual products
// },
// {
// $group: {
// _id: '$products.productId',
// count: { $sum: '$products.quantity' }, // Count the sold quantity
// },
// },
// {
// $lookup: {
// from: 'products', // Name of your Product model's collection
// localField: '_id',
// foreignField: '_id',
// as: 'productData',
// },
// },
// {
// $sort: { count: -1 }, // Sort by count in descending order
// },
// {
// $limit: 6, // Limit to the top 6 products
// },
// ];

// const mostSellingProducts = await OrderDB.aggregate(pipeline);
// return mostSellingProducts;
// } catch (error) {
// console.error('Error fetching most selling products:', error);
// return [];
// }
// };

// Usage
// getMostSellingProducts()
// .then((result) => {
// console.log('Most selling products:', result);
// })
// .catch((error) => {
// console.error('Error:', error);
// });

const errorpageHandil = async(req,res)=>{
try {
Expand Down
Loading

0 comments on commit fc4b535

Please sign in to comment.