| 1 | rodolico | 1 | --
 | 
        
           |  |  | 2 | -- Table structure for table `maintenance_schedule`
 | 
        
           |  |  | 3 | --
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | DROP TABLE IF EXISTS `maintenance_schedule`;
 | 
        
           |  |  | 6 | CREATE TABLE `maintenance_schedule` (
 | 
        
           |  |  | 7 |   `maintenance_schedule_id` int(10) unsigned NOT NULL auto_increment,
 | 
        
           |  |  | 8 |   `device_id` int(10) unsigned NOT NULL COMMENT 'The device this task is due on' references device(device_id),
 | 
        
           |  |  | 9 |   `maintenance_task_id` int(10) unsigned NOT NULL COMMENT 'The task to be performed' references maintenance_task(maintenance_task_id),
 | 
        
           |  |  | 10 |   `schedule` int(10) unsigned NOT NULL COMMENT 'The number of days between performance of this task',
 | 
        
           |  |  | 11 |   `login_id` int(10) unsigned default NULL COMMENT 'Login ID of the persion who is generally responsible for this maintenance' references login(login_id),
 | 
        
           |  |  | 12 |   `added_date` datetime default NULL,
 | 
        
           |  |  | 13 |   `removed_date` datetime default NULL,
 | 
        
           |  |  | 14 |   PRIMARY KEY  (`maintenance_schedule_id`)
 | 
        
           |  |  | 15 | ) COMMENT='Holds a list of maintenance to be performed on a device';
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | --
 | 
        
           |  |  | 18 | -- Table structure for table `maintenance_performed`
 | 
        
           |  |  | 19 | --
 | 
        
           |  |  | 20 |   | 
        
           |  |  | 21 | DROP TABLE IF EXISTS `maintenance_performed`;
 | 
        
           |  |  | 22 | CREATE TABLE `maintenance_performed` (
 | 
        
           |  |  | 23 |   `maintenance_performed_id` int(10) unsigned NOT NULL auto_increment,
 | 
        
           |  |  | 24 |   `device_id` int(10) unsigned NOT NULL COMMENT 'The device this task is due on' references device(device_id),
 | 
        
           |  |  | 25 |   `maintenance_task_id` int(10) unsigned NOT NULL COMMENT 'The task to be performed' references maintenance_task(maintenance_task_id),
 | 
        
           |  |  | 26 |   `maintenance_date` datetime NOT NULL COMMENT 'Date and Time maintenance was performed',
 | 
        
           |  |  | 27 |   `notes` text COMMENT 'Any comments/notes the maintainer wants to put in',
 | 
        
           |  |  | 28 |   `login_id` int(10) unsigned NOT NULL COMMENT 'login id of the person performing the maintenance',
 | 
        
           |  |  | 29 |   PRIMARY KEY  (`maintenance_performed_id`)
 | 
        
           |  |  | 30 | ) COMMENT='This holds the actual maintenance records';
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | --
 | 
        
           |  |  | 33 | -- Table structure for table `maintenance_task`
 | 
        
           |  |  | 34 | --
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 | DROP TABLE IF EXISTS `maintenance_task`;
 | 
        
           |  |  | 37 | CREATE TABLE `maintenance_task` (
 | 
        
           |  |  | 38 |   `maintenance_task_id` int(10) unsigned NOT NULL auto_increment,
 | 
        
           |  |  | 39 |   `description` varchar(64) default NULL COMMENT 'A description of the task',
 | 
        
           |  |  | 40 |   `default_period` int(11) default NULL COMMENT 'The default number of days between maintenance',
 | 
        
           |  |  | 41 |   `notes` text COMMENT 'Detailed instructions on completing task',
 | 
        
           |  |  | 42 |   `added_date` datetime default NULL,
 | 
        
           |  |  | 43 |   `removed_date` datetime default NULL,
 | 
        
           |  |  | 44 |   PRIMARY KEY  (`maintenance_task_id`)
 | 
        
           |  |  | 45 | ) COMMENT='Holds a list of tasks available to assign for maintnenance o';
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 | /* create some keys */
 | 
        
           |  |  | 48 | alter table maintenance_performed add index (login_id);
 | 
        
           |  |  | 49 | alter table maintenance_performed add index (maintenance_task_id);
 | 
        
           |  |  | 50 | alter table maintenance_performed add index (maintenance_date);
 | 
        
           |  |  | 51 | alter table maintenance_performed add index (device_id);
 | 
        
           |  |  | 52 | alter table maintenance_task add index (removed_date);
 | 
        
           |  |  | 53 | alter table maintenance_schedule add index (removed_date);
 | 
        
           |  |  | 54 | alter table maintenance_schedule add index (login_id);
 | 
        
           |  |  | 55 | alter table maintenance_schedule add index (device_id);
 | 
        
           |  |  | 56 | alter table maintenance_schedule add index (maintenance_task_id);
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'Maintenance', 'modules/maintenance/', now() );
 | 
        
           | 49 | rodolico | 59 | /* add maintenance report */
 | 
        
           |  |  | 60 | insert into _system( group_name,key_name,theValue,added_date ) values ( 'device view', 'Maintenance', 'callable.php:maintenanceView', now() );
 | 
        
           | 1 | rodolico | 61 |   | 
        
           |  |  | 62 | insert into menu( url, caption, parent_id) values ('', 'Maintenance', null);
 | 
        
           |  |  | 63 | insert into menu( url,caption,parent_id) select '/modules/maintenance/do_maintenance.html','Scheduled Maintenance',menu_id from menu where caption = 'Maintenance';
 | 
        
           |  |  | 64 | insert into menu( url,caption,parent_id) select '/modules/maintenance/unscheduled_maintenance.html','Unscheduled Maintenance',menu_id from menu where caption = 'Maintenance';
 | 
        
           |  |  | 65 | insert into menu( url,caption,parent_id) select '/modules/maintenance/edit_schedule.html','Edit Schedules',menu_id from menu where caption = 'Maintenance';
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 | /* Maintenance Due Report */
 | 
        
           |  |  | 69 | insert into report ( name, query, parameters ) values ('Maintenance Due','select concat( client.name, \' Site \', site.name ) \"Site\",
 | 
        
           |  |  | 70 |       device.name \"Device Name\",
 | 
        
           |  |  | 71 |       maintenance_task.description \"Task\",
 | 
        
           |  |  | 72 |       DATEDIFF(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY), now()) \"Due\",
 | 
        
           |  |  | 73 |       DATE(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY)) \"Date Due\",
 | 
        
           |  |  | 74 |       login.email \"Technician\"
 | 
        
           |  |  | 75 | from maintenance_schedule join maintenance_performed on 
 | 
        
           |  |  | 76 |             maintenance_performed.maintenance_task_id = maintenance_schedule.maintenance_task_id
 | 
        
           |  |  | 77 |             and maintenance_performed.device_id = maintenance_schedule.device_id
 | 
        
           |  |  | 78 |    join login on login.login_id = maintenance_schedule.login_id
 | 
        
           |  |  | 79 |    join maintenance_task on maintenance_task.maintenance_task_id = maintenance_schedule.maintenance_task_id
 | 
        
           |  |  | 80 |    join device on maintenance_schedule.device_id = device.device_id
 | 
        
           |  |  | 81 |    join site on device.site_id = site.site_id
 | 
        
           |  |  | 82 |    join client on site.client_id = client.client_id
 | 
        
           |  |  | 83 | where device.removed_date is null
 | 
        
           |  |  | 84 |       and site.removed_date is null
 | 
        
           |  |  | 85 |       and client.removed_date is null
 | 
        
           |  |  | 86 |       and maintenance_schedule.removed_date is null
 | 
        
           |  |  | 87 |       and DATE(DATE_ADD(maintenance_performed.maintenance_date, INTERVAL schedule DAY)) <= <maintenancedate>
 | 
        
           |  |  | 88 |       and maintenance_performed.maintenance_performed_id in (
 | 
        
           |  |  | 89 |                select max(maintenance_performed_id) 
 | 
        
           |  |  | 90 |                from maintenance_performed 
 | 
        
           |  |  | 91 |                group by device_id,maintenance_task_id
 | 
        
           |  |  | 92 |             )
 | 
        
           |  |  | 93 | order by client.name,site.name,device.name, maintenance_task.description;
 | 
        
           |  |  | 94 | ','maintenancedate++Report Date++++');
 | 
        
           |  |  | 95 |   | 
        
           |  |  | 96 | /* Maintenance Performed on a device */
 | 
        
           |  |  | 97 |   | 
        
           |  |  | 98 | insert into report ( name, query, parameters ) values ('Device Maintenance Record','select maintenance_task.description \"Task\",
 | 
        
           |  |  | 99 |          DATE(maintenance_performed.maintenance_date) \"Date\",
 | 
        
           |  |  | 100 |          maintenance_performed.notes \"Notes\",
 | 
        
           |  |  | 101 |          login.email \"Technician\"
 | 
        
           |  |  | 102 | from maintenance_performed join device using (device_id)
 | 
        
           |  |  | 103 |    join maintenance_task using (maintenance_task_id)
 | 
        
           |  |  | 104 |    join login using (login_id)
 | 
        
           |  |  | 105 |    join site using (site_id)
 | 
        
           |  |  | 106 |    join client using (client_id)
 | 
        
           |  |  | 107 | where device.device_id = <device>','device++Choose Device++select distinct device.device_id, concat( client.name, \' - \',device.name) \"Device\"from device join site using (site_id) join client using (client_id) join maintenance_performed using (device_id)order by concat( client.name, \' - \',device.name)++select concat( client.name, \' - \',device.name) \"Device\" from device join site using (site_id) join client using (client_id)where device.device_id = <value>');
 | 
        
           |  |  | 108 |   | 
        
           |  |  | 109 | /* Maintenance performed in a period of time */
 | 
        
           |  |  | 110 |   | 
        
           |  |  | 111 | insert into report ( name, query, parameters ) values ('Maintenance Performed in Period','select   client.name \"Client\",
 | 
        
           |  |  | 112 |          device.name \"Device Name\",
 | 
        
           |  |  | 113 |          maintenance_task.description \"Task\",
 | 
        
           |  |  | 114 |          DATE(maintenance_performed.maintenance_date) \"Date\",
 | 
        
           |  |  | 115 |          maintenance_performed.notes \"Notes\",
 | 
        
           |  |  | 116 |          login.email \"Technician\"
 | 
        
           |  |  | 117 | from maintenance_performed join device on maintenance_performed.device_id = device.device_id
 | 
        
           |  |  | 118 |    join maintenance_task on maintenance_task.maintenance_task_id = maintenance_performed.maintenance_task_id
 | 
        
           |  |  | 119 |    join login on login.login_id = maintenance_performed.login_id
 | 
        
           |  |  | 120 |    join site on device.site_id = site.site_id
 | 
        
           |  |  | 121 |    join client on client.client_id = site.client_id
 | 
        
           |  |  | 122 | where DATE(maintenance_performed.maintenance_date) >= <start_date>
 | 
        
           |  |  | 123 |    and DATE(maintenance_performed.maintenance_date) <= <end_date>
 | 
        
           |  |  | 124 | order by DATE(maintenance_performed.maintenance_date), client.name,site.name,device.name
 | 
        
           |  |  | 125 | ','start_date++Starting Date++++
 | 
        
           |  |  | 126 | end_date++Ending Date++++');
 |