Skip to content

Commit

Permalink
#240 [Certificate] add: move FKelement field and rework object fields…
Browse files Browse the repository at this point in the history
… + remove signatory
  • Loading branch information
nicolas-eoxia committed Jul 6, 2023
1 parent 577afcf commit 7fb272a
Showing 1 changed file with 76 additions and 46 deletions.
122 changes: 76 additions & 46 deletions view/certificate/certificate_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@

$elementList = [];
if (!empty($conf->user->enabled)) {
$elementList['user'] = img_picto('', 'user', 'class="pictofixedwidth"') . dol_escape_htmltag($langs->trans('User'));
$object->fields['element_type']['arrayofkeyval']['user'] = $langs->trans('User');
}
if (!empty($conf->societe->enabled)) {
$elementList['product'] .= img_picto('', 'product', 'class="pictofixedwidth"') . dol_escape_htmltag($langs->trans('Product'));
$object->fields['element_type']['arrayofkeyval']['product'] = $langs->trans('Product');
} ?>

print '<tr><td class="titlefieldcreate"><label for="element_type">' . $langs->trans('ElementType') . '</label></td>';
Expand All @@ -283,16 +283,19 @@
});
});
</script>
<?php

switch (GETPOST('element_type')) {
<?php switch (GETPOST('element_type')) {
case 'user' :
$object->fields['fk_element']['type'] = 'integer:User:user/class/user.class.php';
$object->fields['fk_element']['picto'] = 'user';
$object->fields['fk_element']['type'] = 'integer:User:user/class/user.class.php';
$object->fields['fk_element']['picto'] = 'user';
$object->fields['fk_element']['label'] = $langs->trans('User');
$object->fields['element_type']['picto'] = 'user';
break;
case 'product' :
$object->fields['fk_element']['type'] = 'integer:Product:product/class/product.class.php';
$object->fields['fk_element']['picto'] = 'product';
$object->fields['fk_element']['type'] = 'integer:Product:product/class/product.class.php';
$object->fields['fk_element']['picto'] = 'product';
$object->fields['fk_element']['label'] = $langs->trans('Product');
$object->fields['element_type']['picto'] = 'product';
break;
}

Expand Down Expand Up @@ -330,6 +333,41 @@

print '<table class="border centpercent tableforfieldedit">';

if (!empty($conf->user->enabled)) {
$object->fields['element_type']['arrayofkeyval']['user'] = $langs->trans('User');
}
if (!empty($conf->societe->enabled)) {
$object->fields['element_type']['arrayofkeyval']['product'] = $langs->trans('Product');
} ?>

<script>
$(document).ready(function(){
$('#element_type').on('change', function(){
let value = $(this).val();
let url = new URL(document.URL)
let search_params = url.searchParams;
search_params.set('element_type', value);
url.search = search_params.toString();
location.href = url.toString()
});
});
</script>

<?php switch (GETPOST('element_type')) {
case 'user' :
$object->fields['fk_element']['type'] = 'integer:User:user/class/user.class.php';
$object->fields['fk_element']['picto'] = 'user';
$object->fields['fk_element']['label'] = $langs->trans('User');
$object->fields['element_type']['picto'] = 'user';
break;
case 'product' :
$object->fields['fk_element']['type'] = 'integer:Product:product/class/product.class.php';
$object->fields['fk_element']['picto'] = 'product';
$object->fields['fk_element']['label'] = $langs->trans('Product');
$object->fields['element_type']['picto'] = 'product';
break;
}

// Common attributes.
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';

Expand Down Expand Up @@ -380,37 +418,29 @@
// Print form confirm
print $formconfirm;

$mesg = '';
$nbAttendantByRole = [];
$nbAttendants = 0;
$attendantsRole = ['Attendant'];
foreach ($attendantsRole as $attendantRole) {
$signatories = $signatory->fetchSignatory($attendantRole, $object->id, $object->element);
if (is_array($signatories) && !empty($signatories)) {
foreach ($signatories as $objectSignatory) {
if ($objectSignatory->role == $attendantRole) {
$nbAttendantByRole[$attendantRole]++;
}
}
} else {
$nbAttendantByRole[$attendantRole] = 0;
}
if ($nbAttendantByRole[$attendantRole] == 0) {
$mesg .= $langs->trans('NoAttendant', $langs->trans($attendantRole), $langs->transnoentities('The' . ucfirst($object->element))) . '<br>';
}
}

if (!in_array(0, $nbAttendantByRole)) {
$nbAttendants = 1;
}

print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<table class="border centpercent tableforfield">';

unset($object->fields['label']); // Hide field already shown in banner
unset($object->fields['fk_soc']); // Hide field already shown in banner
unset($object->fields['fk_project']); // Hide field already shown in banner
unset($object->fields['label']); // Hide field already shown in banner
unset($object->fields['fk_soc']); // Hide field already shown in banner
unset($object->fields['fk_project']); // Hide field already shown in banner
unset($object->fields['element_type']); // Unwanted

switch ($object->element_type) {
case 'user' :
$object->fields['fk_element']['type'] = 'integer:User:user/class/user.class.php';
$object->fields['fk_element']['picto'] = 'user';
$object->fields['fk_element']['label'] = $langs->trans('User');
$object->fields['element_type']['picto'] = 'user';
break;
case 'product' :
$object->fields['fk_element']['type'] = 'integer:Product:product/class/product.class.php';
$object->fields['fk_element']['picto'] = 'product';
$object->fields['fk_element']['label'] = $langs->trans('Product');
$object->fields['element_type']['picto'] = 'product';
break;
}

// Common attributes.
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
Expand Down Expand Up @@ -444,10 +474,10 @@
}

// Validate
if ($object->status == SaturneCertificate::STATUS_DRAFT && $nbAttendants > 0) {
if ($object->status == SaturneCertificate::STATUS_DRAFT)) {
print '<span class="butAction" id="actionButtonPendingSignature"><i class="fas fa-check"></i> ' . $langs->trans('Validate') . '</span>';
} else {
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeDraft', ucfirst($langs->transnoentities('The' . ucfirst($object->element)))) . '<br>' . $mesg) . '"><i class="fas fa-check"></i> ' . $langs->trans('Validate') . '</span>';
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeDraft', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-check"></i> ' . $langs->trans('Validate') . '</span>';
}

// ReOpen
Expand All @@ -457,15 +487,8 @@
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeValidated', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-lock-open"></i> ' . $langs->trans('ReOpenDoli') . '</span>';
}

// Sign
if ($object->status == SaturneCertificate::STATUS_VALIDATED && !$signatory->checkSignatoriesSignatures($object->id, $object->element)) {
print '<a class="butAction" id="actionButtonSign" href="' . dol_buildpath('/custom/saturne/view/saturne_attendants.php?id=' . $object->id . '&module_name=DoliSIRH&object_type=' . $object->element, 3) . '"><i class="fas fa-signature"></i> ' . $langs->trans('Sign') . '</a>';
} else {
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeValidatedToSign', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-signature"></i> ' . $langs->trans('Sign') . '</span>';
}

// Send mail
if ($object->status >= SaturneCertificate::STATUS_VALIDATED && $signatory->checkSignatoriesSignatures($object->id, $object->element)) {
if ($object->status >= SaturneCertificate::STATUS_VALIDATED) {
$fileparams = dol_most_recent_file($upload_dir . '/' . $object->element . 'document' . '/' . $object->ref);
$file = $fileparams['fullname'];
if (file_exists($file) && !preg_match('/specimen/', $fileparams['name'])) {
Expand All @@ -484,6 +507,13 @@
} else {
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeLockedToArchive', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-archive"></i> ' . $langs->trans('Archive') . '</span>';
}

// Sign
if ($object->status == SaturneCertificate::STATUS_VALIDATED && !$signatory->checkSignatoriesSignatures($object->id, $object->element)) {
print '<a class="butAction" id="actionButtonSign" href="' . dol_buildpath('/custom/saturne/view/saturne_attendants.php?id=' . $object->id . '&module_name=DoliSIRH&object_type=' . $object->element, 3) . '"><i class="fas fa-signature"></i> ' . $langs->trans('Sign') . '</a>';
} else {
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeValidatedToSign', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-signature"></i> ' . $langs->trans('Sign') . '</span>';
}

// Delete (need delete permission, or if draft, just need create/modify permission).
print dolGetButtonAction('<i class="fas fa-trash"></i> ' . $langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete', '', $permissiontodelete || ($object->status == SaturneCertificate::STATUS_DRAFT));
Expand All @@ -504,7 +534,7 @@
$fileDir = $upload_dir . '/' . $dirFiles;
$urlSource = $_SERVER['PHP_SELF'] . '?id=' . $object->id;

print saturne_show_documents('dolisirh:' . ucfirst($object->element) . 'Document', $dirFiles, $fileDir, $urlSource, $permissiontoadd, $permissiontodelete, $conf->global->DOLISIRH_CERTIFICATEDOCUMENT_DEFAULT_MODEL, 1, 0, 0, 0, 0, '', '', '', $langs->defaultlang, $object, 0, 'remove_file', ($object->status > SaturneCertificate::STATUS_DRAFT && $nbAttendants > 0), $langs->trans('ObjectMustBeValidatedToGenerate'));
print saturne_show_documents('dolisirh:' . ucfirst($object->element) . 'Document', $dirFiles, $fileDir, $urlSource, $permissiontoadd, $permissiontodelete, $conf->global->DOLISIRH_CERTIFICATEDOCUMENT_DEFAULT_MODEL, 1, 0, 0, 0, 0, '', '', '', $langs->defaultlang, $object, 0, 'remove_file', ($object->status > SaturneCertificate::STATUS_DRAFT), $langs->trans('ObjectMustBeValidatedToGenerate'));

print '</div><div class="fichehalfright">';

Expand Down

0 comments on commit 7fb272a

Please sign in to comment.