dolibarr/scripts/accountancy/export-thirdpartyaccount.php

261 lines
8.6 KiB
PHP
Raw Normal View History

Better Travis CI NEW: Cleaned up routines for better readability of both declaration and results. PHP versions now really covered. The old code forced install of PHP and didn't use Travis provided versions. This resulted in the process not being executed with the declared PHP version. Dropped MySQL in favor of MariaDB. This is now the FLOSS community standard. This should help avoid problems with buggy MySQL releases. Fast finish enabled to show results faster. Optimized tools installation with composer. The right version of the tool is installed for the PHP version under test. New PHP linter to check for syntax errors. Parallelized for better speed. Apache + PHP FPM for testing webservices. The previous mod_php configuration was not supported on Travis. New global DEBUG environment variable to show verbose output with configuration files content. IRC notification on #dolibarr@freenode for community awareness. FIXES: Bug in scripts preventing execution with environmentalized PHP. Wrong detection of MAIN_URL_ROOT under specific circumstances. $_SERVER["DOCUMENT_ROOT"] empty and $_SERVER["SCRIPT_NAME"] populated. Relative ignore directive in coding style ruleset to avoid bypassing test. Unit test errors without an exit status. This prevented the CI from properly detecting and reporting the error. TODOS: PostgreSQL support. This one is tricky since we only have a MySQL dump and the syntax is not directly compatible. SQLite support. Disabled in core at the moment. Nginx + PHP FPM support. Test webservices on the second most popular webserver. Run dev/* checks. We have a nice collection of scripts we could leverage. Check Javascript. Check CSS. Check SQL.
2015-12-11 05:08:32 +01:00
#!/usr/bin/env php
<?php
2018-09-09 09:36:12 +02:00
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
2019-01-28 21:39:22 +01:00
* Copyright (C) 2013-2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
2018-09-09 09:36:12 +02:00
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
2014-08-27 07:03:42 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2014-08-27 07:03:42 +02:00
*/
/**
2019-12-15 10:02:20 +01:00
* \file scripts/accountancy/export-thirdpartyaccount.php
2014-08-28 06:30:01 +02:00
* \ingroup Accounting Expert
2014-08-30 06:46:42 +02:00
* \brief Page to detect empty accounting account
2014-08-27 07:03:42 +02:00
*/
2021-03-01 00:22:36 +01:00
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
2020-10-27 01:44:00 +01:00
$path = __DIR__.'/';
2018-07-26 11:57:25 +02:00
require_once $path."../../htdocs/master.inc.php";
2014-08-30 06:46:42 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
2014-08-27 07:03:42 +02:00
$langs->loadLangs(array("companies", "compta", "main", "accountancy"));
2014-08-27 07:03:42 +02:00
// Security check
2021-03-01 00:22:36 +01:00
if (!$user->admin) {
accessforbidden();
2021-03-01 00:22:36 +01:00
}
2014-09-02 20:00:10 +02:00
2014-08-30 06:46:42 +02:00
// Date range
2014-08-27 07:03:42 +02:00
$year = GETPOST("year");
if (empty($year)) {
$year_current = strftime("%Y", dol_now());
$month_current = strftime("%m", dol_now());
$year_start = $year_current;
} else {
$year_current = $year;
$month_current = strftime("%m", dol_now());
$year_start = $year;
}
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
// Quarter
2021-03-01 00:22:36 +01:00
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
2014-08-27 07:03:42 +02:00
$q = GETPOST("q") ? GETPOST("q") : 0;
if ($q == 0) {
// We define date_start and date_end
$year_end = $year_start;
$month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
if (!GETPOST('month')) {
if (!GETPOST("year") && $month_start > $month_current) {
$year_start--;
$year_end--;
2014-08-27 07:03:42 +02:00
}
$month_end = $month_start - 1;
2021-03-01 00:22:36 +01:00
if ($month_end < 1) {
2014-08-27 07:03:42 +02:00
$month_end = 12;
2021-03-01 00:22:36 +01:00
} else {
$year_end++;
}
} else {
$month_end = $month_start;
}
2014-08-27 07:03:42 +02:00
$date_start = dol_get_first_day($year_start, $month_start, false);
$date_end = dol_get_last_day($year_end, $month_end, false);
}
if ($q == 1) {
$date_start = dol_get_first_day($year_start, 1, false);
$date_end = dol_get_last_day($year_start, 3, false);
}
if ($q == 2) {
$date_start = dol_get_first_day($year_start, 4, false);
$date_end = dol_get_last_day($year_start, 6, false);
}
if ($q == 3) {
$date_start = dol_get_first_day($year_start, 7, false);
$date_end = dol_get_last_day($year_start, 9, false);
}
if ($q == 4) {
$date_start = dol_get_first_day($year_start, 10, false);
$date_end = dol_get_last_day($year_start, 12, false);
}
}
/*
* Main
*/
2014-08-27 07:03:42 +02:00
llxHeader();
$form = new Form($db);
$nomlink = '';
$periodlink = '';
$exportlink = '';
$nom = $langs->trans("ReportThirdParty");
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
2014-08-27 07:03:42 +02:00
$description = $langs->trans("DescThirdPartyReport");
$builddate = dol_now();
2014-08-27 07:03:42 +02:00
$moreparam = array('action' => '');
2014-09-02 20:00:10 +02:00
report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam);
2014-08-27 07:03:42 +02:00
print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
print '
<script type="text/javascript">
2014-08-30 06:46:42 +02:00
function launch_export()
{
2014-08-27 07:03:42 +02:00
$("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
$("div.fiche div.tabBar form input[type=\"submit\"]").click();
2014-08-30 06:46:42 +02:00
$("div.fiche div.tabBar form input[name=\"action\"]").val();
2014-08-27 07:03:42 +02:00
}
</script>';
$sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town";
if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
$sql .= ", spe.accountancy_code_customer as compta";
} else {
$sql .= ", s.code_compta";
}
$sql .= ", s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , f.datec , f.fk_soc , cp.label as country ";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
}
$sql .= ", ".MAIN_DB_PREFIX."facture as f";
$sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
2014-08-27 07:03:42 +02:00
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid";
2021-03-01 00:22:36 +01:00
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'";
2021-03-01 00:22:36 +01:00
}
$sql .= " AND f.entity IN (".getEntity('invoice', 0).")";
2021-04-26 15:44:24 +02:00
if ($socid > 0) {
$sql .= " AND f.fk_soc = ".((int) $socid);
2021-03-01 00:22:36 +01:00
}
2014-08-27 07:03:42 +02:00
$sql .= " GROUP BY name";
$sql .= ")";
$sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, , ";
if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
$sql .= ", spe.accountancy_code_supplier as compta";
} else {
$sql .= ", s.code_compta_fournisseur as compta";
}
2014-08-27 07:03:42 +02:00
$sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax , ff.datec , ff.fk_soc , cp.label as country ";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
}
$sql .= ", ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
2014-08-27 07:03:42 +02:00
$sql .= " WHERE ff.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid";
2021-03-01 00:22:36 +01:00
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'";
2021-03-01 00:22:36 +01:00
}
$sql .= " AND ff.entity = ".$conf->entity;
2021-04-26 15:44:24 +02:00
if ($socid > 0) {
$sql .= " AND f.fk_soc = ".((int) $socid);
2021-03-01 00:22:36 +01:00
}
2014-08-27 07:03:42 +02:00
$sql .= " GROUP BY name";
$sql .= ")";
$sql .= "ORDER BY name ASC";
dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql='.$sql);
2014-08-27 07:03:42 +02:00
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
2014-09-02 20:00:10 +02:00
2014-08-27 07:03:42 +02:00
// export csv
if (GETPOST('action', 'aZ09') == 'export_csv') {
2014-08-27 07:03:42 +02:00
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=export_csv.csv');
2014-09-02 20:00:10 +02:00
2014-08-27 07:03:42 +02:00
$obj = $db->fetch_object($resql);
2014-09-02 20:00:10 +02:00
print '"'.$obj->compta.'",';
print '"'.$obj->address.'",';
print '"'.$obj->zip.'",';
print '"'.$obj->town.'",';
print '"'.$obj->country.'",';
print '"'.$obj->phone.'",';
print '"'.$obj->fax.'",';
2014-08-27 07:03:42 +02:00
print "\n";
$i++;
2014-08-27 07:03:42 +02:00
}
2014-09-02 20:00:10 +02:00
2014-08-27 07:03:42 +02:00
$thirdpartystatic = new Societe($db);
2014-09-02 20:00:10 +02:00
2014-08-27 07:03:42 +02:00
print '<br><br>';
2014-09-02 20:00:10 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
2014-08-27 07:03:42 +02:00
print "</table>\n";
print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
print '</tr><tr><td colspan=2>';
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="left">'.$langs->trans("ThirdParties").'</td>';
print '<td class="left">'.$langs->trans("AccountNumber").'</td>';
print '<td class="left">'.$langs->trans("RaisonSociale").'</td>';
print '<td class="left">'.$langs->trans("Address").'</td>';
print '<td class="left">'.$langs->trans("Zip").'</td>';
print '<td class="left">'.$langs->trans("Town").'</td>';
print '<td class="left">'.$langs->trans("Country").'</td>';
print '<td class="left">'.$langs->trans("Contact").'</td>';
print '<td class="left">'.$langs->trans("Phone").'</td>';
print '<td class="left">'.$langs->trans("Fax").'</td></tr>';
2014-09-02 20:00:10 +02:00
2021-03-01 00:22:36 +01:00
while ($obj = $db->fetch_object($resql)) {
2018-04-22 20:57:43 +02:00
print '<tr class="oddeven">';
2014-08-27 07:03:42 +02:00
print '<td>';
$thirdpartystatic->id = $obj->rowid;
$thirdpartystatic->name = $obj->name;
$thirdpartystatic->client = $obj->client;
$thirdpartystatic->canvas = $obj->canvas;
$thirdpartystatic->status = $obj->status;
print $thirdpartystatic->getNomUrl(1);
print '</td>';
print '<td class="left">'.$obj->compta.'</td>'."\n";
2019-01-21 10:14:14 +01:00
print '<td class="left"></td>';
print '<td class="left">'.$obj->address.'</td>';
print '<td class="left">'.$obj->zip.'</td>';
print '<td class="left">'.$obj->town.'</td>';
print '<td class="left">'.$obj->country.'</td>';
2019-01-21 10:14:14 +01:00
print '<td class="left"></td>';
print '<td class="left">'.$obj->phone.'</td>';
print '<td class="left">'.$obj->fax.'</td>';
2014-08-27 07:03:42 +02:00
print "</tr>\n";
2014-09-02 20:00:10 +02:00
$i++;
2014-08-27 07:03:42 +02:00
}
2014-09-02 20:00:10 +02:00
2014-08-27 07:03:42 +02:00
print "</table>";
$db->free($resql);
} else {
dol_print_error($db);
}
llxFooter();
2014-09-18 14:32:50 +02:00
$db->close();