how can we round up duration by minute?

Elastix IP Pbx

Moderator: jubjang

how can we round up duration by minute?

โพสต์โดย neogate » 16 มิ.ย. 2011 22:25

any body here know how to round up minute in elastix report billing?
like call duration is 1:32min convert to 2min.
every sec exceed from minute will calculate as 1min.

anywhere to edit?
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

Re: how can we round up duration by minute?

โพสต์โดย nuiz » 18 มิ.ย. 2011 01:38

หน้า CDR Report ต้องการให้เป็นแบบนี้ใช่ป่าวครับ

รูปภาพ

แก้ไขโค๊ดตามนี้นะคับ ในไฟล์ /var/www/html/modules/cdrreport/index.php

ปล. ก่อนแแก้โค๊ดให้ก๊อบปี้ไฟล์ต้นฉบับไว้ก่อนครับ เผื่อเจ้งจะได้แก้กลับคืนได้

1. ฟังก์ชั่น _moduleContent

function _moduleContent(&$smarty, $module_name) {

ค้นหา

โค้ด: เลือกทั้งหมด
            if($cdr[8] <= 60)
                $time = $cdr[8].'s';
            else{
               $timeToSecond = secondsToTime($cdr[8]);
               $time = $cdr[8].'s '.$timeToSecond;
            }


แทนที่ด้วย

โค้ด: เลือกทั้งหมด
            if($cdr[8] <= 0) {
                $time = $cdr[8].' '.'m';
            } elseif (($cdr[8] >= 1) && ($cdr[8] <= 60)) {
                $time = '1'.' '.'m';
            } else {
                $timeToSecond = secondsToTime_2($cdr[8]);
                $time = $timeToSecond.' '.'m';
            }



2. มีการเรียกฟังก์ชั่น secondsToTime_2 ก็ให้สร้างฟังก์ชั่น secondsToTime_2 เพิ่ม ตามนี้ครับ

โค้ด: เลือกทั้งหมด
function secondsToTime_2($time){
            $decimalMinutes = $time/60;
            $minutes = floor($decimalMinutes);

            $decimalSeconds = $decimalMinutes - $minutes;
            $seconds = $decimalSeconds*60;

            if ($seconds == 0) {
                     $minutes = $minutes;
            } elseif (($seconds > 0) && ($seconds <= 60)) {
                     $minutes = $minutes+1;
            }

            return $minutes;
}



หมายเหตุ...
สองบรรทัดนี้
$time = '1'.' '.'m';
$time = $timeToSecond.' '.'m';
จะทำให้หลังตัวเลขมี วรรค และตัว m
ถ้าจะแก้ m เป็น M หรือ min หรือ Min ก็แก้ไขเอานะครับ

โค๊ดส่วนใหญ่ผมแก้เอาจากโค๊ดต้นแบบ ไม่ได้ทำใหม่ทั้งหมด ไม่ค่อยเป็น php หน่ะครับ แต่ก็พอถูๆไถๆได้
** หากมีปัญหากับอุปกรณ์ที่ซื้อมาเองหรือบริการที่ทำขึ้นมาเอง ให้โพสต์ถามในเว็บบอร์ดนี้นะครับ **
** งานเร่งด่วนติดต่อว่าจ้างที่เบอร์ 08-5161-9439 อีเมล์ iamaladin@gmail.com ไลน์ NuizVoip ครับ **
nuiz
Diamond Member
 
โพสต์: 6995
ลงทะเบียนเมื่อ: 24 มี.ค. 2010 09:33

Re: how can we round up duration by minute?

โพสต์โดย neogate » 18 มิ.ย. 2011 04:36

I'm using elastix 2.0 , I found index.php file, but internal data all different. there is no such sentense in that file.
I check with elastix 1.5 also same. please advice.
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

Re: how can we round up duration by minute?

โพสต์โดย nuiz » 18 มิ.ย. 2011 11:39

ก็ Elastix 2.0 นั่นแหล่ะครับ ผมเพิ่งลง Elastix 2.0 เมื่อวาน

ไฟล์ /var/www/html/modules/cdrreport/index.php นะครับ ไม่ใช่ไฟล์ /var/www/html/index.php

แล้วก็เข้าไปเช็ค code แล้วก็ลองแก้ไข แล้วก็ได้ตามรูป

ถ้าไฟล์ /var/www/html/modules/cdrreport/index.php ไม่มี function ชื่อ "_moduleContent" ที่ผมเอ่ยถึง รบกวนก๊อบมาโพสต์หน่อยครับ โพสต์มาทั้งไฟล์เลย ใส่แท๊ก [code] คร่อมด้วย จะได้ดูง่ายๆหน่อย
** หากมีปัญหากับอุปกรณ์ที่ซื้อมาเองหรือบริการที่ทำขึ้นมาเอง ให้โพสต์ถามในเว็บบอร์ดนี้นะครับ **
** งานเร่งด่วนติดต่อว่าจ้างที่เบอร์ 08-5161-9439 อีเมล์ iamaladin@gmail.com ไลน์ NuizVoip ครับ **
nuiz
Diamond Member
 
โพสต์: 6995
ลงทะเบียนเมื่อ: 24 มี.ค. 2010 09:33

Re: how can we round up duration by minute?

โพสต์โดย neogate » 18 มิ.ย. 2011 11:59

โค้ด: เลือกทั้งหมด
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
  Codificación: UTF-8
  +----------------------------------------------------------------------+
  | Elastix version 0.5                                                  |
  | http://www.elastix.org                                               |
  +----------------------------------------------------------------------+
  | Copyright (c) 2006 Palosanto Solutions S. A.                         |
  +----------------------------------------------------------------------+
  | Cdla. Nueva Kennedy Calle E 222 y 9na. Este                          |
  | Telfs. 2283-268, 2294-440, 2284-356                                  |
  | Guayaquil - Ecuador                                                  |
  | http://www.palosanto.com                                             |
  +----------------------------------------------------------------------+
  | The contents of this file are subject to the General Public License  |
  | (GPL) Version 2 (the "License"); you may not use this file except in |
  | compliance with the License. You may obtain a copy of the License at |
  | http://www.opensource.org/licenses/gpl-license.php                   |
  |                                                                      |
  | Software distributed under the License is distributed on an "AS IS"  |
  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
  | the License for the specific language governing rights and           |
  | limitations under the License.                                       |
  +----------------------------------------------------------------------+
  | The Original Code is: Elastix Open Source.                           |
  | The Initial Developer of the Original Code is PaloSanto Solutions    |
  +----------------------------------------------------------------------+
  $Id: index.php,v 1.1.1.1 2007/07/06 21:31:21 gcarrillo Exp $ */

include_once "libs/paloSantoGrid.class.php";
include_once "libs/paloSantoDB.class.php";
include_once "libs/paloSantoForm.class.php";
include_once "libs/paloSantoConfig.class.php";
include_once "libs/paloSantoCDR.class.php";
require_once "libs/misc.lib.php";

function _moduleContent(&$smarty, $module_name)
{
    require_once "modules/$module_name/libs/ringgroup.php";

    //include module files
    include_once "modules/$module_name/configs/default.conf.php";

    load_language_module($module_name);

    global $arrConf;
    global $arrConfModule;
    $arrConf = array_merge($arrConf,$arrConfModule);

    //folder path for custom templates
    $base_dir=dirname($_SERVER['SCRIPT_FILENAME']);
    $templates_dir=(isset($arrConf['templates_dir']))?$arrConf['templates_dir']:'themes';
    $local_templates_dir="$base_dir/modules/$module_name/".$templates_dir.'/'.$arrConf['theme'];

    // DSN para consulta de cdrs
    $dsn = generarDSNSistema('asteriskuser', 'asteriskcdrdb');
    $pDB     = new paloDB($dsn);
    $oCDR    = new paloSantoCDR($pDB);

    // DSN para consulta de ringgroups
    $dsn_asterisk = generarDSNSistema('asteriskuser', 'asterisk');
    $pDB_asterisk=new paloDB($dsn_asterisk);
    $oRG    = new RingGroup($pDB_asterisk);
    $dataRG = $oRG->getRingGroup();
    $dataRG[''] = _tr('(Any ringgroup)');

    $pDBACL = new paloDB($arrConf['elastix_dsn']['acl']);
    if (!empty($pDBACL->errMsg)) {
        return "ERROR DE DB: $pDBACL->errMsg";
    }
    $pACL = new paloACL($pDBACL);
    if (!empty($pACL->errMsg)) {
        return "ERROR DE ACL: $pACL->errMsg";
    }

    // Para usuarios que no son administradores, se restringe a los CDR de la
    // propia extensión
    $sExtension = $pACL->isUserAdministratorGroup($_SESSION['elastix_user'])
        ? ''
        : $pACL->getUserExtension($_SESSION['elastix_user']);

    // Cadenas estáticas en la plantilla
    $smarty->assign(array(
        "Filter"    =>  _tr("Filter"),
        "Delete"    =>  _tr("Delete"),
        "Delete_Warning"    =>  _tr("Are you sure you wish to delete CDR(s) Report(s)?"),
    ));

    $arrFormElements = array(
        "date_start"  => array("LABEL"                  => _tr("Start Date"),
                            "REQUIRED"               => "yes",
                            "INPUT_TYPE"             => "DATE",
                            "INPUT_EXTRA_PARAM"      => "",
                            "VALIDATION_TYPE"        => "ereg",
                            "VALIDATION_EXTRA_PARAM" => "^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}$"),
        "date_end"    => array("LABEL"                  => _tr("End Date"),
                            "REQUIRED"               => "yes",
                            "INPUT_TYPE"             => "DATE",
                            "INPUT_EXTRA_PARAM"      => "",
                            "VALIDATION_TYPE"        => "ereg",
                            "VALIDATION_EXTRA_PARAM" => "^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}$"),
        "field_name"  => array("LABEL"                  => _tr("Field Name"),
                            "REQUIRED"               => "no",
                            "INPUT_TYPE"             => "SELECT",
                            "INPUT_EXTRA_PARAM"      => array( "dst"         => _tr("Destination"),
                                                               "src"         => _tr("Source"),
                                                               "channel"     => _tr("Src. Channel"),
                                                               "accountcode" => _tr("Account Code"),
                                                               "dstchannel"  => _tr("Dst. Channel")),
                            "VALIDATION_TYPE"        => "ereg",
                            "VALIDATION_EXTRA_PARAM" => "^(dst|src|channel|dstchannel|accountcode)$"),
        "field_pattern" => array("LABEL"                  => _tr("Field"),
                            "REQUIRED"               => "no",
                            "INPUT_TYPE"             => "TEXT",
                            "INPUT_EXTRA_PARAM"      => "",
                            "VALIDATION_TYPE"        => "ereg",
                            "VALIDATION_EXTRA_PARAM" => "^[\*|[:alnum:]@_\.,/\-]+$"),
        "status"  => array("LABEL"                  => _tr("Status"),
                            "REQUIRED"               => "no",
                            "INPUT_TYPE"             => "SELECT",
                            "INPUT_EXTRA_PARAM"      => array(
                                                        "ALL"         => _tr("ALL"),
                                                        "ANSWERED"    => _tr("ANSWERED"),
                                                        "BUSY"        => _tr("BUSY"),
                                                        "FAILED"      => _tr("FAILED"),
                                                        "NO ANSWER "  => _tr("NO ANSWER")),
                            "VALIDATION_TYPE"        => "text",
                            "VALIDATION_EXTRA_PARAM" => ""),
        "ringgroup"  => array("LABEL"                  => _tr("Ring Group"),
                            "REQUIRED"               => "no",
                            "INPUT_TYPE"             => "SELECT",
                            "INPUT_EXTRA_PARAM"      => $dataRG ,
                            "VALIDATION_TYPE"        => "text",
                            "VALIDATION_EXTRA_PARAM" => ""),
        );

    $oFilterForm = new paloForm($smarty, $arrFormElements);

    // Parámetros base y validación de parámetros
    $url = array('menu' => $module_name);
    $paramFiltroBase = $paramFiltro = array(
        'date_start'    => date("d M Y"),
        'date_end'      => date("d M Y"),
        'field_name'    => 'dst',
        'field_pattern' => '',
        'status'        => 'ALL',
        'ringgroup'     =>  '',
    );
    foreach (array_keys($paramFiltro) as $k) {
        if (isset($_GET[$k])) $paramFiltro[$k] = $_GET[$k];
        if (isset($_POST[$k])) $paramFiltro[$k] = $_POST[$k];
    }
    $htmlFilter = $oFilterForm->fetchForm("$local_templates_dir/filter.tpl", "", $paramFiltro);
    if (!$oFilterForm->validateForm($paramFiltro)) {
        $smarty->assign(array(
            'mb_title'      =>  _tr('Validation Error'),
            'mb_message'    =>  '<b>'._tr('The following fields contain errors').':</b><br/>'.
                                implode(', ', array_keys($oFilterForm->arrErroresValidacion)),
        ));
        $paramFiltro = $paramFiltroBase;
        unset($_POST['delete']);    // Se aborta el intento de borrar CDRs, si había uno.
    }

    // Tradudir fechas a formato ISO para comparación y para API de CDRs.
    $url = array_merge($url, $paramFiltro);
    $paramFiltro['date_start'] = translateDate($paramFiltro['date_start']).' 00:00:00';
    $paramFiltro['date_end'] = translateDate($paramFiltro['date_end']).' 23:59:59';

    // Valores de filtrado que no se seleccionan mediante filtro
    if ($sExtension != '') $paramFiltro['extension'] = $sExtension;

    // Ejecutar el borrado, si se ha validado.
    if (isset($_POST['delete'])) {
        if($paramFiltro['date_start'] <= $paramFiltro['date_end']){
            $r = $oCDR->borrarCDRs($paramFiltro);
            if (!$r) $smarty->assign(array(
                'mb_title'      =>  _tr('ERROR'),
                'mb_message'    =>  $oCDR->errMsg,
            ));
        }else{
            $smarty->assign(array(
                'mb_title'      =>  _tr('ERROR'),
                'mb_message'    =>  _tr("Please End Date must be greater than Start Date"),
            ));
        }
    }
   
    // Generación del reporte
   
    $oGrid  = new paloSantoGrid($smarty);
    $oGrid->setTitle(_tr("CDR Report"));
    $oGrid->pagingShow(true); // show paging section.

    $oGrid->enableExport();   // enable export.
    $oGrid->setNameFile_Export(_tr("CDRReport"));
    $oGrid->setURL($url);
   
    $arrData = null;

    $total = $oCDR->contarCDRs($paramFiltro);

    if($oGrid->isExportAction()){
        $limit = $total;
        $offset = 0;
       
        $arrColumns = array(_tr("Date"), _tr("Source"), _tr("Ring Group"), _tr("Destination"), _tr("Src. Channel"),_tr("Account Code"),_tr("Dst. Channel"),_tr("Status"),_tr("Duration"));
        $oGrid->setColumns($arrColumns);
   
        $arrResult = $oCDR->listarCDRs($paramFiltro, $limit, $offset);

        if(is_array($arrResult['cdrs']) && $total>0){
            foreach($arrResult['cdrs'] as $key => $value){
                $arrTmp[0] = $value[0];
                $arrTmp[1] = $value[1];
                $arrTmp[2] = $value[11];
                $arrTmp[3] = $value[2];
                $arrTmp[4] = $value[3];
                $arrTmp[5] = $value[9];
                $arrTmp[6] = $value[4];
                $arrTmp[7] = $value[5];
                $iDuracion = $value[8];
                $iSec = $iDuracion % 60; $iDuracion = (int)(($iDuracion - $iSec) / 60);
                $iMin = $iDuracion % 60; $iDuracion = (int)(($iDuracion - $iMin) / 60);
                $sTiempo = "{$value[8]}s";
                if ($value[8] >= 60) {
                      if ($iDuracion > 0) $sTiempo .= " ({$iDuracion}h {$iMin}m {$iSec}s)";
                      elseif ($iMin > 0)  $sTiempo .= " ({$iMin}m {$iSec}s)";
                }
                $arrTmp[8] = $sTiempo;
                $arrData[] = $arrTmp;
            }
        }
        if (!is_array($arrResult)) {
        $smarty->assign(array(
            'mb_title'      =>  _tr('ERROR'),
            'mb_message'    =>  $oCDR->errMsg,
        ));
        }
    }else {
        $limit = 20;
        $oGrid->setLimit($limit);
        $oGrid->setTotal($total);

        $offset = $oGrid->calculateOffset();

        $arrResult = $oCDR->listarCDRs($paramFiltro, $limit, $offset);

        $arrColumns = array(_tr("Date"), _tr("Source"), _tr("Ring Group"), _tr("Destination"), _tr("Src. Channel"),_tr("Account Code"),_tr("Dst. Channel"),_tr("Status"),_tr("Duration"));
        $oGrid->setColumns($arrColumns);

        if(is_array($arrResult['cdrs']) && $total>0){
            foreach($arrResult['cdrs'] as $key => $value){
                $arrTmp[0] = $value[0];
                $arrTmp[1] = $value[1];
                $arrTmp[2] = $value[11];
                $arrTmp[3] = $value[2];
                $arrTmp[4] = $value[3];
                $arrTmp[5] = $value[9];
                $arrTmp[6] = $value[4];
                $arrTmp[7] = $value[5];
                $iDuracion = $value[8];
                $iSec = $iDuracion % 60; $iDuracion = (int)(($iDuracion - $iSec) / 60);
                $iMin = $iDuracion % 60; $iDuracion = (int)(($iDuracion - $iMin) / 60);
                $sTiempo = "{$value[8]}s";
                if ($value[8] >= 60) {
                      if ($iDuracion > 0) $sTiempo .= " ({$iDuracion}h {$iMin}m {$iSec}s)";
                      elseif ($iMin > 0)  $sTiempo .= " ({$iMin}m {$iSec}s)";
                }
                $arrTmp[8] = $sTiempo;
                $arrData[] = $arrTmp;
            }
        }
        if (!is_array($arrResult)) {
        $smarty->assign(array(
            'mb_title'      =>  _tr('ERROR'),
            'mb_message'    =>  $oCDR->errMsg,
        ));
        }
    }
    $oGrid->setData($arrData);
    $smarty->assign("SHOW", _tr("Show"));
    $oGrid->showFilter($htmlFilter);
    $content = $oGrid->fetchGrid();
    return $content;
}
?>
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

Re: how can we round up duration by minute?

โพสต์โดย nuiz » 18 มิ.ย. 2011 13:58

เกือบเหมือนครับ
แต่ Elastix ผมติดตั้งเมื่อวานแล้วก็ yum update แล้ว

โค้ด: เลือกทั้งหมด
[root@elastix-a ~]# rpm -qa | grep elastix
elastix-firstboot-2.0.0-14
elastix-email_admin-2.0.0-23
elastix-2.0.0-62
elastix-asterisk-sounds-1.2.3-1
elastix-vtigercrm-5.1.0-8
elastix-agenda-2.0.0-24
elastix-fax-2.0.0-18
elastix-reports-2.0.0-20
elastix-pbx-2.0.0-44
elastix-a2billing-1.3.0-4
elastix-addons-2.0.0-19
elastix-system-2.0.0-40



ไฟล์ index.php ของผมเป็นแบบนี้

โค้ด: เลือกทั้งหมด
<?php
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
  Codificación: UTF-8
  +----------------------------------------------------------------------+
  | Elastix version 0.5                                                  |
  | http://www.elastix.org                                               |
  +----------------------------------------------------------------------+
  | Copyright (c) 2006 Palosanto Solutions S. A.                         |
  +----------------------------------------------------------------------+
  | Cdla. Nueva Kennedy Calle E 222 y 9na. Este                          |
  | Telfs. 2283-268, 2294-440, 2284-356                                  |
  | Guayaquil - Ecuador                                                  |
  | http://www.palosanto.com                                             |
  +----------------------------------------------------------------------+
  | The contents of this file are subject to the General Public License  |
  | (GPL) Version 2 (the "License"); you may not use this file except in |
  | compliance with the License. You may obtain a copy of the License at |
  | http://www.opensource.org/licenses/gpl-license.php                   |
  |                                                                      |
  | Software distributed under the License is distributed on an "AS IS"  |
  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
  | the License for the specific language governing rights and           |
  | limitations under the License.                                       |
  +----------------------------------------------------------------------+
  | The Original Code is: Elastix Open Source.                           |
  | The Initial Developer of the Original Code is PaloSanto Solutions    |
  +----------------------------------------------------------------------+
  $Id: index.php,v 1.1.1.1 2007/07/06 21:31:21 gcarrillo Exp $ */

function _moduleContent(&$smarty, $module_name)
{
    include_once "libs/paloSantoGrid.class.php";
    include_once "libs/paloSantoDB.class.php";
    include_once "libs/paloSantoForm.class.php";
    include_once "libs/paloSantoConfig.class.php";
    include_once "libs/paloSantoCDR.class.php";
    require_once "libs/misc.lib.php";

    //include module files
    include_once "modules/$module_name/configs/default.conf.php";

    $lang=get_language();
    $base_dir=dirname($_SERVER['SCRIPT_FILENAME']);
    $lang_file="modules/$module_name/lang/$lang.lang";
    if (file_exists("$base_dir/$lang_file")) include_once "$lang_file";
    else include_once "modules/$module_name/lang/en.lang";

    //global variables
    global $arrConf;
    global $arrConfModule;
    global $arrLang;
    global $arrLangModule;
    $arrConf = array_merge($arrConf,$arrConfModule);
    $arrLang = array_merge($arrLang,$arrLangModule);

    //folder path for custom templates
    $base_dir=dirname($_SERVER['SCRIPT_FILENAME']);
    $templates_dir=(isset($arrConf['templates_dir']))?$arrConf['templates_dir']:'themes';
    $local_templates_dir="$base_dir/modules/$module_name/".$templates_dir.'/'.$arrConf['theme'];

    $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*");
    $arrConfAM = $pConfig->leer_configuracion(false);

    $dsn     = $arrConfAM['AMPDBENGINE']['valor'] . "://" . $arrConfAM['AMPDBUSER']['valor'] . ":" . $arrConfAM['AMPDBPASS']['valor'] . "@" .
               $arrConfAM['AMPDBHOST']['valor'] . "/asteriskcdrdb";

    // TODO: validar que conexión se realiza correctamente
    $pDB     = new paloDB($dsn);
    $arrData = array();
    $oCDR    = new paloSantoCDR($pDB);

    $pDBACL = new paloDB($arrConf['elastix_dsn']['acl']);
    if (!empty($pDBACL->errMsg)) {
        echo "ERROR DE DB: $pDBACL->errMsg <br>";
    }
    $pACL = new paloACL($pDBACL);
    if (!empty($pACL->errMsg)) {
        echo "ERROR DE ACL: $pACL->errMsg <br>";
    }
    $extension = $pACL->getUserExtension($_SESSION['elastix_user']);
    $esAdministrador = $pACL->isUserAdministratorGroup($_SESSION['elastix_user']);
    if($esAdministrador)
        $extension = "";

    $smarty->assign("menu","cdrreport");
    $smarty->assign("Filter",$arrLang['Filter']);
    $smarty->assign("Delete",$arrLang['Delete']);
    $smarty->assign("Delete_Warning",$arrLang['Are you sure you wish to delete CDR(s) Report(s)?']);

    if(isset($_GET['exportcsv']) && $_GET['exportcsv']=='yes') {
        $limit = "";
        $offset = 0;
        if(empty($_GET['date_start'])) {
            $date_start = date("Y-m-d") . " 00:00:00";
        } else {
            $date_start = translateDate($_GET['date_start']) . " 00:00:00";
        }
        if(empty($_GET['date_end'])) {
            $date_end = date("Y-m-d") . " 23:59:59";
        } else {
            $date_end   = translateDate($_GET['date_end']) . " 23:59:59";
        }
        $field_name = $_GET['field_name'];
        $field_pattern = $_GET['field_pattern'];
        $status = $_GET['status'];
        header("Cache-Control: private");
        header("Pragma: cache");
        header('Content-Type: application/octec-stream');
        //header('Content-Length: '.strlen($this->buffer));
        header('Content-disposition: inline; filename="cdrreport.csv"');
        header('Content-Type: application/force-download');
        //header('Content-Length: '.strlen($this->buffer));
        //header('Content-disposition: attachment; filename="'.$name.'"');
    } else{
        $arrFormElements = array("date_start"  => array("LABEL"                  => $arrLang["Start Date"],
                                                        "REQUIRED"               => "yes",
                                                        "INPUT_TYPE"             => "DATE",
                                                        "INPUT_EXTRA_PARAM"      => "",
                                                        "VALIDATION_TYPE"        => "ereg",
                                                        "VALIDATION_EXTRA_PARAM" => "^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}$"),
                                 "date_end"    => array("LABEL"                  => $arrLang["End Date"],
                                                        "REQUIRED"               => "yes",
                                                        "INPUT_TYPE"             => "DATE",
                                                        "INPUT_EXTRA_PARAM"      => "",
                                                        "VALIDATION_TYPE"        => "ereg",
                                                        "VALIDATION_EXTRA_PARAM" => "^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}$"),
                                 "field_name"  => array("LABEL"                  => $arrLang["Field Name"],
                                                        "REQUIRED"               => "no",
                                                        "INPUT_TYPE"             => "SELECT",
                                                        "INPUT_EXTRA_PARAM"      => array( "dst"         => $arrLang["Destination"],
                                                                                           "src"         => $arrLang["Source"],
                                                                                           "channel"     => $arrLang["Src. Channel"],
                                                                                           "accountcode" => $arrLang["Account Code"],
                                                                                           "dstchannel"  => $arrLang["Dst. Channel"]),
                                                        "VALIDATION_TYPE"        => "ereg",
                                                        "VALIDATION_EXTRA_PARAM" => "^(dst|src|channel|dstchannel|accountcode)$"),
                                 "field_pattern" => array("LABEL"                  => $arrLang["Field"],
                                                        "REQUIRED"               => "no",
                                                        "INPUT_TYPE"             => "TEXT",
                                                        "INPUT_EXTRA_PARAM"      => "",
                                                        "VALIDATION_TYPE"        => "ereg",
                                                        "VALIDATION_EXTRA_PARAM" => "^[\*|[:alnum:]@_\.,/\-]+$"),
                                 "status"  => array("LABEL"                  => $arrLang["Status"],
                                                        "REQUIRED"               => "no",
                                                        "INPUT_TYPE"             => "SELECT",
                                                        "INPUT_EXTRA_PARAM"      => array(
                                                                                    "ALL"         => $arrLang["ALL"],
                                                                                    "ANSWERED"    => $arrLang["ANSWERED"],
                                                                                    "BUSY"        => $arrLang["BUSY"],
                                                                                    "FAILED"      => $arrLang["FAILED"],
                                                                                    "NO ANSWER "  => $arrLang["NO ANSWER"]),
                                                        "VALIDATION_TYPE"        => "text",
                                                        "VALIDATION_EXTRA_PARAM" => ""),
                                 );

        $oFilterForm = new paloForm($smarty, $arrFormElements);

        // Por omision las fechas toman el sgte. valor (la fecha de hoy)
        $date_start = date("Y-m-d") . " 00:00:00";
        $date_end   = date("Y-m-d") . " 23:59:59";
        $field_name = "";
        $field_pattern = "";
        $status = "ALL";

        if(isset($_POST['delete']) || isset($_POST['filter']) )
        {
            if($oFilterForm->validateForm($_POST)) {
                // Exito, puedo procesar los datos ahora.
                $date_start = translateDate($_POST['date_start']) . " 00:00:00";
                $date_end   = translateDate($_POST['date_end']) . " 23:59:59";
                $field_name = $_POST['field_name'];
                $field_pattern = $_POST['field_pattern'];
                $status = $_POST['status'];

                $arrFilterExtraVars = array("date_start" => $_POST['date_start'], "date_end" => $_POST['date_end'],
                                            "field_name" => $_POST['field_name'], "field_pattern" => $_POST['field_pattern'],"status" => $_POST['status']);
                if(isset($_POST['delete']))
                    $oCDR->Delete_All_CDRs($date_start, $date_end, $field_name, $field_pattern, $status);
            } else {
                // Error
                $smarty->assign("mb_title", $arrLang["Validation Error"]);
                $arrErrores=$oFilterForm->arrErroresValidacion;
                $strErrorMsg = "<b>{$arrLang['The following fields contain errors']}:</b><br>";
                foreach($arrErrores as $k=>$v) {
                    $strErrorMsg .= "$k, ";
                }
                $strErrorMsg .= "";
                $smarty->assign("mb_message", $strErrorMsg);
            }
            $htmlFilter = $contenidoModulo=$oFilterForm->fetchForm("$local_templates_dir/filter.tpl", "", $_POST);
        } else if(isset($_GET['date_start']) AND isset($_GET['date_end'])) {
            $date_start = translateDate($_GET['date_start']) . " 00:00:00";
            $date_end   = translateDate($_GET['date_end']) . " 23:59:59";
            $field_name = $_GET['field_name'];
            $field_pattern = $_GET['field_pattern'];
            $status = $_GET['status'];
            $arrFilterExtraVars = array("date_start" => $_GET['date_start'], "date_end" => $_GET['date_end']);
            $htmlFilter = $contenidoModulo=$oFilterForm->fetchForm("$local_templates_dir/filter.tpl", "", $_GET);
        } else {
            $htmlFilter = $contenidoModulo=$oFilterForm->fetchForm("$local_templates_dir/filter.tpl", "",
                          array('date_start' => date("d M Y"), 'date_end' => date("d M Y"),'field_name' => 'dst','field_pattern' => '','status' => 'ALL' ));
        }

        // LISTADO
        $limit = 50;
        $offset = 0;

        // Si se quiere avanzar a la sgte. pagina
        if(isset($_GET['nav']) && $_GET['nav']=="end") {
            $arrCDRTmp  = $oCDR->obtenerCDRs($limit, $offset, $date_start, $date_end, $field_name, $field_pattern,$status, "", NULL, $extension);
            $totalCDRs  = $arrCDRTmp['NumRecords'][0];
            // Mejorar el sgte. bloque.
            if(($totalCDRs%$limit)==0) {
                $offset = $totalCDRs - $limit;
            } else {
                $offset = $totalCDRs - $totalCDRs%$limit;
            }
        }

        // Si se quiere avanzar a la sgte. pagina
        if(isset($_GET['nav']) && $_GET['nav']=="next") {
            $offset = $_GET['start'] + $limit - 1;
        }

        // Si se quiere retroceder
        if(isset($_GET['nav']) && $_GET['nav']=="previous") {
            $offset = $_GET['start'] - $limit - 1;
        }

        // Construyo el URL base
        if(isset($arrFilterExtraVars) && is_array($arrFilterExtraVars) && count($arrFilterExtraVars)>0) {
            $url = $arrFilterExtraVars;
        } else {
            $url = array();
        }
    }

    // Bloque comun
    $arrCDR  = $oCDR->obtenerCDRs($limit, $offset, $date_start, $date_end, $field_name, $field_pattern,$status, "", NULL, $extension);

    $total   = $arrCDR['NumRecords'][0];

    $arrData = array();
    if(isset($arrCDR['Data']) && is_array($arrCDR['Data']))
    {
        foreach($arrCDR['Data'] as $cdr) {
            $time = "";
            $arrTmp    = array();
            $arrTmp[0] = $cdr[0];
            $arrTmp[1] = $cdr[1];
            $arrTmp[2] = $cdr[2];
            $arrTmp[3] = $cdr[3];
            $arrTmp[4] = $cdr[9];
            $arrTmp[5] = $cdr[4];
            $arrTmp[6] = $cdr[5];
    //        $arrTmp[6] = $cdr[7];


            if($cdr[8] <= 0) {
                //$time = $cdr[8].'s';
                $time = $cdr[8].' '.'m';
            } elseif (($cdr[8] >= 1) && ($cdr[8] <= 60)) {
                //$time = '60'.'s';
                $time = '1'.' '.'m';
            } else {
                $timeToSecond = secondsToTime_2($cdr[8]);
                //$time = $cdr[8].'s '.$timeToSecond;
                $time = $timeToSecond.' '.'m';
            }
           


            //if($cdr[8] <= 60)
            //    $time = $cdr[8].'s';
            //else{
            //   $timeToSecond = secondsToTime($cdr[8]);
            //   $time = $cdr[8].'s '.$timeToSecond;
            //}



            $arrTmp[7] = $time;

            $arrData[] = $arrTmp;
        }
    }

    $arrGrid = array("title"    => $arrLang["CDR Report List"],
                     "url"      => $url,
                     "icon"     => "images/user.png",
                     "width"    => "99%",
                     "start"    => ($total==0) ? 0 : $offset + 1,
                     "end"      => ($offset+$limit)<=$total ? $offset+$limit : $total,
                     "total"    => $total,
                     "columns"  => array(
                                         0 => array("name"      => $arrLang["Date"],
                                                    "property1" => ""),
                                         1 => array("name"      => $arrLang["Source"],
                                                    "property1" => ""),
                                         2 => array("name"      => $arrLang["Destination"],
                                                    "property1" => ""),
                                         3 => array("name"      => $arrLang["Src. Channel"],
                                                    "property"  => ""),
                                         4 => array("name"      => $arrLang["Account Code"],
                                                    "property"  => ""),
                                         5 => array("name"      => $arrLang["Dst. Channel"],
                                                    "property"  => ""),
                                         6 => array("name"      => $arrLang["Status"],
                                                    "property"  => ""),
                                         7 => array("name"      => $arrLang["Duration"],
                                                    "property"  => ""),
                                        )
                    );

    // Creo objeto de grid
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->enableExport();

    if(isset($_GET['exportcsv']) && $_GET['exportcsv']=='yes') {
        return $oGrid->fetchGridCSV($arrGrid, $arrData);
    } else {
        $oGrid->showFilter($htmlFilter);
        return $oGrid->fetchGrid($arrGrid, $arrData,$arrLang);
    }
}

function secondsToTime($time){
        if($time >= 3600){
            $decimalHours = $time/3600;
            $hours = floor($decimalHours);

            $decimalMinutes = $decimalHours - $hours;
            $minutesTotal = $decimalMinutes*60;
            $minutes = floor($minutesTotal);

            $decimalSeconds = $minutesTotal - $minutes;
            $seconds = $decimalSeconds*60;
            return "( ".$hours."h ".$minutes."m ".$seconds."s )";
        }
        else{
            $decimalMinutes = $time/60;
            $minutes = floor($decimalMinutes);

            $decimalSeconds = $decimalMinutes - $minutes;
            $seconds = $decimalSeconds*60;
            return "( ".$minutes."m ".$seconds."s )";
        }
}

function secondsToTime_2($time){
        //if($time >= 3600){
        //    $decimalHours = $time/3600;
        //    $hours = floor($decimalHours);

        //    $decimalMinutes = $decimalHours - $hours;
        //    $minutesTotal = $decimalMinutes*60;
        //    $minutes = floor($minutesTotal);

        //    $decimalSeconds = $minutesTotal - $minutes;
        //    $seconds = $decimalSeconds*60;
        //    return "( ".$hours."h ".$minutes."m ".$seconds."s )";
        //}
        //else{

            $decimalMinutes = $time/60;
            $minutes = floor($decimalMinutes);

            $decimalSeconds = $decimalMinutes - $minutes;
            $seconds = $decimalSeconds*60;

                if ($seconds == 0) {
                        $minutes = $minutes;
                } elseif (($seconds > 0) && ($seconds <= 60)) {
                        $minutes = $minutes+1;
                        //return "( ".$minutes."m)";
                }

            return $minutes;


            //return "( ".$minutes."m ".$seconds."s )";
        //}
}

?>



ลองก๊อบไปแทนไฟล์ index.php ของเดิมดูครับ
** หากมีปัญหากับอุปกรณ์ที่ซื้อมาเองหรือบริการที่ทำขึ้นมาเอง ให้โพสต์ถามในเว็บบอร์ดนี้นะครับ **
** งานเร่งด่วนติดต่อว่าจ้างที่เบอร์ 08-5161-9439 อีเมล์ iamaladin@gmail.com ไลน์ NuizVoip ครับ **
nuiz
Diamond Member
 
โพสต์: 6995
ลงทะเบียนเมื่อ: 24 มี.ค. 2010 09:33

Re: how can we round up duration by minute?

โพสต์โดย neogate » 18 มิ.ย. 2011 14:48

I copy ur code and replace. it work fine. I also need for billing report module.
as I know billing report will show call duration and then calculate the cost ( with rate defined) for outgoing call thru trunk.
Problem now is in cdr, it record 3line. (sorry I dont know how to post pic here, so i sent to ur mail, ple see)
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

Re: how can we round up duration by minute?

โพสต์โดย neogate » 18 มิ.ย. 2011 14:58

in cdr, actual duration counting line should b "dst.channel = SIP/pfingo-00000008"
but when destination number connected, it's dst.channel change to Local/0066810825256@from-internal-3579;1

that's why , in billing report it can't show actual talking duration thru trunk,
bcos it regonize it talk thru Local/0066810825256@from-internal-3579;1 which I didn't define rate.
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

Re: how can we round up duration by minute?

โพสต์โดย neogate » 19 มิ.ย. 2011 00:01

I can fix billing report to round up cost into minute now. by editing index.php file in modules/billing_report/
here is code I add in to that file.
โค้ด: เลือกทั้งหมด
                 if ($iSec > 0)
                  $TMin = $iMin + 1;
              else $TMin = $iMin;


and edit charge sentens like this
โค้ด: เลือกทั้งหมด

$charge=(($TMin)*$rate_value)+$rate_offset;
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

Re: how can we round up duration by minute?

โพสต์โดย neogate » 19 มิ.ย. 2011 00:22

date source destination src.channel dst.channel status duration
04:05:29 086xxx 00668xxx SIP/200-007 Local/00668xxx @from-internal-3579;1 ANSWERED 59sec


04:05:29 086xxx 00668xxx Local/0068xx@from-internal-3579;2 SIP/trunk-00000008 ANSWERED 1sec


04:04:56 0864xxx 2 SIP/200-00000007 ------------------------------------------------- ANSWERED 1 sec

03:53:13 0864xxx 00668xxx SIP/200-00000005 Local/00668xxx @from-internal-6919;1 ANSWERED 1min 40sec

03:53:13 0864xxx 00668xxx Local/00668xxx@from-internal-6919;2 SIP/trunk-00000006 ANSWERED 1 sec


why when destination answer, dst.channel change to local/0066xx.
It cause problem in billing report , billing report show calls pass thru sip trunk only.
any way to make it record as sip/trunk-xxx ?
please advice
neogate
Bronz Member
 
โพสต์: 17
ลงทะเบียนเมื่อ: 27 ม.ค. 2011 21:23

ต่อไป

ย้อนกลับไปยัง Elastix - Unified Communications Software

ผู้ใช้งานขณะนี้

กำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และ บุคคลทั่วไป 2 ท่าน

cron