Skip to content

Commit

Permalink
Fix project profit for loan part
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-john committed Feb 2, 2020
1 parent e59d118 commit fe009c3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
15 changes: 13 additions & 2 deletions htdocs/projet/class/project.class.php
Expand Up @@ -607,18 +607,29 @@ public function get_element_list($type, $tablename, $datefieldname = '', $dates
{
$sql = 'SELECT ms.rowid, ms.fk_user_author as fk_user FROM '.MAIN_DB_PREFIX."stock_mouvement as ms, ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".getEntity('stock').") AND ms.origintype = 'project' AND ms.fk_origin IN (".$ids.") AND ms.type_mouvement = 1";
}
elseif ($type == 'loan')
{
$sql = 'SELECT l.rowid, l.fk_user_author as fk_user FROM '.MAIN_DB_PREFIX."loan as l WHERE l.entity IN (".getEntity('loan').")";
}
else
{
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$projectkey." IN (".$ids.") AND entity IN (".getEntity($type).")";
}

if ($dates > 0 && ($type != 'project_task')) // For table project_taks, we want the filter on date apply on project_time_spent table
if($dates > 0 && $type == 'loan'){
$sql .= " AND (dateend > '".$this->db->idate($dates)."' OR dateend IS NULL)";
}
elseif ($dates > 0 && ($type != 'project_task')) // For table project_taks, we want the filter on date apply on project_time_spent table
{
if (empty($datefieldname) && !empty($this->table_element_date)) $datefieldname = $this->table_element_date;
if (empty($datefieldname)) return 'Error this object has no date field defined';
$sql .= " AND (".$datefieldname." >= '".$this->db->idate($dates)."' OR ".$datefieldname." IS NULL)";
}
if ($datee > 0 && ($type != 'project_task')) // For table project_taks, we want the filter on date apply on project_time_spent table

if($datee > 0 && $type == 'loan'){
$sql .= " AND (datestart < '".$this->db->idate($datee)."' OR datestart IS NULL)";
}
elseif ($datee > 0 && ($type != 'project_task')) // For table project_taks, we want the filter on date apply on project_time_spent table
{
if (empty($datefieldname) && !empty($this->table_element_date)) $datefieldname = $this->table_element_date;
if (empty($datefieldname)) return 'Error this object has no date field defined';
Expand Down
30 changes: 30 additions & 0 deletions htdocs/projet/element.php
Expand Up @@ -49,6 +49,7 @@
if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
if (! empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
if (! empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
if (! empty($conf->tax->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
Expand Down Expand Up @@ -650,6 +651,32 @@
$total_ht_by_line = price2num($tmp['amount'], 'MT');
}
}
elseif ($key == 'loan'){
if((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)){
// Get total loan
$total_ht_by_line = -$element->capital;
}
else{
// Get loan schedule according to date filter
$total_ht_by_line = 0;
$loanScheduleStatic = new LoanSchedule($element->db);
$loanScheduleStatic->fetchAll($element->id);
if(!empty($loanScheduleStatic->lines)){
foreach($loanScheduleStatic->lines as $loanSchedule){
/**
* @var $loanSchedule LoanSchedule
*/
if( ($loanSchedule->datep >= $dates && $loanSchedule->datep <= $datee) // dates filter is defined
|| !empty($dates) && empty($datee) && $loanSchedule->datep >= $dates && $loanSchedule->datep <= dol_now()
|| empty($dates) && !empty($datee) && $loanSchedule->datep <= $datee
){
$total_ht_by_line = -$loanSchedule->amount_capital;
}
}
}
}

}
else $total_ht_by_line = $element->total_ht;

// Define $total_ttc_by_line
Expand All @@ -661,6 +688,9 @@
$defaultvat = get_default_tva($mysoc, $mysoc);
$total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
}
elseif ($key == 'loan'){
$total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr
}
else $total_ttc_by_line = $element->total_ttc;

// Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
Expand Down

0 comments on commit fe009c3

Please sign in to comment.