<?php

if (!empty($_GET['inv_count_header_id'])) {
 $inv_count_header_id_h = (is_array($_GET['inv_count_header_id'])) ? $_GET['inv_count_header_id'][0] : $_GET['inv_count_header_id'];
 $inv_count_h = inv_count_header::find_by_id($inv_count_header_id_h);
 $$class->count_name = $inv_count_h->count_name;
 $$class->org_id = $inv_count_h->org_id;
 $$class->adjustment_ac_id = $inv_count_h->adjustment_ac_id;
 $$class->counted_by = $session->username;
} else {
 $inv_count_header_id_h = null;
}

if (!empty($_GET['inv_count_header_id']) ) {
 $date_i = !empty($_GET['count_date']) ? $_GET['count_date'] : current_time(true);
 $inv_count_schedule_object = inv_count_schedule::find_by_headerId_date_status($_GET['inv_count_header_id'],$date_i);
}

if (empty($inv_count_schedule_object)) {
 $inv_count_schedule_object = [new inv_count_schedule()];
}

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

if (!empty($inv_count_schedule_object)) {
 foreach ($inv_count_schedule_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;
  }
 }
}


if (!empty($_GET['count_date']) && empty($$class->count_date) ){
 $$class->count_date = $_GET['count_date'];
}
?>