Skip to content

Commit

Permalink
Debug of module expense report
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 15, 2015
1 parent 17b736c commit 49a13f5
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 63 deletions.
24 changes: 13 additions & 11 deletions htdocs/expensereport/card.php
Expand Up @@ -829,7 +829,7 @@
$object_ligne->fk_c_type_fees = GETPOST('fk_c_type_fees');

$object_ligne->fk_c_tva = GETPOST('fk_c_tva');
$object_ligne->vatrate = GETPOST('vatrate');
$object_ligne->vatrate = price2num(GETPOST('vatrate'));

$object_ligne->fk_projet = $fk_projet;

Expand Down Expand Up @@ -877,7 +877,7 @@
$type = 0; // TODO What if service
$tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type);

$object_ligne->vatrate = GETPOST('vatrate');
$object_ligne->vatrate = price2num(GETPOST('vatrate'));
$object_ligne->total_ttc = $tmp[2];
$object_ligne->total_ht = $tmp[0];
$object_ligne->total_tva = $tmp[1];
Expand Down Expand Up @@ -905,11 +905,11 @@
$object->fetch($id);

$object_ligne = new ExpenseReportLine($db);
$object_ligne->fetch($_GET["rowid"]);
$object_ligne->fetch(GETPOST("rowid"));
$total_ht = $object_ligne->total_ht;
$total_tva = $object_ligne->total_tva;

$result=$object->deleteline($_GET["rowid"]);
$result=$object->deleteline(GETPOST("rowid"));
if ($result >= 0)
{
if ($result > 0)
Expand Down Expand Up @@ -950,11 +950,12 @@
$rowid = $_POST['rowid'];
$type_fees_id = GETPOST('fk_c_type_fees');
$object_ligne->fk_c_tva = GETPOST('fk_c_tva');
$object_ligne->vatrate = GETPOST('vatrate');
$object_ligne->vatrate = price2num(GETPOST('vatrate'));
$projet_id = $fk_projet;
$comments = GETPOST('comments');
$qty = GETPOST('qty');
$value_unit = GETPOST('value_unit');
$vatrate = GETPOST('vatrate');

if (! GETPOST('fk_c_type_fees') > 0)
{
Expand All @@ -971,7 +972,7 @@

if (! $error)
{
$result = $object->updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $object_id);
$result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id);
if ($result >= 0)
{
if ($result > 0)
Expand All @@ -994,8 +995,9 @@
}
}

$object->recalculer($object_id);
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object_id);
$result = $object->recalculer($id);

header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
}
else
Expand Down Expand Up @@ -1369,7 +1371,7 @@

if ($action == 'delete_line')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".$_GET['rowid'],$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1);
$ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOST('rowid'),$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1);
if ($ret == 'html') print '<br>';
}

Expand Down Expand Up @@ -1635,7 +1637,7 @@

// Select project
print '<td>';
$formproject->select_projects(-1, $objp->fk_projet,'fk_projet', 0, 0, 0, 1);
$formproject->select_projects(-1, $objp->fk_projet,'fk_projet', 0, 0, 1, 1);
print '</td>';

// Select type
Expand Down Expand Up @@ -1711,7 +1713,7 @@
print '<td style="text-align:center;"></td>';
print '</tr>';

print '<tr>';
print '<tr '.$bc[true].'>';

// Select date
print '<td style="text-align:center;">';
Expand Down
124 changes: 74 additions & 50 deletions htdocs/expensereport/class/expensereport.class.php
Expand Up @@ -282,7 +282,7 @@ function update($user)
*/
function fetch($id, $ref='')
{
global $conf,$db;
global $conf;

$sql = "SELECT d.rowid, d.ref, d.note_public, d.note_private,"; // DEFAULT
$sql.= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; // ACTIONS
Expand All @@ -298,10 +298,10 @@ function fetch($id, $ref='')
$sql.= $restrict;

dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$result = $db->query($sql) ;
if ($result)
$resql = $this->db->query($sql) ;
if ($resql)
{
$obj = $db->fetch_object($result);
$obj = $this->db->fetch_object($resql);
if ($obj)
{
$this->id = $obj->rowid;
Expand Down Expand Up @@ -367,7 +367,7 @@ function fetch($id, $ref='')

$result=$this->fetch_lines();

return 1;
return $result;
}
else
{
Expand All @@ -376,7 +376,7 @@ function fetch($id, $ref='')
}
else
{
$this->error=$db->lasterror();
$this->error=$this->db->lasterror();
return -1;
}
}
Expand Down Expand Up @@ -663,6 +663,7 @@ function fetch_line_by_project($projectid,$user='')

/**
* recalculer
* TODO Replace this with call to update_price if not already done
*
* @param int $id Id of expense report
* @return int <0 if KO, >0 if OK
Expand Down Expand Up @@ -733,14 +734,15 @@ function fetch_lines()
$sql.= ' WHERE de.'.$this->fk_element.' = '.$this->id;

dol_syslog('ExpenseReport::fetch_lines sql='.$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($result);
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$objp = $this->db->fetch_object($result);
$objp = $this->db->fetch_object($resql);

$deplig = new ExpenseReportLine($this->db);

$deplig->rowid = $objp->rowid;
Expand Down Expand Up @@ -769,13 +771,13 @@ function fetch_lines()

$i++;
}
$this->db->free($result);
$this->db->free($resql);
return 1;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog('ExpenseReport::fetch_lines: Error '.$this->error,LOG_ERR);
dol_syslog('ExpenseReport::fetch_lines: Error '.$this->error, LOG_ERR);
return -3;
}
}
Expand Down Expand Up @@ -1198,30 +1200,36 @@ function update_totaux_del($ligne_total_ht,$ligne_total_tva){
}



function updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $expensereport_id)
/**
* updateline
*
* @param int $rowid Line to edit
* @param int $type_fees_id Type payment
* @param int $projet_id Project id
* @param double $vatrate Vat rate
* @param string $comments Description
* @param real $qty Qty
* @param double $value_unit Value init
* @param int $date Date
* @param int $expensereport_id Expense report id
* @return int <0 if KO, >0 if OK
*/
function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id)
{
global $user;

if ($this->fk_statut==0 || $this->fk_statut==99)
{
$this->db->begin();

// Select du taux de tva par rapport au code
$sql = "SELECT t.taux as vatrate";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
$sql.= " WHERE t.rowid = ".$c_tva;
$result = $this->db->query($sql);
$objp_tva = $this->db->fetch_object($result);

// calcul de tous les totaux de la ligne
$total_ttc = $qty*$value_unit;
$total_ttc = number_format($total_ttc,2,'.','');
$total_ttc = price2num($qty*$value_unit, 'MT');

$tx_tva = $objp_tva->vatrate/100;
$tx_tva = $vatrate / 100;
$tx_tva = $tx_tva + 1;
$total_ht = $total_ttc/$tx_tva;
$total_ht = number_format($total_ht,2,'.','');
$total_ht = price2num($total_ttc/$tx_tva, 'MT');

$total_tva = $total_ttc - $total_ht;
$total_tva = price2num($total_ttc - $total_ht, 'MT');
// fin calculs

$ligne = new ExpenseReportLine($this->db);
Expand All @@ -1230,15 +1238,14 @@ function updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty,
$ligne->value_unit = $value_unit;
$ligne->date = $date;

$ligne->fk_expensereport = $expensereport_id;
$ligne->fk_expensereport= $expensereport_id;
$ligne->fk_c_type_fees = $type_fees_id;
$ligne->fk_projet = $projet_id;
$ligne->fk_c_tva = $c_tva;

$ligne->total_ht = $total_ht;
$ligne->total_tva = $total_tva;
$ligne->total_ttc = $total_ttc;
$ligne->vatrate = $objp_tva->vatrate;
$ligne->vatrate = price2num($vatrate);
$ligne->rowid = $rowid;

// Select des infos sur le type fees
Expand All @@ -1259,16 +1266,19 @@ function updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty,
$ligne->projet_ref = $objp_projet->ref_projet;
$ligne->projet_title = $objp_projet->title_projet;

$result = $ligne->update();
if ($result > 0):
$this->db->commit();
return 1;
else:
$this->error=$ligne->error;
$this->db->rollback();
return -2;
endif;

$result = $ligne->update($user);
if ($result > 0)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$ligne->error;
$this->errors=$ligne->errors;
$this->db->rollback();
return -2;
}
}
}

Expand Down Expand Up @@ -1566,15 +1576,17 @@ function insert($notrigger=0)
$this->comments=trim($this->comments);
if (!$this->value_unit_HT) $this->value_unit_HT=0;
$this->qty = price2num($this->qty);
$this->vatrate = price2num($this->vatrate);

$this->db->begin();

$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det';
$sql.= ' (fk_expensereport, fk_c_type_fees, fk_projet,';
$sql.= ' fk_c_tva, comments, qty, value_unit, total_ht, total_tva, total_ttc, date)';
$sql.= ' fk_c_tva, tva_tx, comments, qty, value_unit, total_ht, total_tva, total_ttc, date)';
$sql.= " VALUES (".$this->fk_expensereport.",";
$sql.= " ".$this->fk_c_type_fees.",";
$sql.= " ".($this->fk_projet>0?$this->fk_projet:'null').",";
$sql.= " ".($this->fk_c_tva?$this->fk_c_tva:"null").",";
$sql.= " ".$this->vatrate.",";
$sql.= " '".$this->db->escape($this->comments)."',";
$sql.= " ".$this->qty.",";
Expand Down Expand Up @@ -1631,6 +1643,7 @@ function update($user)

// Clean parameters
$this->comments=trim($this->comments);
$this->vatrate = price2num($this->vatrate);

$this->db->begin();

Expand All @@ -1639,14 +1652,11 @@ function update($user)
$sql.= " comments='".$this->db->escape($this->comments)."'";
$sql.= ",value_unit=".$this->value_unit."";
$sql.= ",qty=".$this->qty."";
if ($this->date) {
$sql.= ",date='".$this->date."'";
}
else { $sql.=',date=null';
}
$sql.= ",date='".$this->db->idate($this->date)."'";
$sql.= ",total_ht=".$this->total_ht."";
$sql.= ",total_tva=".$this->total_tva."";
$sql.= ",total_ttc=".$this->total_ttc."";
$sql.= ",tva_tx=".$this->vatrate;
if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->fk_c_type_fees;
else $sql.= ",fk_c_type_fees=null";
if ($this->fk_projet) $sql.= ",fk_projet=".$this->fk_projet;
Expand All @@ -1660,16 +1670,30 @@ function update($user)
$resql=$this->db->query($sql);
if ($resql)
{
$tmpparent=new ExpenseReport($db);
$tmpparent->fetch($this->fk_expensereport);
$result = $tmpparent->update_price();
if ($result < 0)
$tmpparent=new ExpenseReport($this->db);
$result = $tmpparent->fetch($this->fk_expensereport);
if ($result > 0)
{
$result = $tmpparent->update_price();
if ($result < 0)
{
$error++;
$this->error = $tmpparent->error;
$this->errors = $tmpparent->errors;
}
}
else
{
$error++;
$this->error = $tmpparent->error;
$this->errors = $tmpparent->errors;
}
}
else
{
$error++;
dol_print_error($this->db);
}

if (! $error)
{
Expand Down
7 changes: 5 additions & 2 deletions htdocs/install/mysql/migration/3.7.0-3.8.0.sql
Expand Up @@ -235,8 +235,8 @@ CREATE TABLE llx_expensereport_det
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
fk_expensereport integer NOT NULL,
fk_c_type_fees integer NOT NULL,
fk_projet integer NOT NULL,
fk_c_tva integer NOT NULL,
fk_projet integer,
fk_c_tva integer,
comments text NOT NULL,
product_type integer DEFAULT -1,
qty real NOT NULL,
Expand All @@ -259,6 +259,9 @@ CREATE TABLE llx_expensereport_det
import_key varchar(14)
) ENGINE=innodb;

ALTER TABLE llx_expensereport_det MODIFY COLUMN fk_projet integer NULL;
ALTER TABLE llx_expensereport_det MODIFY COLUMN fk_c_tva integer NULL;


ALTER TABLE llx_projet ADD COLUMN budget_amount double(24,8);

Expand Down
3 changes: 3 additions & 0 deletions htdocs/theme/eldy/style.css.php
Expand Up @@ -439,6 +439,9 @@
{
border-right: 1px solid #DDD;
}
#formuserfile {
margin-top: 4px;
}
#formuserfile_link {
margin-left: 1px;
}
Expand Down

0 comments on commit 49a13f5

Please sign in to comment.