<?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='hometicketperformance2' 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 barChart1 =  new dhtmlXChart({
                                view:\"bar\",
                                container:\"div_ticketbaralarm\",
                                value:\"#Tclosed#\",
                                color: \"#2ecc71\",
                                gradient:\"rising\",
                                tooltip:{
                                    template:\"#Tclosed#\"
                                },
                                width:10,
                                tooltip:{
                                    template:\"#Tclosed#\"
                                },
                                xAxis:{
                                    template:\"'#mon#\"
                                },
                                yAxis:{
                                    start:$startvalue,
                                    step:$stepvalue,
                                    end:$endvalue
                                },
                                legend:{
                                    values:[
                                              {text:\"Closed\",color:\"#2ecc71\"},
                                              {text:\"Opened\",color:\"#e74c3c\"},
                                              {text:\"Total Ticket\",color:\"#f1c40f\",markerType: \"item\"}
                                    ],
                                    valign:\"bottom\",
                                    align:\"center\",
                                    layout:\"x\"
                                }
                            });

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


                            barChart1.addSeries({
                                //offset:0,
                                view: \"line\",
                                item:{
                                    radius:0
                                },
                                line:{
                                  color:\"#f1c40f\"
                                },
                                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><span style='color:white'>#vals#</span></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><span style='color:white'>#vals#</span></b>\",
                                shadow:0
                            });
                            pieChart2.parse(datasets,\"json\");
                       
                       };
                  </script>";
            echo $this->FN_CLOSEHEADER();
            echo $this->FN_CREATEBODY("white");
            echo "<table width=\"98%\" 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;box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);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 and category<>'' 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+=round($rw->sla,2);
                                        //echo round($rw->sla,2)."<br/>";
                                    }
                                    $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;box-shadow: 0 4px 8px 0 rgba(0,0,0,0.3);border-radius:2%;background-image: linear-gradient(-20deg, #b721ff 0%, #21d4fd 100%);\">
                                <br/>
                                <table width=\"90%\" align=\"center\" style=\"color:white;margin-top:30;\" cellspacing=\"0\">
                                    <tr>
                                        <td style=\"border-bottom:1px solid white;\"></td>
                                        <td width=\"20%\" style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">Open&nbsp;</td>
                                        <td width=\"20%\" style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">Closed&nbsp;</td>
                                        <td width=\"20%\" style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">Total&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)
                                    {
                                        $grandtotal=0;
                                        while($rw=$this->data_row_object($rs))
                                        {
                                            echo "<tr>";
                                            echo "    <td style=\"border-bottom:1px solid white;font-size:14pt;\">".$rw->category."</td>";
                                            echo "    <td style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">".number_format($rw->opened)."&nbsp;</td>";
                                            echo "    <td style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">".number_format($rw->closed)."&nbsp;</td>";
                                            $total=$rw->opened+$rw->closed;
                                            echo "    <td style=\"border-bottom:1px solid white;border-left:1px solid white;text-align:right;\">".number_format($total)."&nbsp;</td>";
                                            echo "</tr>";
                                            $grandtotal+=$total;
                                        }
                                        echo "<tr>";
                                        echo "    <td style=\"font-style:italic;text-align:right;\" colspan=\"3\">Total : &nbsp;</td>";
                                        echo "    <td style=\"font-weight:bold;font-size:18pt;text-align:right;\">".number_format($grandtotal)."&nbsp;</td>";
                                        echo "</tr>";

                                    }
                                    $this->clearrecordset($rs);
            echo "              </table>    
                            </div>
                        </td>
                    </tr>";
            echo "</table>";
            echo $this->FN_CREATEFOOTER();

        }
    }
?>