From 268b07bcf0fbff4570fb716f0341e18ce0a13ef5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Mar 2018 11:51:13 +0100 Subject: [PATCH] Can add/delete credit card localy --- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/class/translate.class.php | 2 +- .../install/mysql/migration/7.0.0-8.0.0.sql | 4 + .../install/mysql/tables/llx_societe_rib.sql | 2 +- htdocs/langs/en_US/stripe.lang | 8 +- .../class/companypaymentmode.class.php | 47 +++- htdocs/societe/paymentmodes.php | 207 +++++++++++++++--- 7 files changed, 230 insertions(+), 42 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4d26361139000..2dc47e6e9004b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4780,7 +4780,7 @@ function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $ * @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='') { diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 858b57d4c87b6..69fe031459d05 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -231,7 +231,7 @@ function load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='',$loadfromfil $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) { diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index e4c0c406d72ba..534cba912d5fa 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -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 ( diff --git a/htdocs/install/mysql/tables/llx_societe_rib.sql b/htdocs/install/mysql/tables/llx_societe_rib.sql index 6157af37830b1..2463378067ade 100644 --- a/htdocs/install/mysql/tables/llx_societe_rib.sql +++ b/htdocs/install/mysql/tables/llx_societe_rib.sql @@ -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, diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 51aaad3516599..3db643817973c 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -52,4 +52,10 @@ StripeChargeList=List of Stripe charges StripeCustomerId=Stripe customer id StripePaymentModes=Stripe payment modes LocalID=Local ID -StripeID=Stripe ID \ No newline at end of file +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? diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index baba6252284e1..6a2095883c144 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -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 $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 $fk_user_creat; - public $fk_user_modif; public $import_key; - public $status; // END MODULEBUILDER PROPERTIES diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index ae446a047d3db..d24f4dd5f32a8 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -32,6 +32,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.'/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 ($action == 'update' && ! $_POST["cancel"]) + if ($action == 'update') { // Modification if (! GETPOST('label')) @@ -188,19 +189,14 @@ } } - if ($action == 'add' && ! $_POST["cancel"]) + if ($action == 'add') { $error=0; - if (! GETPOST('label')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - $action='create'; - $error++; - } - if (! GETPOST('bank')) + if (! GETPOST('label','alpha') || ! GETPOST('bank','alpha')) { - 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 ($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 ($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 @@ $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); + + $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) + { - if ($action == 'setassourcedefault') + } + } + elseif ($action == 'setassourcedefault') { try { $cu = \Stripe\Customer::retrieve($stripecu); @@ -436,6 +533,7 @@ */ $form = new Form($db); +$formother = new FormOther($db); $formfile = new FormFile($db); llxHeader(); @@ -452,31 +550,38 @@ } 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 '
'; print ''; print ''; print ''; } -if ($socid && $action == 'create' && $user->rights->societe->creer) +if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) { print ''; print ''; - print ''; + $actionforadd='add'; + if ($action == 'createcard') $actionforadd='addcard'; + print ''; } // 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 = ''.$langs->trans("BackToList").''; @@ -533,6 +638,7 @@ print '
'; + // Stripe payment modes if (! (empty($conf->stripe->enabled))) { $morehtmlright=''; @@ -628,17 +734,17 @@ print ''; // Default print ''; - if (empty($obj->default_rib)) + if (empty($companypaymentmodetemp->default_rib)) { - //print ''; + print ''; print img_picto($langs->trans("Default"),'off'); - //print ''; + print ''; } else { print img_picto($langs->trans("Default"),'on'); } print ''; print ''; - 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 ''; print ''; @@ -973,7 +1079,7 @@ dol_fiche_end(); /* - if ($socid && $action != 'edit' && $action != 'create') + if ($socid && $action != 'edit' && $action != 'create' && $action != 'createcard') { // Barre d'actions print '
'; @@ -1031,7 +1137,7 @@ */ } -// 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 @@ } -// 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 @@ print ''; print ''; - print ''; + print ''; print ''; print ''; @@ -1225,6 +1331,55 @@ dol_fiche_end(); + dol_set_focus('#label'); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; +} + +// Create Card +if ($socid && $action == 'createcard' && $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 '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'; + + 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(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 '
'.$langs->trans("CVN").'
'; + + print '
'; + + dol_fiche_end(); + + dol_set_focus('#label'); + print '
'; print ''; print '     '; @@ -1236,7 +1391,7 @@ { print ''; } -if ($socid && $action == 'create' && $user->rights->societe->creer) +if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer) { print ''; }