Skip to content

Commit

Permalink
Merge pull request #386 from nicolas-eoxia/add_service_timesheet
Browse files Browse the repository at this point in the history
#330 [TimeSheet] add: new service on timesheet line
  • Loading branch information
nicolas-eoxia authored Jul 21, 2023
2 parents 48d310c + 23cb785 commit 17ff207
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 60 deletions.
13 changes: 7 additions & 6 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,21 @@
}

if (GETPOST('product_service_set', 'alpha')) {
if ($conf->global->DOLISIRH_PRODUCT_SERVICE_SET == 0) {
if ($conf->global->DOLISIRH_PRODUCT_SERVICE_SET == 0 || $conf->global->DOLISIRH_PRODUCT_SERVICE_SET == 1) {
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';

$product = new Product($db);

$productOrServiceTimesheets = get_product_service_timesheet();

foreach ($productOrServiceTimesheets as $productOrServiceTimesheet) {
$product->ref = $productOrServiceTimesheet['name'];
$product->label = $productOrServiceTimesheet['name'];
$product->ref = $langs->transnoentities($productOrServiceTimesheet['name']);
$product->label = $langs->transnoentities($productOrServiceTimesheet['name']);
$product->type = $productOrServiceTimesheet['type'];
$product->create($user);
}

dolibarr_set_const($db, 'DOLISIRH_PRODUCT_SERVICE_SET', 1, 'integer', 0, '', $conf->entity);
dolibarr_set_const($db, 'DOLISIRH_PRODUCT_SERVICE_SET', 2, 'integer', 0, '', $conf->entity);
}
}

Expand Down Expand Up @@ -242,10 +243,10 @@
print $langs->transnoentities('ProductServiceSetHelp');
print '</td>';
print '<td class="center">';
print $conf->global->DOLISIRH_PRODUCT_SERVICE_SET ? $langs->transnoentities('AlreadyCreated') : $langs->transnoentities('NotCreated');
print (($conf->global->DOLISIRH_PRODUCT_SERVICE_SET == 2) ? $langs->transnoentities('AlreadyCreated') : $langs->transnoentities('NotCreated'));
print '</td>';
print '<td class="center">';
print $conf->global->DOLISIRH_PRODUCT_SERVICE_SET ? '<a class="butActionRefused">' . $langs->transnoentities('Create') . '</a>' : '<input type="submit" class="button" name="product_service_set" value="' . $langs->transnoentities('Create') . '">';
print (($conf->global->DOLISIRH_PRODUCT_SERVICE_SET == 2) ? '<a class="butActionRefused">' . $langs->transnoentities('Create') . '</a>' : '<input type="submit" class="button" name="product_service_set" value="' . $langs->transnoentities('Create') . '">');
print '</td>';
print '</tr>';

Expand Down
8 changes: 4 additions & 4 deletions class/timesheet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class TimeSheetLine extends SaturneObject
* @var int Does this object support multicompany module ?
* 0 = No test on entity, 1 = Test with field entity, 'field@table' = Test with link by field@table.
*/
public int $ismultientitymanaged = 1;
public int $ismultientitymanaged = 0;

/**
* @var int Does object support extrafields ? 0 = No, 1 = Yes.
Expand Down Expand Up @@ -459,9 +459,9 @@ class TimeSheetLine extends SaturneObject
public $date_creation;

/**
* @var float Quantity.
* @var float|null Quantity.
*/
public float $qty;
public ?float $qty;

/**
* @var int Rang.
Expand All @@ -471,7 +471,7 @@ class TimeSheetLine extends SaturneObject
/**
* @var string Description.
*/
public string $description;
public string $description = '';

/**
* @var int|null Product type.
Expand Down
75 changes: 27 additions & 48 deletions core/triggers/interface_99_modDolisirh_DolisirhTriggers.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
* \brief DoliSIRH trigger.
*/

// Load DoliSIRH libraries.
// Load Dolibarr libraries.
require_once DOL_DOCUMENT_ROOT . '/core/triggers/dolibarrtriggers.class.php';

// Load DoliSIRH libraries.
require_once __DIR__ . '/../../lib/dolisirh.lib.php';
require_once __DIR__ . '/../../lib/dolisirh_function.lib.php';


/**
* Class of triggers for DoliSIRH module.
*/
Expand Down Expand Up @@ -105,7 +110,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$actioncomm->userownerid = $user->id;
$actioncomm->percentage = -1;

if (getDolGlobalInt($conf->global->DOLISIRH_ADVANCED_TRIGGER) && !empty($object->fields)) {
if (getDolGlobalInt('DOLISIRH_ADVANCED_TRIGGER') && !empty($object->fields)) {
$actioncomm->note_private = method_exists($object, 'getTriggerDescription') ? $object->getTriggerDescription($object) : '';
}

Expand Down Expand Up @@ -193,14 +198,12 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
break;

case 'BILL_CREATE':
require_once __DIR__ . '/../../lib/dolisirh_function.lib.php';
$categories = GETPOST('categories', 'array:int');
$object->setCategoriesCommon($categories, 'invoice', false);
break;

case 'BILLREC_CREATE':
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
require_once __DIR__ . '/../../lib/dolisirh_function.lib.php';

$cat = new Categorie($this->db);

Expand All @@ -219,7 +222,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($object->src_object_type == 'dolisirh_timesheet') {
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';

$signatory = new SaturneSignature($this->db);
$signatory = new SaturneSignature($this->db, 'dolisirh');

$signatories = $signatory->fetchSignatories($object->src_object_id, 'timesheet');
if (!empty($signatories) && $signatories > 0) {
Expand All @@ -240,59 +243,35 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if (!empty($object->fk_user_assign)) {
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';

$signatory = new SaturneSignature($this->db);
$signatory = new SaturneSignature($this->db, 'dolisirh', $object->element);
$usertmp = new User($this->db);

$usertmp->fetch($object->fk_user_assign);
$signatory->setSignatory($object->id, $object->element, 'user', [$object->fk_user_assign], 'TIMESHEET_SOCIETY_ATTENDANT');
$signatory->setSignatory($object->id, $object->element, 'user', [$usertmp->fk_user], 'TIMESHEET_SOCIETY_RESPONSIBLE');
$signatory->setSignatory($object->id, $object->element, 'user', [$object->fk_user_assign], 'Signatory');
$signatory->setSignatory($object->id, $object->element, 'user', [$usertmp->fk_user], 'Responsible');
}

if (getDolGlobalInt($conf->global->DOLISIRH_PRODUCT_SERVICE_SET)) {
if (getDolGlobalInt('DOLISIRH_PRODUCT_SERVICE_SET')) {
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';

$product = new Product($this->db);
$objectline = new TimeSheetLine($this->db);

$product->fetch('', dol_sanitizeFileName(dol_string_nospecial(trim($langs->transnoentities('MealTicket')))));
$objectline->date_creation = $object->db->idate($now);
$objectline->qty = 0;
$objectline->rang = 1;
$objectline->fk_timesheet = $object->id;
$objectline->fk_parent_line = 0;
$objectline->fk_product = $product->id;
$objectline->product_type = 0;
$objectline->create($user);

$product->fetch('', dol_sanitizeFileName(dol_string_nospecial(trim($langs->transnoentities('JourneySubscription')))));
$objectline->date_creation = $object->db->idate($now);
$objectline->qty = 0;
$objectline->rang = 2;
$objectline->fk_timesheet = $object->id;
$objectline->fk_parent_line = 0;
$objectline->fk_product = $product->id;
$objectline->product_type = 1;
$objectline->create($user);

$product->fetch('', dol_sanitizeFileName(dol_string_nospecial(trim($langs->transnoentities('13thMonthBonus')))));
$objectline->date_creation = $object->db->idate($now);
$objectline->qty = 0;
$objectline->rang = 3;
$objectline->fk_timesheet = $object->id;
$objectline->fk_parent_line = 0;
$objectline->fk_product = $product->id;
$objectline->product_type = 1;
$objectline->create($user);

$product->fetch('', dol_sanitizeFileName(dol_string_nospecial(trim($langs->transnoentities('SpecialBonus')))));
$objectline->date_creation = $object->db->idate($now);
$objectline->qty = 0;
$objectline->rang = 4;
$objectline->fk_timesheet = $object->id;
$objectline->fk_parent_line = 0;
$objectline->fk_product = $product->id;
$objectline->product_type = 1;
$objectline->create($user);
$i = 1;

$productOrServiceTimesheets = get_product_service_timesheet();

foreach ($productOrServiceTimesheets as $productOrServiceTimesheet) {
$product->fetch('', dol_sanitizeFileName(dol_string_nospecial(trim($langs->transnoentities($productOrServiceTimesheet['name'])))));
$objectline->date_creation = $object->db->idate($now);
$objectline->qty = 0;
$objectline->rang = $i++;
$objectline->fk_timesheet = $object->id;
$objectline->fk_parent_line = 0;
$objectline->fk_product = $product->id;
$objectline->product_type = 0;
$objectline->create($user);
}
}

$actioncomm->code = 'AC_' . strtoupper($object->element) . '_CREATE';
Expand Down
2 changes: 2 additions & 0 deletions langs/fr_FR/dolisirh.lang
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,5 @@ MealTicket = Ticket restaurant
JourneySubscription = Abonnement trajet
13thMonthBonus = Prime 13ème mois
SpecialBonus = Prime spéciale
MealBaskets = Paniers repas
TeleworkingPackage = Forfait télétravail
12 changes: 12 additions & 0 deletions lib/dolisirh.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,27 @@ function get_product_service_timesheet(): array
return [
[
'name' => 'MealTicket',
'type' => 0
],
[
'name' => 'JourneySubscription',
'type' => 1
],
[
'name' => '13thMonthBonus',
'type' => 1
],
[
'name' => 'SpecialBonus',
'type' => 1
],
[
'name' => 'MealBaskets',
'type' => 1
],
[
'name' => 'TeleworkingPackage',
'type' => 1
]
];
}
4 changes: 2 additions & 2 deletions view/timesheet/timesheet_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// Initialize technical objects
$object = new TimeSheet($db);
$objectline = new TimeSheetLine($db);
$signatory = new SaturneSignature($db);
$signatory = new SaturneSignature($db, 'dolisirh');
$timesheetdocument = new TimeSheetDocument($db);
$extrafields = new ExtraFields($db);
$project = new Project($db);
Expand Down Expand Up @@ -924,7 +924,7 @@
$genallowed = $permissiontoadd; // If you can read, you can build the PDF to read content
$delallowed = $permissiontodelete; // If you can create/edit, you can remove a file on card

print doliSirhShowDocuments('dolisirh:TimeSheetDocument', $dir_files, $filedir, $urlsource, $genallowed, $object->status == $object::STATUS_LOCKED ? $delallowed : 0, $conf->global->DOLISIRH_TIMESHEETDOCUMENT_DEFAULT_MODEL, 1, 0, 0, 0, 0, '', '', '', $langs->defaultlang, $object, 0, 'removefile', $object->status == $object::STATUS_LOCKED && empty(dol_dir_list($filedir)), $langs->trans('TimeSheetMustBeLocked'));
print saturne_show_documents('dolisirh:TimeSheetDocument', $dir_files, $filedir, $urlsource, $genallowed, $object->status == $object::STATUS_LOCKED ? $delallowed : 0, $conf->global->DOLISIRH_TIMESHEETDOCUMENT_DEFAULT_MODEL, 1, 0, 0, 0, 0, '', '', '', $langs->defaultlang, $object, 0, 'removefile', $object->status == $object::STATUS_LOCKED && empty(dol_dir_list($filedir)), $langs->trans('TimeSheetMustBeLocked'));
}

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

0 comments on commit 17ff207

Please sign in to comment.