Stock Sync App
This script is designed for mainlyextracting stock data from a Cybertill, performing data transformation, and generating CSV files.
This function is responsible for extracting data from a database for a specific location and writing it to a CSV file. It follows these steps:
- Fetch data from the database for the specified location.
- Filter the data to extract relevant information, such as brands and seasons.
- Fetch items using the getItems function with filtering criteria.
- Append the extracted data to the allDatadetails array.
- Repeat the data extraction process until all data is fetched.
- Write the combined data to a CSV file with the location's name.
This function constructs an SQL query based on the provided parameters and fetches data from the database. The steps include:
- Construct a SQL query with parameters like limit, offset, location_id, brandSQL, and seasonSQL.
- Fetch data from the database using the constructed query.
- Return the fetched data.
This function retrieves a list of locations from the database. It constructs and executes an SQL query to obtain this information.
This function generates a summary CSV file that aggregates data from multiple location-specific CSV files. The steps include:
- Iterate over the provided locationNames.
- Read each location-specific CSV file and collect data.
- Group the collected data by the "ref" field.
- Calculate the sum of the "stock" values for each group.
- Generate a CSV file with the aggregated data and write it to "./csv/default.csv".
The main function is the entry point of the script. It coordinates the execution of various tasks, including:
- Fetching the list of locations.
- Iterating over each location to extract data.
- Generating the default location CSV file.
- Uploading data for all locations.
- Writing the timestamp of the last run to a JSON file.