From 6afd4e67e96b0648091910be3197e15d40e47b93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Apr 2018 23:46:56 +0200 Subject: [PATCH 1/4] Fix error in sources->retrieve when a stripeaccount is defined --- htdocs/stripe/class/stripe.class.php | 6 +- htdocs/stripe/payment.php | 235 ++++++++++++++------------- 2 files changed, 124 insertions(+), 117 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 2fbaa261665..3b53b4572f0 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -217,7 +217,7 @@ class Stripe extends CommonObject //$sql.= " AND sa.entity IN (".getEntity('societe').")"; $sql.= " AND sa.type = 'card'"; - dol_syslog(get_class($this) . "::fetch search stripe card id for paymentmode id=".$object->id, LOG_DEBUG); + dol_syslog(get_class($this) . "::fetch search stripe card id for paymentmode id=".$object->id.", stripeacc=".$stripeacc, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -225,13 +225,15 @@ class Stripe extends CommonObject { $obj = $this->db->fetch_object($resql); $cardref = $obj->stripe_card_ref; + dol_syslog("*************".$cardref); if ($cardref) { try { if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage $card = $cu->sources->retrieve($cardref); } else { - $card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc)); + //$card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc)); // this API fails when array stripe_account is provided + $card = $cu->sources->retrieve($cardref); } } catch(Exception $e) diff --git a/htdocs/stripe/payment.php b/htdocs/stripe/payment.php index 0b124ea9929..7e551965df7 100644 --- a/htdocs/stripe/payment.php +++ b/htdocs/stripe/payment.php @@ -240,42 +240,43 @@ if (empty($reshook)) if ($action == 'confirm_paiement' && $confirm == 'yes') { - $error=0; + $error=0; - $datepaye = dol_now(); + $datepaye = dol_now(); - $db->begin(); + $db->begin(); - // Clean parameters amount if payment is for a credit note - if (GETPOST('type') == 2) - { - foreach ($amounts as $key => $value) // How payment is dispatch - { - $newvalue = price2num($value,'MT'); - $amounts[$key] = -$newvalue; - } + // Clean parameters amount if payment is for a credit note + if (GETPOST('type') == 2) + { + foreach ($amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value,'MT'); + $amounts[$key] = -$newvalue; + } foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch - { - $newvalue = price2num($value,'MT'); - $multicurrency_amounts[$key] = -$newvalue; - } - } + { + $newvalue = price2num($value,'MT'); + $multicurrency_amounts[$key] = -$newvalue; + } + } - if (! empty($conf->banque->enabled)) - { - // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement - if (GETPOST('accountid') <= 0) - { - setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors'); - $error++; - } - } -$facture = new Facture($db); -$facture->fetch($facid); -$facture->fetch_thirdparty(); + if (! empty($conf->banque->enabled)) + { + // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement + if (GETPOST('accountid') <= 0) + { + setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors'); + $error++; + } + } - $error = 0; + $facture = new Facture($db); + $facture->fetch($facid); + $facture->fetch_thirdparty(); + + $error = 0; if (is_object($stripe) && $stripeacc) { @@ -286,56 +287,60 @@ $facture->fetch_thirdparty(); } } -$stripeamount=0; - foreach ($amounts as $key => $value) // How payment is dispatch - { -$stripeamount+=price2num($value,'MT'); -} + $stripeamount=0; + foreach ($amounts as $key => $value) // How payment is dispatch + { + $stripeamount+=price2num($value,'MT'); + } -if (preg_match('/acct_/i',$source)) -{ -$paiementcode ="VIR"; -} -elseif (preg_match('/card_/i',$source)) -{ -$paiementcode ="CB"; -} -elseif (preg_match('/src_/i',$source)) -{ -$customer2 = \Stripe\Customer::retrieve($customer->id,array("stripe_account" => $stripe->getStripeAccount($entity))); -$src = $customer2->sources->retrieve("$source"); -if ($src->type=='card'){ -$paiementcode ="CB"; -} -} -$societe = new Societe($db); -$societe->fetch($facture->socid); - dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); + if (preg_match('/acct_/i',$source)) + { + $paiementcode ="VIR"; + } + elseif (preg_match('/card_/i',$source)) + { + $paiementcode ="CB"; + } + elseif (preg_match('/src_/i',$source)) + { + $stripeacc = $stripe->getStripeAccount($entity); + $customer2 = \Stripe\Customer::retrieve($customer->id, array("stripe_account" => $stripeacc)); + //$src = $customer2->sources->retrieve("$source", array("stripe_account" => $stripeacc)); // this API fails when array stripe_account is provided + $src = $customer2->sources->retrieve("$source"); + if ($src->type=='card') + { + $paiementcode ="CB"; + } + } -$charge=$stripe->CreatePaymentStripe($stripeamount,"EUR","invoice",$facid,$source,$customer->id,$stripe->getStripeAccount($conf->entity)); + $societe = new Societe($db); + $societe->fetch($facture->socid); + dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); - if (!$error) - { - // Creation of payment line - $paiement = new Paiement($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array with all payments dispatching - $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = dol_getIdFromCode($db,$paiementcode,'c_paiement'); - $paiement->num_paiement = $charge->message; - $paiement->note = GETPOST('comment'); - } + $charge=$stripe->CreatePaymentStripe($stripeamount,"EUR","invoice",$facid,$source,$customer->id,$stripe->getStripeAccount($conf->entity)); - if (! $error) - { + if (!$error) + { + // Creation of payment line + $paiement = new Paiement($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array with all payments dispatching + $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching + $paiement->paiementid = dol_getIdFromCode($db,$paiementcode,'c_paiement'); + $paiement->num_paiement = $charge->message; + $paiement->note = GETPOST('comment'); + } - $paiement_id = $paiement->create($user, 0); - if ($paiement_id < 0) - { - setEventMessages($paiement->error, $paiement->errors, 'errors'); - $error++; - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($facture->lines)) + if (! $error) + { + + $paiement_id = $paiement->create($user, 0); + if ($paiement_id < 0) + { + setEventMessages($paiement->error, $paiement->errors, 'errors'); + $error++; + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($facture->lines)) { $outputlangs = $langs; $newlang = ''; @@ -349,53 +354,53 @@ $charge=$stripe->CreatePaymentStripe($stripeamount,"EUR","invoice",$facid,$sourc $ret = $facture->fetch($facid); // Reload to get new records $facture->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } + } - if (! $error) - { - $label='(CustomerInvoicePayment)'; - if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)'; - $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),'',''); - if ($result < 0) - { - setEventMessages($paiement->error, $paiement->errors, 'errors'); - $error++; - } - elseif (GETPOST('closepaidinvoices')=='on') { - $facture->set_paid($user); - } - } + if (! $error) + { + $label='(CustomerInvoicePayment)'; + if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)'; + $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),'',''); + if ($result < 0) + { + setEventMessages($paiement->error, $paiement->errors, 'errors'); + $error++; + } + elseif (GETPOST('closepaidinvoices')=='on') { + $facture->set_paid($user); + } + } - if (! $error) - { - $db->commit(); + if (! $error) + { + $db->commit(); - // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card - $invoiceid=0; - foreach ($paiement->amounts as $key => $amount) - { - $facid = $key; - if (is_numeric($amount) && $amount <> 0) - { - if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment - else $invoiceid=$facid; - } - } - if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid; - else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id; - header('Location: '.$loc); - exit; - } - else - { - $loc = dol_buildpath('/stripeconnect/payment.php?facid='.$facid.'&action=create&error='.$e->getMessage().'', 1); - $db->rollback(); - header('Location: '.$loc); - } + // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card + $invoiceid=0; + foreach ($paiement->amounts as $key => $amount) + { + $facid = $key; + if (is_numeric($amount) && $amount <> 0) + { + if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment + else $invoiceid=$facid; + } + } + if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid; + else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id; + header('Location: '.$loc); + exit; + } + else + { + $loc = dol_buildpath('/stripeconnect/payment.php?facid='.$facid.'&action=create&error='.$e->getMessage().'', 1); + $db->rollback(); + header('Location: '.$loc); + exit; + } } } From 9b57dadc18c013834560b0eaa86b7b5a98b0a411 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 21 Apr 2018 00:05:14 +0200 Subject: [PATCH 2/4] css --- htdocs/theme/eldy/style.css.php | 2 +- htdocs/theme/md/style.css.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 9a431c89fa8..93981a73c2e 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -3720,7 +3720,7 @@ table.dp { border-style:none; background-color:transparent; padding:0px; - font-size:9px; + font-size: 0.85em; border-width:0px; color:#0B63A2; vertical-align:middle; diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index f9b43f7c7db..5970ad6ef84 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -3659,7 +3659,7 @@ table.dp { border-style:none; background-color:transparent; padding:0px; - font-size:9px; + font-size: 0.85em; border-width:0px; color: #eee; vertical-align:middle; From 1031fcd79650c3b232a9dea11e1bfd054c98d80c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 21 Apr 2018 00:37:05 +0200 Subject: [PATCH 3/4] logs --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 53e6ed99469..ebb99385b64 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1984,6 +1984,7 @@ class Facture extends CommonInvoice $this->db->begin(); dol_syslog(get_class($this)."::set_paid rowid=".$this->id, LOG_DEBUG); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET'; $sql.= ' fk_statut='.self::STATUS_CLOSED; if (! $close_code) $sql.= ', paye=1'; @@ -1991,7 +1992,6 @@ class Facture extends CommonInvoice if ($close_note) $sql.= ", close_note='".$this->db->escape($close_note)."'"; $sql.= ' WHERE rowid = '.$this->id; - dol_syslog(get_class($this)."::set_paid", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { From f6743484dd758c1bb62c829ddaebd1b0b8961bc1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 21 Apr 2018 00:58:42 +0200 Subject: [PATCH 4/4] Better support of option COMPANY_AQUARIUM_CLEAN_REGEX --- htdocs/core/modules/societe/mod_codecompta_aquarium.php | 4 ++++ htdocs/langs/en_US/admin.lang | 2 ++ 2 files changed, 6 insertions(+) diff --git a/htdocs/core/modules/societe/mod_codecompta_aquarium.php b/htdocs/core/modules/societe/mod_codecompta_aquarium.php index 5bcf3c0f929..c237be0f91c 100644 --- a/htdocs/core/modules/societe/mod_codecompta_aquarium.php +++ b/htdocs/core/modules/societe/mod_codecompta_aquarium.php @@ -77,6 +77,10 @@ class mod_codecompta_aquarium extends ModeleAccountancyCode $texte.= ''; $texte.=$langs->trans("ModuleCompanyCodeCustomer".$this->name,$s2)."
\n"; $texte.=$langs->trans("ModuleCompanyCodeSupplier".$this->name,$s1)."
\n"; + $texte.="
\n"; + if (! isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || ! empty($conf->global->$conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) $texte.=$langs->trans('COMPANY_AQUARIUM_REMOVE_SPECIAL').' = '.yn(1)."
\n"; + //if (! empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) $texte.=$langs->trans('COMPANY_AQUARIUM_REMOVE_ALPHA').' = '.yn($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)."
\n"; + if (! empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) $texte.=$langs->trans('COMPANY_AQUARIUM_CLEAN_REGEX').' = '.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX."
\n"; $texte.= ''; $texte.= '  '; $texte.= ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 62f6194b267..1927008bad1 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1785,6 +1785,8 @@ SetToYesIfGroupIsComputationOfOtherGroups=Set this to yes if this group is a com EnterCalculationRuleIfPreviousFieldIsYes=Enter calculcation rule if previous field was set to Yes (For example 'CODEGRP1+CODEGRP2') SeveralLangugeVariatFound=Several language variants found WebDavServer=URL of %s server : %s +COMPANY_AQUARIUM_REMOVE_SPECIAL=Remove special characters +COMPANY_AQUARIUM_CLEAN_REGEX=Regex filter to clean value (COMPANY_AQUARIUM_CLEAN_REGEX) ##### Resource #### ResourceSetup=Configuration du module Resource UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list).