From b7d99271f86f2d6cedc87f31620b96168f5b071c Mon Sep 17 00:00:00 2001 From: phf Date: Fri, 19 Feb 2016 22:25:59 +0100 Subject: [PATCH 1/4] New add multicurrency on supplier order --- htdocs/core/class/commonobject.class.php | 2 +- .../fourn/class/fournisseur.facture.class.php | 67 ++++++++++++- htdocs/fourn/facture/card.php | 98 ++++++++++++++++++- 3 files changed, 162 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 70a51d2f8fd..51acd7d901a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1499,7 +1499,7 @@ abstract class CommonObject $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, $line->ref_fourn); break; case 'order_supplier': - $r = $this->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit); + $this->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit); break; default: dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 52c35040d2b..6c49ee7dda0 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -31,7 +31,7 @@ */ include_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php'; - +require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; /** * Class to manage suppliers invoices @@ -118,6 +118,14 @@ class FactureFournisseur extends CommonInvoice var $extraparams=array(); + // Multicurrency + var $fk_multicurrency; + var $multicurrency_code; + var $multicurrency_tx; + var $multicurrency_total_ht; + var $multicurrency_total_tva; + var $multicurrency_total_ttc; + /** * Constructor * @@ -162,6 +170,16 @@ class FactureFournisseur extends CommonInvoice $amount = $this->amount; $remise = $this->remise; + // Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate) + if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code); + else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + if (empty($this->fk_multicurrency)) + { + $this->multicurrency_code = $conf->currency; + $this->fk_multicurrency = 0; + $this->multicurrency_tx = 1; + } + $this->db->begin(); if (! $remise) $remise = 0 ; @@ -184,6 +202,9 @@ class FactureFournisseur extends CommonInvoice $sql.= ", fk_user_author"; $sql.= ", date_lim_reglement"; $sql.= ", fk_incoterms, location_incoterms"; + $sql.= ", fk_multicurrency"; + $sql.= ", multicurrency_code"; + $sql.= ", multicurrency_tx"; $sql.= ")"; $sql.= " VALUES ("; $sql.= "'(PROV)'"; @@ -203,6 +224,9 @@ class FactureFournisseur extends CommonInvoice $sql.= $this->date_echeance!=''?"'".$this->db->idate($this->date_echeance)."'":"null"; $sql.= ", ".(int) $this->fk_incoterms; $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; + $sql.= ", ".(int) $this->fk_multicurrency; + $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql.= ", ".(double) $this->multicurrency_tx; $sql.= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); @@ -375,7 +399,8 @@ class FactureFournisseur extends CommonInvoice $sql.= " p.code as mode_reglement_code, p.libelle as mode_reglement_libelle,"; $sql.= ' s.nom as socnom, s.rowid as socid,'; $sql.= ' t.fk_incoterms, t.location_incoterms,'; - $sql.= " i.libelle as libelle_incoterms"; + $sql.= " i.libelle as libelle_incoterms,"; + $sql.= ' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid)"; @@ -445,6 +470,14 @@ class FactureFournisseur extends CommonInvoice $this->location_incoterms = $obj->location_incoterms; $this->libelle_incoterms = $obj->libelle_incoterms; + // Multicurrency + $this->fk_multicurrency = $obj->fk_multicurrency; + $this->multicurrency_code = $obj->multicurrency_code; + $this->multicurrency_tx = $obj->multicurrency_tx; + $this->multicurrency_total_ht = $obj->multicurrency_total_ht; + $this->multicurrency_total_tva = $obj->multicurrency_total_tva; + $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; + $this->extraparams = (array) json_decode($obj->extraparams, true); $this->socid = $obj->socid; @@ -496,6 +529,7 @@ class FactureFournisseur extends CommonInvoice $sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; + $sql.= ', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid'; $sql.= ' WHERE fk_facture_fourn='.$this->id; @@ -547,6 +581,14 @@ class FactureFournisseur extends CommonInvoice $line->rang = $obj->rang; $line->fk_unit = $obj->fk_unit; + // Multicurrency + $line->fk_multicurrency = $objp->fk_multicurrency; + $line->multicurrency_code = $objp->multicurrency_code; + $line->multicurrency_subprice = $objp->multicurrency_subprice; + $line->multicurrency_total_ht = $objp->multicurrency_total_ht; + $line->multicurrency_total_tva = $objp->multicurrency_total_tva; + $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; + $this->lines[$i] = $line; $i++; @@ -1271,7 +1313,7 @@ class FactureFournisseur extends CommonInvoice $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$mysoc, $this->thirdparty); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - $tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type); + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; @@ -1280,6 +1322,12 @@ class FactureFournisseur extends CommonInvoice $pu_ttc = $tabprice[5]; $total_localtax1 = $tabprice[9]; $total_localtax2 = $tabprice[10]; + + // MultiCurrency + $multicurrency_total_ht = $tabprice[16]; + $multicurrency_total_tva = $tabprice[17]; + $multicurrency_total_ttc = $tabprice[18]; + if (empty($info_bits)) $info_bits=0; if ($idproduct) @@ -1321,6 +1369,12 @@ class FactureFournisseur extends CommonInvoice $line->fk_unit = $fk_unit; $line->array_options = $array_options; + // Multicurrency + $line->multicurrency_subprice = price2num($line->subprice * $this->multicurrency_tx); + $line->multicurrency_total_ht = $multicurrency_total_ht; + $line->multicurrency_total_tva = $multicurrency_total_tva; + $line->multicurrency_total_ttc = $multicurrency_total_ttc; + $res = $line->update($notrigger); if ($res < 1) { @@ -2163,6 +2217,13 @@ class SupplierInvoiceLine extends CommonObjectLine $sql.= ", product_type = ".$this->product_type; $sql.= ", info_bits = ".$this->info_bits; $sql.= ", fk_unit = ".$fk_unit; + + // Multicurrency + $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; + $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; + $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; + $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; + $sql.= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 518f09b5316..6860d5b6bb6 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -261,6 +261,16 @@ if (empty($reshook)) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); } + + // Multicurrency Code + else if ($action == 'setmulticurrencycode' && $user->rights->facture->creer) { + $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); + } + + // Multicurrency rate + else if ($action == 'setmulticurrencyrate' && $user->rights->facture->creer) { + $result = $object->setMulticurrencyRate(GETPOST('multicurrency_tx', 'int')); + } // bank account else if ($action == 'setbankaccount' && $user->rights->fournisseur->facture->creer) { @@ -368,6 +378,8 @@ if (empty($reshook)) $object->fk_project = ($tmpproject > 0) ? $tmpproject : null; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); + $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); // Auto calculation of date due if not filled by user if(empty($object->date_echeance)) $object->date_echeance = $object->calculate_date_lim_reglement(); @@ -1264,6 +1276,8 @@ if ($action == 'create') $societe->fetch(GETPOST('socid','int')); } + $currency_code = $conf->currency; + if (GETPOST('origin') && GETPOST('originid')) { // Parse element/subelement (ex: project_task) @@ -1308,6 +1322,12 @@ if ($action == 'create') $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''; + if (!empty($conf->multicurrency->enabled)) + { + if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; + } + $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datetmp); $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); @@ -1323,6 +1343,8 @@ if ($action == 'create') $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datetmp); $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); $datedue=($datetmp==''?-1:$datetmp); + + if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code; } @@ -1331,7 +1353,8 @@ if ($action == 'create') print ''; print ''; print ''; - + if (!empty($currency_tx)) print ''; + dol_fiche_head(); print ''; @@ -1490,6 +1513,16 @@ if ($action == 'create') $form->select_comptes($fk_account, 'fk_account', 0, '', 1); print ''; + // Multicurrency + if (! empty($conf->multicurrency->enabled)) + { + print ''; + print ''; + print ''; + } + // Public note print ''; print '"; + + if (!empty($conf->multicurrency->enabled)) + { + print ''; + print '"; + print '"; + } } else { @@ -1968,6 +2008,44 @@ else } print ''; + // Multicurrency + if (! empty($conf->multicurrency->enabled)) + { + // Multicurrency code + print ''; + print ''; + + // Multicurrency rate + print ''; + print ''; + } + // Bank Account print '
'.fieldLabel('Currency','multicurrency_code').''; + print $form->selectMultiCurrency($currency_code, 'multicurrency_code'); + print '
'.$langs->trans('NotePublic').''; @@ -1555,6 +1588,13 @@ if ($action == 'create') } } print '
'.$langs->trans('TotalTTC').''.price($objectsrc->total_ttc)."
' . $langs->trans('MulticurrencyTotalHT') . '' . price($objectsrc->multicurrency_total_ht) . '
' . $langs->trans('MulticurrencyTotalVAT') . '' . price($objectsrc->multicurrency_total_tva) . "
' . $langs->trans('MulticurrencyTotalTTC') . '' . price($objectsrc->multicurrency_total_ttc) . "
'; + print ''; + if ($action != 'editmulticurrencycode' && ! empty($object->brouillon)) + print ''; + print '
'; + print fieldLabel('Currency','multicurrency_code'); + print 'id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '
'; + print '
'; + if ($action == 'editmulticurrencycode') { + $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'multicurrency_code'); + } else { + $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'none'); + } + print '
'; + print ''; + if ($action != 'editmulticurrencyrate' && ! empty($object->brouillon)) + print ''; + print '
'; + print fieldLabel('Rate','multicurrency_tx'); + print 'id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '
'; + print '
'; + if ($action == 'editmulticurrencyrate') { + $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx'); + } else { + $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none'); + } + print '
'; print ''; + if (!empty($conf->multicurrency->enabled)) + { + // Multicurrency Amount HT + print ''; + print ''; + print ''; + + // Multicurrency Amount VAT + print ''; + print ''; + print ''; + + // Multicurrency Amount TTC + print ''; + print ''; + print ''; + } + // Project if (! empty($conf->projet->enabled)) { From d320aebe824341ef95c9117f100a377dabe6a3bf Mon Sep 17 00:00:00 2001 From: phf Date: Fri, 19 Feb 2016 22:41:47 +0100 Subject: [PATCH 2/4] Fix muticurrency attributs not declared in class PropalLine Fix fetch_lines of FactureFournisseur with multicurrency fields --- htdocs/compta/facture/class/facture.class.php | 8 +++++++ .../fourn/class/fournisseur.facture.class.php | 21 ++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 8fd43f3d5c8..0b34c42cbad 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4030,6 +4030,14 @@ class FactureLigne extends CommonInvoiceLine */ public $fk_prev_id; + // Multicurrency + var $fk_multicurrency; + var $multicurrency_code; + var $multicurrency_subprice; + var $multicurrency_total_ht; + var $multicurrency_total_tva; + var $multicurrency_total_ttc; + /** * Load invoice line from database * diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 6c49ee7dda0..a6bfef7427b 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -529,7 +529,7 @@ class FactureFournisseur extends CommonInvoice $sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; - $sql.= ', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,'; + $sql.= ', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid'; $sql.= ' WHERE fk_facture_fourn='.$this->id; @@ -582,12 +582,12 @@ class FactureFournisseur extends CommonInvoice $line->fk_unit = $obj->fk_unit; // Multicurrency - $line->fk_multicurrency = $objp->fk_multicurrency; - $line->multicurrency_code = $objp->multicurrency_code; - $line->multicurrency_subprice = $objp->multicurrency_subprice; - $line->multicurrency_total_ht = $objp->multicurrency_total_ht; - $line->multicurrency_total_tva = $objp->multicurrency_total_tva; - $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; + $line->fk_multicurrency = $obj->fk_multicurrency; + $line->multicurrency_code = $obj->multicurrency_code; + $line->multicurrency_subprice = $obj->multicurrency_subprice; + $line->multicurrency_total_ht = $obj->multicurrency_total_ht; + $line->multicurrency_total_tva = $obj->multicurrency_total_tva; + $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc; $this->lines[$i] = $line; @@ -2025,6 +2025,13 @@ class SupplierInvoiceLine extends CommonObjectLine public $localtax1_type; public $localtax2_type; + // Multicurrency + var $fk_multicurrency; + var $multicurrency_code; + var $multicurrency_subprice; + var $multicurrency_total_ht; + var $multicurrency_total_tva; + var $multicurrency_total_ttc; /** * Constructor From ec0282a28e453558f14fd29b82b1f8feb0eb6af9 Mon Sep 17 00:00:00 2001 From: phf Date: Sun, 21 Feb 2016 13:26:48 +0100 Subject: [PATCH 3/4] New add multicurrency display on supplier payment --- htdocs/fourn/facture/paiement.php | 86 ++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 124693ed6da..7aab308d2fa 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -65,7 +65,12 @@ if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="p.rowid"; $optioncss = GETPOST('optioncss','alpha'); -$amounts = array(); +$amounts = array();array(); +$amountsresttopay=array(); +$addwarning=0; + +$multicurrency_amounts=array(); +$multicurrency_amountsresttopay=array(); // Security check if ($user->societe_id > 0) @@ -144,6 +149,34 @@ if (empty($reshook)) $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); } + elseif (substr($key,0,21) == 'multicurrency_amount_') + { + $cursorfacid = substr($key,21); + $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid]; + if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++; + $result=$tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1)); + if ($multicurrency_amounts[$cursorfacid]) + { + // Check amount + if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) + { + $addwarning=1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); + } + // Check date + if ($datepaye && ($datepaye < $tmpinvoice->date)) + { + $langs->load("errors"); + //$error++; + setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); + } + } + + $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => GETPOST($key, 'int')); + } } // Check parameters @@ -163,7 +196,7 @@ if (empty($reshook)) } } - if (empty($totalpayment) && empty($atleastonepaymentnotnull)) + if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) { setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors'); $error++; @@ -174,6 +207,13 @@ if (empty($reshook)) setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors'); $error++; } + + // Check if payments in both currency + if ($totalpayment > 0 && $multicurrency_totalpayment > 0) + { + setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors'); + $error++; + } } /* @@ -206,6 +246,7 @@ if (empty($reshook)) $paiement = new PaiementFourn($db); $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array of amounts + $paiement->multicurrency_amounts = $multicurrency_amounts; $paiement->paiementid = $_POST['paiementid']; $paiement->num_paiement = $_POST['num_paiement']; $paiement->note = $_POST['comment']; @@ -344,8 +385,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie /* * Autres factures impayees */ - $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.datef as df'; - $sql.= ', SUM(pf.amount) as am'; + $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df'; + $sql.= ', SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; $sql.= " WHERE f.entity = ".$conf->entity; @@ -378,9 +419,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print ''; print ''; + if (!empty($conf->multicurrency->enabled)) print ''; print ''; + if (!empty($conf->multicurrency->enabled)) print ''; print ''; + if (!empty($conf->multicurrency->enabled)) print ''; print ''; + if (!empty($conf->multicurrency->enabled)) print ''; print ''; $var=True; @@ -408,14 +453,39 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; } print ''; + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) print ''; + print ''; + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) print ''; + print ''; + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) print ''; + print '\n"; + print ""; + + // Multicurrency + if (!empty($conf->multicurrency->enabled)) + { + print '"; + } + + print "\n"; $total+=$objp->total_ht; $total_ttc+=$objp->total_ttc; $totalrecu+=$objp->am; @@ -455,7 +525,11 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $preselectedchoice=$addwarning?'no':'yes'; print '
'; - $text=$langs->trans('ConfirmSupplierPayment',$totalpayment,$langs->trans("Currency".$conf->currency)); + if (!empty($totalpayment)) $text=$langs->trans('ConfirmSupplierPayment',$totalpayment,$langs->trans("Currency".$conf->currency)); + if (!empty($multicurrency_totalpayment)) + { + $text.='
'.$langs->trans('ConfirmSupplierPayment',$multicurrency_totalpayment,$langs->trans("paymentInInvoiceCurrency")); + } if (GETPOST('closepaidinvoices')) { $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); From fd4cda819c4f5e6215321e7935000d58d7f3d723 Mon Sep 17 00:00:00 2001 From: phf Date: Sun, 21 Feb 2016 22:47:52 +0100 Subject: [PATCH 4/4] New add supplier payment --- .../compta/paiement/class/paiement.class.php | 2 +- htdocs/fourn/class/paiementfourn.class.php | 86 ++++++++++++++++--- htdocs/fourn/facture/card.php | 5 +- htdocs/fourn/facture/paiement.php | 2 + .../install/mysql/migration/3.9.0-4.0.0.sql | 1 + .../mysql/tables/llx_paiementfourn.sql | 1 + 6 files changed, 80 insertions(+), 17 deletions(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 7b6c7dd2f5b..daf43ec9d64 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -150,7 +150,7 @@ class Paiement extends CommonObject global $conf, $langs; $error = 0; - $way = $this->getWay(); + $way = $this->getWay(); $now=dol_now(); diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index bb84f8ca917..940de150765 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -27,6 +27,7 @@ */ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; +require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; /** * Class to manage payments for supplier invoices @@ -134,29 +135,58 @@ class PaiementFourn extends Paiement global $langs,$conf; $error = 0; + $way = $this->getWay(); // Clean parameters - $this->total = 0; - foreach ($this->amounts as $key => $value) + $totalamount = 0; + $totalamount_converted = 0; + + if ($way == 'dolibarr') { - $newvalue = price2num($value, 'MT'); - $this->amounts[$key] = $newvalue; - $this->total += $newvalue; + $amounts = &$this->amounts; + $amounts_to_update = &$this->multicurrency_amounts; } - $this->total = price2num($this->total); - + else + { + $amounts = &$this->multicurrency_amounts; + $amounts_to_update = &$this->amounts; + } + + foreach ($amounts as $key => $value) + { + $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way, 'facture_fourn'); + $totalamount_converted += $value_converted; + $amounts_to_update[$key] = price2num($value_converted, 'MT'); + + $newvalue = price2num($value,'MT'); + $amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + $totalamount_converted = price2num($totalamount_converted); $this->db->begin(); - if ($this->total <> 0) // On accepte les montants negatifs + if ($totalamount <> 0) // On accepte les montants negatifs { $ref = $this->getNextNumRef(''); $now=dol_now(); - + + if ($way == 'dolibarr') + { + $total = $totalamount; + $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value + } + else + { + $total = $totalamount_converted; // Maybe use price2num with MT for the converted value + $mtotal = $totalamount; + } + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn ('; - $sql.= 'ref, entity, datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)'; + $sql.= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)'; $sql.= " VALUES ('".$this->db->escape($ref)."', ".$conf->entity.", '".$this->db->idate($now)."',"; - $sql.= " '".$this->db->idate($this->datepaye)."', '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)"; + $sql.= " '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)"; dol_syslog("PaiementFourn::create", LOG_DEBUG); $resql = $this->db->query($sql); @@ -171,8 +201,8 @@ class PaiementFourn extends Paiement if (is_numeric($amount) && $amount <> 0) { $amount = price2num($amount); - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)'; - $sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')'; + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)'; + $sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')'; $resql=$this->db->query($sql); if ($resql) { @@ -229,8 +259,11 @@ class PaiementFourn extends Paiement $error++; } - if ($this->total <> 0 && $error == 0) // On accepte les montants negatifs + if ($totalamount <> 0 && $error == 0) // On accepte les montants negatifs { + $this->amount=$total; + $this->total=$total; + $this->multicurrency_amount=$mtotal; $this->db->commit(); dol_syslog('PaiementFourn::Create Ok Total = '.$this->total); return $this->id; @@ -625,4 +658,29 @@ class PaiementFourn extends Paiement return ""; } } + + /** + * get the right way of payment + * + * @return string 'dolibarr' if standard comportment or paid in dolibarr currency, 'customer' if payment received from multicurrency inputs + */ + function getWay() + { + global $conf; + + $way = 'dolibarr'; + if (!empty($conf->multicurrency->enabled)) + { + foreach ($this->multicurrency_amounts as $value) + { + if (!empty($value)) // one value found then payment is in invoice currency + { + $way = 'customer'; + break; + } + } + } + + return $way; + } } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 6860d5b6bb6..73def71adc1 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1269,14 +1269,15 @@ if ($action == 'create') dol_htmloutput_events(); + $currency_code = $conf->currency; + $societe=''; if (GETPOST('socid') > 0) { $societe=new Societe($db); $societe->fetch(GETPOST('socid','int')); + if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code; } - - $currency_code = $conf->currency; if (GETPOST('origin') && GETPOST('originid')) { diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 7aab308d2fa..dd9d8fae87f 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -497,7 +497,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print ''; print ''; + if (!empty($conf->multicurrency->enabled)) print ''; print ''; + if (!empty($conf->multicurrency->enabled)) print ''; print ''; print ''; print "\n"; diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index 2b38f915869..c05af05a2d5 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -262,6 +262,7 @@ ALTER TABLE llx_contratdet ADD COLUMN multicurrency_total_ttc double(24,8) DEFAU ALTER TABLE llx_paiement ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; ALTER TABLE llx_paiement_facture ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; +ALTER TABLE llx_paiementfourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; ALTER TABLE llx_paiementfourn_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ht double(24,8) NOT NULL; diff --git a/htdocs/install/mysql/tables/llx_paiementfourn.sql b/htdocs/install/mysql/tables/llx_paiementfourn.sql index cbcc93d9b0f..aba54627a09 100644 --- a/htdocs/install/mysql/tables/llx_paiementfourn.sql +++ b/htdocs/install/mysql/tables/llx_paiementfourn.sql @@ -26,6 +26,7 @@ create table llx_paiementfourn datec datetime, -- date de creation de l'enregistrement datep datetime, -- date de paiement amount real DEFAULT 0, -- montant + multicurrency_amount double(24,8) DEFAULT 0, -- multicurrency amount fk_user_author integer, -- auteur fk_paiement integer NOT NULL, -- moyen de paiement num_paiement varchar(50), -- numero de paiement (cheque)
'; @@ -2019,6 +2097,24 @@ else } print '
'.$langs->trans('AmountTTC').''.price($object->total_ttc,1,$langs,0,-1,-1,$conf->currency).'
' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
'.$langs->trans('RefSupplier').''.$langs->trans('Date').''.$langs->trans('AmountTTC').''.$langs->trans('MulticurrencyAmountTTC').''.$langs->trans('AlreadyPaid').''.$langs->trans('MulticurrencyAlreadyPaid').''.$langs->trans('RemainderToPay').''.$langs->trans('MulticurrencyRemainderToPay').''.$langs->trans('PaymentAmount').''.$langs->trans('MulticurrencyPaymentAmount').'
!!!'.price($objp->total_ttc).''.price($objp->multicurrency_total_ttc).''.price($objp->am).''.price($objp->multicurrency_am).''.price($objp->total_ttc - $objp->am).''.price($objp->multicurrency_total_ttc - $objp->multicurrency_am).''; $namef = 'amount_'.$objp->facid; if(!empty($conf->global->FAC_AUTO_FILLJS)) print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->total_ttc - $objp->am)."'"); print ''; - print "
'; + $namef = 'multicurrency_amount_'.$objp->facid; + if(!empty($conf->global->FAC_AUTO_FILLJS)) + print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->multicurrency_total_ttc - $objp->multicurrency_am)."'"); + print ''; + print "
'.$langs->trans('TotalTTC').':'.price($total_ttc).' '.price($totalrecu).' '.price($total_ttc - $totalrecu).'