diff --git a/htdocs/product/admin/product_tools.php b/htdocs/product/admin/product_tools.php index caa131fd708..ab90ed971b3 100644 --- a/htdocs/product/admin/product_tools.php +++ b/htdocs/product/admin/product_tools.php @@ -56,7 +56,7 @@ $oldvatrate = GETPOST('oldvatrate', 'alpha'); $newvatrate = GETPOST('newvatrate', 'alpha'); //$price_base_type=GETPOST('price_base_type'); - +$hookmanager->initHooks(array('productvatadmin')); /* * Actions @@ -107,7 +107,7 @@ if ($action == 'convert') { if ($vat_src_code_old) { $sql .= " AND default_vat_code = '".$db->escape($vat_src_code_old)."'"; } else { - $sql .= " AND default_vat_code = IS NULL"; + $sql .= " AND default_vat_code IS NULL"; } $resql = $db->query($sql); @@ -209,7 +209,7 @@ if ($action == 'convert') { if ($vat_src_code_old) { $sql .= " AND default_vat_code = '".$db->escape($vat_src_code_old)."'"; } else { - $sql .= " AND default_vat_code = IS NULL"; + $sql .= " AND default_vat_code IS NULL"; } $sql .= " AND s.fk_pays = ".((int) $country_id); diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index b0dbd8a8dc3..6b32d74f853 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -335,6 +335,9 @@ class CompanyBankAccount extends Account */ public $datem; + const STATUS_OPEN = 0; + const STATUS_CLOSED = 1; + /** * Constructor * @@ -342,6 +345,8 @@ class CompanyBankAccount extends Account */ public function __construct(DoliDB $db) { + global $langs; + $this->db = $db; $this->socid = 0; @@ -349,6 +354,11 @@ class CompanyBankAccount extends Account $this->balance = 0; $this->default_rib = 0; $this->type = "ban"; + + $this->labelStatus = array( + self::STATUS_OPEN => $langs->transnoentitiesnoconv("StatusAccountOpened"), + self::STATUS_CLOSED => $langs->transnoentitiesnoconv("StatusAccountClosed") + ); } @@ -465,6 +475,10 @@ class CompanyBankAccount extends Account $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'"; $sql .= ",bic='".$this->db->escape($this->bic)."'"; $sql .= ",iban_prefix = '".$this->db->escape(dolEncrypt($this->iban))."'"; + $sql .= ",currency_code = '".$this->db->escape($this->currency_code)."'"; + $sql .= ",fk_country = '".((int) $this->fk_country)."'"; + $sql .= ",state_id = '".((int) $this->state_id)."'"; + $sql .= ",status = '".((int) $this->status)."'"; $sql .= ",domiciliation = '".$this->db->escape($this->address)."'"; $sql .= ",proprio = '".$this->db->escape($this->owner_name)."'"; $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'"; @@ -530,7 +544,7 @@ class CompanyBankAccount extends Account } $sql = "SELECT rowid, label, type, fk_soc as socid, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban,"; - $sql .= " domiciliation as address,"; + $sql .= " currency_code, fk_country, state_id, status, domiciliation as address,"; $sql .= " proprio as owner_name, owner_address, default_rib, datec, tms as datem, rum, frstrecur, date_rum,"; $sql .= " stripe_card_ref, stripe_account, ext_payment_site,"; $sql .= " last_main_doc, model_pdf"; @@ -568,6 +582,10 @@ class CompanyBankAccount extends Account $this->bic = $obj->bic; $this->iban = dolDecrypt($obj->iban); + $this->currency_code = $obj->currency_code; + $this->fk_country = $obj->fk_country; + $this->state_id = $obj->state_id; + $this->status = $obj->status; $this->address = $obj->address; $this->owner_name = $obj->owner_name; diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 43dfea714e3..8742827ebd1 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -38,6 +38,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; @@ -49,6 +50,7 @@ require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs + * @var Societe $mysoc * @var User $user */ @@ -191,6 +193,9 @@ if (empty($reshook)) { $companybankaccount->bic = GETPOST('bic', 'alpha'); $companybankaccount->iban = GETPOST('iban', 'alpha'); + $companybankaccount->currency_code = GETPOST('account_currency_code', 'alpha'); + $companybankaccount->fk_country = GETPOSTINT('account_country_id'); + $companybankaccount->state_id = GETPOSTINT('account_state_id'); $companybankaccount->address = GETPOST('address', 'alpha'); $companybankaccount->owner_name = GETPOST('proprio', 'alpha'); @@ -203,6 +208,9 @@ if (empty($reshook)) { $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, (string) $companybankaccount->id); } + $companybankaccount->status = GETPOSTINT('clos'); + + if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) { // If we set a stripe value that is different than previous one, we also set the stripe account $companypaymentmode->stripe_account = $stripecu.'@'.$site_account; @@ -323,6 +331,9 @@ if (empty($reshook)) { $companybankaccount->bic = GETPOST('bic', 'alpha'); $companybankaccount->iban = GETPOST('iban', 'alpha'); + $companybankaccount->currency_code = GETPOST('account_currency_code', 'alpha'); + $companybankaccount->fk_country = GETPOSTINT('account_country_id'); + $companybankaccount->state_id = GETPOSTINT('account_state_id'); $companybankaccount->address = GETPOST('address', 'alpha'); $companybankaccount->owner_name = GETPOST('proprio', 'alpha'); @@ -733,6 +744,7 @@ if (empty($reshook)) { $db->begin(); + $sql = ''; if (empty($newsup)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token WHERE fk_soc = ".((int) $object->id)." AND service = '".$db->escape($tmpservice)."' AND entity = ".((int) $conf->entity); // TODO Add site and site_account on oauth_token table @@ -891,9 +903,12 @@ if (empty($reshook)) { */ $form = new Form($db); +$formcompany = new FormCompany($db); $formother = new FormOther($db); $formfile = new FormFile($db); +$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; + $title = $langs->trans("ThirdParty"); if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) { $title = $object->name." - ".$langs->trans('PaymentInformation'); @@ -2005,6 +2020,7 @@ if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) { print ''; // Show fields of bank account + $companybankaccount->fetch($id); $bankaccount = $companybankaccount; // Code here is similar as in bank.php for users foreach ($bankaccount->getFieldsToShow(1) as $val) { @@ -2060,6 +2076,52 @@ if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) { print ''; } + // Currency + print ''.$langs->trans("Currency").''; + print ''; + $selectedcode = $bankaccount->currency_code; + if (!$selectedcode) { + $selectedcode = $conf->currency; + } + print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code'); + //print $langs->trans("Currency".$conf->currency); + //print ''; + print ''; + + // Status + $account_status = $bankaccount->status; + print ''.$langs->trans("Status").''; + print ''; + print $form->selectarray("clos", $bankaccount->labelStatus, $account_status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth150onsmartphone'); + print ''; + + // Bank country + $country_codeid = GETPOST("account_country_id") ? GETPOST("account_country_id") : $bankaccount->fk_country; + if (empty($country_codeid)) { + $country_codeid = $mysoc->country_code; + } + $bankaccount->country_code = getCountry($country_codeid, '2'); // Force country code on account to have following field on bank fields matching country rules + + print ''.$langs->trans("BankAccountCountry").''; + print ''; + print img_picto('', 'country', 'class="pictofixedwidth"'); + print $form->select_country($country_codeid, 'account_country_id'); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } + print ''; + + // Bank state + $selected_state_id = $bankaccount->state_id; + print ''.$langs->trans('State').''; + if ($country_codeid) { + print img_picto('', 'state', 'class="pictofixedwidth"'); + print $formcompany->select_state($selected_state_id, $country_codeid, 'account_state_id'); + } else { + print $countrynotdefined; + } + print ''; + print ''.$langs->trans("BankAccountDomiciliation").''; print '