This commit is contained in:
Florian HENRY 2022-04-15 10:16:18 +02:00
parent c6b5dc0a00
commit 5a8e5c4780

View File

@ -393,6 +393,7 @@ if ($action == 'confirm_generateinvoice') {
$invoiceToUse = GETPOST('invoiceid', 'int'); $invoiceToUse = GETPOST('invoiceid', 'int');
$prodDurationHoursBase = 1.0; $prodDurationHoursBase = 1.0;
$product_data_cache = array();
if ($idprod > 0) { if ($idprod > 0) {
$tmpproduct->fetch($idprod); $tmpproduct->fetch($idprod);
if ($result<0) { if ($result<0) {
@ -442,22 +443,22 @@ if ($action == 'confirm_generateinvoice') {
foreach ($toselect as $key => $value) { foreach ($toselect as $key => $value) {
// Get userid, timepent // Get userid, timepent
$object->fetchTimeSpent($value); $object->fetchTimeSpent($value);
$arrayoftasks[$object->timespent_fk_user]['timespent'] += $object->timespent_duration; $arrayoftasks[$object->timespent_fk_user][(int) $value->fk_product]['timespent'] += $object->timespent_duration;
$arrayoftasks[$object->timespent_fk_user]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm); $arrayoftasks[$object->timespent_fk_user][(int) $value->fk_product]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
} }
foreach ($arrayoftasks as $userid => $value) { foreach ($arrayoftasks as $userid => $value) {
$fuser->fetch($userid); $fuser->fetch($userid);
//$pu_ht = $value['timespent'] * $fuser->thm; //$pu_ht = $value['timespent'] * $fuser->thm;
$username = $fuser->getFullName($langs); $username = $fuser->getFullName($langs);
foreach ($value as $fk_product=>$timespent_data) {
// Define qty per hour // Define qty per hour
$qtyhour = $value['timespent'] / 3600; $qtyhour = $timespent_data['timespent'] / 3600;
$qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY); $qtyhourtext = convertSecondToTime($timespent_data['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
// If no unit price known // If no unit price known
if (empty($pu_ht)) { if (empty($pu_ht)) {
$pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU'); $pu_ht = price2num($timespent_data['totalvaluetodivideby3600'] / 3600, 'MU');
} }
// Add lines // Add lines
@ -473,9 +474,10 @@ if ($action == 'confirm_generateinvoice') {
break; break;
} }
} }
}
} elseif ($generateinvoicemode == 'onelineperperiod' || $generateinvoicemode == 'onelineperperiodproduct') { // One line for each time spent line } elseif ($generateinvoicemode == 'onelineperperiod' || $generateinvoicemode == 'onelineperperiodproduct') { // One line for each time spent line
$arrayoftasks = array(); $arrayoftasks = array();
$product_data_cache = array();
$withdetail=GETPOST('detail_time_duration', 'alpha'); $withdetail=GETPOST('detail_time_duration', 'alpha');
foreach ($toselect as $key => $value) { foreach ($toselect as $key => $value) {
// Get userid, timepent // Get userid, timepent