Fix better support for multicurrency for template invoices

This commit is contained in:
Laurent Destailleur 2019-11-03 18:58:26 +01:00
parent 630a150b09
commit 99a4781a42
4 changed files with 83 additions and 19 deletions

View File

@ -25,7 +25,7 @@
*/
/**
* \file htdocs/compta/facture/fiche-rec.php
* \file htdocs/compta/facture/card-rec.php
* \ingroup facture
* \brief Page to show predefined invoice
*/
@ -387,6 +387,15 @@ if (empty($reshook))
setEventMessages($object->error, $object->errors, 'errors');
}
}
// Multicurrency Code
elseif ($action == 'setmulticurrencycode' && $usercancreate) {
$result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
}
// Multicurrency rate
elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
$result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
}
// Delete line
if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer)
@ -1346,6 +1355,52 @@ else
}
print '</td></tr>';
// Multicurrency
if (! empty($conf->multicurrency->enabled))
{
// Multicurrency code
print '<tr>';
print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
print '</td>';
if ($usercancreate && $action != 'editmulticurrencycode' && ! empty($object->brouillon))
print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencycode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
print '</tr></table>';
print '</td><td>';
$htmlname = (($usercancreate && $action == 'editmulticurrencycode')?'multicurrency_code':'none');
$form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, $htmlname);
print '</td></tr>';
// Multicurrency rate
if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
{
print '<tr>';
print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
print '</td>';
if ($usercancreate && $action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencyrate&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
print '</tr></table>';
print '</td><td>';
if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
if($action == 'actualizemulticurrencyrate') {
list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
}
$form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, ($usercancreate?'multicurrency_tx':'none'), $object->multicurrency_code);
} else {
$form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
if($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
print '</div>';
}
}
print '</td></tr>';
}
}
// Help of substitution key
$dateexample=dol_now();
if (! empty($object->frequency) && ! empty($object->date_when)) $dateexample=$object->date_when;
@ -1701,11 +1756,11 @@ else
{
if (empty($object->suspended))
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?action=disable&id='.$object->id.'">'.$langs->trans("Disable").'</a></div>';
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/facture/card-rec.php?action=disable&id='.$object->id.'">'.$langs->trans("Disable").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?action=enable&id='.$object->id.'">'.$langs->trans("Enable").'</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card-rec.php?action=enable&id='.$object->id.'">'.$langs->trans("Enable").'</a></div>';
}
}

View File

@ -2579,7 +2579,6 @@ $title = $langs->trans('InvoiceCustomer') . " - " . $langs->trans('Card');
$helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
llxHeader('', $title, $helpurl);
// Mode creation
if ($action == 'create')
@ -2600,18 +2599,19 @@ if ($action == 'create')
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
$regs = array();
if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
$element = $regs [1];
$subelement = $regs [2];
$element = $reg[1];
$subelement = $regs[2];
}
if ($element == 'project') {
$projectid = $originid;
if (!$cond_reglement_id) {
if (empty($cond_reglement_id)) {
$cond_reglement_id = $soc->cond_reglement_id;
}
if (!$mode_reglement_id) {
if (empty($mode_reglement_id)) {
$mode_reglement_id = $soc->mode_reglement_id;
}
if (!$remise_percent) {
@ -2754,7 +2754,7 @@ if ($action == 'create')
// Thirdparty
print '<td class="fieldrequired">' . $langs->trans('Customer') . '</td>';
if ($soc->id > 0 && ! GETPOST('fac_rec', 'alpha'))
if ($soc->id > 0 && ! GETPOST('fac_rec', 'int'))
{
print '<td colspan="2">';
print $soc->getNomUrl(1);
@ -2797,7 +2797,7 @@ if ($action == 'create')
$exampletemplateinvoice=new FactureRec($db);
// Overwrite value if creation of invoice is from a predefined invoice
// Overwrite some values if creation of invoice is from a predefined invoice
if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0)
{
$invoice_predefined = new FactureRec($db);
@ -2811,6 +2811,9 @@ if ($action == 'create')
$note_public = $invoice_predefined->note_public;
$note_private = $invoice_predefined->note_private;
if (! empty($invoice_predefined->multicurrency_code)) $currency_code = $invoice_predefined->multicurrency_code;
if (! empty($invoice_predefined->multicurrency_tx)) $currency_tx = $invoice_predefined->multicurrency_tx;
$sql = 'SELECT r.rowid, r.titre as title, r.total_ttc';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r';
$sql .= ' WHERE r.fk_soc = ' . $invoice_predefined->socid;
@ -2833,7 +2836,7 @@ if ($action == 'create')
if (GETPOST('fac_rec') == $objp->rowid)
{
print ' selected';
$exampletemplateinvoice->fetch(GETPOST('fac_rec'));
$exampletemplateinvoice->fetch(GETPOST('fac_rec', 'int'));
}
print '>' . $objp->title . ' (' . price($objp->total_ttc) . ' ' . $langs->trans("TTC") . ')</option>';
$i ++;
@ -2921,12 +2924,17 @@ if ($action == 'create')
// Next situation invoice
$opt = $form->selectSituationInvoices(GETPOST('originid'), $socid);
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" name="type" value="5"' . (GETPOST('type') == 5 && GETPOST('originid') ? ' checked' : '');
if ($opt == ('<option value ="0" selected>' . $langs->trans('NoSituations') . '</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) $tmp.=' disabled';
if ($opt == ('<option value ="0" selected>' . $langs->trans('NoSituations') . '</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande'))
$tmp.=' disabled';
$tmp.= '> ';
$text = '<label>'.$tmp.$langs->trans("InvoiceSituationAsk") . '</label> ';
$text .= '<select class="flat" id="situations" name="situations">';
$text .= '<select class="flat" id="situations" name="situations"';
if ($opt == ('<option value ="0" selected>' . $langs->trans('NoSituations') . '</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande'))
$text .= ' disabled';
$text .='>';
$text .= $opt;
$text .= '</select>';
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceSituationDesc"), 1, 'help', '', 0, 3);
@ -5026,7 +5034,7 @@ elseif ($id > 0 || ! empty($ref))
{
if (! $objectidnext && count($object->lines) > 0)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid=' . $object->id . '&amp;action=create">' . $langs->trans("ChangeIntoRepeatableInvoice") . '</a>';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card-rec.php?facid=' . $object->id . '&amp;action=create">' . $langs->trans("ChangeIntoRepeatableInvoice") . '</a>';
}
}

View File

@ -896,7 +896,7 @@ class FactureRec extends CommonInvoice
* @param int $date_start_fill 1=Flag to fill start date when generating invoice
* @param int $date_end_fill 1=Flag to fill end date when generating invoice
* @param int $fk_fournprice Id of origin supplier price
* @param int $pa_ht Price (without tax) of product when it was bought
* @param int $pa_ht Price (without tax) of product for margin calculation
* @return int <0 if KO, Id of line if OK
*/
public function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = '', $pu_ttc = 0, $type = 0, $rang = -1, $special_code = 0, $label = '', $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $date_start_fill = 0, $date_end_fill = 0, $fk_fournprice = null, $pa_ht = 0)
@ -920,8 +920,9 @@ class FactureRec extends CommonInvoice
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (empty($info_bits)) $info_bits=0;
$pu_ht=price2num($pu_ht);
$pu_ttc=price2num($pu_ttc);
$pu_ht = price2num($pu_ht);
$pu_ttc = price2num($pu_ttc);
$pu_ht_devise = price2num($pu_ht_devise);
$txtva=price2num($txtva);
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
@ -1258,7 +1259,7 @@ class FactureRec extends CommonInvoice
}
}
$url = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid='.$this->id;
$url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
if ($short) return $url;

View File

@ -189,7 +189,7 @@ function invoice_rec_prepare_head($object)
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?id='.$object->id;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/card-rec.php?id='.$object->id;
$head[$h][1] = $langs->trans("CardBill");
$head[$h][2] = 'card';
$h++;