From 79cb1f5699c9c13c52c377662b768f425e2ded64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 13 Sep 2018 13:57:01 +0200 Subject: [PATCH] clean code --- htdocs/stripe/payment.php | 329 +++++++++++++++++----------------- htdocs/stripe/transaction.php | 78 ++++---- 2 files changed, 209 insertions(+), 198 deletions(-) diff --git a/htdocs/stripe/payment.php b/htdocs/stripe/payment.php index 6560d42d137..a26e8e23335 100644 --- a/htdocs/stripe/payment.php +++ b/htdocs/stripe/payment.php @@ -1,14 +1,15 @@ - * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2007 Franky Van Liedekerke - * Copyright (C) 2012 Cédric Salvador - * Copyright (C) 2014 Raphaël Doursenaud - * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> - * Copyright (C) 2015 Juanjo Menent - * Copyright (C) 2018 ThibaultFOUCART +/* Copyright (C) 2001-2006 Rodolphe Quiedeville + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2007 Franky Van Liedekerke + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2014 Raphaël Doursenaud + * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> + * Copyright (C) 2015 Juanjo Menent + * Copyright (C) 2018 ThibaultFOUCART + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,9 +48,9 @@ $confirm = GETPOST('confirm'); $facid = GETPOST('facid','int'); $socname = GETPOST('socname'); -$source = GETPOST('source_id'); +$source = GETPOST('source_id'); $accountid = GETPOST('accountid'); -$paymentnum = GETPOST('num_paiement'); +$paymentnum = GETPOST('num_paiement'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); @@ -218,15 +219,12 @@ if (empty($reshook)) /* * Action add_paiement */ - if ($action == 'add_paiement') - { - if ($error) - { - $action = 'create'; - if (!$source) - { - setEventMessages($langs->transnoentities('NoSource'), null, 'errors'); - } + if ($action == 'add_paiement') { + if ($error) { + $action = 'create'; + if (!$source) { + setEventMessages($langs->transnoentities('NoSource'), null, 'errors'); + } $error++; } // Le reste propre a cette action s'affiche en bas de page. @@ -301,7 +299,7 @@ if (empty($reshook)) } elseif (preg_match('/src_/i',$source)) { - + $customer2 = $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus); $src = $customer2->sources->retrieve("$source"); if ($src->type=='card') @@ -406,16 +404,14 @@ if (empty($reshook)) * View */ -$form=new Form($db); +$form = new Form($db); llxHeader(); -if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) -{ +if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) { $service = 'StripeLive'; $servicestatus = 0; -} -else { +} else { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); } @@ -568,7 +564,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''.$langs->trans('Invoice').''.$facture->getNomUrl(4)."\n"; }*/ - // Third party + // Third party print ''.$langs->trans('Company').''.$facture->thirdparty->getNomUrl(4)."\n"; // Bank account @@ -583,22 +579,22 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } // Cheque number -// print ''.$langs->trans('Numero'); -// print ' ('.$langs->trans("ChequeOrTransferNumber").')'; -// print ''; -// print ''; + //print ''.$langs->trans('Numero'); + //print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + //print ''; + //print ''; // Check transmitter -// print ''.$langs->trans('CheckTransmitter'); -// print ' ('.$langs->trans("ChequeMaker").')'; -// print ''; -// print ''; + //print ''.$langs->trans('CheckTransmitter'); + //print ' ('.$langs->trans("ChequeMaker").')'; + //print ''; + //print ''; // Bank name -// print ''.$langs->trans('Bank'); -// print ' ('.$langs->trans("ChequeBank").')'; -// print ''; -// print ''; + //print ''.$langs->trans('Bank'); + //print ' ('.$langs->trans("ChequeBank").')'; + //print ''; + //print ''; // Comments print ''.$langs->trans('Comments').''; @@ -607,145 +603,155 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; - dol_fiche_end(); + dol_fiche_end(); - $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus); + $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus); - print '
'; - print_barre_liste($langs->trans('StripeSourceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); + print '
'; + print_barre_liste($langs->trans('StripeSourceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); - print ''."\n"; - // Titles with sort buttons - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - foreach ($customerstripe->sources->data as $src) { - print ''; + print '
'.$langs->trans('Type').''.$langs->trans('Informations').'
'."\n"; + // Titles with sort buttons + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + foreach ($customerstripe->sources->data as $src) { + print ''; print ''; -print ''; -print ''; + print' >'; + if ($src->object=='card') { + print img_credit_card($src->brand); + } elseif ($src->object=='source' && $src->type=='card') { + print img_credit_card($src->card->brand); + } elseif ($src->object=='source' && $src->type=='sepa_debit') { + print ''; + } + print ''; + print ''; // Default print ''; -print ''; -} -// TODO more dolibarize with new stripe function and stripeconnect -//if ($stripe->getStripeCustomerAccount($facture->socid)) { -//$account=\Stripe\Account::retrieve("".$stripe->getStripeCustomerAccount($facture->socid).""); -//} + print ''; + } + // TODO more dolibarize with new stripe function and stripeconnect + //if ($stripe->getStripeCustomerAccount($facture->socid)) { + // $account=\Stripe\Account::retrieve("".$stripe->getStripeCustomerAccount($facture->socid).""); + //} - if (($account->type=='custom' or $account->type=='express') && $entity==1) { - print ''; + if (($account->type=='custom' or $account->type=='express') && $entity==1) { + print ''; - print ''; + print ''; - print ''; - // Default - print ''; - print ''; - } - if (empty($input)&&!$stripe->getStripeCustomerAccount($facture->socid)) - { - print ''; - } + print ''; + // Default + print ''; + print ''; + } + if (empty($input)&&!$stripe->getStripeCustomerAccount($facture->socid)) { + print ''; + } - print "
'.$langs->trans('Type').''.$langs->trans('Informations').'
id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"';} -print'>id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { + if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { + print'class="opacitymedium"'; + } + print '>id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print ' disabled'; } elseif (($customerstripe->default_source==$src->id && $action != 'add_paiement') or ($source==$src->id && $action == 'add_paiement')) { print ' checked'; } print '>id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"';} + print 'id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { + print'class="opacitymedium"'; + } -print' >'; - if ($src->object=='card') - { - print img_credit_card($src->brand); - } - elseif ($src->object=='source' && $src->type=='card') - { - print img_credit_card($src->card->brand); - } - elseif ($src->object=='source' && $src->type=='sepa_debit') - { - print ''; - } -print 'id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"';} -print' >'; -if ($src->object=='card'){ - print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; -print ''; - if ($src->country) - { - $img=picto_from_langcode($src->country); - print $img?$img.' ':''; - print getCountry($src->country,1); - } - else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; -} -elseif ($src->object=='source' && $src->type=='card'){ - print $src->owner->name.'
....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; -print '
'; - if ($src->card->country) - { - $img=picto_from_langcode($src->card->country); - print $img?$img.' ':''; - print getCountry($src->card->country,1); - } - else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; -} -elseif ($src->object=='source' && $src->type=='sepa_debit'){ -print 'info sepa'; -print ''; - if ($src->sepa_debit->country) - { - $img=picto_from_langcode($src->sepa_debit->country); - print $img?$img.' ':''; - print getCountry($src->sepa_debit->country,1); - } - else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; -} -print 'id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { + print'class="opacitymedium"'; + } + print' >'; + if ($src->object=='card') { + print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; + print ''; + if ($src->country) { + $img = picto_from_langcode($src->country); + print $img?$img.' ':''; + print getCountry($src->country,1); + } else { + print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + } + } elseif ($src->object=='source' && $src->type=='card') { + print $src->owner->name.'
....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; + print '
'; + if ($src->card->country) { + $img = picto_from_langcode($src->card->country); + print $img?$img.' ':''; + print getCountry($src->card->country,1); + } else { + print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + } + } elseif ($src->object=='source' && $src->type=='sepa_debit') { + print 'info sepa'; + print ''; + if ($src->sepa_debit->country) { + $img = picto_from_langcode($src->sepa_debit->country); + print $img?$img.' ':''; + print getCountry($src->sepa_debit->country,1); + } else { + print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + } + } + print 'id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"';} -print'>'; + if (($action == 'add_paiement' && $src->id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { + print'class="opacitymedium"'; + } + print'>'; if (($customerstripe->default_source==$src->id)) { print ""; } print '
getStripeCustomerAccount($facture->socid)!=$source) { print'class="opacitymedium"';} - print'>global->STRIPE_EXTERNAL_ACCOUNT && $action == 'add_paiement')) { - print ' checked'; - } elseif ($action == 'add_paiement' && $conf->global->STRIPE_EXTERNAL_ACCOUNT!=$source) { - print ' disabled'; - } - print '>getStripeCustomerAccount($facture->socid)!=$source) { print'class="opacitymedium"';} - print '>getStripeCustomerAccount($facture->socid)!=$source) { + print'class="opacitymedium"'; + } + print'>global->STRIPE_EXTERNAL_ACCOUNT && $action == 'add_paiement')) { + print ' checked'; + } elseif ($action == 'add_paiement' && $conf->global->STRIPE_EXTERNAL_ACCOUNT!=$source) { + print ' disabled'; + } + print '>getStripeCustomerAccount($facture->socid)!=$source) { + print'class="opacitymedium"'; + } + print '>getStripeCustomerAccount($facture->socid)!=$source) { print'class="opacitymedium"';} - print'>'.$langs->trans('sold'); - print'id!=$source) { print'class="opacitymedium"';} - print'>'; + print 'getStripeCustomerAccount($facture->socid)!=$source) { + print'class="opacitymedium"'; + } + print'>'.$langs->trans('sold'); + print'id!=$source) { + print'class="opacitymedium"'; + } + print'>'; - print 'id!=$source) { print'class="opacitymedium"';} - print'>'; - // if (($customer->default_source!=$src->id)) { - // print img_picto($langs->trans("Disabled"),'off'); - // } else { - // print img_picto($langs->trans("Default"),'on'); - // } - print '
'.$langs->trans("None").'
id!=$source) { + print'class="opacitymedium"'; + } + print'>'; + //if (($customer->default_source!=$src->id)) { + // print img_picto($langs->trans("Disabled"),'off'); + //} else { + // print img_picto($langs->trans("Default"),'on'); + //} + print '
'.$langs->trans("None").'
"; + print ""; /* @@ -756,14 +762,14 @@ print ''; $sql.= ' f.datef as df, f.fk_soc as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; } $sql.= ' WHERE f.entity = '.$conf->entity; $sql.= ' AND (f.fk_soc = '.$facture->socid; - if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) { + if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) { $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; } @@ -1023,10 +1029,11 @@ print ''; $preselectedchoice=$addwarning?'no':'yes'; print '
'; - if (!empty($totalpayment)) $text=$langs->trans('ConfirmCustomerPayment',$totalpayment,$langs->trans("Currency".$conf->currency)); - if (!empty($multicurrency_totalpayment)) - { - $text.='
'.$langs->trans('ConfirmCustomerPayment',$multicurrency_totalpayment,$langs->trans("paymentInInvoiceCurrency")); + if (!empty($totalpayment)) { + $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency)); + } + if (!empty($multicurrency_totalpayment)) { + $text.='
'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency")); } if (GETPOST('closepaidinvoices')) { diff --git a/htdocs/stripe/transaction.php b/htdocs/stripe/transaction.php index 415ed32a62a..af40eaa42c9 100644 --- a/htdocs/stripe/transaction.php +++ b/htdocs/stripe/transaction.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2018 PtibogXIV + * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +26,9 @@ require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; +if (! empty($conf->accounting->enabled)) { + require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe')); @@ -77,25 +80,26 @@ $stripeaccount = $stripe->getStripeAccount($service); if (! $rowid) { - print '
'; - if ($optioncss != '') - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + if ($optioncss != '') { + print ''; + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; $title=$langs->trans("StripeTransactionList"); $title.=($stripeaccount?' (Stripe connection with Stripe OAuth Connect account '.$stripeaccount.')':' (Stripe connection with keys from Stripe module setup)'); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit); - print '
'; - print '' . "\n"; + print '
'; + print '
' . "\n"; - print ''; + print ''; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder); //print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder); //print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder); @@ -105,9 +109,9 @@ if (! $rowid) { print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", 'align="right"'); - print "\n"; + print "\n"; - print "\n"; + print "\n"; if ($stripeaccount) { @@ -155,14 +159,14 @@ if (! $rowid) { $societestatic->email = $obj->email; $societestatic->societe_id = $obj->fk_soc; - print ''; + print ''; // Ref - print "\n"; + print "\n"; // Stripe customer - //print "\n"; + //print "\n"; // Link - /*print "\n";*/ + print "\n";*/ // Origine - print "\n"; + print "\n"; // Date payment - print '\n"; + print '\n"; // Type - print ''; + print ''; // Amount - print ""; - print ""; + print ""; + print ""; // Status - print "'; - print "\n"; + print ''; + print "\n"; } - print "
" . $txn->source . "" . $txn->source . "".$charge->customer."".$charge->customer.""; + /*print ""; if ($societestatic->id > 0) { print $societestatic->getNomUrl(1); @@ -171,37 +175,37 @@ if (! $rowid) { { print $memberstatic->getNomUrl(1); } - print ""; + print ""; print $FULLTAG; if ($charge->metadata->source=="order"){ $object = new Commande($db); $object->fetch($charge->metadata->idsource); - print "".img_picto('', 'object_order')." ".$object->ref.""; - } elseif ($charge->metadata->source=="invoice"){ + print "".img_picto('', 'object_order')." ".$object->ref.""; + } elseif ($charge->metadata->source=="invoice") { $object = new Facture($db); $object->fetch($charge->metadata->idsource); - print "".img_picto('', 'object_invoice')." ".$object->ref.""; + print "".img_picto('', 'object_invoice')." ".$object->ref.""; } - print "' . dol_print_date($txn->created, '%d/%m/%Y %H:%M') . "' . dol_print_date($txn->created, '%d/%m/%Y %H:%M') . "' . $txn->type . '' . $txn->type . '" . price(($txn->amount) / 100) . "" . price(($txn->fee) / 100) . "" . price(($txn->amount) / 100) . "" . price(($txn->fee) / 100) . ""; + print ""; print $txn->status; - print '
"; - print '
'; - print '
'; -} else {} + print ""; + print ''; + print ''; +} // End of page llxFooter();