function generateSquareFormat(listOfMaintenanceEventDates, currentYearToCheck) {
  // Build month format array
  let monthFormatArray = [
    "01",
    "02",
    "03",
    "04",
    "05",
    "06",
    "07",
    "08",
    "09",
    "10",
    "11",
    "12"
  ];
  // init array for pushing result format
  let monthSquareFormat = [];

  // Iterate through month format array (once for each month) to check if occurence of event within month
  for (let i = 0; i < monthFormatArray.length; i++) {
    // Form date based on current month
    var currentDateToCheck = moment(
      new Date(monthFormatArray[i] + "/01/" + currentYearToCheck)
    );
    // Init variables with start values
    let numberOfEvents = 0;
    let scheduledEvent = false;
    let status = false;
    var result = {};
    var foundEventId;

    // Iterate through list of maintenance event dates checking if there's a match with the current month we are checking
    for (let i = 0; i < listOfMaintenanceEventDates.length; i++) {
      // If the current date to check is within same month as event

      // If the the current date to check is in the same month as the current maintenance date
      if (
        currentDateToCheck.isSame(
          listOfMaintenanceEventDates[i].date_scheduled,
          "month"
        )
      ) {
        // Increment number of events by 1
        numberOfEvents += 1;

        // If it's a scheduled event. mark scheduled event true
        if (listOfMaintenanceEventDates[i].scheduled) {
          // Set scheduled event to true and record status
          scheduledEvent = true;
          status = listOfMaintenanceEventDates[i].status;
          foundEventId = listOfMaintenanceEventDates[i].event_id;
        }
      }
      // Create record
      result = {
        numberOfEvents: numberOfEvents,
        scheduledEvent: scheduledEvent,
        status: status,
        foundEventId: foundEventId
      };
    }
    // Push result for current month into result
    monthSquareFormat.push(result);
    // Reset variables for loop refresh
    numberOfEvents = 0;
    scheduledEvent = false;
    status = false;
    result = {};
    foundEventId = false;
  }

  return monthSquareFormat;
}
// Generates square based on maintenance event forecast input
Generates square based on maintenance event forecast input
Generates square based on maintenance event forecast input
function generateSquareFormat(listOfMaintenanceEventDates, currentYearToCheck) {
  let monthFormatArray = [
    "01",
    "02",
    "03",
    "04",
    "05",
    "06",
    "07",
    "08",
    "09",
    "10",
    "11",
    "12"
  ];
  let monthSquareFormat = [];
  for (let i = 0; i < monthFormatArray.length; i++) {
    var currentDateToCheck = moment(
      new Date(monthFormatArray[i] + "/01/" + currentYearToCheck)
    );
    let numberOfEvents = 0;
    let scheduledEvent = false;
    let status = false;
    var result = {};
    var foundEventId;
    for (let i = 0; i < listOfMaintenanceEventDates.length; i++) {
      if (
        currentDateToCheck.isSame(
          listOfMaintenanceEventDates[i].date_scheduled,
          "month"
        )
      ) {
        numberOfEvents += 1;
        if (listOfMaintenanceEventDates[i].scheduled) {
          scheduledEvent = true;
          status = listOfMaintenanceEventDates[i].status;
          foundEventId = listOfMaintenanceEventDates[i].event_id;
        }
      }
      result = {
        numberOfEvents: numberOfEvents,
        scheduledEvent: scheduledEvent,
        status: status,
        foundEventId: foundEventId
      };
    }
    monthSquareFormat.push(result);
    numberOfEvents = 0;
    scheduledEvent = false;
    status = false;
    result = {};
    foundEventId = false;
  }
  return monthSquareFormat;
}
function generateSquareFormat ( listOfMaintenanceEventDates , currentYearToCheck ) { let monthFormatArray = [ "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" ] ; let monthSquareFormat = [ ] ; for ( let i = 0 ; i < monthFormatArray . length ; i ++ ) { var currentDateToCheck = moment ( new Date ( monthFormatArray [ i ] + "/01/" + currentYearToCheck ) ) ; let numberOfEvents = 0 ; let scheduledEvent = false ; let status = false ; var result = { } ; var foundEventId ; for ( let i = 0 ; i < listOfMaintenanceEventDates . length ; i ++ ) { if ( currentDateToCheck . isSame ( listOfMaintenanceEventDates [ i ] . date_scheduled , "month" ) ) { numberOfEvents += 1 ; if ( listOfMaintenanceEventDates [ i ] . scheduled ) { scheduledEvent = true ; status = listOfMaintenanceEventDates [ i ] . status ; foundEventId = listOfMaintenanceEventDates [ i ] . event_id ; } } result = { numberOfEvents : numberOfEvents , scheduledEvent : scheduledEvent , status : status , foundEventId : foundEventId } ; } monthSquareFormat . push ( result ) ; numberOfEvents = 0 ; scheduledEvent = false ; status = false ; result = { } ; foundEventId = false ; } return monthSquareFormat ; }
Generates square based on maintenance event forecast input
Generates square based on maintenance event forecast input
// Build month format array // init array for pushing result format // Iterate through month format array (once for each month) to check if occurence of event within month // Form date based on current month // Init variables with start values // Iterate through list of maintenance event dates checking if there's a match with the current month we are checking // If the current date to check is within same month as event // If the the current date to check is in the same month as the current maintenance date // Increment number of events by 1 // If it's a scheduled event. mark scheduled event true // Set scheduled event to true and record status // Create record // Push result for current month into result // Reset variables for loop refresh