payout.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* Copyright (C) 2018-2023 Thibault FOUCART <support@ptibogxiv.net>
  3. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. // Put here all includes required by your class file
  19. // Load Dolibarr environment
  20. require '../main.inc.php';
  21. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  22. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  23. require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  24. //require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  28. if (isModEnabled('accounting')) {
  29. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  30. }
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
  33. // Security check
  34. $socid = GETPOST("socid", "int");
  35. if ($user->socid) {
  36. $socid = $user->socid;
  37. }
  38. //$result = restrictedArea($user, 'salaries', '', '', '');
  39. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  40. $rowid = GETPOST("rowid", 'alpha');
  41. $sortfield = GETPOST('sortfield', 'aZ09comma');
  42. $sortorder = GETPOST('sortorder', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. if (empty($page) || $page == -1) {
  45. $page = 0;
  46. } // If $page is not defined, or '' or -1
  47. $offset = $limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. $optioncss = GETPOST('optioncss', 'alpha');
  51. $param = "";
  52. $num = 0;
  53. $result = restrictedArea($user, 'banque');
  54. /*
  55. * View
  56. */
  57. $form = new Form($db);
  58. $acc = new Account($db);
  59. $stripe = new Stripe($db);
  60. llxHeader('', $langs->trans("StripePayoutList"));
  61. if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
  62. $service = 'StripeTest';
  63. $servicestatus = '0';
  64. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  65. } else {
  66. $service = 'StripeLive';
  67. $servicestatus = '1';
  68. }
  69. $stripeacc = $stripe->getStripeAccount($service);
  70. /*if (empty($stripeaccount))
  71. {
  72. print $langs->trans('ErrorStripeAccountNotDefined');
  73. }*/
  74. $moreforfilter = '';
  75. $totalnboflines = -1;
  76. if (!$rowid) {
  77. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  78. if ($optioncss != '') {
  79. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  80. }
  81. print '<input type="hidden" name="token" value="'.newToken().'">';
  82. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  83. print '<input type="hidden" name="action" value="list">';
  84. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  85. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  86. print '<input type="hidden" name="page" value="'.$page.'">';
  87. $title = $langs->trans("StripePayoutList");
  88. $title .= ($stripeacc ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
  89. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
  90. print '<div class="div-table-responsive">';
  91. print '<table class="tagtable liste'.(!empty($moreforfilter) ? " listwithfilterbefore" : "").'">'."\n";
  92. print '<tr class="liste_titre">';
  93. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  94. print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
  95. print_liste_field_titre("DateOperation", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
  96. print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
  97. print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
  98. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
  99. print "</tr>\n";
  100. print "</tr>\n";
  101. try {
  102. if ($stripeacc) {
  103. $payout = \Stripe\Payout::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
  104. } else {
  105. $payout = \Stripe\Payout::all(array("limit" => $limit));
  106. }
  107. foreach ($payout->data as $payout) {
  108. print '<tr class="oddeven">';
  109. // Ref
  110. if (!empty($stripeacc)) {
  111. $connect = $stripeacc.'/';
  112. } else $connect = null;
  113. $url = 'https://dashboard.stripe.com/'.$connect.'test/payouts/'.$payout->id;
  114. if ($servicestatus) {
  115. $url = 'https://dashboard.stripe.com/'.$connect.'payouts/'.$payout->id;
  116. }
  117. print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$payout->id."</a></td>\n";
  118. // Date payment
  119. print '<td class="center">'.dol_print_date($payout->created, 'dayhour')."</td>\n";
  120. // Date payment
  121. print '<td class="center">'.dol_print_date($payout->arrival_date, 'dayhour')."</td>\n";
  122. // Type
  123. print '<td>'.$payout->description.'</td>';
  124. // Amount
  125. print '<td class="right"><span class="amount">'.price(($payout->amount) / 100, 0, '', 1, -1, -1, strtoupper($payout->currency))."</span></td>";
  126. // Status
  127. print "<td class='right'>";
  128. if ($payout->status == 'paid') {
  129. print img_picto($langs->trans($payout->status), 'statut4');
  130. } elseif ($payout->status == 'pending') {
  131. print img_picto($langs->trans($payout->status), 'statut7');
  132. } elseif ($payout->status == 'in_transit') {
  133. print img_picto($langs->trans($payout->status), 'statut7');
  134. } elseif ($payout->status == 'failed') {
  135. print img_picto($langs->trans($payout->status), 'statut7');
  136. } elseif ($payout->status == 'canceled') {
  137. print img_picto($langs->trans($payout->status), 'statut8');
  138. }
  139. print '</td>';
  140. print "</tr>\n";
  141. }
  142. } catch (Exception $e) {
  143. print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
  144. }
  145. print "</table>";
  146. print '</div>';
  147. print '</form>';
  148. }
  149. // End of page
  150. llxFooter();
  151. $db->close();