public static function _generateInvoiceNumber($a_user_id = 0)
 {
     global $ilSetting;
     if ($a_user_id == 0) {
         global $ilUser;
         $a_user_id = $ilUser->getId();
     }
     $inst_id = $ilSetting->get('inst_id');
     $cur_time = time();
     include_once './Services/Payment/classes/class.ilUserDefinedInvoiceNumber.php';
     $invObj = new ilUserDefinedInvoiceNumber();
     if ($invObj->getUDInvoiceNumberActive() == 1) {
         $next_number = ilUserDefinedInvoiceNumber::_nextIncCurrentValue();
         $invoice_number = $invObj->getInvoiceNumberText();
         $invoice_number = str_replace('[CURRENT_TIMESTAMP]', $cur_time, $invoice_number);
         $invoice_number = str_replace('[INSTALLATION_ID]', $inst_id, $invoice_number);
         $invoice_number = str_replace('[USER_ID]', $a_user_id, $invoice_number);
         $invoice_number = str_replace('[DAY]', date('d', $cur_time), $invoice_number);
         $invoice_number = str_replace('[MONTH]', date('m', $cur_time), $invoice_number);
         $invoice_number = str_replace('[YEAR]', date('Y', $cur_time), $invoice_number);
         $invoice_number = str_replace('[INCREMENTAL_NUMBER]', $next_number, $invoice_number);
     } else {
         $inst_id_time = $inst_id . '_' . $a_user_id . '_' . substr((string) $cur_time, -3);
         $invoice_number = $inst_id_time . substr(md5(uniqid(rand(), true)), 0, 4);
     }
     return $invoice_number;
 }
 public function InvoiceNumberObject()
 {
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $invObj = new ilUserDefinedInvoiceNumber();
     $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html', 'Services/Payment');
     $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
     $form_gui = new ilPropertyFormGUI();
     $form_gui->setFormAction($this->ctrl->getFormAction($this, 'saveInvoiceNumber'));
     $form_gui->setTitle($this->lng->txt('invoice_number_setting'));
     // invoice_type
     $radio_group = new ilRadioGroupInputGUI($this->lng->txt('invoice_number'), 'ud_invoice_number');
     $radio_option_1 = new ilRadioOption($this->lng->txt('ilias_invoice_number'), '0');
     $radio_group->addOption($radio_option_1);
     $radio_option_2 = new ilRadioOption($this->lng->txt('userdefined_invoice_number'), '1');
     $radio_group->addOption($radio_option_2);
     $radio_group->setRequired(true);
     $radio_group->setValue($invObj->getUDInvoiceNumberActive(), '0');
     $radio_group->setPostVar('ud_invoice_number');
     $form_gui->addItem($radio_group);
     // incremental current value
     $cur_num = new ilNonEditableValueGUI($this->lng->txt('incremental_current_value'), 'inc_current_value');
     $cur_num->setValue(ilUserDefinedInvoiceNumber::_getIncCurrentValue(), 1);
     $radio_option_2->addSubItem($cur_num);
     // incremental start value
     $inc_num = new ilNumberInputGUI($this->lng->txt('incremental_start_value'), 'inc_start_value');
     $inc_num->setValue($this->error != "" && isset($_POST['incremental_start_value']) ? ilUtil::prepareFormOutput($_POST['incremental_start_value'], true) : ilUtil::prepareFormOutput($invObj->getIncStartValue(), true));
     $inc_num->setInfo($this->lng->txt('incremental_start_value_info'));
     $radio_option_2->addSubItem($inc_num);
     // reset period of current value
     $sel_reset = new ilSelectInputGUI($this->lng->txt('invoice_number_reset_period'), 'inc_reset_period');
     $sel_reset->setValue($this->error != "" && isset($_POST['inc_reset_period']) ? $_POST['inc_reset_period'] : $invObj->getIncResetPeriod());
     $reset_options = array(1 => $this->lng->txt('yearly'), 2 => $this->lng->txt('monthly'));
     $sel_reset->setOptions($reset_options);
     $radio_option_2->addSubItem($sel_reset);
     // invoice_number_text
     $inp = new ilTextAreaInputGUI($this->lng->txt('invoice_number_text'), 'invoice_number_text');
     $inp->setValue($this->error != "" && isset($_POST['invoice_number_text']) ? ilUtil::prepareFormOutput($_POST['invoice_number_text'], true) : ilUtil::prepareFormOutput($invObj->getInvoiceNumberText(), true));
     $inp->setRequired(false);
     $inp->setCols(60);
     $inp->setRows(3);
     $radio_option_2->addSubItem($inp);
     // PLACEHOLDERS
     $prop = new ilInvoiceNumberPlaceholdersPropertyGUI();
     $radio_option_2->addSubItem($prop);
     $form_gui->addCommandButton('saveInvoiceNumber', $this->lng->txt('save'));
     $this->tpl->setVariable('FORM', $form_gui->getHTML());
 }