diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6616745888b..4600cefbdc3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5527,7 +5527,7 @@ abstract class CommonObject $label = $val['label']; $type = $val['type']; $size = $val['css']; - + // Convert var to be able to share same code than showOutputField of extrafields if (preg_match('/varchar\((\d+)\)/', $type, $reg)) { @@ -6675,6 +6675,9 @@ abstract class CommonObject // TODO... } + + /* Part for comments */ + /** * Load comments linked with current task * @return boolean 1 if ok diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 80c4c12a68c..65753457000 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3525,6 +3525,24 @@ function img_allow($allow, $titlealt = 'default') return '-'; } +/** + * Return image of a credit card according to its brand name + * + * @param string $brand Brand name of credit card + * @return string Return img tag + */ +function img_credit_card($brand) +{ + if ($brand == 'Visa') {$brand='cc-visa';} + elseif ($brand == 'MasterCard') {$brand='cc-mastercard';} + elseif ($brand == 'American Express') {$brand='cc-amex';} + elseif ($brand == 'Discover') {$brand='cc-discover';} + elseif ($brand == 'JCB') {$brand='cc-jcb';} + elseif ($brand == 'Diners Club') {$brand='cc-diners-club';} + elseif (! in_array($brand, array('cc-visa','cc-mastercard','cc-amex','cc-discover','cc-jcb','cc-diners-club'))) {$brand='credit-card';} + + return ''; +} /** * Show MIME img of a file diff --git a/htdocs/loan/class/loanschedule.class.php b/htdocs/loan/class/loanschedule.class.php index ebb1820bca0..a430f79366e 100644 --- a/htdocs/loan/class/loanschedule.class.php +++ b/htdocs/loan/class/loanschedule.class.php @@ -386,7 +386,7 @@ class LoanSchedule extends CommonObject * @param int $loanid Id object * @return int <0 if KO, >0 if OK */ - function fetchall($loanid) + function fetchAll($loanid) { global $langs; @@ -409,7 +409,7 @@ class LoanSchedule extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql.= " WHERE t.fk_loan = ".$loanid; - dol_syslog(get_class($this)."::fetchall", LOG_DEBUG); + dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/loan/createschedule.php b/htdocs/loan/createschedule.php index 4ab2499c265..0ecc0038835 100644 --- a/htdocs/loan/createschedule.php +++ b/htdocs/loan/createschedule.php @@ -89,7 +89,7 @@ if ($action == 'updateecheancier') { } $echeance = new LoanSchedule($db); -$echeance->fetchall($object->id); +$echeance->fetchAll($object->id); top_htmlhead('', ''); $var = ! $var; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index e40b6b178e6..267a869fb46 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -142,12 +142,21 @@ class MyObject extends CommonObject */ public function __construct(DoliDB $db) { - global $conf; + global $conf, $user; $this->db = $db; - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; - if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0; + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0; + if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0; + + // Unset fields that are disabled + foreach($this->fields as $key => $val) + { + if (isset($val['enabled']) && empty($val['enabled'])) + { + unset($this->fields[$key]); + } + } } /** diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 4dc509c251e..baba6252284 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -112,10 +112,10 @@ 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), ); public $rowid; public $fk_soc; - public $entity; public $label; public $amount; public $description; @@ -167,8 +167,8 @@ class CompanyPaymentMode extends CommonObject $this->db = $db; - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; - if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0; + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0; + if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0; } /** diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 273b5e53bb5..845bc3e4c1e 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -33,6 +33,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.'/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'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; @@ -409,7 +410,7 @@ if (empty($reshook)) } } - elseif ($action == 'delete') + elseif ($action == 'deletecard') { try { $cu = \Stripe\Customer::retrieve($stripecu); @@ -534,7 +535,12 @@ if ($socid && $action != 'edit' && $action != "create") if (! (empty($conf->stripe->enabled))) { - print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc ? ' ('.$stripeacc.')':''), '', ''); + $morehtmlright=''; + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + $morehtmlright=''.$langs->trans("Add").''; + } + print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' ('.$stripeacc.')':''), $morehtmlright, ''); $listofsources = array(); if (is_object($stripe) && $stripeacc) @@ -554,43 +560,131 @@ if ($socid && $action != 'edit' && $action != "create") print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''."\n"; print ''; - print ''; + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + print ''; + } + print ''; print ''; print ''; print ''; print ''; + print ''; print "\n"; - if (is_array($listofsources)) + $nbremote = 0; + $nblocal = 0; + $arrayofstripecard = array(); + + // Show local sources + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + //$societeaccount = new SocieteAccount($db); + $companypaymentmodetemp = new CompanyPaymentMode($db); + + $sql='SELECT rowid FROM '.MAIN_DB_PREFIX."societe_rib"; + $sql.=" WHERE type in ('card', 'paypal')"; + $sql.=" AND fk_soc = ".$object->id; + + $resql = $db->query($sql); + if ($resql) + { + $num_rows = $db->num_rows($resql); + if ($num_rows) + { + $i=0; + while ($i < $num_rows) + { + $nblocal++; + + $obj = $db->fetch_object($resql); + if ($obj) + { + $companypaymentmodetemp->fetch($obj->rowid); + + $arrayofstripecard[$obj->stripe_card_ref]=$obj->stripe_card_ref; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + $i++; + } + } + else + { + print $langs->trans("NoPaymentMethodOnFile"); + } + } + else dol_print_error($db); + } + + // Show remote sources (not already shown as local source) + if (is_array($listofsources) && count($listofsources)) { foreach ($listofsources as $src) { + if (! empty($arrayofstripecard[$src->id])) continue; // Already in previous list + + $nbremote++; + print ''; + // Local ID + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) + { + print ''; + } print ''; print ''; + print ''; print ''; + print ''; + + print ''; } } - if (empty($listofsources)) + + if ($nbremote == 0 && $nblocal == 0) { - print ''; + print ''; } print "
'.$langs->trans('ID').''.$langs->trans('LocalID').''.$langs->trans('StripeID').''.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('Default').''.$langs->trans('Note').'
'; + print $obj->rowid; + print ''; + print $obj->stripe_card_ref; + print ''; + print img_credit_card($companypaymentmodetemp->type); + print ''; + if ($companypaymentmodetemp->last_four) print '**** '.$companypaymentmodetemp->last_four; + if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) print ' - '.$companypaymentmodetemp->exp_date_month.'/'.$companypaymentmodetemp->exp_date_year.''; + print ''; + if ($companypaymentmodetemp->country_code) + { + $img=picto_from_langcode($companypaymentmodetemp->country_code); + print $img?$img.' ':''; + print getCountry($companypaymentmodetemp->country_code,1); + } + else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + print ''; + print yn($obj->default_rib); + print ''; + if (empty($obj->stripe_card_ref)) print $langs->trans("Local"); + else print $langs->trans("LocalAndRemote"); + print ''; + if ($user->rights->societe->creer) + { + print ''; + print img_picto($langs->trans("Modify"),'edit'); + print ''; + print ' '; + print ''; + print img_delete($langs->trans("Delete")); + print ''; + } + print '
'; + print ''; print $src->id; print ''; if ($src->object=='card') { - if ($src->brand == 'Visa') {$brand='cc-visa';} - elseif ($src->brand == 'MasterCard') {$brand='cc-mastercard';} - elseif ($src->brand == 'American Express') {$brand='cc-amex';} - elseif ($src->brand == 'Discover') {$brand='cc-discover';} - elseif ($src->brand == 'JCB') {$brand='cc-jcb';} - elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';} - else {$brand='credit-card';} - print ''; + print img_credit_card($src->brand); } elseif ($src->object=='source' && $src->type=='card') { - if ($src->card->brand == 'Visa') {$brand='cc-visa';} - elseif ($src->card->brand == 'MasterCard') {$brand='cc-mastercard';} - elseif ($src->card->brand == 'American Express') {$brand='cc-amex';} - elseif ($src->card->brand == 'Discover') {$brand='cc-discover';} - elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';} - elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';} - else {$brand='credit-card';} - print ''; + print img_credit_card($src->card->brand); } elseif ($src->object=='source' && $src->type=='sepa_debit') { @@ -647,23 +741,25 @@ if ($socid && $action != 'edit' && $action != "create") print img_picto($langs->trans("Default"),'on'); } print ''; + print $langs->trans("Remote"); + print ''; if ($user->rights->societe->creer) { - // print ''; - // print img_picto($langs->trans("Modify"),'edit'); - // print ''; - // print ' '; - print ''; - print img_delete($langs->trans("Delete")); - print ''; + print ''; + print img_delete($langs->trans("Delete")); + print ''; } - print '
'.$langs->trans("NoSource").'
'.$langs->trans("None").'
"; print "
";