Ejemplo n.º 1
0
 function setModuleSeqNumber($mode, $module, $req_str = '', $req_no = '', $reqPostfix = '')
 {
     $adb = PearDatabase::getInstance();
     //when we configure the invoice number in Settings this will be used
     if ($mode == 'configure' && $req_no != '') {
         $query = 'SELECT cur_id FROM vtiger_modentity_num WHERE semodule = ? AND prefix = ? AND postfix = ?;';
         $check = $adb->pquery($query, [$module, $req_str, $reqPostfix]);
         $numRows = $adb->num_rows($check);
         if ($numRows == 0) {
             $numid = $adb->getUniqueId('vtiger_modentity_num');
             $active = $adb->pquery('SELECT num_id FROM vtiger_modentity_num WHERE semodule = ? AND active = 1;', [$module]);
             $adb->pquery('UPDATE vtiger_modentity_num SET active = 0 WHERE num_id = ?;', [$adb->query_result($active, 0, 'num_id')]);
             $adb->pquery('INSERT INTO vtiger_modentity_num VALUES(?,?,?,?,?,?,?);', [$numid, $module, $req_str, $reqPostfix, $req_no, $req_no, 1]);
             return true;
         } else {
             if ($numRows != 0) {
                 $num_check = $adb->query_result($check, 0, 'cur_id');
                 if ($req_no < $num_check) {
                     return false;
                 } else {
                     $adb->pquery('UPDATE vtiger_modentity_num SET active = 0 WHERE active = 1 AND semodule = ?;', [$module]);
                     $query = 'UPDATE vtiger_modentity_num SET cur_id = ?, active = 1 WHERE prefix = ? AND postfix = ? AND semodule = ?;';
                     $adb->pquery($query, [$req_no, $req_str, $reqPostfix, $module]);
                     return true;
                 }
             }
         }
     } else {
         if ($mode == "increment") {
             //when we save new invoice we will increment the invoice id and write
             $check = $adb->pquery('SELECT cur_id, prefix, postfix FROM vtiger_modentity_num WHERE semodule = ? AND active = 1;', [$module]);
             $prefix = $adb->query_result($check, 0, 'prefix');
             $postfix = $adb->query_result($check, 0, 'postfix');
             $curid = $adb->query_result($check, 0, 'cur_id');
             $fullPrefix = Settings_Vtiger_CustomRecordNumberingModule_Model::parseNumberingVariables($prefix . $curid . $postfix);
             $strip = strlen($curid) - strlen($curid + 1);
             if ($strip < 0) {
                 $strip = 0;
             }
             $temp = str_repeat('0', $strip);
             $req_no .= $temp . ($curid + 1);
             $adb->pquery('UPDATE vtiger_modentity_num SET cur_id = ? WHERE cur_id = ? AND active = 1 AND semodule = ?;', [$req_no, $curid, $module]);
             return decode_html($fullPrefix);
         }
     }
 }