Can add/delete credit card localy

This commit is contained in:
Laurent Destailleur 2018-03-14 11:51:13 +01:00
parent fe68e8acdd
commit 268b07bcf0
7 changed files with 231 additions and 43 deletions

View File

@ -4780,7 +4780,7 @@ class Form
* @param string $addplusone Add a link "+1 hour". Value must be name of another select_date field.
* @param datetime $adddateof Add a link "Date of invoice" using the following date.
* @return string|null Nothing or string if nooutput is 1
* @see form_date
* @see form_date, select_month, select_year, select_dayofweek
*/
function select_date($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowlink=0, $nooutput=0, $disabled=0, $fullday='', $addplusone='', $adddateof='')
{

View File

@ -231,7 +231,7 @@ class Translate
$filelangexists=is_file($file_lang_osencoded);
dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists);
//dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists);
if ($filelangexists)
{

View File

@ -119,6 +119,10 @@ ALTER TABLE llx_societe_rib ADD COLUMN starting_date date;
ALTER TABLE llx_societe_rib ADD COLUMN total_amount_of_all_payments double(24,8);
ALTER TABLE llx_societe_rib ADD COLUMN stripe_card_ref varchar(128);
ALTER TABLE llx_societe_rib ADD COLUMN status integer NOT NULL DEFAULT 1;
UPDATE llx_societe_rib set type = 'ban' where type = '' OR type IS NULL;
-- VMYSQL4.3 ALTER TABLE llx_societe_rib MODIFY COLUMN type varchar(32) NOT NULL;
-- VPGSQL8.2 ALTER TABLE llx_societe_rib ALTER COLUMN type SET NOT NULL;
CREATE TABLE llx_ticketsup
(

View File

@ -23,7 +23,7 @@
create table llx_societe_rib
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
type varchar(32) DEFAULT 'ban', -- 'ban' or 'paypal' or 'card' or 'stripe'
type varchar(32) DEFAULT 'ban' NOT NULL, -- 'ban' or 'paypal' or 'card' or 'stripe'
label varchar(30),
fk_soc integer NOT NULL,
datec datetime,

View File

@ -52,4 +52,10 @@ StripeChargeList=List of Stripe charges
StripeCustomerId=Stripe customer id
StripePaymentModes=Stripe payment modes
LocalID=Local ID
StripeID=Stripe ID
StripeID=Stripe ID
NameOnCard=Name on card
CardNumber=Card Number
ExpiryDate=Expiry Date
CVN=CVN
DeleteACard=Delete Card record
ConfirmDeleteCard=Are you sure you want to delete this Card record?

View File

@ -78,8 +78,6 @@ class CompanyPaymentMode extends CommonObject
public $fields=array(
'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35),
'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40),
@ -95,7 +93,6 @@ class CompanyPaymentMode extends CommonObject
'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90),
'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95),
'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110),
'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115),
'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120),
@ -112,21 +109,47 @@ class CompanyPaymentMode extends CommonObject
'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175),
'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185),
//'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
//'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
);
public $rowid;
public $fk_soc;
public $label;
public $amount;
public $description;
public $note_public;
public $note_private;
public $date_creation;
public $tms;
public $fk_user_creat;
public $fk_user_modif;
public $import_key;
public $bank;
public $code_banque;
public $code_guichet;
public $number;
public $cle_rib;
public $bic;
public $iban_prefix;
public $domiciliation;
public $proprio;
public $owner_address;
public $default_rib;
public $rum;
public $date_rum;
public $frstrecur;
public $type;
public $last_four;
public $card_type;
public $cvn;
public $exp_date_month;
public $exp_date_year;
public $country_code;
public $approved;
public $email;
public $max_total_amount_of_all_payments;
public $preapproval_key;
public $total_amount_of_all_payments;
public $stripe_card_ref;
public $status;
public $starting_date;
public $ending_date;
public $datec;
public $tms;
public $import_key;
// END MODULEBUILDER PROPERTIES

View File

@ -32,6 +32,7 @@ require '../main.inc.php';
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.'/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';
@ -111,7 +112,7 @@ if (empty($reshook))
}
}
if ($action == 'update' && ! $_POST["cancel"])
if ($action == 'update')
{
// Modification
if (! GETPOST('label'))
@ -188,19 +189,14 @@ if (empty($reshook))
}
}
if ($action == 'add' && ! $_POST["cancel"])
if ($action == 'add')
{
$error=0;
if (! GETPOST('label'))
if (! GETPOST('label','alpha') || ! GETPOST('bank','alpha'))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
$action='create';
$error++;
}
if (! GETPOST('bank'))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), 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='create';
$error++;
}
@ -291,6 +287,68 @@ if (empty($reshook))
}
}
if ($action == 'addcard')
{
$error=0;
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++;
}
if (! $error)
{
// Ajout
$paymentmode = 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;
$db->begin();
if (! $error)
{
$result = $paymentmode->create($user);
if ($result < 0)
{
$error++;
setEventMessages($paymentmode->error, $paymentmode->errors, 'errors');
$action='createcard'; // Force chargement page création
}
}
if (! $error)
{
$db->commit();
$url=$_SERVER["PHP_SELF"].'?socid='.$object->id;
header('Location: '.$url);
exit;
}
else
{
$db->rollback();
}
}
}
if ($action == 'setasbankdefault')
{
$account = new CompanyBankAccount($db);
@ -307,7 +365,29 @@ if (empty($reshook))
}
}
if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes')
if ($action == 'confirm_deletecard' && GETPOST('confirm','alpha') == 'yes')
{
$paymentmode = new CompanyPaymentMode($db);
if ($paymentmode->fetch($ribid?$ribid:$id))
{
$result = $paymentmode->delete($user);
if ($result > 0)
{
$url = $_SERVER['PHP_SELF']."?socid=".$object->id;
header('Location: '.$url);
exit;
}
else
{
setEventMessages($paymentmode->error, $paymentmode->errors, 'errors');
}
}
else
{
setEventMessages($paymentmode->error, $paymentmode->errors, 'errors');
}
}
if ($action == 'confirm_delete' && GETPOST('confirm','alpha') == 'yes')
{
$account = new CompanyBankAccount($db);
if ($account->fetch($ribid?$ribid:$id))
@ -393,8 +473,25 @@ if (empty($reshook))
$db->rollback();
}
}
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);
if ($action == 'setassourcedefault')
$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;
header('Location: '.$url);
exit;
}
catch(Exception $e)
{
}
}
elseif ($action == 'setassourcedefault')
{
try {
$cu = \Stripe\Customer::retrieve($stripecu);
@ -436,6 +533,7 @@ if (empty($reshook))
*/
$form = new Form($db);
$formother = new FormOther($db);
$formfile = new FormFile($db);
llxHeader();
@ -452,31 +550,38 @@ else
}
if (empty($account->socid)) $account->socid=$object->id;
if ($socid && $action == 'edit' && $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 '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.GETPOST("id","int").'">';
}
if ($socid && $action == 'create' && $user->rights->societe->creer)
if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer)
{
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="action" value="add">';
$actionforadd='add';
if ($action == 'createcard') $actionforadd='addcard';
print '<input type="hidden" name="action" value="'.$actionforadd.'">';
}
// View
if ($socid && $action != 'edit' && $action != "create")
if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard')
{
dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company');
// Confirm delete third party
// 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);
}
// 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);
}
$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
@ -533,6 +638,7 @@ if ($socid && $action != 'edit' && $action != "create")
print '<br>';
// Stripe payment modes
if (! (empty($conf->stripe->enabled)))
{
$morehtmlright='';
@ -628,17 +734,17 @@ if ($socid && $action != 'edit' && $action != "create")
print '</td>';
// Default
print '<td align="center">';
if (empty($obj->default_rib))
if (empty($companypaymentmodetemp->default_rib))
{
//print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault">';
print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=setlocalassourcedefault">';
print img_picto($langs->trans("Default"),'off');
//print '</a>';
print '</a>';
} else {
print img_picto($langs->trans("Default"),'on');
}
print '</td>';
print '<td>';
if (empty($obj->stripe_card_ref)) print $langs->trans("Local");
if (empty($companypaymentmodetemp->stripe_card_ref)) print $langs->trans("Local");
else print $langs->trans("LocalAndRemote");
print '</td>';
print '<td align="center">';
@ -973,7 +1079,7 @@ if ($socid && $action != 'edit' && $action != "create")
dol_fiche_end();
/*
if ($socid && $action != 'edit' && $action != 'create')
if ($socid && $action != 'edit' && $action != 'create' && $action != 'createcard')
{
// Barre d'actions
print '<div class="tabsAction">';
@ -1031,7 +1137,7 @@ if ($socid && $action != 'edit' && $action != "create")
*/
}
// Edit
// Edit BAN
if ($socid && $action == 'edit' && $user->rights->societe->creer)
{
dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company');
@ -1136,7 +1242,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
}
// Create
// Create BAN
if ($socid && $action == 'create' && $user->rights->societe->creer)
{
dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company');
@ -1151,7 +1257,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
print '<table class="border centpercent">';
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LabelRIB").'</td>';
print '<td><input size="30" type="text" name="label" value="'.GETPOST('label').'"></td></tr>';
print '<td><input size="30" type="text" id="label" name="label" value="'.GETPOST('label').'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>';
print '<td><input size="30" type="text" name="bank" value="'.GETPOST('bank').'"></td></tr>';
@ -1225,6 +1331,55 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
dol_fiche_end();
dol_set_focus('#label');
print '<div class="center">';
print '<input class="button" value="'.$langs->trans("Add").'" type="submit">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input name="cancel" class="button" value="'.$langs->trans("Cancel").'" type="submit">';
print '</div>';
}
// Create Card
if ($socid && $action == 'createcard' && $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="nofichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">';
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 '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
print '<td><input size="30" type="text" name="proprio" value="'.GETPOST('proprio','alpha').'"></td></tr>';
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 '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
print '<td>';
print $formother->select_month(GETPOST('exp_date_month','int'), 'exp_date_month', 1);
print $formother->select_year(GETPOST('exp_date_year','int'), '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="'.GETPOST('cvn','alpha').'"></td></tr>';
print '</table>';
print '</div>';
dol_fiche_end();
dol_set_focus('#label');
print '<div class="center">';
print '<input class="button" value="'.$langs->trans("Add").'" type="submit">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
@ -1236,7 +1391,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
{
print '</form>';
}
if ($socid && $action == 'create' && $user->rights->societe->creer)
if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer)
{
print '</form>';
}