From 99a4781a429224356592bfc8299120f029ebca70 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Nov 2019 18:58:26 +0100 Subject: [PATCH] Fix better support for multicurrency for template invoices --- .../facture/{fiche-rec.php => card-rec.php} | 61 ++++++++++++++++++- htdocs/compta/facture/card.php | 30 +++++---- .../facture/class/facture-rec.class.php | 9 +-- htdocs/core/lib/invoice.lib.php | 2 +- 4 files changed, 83 insertions(+), 19 deletions(-) rename htdocs/compta/facture/{fiche-rec.php => card-rec.php} (95%) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/card-rec.php similarity index 95% rename from htdocs/compta/facture/fiche-rec.php rename to htdocs/compta/facture/card-rec.php index 2c5cd1a87c7..10eb2ac03c8 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -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 ''; + // Multicurrency + if (! empty($conf->multicurrency->enabled)) + { + // Multicurrency code + print ''; + print ''; + print ''; + if ($usercancreate && $action != 'editmulticurrencycode' && ! empty($object->brouillon)) + print ''; + print '
'; + print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); + print 'id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '
'; + print ''; + $htmlname = (($usercancreate && $action == 'editmulticurrencycode')?'multicurrency_code':'none'); + $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, $htmlname); + print ''; + + // Multicurrency rate + if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) + { + print ''; + print ''; + print ''; + if ($usercancreate && $action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) + print ''; + print '
'; + print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); + print 'id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '
'; + print ''; + 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 '
        '; + print ''.$langs->trans("ActualizeCurrency").''; + print '
'; + } + } + print ''; + } + } + // 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 '
'.$langs->trans("Disable").'
'; + print '
'.$langs->trans("Disable").'
'; } else { - print '
'.$langs->trans("Enable").'
'; + print '
'.$langs->trans("Enable").'
'; } } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 7aff05a8c03..fce1fb7cb25 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -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 '' . $langs->trans('Customer') . ''; - if ($soc->id > 0 && ! GETPOST('fac_rec', 'alpha')) + if ($soc->id > 0 && ! GETPOST('fac_rec', 'int')) { print ''; 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") . ')'; $i ++; @@ -2921,12 +2924,17 @@ if ($action == 'create') // Next situation invoice $opt = $form->selectSituationInvoices(GETPOST('originid'), $socid); + print '
'; $tmp='' . $langs->trans('NoSituations') . '') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) $tmp.=' disabled'; + if ($opt == ('') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) + $tmp.=' disabled'; $tmp.= '> '; $text = ' '; - $text .= '' . $langs->trans('NoSituations') . '') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) + $text .= ' disabled'; + $text .='>'; $text .= $opt; $text .= ''; $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 '' . $langs->trans("ChangeIntoRepeatableInvoice") . ''; + print '' . $langs->trans("ChangeIntoRepeatableInvoice") . ''; } } diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 9ff90b7b025..408ce2c1303 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -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; diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 004f355a27a..7dfee37666a 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -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++;