Skip to content

Commit

Permalink
Can work both with remote and local payment modes
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 13, 2018
1 parent c78e5d2 commit da617f7
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 40 deletions.
5 changes: 4 additions & 1 deletion htdocs/core/class/commonobject.class.php
Expand Up @@ -5527,7 +5527,7 @@ function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyp
$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))
{
Expand Down Expand Up @@ -6675,6 +6675,9 @@ public function initAsSpecimenCommon()
// TODO...
}


/* Part for comments */

/**
* Load comments linked with current task
* @return boolean 1 if ok
Expand Down
18 changes: 18 additions & 0 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -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 '<span class="fa fa-'.$brand.' fa-2x fa-fw"></span>';
}

/**
* Show MIME img of a file
Expand Down
4 changes: 2 additions & 2 deletions htdocs/loan/class/loanschedule.class.php
Expand Up @@ -386,7 +386,7 @@ function calc_mens($capital,$rate,$nbterm)
* @param int $loanid Id object
* @return int <0 if KO, >0 if OK
*/
function fetchall($loanid)
function fetchAll($loanid)
{
global $langs;

Expand All @@ -409,7 +409,7 @@ function fetchall($loanid)
$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)
Expand Down
2 changes: 1 addition & 1 deletion htdocs/loan/createschedule.php
Expand Up @@ -89,7 +89,7 @@
}

$echeance = new LoanSchedule($db);
$echeance->fetchall($object->id);
$echeance->fetchAll($object->id);

top_htmlhead('', '');
$var = ! $var;
Expand Down
15 changes: 12 additions & 3 deletions htdocs/modulebuilder/template/class/myobject.class.php
Expand Up @@ -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]);
}
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions htdocs/societe/class/companypaymentmode.class.php
Expand Up @@ -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;
Expand Down Expand Up @@ -167,8 +167,8 @@ public function __construct(DoliDB $db)

$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;
}

/**
Expand Down
156 changes: 126 additions & 30 deletions htdocs/societe/paymentmodes.php
Expand Up @@ -33,6 +33,7 @@
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';
Expand Down Expand Up @@ -409,7 +410,7 @@

}
}
elseif ($action == 'delete')
elseif ($action == 'deletecard')
{
try {
$cu = \Stripe\Customer::retrieve($stripecu);
Expand Down Expand Up @@ -534,7 +535,12 @@

if (! (empty($conf->stripe->enabled)))
{
print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc ? ' ('.$stripeacc.')':''), '', '');
$morehtmlright='';
if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
{
$morehtmlright='<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=createcard">'.$langs->trans("Add").'</a>';
}
print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc?' ('.$stripeacc.')':''), $morehtmlright, '');

$listofsources = array();
if (is_object($stripe) && $stripeacc)
Expand All @@ -554,43 +560,131 @@
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="liste" width="100%">'."\n";
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('ID').'</td>';
if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
{
print '<td>'.$langs->trans('LocalID').'</td>';
}
print '<td>'.$langs->trans('StripeID').'</td>';
print '<td>'.$langs->trans('Type').'</td>';
print '<td>'.$langs->trans('Informations').'</td>';
print '<td></td>';
print '<td align="center">'.$langs->trans('Default').'</td>';
print '<td>'.$langs->trans('Note').'</td>';
print "<td></td></tr>\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 '<tr>';
print '<td>';
print $obj->rowid;
print '</td>';
print '<td>';
print $obj->stripe_card_ref;
print '</td>';
print '<td>';
print img_credit_card($companypaymentmodetemp->type);
print '</td>';
print '<td>';
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 '</td><td>';
if ($companypaymentmodetemp->country_code)
{
$img=picto_from_langcode($companypaymentmodetemp->country_code);
print $img?$img.' ':'';
print getCountry($companypaymentmodetemp->country_code,1);
}
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
print '</td>';
print '<td align="center">';
print yn($obj->default_rib);
print '</td>';
print '<td>';
if (empty($obj->stripe_card_ref)) print $langs->trans("Local");
else print $langs->trans("LocalAndRemote");
print '</td>';
print '<td align="center">';
if ($user->rights->societe->creer)
{
print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=editcard">';
print img_picto($langs->trans("Modify"),'edit');
print '</a>';
print '&nbsp;';
print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=deletecard">';
print img_delete($langs->trans("Delete"));
print '</a>';
}
print '</td>';
print '</tr>';
}
$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 '<tr class="oddeven">';
// Local ID
if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
{
print '<td>';
print '</td>';
}
print '<td>';
print $src->id;
print '</td>';
print '<td>';
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 '<span class="fa fa-'.$brand.' fa-2x fa-fw"></span>';
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 '<span class="fa fa-'.$brand.' fa-2x fa-fw"></span>';
print img_credit_card($src->card->brand);
}
elseif ($src->object=='source' && $src->type=='sepa_debit')
{
Expand Down Expand Up @@ -647,23 +741,25 @@
print img_picto($langs->trans("Default"),'on');
}
print '</td>';
print '<td>';
print $langs->trans("Remote");
print '</td>';
print '<td align="center">';
if ($user->rights->societe->creer)
{
// print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$src->id.'&action=edit">';
// print img_picto($langs->trans("Modify"),'edit');
// print '</a>';
// print '&nbsp;';
print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=delete">';
print img_delete($langs->trans("Delete"));
print '</a>';
print '<a href="' . DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=deletecard">';
print img_delete($langs->trans("Delete"));
print '</a>';
}
print '</td></tr>';
print '</td>';

print '</tr>';
}
}
if (empty($listofsources))

if ($nbremote == 0 && $nblocal == 0)
{
print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("NoSource").'</td></tr>';
print '<tr><td class="opacitymedium" colspan="7">'.$langs->trans("None").'</td></tr>';
}
print "</table>";
print "</div>";
Expand Down

0 comments on commit da617f7

Please sign in to comment.