diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 059af63b708..caf27c0aced 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -254,6 +254,7 @@ else if ($action == 'add' && $user->rights->propal->creer) {
$object->duree_validite = $duration;
$object->cond_reglement_id = GETPOST('cond_reglement_id');
$object->mode_reglement_id = GETPOST('mode_reglement_id');
+ $object->fk_account = GETPOST('fk_account', 'int');
$object->remise_percent = GETPOST('remise_percent');
$object->remise_absolue = GETPOST('remise_absolue');
$object->socid = GETPOST('socid');
@@ -279,7 +280,7 @@ else if ($action == 'add' && $user->rights->propal->creer) {
$object->duree_validite = GETPOST('duree_validite');
$object->cond_reglement_id = GETPOST('cond_reglement_id');
$object->mode_reglement_id = GETPOST('mode_reglement_id');
-
+ $object->fk_account = GETPOST('fk_account', 'int');
$object->contactid = GETPOST('contactidp');
$object->fk_project = GETPOST('projectid');
$object->modelpdf = GETPOST('model');
@@ -1104,6 +1105,11 @@ else if ($action == 'setmode' && $user->rights->propal->creer) {
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
}
+// bank account
+else if ($action == 'setbankaccount' && $user->rights->propal->creer) {
+ $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
+}
+
/*
* Ordonnancement des lignes
*/
@@ -1368,6 +1374,11 @@ if ($action == 'create') {
$form->select_types_paiements($soc->mode_reglement_id, 'mode_reglement_id');
print '';
+ // Bank Account
+ print '
| ' . $langs->trans('BankAccount') . ' | ';
+ $form->select_comptes($fk_account, 'fk_account', 0, '', 1);
+ print ' |
';
+
// What trigger creation
print '| ' . $langs->trans('Source') . ' | ';
$form->selectInputReason('', 'demand_reason_id', "SRC_PROP", 1);
@@ -1965,6 +1976,25 @@ if ($action == 'create') {
}
}
}
+ // Bank Account
+ print ' |
| ';
+ print '';
+ print ' | ';
+ if ($action == 'editbankaccount')
+ {
+ $form->form_select_comptes($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
+ }
+ else
+ {
+ $form->form_select_comptes($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
+ }
+ print " | ";
+ print '
';
// Amount HT
print '| ' . $langs->trans('AmountHT') . ' | ';
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 7f2ebf1de4b..a2d4d90f6c7 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -79,6 +79,7 @@ class Propal extends CommonObject
var $cond_reglement_id;
var $cond_reglement_code;
+ var $fk_account; // Id of bank account
var $mode_reglement_id;
var $mode_reglement_code;
var $remise;
@@ -714,6 +715,7 @@ class Propal extends CommonObject
$sql.= ", fin_validite";
$sql.= ", fk_cond_reglement";
$sql.= ", fk_mode_reglement";
+ $sql.= ", fk_account";
$sql.= ", ref_client";
$sql.= ", date_livraison";
$sql.= ", fk_availability";
@@ -739,6 +741,7 @@ class Propal extends CommonObject
$sql.= ", ".($this->fin_validite!=''?"'".$this->db->idate($this->fin_validite)."'":"null");
$sql.= ", ".$this->cond_reglement_id;
$sql.= ", ".$this->mode_reglement_id;
+ $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
$sql.= ", '".$this->db->escape($this->ref_client)."'";
$sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"null");
$sql.= ", ".$this->availability_id;
@@ -1056,6 +1059,7 @@ class Propal extends CommonObject
$sql.= ", p.fk_input_reason";
$sql.= ", p.fk_cond_reglement";
$sql.= ", p.fk_mode_reglement";
+ $sql.= ', p.fk_account';
$sql.= ", c.label as statut_label";
$sql.= ", ca.code as availability_code, ca.label as availability";
$sql.= ", dr.code as demand_reason_code, dr.label as demand_reason";
@@ -1120,6 +1124,7 @@ class Propal extends CommonObject
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement;
+ $this->fk_account = ($obj->fk_account>0)?$obj->fk_account:null;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement;
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 472b46ce925..b6d06abf368 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -60,6 +60,7 @@ class Commande extends CommonOrder
var $brouillon;
var $cond_reglement_id;
var $cond_reglement_code;
+ var $fk_account;
var $mode_reglement_id;
var $mode_reglement_code;
var $availability_id;
@@ -658,7 +659,7 @@ class Commande extends CommonOrder
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande (";
$sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note_private, note_public, ref_client, ref_int";
- $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
+ $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_account, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
$sql.= ", remise_absolue, remise_percent";
$sql.= ", entity";
$sql.= ")";
@@ -673,6 +674,7 @@ class Commande extends CommonOrder
$sql.= ", '".$this->modelpdf."'";
$sql.= ", ".($this->cond_reglement_id>0?"'".$this->cond_reglement_id."'":"null");
$sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"null");
+ $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
$sql.= ", ".($this->availability_id>0?"'".$this->availability_id."'":"null");
$sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null");
$sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null");
@@ -986,6 +988,7 @@ class Commande extends CommonOrder
$this->fk_project = $object->fk_project;
$this->cond_reglement_id = $object->cond_reglement_id;
$this->mode_reglement_id = $object->mode_reglement_id;
+ $this->fk_account = $object->fk_account;
$this->availability_id = $object->availability_id;
$this->demand_reason_id = $object->demand_reason_id;
$this->date_livraison = $object->date_livraison;
@@ -1329,6 +1332,7 @@ class Commande extends CommonOrder
$sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut';
$sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_input_reason';
+ $sql.= ', c.fk_account';
$sql.= ', c.date_commande';
$sql.= ', c.date_livraison';
$sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as billed';
@@ -1388,6 +1392,7 @@ class Commande extends CommonOrder
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
+ $this->fk_account = $obj->fk_account;
$this->availability_id = $obj->fk_availability;
$this->availability_code = $obj->availability_code;
$this->demand_reason_id = $obj->fk_input_reason;
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 8b1d6ec9ae3..b2f331b051f 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -227,6 +227,7 @@ else if ($action == 'add' && $user->rights->commande->creer) {
$object->modelpdf = GETPOST('model');
$object->cond_reglement_id = GETPOST('cond_reglement_id');
$object->mode_reglement_id = GETPOST('mode_reglement_id');
+ $object->fk_account = GETPOST('fk_account', 'int');
$object->availability_id = GETPOST('availability_id');
$object->demand_reason_id = GETPOST('demand_reason_id');
$object->date_livraison = $datelivraison;
@@ -488,6 +489,11 @@ else if ($action == 'setconditions' && $user->rights->commande->creer) {
}
}
+// bank account
+else if ($action == 'setbankaccount' && $user->rights->propal->creer) {
+ $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
+}
+
else if ($action == 'setremisepercent' && $user->rights->commande->creer) {
$result = $object->set_remise($user, GETPOST('remise_percent'));
}
@@ -1392,6 +1398,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
$soc = $objectsrc->client;
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
+ $fk_account = (!empty($objectsrc->fk_account)?$objectsrc->fk_account:(!empty($soc->fk_account)?$soc->fk_account:0));
$availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
$demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0));
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
@@ -1411,6 +1418,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
{
$cond_reglement_id = $soc->cond_reglement_id;
$mode_reglement_id = $soc->mode_reglement_id;
+ $fk_account = $soc->fk_account;
$availability_id = $soc->availability_id;
$demand_reason_id = $soc->demand_reason_id;
$remise_percent = $soc->remise_percent;
@@ -1506,6 +1514,11 @@ if ($action == 'create' && $user->rights->commande->creer) {
$form->select_types_paiements($mode_reglement_id, 'mode_reglement_id');
print '
';
+ // Bank Account
+ print '| ' . $langs->trans('BankAccount') . ' | ';
+ $form->select_comptes($fk_account, 'fk_account', 0, '', 1);
+ print ' |
';
+
// Delivery delay
print '| ' . $langs->trans('AvailabilityPeriod') . ' | ';
$form->selectAvailabilityDelay($availability_id, 'availability_id', '', 1);
@@ -2120,7 +2133,27 @@ if ($action == 'create' && $user->rights->commande->creer) {
if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0)
$rowspan ++;
- // Total HT
+ // Bank Account
+ print ' |
| ';
+ print '';
+ print ' | ';
+ if ($action == 'editbankaccount')
+ {
+ $form->form_select_comptes($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
+ }
+ else
+ {
+ $form->form_select_comptes($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
+ }
+ print " | ";
+ print '
';
+
+ // Total HT
print '| ' . $langs->trans('AmountHT') . ' | ';
print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . ' | ';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index c06c43eb4a4..44554d39180 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1079,6 +1079,40 @@ abstract class CommonObject
}
+ /**
+ * Change the bank account
+ *
+ * @param int $fk_account Id of bank account
+ * @return int 1 if OK, 0 if KO
+ */
+ function setBankAccount($fk_account)
+ {
+ if (! $this->table_element)
+ {
+ dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR);
+ return -1;
+ }
+ if ($fk_account<0) $fk_account='NULL';
+ dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
+ $sql.= " SET fk_account = ".$fk_account;
+ $sql.= " WHERE rowid=".$this->id;
+
+ if ($this->db->query($sql))
+ {
+ $this->fk_account = ($fk_account=='NULL')?null:$fk_account;
+ return 1;
+ }
+ else
+ {
+ dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error());
+ $this->error=$this->db->error();
+ return 0;
+ }
+ }
+
+
/**
* Save a new position (field rang) for details lines.
* You can choose to set position for lines with already a position or lines without any position defined.
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 1e7f0bb8246..cdc7294c302 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -2480,6 +2480,44 @@ class Form
}
}
+ /**
+ * Display form to select bank account
+ *
+ * @param string $page Page
+ * @param int $selected Id of bank account
+ * @param string $htmlname Name of select html field
+ * @param int $addempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
+ * @return void
+ */
+ function form_select_comptes($page, $selected='', $htmlname='fk_account', $addempty=0)
+ {
+ global $langs;
+ if ($htmlname != "none")
+ {
+ print '';
+ }
+ else
+ {
+ if ($selected)
+ {
+ require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
+ $bankstatic=new Account($this->db);
+ $bankstatic->fetch($selected);
+ print $bankstatic->label.' ('.$bankstatic->currency_code.')';
+ } else {
+ print " ";
+ }
+ }
+ }
+
/**
* Return list of categories having choosed type
*