dolibarr  13.0.2
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 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("StripePayoutList"));
62 
63 if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
64  $service = 'StripeTest';
65  $servicestatus = '0';
66  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
67 } else {
68  $service = 'StripeLive';
69  $servicestatus = '1';
70 }
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 != '') {
81  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
82  }
83  print '<input type="hidden" name="token" value="'.newToken().'">';
84  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
85  print '<input type="hidden" name="action" value="list">';
86  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
87  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
88  print '<input type="hidden" name="page" value="'.$page.'">';
89 
90  $title = $langs->trans("StripePayoutList");
91  $title .= ($stripeaccount ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
92 
93  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
94 
95  print '<div class="div-table-responsive">';
96  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
97 
98  print '<tr class="liste_titre">';
99  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
100  //print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
101  //print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
102  //print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
103  print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
104  print_liste_field_titre("DateOperation", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
105  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
106  print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
107  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
108  print "</tr>\n";
109 
110  print "</tr>\n";
111 
112  try {
113  if ($stripeacc)
114  {
115  $payout = \Stripe\Payout::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
116  } else {
117  $payout = \Stripe\Payout::all(array("limit" => $limit));
118  }
119 
120  foreach ($payout->data as $payout)
121  {
122  //$charge = $payout;
123  //var_dump($payout);
124 
125  // The metadata FULLTAG is defined by the online payment page
126  /*$FULLTAG=$charge->metadata->FULLTAG;
127 
128  // Save into $tmparray all metadata
129  $tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
130  // Load origin object according to metadata
131  if (! empty($tmparray['CUS']))
132  {
133  $societestatic->fetch($tmparray['CUS']);
134  }
135  else
136  {
137  $societestatic->id = 0;
138  }
139  if (! empty($tmparray['MEM']))
140  {
141  $memberstatic->fetch($tmparray['MEM']);
142  }
143  else
144  {
145  $memberstatic->id = 0;
146  }*/
147 
148  $societestatic->fetch($charge->metadata->idcustomer);
149  $societestatic->id = $charge->metadata->idcustomer;
150  $societestatic->lastname = $obj->lastname;
151  $societestatic->firstname = $obj->firstname;
152  $societestatic->admin = $obj->admin;
153  $societestatic->login = $obj->login;
154  $societestatic->email = $obj->email;
155  $societestatic->socid = $obj->fk_soc;
156 
157  print '<tr class="oddeven">';
158 
159  // Ref
160  if (!empty($stripeacc)) $connect = $stripeacc.'/';
161 
162  $url = 'https://dashboard.stripe.com/'.$connect.'test/payouts/'.$payout->id;
163  if ($servicestatus) {
164  $url = 'https://dashboard.stripe.com/'.$connect.'payouts/'.$payout->id;
165  }
166 
167  print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$payout->id."</a></td>\n";
168 
169 
170  // Stripe customer
171  //print "<td>".$charge->customer."</td>\n";
172  // Link
173  /*print "<td>";
174  if ($societestatic->id > 0)
175  {
176  print $societestatic->getNomUrl(1);
177  }
178  if ($memberstatic->id > 0)
179  {
180  print $memberstatic->getNomUrl(1);
181  }
182  print "</td>\n";*/
183  // Origine
184  //print "<td>";
186  // $object = new Commande($db);
187  // $object->fetch($charge->metadata->dol_id);
188  // print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
189  //} elseif ($charge->metadata->dol_type=="invoice"){
190  // $object = new Facture($db);
191  // $object->fetch($charge->metadata->dol_id);
192  // print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
193  //}
194  //print "</td>\n";
195  // Date payment
196  print '<td class="center">'.dol_print_date($payout->created, '%d/%m/%Y %H:%M')."</td>\n";
197  // Date payment
198  print '<td class="center">'.dol_print_date($payout->arrival_date, '%d/%m/%Y %H:%M')."</td>\n";
199  // Type
200  print '<td>'.$payout->description.'</td>';
201  // Amount
202  print '<td class="right">'.price(($payout->amount) / 100, 0, '', 1, -1, -1, strtoupper($payout->currency))."</td>";
203  // Status
204  print "<td class='right'>";
205  if ($payout->status == 'paid') {
206  print img_picto($langs->trans("".$payout->status.""), 'statut4');
207  } elseif ($payout->status == 'pending') {
208  print img_picto($langs->trans("".$payout->status.""), 'statut7');
209  } elseif ($payout->status == 'in_transit') {
210  print img_picto($langs->trans("".$payout->status.""), 'statut7');
211  } elseif ($payout->status == 'failed') {
212  print img_picto($langs->trans("".$payout->status.""), 'statut7');
213  } elseif ($payout->status == 'canceled') {
214  print img_picto($langs->trans("".$payout->status.""), 'statut8');
215  }
216  print '</td>';
217  print "</tr>\n";
218  }
219  } catch (Exception $e) {
220  print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
221  }
222  print "</table>";
223  print '</div>';
224  print '</form>';
225 }
226 
227 // End of page
228 llxFooter();
229 $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