export-thirdpartyaccount.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?PHP
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2014 Alexandre Spangaro <alexandre.spangaro@fidurex.fr>
  4. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/accountancy/admin/export-thirdpartyaccount.php
  21. * \ingroup Accounting Expert
  22. * \brief Page to detect empty accounting account
  23. */
  24. require_once($path."../../htdocs/master.inc.php");
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  27. $langs->load("companies");
  28. $langs->load("compta");
  29. $langs->load("main");
  30. $langs->load("accountancy");
  31. // Security check
  32. if (!$user->admin)
  33. accessforbidden();
  34. // Date range
  35. $year = GETPOST("year");
  36. if (empty($year)) {
  37. $year_current = strftime("%Y", dol_now());
  38. $month_current = strftime("%m", dol_now());
  39. $year_start = $year_current;
  40. } else {
  41. $year_current = $year;
  42. $month_current = strftime("%m", dol_now());
  43. $year_start = $year;
  44. }
  45. $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
  46. $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
  47. // Quarter
  48. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  49. {
  50. $q = GETPOST("q") ? GETPOST("q") : 0;
  51. if ($q == 0) {
  52. // We define date_start and date_end
  53. $year_end = $year_start;
  54. $month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
  55. if (! GETPOST('month')) {
  56. if (! GETPOST("year") && $month_start > $month_current) {
  57. $year_start --;
  58. $year_end --;
  59. }
  60. $month_end = $month_start - 1;
  61. if ($month_end < 1)
  62. $month_end = 12;
  63. else
  64. $year_end ++;
  65. } else
  66. $month_end = $month_start;
  67. $date_start = dol_get_first_day($year_start, $month_start, false);
  68. $date_end = dol_get_last_day($year_end, $month_end, false);
  69. }
  70. if ($q == 1) {
  71. $date_start = dol_get_first_day($year_start, 1, false);
  72. $date_end = dol_get_last_day($year_start, 3, false);
  73. }
  74. if ($q == 2) {
  75. $date_start = dol_get_first_day($year_start, 4, false);
  76. $date_end = dol_get_last_day($year_start, 6, false);
  77. }
  78. if ($q == 3) {
  79. $date_start = dol_get_first_day($year_start, 7, false);
  80. $date_end = dol_get_last_day($year_start, 9, false);
  81. }
  82. if ($q == 4) {
  83. $date_start = dol_get_first_day($year_start, 10, false);
  84. $date_end = dol_get_last_day($year_start, 12, false);
  85. }
  86. } else {
  87. }
  88. llxHeader();
  89. $form = new Form($db);
  90. $nomlink = '';
  91. $periodlink = '';
  92. $exportlink = '';
  93. $nom = $langs->trans("ReportThirdParty");
  94. $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
  95. $description = $langs->trans("DescThirdPartyReport");
  96. $builddate = time();
  97. $moreparam=array('action' => '');
  98. report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam);
  99. print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
  100. print '
  101. <script type="text/javascript">
  102. function launch_export()
  103. {
  104. $("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
  105. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  106. $("div.fiche div.tabBar form input[name=\"action\"]").val();
  107. }
  108. </script>';
  109. $sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta as compta , ";
  110. $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country ";
  111. $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
  112. $sql .= ", " . MAIN_DB_PREFIX . "facture as f";
  113. $sql .= ", " . MAIN_DB_PREFIX . "c_country as cp";
  114. $sql .= " WHERE f.fk_soc = s.rowid";
  115. $sql .= " AND s.fk_pays = cp.rowid";
  116. if (! empty($date_start) && ! empty($date_end))
  117. $sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
  118. $sql .= " AND f.entity = " . $conf->entity;
  119. if ($socid)
  120. $sql .= " AND f.fk_soc = " . $socid;
  121. $sql .= " GROUP BY name";
  122. $sql .= ")";
  123. $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
  124. $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , ff.datec , ff.fk_soc , cp.label as country ";
  125. $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
  126. $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as ff";
  127. $sql .= ", " . MAIN_DB_PREFIX . "c_country as cp";
  128. $sql .= " WHERE ff.fk_soc = s.rowid";
  129. $sql .= " AND s.fk_pays = cp.rowid";
  130. if (! empty($date_start) && ! empty($date_end))
  131. $sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
  132. $sql .= " AND ff.entity = " . $conf->entity;
  133. if ($socid)
  134. $sql .= " AND f.fk_soc = " . $socid;
  135. $sql .= " GROUP BY name";
  136. $sql .= ")";
  137. $sql .= "ORDER BY name ASC";
  138. dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql=' . $sql);
  139. $resql = $db->query($sql);
  140. if ($resql) {
  141. $num = $db->num_rows($resql);
  142. $i = 0;
  143. // export csv
  144. if (GETPOST('action') == 'export_csv') {
  145. header('Content-Type: text/csv');
  146. header('Content-Disposition: attachment;filename=export_csv.csv');
  147. $obj = $db->fetch_object($resql);
  148. $var = ! $var;
  149. print '"' . $obj->compta . '",';
  150. print '"' . $obj->address . '",';
  151. print '"' . $obj->zip . '",';
  152. print '"' . $obj->town . '",';
  153. print '"' . $obj->country . '",';
  154. print '"' . $obj->phone . '",';
  155. print '"' . $obj->fax . '",';
  156. print "\n";
  157. $i ++;
  158. }
  159. /*
  160. * View
  161. */
  162. $thirdpartystatic = new Societe($db);
  163. print '<br><br>';
  164. print '<table class="noborder" width="100%">';
  165. print "</table>\n";
  166. print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
  167. print '</tr><tr><td colspan=2>';
  168. print '<table class="noborder" width="100%">';
  169. print '<tr class="liste_titre"><td align="left">' . $langs->trans("ThirdParties") . '</td>';
  170. print '<td align="left">' . $langs->trans("AccountNumber") . '</td>';
  171. print '<td align="left">' . $langs->trans("RaisonSociale") . '</td>';
  172. print '<td align="left">' . $langs->trans("Address") . '</td>';
  173. print '<td align="left">' . $langs->trans("Zip") . '</td>';
  174. print '<td align="left">' . $langs->trans("Town") . '</td>';
  175. print '<td align="left">' . $langs->trans("Country") . '</td>';
  176. print '<td align="left">' . $langs->trans("Contact") . '</td>';
  177. print '<td align="left">' . $langs->trans("Phone") . '</td>';
  178. print '<td align="left">' . $langs->trans("Fax") . '</td></tr>';
  179. $var = True;
  180. while ( $obj = $db->fetch_object($resql) ) {
  181. $var = ! $var;
  182. print "<tr $bc[$var]>";
  183. print '<td>';
  184. $thirdpartystatic->id = $obj->rowid;
  185. $thirdpartystatic->name = $obj->name;
  186. $thirdpartystatic->client = $obj->client;
  187. $thirdpartystatic->canvas = $obj->canvas;
  188. $thirdpartystatic->status = $obj->status;
  189. print $thirdpartystatic->getNomUrl(1);
  190. print '</td>';
  191. print '<td align="left">' . $obj->compta . '</td>' . "\n";
  192. print '<td align="left"></td>';
  193. print '<td align="left">' . $obj->address . '</td>';
  194. print '<td align="left">' . $obj->zip . '</td>';
  195. print '<td align="left">' . $obj->town . '</td>';
  196. print '<td align="left">' . $obj->country . '</td>';
  197. print '<td align="left"></td>';
  198. print '<td align="left">' . $obj->phone . '</td>';
  199. print '<td align="left">' . $obj->fax . '</td>';
  200. print "</tr>\n";
  201. $i ++;
  202. }
  203. print "</table>";
  204. $db->free($resql);
  205. } else {
  206. dol_print_error($db);
  207. }
  208. llxFooter();
  209. $db->close();