dolibarr  13.0.2
export-thirdpartyaccount.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
3 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
4  * Copyright (C) 2013-2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
5  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 if (!defined('NOSESSION')) define('NOSESSION', '1');
29 
30 $path = __DIR__.'/';
31 
32 require_once $path."../../htdocs/master.inc.php";
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 
36 $langs->loadLangs(array("companies", "compta", "main", "accountancy"));
37 
38 // Security check
39 if (!$user->admin)
41 
42 // Date range
43 $year = GETPOST("year");
44 if (empty($year)) {
45  $year_current = strftime("%Y", dol_now());
46  $month_current = strftime("%m", dol_now());
47  $year_start = $year_current;
48 } else {
49  $year_current = $year;
50  $month_current = strftime("%m", dol_now());
51  $year_start = $year;
52 }
53 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
54 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
55 
56 // Quarter
57 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
58 {
59  $q = GETPOST("q") ? GETPOST("q") : 0;
60  if ($q == 0) {
61  // We define date_start and date_end
62  $year_end = $year_start;
63  $month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
64  if (!GETPOST('month')) {
65  if (!GETPOST("year") && $month_start > $month_current) {
66  $year_start--;
67  $year_end--;
68  }
69  $month_end = $month_start - 1;
70  if ($month_end < 1)
71  $month_end = 12;
72  else $year_end++;
73  } else $month_end = $month_start;
74  $date_start = dol_get_first_day($year_start, $month_start, false);
75  $date_end = dol_get_last_day($year_end, $month_end, false);
76  }
77  if ($q == 1) {
78  $date_start = dol_get_first_day($year_start, 1, false);
79  $date_end = dol_get_last_day($year_start, 3, false);
80  }
81  if ($q == 2) {
82  $date_start = dol_get_first_day($year_start, 4, false);
83  $date_end = dol_get_last_day($year_start, 6, false);
84  }
85  if ($q == 3) {
86  $date_start = dol_get_first_day($year_start, 7, false);
87  $date_end = dol_get_last_day($year_start, 9, false);
88  }
89  if ($q == 4) {
90  $date_start = dol_get_first_day($year_start, 10, false);
91  $date_end = dol_get_last_day($year_start, 12, false);
92  }
93 } else {
94 }
95 
96 llxHeader();
97 
98 $form = new Form($db);
99 
100 $nomlink = '';
101 $periodlink = '';
102 $exportlink = '';
103 
104 $nom = $langs->trans("ReportThirdParty");
105 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
106 $description = $langs->trans("DescThirdPartyReport");
107 $builddate = dol_now();
108 
109 $moreparam = array('action' => '');
110 report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam);
111 
112 print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
113 
114 print '
115  <script type="text/javascript">
116  function launch_export()
117  {
118  $("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
119  $("div.fiche div.tabBar form input[type=\"submit\"]").click();
120  $("div.fiche div.tabBar form input[name=\"action\"]").val();
121  }
122 </script>';
123 
124 $sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta as compta , ";
125 $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country ";
126 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
127 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
128 $sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
129 $sql .= " WHERE f.fk_soc = s.rowid";
130 $sql .= " AND s.fk_pays = cp.rowid";
131 if (!empty($date_start) && !empty($date_end))
132  $sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'";
133 $sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
134 if ($socid)
135  $sql .= " AND f.fk_soc = ".$socid;
136 $sql .= " GROUP BY name";
137 $sql .= ")";
138 $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
139 $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , ff.datec , ff.fk_soc , cp.label as country ";
140 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
141 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as ff";
142 $sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
143 $sql .= " WHERE ff.fk_soc = s.rowid";
144 $sql .= " AND s.fk_pays = cp.rowid";
145 if (!empty($date_start) && !empty($date_end))
146  $sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'";
147 $sql .= " AND ff.entity = ".$conf->entity;
148 if ($socid)
149  $sql .= " AND f.fk_soc = ".$socid;
150 $sql .= " GROUP BY name";
151 $sql .= ")";
152 
153 $sql .= "ORDER BY name ASC";
154 
155 dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql='.$sql);
156 $resql = $db->query($sql);
157 if ($resql) {
158  $num = $db->num_rows($resql);
159  $i = 0;
160 
161  // export csv
162  if (GETPOST('action', 'aZ09') == 'export_csv') {
163  header('Content-Type: text/csv');
164  header('Content-Disposition: attachment;filename=export_csv.csv');
165 
166  $obj = $db->fetch_object($resql);
167 
168  print '"'.$obj->compta.'",';
169  print '"'.$obj->address.'",';
170  print '"'.$obj->zip.'",';
171  print '"'.$obj->town.'",';
172  print '"'.$obj->country.'",';
173  print '"'.$obj->phone.'",';
174  print '"'.$obj->fax.'",';
175  print "\n";
176  $i++;
177  }
178 
179  /*
180  * View
181  */
182 
183  $thirdpartystatic = new Societe($db);
184 
185  print '<br><br>';
186 
187  print '<table class="noborder centpercent">';
188  print "</table>\n";
189  print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
190  print '</tr><tr><td colspan=2>';
191  print '<table class="noborder centpercent">';
192  print '<tr class="liste_titre"><td class="left">'.$langs->trans("ThirdParties").'</td>';
193  print '<td class="left">'.$langs->trans("AccountNumber").'</td>';
194  print '<td class="left">'.$langs->trans("RaisonSociale").'</td>';
195  print '<td class="left">'.$langs->trans("Address").'</td>';
196  print '<td class="left">'.$langs->trans("Zip").'</td>';
197  print '<td class="left">'.$langs->trans("Town").'</td>';
198  print '<td class="left">'.$langs->trans("Country").'</td>';
199  print '<td class="left">'.$langs->trans("Contact").'</td>';
200  print '<td class="left">'.$langs->trans("Phone").'</td>';
201  print '<td class="left">'.$langs->trans("Fax").'</td></tr>';
202 
203  while ($obj = $db->fetch_object($resql))
204  {
205  print '<tr class="oddeven">';
206  print '<td>';
207  $thirdpartystatic->id = $obj->rowid;
208  $thirdpartystatic->name = $obj->name;
209  $thirdpartystatic->client = $obj->client;
210  $thirdpartystatic->canvas = $obj->canvas;
211  $thirdpartystatic->status = $obj->status;
212  print $thirdpartystatic->getNomUrl(1);
213  print '</td>';
214  print '<td class="left">'.$obj->compta.'</td>'."\n";
215  print '<td class="left"></td>';
216  print '<td class="left">'.$obj->address.'</td>';
217  print '<td class="left">'.$obj->zip.'</td>';
218  print '<td class="left">'.$obj->town.'</td>';
219  print '<td class="left">'.$obj->country.'</td>';
220  print '<td class="left"></td>';
221  print '<td class="left">'.$obj->phone.'</td>';
222  print '<td class="left">'.$obj->fax.'</td>';
223  print "</tr>\n";
224 
225  $i++;
226  }
227 
228  print "</table>";
229  $db->free($resql);
230 } else {
231  dol_print_error($db);
232 }
233 
234 llxFooter();
235 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
Definition: report.lib.php:41
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59