Example #1
0
 /**
  * gets all user payments by current month and stores it into payments prop
  * 
  * @return void
  */
 protected function loadPayments()
 {
     $curmonth = curmonth();
     $query = "SELECT * from `payments` WHERE `date` LIKE '" . $curmonth . "-%' AND `summ`>0;";
     $all = simple_queryall($query);
     if (!empty($all)) {
         $this->payments = $all;
     }
 }
Example #2
0
 /**
  * Returns array of payments performed in current month
  * 
  * @return array
  */
 protected function getMonthPayments()
 {
     $result = array();
     $curmonth = curmonth();
     $query = "SELECT * from `payments` WHERE `date` LIKE '" . $curmonth . "-%' AND `summ`>0";
     $all = simple_queryall($query);
     if (!empty($all)) {
         foreach ($all as $io => $each) {
             $result[$each['id']] = $each;
         }
     }
     return $result;
 }
Example #3
0
 function ts_EmployeeMonthGraphs()
 {
     $curmonth = curmonth();
     $employees = ts_GetAllEmployee();
     $month_jobs_q = "SELECT `workerid`,`jobid` from `jobs` WHERE `date` LIKE '" . $curmonth . "%'";
     $alljobs = simple_queryall($month_jobs_q);
     $jobtypes = ts_GetAllJobtypes();
     $jobdata = array();
     $result = '';
     if (!empty($employees)) {
         if (!empty($alljobs)) {
             foreach ($alljobs as $io => $eachjob) {
                 if (isset($jobdata[$eachjob['workerid']][$eachjob['jobid']])) {
                     $jobdata[$eachjob['workerid']][$eachjob['jobid']]++;
                 } else {
                     $jobdata[$eachjob['workerid']][$eachjob['jobid']] = 1;
                 }
             }
         }
         //build graphs for each employee
         if (!empty($jobdata)) {
             foreach ($jobdata as $employee => $each) {
                 $employeeName = isset($employees[$employee]) ? $employees[$employee] : __('Deleted');
                 $result .= wf_tag('h3', false) . $employeeName . wf_tag('h3', true);
                 $rows = '';
                 if (!empty($each)) {
                     foreach ($each as $jobid => $count) {
                         $cells = wf_TableCell(@$jobtypes[$jobid], '40%');
                         $cells .= wf_TableCell($count, '20%');
                         $cells .= wf_TableCell(web_bar($count, sizeof($alljobs)), '40%');
                         $rows .= wf_TableRow($cells, 'row3');
                     }
                 }
                 $result .= wf_TableBody($rows, '100%', 0);
                 $result .= wf_delimiter();
             }
         }
     }
     return $result;
 }
Example #4
0
 /**
  * renders users signup report
  * 
  * @return void
  */
 public function reportSignup()
 {
     $regdates = array();
     $months = months_array();
     $monthCount = array();
     $showYear = wf_CheckPost(array('showyear')) ? vf($_POST['showyear'], 3) : curyear();
     $showMonth = wf_CheckGet(array('month')) ? mysql_real_escape_string($_GET['month']) : curmonth();
     $yearCount = 0;
     if (!empty($this->users)) {
         foreach ($this->users as $io => $each) {
             if (!empty($each['regdate'])) {
                 $dateTime = explode(' ', $each['regdate']);
                 $regdates[$dateTime[0]][] = $each['id'];
             }
         }
     }
     // show year selector
     $yearInputs = wf_YearSelector('showyear', ' ', false);
     $yearInputs .= wf_Submit(__('Show'));
     $yearForm = wf_Form('', 'POST', $yearInputs, 'glamour');
     show_window(__('Year'), $yearForm);
     //extract year signup count data
     foreach ($months as $eachMonth => $monthName) {
         $sigcount = 0;
         if (!empty($regdates)) {
             foreach ($regdates as $eachRegDate => $userIds) {
                 $dateMark = $showYear . '-' . $eachMonth;
                 if (ispos($eachRegDate, $dateMark)) {
                     $sigcount = $sigcount + count($regdates[$eachRegDate]);
                 }
                 $monthCount[$eachMonth] = $sigcount;
             }
             $yearCount = $yearCount + $sigcount;
         }
     }
     //render per year grid
     $cells = wf_TableCell('');
     $cells .= wf_TableCell(__('Month'));
     $cells .= wf_TableCell(__('Signups'));
     $cells .= wf_TableCell(__('Visual'));
     $rows = wf_TableRow($cells, 'row1');
     foreach ($months as $eachMonth => $monthName) {
         $cells = wf_TableCell($eachMonth);
         $monthLink = wf_Link(self::URL_REPORTS_MGMT . 'reportSignup&month=' . $showYear . '-' . $eachMonth, rcms_date_localise($monthName), false);
         $cells .= wf_TableCell($monthLink);
         $cells .= wf_TableCell($monthCount[$eachMonth]);
         $cells .= wf_TableCell(web_bar($monthCount[$eachMonth], $yearCount));
         $rows .= wf_TableRow($cells, 'row3');
     }
     $result = wf_TableBody($rows, '100%', 0, 'sortable');
     $result .= __('Total') . ': ' . $yearCount;
     show_window(__('User signups by year') . ' ' . $showYear, $result);
     //render per month registrations
     $cells = wf_TableCell(__('ID'));
     $cells .= wf_TableCell(__('Date'));
     $cells .= wf_TableCell(__('Full address'));
     $cells .= wf_TableCell(__('Real Name'));
     $cells .= wf_TableCell(__('Tariff'));
     $rows = wf_TableRow($cells, 'row1');
     if (!empty($regdates)) {
         foreach ($regdates as $eachRegDate => $eachRegUsers) {
             if (ispos($eachRegDate, $showMonth)) {
                 foreach ($eachRegUsers as $ix => $eachUserId) {
                     $cells = wf_TableCell($eachUserId);
                     $cells .= wf_TableCell($this->users[$eachUserId]['regdate']);
                     $userLink = wf_Link(self::URL_USERS_PROFILE . $eachUserId, web_profile_icon() . ' ', false);
                     $cells .= wf_TableCell($userLink . $this->userGetFullAddress($eachUserId));
                     $cells .= wf_TableCell($this->users[$eachUserId]['realname']);
                     $cells .= wf_TableCell(@$this->tariffs[$this->users[$eachUserId]['tariffid']]['tariffname']);
                     $rows .= wf_TableRow($cells, 'row3');
                 }
             }
         }
     }
     $result = wf_TableBody($rows, '100%', '0', 'sortable');
     if ($showMonth == curmonth()) {
         $monthTitle = __('Current month user signups');
     } else {
         $monthTitle = __('User signups by month') . ' ' . $showMonth;
     }
     show_window($monthTitle, $result);
 }
Example #5
0
 /**
  * Renders per-payment system openpayz transaction charts
  * 
  * @return string
  */
 public function renderGraphs()
 {
     $psysdata = array();
     $gcAllData = array();
     $gcMonthData = array();
     $result = wf_Link('?module=openpayz', __('Back'), true, 'ubButton');
     if (!empty($this->allTransactions)) {
         foreach ($this->allTransactions as $io => $each) {
             $timestamp = strtotime($each['date']);
             $curMonth = curmonth();
             $date = date("Y-m-01", $timestamp);
             if (isset($psysdata[$each['paysys']][$date]['count'])) {
                 $psysdata[$each['paysys']][$date]['count']++;
                 $psysdata[$each['paysys']][$date]['summ'] = $psysdata[$each['paysys']][$date]['summ'] + $each['summ'];
             } else {
                 $psysdata[$each['paysys']][$date]['count'] = 1;
                 $psysdata[$each['paysys']][$date]['summ'] = $each['summ'];
             }
             //all time stats
             if (isset($gcAllData[$each['paysys']])) {
                 $gcAllData[$each['paysys']]++;
             } else {
                 $gcAllData[$each['paysys']] = 1;
             }
             //current month stats
             if (ispos($date, $curMonth . '-')) {
                 if (isset($gcMonthData[$each['paysys']])) {
                     $gcMonthData[$each['paysys']]++;
                 } else {
                     $gcMonthData[$each['paysys']] = 1;
                 }
             }
         }
     }
     $chartOpts = "chartArea: {  width: '90%', height: '90%' }, legend : {position: 'right'}, ";
     if (!empty($gcAllData)) {
         $gcAllPie = wf_gcharts3DPie($gcAllData, __('All time'), '400px', '400px', $chartOpts);
     } else {
         $gcAllPie = '';
     }
     if (!empty($gcMonthData)) {
         $gcMonthPie = wf_gcharts3DPie($gcMonthData, __('Current month'), '400px', '400px', $chartOpts);
     } else {
         $gcMonthPie = '';
     }
     $gcells = wf_TableCell($gcAllPie);
     $gcells .= wf_TableCell($gcMonthPie);
     $grows = wf_TableRow($gcells);
     $result .= wf_TableBody($grows, '100%', 0, '');
     if (!empty($psysdata)) {
         foreach ($psysdata as $psys => $opdate) {
             $gdata = __('Date') . ',' . __('Count') . ',' . __('Cash') . "\n";
             foreach ($opdate as $datestamp => $optrans) {
                 $gdata .= $datestamp . ',' . $optrans['count'] . ',' . $optrans['summ'] . "\n";
             }
             $result .= wf_tag('div', false, '', '');
             $result .= wf_tag('h2') . $psys . wf_tag('h2', true) . wf_delimiter();
             $result .= wf_Graph($gdata, '800', '200', false);
             $result .= wf_tag('div', true);
         }
     }
     return $result;
 }
Example #6
0
 /**
  * Shows signup tariffs popularity  chart
  * 
  * @return void
  */
 function web_SignupGraph()
 {
     if (!wf_CheckGet(array('month'))) {
         $cmonth = curmonth();
     } else {
         $cmonth = mysql_real_escape_string($_GET['month']);
     }
     $where = "WHERE `date` LIKE '" . $cmonth . "%'";
     $alltariffnames = zb_TariffsGetAll();
     $tariffusers = zb_TariffsGetAllUsers();
     $allsignups = zb_SignupsGet($where);
     $tcount = array();
     if (!empty($allsignups)) {
         foreach ($alltariffnames as $io => $eachtariff) {
             foreach ($allsignups as $ii => $eachsignup) {
                 if (@$tariffusers[$eachsignup['login']] == $eachtariff['name']) {
                     @($tcount[$eachtariff['name']] = $tcount[$eachtariff['name']] + 1);
                 }
             }
         }
     }
     $tablecells = wf_TableCell(__('Tariff'));
     $tablecells .= wf_TableCell(__('Count'));
     $tablecells .= wf_TableCell(__('Visual'));
     $tablerows = wf_TableRow($tablecells, 'row1');
     if (!empty($tcount)) {
         foreach ($tcount as $sigtariff => $eachcount) {
             $tablecells = wf_TableCell($sigtariff);
             $tablecells .= wf_TableCell($eachcount);
             $tablecells .= wf_TableCell(web_bar($eachcount, sizeof($allsignups)), '', '', 'sorttable_customkey="' . $eachcount . '"');
             $tablerows .= wf_TableRow($tablecells, 'row3');
         }
     }
     $result = wf_TableBody($tablerows, '100%', '0', 'sortable');
     show_window(__('Tariffs report'), $result);
 }
Example #7
0
 /**
  * Renders ONU signal history chart
  * 
  * @param int $onuId
  * @return string
  */
 protected function onuSignalHistory($onuId)
 {
     $onuId = vf($onuId, 3);
     $result = '';
     if (isset($this->allOnu[$onuId])) {
         //not empty MAC
         if ($this->allOnu[$onuId]['mac']) {
             if (file_exists(self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']))) {
                 $historyKey = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']);
             } elseif (file_exists(self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']))) {
                 $historyKey = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']);
             } else {
                 $historyKey = '';
             }
             if (!empty($historyKey)) {
                 $rawData = file_get_contents($historyKey);
                 $result .= wf_delimiter();
                 $result .= wf_tag('h2') . __('ONU signal history') . wf_tag('h2', true);
                 //current day signal levels
                 $todaySignal = '';
                 $curdate = curdate();
                 if (!empty($rawData)) {
                     $todayTmp = explodeRows($rawData);
                     if (!empty($todayTmp)) {
                         foreach ($todayTmp as $io => $each) {
                             if (ispos($each, $curdate)) {
                                 $todaySignal .= $each . "\n";
                             }
                         }
                     }
                 }
                 $result .= __('Today');
                 $result .= wf_tag('div', false, '', '');
                 $result .= wf_Graph($todaySignal, '800', '300', false);
                 $result .= wf_tag('div', true);
                 $result .= wf_tag('br');
                 //current month signal levels
                 $monthSignal = '';
                 $curmonth = curmonth();
                 if (!empty($rawData)) {
                     $monthTmp = explodeRows($rawData);
                     if (!empty($monthTmp)) {
                         foreach ($monthTmp as $io => $each) {
                             if (ispos($each, $curmonth)) {
                                 $monthSignal .= $each . "\n";
                             }
                         }
                     }
                 }
                 $result .= __('Month');
                 $result .= wf_tag('div', false, '', '');
                 $result .= wf_Graph($monthSignal, '800', '300', false);
                 $result .= wf_tag('div', true);
                 $result .= wf_tag('br');
                 //all time signal history
                 $result .= __('All time');
                 $result .= wf_tag('div', false, '', '');
                 $result .= wf_GraphCSV($historyKey, '800', '300', false);
                 $result .= wf_tag('div', true);
             }
         }
     }
     return $result;
 }
Example #8
0
 /**
  * Shows salary summary report
  * 
  * @return void
  */
 public function summaryReport()
 {
     $result = '';
     if ($_SERVER['QUERY_STRING'] == 'module=salary') {
         $messages = new UbillingMessageHelper();
         if (empty($this->allEmployee)) {
             $result .= $messages->getStyledMessage(__('No available workers for wage creation'), 'error');
         } else {
             $result .= $messages->getStyledMessage(__('Total existing employees') . ': ' . sizeof($this->allEmployee), 'info');
         }
         if (empty($this->allJobtypes)) {
             $result .= $messages->getStyledMessage(__('No available job types for pricing'), 'error');
         } else {
             $result .= $messages->getStyledMessage(__('Total existing job types') . ': ' . sizeof($this->allJobtypes), 'info');
         }
         if (empty($this->allJobPrices)) {
             $result .= $messages->getStyledMessage(__('There is no set prices for job types'), 'warning');
         } else {
             $result .= $messages->getStyledMessage(__('Total paid types of work') . ': ' . sizeof($this->allJobPrices), 'info');
         }
         if (empty($this->allWages)) {
             $result .= $messages->getStyledMessage(__('There is no set wages for workers'), 'warning');
         }
         if (empty($this->allJobs)) {
             $result .= $messages->getStyledMessage(__('Not done yet any paid work'), 'warning');
         } else {
             $todayJobs = $this->jobsFilterDate(curdate());
             $todayJobsCount = sizeof($todayJobs);
             $monthJobs = $this->jobsFilterDate(curmonth());
             $monthJobsCount = sizeof($monthJobs);
             $result .= $messages->getStyledMessage(__('Today performed paid work') . ': ' . $todayJobsCount, 'success');
             $result .= $messages->getStyledMessage(__('Month performed paid work') . ': ' . $monthJobsCount, 'success');
             $result .= $messages->getStyledMessage(__('Total performed paid work') . ': ' . sizeof($this->allJobs), 'success');
         }
         if (empty($this->allTimesheetDates)) {
             $result .= $messages->getStyledMessage(__('No filled timesheets'), 'warning');
         } else {
             if (!isset($this->allTimesheetDates[curdate()])) {
                 $result .= $messages->getStyledMessage(__('For today is not filled timesheets'), 'warning');
             } else {
                 $result .= $messages->getStyledMessage(__('For today timesheets is filled'), 'success');
             }
             $result .= $messages->getStyledMessage(__('Filled timesheets for') . ' ' . sizeof($this->allTimesheetDates) . ' ' . __('days'), 'success');
         }
         if (!empty($result)) {
             show_window(__('Stats'), $result);
         }
     }
 }
Example #9
0
/**
 * Do the processing of discounts by the payments
 * 
 * @param bool $debug
 */
function zb_DiscountProcessPayments($debug = false)
{
    $alterconf = rcms_parse_ini_file(CONFIG_PATH . "alter.ini");
    $cashtype = $alterconf['DISCOUNT_CASHTYPEID'];
    $operation = $alterconf['DISCOUNT_OPERATION'];
    if (isset($alterconf['DISCOUNT_PREVMONTH'])) {
        if ($alterconf['DISCOUNT_PREVMONTH']) {
            $targetMonth = prevmonth();
        } else {
            $targetMonth = curmonth();
        }
    } else {
        $targetMonth = curmonth();
    }
    $alldiscountusers = zb_DiscountsGetAllUsers();
    $monthpayments = zb_DiscountsGetMonthPayments($targetMonth);
    if (!empty($alldiscountusers) and !empty($monthpayments)) {
        foreach ($monthpayments as $login => $eachpayment) {
            //have this user discount?
            if (isset($alldiscountusers[$login])) {
                //yes it have
                $discount_percent = $alldiscountusers[$login];
                $payment_summ = $eachpayment;
                $discount_payment = $payment_summ / 100 * $discount_percent;
                if ($operation == 'CORR') {
                    zb_CashAdd($login, $discount_payment, 'correct', $cashtype, 'DISCOUNT:' . $discount_percent);
                }
                if ($operation == 'ADD') {
                    zb_CashAdd($login, $discount_payment, 'add', $cashtype, 'DISCOUNT:' . $discount_percent);
                }
                if ($debug) {
                    print 'USER:'******' SUMM:' . $payment_summ . ' DISCOUNT:' . $discount_percent . ' PAYMENT:' . $discount_payment . "\n";
                    log_register("DISCOUNT " . $operation . " (" . $login . ") ON " . $discount_payment);
                }
            }
        }
    }
}
Example #10
0
 /**
  * Renders per-payment system openpayz transaction charts
  * 
  * @return string
  */
 public function renderGraphs()
 {
     $psysdata = array();
     $gcAllData = array();
     $gcMonthData = array();
     $gchartsData = array();
     $chartsOptions = "\n            'focusTarget': 'category',\n                        'hAxis': {\n                        'color': 'none',\n                            'baselineColor': 'none',\n                    },\n                        'vAxis': {\n                        'color': 'none',\n                            'baselineColor': 'none',\n                    },\n                        'curveType': 'function',\n                        'pointSize': 5,\n                        'crosshair': {\n                        trigger: 'none'\n                    },";
     $result = wf_Link('?module=openpayz', __('Back'), true, 'ubButton');
     if (!empty($this->allTransactions)) {
         foreach ($this->allTransactions as $io => $each) {
             $timestamp = strtotime($each['date']);
             $curMonth = curmonth();
             $date = date("Y-m", $timestamp);
             if (isset($psysdata[$each['paysys']][$date]['count'])) {
                 $psysdata[$each['paysys']][$date]['count']++;
                 $psysdata[$each['paysys']][$date]['summ'] = $psysdata[$each['paysys']][$date]['summ'] + $each['summ'];
             } else {
                 $psysdata[$each['paysys']][$date]['count'] = 1;
                 $psysdata[$each['paysys']][$date]['summ'] = $each['summ'];
             }
             //all time stats
             if (isset($gcAllData[$each['paysys']])) {
                 $gcAllData[$each['paysys']]++;
             } else {
                 $gcAllData[$each['paysys']] = 1;
             }
             //current month stats
             if (ispos($date, $curMonth)) {
                 if (isset($gcMonthData[$each['paysys']])) {
                     $gcMonthData[$each['paysys']]++;
                 } else {
                     $gcMonthData[$each['paysys']] = 1;
                 }
             }
         }
     }
     $chartOpts = "chartArea: {  width: '90%', height: '90%' }, legend : {position: 'right'}, ";
     if (!empty($gcAllData)) {
         $gcAllPie = wf_gcharts3DPie($gcAllData, __('All time'), '400px', '400px', $chartOpts);
     } else {
         $gcAllPie = '';
     }
     if (!empty($gcMonthData)) {
         $gcMonthPie = wf_gcharts3DPie($gcMonthData, __('Current month'), '400px', '400px', $chartOpts);
     } else {
         $gcMonthPie = '';
     }
     $gcells = wf_TableCell($gcAllPie);
     $gcells .= wf_TableCell($gcMonthPie);
     $grows = wf_TableRow($gcells);
     $result .= wf_TableBody($grows, '100%', 0, '');
     if (!empty($psysdata)) {
         foreach ($psysdata as $psys => $opdate) {
             $gchartsData[] = array(__('Date'), __('Count'), __('Cash'));
             foreach ($opdate as $datestamp => $optrans) {
                 $gchartsData[] = array($datestamp, $optrans['count'], $optrans['summ']);
             }
             $result .= wf_gchartsLine($gchartsData, $psys, '100%', '300px;', $chartsOptions);
             $gchartsData = array();
         }
     }
     return $result;
 }
Example #11
0
 /**
  * Preloads alter config, for further usage as key=>value
  * 
  * @global object $ubillingConfig
  * 
  * @return void
  */
 protected function loadConfig()
 {
     global $ubillingConfig;
     $this->altCfg = $ubillingConfig->getAlter();
     //sets current month
     $this->curmonth = curmonth();
     //loading complex tariffs config
     if ($this->altCfg['COMPLEX_ENABLED']) {
         $this->complexFlag = true;
         if (!empty($this->altCfg['COMPLEX_MASKS'])) {
             $masksRaw = explode(",", $this->altCfg['COMPLEX_MASKS']);
             if (!empty($masksRaw)) {
                 foreach ($masksRaw as $eachmask) {
                     $this->complexMasks[] = trim($eachmask);
                 }
             }
         } else {
             throw new Exception(self::CPL_EMPTY_EX);
         }
     }
     //loading UKV options
     if ($this->altCfg['UKV_ENABLED']) {
         $this->ukvFlag = true;
         $this->ukvComplex = $this->altCfg['UKV_COMPLEX_TARIFFID'];
         $this->ukvIllegal = $this->altCfg['UKV_ILLEGAL_TARIFFID'];
         $this->ukvSocial = $this->altCfg['UKV_SOCIAL_TARIFFID'];
         $this->ukvDebtLimit = $this->altCfg['UKV_MONTH_DEBTLIMIT'];
     }
     //Askozia PBX integration
     if ($this->altCfg['ASKOZIA_ENABLED']) {
         $this->askoziaFlag = true;
         $this->askoziaUrl = zb_StorageGet('ASKOZIAPBX_URL');
         $this->askoziaLogin = zb_StorageGet('ASKOZIAPBX_LOGIN');
         $this->askoziaPassword = zb_StorageGet('ASKOZIAPBX_PASSWORD');
     }
     //PONizer enabled?
     if ($this->altCfg['PON_ENABLED']) {
         $this->ponFlag = true;
     }
     //is DOCSIS support enabled?
     if ($this->altCfg['DOCSIS_SUPPORT']) {
         $this->docsisFlag = true;
     }
 }