From bb5dd734a9ea9c9d553762e44a22b8f204e4fc5e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Mon, 5 Aug 2019 23:34:28 +0200 Subject: [PATCH 1/7] Balance Stripe connect account for supplier --- htdocs/societe/paymentmodes.php | 92 +++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 4f525330e79..d0a67aa6448 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -788,10 +788,8 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' $permissiontowrite = $user->rights->societe->creer; // Stripe customer key 'cu_....' stored into llx_societe_account print ''; - //print $langs->trans('StripeCustomerId'); print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', 0, 2, 'socid'); print ''; - //print $stripecu; print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid'); if (! empty($conf->stripe->enabled) && $stripecu && $action != 'editkey_account') { @@ -817,6 +815,60 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; } } + + if ($object->fournisseur && $conf->global->MAIN_FEATURES_LEVEL >= 2) + { + print ''; + print $langs->trans('SupplierCode').''; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print ''; + $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid; + $resql=$db->query($sql); + if (!$resql) dol_print_error($db); + $obj = $db->fetch_object($resql); + $nbFactsClient = $obj->nb; + $thirdTypeArray['customer']=$langs->trans("customer"); + if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal']=$langs->transnoentitiesnoconv('Proposals'); + if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); + if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); + if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); + + if (! empty($conf->stripe->enabled) && ! empty($conf->stripeconnect->enabled)) + { + $permissiontowrite = $user->rights->societe->creer; + $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here) + + // Stripe customer key 'cu_....' stored into llx_societe_account + print ''; + print $form->editfieldkey("StripeSupplierId", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', 0, 2, 'socid'); + print ''; + print $form->editfieldval("StripeSupplierId", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid'); + if (! empty($conf->stripe->enabled) && $stripesupplieracc && $action != 'editkey_account') + { + $connect=''; + + $url='https://dashboard.stripe.com/test/'.$stripesupplieracc; + if ($servicestatus) + { + $url='https://dashboard.stripe.com/'.$stripesupplieracc; + } + print ' '.img_picto($langs->trans('ShowInStripe'), 'object_globe').''; + } + print ''; + if (empty($stripesupplieracc)) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + //print ''; + print '
'; + } + print ''; + } + } print ''; print ''; @@ -826,7 +878,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print '
'; // List of Stripe payment modes - if (! (empty($conf->stripe->enabled))) + if (! (empty($conf->stripe->enabled)) && $object->client) { $morehtmlright=''; if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) @@ -1188,11 +1240,41 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } print ""; print ""; + print '
'; } - + + // List of Stripe payment modes + if (! empty($conf->stripe->enabled) && ! empty($conf->stripeconnect->enabled) && $object->fournisseur && ! empty($stripesupplieracc)) + { + print load_fiche_titre($langs->trans('StripeBalance').($stripesupplieracc?' (Stripe connection with StripeConnect account '.$stripesupplieracc.')':' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, ''); + $balance = \Stripe\Balance::retrieve(array("stripe_account" => $stripesupplieracc)); + print ''."\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + + if (is_array($balance->available) && count($balance->available)) + { + foreach ($balance->available as $cpt) + { + print ''; + } + } + + if (is_array($balance->pending) && count($balance->pending)) + { + foreach ($balance->pending as $cpt) + { + print ''; + } + } + print '
'.$langs->trans('Status').''.$langs->trans('Amount').''.$langs->trans('Currency').'
'.$langs->trans("Available").''.price($cpt->amount, 0, '', 1, - 1, - 1, strtoupper($cpt->currency)).' '.$langs->trans("Currency".strtoupper($cpt->currency)).'
'.$langs->trans("Pending").''.price($cpt->amount, 0, '', 1, - 1, - 1, strtoupper($cpt->currency)).' '.$langs->trans("Currency".strtoupper($cpt->currency)).'
'; + print '
'; + } // List of bank accounts - print '
'; $morehtmlright= dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=create'); From de5872db6d812e63d6a0c1372c18d87be4df6555 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 6 Aug 2019 00:12:49 +0200 Subject: [PATCH 2/7] Update paymentmodes.php --- htdocs/societe/paymentmodes.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index d0a67aa6448..23d259fd2e1 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -868,7 +868,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } print ''; } - } + } print ''; print ''; @@ -1252,7 +1252,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; print ''.$langs->trans('Status').''; print ''.$langs->trans('Amount').''; - print ''.$langs->trans('Currency').''; + print ''.$langs->trans('Currency').''; print ''; if (is_array($balance->available) && count($balance->available)) @@ -1260,19 +1260,19 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' foreach ($balance->available as $cpt) { print ''.$langs->trans("Available").''.price($cpt->amount, 0, '', 1, - 1, - 1, strtoupper($cpt->currency)).' '.$langs->trans("Currency".strtoupper($cpt->currency)).''; - } - } + } + } if (is_array($balance->pending) && count($balance->pending)) { foreach ($balance->pending as $cpt) { print ''.$langs->trans("Pending").''.price($cpt->amount, 0, '', 1, - 1, - 1, strtoupper($cpt->currency)).' '.$langs->trans("Currency".strtoupper($cpt->currency)).''; - } + } } print ''; print '
'; - } + } // List of bank accounts From 0fafeab7641664fbd7f03532c74bd26d17bcdc62 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 6 Aug 2019 13:08:34 +0200 Subject: [PATCH 3/7] Update paymentmodes.php --- htdocs/societe/paymentmodes.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 23d259fd2e1..2b0dd39dc83 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -816,7 +816,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } } - if ($object->fournisseur && $conf->global->MAIN_FEATURES_LEVEL >= 2) + if ($object->fournisseur) { print ''; print $langs->trans('SupplierCode').''; @@ -833,8 +833,9 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); - - if (! empty($conf->stripe->enabled) && ! empty($conf->stripeconnect->enabled)) + } + + if (! empty($conf->stripe->enabled) && ! empty($conf->stripeconnect->enabled) && $conf->global->MAIN_FEATURES_LEVEL >= 2) { $permissiontowrite = $user->rights->societe->creer; $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here) @@ -868,7 +869,6 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } print ''; } - } print ''; print ''; From 2585f7232aa0b517ada76eaa0be150959f6fe92e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 6 Aug 2019 13:09:56 +0200 Subject: [PATCH 4/7] Update paymentmodes.php --- htdocs/societe/paymentmodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 2b0dd39dc83..e6ec4643e37 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -844,7 +844,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; print $form->editfieldkey("StripeSupplierId", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', 0, 2, 'socid'); print ''; - print $form->editfieldval("StripeSupplierId", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid'); + print $form->editfieldval("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid'); if (! empty($conf->stripe->enabled) && $stripesupplieracc && $action != 'editkey_account') { $connect=''; From 944943dcc0752b9664e004425b6cd41eb0f0fe72 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 6 Aug 2019 13:10:40 +0200 Subject: [PATCH 5/7] Update paymentmodes.php --- htdocs/societe/paymentmodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index e6ec4643e37..1b5fb26a5d2 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -842,7 +842,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' // Stripe customer key 'cu_....' stored into llx_societe_account print ''; - print $form->editfieldkey("StripeSupplierId", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', 0, 2, 'socid'); + print $form->editfieldkey("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', 0, 2, 'socid'); print ''; print $form->editfieldval("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid'); if (! empty($conf->stripe->enabled) && $stripesupplieracc && $action != 'editkey_account') From d0f6d1f17515664c0572d1daeed0d7e893afec8e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 6 Aug 2019 13:12:10 +0200 Subject: [PATCH 6/7] Update paymentmodes.php --- htdocs/societe/paymentmodes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 1b5fb26a5d2..1bbd60a577f 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -849,10 +849,10 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { $connect=''; - $url='https://dashboard.stripe.com/test/'.$stripesupplieracc; + $url='https://dashboard.stripe.com/test/connect/accounts/'.$stripesupplieracc; if ($servicestatus) { - $url='https://dashboard.stripe.com/'.$stripesupplieracc; + $url='https://dashboard.stripe.com/connect/accounts/'.$stripesupplieracc; } print ' '.img_picto($langs->trans('ShowInStripe'), 'object_globe').''; } From 32d1c787fc26edd4623109c972511e075b4ce438 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sat, 10 Aug 2019 09:37:03 +0200 Subject: [PATCH 7/7] Update paymentmodes.php --- htdocs/societe/paymentmodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 1bbd60a577f..8e1ad71f5b0 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -838,7 +838,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' if (! empty($conf->stripe->enabled) && ! empty($conf->stripeconnect->enabled) && $conf->global->MAIN_FEATURES_LEVEL >= 2) { $permissiontowrite = $user->rights->societe->creer; - $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here) + $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here) // Stripe customer key 'cu_....' stored into llx_societe_account print '';