function OnAppElastic_Custom_ConvertTrial($params)
{
    //echo '<pre style="text-align: left;">';
    //print_r( $params );
    //exit( PHP_EOL . ' die at ' . __LINE__ . ' in ' . __FILE__ );
    $result = select_query('OnAppElasticUsers', '', ['serviceID' => $params['serviceid'], 'WHMCSUserID' => $params['userid'], 'serverID' => $params['serverid']]);
    $OnAppUserID = mysql_fetch_object($result)->OnAppUserID;
    $module = new OnAppElasticUsersModule($params);
    $OnAppUser = $module->getObject('OnApp_User');
    $unset = ['time_zone', 'user_group_id', 'locale'];
    $OnAppUser->unsetFields($unset);
    $OnAppUser->_id = $OnAppUserID;
    $OnAppUser->_billing_plan_id = json_decode($params['configoption24'])->{2};
    $OnAppUser->save();
    $data = new stdClass();
    $lang = $module->loadLang()->Client;
    if (!is_null($OnAppUser->error)) {
        $data->status = false;
        $data->message = $lang->Error_ConvertTrial . ':<br>';
        $data->message .= $OnAppUser->getErrorsAsString('<br>');
    } else {
        $update = ['isTrial' => false, 'billingPlanID' => $OnAppUser->_billing_plan_id];
        $data->status = true;
        $data->message = $lang->TrialConverted;
        update_query('OnAppElasticUsers', $update, ['serviceID' => $params['serviceid'], 'WHMCSUserID' => $params['userid'], 'serverID' => $params['serverid'], 'OnAppUserID' => $OnAppUserID]);
    }
    exit(json_encode($data));
}
 protected function generateInvoiceData($data, array $client)
 {
     require_once dirname(__DIR__) . '/OnAppElasticUsers.php';
     $module = new OnAppElasticUsersModule();
     $lang = $module->loadLang()->Invoice;
     //check if invoice should be generated
     $fromTime = strtotime($this->fromDate);
     $tillTime = strtotime($this->tillDate);
     if ($fromTime >= $tillTime) {
         return false;
     }
     if (empty($client['dueDate'])) {
         $dueDate = $this->dueDate;
     } else {
         $dueDate = date('Ymd', time() + $client['dueDate'] * 86400);
     }
     # check if the item should be taxed
     $taxed = empty($client['taxexempt']) && (int) $client['tax'];
     if ($taxed) {
         $taxrate = getTaxRate(1, $client['state'], $client['country']);
         $taxrate = $taxrate['rate'];
     } else {
         $taxrate = '';
     }
     $timeZone = ' UTC';
     if ($this->timeZoneOffset > 0) {
         $timeZone .= '+' . $this->timeZoneOffset / 3600;
     } elseif ($this->timeZoneOffset < 0) {
         $timeZone .= $this->timeZoneOffset / 3600;
     }
     $this->fromDate = date($lang->DateFormat, $fromTime);
     $this->tillDate = date($lang->DateFormat, $tillTime);
     $invoiceDescription = array($lang->Product . $client['packagename'], $lang->Period . $this->fromDate . ' - ' . $this->tillDate . $timeZone);
     $invoiceDescription = implode(PHP_EOL, $invoiceDescription);
     $return = array('userid' => $client['WHMCSUserID'], 'date' => $this->dueDate, 'duedate' => $dueDate, 'paymentmethod' => $client['paymentmethod'], 'taxrate' => $taxrate, 'sendinvoice' => true, 'itemdescription1' => $invoiceDescription, 'itemamount1' => 0, 'itemtaxed1' => $taxed);
     unset($data->total_cost);
     $i = 1;
     foreach ($data as $key => $value) {
         if ($value > 0) {
             $tmp = array('itemdescription' . ++$i => $lang->{$key}, 'itemamount' . $i => $value, 'itemtaxed' . $i => $taxed);
             $return = array_merge($return, $tmp);
         }
     }
     if ($this->printEnabled) {
         print_r($return);
     }
     return $return;
 }