Work on generic customer payment modes

This commit is contained in:
Laurent Destailleur 2018-03-14 13:56:21 +01:00
parent 268b07bcf0
commit 5c2a005e75
5 changed files with 317 additions and 156 deletions

View File

@ -6481,19 +6481,21 @@ abstract class CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref * @param string $ref Ref
* @return int <0 if KO, 0 if not found, >0 if OK * @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; if (empty($id) && empty($ref)) return false;
$sql = 'SELECT '.$this->get_field_list(); $sql = 'SELECT '.$this->get_field_list();
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; $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']); else $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
if ($morewhere) $sql.=$morewhere;
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)

View File

@ -932,4 +932,7 @@ PayedBy=Payed by
PayedTo=Payed to PayedTo=Payed to
Monthly=Monthly Monthly=Monthly
Quarterly=Quarterly Quarterly=Quarterly
Annual=Annual Annual=Annual
Local=Local
Remote=Remote
LocalAndRemote=Local and remote

View File

@ -197,7 +197,7 @@ class CompanyBankAccount extends Account
* Load record from database * Load record from database
* *
* @param int $id Id of record * @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 * @return int <0 if KO, >0 if OK
*/ */
function fetch($id, $socid=0) 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.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
if ($id) $sql.= " WHERE rowid = ".$id; 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); $resql = $this->db->query($sql);
if ($resql) if ($resql)

View File

@ -258,13 +258,18 @@ class CompanyPaymentMode extends CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref * @param string $ref Ref
* @return int <0 if KO, 0 if not found, >0 if OK * @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(); if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
return $result; return $result;
} }
@ -368,6 +373,67 @@ class CompanyPaymentMode extends CommonObject
return $result; 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) * Retourne le libelle du status d'un user (actif, inactif)
* *

View File

@ -55,7 +55,8 @@ $cancel=GETPOST('cancel', 'alpha');
$object = new Societe($db); $object = new Societe($db);
$object->fetch($socid); $object->fetch($socid);
$account = new CompanyBankAccount($db); $companybankaccount = new CompanyBankAccount($db);
$companypaymentmode = new CompanyPaymentMode($db);
$prelevement = new BonPrelevement($db); $prelevement = new BonPrelevement($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
@ -115,19 +116,14 @@ if (empty($reshook))
if ($action == 'update') if ($action == 'update')
{ {
// Modification // 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'; $action='edit';
$error++; $error++;
} }
if (! GETPOST('bank')) if ($companybankaccount->needIBAN() == 1)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors');
$action='edit';
$error++;
}
if ($account->needIBAN() == 1)
{ {
if (! GETPOST('iban')) if (! GETPOST('iban'))
{ {
@ -143,43 +139,94 @@ if (empty($reshook))
} }
} }
$account->fetch($id); $companybankaccount->fetch($id);
if (! $error) if (! $error)
{ {
$account->socid = $object->id; $companybankaccount->socid = $object->id;
$account->bank = GETPOST('bank','alpha'); $companybankaccount->bank = GETPOST('bank','alpha');
$account->label = GETPOST('label','alpha'); $companybankaccount->label = GETPOST('label','alpha');
$account->courant = GETPOST('courant','alpha'); $companybankaccount->courant = GETPOST('courant','alpha');
$account->clos = GETPOST('clos','alpha'); $companybankaccount->clos = GETPOST('clos','alpha');
$account->code_banque = GETPOST('code_banque','alpha'); $companybankaccount->code_banque = GETPOST('code_banque','alpha');
$account->code_guichet = GETPOST('code_guichet','alpha'); $companybankaccount->code_guichet = GETPOST('code_guichet','alpha');
$account->number = GETPOST('number','alpha'); $companybankaccount->number = GETPOST('number','alpha');
$account->cle_rib = GETPOST('cle_rib','alpha'); $companybankaccount->cle_rib = GETPOST('cle_rib','alpha');
$account->bic = GETPOST('bic','alpha'); $companybankaccount->bic = GETPOST('bic','alpha');
$account->iban = GETPOST('iban','alpha'); $companybankaccount->iban = GETPOST('iban','alpha');
$account->domiciliation = GETPOST('domiciliation','alpha'); $companybankaccount->domiciliation = GETPOST('domiciliation','alpha');
$account->proprio = GETPOST('proprio','alpha'); $companybankaccount->proprio = GETPOST('proprio','alpha');
$account->owner_address = GETPOST('owner_address','alpha'); $companybankaccount->owner_address = GETPOST('owner_address','alpha');
$account->frstrecur = GETPOST('frstrecur','alpha'); $companybankaccount->frstrecur = GETPOST('frstrecur','alpha');
$account->rum = GETPOST('rum','alpha'); $companybankaccount->rum = GETPOST('rum','alpha');
if (empty($account->rum)) if (empty($companybankaccount->rum))
{ {
$account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
$account->date_rum = dol_now(); $companybankaccount->date_rum = dol_now();
} }
$result = $account->update($user); $result = $companybankaccount->update($user);
if (! $result) if (! $result)
{ {
setEventMessages($account->error, $account->errors, 'errors'); setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
} }
else else
{ {
// If this account is the default bank account, we disable others // 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; $url=$_SERVER["PHP_SELF"].'?socid='.$object->id;
@ -204,31 +251,32 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
// Ajout // Ajout
$account = new CompanyBankAccount($db); $companybankaccount = new CompanyBankAccount($db);
$account->socid = $object->id; $companybankaccount->socid = $object->id;
$account->bank = GETPOST('bank','alpha'); $companybankaccount->bank = GETPOST('bank','alpha');
$account->label = GETPOST('label','alpha'); $companybankaccount->label = GETPOST('label','alpha');
$account->courant = GETPOST('courant','alpha'); $companybankaccount->courant = GETPOST('courant','alpha');
$account->clos = GETPOST('clos','alpha'); $companybankaccount->clos = GETPOST('clos','alpha');
$account->code_banque = GETPOST('code_banque','alpha'); $companybankaccount->code_banque = GETPOST('code_banque','alpha');
$account->code_guichet = GETPOST('code_guichet','alpha'); $companybankaccount->code_guichet = GETPOST('code_guichet','alpha');
$account->number = GETPOST('number','alpha'); $companybankaccount->number = GETPOST('number','alpha');
$account->cle_rib = GETPOST('cle_rib','alpha'); $companybankaccount->cle_rib = GETPOST('cle_rib','alpha');
$account->bic = GETPOST('bic','alpha'); $companybankaccount->bic = GETPOST('bic','alpha');
$account->iban = GETPOST('iban','alpha'); $companybankaccount->iban = GETPOST('iban','alpha');
$account->domiciliation = GETPOST('domiciliation','alpha'); $companybankaccount->domiciliation = GETPOST('domiciliation','alpha');
$account->proprio = GETPOST('proprio','alpha'); $companybankaccount->proprio = GETPOST('proprio','alpha');
$account->owner_address = GETPOST('owner_address','alpha'); $companybankaccount->owner_address = GETPOST('owner_address','alpha');
$account->frstrecur = GETPOST('frstrecur'); $companybankaccount->frstrecur = GETPOST('frstrecur');
$account->rum = GETPOST('rum','alpha'); $companybankaccount->rum = GETPOST('rum','alpha');
$account->datec = dol_now(); $companybankaccount->datec = dol_now();
$companybankaccount->status = 1;
$db->begin(); $db->begin();
// This test can be done only once properties were set // This test can be done only once properties were set
if ($account->needIBAN() == 1) if ($companybankaccount->needIBAN() == 1)
{ {
if (! GETPOST('iban')) if (! GETPOST('iban'))
{ {
@ -246,28 +294,28 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
$result = $account->create($user); $result = $companybankaccount->create($user);
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
setEventMessages($account->error, $account->errors, 'errors'); setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
$action='create'; // Force chargement page création $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); $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
$account->date_rum = dol_now(); $companybankaccount->date_rum = dol_now();
} }
} }
if (! $error) 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) if ($result < 0)
{ {
$error++; $error++;
setEventMessages($account->error, $account->errors, 'errors'); setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
$action='create'; $action='create';
} }
} }
@ -305,31 +353,34 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
// Ajout // Ajout
$paymentmode = new CompanyPaymentMode($db); $companypaymentmode = new CompanyPaymentMode($db);
$paymentmode->fk_soc = $object->id; $companypaymentmode->fk_soc = $object->id;
$paymentmode->bank = GETPOST('bank','alpha'); $companypaymentmode->bank = GETPOST('bank','alpha');
$paymentmode->label = GETPOST('label','alpha'); $companypaymentmode->label = GETPOST('label','alpha');
$paymentmode->number = GETPOST('cardnumber','alpha'); $companypaymentmode->number = GETPOST('cardnumber','alpha');
$paymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4); $companypaymentmode->last_four = substr(GETPOST('cardnumber','alpha'), -4);
$paymentmode->proprio = GETPOST('proprio','alpha'); $companypaymentmode->proprio = GETPOST('proprio','alpha');
$paymentmode->exp_date_month = GETPOST('exp_date_month','int'); $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int');
$paymentmode->exp_date_year = GETPOST('exp_date_year','int'); $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int');
$paymentmode->cvn = GETPOST('cvn','alpha'); $companypaymentmode->cvn = GETPOST('cvn','alpha');
$paymentmode->datec = dol_now(); $companypaymentmode->datec = dol_now();
$paymentmode->default_rib = 0; $companypaymentmode->default_rib = 0;
$paymentmode->type = 'card'; $companypaymentmode->type = 'card';
$paymentmode->country_code = $mysoc->country_code; $companypaymentmode->country_code = $mysoc->country_code;
$companypaymentmode->status = 1;
$companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha');
$db->begin(); $db->begin();
if (! $error) if (! $error)
{ {
$result = $paymentmode->create($user); $result = $companypaymentmode->create($user);
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
$action='createcard'; // Force chargement page création $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); $companybankaccount = new CompanyBankAccount($db);
$res = $account->setAsDefault(GETPOST('ribid','int')); $res = $companybankaccount->setAsDefault(GETPOST('ribid','int'));
if ($res) if ($res)
{ {
$url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; $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') if ($action == 'confirm_deletecard' && GETPOST('confirm','alpha') == 'yes')
{ {
$paymentmode = new CompanyPaymentMode($db); $companypaymentmode = new CompanyPaymentMode($db);
if ($paymentmode->fetch($ribid?$ribid:$id)) if ($companypaymentmode->fetch($ribid?$ribid:$id))
{ {
$result = $paymentmode->delete($user); $result = $companypaymentmode->delete($user);
if ($result > 0) if ($result > 0)
{ {
$url = $_SERVER['PHP_SELF']."?socid=".$object->id; $url = $_SERVER['PHP_SELF']."?socid=".$object->id;
@ -379,20 +430,20 @@ if (empty($reshook))
} }
else else
{ {
setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
} }
} }
else else
{ {
setEventMessages($paymentmode->error, $paymentmode->errors, 'errors'); setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
} }
} }
if ($action == 'confirm_delete' && GETPOST('confirm','alpha') == 'yes') if ($action == 'confirm_delete' && GETPOST('confirm','alpha') == 'yes')
{ {
$account = new CompanyBankAccount($db); $companybankaccount = new CompanyBankAccount($db);
if ($account->fetch($ribid?$ribid:$id)) if ($companybankaccount->fetch($ribid?$ribid:$id))
{ {
$result = $account->delete($user); $result = $companybankaccount->delete($user);
if ($result > 0) if ($result > 0)
{ {
$url = $_SERVER['PHP_SELF']."?socid=".$object->id; $url = $_SERVER['PHP_SELF']."?socid=".$object->id;
@ -401,12 +452,12 @@ if (empty($reshook))
} }
else else
{ {
setEventMessages($account->error, $account->errors, 'errors'); setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
} }
} }
else else
{ {
setEventMessages($account->error, $account->errors, 'errors'); setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
} }
} }
@ -476,11 +527,7 @@ if (empty($reshook))
if ($action == 'setlocalassourcedefault') if ($action == 'setlocalassourcedefault')
{ {
try { try {
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib set default_rib = 0 WHERE type = 'card' AND default_rib <> 0"; $companypaymentmode->setAsDefault($id);
$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);
$url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
header('Location: '.$url); header('Location: '.$url);
@ -540,21 +587,26 @@ llxHeader();
$head=societe_prepare_head($object); $head=societe_prepare_head($object);
// Load Bank account
if (! $id) if (! $id)
{ {
$account->fetch(0,$object->id); $companybankaccount->fetch(0, $object->id);
$companypaymentmode->fetch(0, null, $object->id, 'card');
} }
else 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) if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer)
{ {
print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">'; $actionforadd='update';
if ($action == 'editcard') $actionforadd='updatecard';
print '<input type="hidden" name="action" value="'.$actionforadd.'">';
print '<input type="hidden" name="id" value="'.GETPOST("id","int").'">'; print '<input type="hidden" name="id" value="'.GETPOST("id","int").'">';
} }
if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) 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 // Confirm delete ban
if ($action == 'delete') 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 // Confirm delete card
if ($action == 'deletecard') 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 = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
@ -638,7 +690,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
print '<br>'; print '<br>';
// Stripe payment modes // List of Stripe payment modes
if (! (empty($conf->stripe->enabled))) if (! (empty($conf->stripe->enabled)))
{ {
$morehtmlright=''; $morehtmlright='';
@ -708,14 +760,14 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
{ {
$companypaymentmodetemp->fetch($obj->rowid); $companypaymentmodetemp->fetch($obj->rowid);
$arrayofstripecard[$obj->stripe_card_ref]=$obj->stripe_card_ref; $arrayofstripecard[$companypaymentmodetemp->stripe_card_ref]=$companypaymentmodetemp->stripe_card_ref;
print '<tr>'; print '<tr>';
print '<td>'; print '<td>';
print $obj->rowid; print $companypaymentmodetemp->id;
print '</td>'; print '</td>';
print '<td>'; print '<td>';
print $obj->stripe_card_ref; print $companypaymentmodetemp->stripe_card_ref;
print '</td>'; print '</td>';
print '<td>'; print '<td>';
print img_credit_card($companypaymentmodetemp->type); print img_credit_card($companypaymentmodetemp->type);
@ -1078,20 +1130,8 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
} }
dol_fiche_end(); dol_fiche_end();
/*
if ($socid && $action != 'edit' && $action != 'create' && $action != 'createcard')
{
// Barre d'actions
print '<div class="tabsAction">';
if ($user->rights->societe->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=create">'.$langs->trans("Add").'</a>';
}
print '</div>';
}
*/
if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
{ {
print '<div class="fichecenter"><div class="fichehalfleft">'; print '<div class="fichecenter"><div class="fichehalfleft">';
@ -1152,41 +1192,41 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("LabelRIB").'</td>'; print '<tr><td class="titlefield fieldrequired">'.$langs->trans("LabelRIB").'</td>';
print '<td><input size="30" type="text" name="label" value="'.$account->label.'"></td></tr>'; print '<td><input class="minwidth300" type="text" name="label" value="'.$companybankaccount->label.'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("BankName").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("BankName").'</td>';
print '<td><input size="30" type="text" name="bank" value="'.$account->bank.'"></td></tr>'; print '<td><input class="minwidth200" type="text" name="bank" value="'.$companybankaccount->bank.'"></td></tr>';
// Show fields of bank account // Show fields of bank account
foreach ($account->getFieldsToShow(1) as $val) { foreach ($companybankaccount->getFieldsToShow(1) as $val) {
$require=false; $require=false;
if ($val == 'BankCode') { if ($val == 'BankCode') {
$name = 'code_banque'; $name = 'code_banque';
$size = 8; $size = 8;
$content = $account->code_banque; $content = $companybankaccount->code_banque;
} elseif ($val == 'DeskCode') { } elseif ($val == 'DeskCode') {
$name = 'code_guichet'; $name = 'code_guichet';
$size = 8; $size = 8;
$content = $account->code_guichet; $content = $companybankaccount->code_guichet;
} elseif ($val == 'BankAccountNumber') { } elseif ($val == 'BankAccountNumber') {
$name = 'number'; $name = 'number';
$size = 18; $size = 18;
$content = $account->number; $content = $companybankaccount->number;
} elseif ($val == 'BankAccountNumberKey') { } elseif ($val == 'BankAccountNumberKey') {
$name = 'cle_rib'; $name = 'cle_rib';
$size = 3; $size = 3;
$content = $account->cle_rib; $content = $companybankaccount->cle_rib;
} elseif ($val == 'IBAN') { } elseif ($val == 'IBAN') {
$name = 'iban'; $name = 'iban';
$size = 30; $size = 30;
$content = $account->iban; $content = $companybankaccount->iban;
if ($account->needIBAN()) $require=true; if ($companybankaccount->needIBAN()) $require=true;
} elseif ($val == 'BIC') { } elseif ($val == 'BIC') {
$name = 'bic'; $name = 'bic';
$size = 12; $size = 12;
$content = $account->bic; $content = $companybankaccount->bic;
if ($account->needIBAN()) $require=true; if ($companybankaccount->needIBAN()) $require=true;
} }
print '<tr><td'.($require?' class="fieldrequired" ':'').'>'.$langs->trans($val).'</td>'; print '<tr><td'.($require?' class="fieldrequired" ':'').'>'.$langs->trans($val).'</td>';
@ -1196,16 +1236,16 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>'; print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
print '<textarea name="domiciliation" rows="4" cols="40" maxlength="255">'; print '<textarea name="domiciliation" rows="4" cols="40" maxlength="255">';
print $account->domiciliation; print $companybankaccount->domiciliation;
print "</textarea></td></tr>"; print "</textarea></td></tr>";
print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>'; print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
print '<td><input size="30" type="text" name="proprio" value="'.$account->proprio.'"></td></tr>'; print '<td><input class="minwidth300" type="text" name="proprio" value="'.$companybankaccount->proprio.'"></td></tr>';
print "</td></tr>\n"; print "</td></tr>\n";
print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>'; print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
print '<textarea name="owner_address" rows="'.ROWS_4.'" cols="40" maxlength="255">'; print '<textarea name="owner_address" rows="'.ROWS_4.'" cols="40" maxlength="255">';
print $account->owner_address; print $companybankaccount->owner_address;
print "</textarea></td></tr>"; print "</textarea></td></tr>";
print '</table>'; print '</table>';
@ -1216,15 +1256,15 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
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 // RUM
print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>'; print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>';
print '<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($account->rum).'"></td></tr>'; print '<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($companybankaccount->rum).'"></td></tr>';
print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>'; print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
$tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); $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 '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
@ -1241,6 +1281,53 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
print '</div>'; print '</div>';
} }
// Edit Card
if ($socid && $action == 'editcard' && $user->rights->societe->creer)
{
dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company');
$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">';
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
print '<td><input class="minwidth300" type="text" id="label" name="label" value="'.$companypaymentmode->label.'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
print '<td><input class="minwidth200" type="text" name="proprio" value="'.$companypaymentmode->proprio.'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("CardNumber").'</td>';
print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.$companypaymentmode->number.'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
print '<td>';
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 '</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("CVN").'</td>';
print '<td><input size="8" type="text" name="cvn" value="'.$companypaymentmode->cvn.'"></td></tr>';
print '<tr><td>'.$langs->trans("StripeID")." ('card_....')</td>";
print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.'"></td></tr>';
print '</table>';
print '</div>';
dol_fiche_end();
print '<div align="center">';
print '<input class="button" value="'.$langs->trans("Modify").'" type="submit">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
print '</div>';
}
// Create BAN // Create BAN
if ($socid && $action == 'create' && $user->rights->societe->creer) if ($socid && $action == 'create' && $user->rights->societe->creer)
@ -1257,13 +1344,13 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LabelRIB").'</td>'; print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LabelRIB").'</td>';
print '<td><input size="30" type="text" id="label" name="label" value="'.GETPOST('label').'"></td></tr>'; print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label').'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>';
print '<td><input size="30" type="text" name="bank" value="'.GETPOST('bank').'"></td></tr>'; print '<td><input class="minwidth200" type="text" name="bank" value="'.GETPOST('bank').'"></td></tr>';
// Show fields of bank account // Show fields of bank account
foreach ($account->getFieldsToShow(1) as $val) { foreach ($companybankaccount->getFieldsToShow(1) as $val) {
$require=false; $require=false;
if ($val == 'BankCode') { if ($val == 'BankCode') {
@ -1281,11 +1368,11 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
} elseif ($val == 'IBAN') { } elseif ($val == 'IBAN') {
$name = 'iban'; $name = 'iban';
$size = 30; $size = 30;
if ($account->needIBAN()) $require=true; if ($companybankaccount->needIBAN()) $require=true;
} elseif ($val == 'BIC') { } elseif ($val == 'BIC') {
$name = 'bic'; $name = 'bic';
$size = 12; $size = 12;
if ($account->needIBAN()) $require=true; if ($companybankaccount->needIBAN()) $require=true;
} }
print '<tr><td'.($require?' class="fieldrequired" ':'').'>'.$langs->trans($val).'</td>'; print '<tr><td'.($require?' class="fieldrequired" ':'').'>'.$langs->trans($val).'</td>';
@ -1299,7 +1386,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
print "</textarea></td></tr>"; print "</textarea></td></tr>";
print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>'; print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
print '<td><input size="30" type="text" name="proprio" value="'.GETPOST('proprio').'"></td></tr>'; print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio').'"></td></tr>';
print "</td></tr>\n"; print "</td></tr>\n";
print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>'; print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
@ -1355,13 +1442,13 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer)
print '<table class="border centpercent">'; print '<table class="border centpercent">';
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>'; print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
print '<td><input size="30" type="text" id="label" name="label" value="'.GETPOST('label','alpha').'"></td></tr>'; print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label','alpha').'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
print '<td><input size="30" type="text" name="proprio" value="'.GETPOST('proprio','alpha').'"></td></tr>'; print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio','alpha').'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("CardNumber").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("CardNumber").'</td>';
print '<td><input size="30" type="text" name="cardnumber" value="'.GETPOST('cardnumber','alpha').'"></td></tr>'; print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.GETPOST('cardnumber','alpha').'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
print '<td>'; print '<td>';
@ -1372,6 +1459,9 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer)
print '<tr><td class="fieldrequired">'.$langs->trans("CVN").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("CVN").'</td>';
print '<td><input size="8" type="text" name="cvn" value="'.GETPOST('cvn','alpha').'"></td></tr>'; print '<td><input size="8" type="text" name="cvn" value="'.GETPOST('cvn','alpha').'"></td></tr>';
print '<tr><td>'.$langs->trans("StripeID")." ('card_....')</td>";
print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref','alpha').'"></td></tr>';
print '</table>'; print '</table>';
print '</div>'; print '</div>';
@ -1387,7 +1477,7 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer)
print '</div>'; print '</div>';
} }
if ($socid && $action == 'edit' && $user->rights->societe->creer) if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer)
{ {
print '</form>'; print '</form>';
} }