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