瀏覽代碼

NEW functionality for clone job profile (#26599)

* NEW functionality for combined salary invoice and supplier invoice

* remove print_r

* NEW functionality for clone jobProfile
lamrani abdelwadoud 1 年之前
父節點
當前提交
c082074129
共有 3 個文件被更改,包括 103 次插入4 次删除
  1. 30 0
      htdocs/hrm/class/job.class.php
  2. 11 1
      htdocs/hrm/class/skillrank.class.php
  3. 62 3
      htdocs/hrm/job_card.php

+ 30 - 0
htdocs/hrm/class/job.class.php

@@ -1103,6 +1103,36 @@ class Job extends CommonObject
 		$return .= '</div>';
 		return $return;
 	}
+	/**
+	 * function for get required skills associate to job object
+	 * @param int  $id  Id of object
+	 * @return array|int     list of ids skillranks
+	 */
+	public function getSkillRankForJob($id)
+	{
+		if (empty($id)) {
+			return -1;
+		}
+		$skillranks = array();
+		$sql = "SELECT rowid";
+		$sql .= " FROM ".MAIN_DB_PREFIX."hrm_skillrank";
+		$sql .= " WHERE fk_object = ".((int) $id);
+
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			$num = $this->db->num_rows($resql);
+			$i = 0;
+			while ($i < $num) {
+				$obj = $this->db->fetch_object($resql);
+				$skillranks[] = $obj;
+				$i++;
+			}
+			$this->db->free($resql);
+		} else {
+			dol_print_error($this->db);
+		}
+		return $skillranks;
+	}
 }
 
 

+ 11 - 1
htdocs/hrm/class/skillrank.class.php

@@ -234,9 +234,10 @@ class SkillRank extends CommonObject
 	 *
 	 * @param  	User 	$user      	User that creates
 	 * @param  	int 	$fromid     Id of object to clone
+	 * @param   int     $fk_object  id of Job object (if new job object)
 	 * @return 	mixed 				New object created, <0 if KO
 	 */
-	public function createFromClone(User $user, $fromid)
+	public function createFromClone(User $user, $fromid, $fk_object = 0)
 	{
 		global $langs, $extrafields;
 		$error = 0;
@@ -261,6 +262,10 @@ class SkillRank extends CommonObject
 		unset($object->id);
 		unset($object->fk_user_creat);
 		unset($object->import_key);
+		if (!empty($fk_object) && $fk_object > 0) {
+			unset($object->fk_object);
+		}
+
 
 		// Clear fields
 		if (property_exists($object, 'ref')) {
@@ -278,6 +283,11 @@ class SkillRank extends CommonObject
 		if (property_exists($object, 'date_modification')) {
 			$object->date_modification = null;
 		}
+		if (!empty($fk_object) && $fk_object > 0) {
+			if (property_exists($object, 'fk_object')) {
+				$object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
+			}
+		}
 		// ...
 		// Clear extrafields that are unique
 		if (is_array($object->array_options) && count($object->array_options) > 0) {

+ 62 - 3
htdocs/hrm/job_card.php

@@ -34,6 +34,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
 require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
 require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
 
 // Load translation files required by the page
 $langs->loadLangs(array('hrm', 'other', 'products'));   // why products?
@@ -120,7 +121,9 @@ if (empty($reshook)) {
 
 
 	// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
-	include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
+	if ($action != 'confirm_clone') {
+		include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
+	}
 
 	// Actions when linking object each other
 	include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
@@ -146,6 +149,56 @@ if (empty($reshook)) {
 	$autocopy = 'MAIN_MAIL_AUTOCOPY_JOB_TO';
 	$trackid = 'job' . $object->id;
 	include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
+
+	if ($action == 'confirm_clone' && $confirm != 'yes') {
+		$action = '';
+	}
+
+	if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->hasRight('salaries', 'write'))) {
+		$db->begin();
+
+		$originalId = $id;
+
+		$object->fetch($id);
+		$skillRequire = $object->getSkillRankForJob($originalId);
+		if ($object->id > 0) {
+			$object->id = $object->ref = null;
+
+			if (GETPOST('clone_label', 'alphanohtml')) {
+				$object->label = GETPOST('clone_label', 'alphanohtml');
+			} else {
+				$object->label = $langs->trans("CopyOf").' '.$object->label;
+			}
+			if (GETPOST('clone_skills_required')) {
+				$cloneSkillRequired = GETPOST('clone_skills_required');
+			}
+
+			$id = $object->create($user);
+			if ($id > 0) {
+				if (!empty($cloneSkillRequired)) {
+					$i = 0;
+					while ($i < count($skillRequire)) {
+						$skillrank = new SkillRank($db);
+						$skillrank->createFromClone($user, $skillRequire[$i]->rowid, $id);
+						$i++;
+					}
+				}
+				$db->commit();
+				$db->close();
+
+				header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
+				exit;
+			} else {
+				$id = $originalId;
+				$db->rollback();
+
+				setEventMessages($object->error, $object->errors, 'errors');
+			}
+		} else {
+			$db->rollback();
+			dol_print_error($db, $object->error);
+		}
+	}
 }
 
 
@@ -275,8 +328,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 	// Clone confirmation
 	if ($action == 'clone') {
 		// Create an array for form
-		$formquestion = array();
-		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
+		$formquestion = array(
+			array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
+			array('type' => 'checkbox', 'name' => 'clone_skills_required', 'label' => $langs->trans("RequiredSkills"), 'value' => '',),
+
+		);
+		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->label), 'confirm_clone', $formquestion, 'yes', 1, 280);
 	}
 
 	// Confirmation of action xxxx
@@ -413,6 +470,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 
 			print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
 
+			print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=clone&token=' . newToken(), '', $permissiontoadd);
+
 			// Delete (need delete permission, or if draft, just need create/modify permission)
 			print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
 		}