#!/usr/bin/perl

use strict;
use CGI;
use JSON;
use Storable qw (dclone);

use Opals::Context;
use Opals::Template qw(
    tmpl_read
    tmpl_write
    tmpl_rangedPageList
    tmpl_redirect
    tmpl_preference
);
use Opals::User qw(
    user_currentUserID
);
use Opals::Eq_SolrSearch;
use Opals::Eq_SolrIndex;

use Opals::Eq_Search qw(
    eq_category_getList
    eq_category_getListById
    eq_search_cat
    eq_search
    eq_search_countByCat
);
use Opals::Equipment qw(
    eq_record_doDelete
    eq_defItem_getList
    eq_defRecord_getList
    eq_itemFields
    eq_recordFields
);

use Opals::Eq_Circulation qw(
    circ_infoRecord
    circ_getItemStatus
);

use Opals::Locale qw(
    loc_getMsgFile
    loc_write
);

use Opals::Log;
use JSON;

my $dbh = Opals::Context->dbh();
END { $dbh->disconnect(); }

my $cgi = CGI->new;
my $input = $cgi->Vars();

my ($permission, $cookieList, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => 'eqmnt/search/srchPage.tmpl', #testing
        #tmplFile        => 'eqmnt/search/searchPage.tmpl',
    }
);

my $uIdInfo = user_currentUserID($dbh,$cgi);

open debug, ">/tmp/S";
print debug "input from searchPage 1:", to_json($input), "\n";
################################################################################
# Delete Record
#if ($permission && $ENV{'REQUEST_METHOD'} =~ m/^post$/i && $input->{'op'} eq 'delRec') {
if ($permission->{'eq_record_edit'} == 1 && $input->{'op'} eq 'delRec') {
    my $rid = $input->{'rid'};
    eq_record_doDelete($dbh, $rid) if ($rid ne '' && $rid > 0);
    my $eq_solr = Opals::Eq_SolrIndex->new(dbh=>$dbh);
    $eq_solr->eq_solrIndex_cleanByRId($rid);
    $eq_solr->eq_slr_updateIndex();
    my $log = Opals::Log->new(dbh=>$dbh);
    
    my $content_log = to_json($input, {pretty=>1});
    my $params = {
        module      => "eqmnt",
        uid         => $uIdInfo->{'uid'} || 0,
        sessionid   => $uIdInfo->{'sessionid'} || "",
        action      => "delete",
        content     => $content_log
    };
    $log->log($params);
    delete $input->{'rid'};
    delete $input->{'op'};
}

################################################################################
#
my $kw          = $input->{'kw'};
my $kw1         = $input->{'kw1'};
my $kw2         = $input->{'kw2'};
my $kw3         = $input->{'kw3'};
my $sfield      = $input->{'sfield'} || $input->{'field'} || 0;
my $sfield1     = $input->{'sfield1'} || 0;
my $sfield2     = $input->{'sfield2'} || 0;
my $sfield3     = $input->{'sfield3'} || 0;
my $cfield1     = $input->{'cfield1'} ;
my $cfield2     = $input->{'cfield2'} ;
my $exactmatch  = $input->{'exactmatch'} || 0;
my $sortAttr    = $input->{'sortAttr'};
my $sortOrder   = $input->{'sortOrder'};
my $buildingSel = $input->{'bldList'};
my $searchType  = $input->{'searchType'} || "simple";

    if (!$sortAttr){
       $input->{'sortAttr'} = $sortAttr = 'eq_name';
    }
    if (!defined $sortOrder || $sortOrder eq "") {
        $input->{'sortOrder'} = $sortOrder = 1;
    }
    #$input->{'exactmatch'} = $exactmatch;

my $cat         = $input->{'cat'} || 0;
my $searchByCat = $input->{'searchByCat'};
my $content_log = to_json($input, {pretty=>1});

my $pRange = 5;
#my $pSize = 10;
my $pSize = $input->{'pSize'} || 10;
my $curPage = $input->{'pNo'}||1;
if (!$input->{'pNo'} ){
  $input->{'pNo'}=1;
}
if (!$input->{'pSize'} ){
  $input->{'pSize'}=10;
}
if (!$input->{'field'} ){
  $input->{'field'}=$input->{'sfield'}||0;
}


my $offset;
($curPage && $curPage >= 1) || ($curPage = 1);
$offset = ($curPage - 1) * $pSize;

$input->{'offset'} = $offset;

my $srchCatId   = eq_category_getListById($dbh,$cat);
my $defList = _eq_definition_getList($dbh,$sfield);
my $sortFieldList = _eq_sortField_getList();
my $categoryList = _eq_category_getList($dbh);
my @cat1;
foreach my $c (@{$categoryList}){
    push @cat1,$c;
    foreach my $cc (@{$c->{'children'}}){
        push @cat1, $cc;
    }
}

my $catHash;
my $catSelected="";
foreach my $c (@cat1){
    $catHash->{$c->{'id'}} = $c->{'name'};
    $c->{'select'} = 0;
    if ($c->{'id'} == $cat){
        $c->{'select'} = 1;
        $catSelected = $c->{'name'};
    }
}

#my $displayStyle = (getSearchDisplayStyle($dbh) > 0)?"linear" : "record";
my $displayStyle = (getSearchDisplayStyle($dbh) > 0)?"barcode" : "record";

$input->{'displayStyle'} = $displayStyle;
my ($hits,$recList,$facetList) = (0,[],[]);
delete $input->{'rid'};
delete $input->{'op'};


print debug "input from searchPage:", to_json($input), "\n";
my $rs = do_SolrSearch($input);

($hits,$recList,$facetList) = ($rs->{'hits'},$rs->{'recordList'},$rs->{'facetList'});

my $categories;
my $category_facetList = [];
my $building_facetList = [];
foreach my $f (@{$facetList}){
    if ($f->{'field'} =~ m/building_facet/){
        $building_facetList = $f->{'facetList'};
    }
    elsif ($f->{'field'} =~ m/category_facet/){
        $category_facetList = $f->{'facetList'};
    }
}

foreach my $c (@$category_facetList){
    if ($c->{'field'} ne "" && $c->{'value'} > 0){
        $categories->{$c->{'field'}} = $c->{'value'};
    }
}

foreach my $c (@$categoryList) {
    $c->{'hasRec'} = 0;
    if ($categories->{$c->{'id'}} > 0){
        $c->{'hasRec'} = 1;
        $c->{'count'} = $categories->{$c->{'id'}};
    }
    $c->{'count'} = $categories->{$c->{'name'}};
    foreach my $cc (@{$c->{'children'}}){
        $cc->{'count'} = $categories->{$cc->{'id'}};
    }
}

print debug "rs", to_json($rs),"\n";

my $buildingList = _eq_building_getList($dbh);

my $building = {};

foreach my $bld (@{$buildingList}) {
    $bld->{'selected'} = 0;
    if ($bld->{'id'} eq $buildingSel){
        $bld->{'selected'} = 1;
    }
    $building->{$bld->{'id'}} = $bld->{'name'};
}
foreach my $b (@{$building_facetList}){
    $b->{'name'} = $building->{$b->{'field'}};
}
@{$building_facetList} = sort {$a->{'name'} cmp $b->{'name'}} @{$building_facetList};
my $recRsPos = $offset;
my $showOnSearchFieldList = getShowOnSearchFieldList($dbh);
foreach my $r (@{$recList}) {
    $r->{'eq_name'} = ($r->{'eq_name'} =~ /^ *$/)?$r->{'rid'}:$r->{'eq_name'};
    $r->{'fieldList'} = [];
    my $bName="";
    foreach my $f (@{$showOnSearchFieldList}){
        if ($f->{'id'} eq '18'){
            $bName = ($building->{$r->{$f->{'id'}}})?$building->{$r->{$f->{'id'}}}:"";
        }
        push @{$r->{'fieldList'}},{
            id      => ($f->{'id'} eq '18')?"Building Name": $f->{'name'},
            value   => ($f->{'id'} eq '18' && $bName ne "")? $r->{$f->{'id'}} . "-" . $bName :$r->{$f->{'id'}} 
        }
    }
    $r->{'recRsPos'}=$recRsPos++;
    my ($numTotal,$numLoan,$numReserve,$numHold,$itemList,$totalCirc,$totalMissing,$totalDamaged,$totalLost,$totalInRepair,$totalWeed,$totalNeverReturn,$qty)=circ_infoRecord($dbh,$r->{'rid'});
    $r->{'numTotal'}        = $numTotal;
    $r->{'numLoan'}         = $numLoan;
    $r->{'numLost'}         = $totalLost;
    $r->{'numDamaged'}      = $totalDamaged;
    $r->{'numMissing'}      = $totalMissing;
    $r->{'numInRepair'}     = $totalInRepair;
    $r->{'numWeed'}         = $totalWeed;
    $r->{'numReserve'}      = $numReserve;
    $r->{'numHold'}         = $numHold;
    $r->{'numReserveTotal'} = $numReserve + $numHold;
    $r->{'numAvailable'}    = $numTotal-$numLoan-$numHold-$totalMissing-$totalDamaged-$totalLost-$totalInRepair-$totalWeed-$totalNeverReturn;
    $r->{'available'}       = ($numTotal-$numLoan-$numHold-$totalMissing-$totalDamaged-$totalLost-$totalInRepair-$totalWeed,$totalNeverReturn)>0?"Available":"On Loan";
	  $r->{'recNoHolding'}    = $numTotal==0?1:0;
	  $r->{'qty'}    = $qty;
    my $itemStatusInfo;
    if ($displayStyle eq "linear"){
      $r->{'itemStatusInfo'} = circ_getItemStatus($dbh,{barcode=>$r->{'eq_barcode'}});
    }
}
my $result_json = to_json($recList, {pretty=>1});
my $defRecList = eq_defRecord_getList($dbh);
my $defItmList = eq_defItem_getList($dbh);

my $srchItmFieldShow=();
my $srchRecFieldShow=();
foreach my $f (@$showOnSearchFieldList){
  if ($f->{'defType'} eq 'record'){
      push @{$srchRecFieldShow},{
        id    => $f->{'id'},
        name  => $f->{'name'},
        idName=>$f->{'idName'},
        fieldType=>$f->{'fieldType'}
      };
  }
  if ($f->{'defType'} eq 'item' ){
      push @{$srchItmFieldShow},{
        id    => $f->{'id'},
        name  => $f->{'name'},
        idName=>$f->{'idName'},
        fieldType=>$f->{'fieldType'}
      };
  }
}

my $bldFieldList = [
    #{id=>'bldCode',  name=>"Building Code"} ,
    {id=>'bldName',  name=>"Building Name"} ,
    {id=>'bldAddress',name=>"Building Address"} ,
    {id=>'bldCity',   name=>"Building City"} ,
    {id=>'bldState',  name=>"Building State"} ,
]; 
my $searchFieldList = _getSearchFieldList();
close debug;
$template->param(
    kw              => $kw,
    kw1             => $kw1,
    kw2             => $kw2,
    kw3             => $kw3,
    pNum            => $curPage,
    sfield          => $sfield,
    sfield1         => $sfield1,
    sfield2         => $sfield2,
    sfield3         => $sfield3,
    hits            => $hits,
    recList         => $recList,
    listResult      => (scalar(@{$recList})>0)?1:0,
    hasNoResult     => ($kw ne "" && $hits <=0)?1:0,
    sortFieldList   => $sortFieldList,
    sortFields      => to_json($sortFieldList),
    buildingList    => $buildingList,
    buildingListJson=> to_json(_eq_building_getList($dbh)),
    hasMultiBlds    => scalar(@{$buildingList})>0?1:0,
    categoryGroup   => $categoryList,
    buildingFacetList=>$building_facetList,
    hasBuildingFacetList=>scalar(@{$building_facetList})>0?1:0,
    defRecList      => $defRecList,
    srchFieldShow   => to_json( {record=>$srchRecFieldShow, item=>$srchItmFieldShow}),
    fieldList       => to_json({record=>$defRecList , item=>$defItmList }),
    defItmList      => $defItmList,
    bldFieldList    => $bldFieldList,
    bldListJson     => to_json({hasMultiBlds=>scalar(@{$buildingList})>0?1:0, list=>$bldFieldList }),
    cat             => $cat,
    exactMatch      => $exactmatch,
    result_json     => $result_json,
    displayStyle    => $displayStyle, 
    showOnSearchFields=>$showOnSearchFieldList,
    searchType      => $searchType,
    searchByCat     => $searchByCat,
    pSize           => $pSize,
    loggedId        => $uIdInfo->{'uid'} || 0,
    searchFieldList => to_json($searchFieldList),
    srchParam       => to_json($input),
    categoryList    => to_json($categoryList),
    bldList         => to_json($buildingList)
);

writeSortParam2Tmpl();

my @rangedPageList = tmpl_rangedPageList($hits, $curPage, $pSize, $pRange);

my $recTo   = $offset + $pSize;
if ($recTo > $hits){
    $recTo = $hits
}
    my @defList1 =  @{dclone(\@{$defList})};
    my @defList2 =  @{dclone(\@{$defList})};
    my @defList3 =  @{dclone(\@{$defList})};
    foreach my $d (@defList1){
        if ($d->{'id'} eq $sfield1 ) {$d->{'selected'} = 1;}
    }
    foreach my $d (@defList2){
        if ($d->{'id'} eq $sfield2 ) {$d->{'selected'} = 1;}
    }
    foreach my $d (@defList3){
        if ($d->{'id'} eq  $sfield3 ) {$d->{'selected'} = 1;}
    }
    my @cfield1List = (
        {name => 'AND', value => 'and', selected=>0},
        {name => 'OR', value => 'or',   selected=>0},
        {name => 'NOT', value => 'not', selected=>0},
    );
    my @cfield2List = (
        {name => 'AND', value => 'and',selected=>0},
        {name => 'OR', value => 'or' , selected=>1},
        {name => 'NOT', value => 'not',selected=>0},
    );
    if ($input->{'cfield1'} && $input->{'cfield1'} ne "") { 
        foreach my $c(@cfield1List){
            $c->{'selected'} = 0;
            if ($input->{'cfield1'} && $input->{'cfield1'} eq $c->{'value'}){$c->{'selected'} = 1};
        }
    }
    if ($input->{'cfield2'} && $input->{'cfield2'} ne "") {
        foreach my $c(@cfield2List){
            $c->{'selected'} = 0;
            if ($input->{'cfield2'} && $input->{'cfield2'} eq $c->{'value'}){$c->{'selected'} = 1};
        }
    }

$template->param(
    defList         =>  $defList,
    defList1        =>  \@defList1,
    defList2        =>  \@defList2,
    defList3        =>  \@defList3,
    cfield1List     => \@cfield1List,
    cfield2List     => \@cfield2List,
    recFrom         =>  $offset + 1,
    recTo           =>  $recTo,
    rangedPageList  =>  \@rangedPageList,
);

if ($permission && $permission->{'eq_report'}) {
  $template->param(    eq_report      => 1);
}
if ($permission && $permission->{'eq_record_edit'}) {
  $template->param(    eq_record_edit      => 1);

}
my $msgValMap={} ;
my $stdMsgMap  =loc_getMsgFile('/search/standard.msg',$msgValMap);
loc_write($template,$stdMsgMap);
tmpl_write($dbh, $cgi, $cookieList, $template);

#-----------------------------------------------------------------------
sub writeSortParam2Tmpl{
    
    $template->param(
        sortOrder       => $sortOrder,
        sortAttr        => $sortAttr,
        sortDown        => ($sortOrder && $sortOrder == 1)  ? 1 : 0 ,
    );
}

sub _eq_definition_getList {
    my ($dbh,$sf) = @_;
    #my $sql = "select id,defType,name from eq_def order by name";
    #my $sth = $dbh->prepare($sql);
    #$sth->execute();
    my @retList = ();
    @retList = (
        {id=> "eq_barcode", defType=>"record",name=>"Barcode", selected=>0},
        {id=> "5", defType=>"item", name=>"Serial#", selected=>0},
        {id=> "48", defType=>"item", name=>"Accessories", selected=>0},
        {id=> "40", defType=>"item", name=>"Assigned Person First Name", selected=>0},
        {id=> "41", defType=>"item", name=>"Assigned Person Last Name", selected=>0},
        {id=> "18", defType=>"item", name=>"Building Code", selected=>0},
        {id=> "46", defType=>"item", name=>"Cart Number", selected=>0},
        {id=> "categorySrch", defType=>"record", name=>"Category", selected=>0},
        {id=> "31", defType=>"item", name=>"Date Acquired/Assigned/Install", selected=>0},
        {id=> "26", defType=>"item", name=>"District Code", selected=>0},
        {id=> "7", defType=>"item", name=>"District inventory #", selected=>0},
        {id=> "eq_name", defType=>"record",name=>"Equipment Name", selected=>0},
        {id=> "9", defType=>"item", name=>"Funding Source", selected=>0},
        {id=> "36", defType=>"record", name=>"General Accessories Notes", selected=>0},
        {id=> "33", defType=>"record", name=>"General Notes", selected=>0},
        {id=> "43", defType=>"item", name=>"IP Address", selected=>0},
        {id=> "8", defType=>"item",name=>"Item Designation", selected=>0},
        {id=> "38", defType=>"item", name=>"Items Status Notes", selected=>0},
        {id=> "typeId", defType=>"item",name=>"Item Type", selected=>0},
        {id=> "11", defType=>"item", name=>"Location in building", selected=>0},
        {id=> "44", defType=>"item", name=>"MAC Address", selected=>0},
        {id=> "37", defType=>"item", name=>"Machine Name", selected=>0},
        {id=> "1", defType=>"record", name=>"Manufacturer", selected=>0},
        {id=> "16", defType=>"record", name=>"Manufacturer URL", selected=>0},
        {id=> "3", defType=>"record", name=>"Model", selected=>0},
        {id=> "28", defType=>"record", name=>"Online Manual", selected=>0},
        {id=> "42", defType=>"item", name=>"P.O. Number", selected=>0},
        {id=> "6", defType=>"item", name=>"Price ", selected=>0},
        {id=> "rid", defType=>"record", name=>"Record ID", selected=>0},
        {id=> "47", defType=>"item", name=>"Slot Number", selected=>0 },
        {id=> "45", defType=>"item", name=>"Software Key", selected=>0 },
        {id=> "27", defType=>"record", name=>"Supplier URL ", selected=>0 },
        {id=> "39", defType=>"item", name=>"Vendor Name", selected=>0 },
        {id=> "14", defType=>"record", name=>"Warranty Notes", selected=>0 },
    );
    foreach my $r(@retList) {
        if ($r->{'id'} eq $sf){
            $r->{'selected'} = 1;
        }
    }
    return \@retList;
}

sub _eq_sortField_getList {

    my @retList = ();
    @retList = (
        {id=>'eq_name',name=>'Equipment Name' },
        {id=>'1',name=>'Manufacturer' },
        {id=>'3',name=>'Model' },
    );
    foreach my $s(@retList) {
        if ($s->{'id'} eq $sortAttr){
            $s->{'selected'} = 1;
        }
    }
    return \@retList;
}

sub do_SolrSearch {
    my ($input) = @_;
    return undef if ($input->{'kw'} eq "" && $input->{'kw1'} eq "" && $input->{'kw2'} eq "" && $input->{'kw3'} eq "");
    if ($input->{'displayStyle'} eq 'linear'){
        $input->{'groupBy'} = 'barcode';
    }
    print debug "input >> ",to_json($input,{pretty=>1}),"\n";
    my $eq_solr = Opals::Eq_SolrSearch->new(dbh=>$dbh);
    my $lQuery = $eq_solr->eq_slr_srchQuery($input); 
    print debug "lQuer:$lQuery \n";
    my $params={
        lQuery=>$lQuery,
        displayStyle=>$input->{'displayStyle'},
    };
    my $rs = $eq_solr->eq_slr_search($params); #
    $input->{'hits'} = $rs->{'hits'};
    my $content_log = to_json($input, {pretty=>1});
    my $log = Opals::Log->new(dbh=>$dbh);
    my $params = {
        module      => "eqmnt",
        uid         => $uIdInfo->{'uid'} || 0,
        sessionid   => $uIdInfo->{'sessionid'} || "",
        action      => "search",
        content     => $content_log
    };
    $log->log($params);
    return $rs ;
}

=item
sub do_SolrSearch1 {
    my ($input) = @_;
    return undef if ($input->{'kw'} eq "" && $input->{'kw1'} eq "" && $input->{'kw2'} eq "" && $input->{'kw3'} eq "");
   
    if ($input->{'displayStyle'} eq 'linear'){
        $input->{'groupBy'} = 'barcode';
    }
    print debug "input>>",to_json($input,{pretty=>1}),"\n";
    my $eq_solr = Opals::Eq_SolrSearch->new(dbh=>$dbh);
    #my $lQuery = $eq_solr->eq_slr_buildSearchQuery($input);
    my $lQuery = $eq_solr->eq_slr_buildSrchQueryJson($input);
    print debug "lQuer:$lQuery \n";
    my $params={
        lQuery=>$lQuery,
        displayStyle=>$input->{'displayStyle'},
    };
    my $rs = $eq_solr->eq_slr_searchJson($params);
    $input->{'hits'} = $rs->{'hits'};
    my $content_log = to_json($input, {pretty=>1});
    my $log = Opals::Log->new(dbh=>$dbh);
    my $params = {
        module      => "eqmnt",
        uid         => $uIdInfo->{'uid'} || 0,
        sessionid   => $uIdInfo->{'sessionid'} || "",
        action      => "search",
        content     => $content_log
    };
    $log->log($params);
    return $rs ;
}
=cut

sub _eq_category_getList {
    my ($dbh) = @_;
    my @catList;
    my $sql = "select * from eq_category where parentId=0 order by name";
    my $sth = $dbh->prepare($sql);
    $sth->execute();
    my $subsql = "select * from eq_category where parentId=? order by name";
    my $sth_sub = $dbh->prepare($subsql);
    while ( my $rec = $sth->fetchrow_hashref){
        $sth_sub->execute($rec->{'id'});
        $rec->{'hasChild'} = 0;
        while(my $c = $sth_sub->fetchrow_hashref){
            $rec->{'hasChild'} = 1;
            push @{$rec->{'children'}}, $c;
        }
        push @catList,$rec;
    }
    $sth->finish;
    $sth_sub->finish;
    return \@catList;
}

sub _eq_building_getList {
    my ($dbh) = @_;
    my @list =();
    my $sql = 
    my $sql = (<<_SQL_) ;
select count(*) as count, sfValue as id, l.name as name 
from eq_itemFields f inner join eq_locationDirectory l on (BINARY l.code= BINARY f.sfValue) 
where f.sfId=18 group by f.sfValue 
    having count>0 
    order by l.name
_SQL_
    my $sth = $dbh->prepare($sql);
    $sth->execute();
    while(my $rec = $sth->fetchrow_hashref) {
        push @list, $rec;
    }
    $sth->finish;
    return \@list;
}

sub getShowOnSearchFieldList {
    my ($dbh) = @_;
    my $sth = $dbh->prepare("select id,name,idName,fieldType,defType, showOnSearch from eq_def where showOnSearch=1");
    my @list;
    $sth->execute();
    while (my $f = $sth->fetchrow_hashref()) {
        push @list, $f;
    }
    return \@list;
}

sub getSearchDisplayStyle {
    #display record type or linear (for detroit..)
    my ($dbh) = @_;
    my $sth = $dbh->prepare("select count(*) from eq_def where showOnSearch=1 && defType ='item'");
    $sth->execute();
    my $ret = $sth->fetchrow_array();
    $sth->finish;
    if (!$ret){
        return 0;
    }
    return $ret;
}

sub _getSearchFieldList {
  my $itemFields = _eq_itemFields();
  my $recordFields = _eq_recordFields();
  my $ret;
  foreach my $f (@$itemFields,@{$recordFields}) {
    push @{$ret},{
      "id"    => $f->{'id'},
      "name"  => $f->{'name'},
      "idName"=> $f->{'idName'},
      "value" => $f->{'idName'}
    }
  }
  return $ret;
}


sub _eq_itemFields {
  my @retList =  ();
  @retList = (
    {"id"=>"eq_barcode","idName"=>"eq_barcode","name"=>"Barcode","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"copyNumber","idName"=>"copyNumber","name"=>"Copy Number","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"typeId","idName"=>"typeId","name"=>"Item Type","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"5","idName"=>"serialNumber","name"=>"Serial Number","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"42","idName"=>"purchaseOrder","name"=>"Purchase Order","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"6","idName"=>"price","name"=>"Price","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"43","idName"=>"ipAddress","name"=>"IP Address","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"44","idName"=>"macAddress","name"=>"MAC Address","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"45","idName"=>"softwareKey","name"=>"Software Key","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"46","idName"=>"cartNumber","name"=>"Cart Number","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"47","idName"=>"slotNumber","name"=>"Slot Number","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"48","idName"=>"accessories","name"=>"Accessories","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"9","idName"=>"fundingSource","name"=>"Funding Source","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"26","idName"=>"districtCode","name"=>"District Code","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"18","idName"=>"buildingCode","name"=>"Building Code","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"11","idName"=>"location","name"=>"Location","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"31","idName"=>"dateAcquired","name"=>"Date Acquired/Assigned/Install","description"=>"","dataType"=>"date","authCtrl"=>"0","size"=>50 },
    {"id"=>"7","idName"=>"districtInventoryNumber","name"=>"District Inventory Number","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50},
    {"id"=>"38","idName"=>"statusNote","name"=>"Item Status Note","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"37","idName"=>"machineName","name"=>"Machine Name","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"39","idName"=>"vendorName","name"=>"Vendor Name","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"40","idName"=>"assignedPersonFirstName","name"=>"Assigned Person First Name","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"41","idName"=>"assignedPersonLastName","name"=>"Assigned Person Last Name","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"8","idName"=>"itemDesignation","name"=>"Item Designation","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
  );
  return \@retList;
}
sub _eq_recordFields {
  my @retList = ();
  @retList = (
    {"id"=>"eq_name","idName"=>"eq_name","name"=>"Equipment","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"category","idName"=>"category","name"=>"Category","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"1","idName"=>"manufacturer","name"=>"Manufacturer","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"3","idName"=>"model","name"=>"Model","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"14","idName"=>"warrantyNote","name"=>"Warranty Note","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"16","idName"=>"manufacturerUrl","name"=>"Manufacturer Url","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"28","idName"=>"manualUrl","name"=>"Manual Url","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"27","idName"=>"supplierUrl","name"=>"Supplier Url","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"33","idName"=>"generalNote","name"=>"General Note","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
    {"id"=>"36","idName"=>"generalAccessoriesNote","name"=>"General Accessories Note","description"=>"","dataType"=>"text","authCtrl"=>"0","size"=>50 },
  );
  return \@retList;
}



