From 5c2a005e75e44677fa335cc6f66a81eff0242453 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 13:56:21 +0100 Subject: [PATCH] Work on generic customer payment modes --- htdocs/core/class/commonobject.class.php | 12 +- htdocs/langs/en_US/main.lang | 5 +- .../class/companybankaccount.class.php | 4 +- .../class/companypaymentmode.class.php | 76 +++- htdocs/societe/paymentmodes.php | 376 +++++++++++------- 5 files changed, 317 insertions(+), 156 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4600cefbdc3..43275b22afc 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6481,19 +6481,21 @@ abstract class CommonObject /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @param string $morewhere More SQL filters (' AND ...') + * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetchCommon($id, $ref = null) + public function fetchCommon($id, $ref = null, $morewhere = '') { if (empty($id) && empty($ref)) return false; $sql = 'SELECT '.$this->get_field_list(); $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - if(!empty($id)) $sql.= ' WHERE rowid = '.$id; + if (!empty($id)) $sql.= ' WHERE rowid = '.$id; else $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); + if ($morewhere) $sql.=$morewhere; $res = $this->db->query($sql); if ($res) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 063ea39127b..6473869be21 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -932,4 +932,7 @@ PayedBy=Payed by PayedTo=Payed to Monthly=Monthly Quarterly=Quarterly -Annual=Annual \ No newline at end of file +Annual=Annual +Local=Local +Remote=Remote +LocalAndRemote=Local and remote \ No newline at end of file diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index 97c8871202e..187f7c5ec65 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -197,7 +197,7 @@ class CompanyBankAccount extends Account * Load record from database * * @param int $id Id of record - * @param int $socid Id of company. If this is filled, function will return the default RIB of company + * @param int $socid Id of company. If this is filled, function will return the first default RIB of company * @return int <0 if KO, >0 if OK */ function fetch($id, $socid=0) @@ -208,7 +208,7 @@ class CompanyBankAccount extends Account $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($id) $sql.= " WHERE rowid = ".$id; - if ($socid) $sql.= " WHERE fk_soc = ".$socid." AND default_rib = 1"; + if ($socid) $sql.= " WHERE fk_soc = ".$socid." AND default_rib = 1 AND type ='ban'"; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 6a2095883c1..662361a619d 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -258,13 +258,18 @@ class CompanyPaymentMode extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object - * @param string $ref Ref - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @param int $socid Id of company to get first default payment mode + * @param string $type Filter on type ('ban', 'card', ...) + * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = null) + public function fetch($id, $ref = null, $socid = 0, $type = '') { - $result = $this->fetchCommon($id, $ref); + if ($socid) $sql.= " AND fk_soc = ".$this->db->escape($socid)." AND default_rib = 1"; + if ($type) $sql.= " AND type = '".$this->db->escape($type)."'"; + + $result = $this->fetchCommon($id, $ref, $morewhere); if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); return $result; } @@ -368,6 +373,67 @@ class CompanyPaymentMode extends CommonObject return $result; } + /** + * Set a Payment mode as Default + * + * @param int $id Payment mode ID + * @param string $alltypes 1=The default is for all payment types instead of per type + * @return int 0 if KO, 1 if OK + */ + function setAsDefault($id=0, $alltypes=0) + { + $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib"; + $sql1.= " WHERE rowid = ".($id?$id:$this->id); + + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); + $result1 = $this->db->query($sql1); + if ($result1) + { + if ($this->db->num_rows($result1) == 0) + { + return 0; + } + else + { + $obj = $this->db->fetch_object($result1); + + $type = ''; + if (empty($alltypes)) $type = $obj->type; + + $this->db->begin(); + + $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0"; + $sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc; + if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'"; + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); + $result2 = $this->db->query($sql2); + + $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1"; + $sql3.= " WHERE rowid = ".$obj->id; + if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'"; + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); + $result3 = $this->db->query($sql3); + + if (!$result2 || !$result3) + { + dol_print_error($this->db); + $this->db->rollback(); + return -1; + } + else + { + $this->db->commit(); + return 1; + } + } + } + else + { + dol_print_error($this->db); + return -1; + } + } + /** * Retourne le libelle du status d'un user (actif, inactif) * diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index d24f4dd5f32..9365511b78d 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -55,7 +55,8 @@ $cancel=GETPOST('cancel', 'alpha'); $object = new Societe($db); $object->fetch($socid); -$account = new CompanyBankAccount($db); +$companybankaccount = new CompanyBankAccount($db); +$companypaymentmode = new CompanyPaymentMode($db); $prelevement = new BonPrelevement($db); $extrafields = new ExtraFields($db); @@ -115,19 +116,14 @@ if (empty($reshook)) if ($action == 'update') { // Modification - if (! GETPOST('label')) + if (! GETPOST('label','alpha') || ! GETPOST('bank','alpha')) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('label','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('bank','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); $action='edit'; $error++; } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); - $action='edit'; - $error++; - } - if ($account->needIBAN() == 1) + if ($companybankaccount->needIBAN() == 1) { if (! GETPOST('iban')) { @@ -143,43 +139,94 @@ if (empty($reshook)) } } - $account->fetch($id); + $companybankaccount->fetch($id); if (! $error) { - $account->socid = $object->id; + $companybankaccount->socid = $object->id; - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur','alpha'); - $account->rum = GETPOST('rum','alpha'); - if (empty($account->rum)) + $companybankaccount->bank = GETPOST('bank','alpha'); + $companybankaccount->label = GETPOST('label','alpha'); + $companybankaccount->courant = GETPOST('courant','alpha'); + $companybankaccount->clos = GETPOST('clos','alpha'); + $companybankaccount->code_banque = GETPOST('code_banque','alpha'); + $companybankaccount->code_guichet = GETPOST('code_guichet','alpha'); + $companybankaccount->number = GETPOST('number','alpha'); + $companybankaccount->cle_rib = GETPOST('cle_rib','alpha'); + $companybankaccount->bic = GETPOST('bic','alpha'); + $companybankaccount->iban = GETPOST('iban','alpha'); + $companybankaccount->domiciliation = GETPOST('domiciliation','alpha'); + $companybankaccount->proprio = GETPOST('proprio','alpha'); + $companybankaccount->owner_address = GETPOST('owner_address','alpha'); + $companybankaccount->frstrecur = GETPOST('frstrecur','alpha'); + $companybankaccount->rum = GETPOST('rum','alpha'); + if (empty($companybankaccount->rum)) { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); + $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); + $companybankaccount->date_rum = dol_now(); } - $result = $account->update($user); + $result = $companybankaccount->update($user); if (! $result) { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); } else { // If this account is the default bank account, we disable others - if ($account->default_rib) + if ($companybankaccount->default_rib) { - $account->setAsDefault($id); // This will make sure there is only one default rib + $companybankaccount->setAsDefault($id); // This will make sure there is only one default rib + } + + $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; + header('Location: '.$url); + exit; + } + } + } + + if ($action == 'updatecard') + { + // Modification + if (! GETPOST('label','alpha') || ! GETPOST('proprio','alpha') || ! GETPOST('cardnumber','alpha') || ! GETPOST('exp_date_month','alpha') || ! GETPOST('exp_date_year','alpha') || ! GETPOST('cvn','alpha')) + { + if (! GETPOST('label','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + if (! GETPOST('proprio','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); + if (! GETPOST('cardnumber','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); + if (! (GETPOST('exp_date_month','alpha') > 0) || ! (GETPOST('exp_date_year','alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); + if (! GETPOST('cvn','alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); + $action='createcard'; + $error++; + } + + $companypaymentmode->fetch($id); + if (! $error) + { + $companypaymentmode->fk_soc = $object->id; + + $companypaymentmode->bank = GETPOST('bank','alpha'); + $companypaymentmode->label = GETPOST('label','alpha'); + $companypaymentmode->number = GETPOST('cardnumber','alpha'); + $companypaymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); + $companypaymentmode->proprio = GETPOST('proprio','alpha'); + $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int'); + $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int'); + $companypaymentmode->cvn = GETPOST('cvn','alpha'); + $companypaymentmode->country_code = $mysoc->country_code; + + $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha'); + + $result = $companypaymentmode->update($user); + if (! $result) + { + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); + } + else + { + // If this account is the default bank account, we disable others + if ($companypaymentmode->default_rib) + { + $companypaymentmode->setAsDefault($id); // This will make sure there is only one default rib } $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; @@ -204,31 +251,32 @@ if (empty($reshook)) if (! $error) { // Ajout - $account = new CompanyBankAccount($db); + $companybankaccount = new CompanyBankAccount($db); - $account->socid = $object->id; + $companybankaccount->socid = $object->id; - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur'); - $account->rum = GETPOST('rum','alpha'); - $account->datec = dol_now(); + $companybankaccount->bank = GETPOST('bank','alpha'); + $companybankaccount->label = GETPOST('label','alpha'); + $companybankaccount->courant = GETPOST('courant','alpha'); + $companybankaccount->clos = GETPOST('clos','alpha'); + $companybankaccount->code_banque = GETPOST('code_banque','alpha'); + $companybankaccount->code_guichet = GETPOST('code_guichet','alpha'); + $companybankaccount->number = GETPOST('number','alpha'); + $companybankaccount->cle_rib = GETPOST('cle_rib','alpha'); + $companybankaccount->bic = GETPOST('bic','alpha'); + $companybankaccount->iban = GETPOST('iban','alpha'); + $companybankaccount->domiciliation = GETPOST('domiciliation','alpha'); + $companybankaccount->proprio = GETPOST('proprio','alpha'); + $companybankaccount->owner_address = GETPOST('owner_address','alpha'); + $companybankaccount->frstrecur = GETPOST('frstrecur'); + $companybankaccount->rum = GETPOST('rum','alpha'); + $companybankaccount->datec = dol_now(); + $companybankaccount->status = 1; $db->begin(); // This test can be done only once properties were set - if ($account->needIBAN() == 1) + if ($companybankaccount->needIBAN() == 1) { if (! GETPOST('iban')) { @@ -246,28 +294,28 @@ if (empty($reshook)) if (! $error) { - $result = $account->create($user); + $result = $companybankaccount->create($user); if ($result < 0) { $error++; - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); $action='create'; // Force chargement page création } - if (empty($account->rum)) + if (empty($companybankaccount->rum)) { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); + $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); + $companybankaccount->date_rum = dol_now(); } } if (! $error) { - $result = $account->update($user); // This will set the UMR number. + $result = $companybankaccount->update($user); // This will set the UMR number. if ($result < 0) { $error++; - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); $action='create'; } } @@ -305,31 +353,34 @@ if (empty($reshook)) if (! $error) { // Ajout - $paymentmode = new CompanyPaymentMode($db); + $companypaymentmode = new CompanyPaymentMode($db); - $paymentmode->fk_soc = $object->id; - $paymentmode->bank = GETPOST('bank','alpha'); - $paymentmode->label = GETPOST('label','alpha'); - $paymentmode->number = GETPOST('cardnumber','alpha'); - $paymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); - $paymentmode->proprio = GETPOST('proprio','alpha'); - $paymentmode->exp_date_month = GETPOST('exp_date_month','int'); - $paymentmode->exp_date_year = GETPOST('exp_date_year','int'); - $paymentmode->cvn = GETPOST('cvn','alpha'); - $paymentmode->datec = dol_now(); - $paymentmode->default_rib = 0; - $paymentmode->type = 'card'; - $paymentmode->country_code = $mysoc->country_code; + $companypaymentmode->fk_soc = $object->id; + $companypaymentmode->bank = GETPOST('bank','alpha'); + $companypaymentmode->label = GETPOST('label','alpha'); + $companypaymentmode->number = GETPOST('cardnumber','alpha'); + $companypaymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); + $companypaymentmode->proprio = GETPOST('proprio','alpha'); + $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int'); + $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int'); + $companypaymentmode->cvn = GETPOST('cvn','alpha'); + $companypaymentmode->datec = dol_now(); + $companypaymentmode->default_rib = 0; + $companypaymentmode->type = 'card'; + $companypaymentmode->country_code = $mysoc->country_code; + $companypaymentmode->status = 1; + + $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha'); $db->begin(); if (! $error) { - $result = $paymentmode->create($user); + $result = $companypaymentmode->create($user); if ($result < 0) { $error++; - setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); $action='createcard'; // Force chargement page création } } @@ -349,10 +400,10 @@ if (empty($reshook)) } } - if ($action == 'setasbankdefault') + if ($action == 'setasbankdefault' && GETPOST('ribid','int') > 0) { - $account = new CompanyBankAccount($db); - $res = $account->setAsDefault(GETPOST('ribid','int')); + $companybankaccount = new CompanyBankAccount($db); + $res = $companybankaccount->setAsDefault(GETPOST('ribid','int')); if ($res) { $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; @@ -367,10 +418,10 @@ if (empty($reshook)) if ($action == 'confirm_deletecard' && GETPOST('confirm','alpha') == 'yes') { - $paymentmode = new CompanyPaymentMode($db); - if ($paymentmode->fetch($ribid?$ribid:$id)) + $companypaymentmode = new CompanyPaymentMode($db); + if ($companypaymentmode->fetch($ribid?$ribid:$id)) { - $result = $paymentmode->delete($user); + $result = $companypaymentmode->delete($user); if ($result > 0) { $url = $_SERVER['PHP_SELF']."?socid=".$object->id; @@ -379,20 +430,20 @@ if (empty($reshook)) } else { - setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); } } else { - setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); + setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors'); } } if ($action == 'confirm_delete' && GETPOST('confirm','alpha') == 'yes') { - $account = new CompanyBankAccount($db); - if ($account->fetch($ribid?$ribid:$id)) + $companybankaccount = new CompanyBankAccount($db); + if ($companybankaccount->fetch($ribid?$ribid:$id)) { - $result = $account->delete($user); + $result = $companybankaccount->delete($user); if ($result > 0) { $url = $_SERVER['PHP_SELF']."?socid=".$object->id; @@ -401,12 +452,12 @@ if (empty($reshook)) } else { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); } } else { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors'); } } @@ -476,11 +527,7 @@ if (empty($reshook)) if ($action == 'setlocalassourcedefault') { try { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 0 WHERE type = 'card' AND default_rib <> 0"; - $db->query($sql); - - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 1 WHERE type = 'card' AND rowid = ".GETPOST('id','int'); - $db->query($sql); + $companypaymentmode->setAsDefault($id); $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; header('Location: '.$url); @@ -540,21 +587,26 @@ llxHeader(); $head=societe_prepare_head($object); +// Load Bank account if (! $id) { - $account->fetch(0,$object->id); + $companybankaccount->fetch(0, $object->id); + $companypaymentmode->fetch(0, null, $object->id, 'card'); } else { - $account->fetch($id); + $companybankaccount->fetch($id); + $companypaymentmode->fetch($id); } -if (empty($account->socid)) $account->socid=$object->id; +if (empty($companybankaccount->socid)) $companybankaccount->socid=$object->id; if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer) { print '
'; print ''; - print ''; + $actionforadd='update'; + if ($action == 'editcard') $actionforadd='updatecard'; + print ''; print ''; } if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) @@ -575,12 +627,12 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' // Confirm delete ban if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $companybankaccount->getRibLabel()), "confirm_delete", '', 0, 1); } // Confirm delete card if ($action == 'deletecard') { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $account->getRibLabel()), "confirm_deletecard", '', 0, 1); + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $companybankaccount->getRibLabel()), "confirm_deletecard", '', 0, 1); } $linkback = ''.$langs->trans("BackToList").''; @@ -638,7 +690,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print '
'; - // Stripe payment modes + // List of Stripe payment modes if (! (empty($conf->stripe->enabled))) { $morehtmlright=''; @@ -708,14 +760,14 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $companypaymentmodetemp->fetch($obj->rowid); - $arrayofstripecard[$obj->stripe_card_ref]=$obj->stripe_card_ref; + $arrayofstripecard[$companypaymentmodetemp->stripe_card_ref]=$companypaymentmodetemp->stripe_card_ref; print ''; print ''; - print $obj->rowid; + print $companypaymentmodetemp->id; print ''; print ''; - print $obj->stripe_card_ref; + print $companypaymentmodetemp->stripe_card_ref; print ''; print ''; print img_credit_card($companypaymentmodetemp->type); @@ -1078,20 +1130,8 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } dol_fiche_end(); -/* - if ($socid && $action != 'edit' && $action != 'create' && $action != 'createcard') - { - // Barre d'actions - print '
'; - if ($user->rights->societe->creer) - { - print ''.$langs->trans("Add").''; - } - print '
'; - } -*/ if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) { print '
'; @@ -1152,41 +1192,41 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { + foreach ($companybankaccount->getFieldsToShow(1) as $val) { $require=false; if ($val == 'BankCode') { $name = 'code_banque'; $size = 8; - $content = $account->code_banque; + $content = $companybankaccount->code_banque; } elseif ($val == 'DeskCode') { $name = 'code_guichet'; $size = 8; - $content = $account->code_guichet; + $content = $companybankaccount->code_guichet; } elseif ($val == 'BankAccountNumber') { $name = 'number'; $size = 18; - $content = $account->number; + $content = $companybankaccount->number; } elseif ($val == 'BankAccountNumberKey') { $name = 'cle_rib'; $size = 3; - $content = $account->cle_rib; + $content = $companybankaccount->cle_rib; } elseif ($val == 'IBAN') { $name = 'iban'; $size = 30; - $content = $account->iban; - if ($account->needIBAN()) $require=true; + $content = $companybankaccount->iban; + if ($companybankaccount->needIBAN()) $require=true; } elseif ($val == 'BIC') { $name = 'bic'; $size = 12; - $content = $account->bic; - if ($account->needIBAN()) $require=true; + $content = $companybankaccount->bic; + if ($companybankaccount->needIBAN()) $require=true; } print ''.$langs->trans($val).''; @@ -1196,16 +1236,16 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print '"; print ''; - print ''; + print ''; print "\n"; print '"; print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankName").'
'.$langs->trans("BankAccountDomiciliation").''; print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; print '
'; @@ -1216,15 +1256,15 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''; - if (empty($account->rum)) $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); + if (empty($companybankaccount->rum)) $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id); // RUM print ''; - print ''; + print ''; print ''; print '
'.$langs->trans("RUM").'
'.$langs->trans("WithdrawMode").''; $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur','alpha')?GETPOST('frstrecur','alpha'):$account->frstrecur), 0); + print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur','alpha')?GETPOST('frstrecur','alpha'):$companybankaccount->frstrecur), 0); print '
'; @@ -1241,6 +1281,53 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print '
'; } +// Edit Card +if ($socid && $action == 'editcard' && $user->rights->societe->creer) +{ + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print '"; + print ''; + + print '
'.$langs->trans("Label").'
'.$langs->trans("NameOnCard").'
'.$langs->trans("CardNumber").'
'.$langs->trans("ExpiryDate").''; + print $formother->select_month($companypaymentmode->exp_date_month, 'exp_date_month', 1); + print $formother->select_year($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); + print '
'.$langs->trans("CVN").'
'.$langs->trans("StripeID")." ('card_....')
'; + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; +} + // Create BAN if ($socid && $action == 'create' && $user->rights->societe->creer) @@ -1257,13 +1344,13 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { + foreach ($companybankaccount->getFieldsToShow(1) as $val) { $require=false; if ($val == 'BankCode') { @@ -1281,11 +1368,11 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) } elseif ($val == 'IBAN') { $name = 'iban'; $size = 30; - if ($account->needIBAN()) $require=true; + if ($companybankaccount->needIBAN()) $require=true; } elseif ($val == 'BIC') { $name = 'bic'; $size = 12; - if ($account->needIBAN()) $require=true; + if ($companybankaccount->needIBAN()) $require=true; } print ''.$langs->trans($val).''; @@ -1299,7 +1386,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) print ""; print ''; - print ''; + print ''; print "\n"; print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; @@ -1355,13 +1442,13 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; + print '"; + print ''; + print '
'.$langs->trans("Label").'
'.$langs->trans("NameOnCard").'
'.$langs->trans("CardNumber").'
'.$langs->trans("ExpiryDate").''; @@ -1372,6 +1459,9 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print '
'.$langs->trans("CVN").'
'.$langs->trans("StripeID")." ('card_....')
'; print ''; @@ -1387,7 +1477,7 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print ''; } -if ($socid && $action == 'edit' && $user->rights->societe->creer) +if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer) { print ''; }