Better management of vat with code

This commit is contained in:
Laurent Destailleur 2017-07-08 18:50:58 +02:00
parent f40afcf023
commit f32b27e8bd
2 changed files with 15 additions and 20 deletions

View File

@ -1080,11 +1080,10 @@ if (empty($reshook))
// if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
if (empty($vatrate)) $vatrate = "0.000"; if (empty($vatrate)) $vatrate = "0.000";
$object_ligne->vatrate = price2num($vatrate);
$object_ligne->fk_projet = $fk_projet; $object_ligne->fk_projet = $fk_projet;
if (! GETPOST('fk_c_type_fees') > 0) if (! (GETPOST('fk_c_type_fees') > 0))
{ {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
@ -1949,7 +1948,7 @@ else
// Fetch Lines of current expense report // Fetch Lines of current expense report
$sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,'; $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,';
$sql.= ' fde.tva_tx as vatrate, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,'; $sql.= ' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,';
$sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
$sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref'; $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
$sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde';
@ -2028,7 +2027,7 @@ else
// print '<td style="text-align:center;">'.$langs->trans("TF_".strtoupper(empty($objp->type_fees_libelle)?'OTHER':$objp->type_fees_libelle)).'</td>'; // print '<td style="text-align:center;">'.$langs->trans("TF_".strtoupper(empty($objp->type_fees_libelle)?'OTHER':$objp->type_fees_libelle)).'</td>';
print '<td style="text-align:center;">'.($langs->trans(($objp->type_fees_code)) == $objp->type_fees_code ? $objp->type_fees_libelle : $langs->trans(($objp->type_fees_code))).'</td>'; print '<td style="text-align:center;">'.($langs->trans(($objp->type_fees_code)) == $objp->type_fees_code ? $objp->type_fees_libelle : $langs->trans(($objp->type_fees_code))).'</td>';
print '<td style="text-align:left;">'.$objp->comments.'</td>'; print '<td style="text-align:left;">'.$objp->comments.'</td>';
print '<td style="text-align:right;">'.vatrate($objp->vatrate,true).'</td>'; print '<td style="text-align:right;">'.vatrate($objp->vatrate.($objp->vat_src_code?' ('.$objp->vat_src_code.')':''),true).'</td>';
print '<td style="text-align:right;">'.price($objp->value_unit).'</td>'; print '<td style="text-align:right;">'.price($objp->value_unit).'</td>';
print '<td style="text-align:right;">'.$objp->qty.'</td>'; print '<td style="text-align:right;">'.$objp->qty.'</td>';
@ -2082,24 +2081,25 @@ else
// Add comments // Add comments
print '<td>'; print '<td>';
print '<textarea name="comments" class="flat_ndf centpercent">'.$objp->comments.'</textarea>'; print '<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($objp->comments).'</textarea>';
print '</td>'; print '</td>';
// VAT // VAT
print '<td style="text-align:right;">'; print '<td style="text-align:right;">';
$seller=$mysoc; $seller=$mysoc;
$buyer=new Societe($db); $buyer=new Societe($db);
print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $seller, $buyer, 0, 0, '', false, 1); $selectedvat=(GETPOST("vatrate",'alpha')?GETPOST("vatrate",'alpha'):$objp->vatrate.($objp->vat_src_code?' ('.$objp->vat_src_code.')':''));
print $form->load_tva('vatrate', $selectedvat, $seller, $buyer, 0, 0, '', false, 1);
print '</td>'; print '</td>';
// Unit price // Unit price
print '<td style="text-align:right;">'; print '<td style="text-align:right;">';
print '<input type="text" min="0" class="maxwidth100" name="value_unit" value="'.$objp->value_unit.'" />'; print '<input type="text" min="0" class="maxwidth100" name="value_unit" value="'.dol_escape_htmltag($objp->value_unit).'" />';
print '</td>'; print '</td>';
// Quantity // Quantity
print '<td style="text-align:right;">'; print '<td style="text-align:right;">';
print '<input type="number" min="0" class="maxwidth100" name="qty" value="'.$objp->qty.'" />'; print '<input type="text" min="0" class="maxwidth50" name="qty" value="'.$objp->qty.'" />'; // We must be able to enter decimal qty
print '</td>'; print '</td>';
if ($action != 'editline') if ($action != 'editline')
@ -2120,13 +2120,6 @@ else
$db->free($resql); $db->free($resql);
} }
else
{
/* print '<table width="100%">';
print '<tr><td><div class="error" style="display:block;">'.$langs->trans("AucuneLigne").'</div></td></tr>';
print '</table>';*/
}
//print '</div>';
// Add a line // Add a line
if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline' && $user->rights->expensereport->creer) if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline' && $user->rights->expensereport->creer)
@ -2143,7 +2136,6 @@ else
print '<td colspan="3"></td>'; print '<td colspan="3"></td>';
print '</tr>'; print '</tr>';
print '<tr '.$bc[true].'>'; print '<tr '.$bc[true].'>';
print '<td></td>'; print '<td></td>';
@ -2180,12 +2172,12 @@ else
// Unit price // Unit price
print '<td align="right">'; print '<td align="right">';
print '<input type="text" class="right maxwidth50" name="value_unit" value="'.$value_unit.'">'; print '<input type="text" class="right maxwidth50" name="value_unit" value="'.(GETPOST('value_unit','alpha')?GETPOST('value_unit','alpha'):dol_escape_htmltag($value_unit)).'">';
print '</td>'; print '</td>';
// Quantity // Quantity
print '<td align="right">'; print '<td align="right">';
print '<input type="number" min="0" class="right maxwidth50" name="qty" value="'.($qty?$qty:1).'">'; print '<input type="text" min="0" class="right maxwidth50" name="qty" value="'.($qty?$qty:1).'">'; // We must be able to enter decimal qty
print '</td>'; print '</td>';
if ($action != 'editline') if ($action != 'editline')

View File

@ -2058,7 +2058,7 @@ class ExpenseReportLine
function fetch($rowid) function fetch($rowid)
{ {
$sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,'; $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,';
$sql.= ' fde.tva_tx as vatrate, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,'; $sql.= ' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,';
$sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
$sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref'; $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
$sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde';
@ -2087,6 +2087,7 @@ class ExpenseReportLine
$this->projet_ref = $objp->projet_ref; $this->projet_ref = $objp->projet_ref;
$this->projet_title = $objp->projet_title; $this->projet_title = $objp->projet_title;
$this->vatrate = $objp->vatrate; $this->vatrate = $objp->vatrate;
$this->vat_src_code = $objp->vat_src_code;
$this->total_ht = $objp->total_ht; $this->total_ht = $objp->total_ht;
$this->total_tva = $objp->total_tva; $this->total_tva = $objp->total_tva;
$this->total_ttc = $objp->total_ttc; $this->total_ttc = $objp->total_ttc;
@ -2121,11 +2122,12 @@ class ExpenseReportLine
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det';
$sql.= ' (fk_expensereport, fk_c_type_fees, fk_projet,'; $sql.= ' (fk_expensereport, fk_c_type_fees, fk_projet,';
$sql.= ' tva_tx, comments, qty, value_unit, total_ht, total_tva, total_ttc, date)'; $sql.= ' tva_tx, vat_src_code, comments, qty, value_unit, total_ht, total_tva, total_ttc, date)';
$sql.= " VALUES (".$this->fk_expensereport.","; $sql.= " VALUES (".$this->fk_expensereport.",";
$sql.= " ".$this->fk_c_type_fees.","; $sql.= " ".$this->fk_c_type_fees.",";
$sql.= " ".($this->fk_projet>0?$this->fk_projet:'null').","; $sql.= " ".($this->fk_projet>0?$this->fk_projet:'null').",";
$sql.= " ".$this->vatrate.","; $sql.= " ".$this->vatrate.",";
$sql.= " '".$this->db->escape($this->vat_src_code)."',";
$sql.= " '".$this->db->escape($this->comments)."',"; $sql.= " '".$this->db->escape($this->comments)."',";
$sql.= " ".$this->qty.","; $sql.= " ".$this->qty.",";
$sql.= " ".$this->value_unit.","; $sql.= " ".$this->value_unit.",";
@ -2196,6 +2198,7 @@ class ExpenseReportLine
$sql.= ",total_tva=".$this->total_tva.""; $sql.= ",total_tva=".$this->total_tva."";
$sql.= ",total_ttc=".$this->total_ttc.""; $sql.= ",total_ttc=".$this->total_ttc."";
$sql.= ",tva_tx=".$this->vatrate; $sql.= ",tva_tx=".$this->vatrate;
$sql.= ",vat_src_code='".$this->db->escape($this->vat_src_code)."'";
if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->fk_c_type_fees; if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->fk_c_type_fees;
else $sql.= ",fk_c_type_fees=null"; else $sql.= ",fk_c_type_fees=null";
if ($this->fk_projet) $sql.= ",fk_projet=".$this->fk_projet; if ($this->fk_projet) $sql.= ",fk_projet=".$this->fk_projet;