Merge pull request #7084 from atm-florian/develop
FIX Transfer between account with different currencies
This commit is contained in:
commit
451508ba20
@ -539,8 +539,9 @@ class AccountancyCategory
|
|||||||
/**
|
/**
|
||||||
* get cpts of category
|
* get cpts of category
|
||||||
*
|
*
|
||||||
* @param int $cat_id Category id
|
* @param int $cat_id Id accounting account category
|
||||||
* @return array Result in table
|
*
|
||||||
|
* @return array Result in table
|
||||||
*/
|
*/
|
||||||
public function getCptsCat($cat_id) {
|
public function getCptsCat($cat_id) {
|
||||||
global $mysoc;
|
global $mysoc;
|
||||||
|
|||||||
@ -43,13 +43,14 @@ $action = GETPOST('action','alpha');
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($action == 'add')
|
if ($action == 'add_confirm')
|
||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
|
|
||||||
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
||||||
$label = GETPOST('label','alpha');
|
$label = GETPOST('label','alpha');
|
||||||
$amount= GETPOST('amount');
|
$amount= GETPOST('amount');
|
||||||
|
$amount_to= GETPOST('amount_to');
|
||||||
|
|
||||||
if (! $label)
|
if (! $label)
|
||||||
{
|
{
|
||||||
@ -81,7 +82,7 @@ if ($action == 'add')
|
|||||||
$accountto=new Account($db);
|
$accountto=new Account($db);
|
||||||
$accountto->fetch(GETPOST('account_to','int'));
|
$accountto->fetch(GETPOST('account_to','int'));
|
||||||
|
|
||||||
if (($accountto->id != $accountfrom->id) && ($accountto->currency_code == $accountfrom->currency_code))
|
if ($accountto->id != $accountfrom->id)
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ if ($action == 'add')
|
|||||||
$result=0;
|
$result=0;
|
||||||
|
|
||||||
// By default, electronic transfert from bank to bank
|
// By default, electronic transfert from bank to bank
|
||||||
$typefrom='VIR';
|
$typefrom='PRE';
|
||||||
$typeto='VIR';
|
$typeto='VIR';
|
||||||
if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH)
|
if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH)
|
||||||
{
|
{
|
||||||
@ -102,7 +103,8 @@ if ($action == 'add')
|
|||||||
|
|
||||||
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
|
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
|
||||||
if (! ($bank_line_id_from > 0)) $error++;
|
if (! ($bank_line_id_from > 0)) $error++;
|
||||||
if (! $error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount), '', '', $user);
|
if ((! $error) && ($accountto->currency_code == $accountfrom->currency_code)) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount), '', '', $user);
|
||||||
|
if ((! $error) && ($accountto->currency_code != $accountfrom->currency_code)) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount_to), '', '', $user);
|
||||||
if (! ($bank_line_id_to > 0)) $error++;
|
if (! ($bank_line_id_to > 0)) $error++;
|
||||||
|
|
||||||
if (! $error) $result=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
|
if (! $error) $result=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
|
||||||
@ -112,7 +114,7 @@ if ($action == 'add')
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$mesgs = $langs->trans("TransferFromToDone","<a href=\"bankentries.php?id=".$accountfrom->id."\">".$accountfrom->label."</a>","<a href=\"bankentries.php?id=".$accountto->id."\">".$accountto->label."</a>",$amount,$langs->transnoentities("Currency".$conf->currency));
|
$mesgs = $langs->trans("TransferFromToDone","<a href=\"account.php?account=".$accountfrom->id."\">".$accountfrom->label."</a>","<a href=\"account.php?account=".$accountto->id."\">".$accountto->label."</a>",$amount,$langs->transnoentities("Currency".$conf->currency));
|
||||||
setEventMessages($mesgs, null, 'mesgs');
|
setEventMessages($mesgs, null, 'mesgs');
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
}
|
||||||
@ -143,6 +145,7 @@ $account_from='';
|
|||||||
$account_to='';
|
$account_to='';
|
||||||
$label='';
|
$label='';
|
||||||
$amount='';
|
$amount='';
|
||||||
|
$amount_to='';
|
||||||
|
|
||||||
if($error)
|
if($error)
|
||||||
{
|
{
|
||||||
@ -164,7 +167,8 @@ print '<input type="hidden" name="action" value="add">';
|
|||||||
|
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print '<td>'.$langs->trans("TransferFrom").'</td><td>'.$langs->trans("TransferTo").'</td><td>'.$langs->trans("Date").'</td><td>'.$langs->trans("Description").'</td><td>'.$langs->trans("Amount").'</td>';
|
print '<td>'.$langs->trans("TransferFrom").'</td><td>'.$langs->trans("TransferTo").'</td><td>'.$langs->trans("Date").'</td>';
|
||||||
|
print '<td>'.$langs->trans("Description").'</td><td>'.$langs->trans("Amount").'</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
$var=false;
|
$var=false;
|
||||||
@ -181,7 +185,6 @@ $form->select_date((! empty($dateo)?$dateo:''),'','','','','add');
|
|||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
print '<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.$label.'"></td>';
|
print '<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.$label.'"></td>';
|
||||||
print '<td><input name="amount" class="flat" type="text" size="6" value="'.$amount.'"></td>';
|
print '<td><input name="amount" class="flat" type="text" size="6" value="'.$amount.'"></td>';
|
||||||
|
|
||||||
print "</table>";
|
print "</table>";
|
||||||
|
|
||||||
print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans("Add").'"></div>';
|
print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans("Add").'"></div>';
|
||||||
|
|||||||
@ -65,7 +65,7 @@ class EcmFiles //extends CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -88,13 +88,13 @@ class EcmFiles //extends CommonObject
|
|||||||
public function create(User $user, $notrigger = false)
|
public function create(User $user, $notrigger = false)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
|
|
||||||
if (isset($this->label)) {
|
if (isset($this->label)) {
|
||||||
$this->label = trim($this->label);
|
$this->label = trim($this->label);
|
||||||
}
|
}
|
||||||
@ -135,13 +135,13 @@ class EcmFiles //extends CommonObject
|
|||||||
$this->acl = trim($this->acl);
|
$this->acl = trim($this->acl);
|
||||||
}
|
}
|
||||||
if (empty($this->date_c)) $this->date_c = dol_now();
|
if (empty($this->date_c)) $this->date_c = dol_now();
|
||||||
|
|
||||||
$maxposition=0;
|
$maxposition=0;
|
||||||
if (empty($this->position)) // Get max used
|
if (empty($this->position)) // Get max used
|
||||||
{
|
{
|
||||||
$sql = "SELECT MAX(position) as maxposition FROM " . MAIN_DB_PREFIX . $this->table_element;
|
$sql = "SELECT MAX(position) as maxposition FROM " . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql.= " WHERE filepath ='".$this->db->escape($this->filepath)."'";
|
$sql.= " WHERE filepath ='".$this->db->escape($this->filepath)."'";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -204,7 +204,7 @@ class EcmFiles //extends CommonObject
|
|||||||
if (!$error) {
|
if (!$error) {
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
|
||||||
$this->position = $maxposition;
|
$this->position = $maxposition;
|
||||||
|
|
||||||
if (!$notrigger) {
|
if (!$notrigger) {
|
||||||
// Uncomment this and change MYOBJECT to your own tag if you
|
// Uncomment this and change MYOBJECT to your own tag if you
|
||||||
// want this action to call a trigger.
|
// want this action to call a trigger.
|
||||||
@ -299,7 +299,7 @@ class EcmFiles //extends CommonObject
|
|||||||
$this->fk_user_m = $obj->fk_user_m;
|
$this->fk_user_m = $obj->fk_user_m;
|
||||||
$this->acl = $obj->acl;
|
$this->acl = $obj->acl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve all extrafields for invoice
|
// Retrieve all extrafields for invoice
|
||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
/*
|
/*
|
||||||
@ -309,7 +309,7 @@ class EcmFiles //extends CommonObject
|
|||||||
$this->fetch_optionals($this->id,$extralabels);
|
$this->fetch_optionals($this->id,$extralabels);
|
||||||
*/
|
*/
|
||||||
// $this->fetch_lines();
|
// $this->fetch_lines();
|
||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
if ($numrows) {
|
if ($numrows) {
|
||||||
@ -393,7 +393,7 @@ class EcmFiles //extends CommonObject
|
|||||||
$line = new EcmfilesLine();
|
$line = new EcmfilesLine();
|
||||||
|
|
||||||
$line->id = $obj->rowid;
|
$line->id = $obj->rowid;
|
||||||
|
|
||||||
$line->label = $obj->label;
|
$line->label = $obj->label;
|
||||||
$line->entity = $obj->entity;
|
$line->entity = $obj->entity;
|
||||||
$line->filename = $obj->filename;
|
$line->filename = $obj->filename;
|
||||||
@ -437,7 +437,7 @@ class EcmFiles //extends CommonObject
|
|||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
|
|
||||||
if (isset($this->label)) {
|
if (isset($this->label)) {
|
||||||
$this->label = trim($this->label);
|
$this->label = trim($this->label);
|
||||||
}
|
}
|
||||||
@ -562,7 +562,7 @@ class EcmFiles //extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If you need to delete child tables to, you can insert them here
|
// If you need to delete child tables to, you can insert them here
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
|
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
|
||||||
$sql .= ' WHERE rowid=' . $this->id;
|
$sql .= ' WHERE rowid=' . $this->id;
|
||||||
@ -651,7 +651,7 @@ class EcmFiles //extends CommonObject
|
|||||||
global $menumanager;
|
global $menumanager;
|
||||||
|
|
||||||
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
|
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
|
||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
$companylink = '';
|
$companylink = '';
|
||||||
|
|
||||||
@ -660,7 +660,7 @@ class EcmFiles //extends CommonObject
|
|||||||
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
|
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
|
||||||
|
|
||||||
$url = DOL_URL_ROOT.'/ecm/'.$this->table_name.'_card.php?id='.$this->id;
|
$url = DOL_URL_ROOT.'/ecm/'.$this->table_name.'_card.php?id='.$this->id;
|
||||||
|
|
||||||
$linkclose='';
|
$linkclose='';
|
||||||
if (empty($notooltip))
|
if (empty($notooltip))
|
||||||
{
|
{
|
||||||
@ -673,7 +673,7 @@ class EcmFiles //extends CommonObject
|
|||||||
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
|
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
|
||||||
}
|
}
|
||||||
else $linkclose = ($morecss?' class="'.$morecss.'"':'');
|
else $linkclose = ($morecss?' class="'.$morecss.'"':'');
|
||||||
|
|
||||||
$linkstart = '<a href="'.$url.'"';
|
$linkstart = '<a href="'.$url.'"';
|
||||||
$linkstart.=$linkclose.'>';
|
$linkstart.=$linkclose.'>';
|
||||||
$linkend='</a>';
|
$linkend='</a>';
|
||||||
@ -757,9 +757,9 @@ class EcmFiles //extends CommonObject
|
|||||||
public function initAsSpecimen()
|
public function initAsSpecimen()
|
||||||
{
|
{
|
||||||
global $conf,$user;
|
global $conf,$user;
|
||||||
|
|
||||||
$this->id = 0;
|
$this->id = 0;
|
||||||
|
|
||||||
$this->label = '0a1b2c3e4f59999999';
|
$this->label = '0a1b2c3e4f59999999';
|
||||||
$this->entity = '1';
|
$this->entity = '1';
|
||||||
$this->filename = 'myspecimenfilefile.pdf';
|
$this->filename = 'myspecimenfilefile.pdf';
|
||||||
@ -780,3 +780,23 @@ class EcmFiles //extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EcmfilesLine
|
||||||
|
{
|
||||||
|
public $label;
|
||||||
|
public $entity;
|
||||||
|
public $filename;
|
||||||
|
public $filepath;
|
||||||
|
public $fullpath_orig;
|
||||||
|
public $description;
|
||||||
|
public $keywords;
|
||||||
|
public $cover;
|
||||||
|
public $position;
|
||||||
|
public $gen_or_uploaded; // can be 'generated', 'uploaded', 'unknown'
|
||||||
|
public $extraparams;
|
||||||
|
public $date_c = '';
|
||||||
|
public $date_m = '';
|
||||||
|
public $fk_user_c;
|
||||||
|
public $fk_user_m;
|
||||||
|
public $acl;
|
||||||
|
}
|
||||||
|
|||||||
@ -433,7 +433,7 @@ class MyObject extends CommonObject
|
|||||||
|
|
||||||
global $user;
|
global $user;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$object = new MyModuleObject($this->db);
|
$object = new self($this->db);
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user