summaryrefslogtreecommitdiff
path: root/httemplate/browse/sched_item.html
blob: 372d4fd7e16663e77a2644f034f1d2d1824fd3cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<& elements/browse.html,
     'title'         => 'Installer schedules', #$sched_item_class->classname. ' schedules',
     'name_singular' => 'installer', #$sched_item_class->classname
     'query'         => { 'table' => 'sched_item' },
     'count_query'   => 'SELECT COUNT(*) FROM sched_item',
     'header'        => [ 'Installer', #$sched_item_class->classname
                          @dow,
                          'Overrides',
                        ],
     'fields'        => [ 'name',
                          ( map dow_factory($_), (0..6) ),
                          $override_sub,
                        ],
     'links'         => [ $link, ],
     'disableable'        => 1,
     'disabled_statuspos' => 1,
&>
<%init>

#XXX more specific AccessRight for scheduling
die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

my $link = [ $p.'edit/sched_item.html?', 'itemnum' ];

my @dow = qw( Sunday Monday Tuesday Wednesday Thursday Friday Saturday );

sub dow_factory {
  my $wday = shift;

  return sub {
     my $sched_item = shift;

     my @sched_avail = qsearch({
                         'table'   => 'sched_avail',
                         'hashref' => {
                           'itemnum'       => $sched_item->itemnum,
                           'wday'          => $wday, #thanks, closure
                           'override_date' => '',
                         },
                         'order_by' => 'ORDER BY stime',
                       });

    return 'Not available' unless @sched_avail;

    #data
    # align bgcolor colspan rowspan style valign width
    # link onclick size data_style   

    [
      map {
            [ { data=> $_->stime_pretty },
              { data=> '-', },
              { data=> $_->etime_pretty },
            ];
          }
        @sched_avail
    ];

  };

}

my $override_sub = sub {
  my $sched_item = shift;

   my @sched_avail = qsearch({
                       'table'   => 'sched_avail',
                       'hashref' => {
                         'itemnum'       => $sched_item->itemnum,
                         'override_date' => { op=>'!=', value=>'' },
                       },
                       'order_by' => 'ORDER BY override_date, stime',
                     });

  return 'None' unless @sched_avail;

  #XXX print each override date (and day of week)

};

</%init>