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