diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index f0ce82cfb6453315183b8aa25ec3e156855bf4e6..a9ccf2471db67474de622db9c95bb6f97dfa61aa 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -829,7 +829,7 @@ if ($action == "addline") $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; @@ -877,7 +877,7 @@ if ($action == "addline") $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]; @@ -905,11 +905,11 @@ if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes") $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) @@ -950,11 +950,12 @@ if ($action == "updateligne" ) $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) { @@ -971,7 +972,7 @@ if ($action == "updateligne" ) 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) @@ -994,8 +995,9 @@ if ($action == "updateligne" ) } } - $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 @@ -1369,7 +1371,7 @@ else 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>'; } @@ -1635,7 +1637,7 @@ else // 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 @@ -1711,7 +1713,7 @@ else print '<td style="text-align:center;"></td>'; print '</tr>'; - print '<tr>'; + print '<tr '.$bc[true].'>'; // Select date print '<td style="text-align:center;">'; diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index d6b767da849e93219621be7be80a00fa2502ea92..3a0a15d6d819144ad6e9cd2d92084a7cd74f9fab 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -282,7 +282,7 @@ class ExpenseReport extends CommonObject */ 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 @@ -298,10 +298,10 @@ class ExpenseReport extends CommonObject $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; @@ -367,7 +367,7 @@ class ExpenseReport extends CommonObject $result=$this->fetch_lines(); - return 1; + return $result; } else { @@ -376,7 +376,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$db->lasterror(); + $this->error=$this->db->lasterror(); return -1; } } @@ -663,6 +663,7 @@ class ExpenseReport extends CommonObject /** * 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 @@ -733,14 +734,15 @@ class ExpenseReport extends CommonObject $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; @@ -769,13 +771,13 @@ class ExpenseReport extends CommonObject $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; } } @@ -1198,30 +1200,36 @@ class ExpenseReport extends CommonObject } - - 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); @@ -1230,15 +1238,14 @@ class ExpenseReport extends CommonObject $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 @@ -1259,16 +1266,19 @@ class ExpenseReport extends CommonObject $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; + } } } @@ -1566,15 +1576,17 @@ class ExpenseReportLine $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.","; @@ -1631,6 +1643,7 @@ class ExpenseReportLine // Clean parameters $this->comments=trim($this->comments); + $this->vatrate = price2num($this->vatrate); $this->db->begin(); @@ -1639,14 +1652,11 @@ class ExpenseReportLine $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; @@ -1660,16 +1670,30 @@ class ExpenseReportLine $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) { diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 28f4ab69f71fb23d627ad0e43922dee74899c154..be2984cb0e0d9eb6ec6f6ecfcc14f680ebf035b2 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -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, @@ -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); diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index d024f99a87da809871c02e82312679c3b06c843c..021a2483458d53b686d492964324201fd70f5ee0 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -439,6 +439,9 @@ textarea.centpercent { { border-right: 1px solid #DDD; } +#formuserfile { + margin-top: 4px; +} #formuserfile_link { margin-left: 1px; }