payout.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. /* Copyright (C) 2018-2019 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. require '../main.inc.php';
  20. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  21. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  22. require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  23. //require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  27. if (!empty($conf->accounting->enabled)) {
  28. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  29. }
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
  32. // Security check
  33. $socid = GETPOST("socid", "int");
  34. if ($user->socid) {
  35. $socid = $user->socid;
  36. }
  37. //$result = restrictedArea($user, 'salaries', '', '', '');
  38. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  39. $rowid = GETPOST("rowid", 'alpha');
  40. $sortfield = GETPOST('sortfield', 'aZ09comma');
  41. $sortorder = GETPOST('sortorder', 'aZ09comma');
  42. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  43. if (empty($page) || $page == -1) {
  44. $page = 0;
  45. } // If $page is not defined, or '' or -1
  46. $offset = $limit * $page;
  47. $pageprev = $page - 1;
  48. $pagenext = $page + 1;
  49. $result = restrictedArea($user, 'banque');
  50. /*
  51. * View
  52. */
  53. $form = new Form($db);
  54. $societestatic = new Societe($db);
  55. $memberstatic = new Adherent($db);
  56. $acc = new Account($db);
  57. $stripe = new Stripe($db);
  58. llxHeader('', $langs->trans("StripePayoutList"));
  59. if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
  60. $service = 'StripeTest';
  61. $servicestatus = '0';
  62. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  63. } else {
  64. $service = 'StripeLive';
  65. $servicestatus = '1';
  66. }
  67. $stripeacc = $stripe->getStripeAccount($service);
  68. /*if (empty($stripeaccount))
  69. {
  70. print $langs->trans('ErrorStripeAccountNotDefined');
  71. }*/
  72. if (!$rowid) {
  73. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  74. if ($optioncss != '') {
  75. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  76. }
  77. print '<input type="hidden" name="token" value="'.newToken().'">';
  78. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  79. print '<input type="hidden" name="action" value="list">';
  80. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  81. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  82. print '<input type="hidden" name="page" value="'.$page.'">';
  83. $title = $langs->trans("StripePayoutList");
  84. $title .= ($stripeaccount ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
  85. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
  86. print '<div class="div-table-responsive">';
  87. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  88. print '<tr class="liste_titre">';
  89. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  90. //print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
  91. //print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  92. //print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  93. print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
  94. print_liste_field_titre("DateOperation", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
  95. print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
  96. print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
  97. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
  98. print "</tr>\n";
  99. print "</tr>\n";
  100. try {
  101. if ($stripeacc) {
  102. $payout = \Stripe\Payout::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
  103. } else {
  104. $payout = \Stripe\Payout::all(array("limit" => $limit));
  105. }
  106. foreach ($payout->data as $payout) {
  107. //$charge = $payout;
  108. //var_dump($payout);
  109. // The metadata FULLTAG is defined by the online payment page
  110. /*$FULLTAG=$charge->metadata->FULLTAG;
  111. // Save into $tmparray all metadata
  112. $tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
  113. // Load origin object according to metadata
  114. if (! empty($tmparray['CUS']))
  115. {
  116. $societestatic->fetch($tmparray['CUS']);
  117. }
  118. else
  119. {
  120. $societestatic->id = 0;
  121. }
  122. if (! empty($tmparray['MEM']))
  123. {
  124. $memberstatic->fetch($tmparray['MEM']);
  125. }
  126. else
  127. {
  128. $memberstatic->id = 0;
  129. }*/
  130. $societestatic->fetch($charge->metadata->idcustomer);
  131. $societestatic->id = $charge->metadata->idcustomer;
  132. $societestatic->lastname = $obj->lastname;
  133. $societestatic->firstname = $obj->firstname;
  134. $societestatic->admin = $obj->admin;
  135. $societestatic->login = $obj->login;
  136. $societestatic->email = $obj->email;
  137. $societestatic->socid = $obj->fk_soc;
  138. print '<tr class="oddeven">';
  139. // Ref
  140. if (!empty($stripeacc)) {
  141. $connect = $stripeacc.'/';
  142. }
  143. $url = 'https://dashboard.stripe.com/'.$connect.'test/payouts/'.$payout->id;
  144. if ($servicestatus) {
  145. $url = 'https://dashboard.stripe.com/'.$connect.'payouts/'.$payout->id;
  146. }
  147. print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$payout->id."</a></td>\n";
  148. // Stripe customer
  149. //print "<td>".$charge->customer."</td>\n";
  150. // Link
  151. /*print "<td>";
  152. if ($societestatic->id > 0)
  153. {
  154. print $societestatic->getNomUrl(1);
  155. }
  156. if ($memberstatic->id > 0)
  157. {
  158. print $memberstatic->getNomUrl(1);
  159. }
  160. print "</td>\n";*/
  161. // Origine
  162. //print "<td>";
  163. ////if ($charge->metadata->dol_type=="order"){
  164. // $object = new Commande($db);
  165. // $object->fetch($charge->metadata->dol_id);
  166. // print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
  167. //} elseif ($charge->metadata->dol_type=="invoice"){
  168. // $object = new Facture($db);
  169. // $object->fetch($charge->metadata->dol_id);
  170. // print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
  171. //}
  172. //print "</td>\n";
  173. // Date payment
  174. print '<td class="center">'.dol_print_date($payout->created, 'dayhour')."</td>\n";
  175. // Date payment
  176. print '<td class="center">'.dol_print_date($payout->arrival_date, 'dayhour')."</td>\n";
  177. // Type
  178. print '<td>'.$payout->description.'</td>';
  179. // Amount
  180. print '<td class="right"><span class="amount">'.price(($payout->amount) / 100, 0, '', 1, -1, -1, strtoupper($payout->currency))."</span></td>";
  181. // Status
  182. print "<td class='right'>";
  183. if ($payout->status == 'paid') {
  184. print img_picto($langs->trans("".$payout->status.""), 'statut4');
  185. } elseif ($payout->status == 'pending') {
  186. print img_picto($langs->trans("".$payout->status.""), 'statut7');
  187. } elseif ($payout->status == 'in_transit') {
  188. print img_picto($langs->trans("".$payout->status.""), 'statut7');
  189. } elseif ($payout->status == 'failed') {
  190. print img_picto($langs->trans("".$payout->status.""), 'statut7');
  191. } elseif ($payout->status == 'canceled') {
  192. print img_picto($langs->trans("".$payout->status.""), 'statut8');
  193. }
  194. print '</td>';
  195. print "</tr>\n";
  196. }
  197. } catch (Exception $e) {
  198. print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
  199. }
  200. print "</table>";
  201. print '</div>';
  202. print '</form>';
  203. }
  204. // End of page
  205. llxFooter();
  206. $db->close();