<?php
    class HOME_TICKET extends HOME
    {
        public function home_ticket_javainit()
        {

        }

        public function fn_ticket_init()
        {
            if(isset($_REQUEST['task'])){$task=trim(strtolower($_REQUEST['task']));}
            if(isset($_POST['task'])){$task=trim(strtolower($_POST['task']));}
            if($_REQUEST||$_POST){if($_REQUEST['sec']||$_POST['sec']){$task=$this->dec($task);}}

            switch($task)
            {
                case "default":
                    $this->fn_default_sum();
                break;

                case $task:
                    $task="fn_".$task;
                    if(method_exists($this,$task)){$this->$task();}
                break;

                default:
                    $this->fn_default_sum();
                break;
            }
        }
        
        public function fn_default_sum()
        {
            echo $this->FN_CREATEHEADER();

            echo "<style>
                       .besidebtnsave {margin-left:80px;margin-top:-6px;position:absolute;}
                  </style>";
            echo "<script>
                       var myForm,myFormsearch,dgtra;
                       function initObject()
                       {";
                            $qry="select datasets,startvalue,stepvalue,endvalue from ".DB_APORTIL.".tbl_chart_trendsum
                                  where modules='hometicketperformance' and isdeleted=0 order by id desc limit 1";
                            $spval=$this->fn_get_fieldsvalues("datasets,startvalue,stepvalue,endvalue",$qry);
                            $datasets=$spval[0];$startvalue=$spval[1];$stepvalue=$spval[2];$endvalue=$spval[3];
//            echo "          var datasets = [
//                                { sitedown:\"20\", mainsfail:\"35\", alarm3G:\"35\", alarm4G:\"15\", totalticket:\"55\", year:\"Jan\" },
//                                { sitedown:\"20\", mainsfail:\"35\", alarm3G:\"35\", alarm4G:\"35\", totalticket:\"55\", year:\"Feb\" },
//                                { sitedown:\"40\", mainsfail:\"24\", alarm3G:\"35\", alarm4G:\"25\", totalticket:\"40\", year:\"Mar\" },
//                                { sitedown:\"44\", mainsfail:\"20\", alarm3G:\"35\", alarm4G:\"5\", totalticket:\"27\", year:\"Apr\" },
//                                { sitedown:\"23\", mainsfail:\"50\", alarm3G:\"35\", alarm4G:\"56\", totalticket:\"43\", year:\"May\" },
//                                { sitedown:\"21\", mainsfail:\"36\", alarm3G:\"35\", alarm4G:\"23\", totalticket:\"31\", year:\"Jun\" },
//                                { sitedown:\"50\", mainsfail:\"40\", alarm3G:\"35\", alarm4G:\"12\", totalticket:\"56\", year:\"Jul\" },
//                                { sitedown:\"30\", mainsfail:\"65\", alarm3G:\"35\", alarm4G:\"33\", totalticket:\"75\", year:\"Aug\" },
//                                { sitedown:\"90\", mainsfail:\"62\", alarm3G:\"35\", alarm4G:\"20\", totalticket:\"55\", year:\"Sep\" },
//                                { sitedown:\"55\", mainsfail:\"40\", alarm3G:\"35\", alarm4G:\"10\", totalticket:\"60\", year:\"Oct\" },
//                                { sitedown:\"72\", mainsfail:\"45\", alarm3G:\"35\", alarm4G:\"14\", totalticket:\"54\", year:\"Nov\" },
//                                { sitedown:\"72\", mainsfail:\"45\", alarm3G:\"35\", alarm4G:\"13\", totalticket:\"54\", year:\"Dec\" }
//                            ];";
                            
            echo "          var datasets=$datasets;
                            var barChart1 =  new dhtmlXChart({
                                view:\"bar\",
                                container:\"div_ticketbaralarm\",
                                value:\"#T1#\",
                                color: \"#58dccd\",
                                gradient:\"rising\",
                                tooltip:{
                                    template:\"#T1#\"
                                },
                                width:10,
                                tooltip:{
                                    template:\"#T1#\"
                                },
                                xAxis:{
                                    template:\"'#mon#\"
                                },
                                yAxis:{
                                    start:$startvalue,
                                    step:$stepvalue,
                                    end:$endvalue
                                },
                                legend:{
                                    values:[
                                              {text:\"SiteDown\",color:\"#58dccd\"},
                                              {text:\"Mainsfails\",color:\"#a7ee70\"},
                                              {text:\"alarm3G\",color:\"#2980b9\"},
                                              {text:\"alarm4G\",color:\"#1abc9c\"},
                                              {text:\"Total Ticket\",color:\"#36abee\",markerType: \"item\"}
                                    ],
                                    valign:\"bottom\",
                                    align:\"center\",
                                    layout:\"x\"
                                }
                            });

                            barChart1.addSeries({
                                value:\"#T2#\",
                                color:\"#a7ee70\",
                                tooltip:{
                                    template:\"#T2#\"
                                }
                            });

                            barChart1.addSeries({
                                value:\"#T3#\",
                                color:\"#2980b9\",
                                tooltip:{
                                    template:\"#T3#\"
                                }
                            });

                            barChart1.addSeries({
                                value:\"#T4#\",
                                color:\"#1abc9c\",
                                tooltip:{
                                    template:\"#T4#\"
                                }
                            });

                            barChart1.addSeries({
                                //offset:0,
                                view: \"line\",
                                item:{
                                    radius:0
                                },
                                line:{
                                  color:\"#36abee\"
                                },
                                value:\"#totalticket#\",
                                tooltip:{
                                    template:\"#totalticket#\"
                                },
                                label:\"<b>#totalticket#</b>\"
                            });

                            barChart1.parse(datasets,\"json\");";
                            
                            // === Trend Pie1 by Revenue                            
                            $qry="select datasets,startvalue,stepvalue,endvalue from ".DB_APORTIL.".tbl_chart_trendsum
                                  where modules='hometicketperformancepie1' and isdeleted=0 order by id desc limit 1";
                            $spval=$this->fn_get_fieldsvalues("datasets,startvalue,stepvalue,endvalue",$qry);
                            $datasets=$spval[0];$startvalue=$spval[1];$stepvalue=$spval[2];$endvalue=$spval[3];             
            echo "          var datasets = $datasets;
                            var pieChart =  new dhtmlXChart({
                                view:\"pie\",
                                container:\"div_ticketpie1alarm\",
                                value:\"#vals#\",
                                color:\"#color#\",
                                legend:\"#category#\",
                                pieInnerText:\"<b>#vals#</b>\",
                                shadow:0
                            });
                            pieChart.parse(datasets,\"json\");";
                            
                            // === Trend Pie2 by Sitetype
                            $qry="select datasets,startvalue,stepvalue,endvalue from ".DB_APORTIL.".tbl_chart_trendsum
                                  where modules='hometicketperformancepie2' and isdeleted=0 order by id desc limit 1";
                            $spval=$this->fn_get_fieldsvalues("datasets,startvalue,stepvalue,endvalue",$qry);
                            $datasets=$spval[0];$startvalue=$spval[1];$stepvalue=$spval[2];$endvalue=$spval[3];             
            echo "          var datasets = $datasets;                                                        
                            var pieChart2 =  new dhtmlXChart({
                                view:\"pie\",
                                container:\"div_ticketpie2alarm\",
                                value:\"#vals#\",
                                color:\"#color#\",
                                legend:\"#sitetype#\",
                                pieInnerText:\"<b>#vals#</b>\",
                                shadow:0
                            });
                            pieChart2.parse(datasets,\"json\");
                       
                       };
                  </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("white");
            echo "<table width=\"100%\" height=\"100%\">";
            echo "  <tr>
                        <td valign=\"top\" width=\"70%\">
                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:24px;color:blue\">Trend Tickets Alarm Period ".date("Y")."</div>
                            <div id=\"div_ticketbaralarm\" style=\"width:100%;height:330px;\"></div>
                        </td>
                        <td valign=\"top\">
                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:24px;color:blue\">MTTR Ticket Period ".date("M")."/".date("Y")."</div>
                            <div style=\"width:100%;height:230px;margin-top:35px;border-radius:2%;background-image: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);\">";
                                $qry="select category,slainhours sla from ".DB_APORTIL.".tbl_nits_mttrbycategory where isdeleted=0 order by id asc";
                                $rs=$this->selectquery($qry);$arrsla=array();
                                if($rs)
                                {
                                    $avgall=0;
                                    while($rw=$this->data_row_object($rs))
                                    {
                                        $arrsla[$rw->category]=round($rw->sla,2);
                                        $avgall+=$rw->sla;
                                    }
                                    $avgall=round(($avgall/4),2);
                                }
                                $this->clearrecordset($rs);
            echo "              <table width=\"98%\" height=\"100%\" align=\"center\" style=\"color:white;font-size:18px\">
                                    <tr height=\"10%\">
                                        <td colspan=\"3\" style=\"font-size:20px;font-style:italic;\">Today ".date("d M Y")."&nbsp;</td>
                                    </tr>
                                    <tr height=\"10%\">
                                        <td width=\"25%\">PLATINUM</td>
                                        <td width=\"2px\" align=\"center\">:</td>
                                        <td>".$arrsla["PLATINUM"]." Hours</td>
                                    </tr>
                                    <tr height=\"10%\">
                                        <td>GOLD</td>
                                        <td width=\"2px\" align=\"center\">:</td>
                                        <td>".$arrsla["GOLD"]." Hours</td>
                                    </tr>
                                    <tr height=\"10%\">
                                        <td>SILVER</td>
                                        <td width=\"2px\" align=\"center\">:</td>
                                        <td>".$arrsla["SILVER"]." Hours</td>
                                    </tr>
                                    <tr height=\"10%\">
                                        <td>BRONZE</td>
                                        <td width=\"2px\" align=\"center\">:</td>
                                        <td>".$arrsla["BRONZE"]." Hours</td>
                                    </tr>
                                    <tr>
                                        <td colspan=\"3\" align=\"center\" valign=\"middle\">
                                            <span style=\"font-size:46px;\">                                                
                                                $avgall Hours
                                            </span>
                                            <div style=\"margin-top:-15px\">
                                                <font style=\"font-size:12px;font-style:italic;\">average for closed ticket</font>
                                            </div>                                            
                                        </td>
                                    </tr>
                                </table>
                            </div> 
                        </td>
                    </tr>
                    <tr>
                        <td valign=\"top\">
                            <table width=\"96%\" style=\"background-color:#ecf0f1\" align=\"center\">
                                <tr>
                                    <td style=\"text-align:center;\" width=\"50%\" halign=\"center\">
                                        <div id=\"div_content\" style=\"width:100%;border:1px solid #A4BED4;\">
                                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:20px;color:blue\">Alarm By Category Period ".date("M")."/".date("Y")."</div>
                                            <div id=\"div_ticketpie1alarm\" style=\"width:100%;height:250px;\"></div>
                                        </div>
                                    </td>
                                    
                                    <td>
                                        <div id=\"div_content\" style=\"width:100%;border:1px solid #A4BED4;\">
                                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:20px;color:blue\">Alarm By Sitetype Period ".date("M")."/".date("Y")."</div>
                                            <div id=\"div_ticketpie2alarm\" style=\"width:100%;height:250px;\"></div>
                                        </div>
                                    </td>
                                </tr>
                            </table>                            
                        </td>
                        <td valign=\"top\">
                            <div style=\"width:100%;text-align:center;text-decoration:underline;font-size:24px;color:blue\">SUMMARY Ticket Period ".date("M")."/".date("Y")."</div>
                            <div style=\"width:100%;height:230px;margin-top:15px;border-radius:2%;background-image: linear-gradient(to right, #92fe9d 0%, #00c9ff 100%);\">
                                <br/>
                                <table width=\"80%\" align=\"center\" style=\"color:white;margin-top:30;\" cellspacing=\"0\">
                                    <tr>
                                        <td style=\"border-bottom:1px solid white;\"></td>
                                        <td width=\"30%\" style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">Open&nbsp;</td>
                                        <td width=\"30%\" style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">Closed&nbsp;</td>
                                    </tr>";
                                    $qry="select category,opened,closed from ".DB_APORTIL.".tbl_nits_sumticketstatus
                                          where isdeleted=0 order by id asc";
                                    $rs=$this->selectquery($qry);
                                    if($rs)
                                    {
                                        while($rw=$this->data_row_object($rs))
                                        {
                                            echo "<tr>";
                                            echo "    <td>".$rw->category."</td>";
                                            echo "    <td style=\"text-align:right;\">".$rw->opened."&nbsp;</td>";
                                            echo "    <td style=\"text-align:right;\">".$rw->closed."&nbsp;</td>";
                                            echo "</tr>";
                                        }
                                    }
                                    $this->clearrecordset($rs);
            echo "              </table>    
                            </div>
                        </td>
                    </tr>";
            echo "</table>";
            echo $this->FN_CREATEFOOTER();

        }
    }
?>