<?php
$maint_sch = new am_maintenance_schedule();
if (!empty($_GET['am_maintenance_schedule_id'])) {
 $am_maintenance_schedule_id_h = (is_array($_GET['am_maintenance_schedule_id'])) ? $_GET['am_maintenance_schedule_id'][0] : $_GET['am_maintenance_schedule_id'];
 $maint_sch->findBy_id($am_maintenance_schedule_id_h);
} else {
 $am_maintenance_schedule_id_h = null;
}

if (!empty($am_maintenance_schedule_id_h) && empty($am_ms_calendar_date_object)) {
 $am_ms_calendar_date_object = am_ms_calendar_date::find_by_parent_id($am_maintenance_schedule_id_h);
}

if (empty($am_ms_calendar_date_object)) {
 $am_ms_calendar_date_object = [new am_ms_calendar_date()];
}

$pageno = !empty($_GET['pageno']) ? $_GET['pageno'] : 1;
$per_page = !empty($_GET['per_page']) ? $_GET['per_page'] : 10;
$total_count = count($am_ms_calendar_date_object);
$pagination = new pagination($pageno, $per_page, $total_count);
$pagination->setProperty('_path', 'form');
$position = ($pageno - 1) * $per_page;

if (!empty($am_ms_calendar_date_object)) {
 foreach ($am_ms_calendar_date_object as &$object) {
  if (!empty($object->item_id_m)) {
   $item_i = item::find_by_item_id_m($object->item_id_m);
   $object->item_number = $item_i->item_number;
   $object->item_description = $item_i->item_description;
   $object->uom_id = $item_i->uom_id;
  } else {
   $object->item_number = null;
   $object->item_description = null;
   $object->uom_id = null;
  }
 }
}
?>