Help with auto calculating inventory
Hello, I am currently trying to create a program that will auto calculate a refill field and a threshold field and schedule it to run every night. We want to take 60 days worth of data and divide it by 2 to get an average for a month and then divide it by two again to get our threshold. I have not ran my code yet because I am nervous if it is wrong, it will change all the values to wrong. Any help/advice would be greatly appreciated.
- //Fetching all records from Book and Invoice Tables
- Books = Books[ID != 0];
- Invoice_Data = Invoice_Data[ID != 0];
- //getting a value that is 2 months less than today's date
- two_months_ago = subMonth(zoho.currentdate,2);
- //If date field is in the last 60 days.
- if(Invoice_Data.Date_field > two_months_ago)
- {
- for each Each_Book in Invoice_Data
- {
- //Counting all the books in invoice in last 2 months and dividing by 2
- Total_Books = Invoice_Data[Book = Book].count();
- Total_Books2 = Total_Books / 2;
- Total_Books3 = Total_Books2 / 2;
- //converting decimal to Long
- Total_Books_Threshold = Total_Books3.toLong();
- Total_Books_Refill = Total_Books2.toLong();
- //Updating refill/threshold
- Books.Refill_To=Total_Books_Refill;
- Books.Refill_Threshold=Total_Books_Threshold;
- }
- }