NEW Can generate invoices from timespent of a project
This commit is contained in:
parent
57f81217ee
commit
695a681c14
@ -1226,6 +1226,7 @@ class Task extends CommonObject
|
||||
$sql.= " t.task_date_withhour,";
|
||||
$sql.= " t.task_duration,";
|
||||
$sql.= " t.fk_user,";
|
||||
$sql.= " t.thm,";
|
||||
$sql.= " t.note";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
|
||||
$sql.= " WHERE t.rowid = ".$id;
|
||||
@ -1245,6 +1246,7 @@ class Task extends CommonObject
|
||||
$this->timespent_withhour = $obj->task_date_withhour;
|
||||
$this->timespent_duration = $obj->task_duration;
|
||||
$this->timespent_fk_user = $obj->fk_user;
|
||||
$this->timespent_thm = $obj->thm; // hourly rate
|
||||
$this->timespent_note = $obj->note;
|
||||
}
|
||||
|
||||
|
||||
@ -322,16 +322,24 @@ if ($action == 'confirm_generateinvoice')
|
||||
$fuser = new User($db);
|
||||
|
||||
$db->begin();
|
||||
|
||||
$idprod = GETPOST('productid', 'int');
|
||||
if ($idprod > 0)
|
||||
{
|
||||
$tmpproduct->fetch($idprod);
|
||||
}
|
||||
|
||||
$dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
|
||||
$pu_ht = empty($dataforprice['pu_ht'])?0:$dataforprice['pu_ht'];
|
||||
$txtva = $dataforprice['tva_tx'];
|
||||
$dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
|
||||
$pu_ht = empty($dataforprice['pu_ht'])?0:$dataforprice['pu_ht'];
|
||||
$txtva = $dataforprice['tva_tx'];
|
||||
$localtax1 = $dataforprice['localtax1'];
|
||||
$localtax2 = $dataforprice['localtax2'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$pu_ht = 0;
|
||||
$txtva = get_default_tva($mysoc, $projectstatic->thirdparty);
|
||||
$localtax1 = get_default_localtax($mysoc, $projectstatic->thirdparty, 1);
|
||||
$localtax2 = get_default_localtax($mysoc, $projectstatic->thirdparty, 2);
|
||||
}
|
||||
|
||||
$tmpinvoice->socid = $projectstatic->thirdparty->id;
|
||||
$tmpinvoice->date = dol_mktime(GETPOST('rehour', 'int'), GETPOST('remin', 'int'), GETPOST('resec', 'int'), GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
@ -351,8 +359,8 @@ if ($action == 'confirm_generateinvoice')
|
||||
{
|
||||
// Get userid, timepent
|
||||
$object->fetchTimeSpent($value);
|
||||
|
||||
$arrayoftasks[$object->timespent_fk_user]['timespent']+=$object->timespent_duration;
|
||||
$arrayoftasks[$object->timespent_fk_user]['totalvaluetodivideby3600']+=($object->timespent_duration * $object->timespent_thm);
|
||||
}
|
||||
|
||||
foreach($arrayoftasks as $userid => $value)
|
||||
@ -365,8 +373,14 @@ if ($action == 'confirm_generateinvoice')
|
||||
$qtyhour = round($value['timespent'] / 3600, 2);
|
||||
$qtyhourtext = convertSecondToTime($value['timespent']);
|
||||
|
||||
// If no unit price known
|
||||
if (empty($pu_ht))
|
||||
{
|
||||
$pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU');
|
||||
}
|
||||
|
||||
// Add lines
|
||||
$lineid = $tmpinvoice->addline($langs->trans("TimeSpentForInvoice", $username).' : '.$qtyhourtext, $pu_ht, $qtyhour, $txtva);
|
||||
$lineid = $tmpinvoice->addline($langs->trans("TimeSpentForInvoice", $username).' : '.$qtyhourtext, $pu_ht, $qtyhour, $txtva, $localtax1, $localtax2, ($idprod > 0 ? $idprod : 0));
|
||||
|
||||
// Update lineid into line of timespent
|
||||
$sql ='UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.$lineid.', invoice_id = '.$tmpinvoice->id;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user