dolibarr  x.y.z
payout.php
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 
19 // Put here all includes required by your class file
20 
21 // Load Dolibarr environment
22 require '../main.inc.php';
23 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
24 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
25 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
26 //require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30 if (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 = GETPOST("socid", "int");
39 if ($user->socid) {
40  $socid = $user->socid;
41 }
42 //$result = restrictedArea($user, 'salaries', '', '', '');
43 
44 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
45 $rowid = GETPOST("rowid", 'alpha');
46 $sortfield = GETPOST('sortfield', 'aZ09comma');
47 $sortorder = GETPOST('sortorder', 'aZ09comma');
48 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
49 if (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 
60 $result = restrictedArea($user, 'banque');
61 
62 
63 /*
64  * View
65  */
66 
67 $form = new Form($db);
68 $societestatic = new Societe($db);
69 $memberstatic = new Adherent($db);
70 $acc = new Account($db);
71 $stripe = new Stripe($db);
72 
73 llxHeader('', $langs->trans("StripePayoutList"));
74 
75 if (isModEnabled('stripe') && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
76  $service = 'StripeTest';
77  $servicestatus = '0';
78  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
79 } else {
80  $service = 'StripeLive';
81  $servicestatus = '1';
82 }
83 
84 $stripeacc = $stripe->getStripeAccount($service);
85 /*if (empty($stripeaccount))
86 {
87  print $langs->trans('ErrorStripeAccountNotDefined');
88 }*/
89 
90 if (!$rowid) {
91  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
92  if ($optioncss != '') {
93  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
94  }
95  print '<input type="hidden" name="token" value="'.newToken().'">';
96  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
97  print '<input type="hidden" name="action" value="list">';
98  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
99  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
100  print '<input type="hidden" name="page" value="'.$page.'">';
101 
102  $title = $langs->trans("StripePayoutList");
103  $title .= ($stripeacc ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
104 
105  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
106 
107  print '<div class="div-table-responsive">';
108  print '<table class="tagtable liste'.(!empty($moreforfilter) ? " listwithfilterbefore" : "").'">'."\n";
109 
110  print '<tr class="liste_titre">';
111  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
112  //print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
113  //print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
114  //print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
115  print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
116  print_liste_field_titre("DateOperation", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
117  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
118  print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
119  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
120  print "</tr>\n";
121 
122  print "</tr>\n";
123 
124  try {
125  if ($stripeacc) {
126  $payout = \Stripe\Payout::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
127  } else {
128  $payout = \Stripe\Payout::all(array("limit" => $limit));
129  }
130 
131  foreach ($payout->data as $payout) {
132  //$charge = $payout;
133  //var_dump($payout);
134 
135  // The metadata FULLTAG is defined by the online payment page
136  /*$FULLTAG=$charge->metadata->FULLTAG;
137 
138  // Save into $tmparray all metadata
139  $tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
140  // Load origin object according to metadata
141  if (!empty($tmparray['CUS']))
142  {
143  $societestatic->fetch($tmparray['CUS']);
144  }
145  else
146  {
147  $societestatic->id = 0;
148  }
149  if (!empty($tmparray['MEM']))
150  {
151  $memberstatic->fetch($tmparray['MEM']);
152  }
153  else
154  {
155  $memberstatic->id = 0;
156  }*/
157 
158  $societestatic->fetch($charge->metadata->idcustomer);
159  $societestatic->id = $charge->metadata->idcustomer;
160  $societestatic->lastname = $obj->lastname;
161  $societestatic->firstname = $obj->firstname;
162  $societestatic->admin = $obj->admin;
163  $societestatic->login = $obj->login;
164  $societestatic->email = $obj->email;
165  $societestatic->socid = $obj->fk_soc;
166 
167  print '<tr class="oddeven">';
168 
169  // Ref
170  if (!empty($stripeacc)) {
171  $connect = $stripeacc.'/';
172  }
173 
174  $url = 'https://dashboard.stripe.com/'.$connect.'test/payouts/'.$payout->id;
175  if ($servicestatus) {
176  $url = 'https://dashboard.stripe.com/'.$connect.'payouts/'.$payout->id;
177  }
178 
179  print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$payout->id."</a></td>\n";
180 
181 
182  // Stripe customer
183  //print "<td>".$charge->customer."</td>\n";
184  // Link
185  /*print "<td>";
186  if ($societestatic->id > 0)
187  {
188  print $societestatic->getNomUrl(1);
189  }
190  if ($memberstatic->id > 0)
191  {
192  print $memberstatic->getNomUrl(1);
193  }
194  print "</td>\n";*/
195  // Origine
196  //print "<td>";
198  // $object = new Commande($db);
199  // $object->fetch($charge->metadata->dol_id);
200  // print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
201  //} elseif ($charge->metadata->dol_type=="invoice"){
202  // $object = new Facture($db);
203  // $object->fetch($charge->metadata->dol_id);
204  // print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
205  //}
206  //print "</td>\n";
207  // Date payment
208  print '<td class="center">'.dol_print_date($payout->created, 'dayhour')."</td>\n";
209  // Date payment
210  print '<td class="center">'.dol_print_date($payout->arrival_date, 'dayhour')."</td>\n";
211  // Type
212  print '<td>'.$payout->description.'</td>';
213  // Amount
214  print '<td class="right"><span class="amount">'.price(($payout->amount) / 100, 0, '', 1, -1, -1, strtoupper($payout->currency))."</span></td>";
215  // Status
216  print "<td class='right'>";
217  if ($payout->status == 'paid') {
218  print img_picto($langs->trans($payout->status), 'statut4');
219  } elseif ($payout->status == 'pending') {
220  print img_picto($langs->trans($payout->status), 'statut7');
221  } elseif ($payout->status == 'in_transit') {
222  print img_picto($langs->trans($payout->status), 'statut7');
223  } elseif ($payout->status == 'failed') {
224  print img_picto($langs->trans($payout->status), 'statut7');
225  } elseif ($payout->status == 'canceled') {
226  print img_picto($langs->trans($payout->status), 'statut8');
227  }
228  print '</td>';
229  print "</tr>\n";
230  }
231  } catch (Exception $e) {
232  print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
233  }
234  print "</table>";
235  print '</div>';
236  print '</form>';
237 }
238 
239 // End of page
240 llxFooter();
241 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
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.