dolibarr  16.0.5
transaction.php
1 <?php
2 /* Copyright (C) 2018-2019 Thibault FOUCART <support@ptibogxiv.net>
3  * Copyright (C) 2018-2021 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 
19 // Put here all includes required by your class file
20 
21 require '../main.inc.php';
22 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
23 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
24 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
25 //require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
26 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
29 if (!empty($conf->accounting->enabled)) {
30  require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
31 }
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
35 
36 // Security check
37 $socid = GETPOST("socid", "int");
38 if ($user->socid) {
39  $socid = $user->socid;
40 }
41 //$result = restrictedArea($user, 'salaries', '', '', '');
42 
43 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
44 $rowid = GETPOST("rowid", 'alpha');
45 $sortfield = GETPOST('sortfield', 'aZ09comma');
46 $sortorder = GETPOST('sortorder', 'aZ09comma');
47 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
48 if (empty($page) || $page == -1) {
49  $page = 0;
50 } // If $page is not defined, or '' or -1
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 $optioncss = GETPOST('optioncss', 'alpha');
55 
56 $result = restrictedArea($user, 'banque');
57 
58 
59 /*
60  * View
61  */
62 
63 $form = new Form($db);
64 $societestatic = new Societe($db);
65 $memberstatic = new Adherent($db);
66 $acc = new Account($db);
67 $stripe = new Stripe($db);
68 
69 llxHeader('', $langs->trans("StripeTransactionList"));
70 
71 if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
72  $service = 'StripeTest';
73  $servicestatus = '0';
74  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
75 } else {
76  $service = 'StripeLive';
77  $servicestatus = '1';
78 }
79 $stripeacc = $stripe->getStripeAccount($service);
80 /*if (empty($stripeaccount))
81 {
82  print $langs->trans('ErrorStripeAccountNotDefined');
83 }*/
84 
85 if (!$rowid) {
86  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
87  if ($optioncss != '') {
88  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
89  }
90  print '<input type="hidden" name="token" value="'.newToken().'">';
91  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
92  print '<input type="hidden" name="action" value="list">';
93  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
94  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
95  print '<input type="hidden" name="page" value="'.$page.'">';
96 
97  $title = $langs->trans("StripeTransactionList");
98  $title .= ($stripeaccount ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
99 
100  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
101 
102  print '<div class="div-table-responsive">';
103  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
104 
105  print '<tr class="liste_titre">';
106  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
107  //print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
108  //print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
109  //print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
110  print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
111  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
112  print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
113  print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
114  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
115  print "</tr>\n";
116 
117  try {
118  if ($stripeacc) {
119  $txn = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
120  } else {
121  $txn = \Stripe\BalanceTransaction::all(array("limit" => $limit));
122  }
123 
124  foreach ($txn->data as $txn) {
125  //$charge = $txn;
126  //var_dump($txn);
127 
128  // The metadata FULLTAG is defined by the online payment page
129  /*$FULLTAG=$charge->metadata->FULLTAG;
130 
131  // Save into $tmparray all metadata
132  $tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
133  // Load origin object according to metadata
134  if (! empty($tmparray['CUS']))
135  {
136  $societestatic->fetch($tmparray['CUS']);
137  }
138  else
139  {
140  $societestatic->id = 0;
141  }
142  if (! empty($tmparray['MEM']))
143  {
144  $memberstatic->fetch($tmparray['MEM']);
145  }
146  else
147  {
148  $memberstatic->id = 0;
149  }*/
150 
151  $societestatic->fetch($charge->metadata->idcustomer);
152  $societestatic->id = $charge->metadata->idcustomer;
153  $societestatic->lastname = $obj->lastname;
154  $societestatic->firstname = $obj->firstname;
155  $societestatic->admin = $obj->admin;
156  $societestatic->login = $obj->login;
157  $societestatic->email = $obj->email;
158  $societestatic->societe_id = $obj->fk_soc;
159 
160  print '<tr class="oddeven">';
161 
162  // Ref
163  if (!empty($stripeacc)) {
164  $connect = $stripeacc.'/';
165  }
166 
167  // Ref
168  if (preg_match('/po_/i', $txn->source)) {
169  $origin = "payouts";
170  } elseif (preg_match('/fee_/i', $txn->source)) {
171  $origin = "connect/application_fees";
172  } else {
173  $origin = "payments";
174  }
175 
176  $url = 'https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
177  if ($servicestatus) {
178  $url = 'https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
179  }
180  if ($txn->type == 'stripe_fee' || $txn->type == 'reserve_transaction') {
181  print "<td>".$txn->type."</td>";
182  } else {
183  print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$txn->source."</a></td>\n";
184  }
185 
186  // Stripe customer
187  //print "<td>".$charge->customer."</td>\n";
188  // Link
189  /*print "<td>";
190  if ($societestatic->id > 0) {
191  print $societestatic->getNomUrl(1);
192  }
193  if ($memberstatic->id > 0) {
194  print $memberstatic->getNomUrl(1);
195  }
196  print "</td>\n";*/
197  // Origine
198  //print "<td>";
200  // $object = new Commande($db);
201  // $object->fetch($charge->metadata->dol_id);
202  // print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
203  //} elseif ($charge->metadata->dol_type=="invoice"){
204  // $object = new Facture($db);
205  // $object->fetch($charge->metadata->dol_id);
206  // print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
207  //}
208  //print "</td>\n";
209  // Date payment
210  print '<td class="center">'.dol_print_date($txn->created, 'dayhour')."</td>\n";
211  // Type
212  print '<td>'.$txn->type.'</td>';
213  // Amount
214  print '<td class="right"><span class="amount">'.price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</span></td>";
215  print '<td class="right"><span class="amount">'.price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</span></td>";
216  // Status
217  print "<td class='right'>";
218  if ($txn->status == 'available') {
219  print img_picto($langs->trans("".$txn->status.""), 'statut4');
220  } elseif ($txn->status == 'pending') {
221  print img_picto($langs->trans("".$txn->status.""), 'statut7');
222  } elseif ($txn->status == 'failed') {
223  print img_picto($langs->trans("".$txn->status.""), 'statut8');
224  }
225  print '</td>';
226  print "</tr>\n";
227  }
228  } catch (Exception $e) {
229  print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
230  }
231  print "</table>";
232  print '</div>';
233  print '</form>';
234 }
235 
236 // End of page
237 llxFooter();
238 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
Exception
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_htmloutput_mesg
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
Definition: functions.lib.php:8299
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
Stripe
Stripe class.
Definition: stripe.class.php:29
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Account
Class to manage bank accounts.
Definition: account.class.php:38