From 0c98dc0bb15fcd2d1b1e685455f31faaa22fa858 Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Sun, 4 Jan 2026 17:37:05 -0600 Subject: [PATCH] =?UTF-8?q?add:=20implementar=20servicio=20de=20reportes?= =?UTF-8?q?=20para=20productos=20m=C3=A1s=20vendidos=20y=20sin=20movimient?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Dashboard/Index.vue | 230 +++++++++++++++++++++++++++++++++- src/services/reportService.js | 57 +++++++++ 2 files changed, 284 insertions(+), 3 deletions(-) create mode 100644 src/services/reportService.js diff --git a/src/pages/Dashboard/Index.vue b/src/pages/Dashboard/Index.vue index 1b0dd60..cb7a3c1 100644 --- a/src/pages/Dashboard/Index.vue +++ b/src/pages/Dashboard/Index.vue @@ -1,9 +1,233 @@ \ No newline at end of file diff --git a/src/services/reportService.js b/src/services/reportService.js new file mode 100644 index 0000000..5d9e8e7 --- /dev/null +++ b/src/services/reportService.js @@ -0,0 +1,57 @@ +import { api, apiURL } from '@Services/Api'; + +const reportService = { + /** + * Fetches the top selling product. + * @param {string|null} fromDate - Start date in YYYY-MM-DD format. + * @param {string|null} toDate - End date in YYYY-MM-DD format. + * @returns {Promise} + */ + async getTopSellingProduct(fromDate = null, toDate = null) { + return new Promise((resolve, reject) => { + const params = {}; + if (fromDate) params.from_date = fromDate; + if (toDate) params.to_date = toDate; + + api.get(apiURL('reports/top-selling-product'), { + params, + onSuccess: (response) => { + resolve(response); + }, + onError: (error) => { + console.error('Error fetching top selling product:', error); + reject(error); + } + }); + }); + }, + + /** + * Fetches products without movement. + * @param {number} daysThreshold - The threshold in days. + * @param {boolean} includeStockValue - Flag to include the inventory value in the response. + * @returns {Promise} + */ + async getProductsWithoutMovement(daysThreshold = 30, includeStockValue = true) { + return new Promise((resolve, reject) => { + const params = { + days_threshold: daysThreshold, + // Convert boolean to 1 or 0 for Laravel validation + include_stock_value: includeStockValue ? 1 : 0 + }; + + api.get(apiURL('reports/products-without-movement'), { + params, + onSuccess: (response) => { + resolve(response); + }, + onError: (error) => { + console.error('Error fetching products without movement:', error); + reject(error); + } + }); + }); + } +}; + +export default reportService; \ No newline at end of file