--- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_byratecountry.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_byratecountry.php @@ -3,2 +3 @@ - * Copyright (C) 2018-2021 Frédéric France - * Copyright (C) 2022 Alexandre Spangaro + * Copyright (C) 2018 Frédéric France @@ -25 +23,0 @@ -// Load Dolibarr environment @@ -48,3 +46,4 @@ -if (empty($year)) { - $year_current = dol_print_date(dol_now(), '%Y'); - $month_current = dol_print_date(dol_now(), '%m'); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -54 +53 @@ - $month_current = dol_print_date(dol_now(), '%m'); + $month_current = strftime("%m", dol_now()); @@ -57,3 +56,2 @@ -$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere - +$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); +$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); @@ -61,2 +59,2 @@ -$q = ''; -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ @@ -64 +62,2 @@ - if (empty($q)) { + if (empty($q)) + { @@ -66 +65 @@ - $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); @@ -69,2 +68,4 @@ - if (!GETPOST("month")) { // If month not forced - if (!GETPOST('year') && $month_start > $month_current) { + if (!GETPOST("month")) // If month not forced + { + if (!GETPOST('year') && $month_start > $month_current) + { @@ -75,5 +76,2 @@ - if ($month_end < 1) { - $month_end = 12; - } else { - $year_end++; - } + if ($month_end < 1) $month_end = 12; + else $year_end++; @@ -81,19 +79,8 @@ - $date_start = dol_get_first_day($year_start, $month_start, false); - $date_end = dol_get_last_day($year_end, $month_end, false); - } else { - 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); - } + $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false); + } + else + { + 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); } @@ -110,3 +97 @@ -if ($tmp_date_end < $date_end || $date_end < $date_start) { - $date_end = $tmp_date_end; -} +if ($tmp_date_end < $date_end || $date_end < $date_start) $date_end = $tmp_date_end; @@ -115,3 +100 @@ -if (empty($min)) { - $min = 0; -} +if (empty($min)) $min = 0; @@ -121,7 +104,3 @@ -$modetax = !getDolGlobalString('TAX_MODE') ? 0 : $conf->global->TAX_MODE; -if (GETPOSTISSET("modetax")) { - $modetax = GETPOST("modetax", 'int'); -} -if (empty($modetax)) { - $modetax = 0; -} +$modetax = $conf->global->TAX_MODE; +if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int'); +if (empty($modetax)) $modetax = 0; @@ -131,3 +110 @@ -if ($user->socid) { - $socid = $user->socid; -} +if ($user->socid) $socid = $user->socid; @@ -154,4 +131,3 @@ -foreach ($listofparams as $param) { - if (GETPOST($param) != '') { - $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param); - } +foreach ($listofparams as $param) +{ + if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param); @@ -162,2 +138 @@ -$exportlink=""; -$namelink=""; + @@ -167 +141,0 @@ -$fsearch = ''; @@ -177,9 +151,3 @@ -if ($modetax == 0) { - $calcmode = $langs->trans('OptionVATDefault'); -} -if ($modetax == 1) { - $calcmode = $langs->trans('OptionVATDebitOption'); -} -if ($modetax == 2) { - $calcmode = $langs->trans('OptionPaymentForProductAndServices'); -} +if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault'); +if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption'); +if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices'); @@ -188,5 +156,2 @@ -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$prevyear = $year_start; -$prevquarter = $q; +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +$prevyear = $year_start; $prevquarter = $q; @@ -196,5 +161,3 @@ - $prevquarter = 4; - $prevyear--; -} -$nextyear = $year_start; -$nextquarter = $q; + $prevquarter = 4; $prevyear--; +} +$nextyear = $year_start; $nextquarter = $q; @@ -204,4 +167,3 @@ - $nextquarter = 1; - $nextyear++; -} -$description = $fsearch; + $nextquarter = 1; $nextyear++; +} +$description .= $fsearch; @@ -210,16 +172,5 @@ -if (isModEnabled('comptabilite')) { - $description .= '
'.$langs->trans("ThisIsAnEstimatedValue"); -} -if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'invoice') { - $description .= '
'.$langs->trans("RulesVATDueProducts"); -} -if (getDolGlobalString('TAX_MODE_SELL_PRODUCT') == 'payment') { - $description .= '
'.$langs->trans("RulesVATInProducts"); -} -if (getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'invoice') { - $description .= '
'.$langs->trans("RulesVATDueServices"); -} -if (getDolGlobalString('TAX_MODE_SELL_SERVICE') == 'payment') { - $description .= '
'.$langs->trans("RulesVATInServices"); -} -if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { +if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description .= $langs->trans("RulesVATDueProducts"); +if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description .= $langs->trans("RulesVATInProducts"); +if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description .= '
'.$langs->trans("RulesVATDueServices"); +if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description .= '
'.$langs->trans("RulesVATInServices"); +if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -228,3 +179,2 @@ -if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { - $description .= $langs->trans("SupplierDepositsAreNotIncluded"); -} +if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .= '
'.$langs->trans("ThisIsAnEstimatedValue"); + @@ -239,0 +190,3 @@ +$namesup = $namecust; + + @@ -242,6 +195,2 @@ -if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -} -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} +if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES"; +if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES"; @@ -255,2 +204,2 @@ - $description .= '
'.$langs->trans("RulesCADue"); - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { + $description = $langs->trans("RulesCADue"); + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -261,3 +209,0 @@ - if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { - $description .= $langs->trans("SupplierDepositsAreNotIncluded"); - } @@ -266 +212,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -271 +219 @@ - $description .= $langs->trans("RulesCAIn"); + $description = $langs->trans("RulesCAIn"); @@ -275,11 +223,10 @@ -} elseif ($modecompta == "BOOKKEEPING") { -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { -} -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); -if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) { - $periodlink = ''.img_previous().' '.img_next().''; -} else { - $periodlink = ''; -} +} +elseif ($modecompta == "BOOKKEEPING") +{ +} +elseif ($modecompta == "BOOKKEEPINGCOLLECTED") +{ +} +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().' '.img_next().''; +else $periodlink = ''; @@ -291 +238,2 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ @@ -303,4 +251,2 @@ - $j = $i + (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); - if ($j > 12) { - $j -= 12; - } + $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); + if ($j > 12) $j -= 12; @@ -312 +257,0 @@ - // Sales invoices @@ -317 +262 @@ - $sql .= " SUM(".$db->ifsql("MONTH(f.datef)=".$i, "fd.total_ht", "0").") AS month".str_pad($i, 2, "0", STR_PAD_LEFT).","; + $sql .= " SUM(".$db->ifsql('MONTH(f.datef)='.$i, 'fd.total_ht', '0').") AS month".str_pad($i, 2, '0', STR_PAD_LEFT).","; @@ -327 +272 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -336 +281,2 @@ - dol_syslog("htdocs/compta/tva/index.php", LOG_DEBUG); + + dol_syslog("htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG); @@ -353,4 +299,2 @@ - $j = $i + (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); - if ($j > 12) { - $j -= 12; - } + $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); + if ($j > 12) $j -= 12; @@ -372,4 +316,2 @@ - $j = $i + (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); - if ($j > 12) { - $j -= 12; - } + $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); + if ($j > 12) $j -= 12; @@ -377 +319 @@ - print ''.price((empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j])).''; + print ''.price($totalpermonth[$j]).''; @@ -379 +321 @@ - print ''.price((empty($totalpermonth['total']) ? 0 : $totalpermonth['total'])).''; + print ''.price($totalpermonth['total']).''; @@ -383,0 +326 @@ + @@ -389,5 +332,4 @@ - while ($i < 12) { - $j = $i + (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); - if ($j > 12) { - $j -= 12; - } + while ($i < 12) + { + $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); + if ($j > 12) $j -= 12; @@ -399 +340,0 @@ - // Purchase invoices @@ -404 +345 @@ - $sql2 .= " SUM(".$db->ifsql("MONTH(ff.datef)=".$i, "ffd.total_ht", "0").") AS month".str_pad($i, 2, "0", STR_PAD_LEFT).","; + $sql2 .= " SUM(".$db->ifsql('MONTH(ff.datef)='.$i, 'ffd.total_ht', '0').") AS month".str_pad($i, 2, '0', STR_PAD_LEFT).","; @@ -414 +355 @@ - if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -424 +365 @@ - dol_syslog("htdocs/compta/tva/index.php", LOG_DEBUG); + dol_syslog("htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG); @@ -440,4 +381,2 @@ - $j = $i + (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); - if ($j > 12) { - $j -= 12; - } + $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); + if ($j > 12) $j -= 12; @@ -459,4 +398,2 @@ - $j = $i + (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); - if ($j > 12) { - $j -= 12; - } + $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START); + if ($j > 12) $j -= 12; @@ -464 +401 @@ - print ''.price(empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]).''; + print ''.price($totalpermonth[$j]).''; @@ -466 +403 @@ - print ''.price(empty($totalpermonth['total']) ? 0 : $totalpermonth['total']).''; + print ''.price($totalpermonth['total']).''; --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_cabyprodserv.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_cabyprodserv.php @@ -6 +5,0 @@ - * Copyright (C) 2022 Alexandre Spangaro @@ -27 +25,0 @@ -// Load Dolibarr environment @@ -41,9 +39,3 @@ -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); -} +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); @@ -53,12 +45,6 @@ -if (GETPOST("modecompta")) { - $modecompta = GETPOST("modecompta"); -} - -$sortorder = GETPOST("sortorder", 'aZ09comma'); -$sortfield = GETPOST("sortfield", 'aZ09comma'); -if (!$sortorder) { - $sortorder = "asc"; -} -if (!$sortfield) { - $sortfield = "ref"; -} +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta"); + +$sortorder = isset($_GET["sortorder"]) ? $_GET["sortorder"] : $_POST["sortorder"]; +$sortfield = isset($_GET["sortfield"]) ? $_GET["sortfield"] : $_POST["sortfield"]; +if (!$sortorder) $sortorder = "asc"; +if (!$sortfield) $sortfield = "ref"; @@ -73,2 +58,0 @@ -$categorie = new Categorie($db); - @@ -77,6 +61 @@ -if ($selected_type == '') { - $selected_type = -1; -} - -// Hook -$hookmanager->initHooks(array('cabyprodservlist')); +if ($selected_type == '') $selected_type = -1; @@ -93,3 +72,4 @@ -if (empty($year)) { - $year_current = dol_print_date(dol_now(), '%Y'); - $month_current = dol_print_date(dol_now(), '%m'); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -99 +79 @@ - $month_current = dol_print_date(dol_now(), '%m'); + $month_current = strftime("%m", dol_now()); @@ -102,2 +82,2 @@ -$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere +$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); +$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); @@ -105 +85,2 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ @@ -107 +88,2 @@ - if (empty($q)) { + if (empty($q)) + { @@ -109 +91 @@ - $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); @@ -112,2 +94,4 @@ - if (!GETPOST("month")) { // If month not forced - if (!GETPOST('year') && $month_start > $month_current) { + if (!GETPOST("month")) // If month not forced + { + if (!GETPOST('year') && $month_start > $month_current) + { @@ -118,5 +102,2 @@ - if ($month_end < 1) { - $month_end = 12; - } else { - $year_end++; - } + if ($month_end < 1) $month_end = 12; + else $year_end++; @@ -124,19 +105,8 @@ - $date_start = dol_get_first_day($year_start, $month_start, false); - $date_end = dol_get_last_day($year_end, $month_end, false); - } else { - 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); - } + $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false); + } + else + { + 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); } @@ -156,9 +126,3 @@ -if (!empty($modecompta)) { - $commonparams['modecompta'] = $modecompta; -} -if (!empty($sortorder)) { - $commonparams['sortorder'] = $sortorder; -} -if (!empty($sortfield)) { - $commonparams['sortfield'] = $sortfield; -} +if (!empty($modecompta)) $commonparams['modecompta'] = $modecompta; +if (!empty($sortorder)) $commonparams['sortorder'] = $sortorder; +if (!empty($sortfield)) $commonparams['sortfield'] = $sortfield; @@ -167,27 +131,9 @@ -if (!empty($date_startyear)) { - $headerparams['date_startyear'] = $date_startyear; -} -if (!empty($date_startmonth)) { - $headerparams['date_startmonth'] = $date_startmonth; -} -if (!empty($date_startday)) { - $headerparams['date_startday'] = $date_startday; -} -if (!empty($date_endyear)) { - $headerparams['date_endyear'] = $date_endyear; -} -if (!empty($date_endmonth)) { - $headerparams['date_endmonth'] = $date_endmonth; -} -if (!empty($date_endday)) { - $headerparams['date_endday'] = $date_endday; -} -if (!empty($year)) { - $headerparams['year'] = $year; -} -if (!empty($month)) { - $headerparams['month'] = $month; -} -if (!empty($q)) { - $headerparams['q'] = $q; -} +if (!empty($date_startyear)) $headerparams['date_startyear'] = $date_startyear; +if (!empty($date_startmonth)) $headerparams['date_startmonth'] = $date_startmonth; +if (!empty($date_startday)) $headerparams['date_startday'] = $date_startday; +if (!empty($date_endyear)) $headerparams['date_endyear'] = $date_endyear; +if (!empty($date_endmonth)) $headerparams['date_endmonth'] = $date_endmonth; +if (!empty($date_endday)) $headerparams['date_endday'] = $date_endday; +if (!empty($year)) $headerparams['year'] = $year; +if (!empty($month)) $headerparams['month'] = $month; +$headerparams['q'] = $q; @@ -196,9 +142,3 @@ -if (!empty($selected_cat)) { - $tableparams['search_categ'] = $selected_cat; -} -if (!empty($selected_soc)) { - $tableparams['search_soc'] = $selected_soc; -} -if (!empty($selected_type)) { - $tableparams['search_type'] = $selected_type; -} +if (!empty($selected_cat)) $tableparams['search_categ'] = $selected_cat; +if (!empty($selected_soc)) $tableparams['search_soc'] = $selected_soc; +if (!empty($selected_type)) $tableparams['search_type'] = $selected_type; @@ -212 +151,0 @@ -$paramslink=""; @@ -228,9 +167,2 @@ -if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -} -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} - -$exportlink=""; -$namelink=""; +if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES"; +if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES"; @@ -245 +177 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -249,0 +182 @@ + @@ -251 +184,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -260,12 +195,11 @@ -} elseif ($modecompta == "BOOKKEEPING") { -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { -} - -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) { - $periodlink = ''.img_previous().' '.img_next().''; -} else { - $periodlink = ''; -} +} +elseif ($modecompta == "BOOKKEEPING") +{ +} +elseif ($modecompta == "BOOKKEEPINGCOLLECTED") +{ +} + +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().' '.img_next().''; +else $periodlink = ''; @@ -275 +209,2 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ @@ -288 +223,2 @@ -if ($modecompta == 'CREANCES-DETTES') { +if ($modecompta == 'CREANCES-DETTES') +{ @@ -292,5 +227,0 @@ - - $parameters = array(); - $hookmanager->executeHooks('printFieldListSelect', $parameters); - $sql .= $hookmanager->resPrint; - @@ -298,4 +229,2 @@ - if ($selected_soc > 0) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc ON (soc.rowid = f.fk_soc)"; - } - $sql .= ",".MAIN_DB_PREFIX."facturedet as l"; + if ($selected_soc > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc ON (soc.rowid = f.fk_soc)"; + $sql .= ",".MAIN_DB_PREFIX."facturedet as l"; @@ -303 +232,2 @@ - if ($selected_cat === -2) { // Without any category + if ($selected_cat === -2) // Without any category + { @@ -306,5 +236,4 @@ - - $parameters = array(); - $hookmanager->executeHooks('printFieldListFrom', $parameters); - $sql .= $hookmanager->resPrint; - + elseif ($selected_cat) // Into a specific category + { + $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_product as cp"; + } @@ -314 +243 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -322,4 +251,6 @@ - if ($selected_type >= 0) { - $sql .= " AND l.product_type = ".((int) $selected_type); - } - if ($selected_cat === -2) { // Without any category + if ($selected_type >= 0) + { + $sql .= " AND l.product_type = ".$selected_type; + } + if ($selected_cat === -2) // Without any category + { @@ -327,25 +258,8 @@ - } elseif ($selected_cat > 0) { // Into a specific category - if ($subcat) { - $TListOfCats = $categorie->get_full_arbo('product', $selected_cat, 1); - - $listofcatsql = ""; - foreach ($TListOfCats as $key => $cat) { - if ($key !== 0) { - $listofcatsql .= ","; - } - $listofcatsql .= $cat['rowid']; - } - } - - $sql .= " AND (p.rowid IN "; - $sql .= " (SELECT fk_product FROM ".MAIN_DB_PREFIX."categorie_product cp WHERE "; - if ($subcat) { - $sql .= "cp.fk_categorie IN (".$db->sanitize($listofcatsql).")"; - } else { - $sql .= "cp.fk_categorie = ".((int) $selected_cat); - } - $sql .= "))"; - } - if ($selected_soc > 0) { - $sql .= " AND soc.rowid=".((int) $selected_soc); - } + } + elseif ($selected_cat) { // Into a specific category + $sql .= " AND (c.rowid = ".$selected_cat; + if ($subcat) $sql .= " OR c.fk_parent = ".$selected_cat; + $sql .= ")"; + $sql .= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid"; + } + if ($selected_soc > 0) $sql .= " AND soc.rowid=".$selected_soc; @@ -353,5 +266,0 @@ - - $parameters = array(); - $hookmanager->executeHooks('printFieldListWhere', $parameters); - $sql .= $hookmanager->resPrint; - @@ -387 +296,2 @@ - foreach ($headerparams as $key => $value) { + foreach ($headerparams as $key => $value) + { @@ -391,4 +301,4 @@ - $moreforfilter = ''; - - print '
'; - print ''."\n"; + $moreforfilter = ''; + + print '
'; + print '
'."\n"; @@ -399,2 +309 @@ - print img_picto('', 'category', 'class="paddingrightonly"'); - print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', 0, $langs->trans("Category")); + print $langs->trans("Category").': '.$formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', true); @@ -408,12 +317,11 @@ - // type filter (produit/service) - print ' '; - print $langs->trans("Type").': '; - $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', 1, 1, 1); - - //select thirdparty - print '
'; - print img_picto('', 'company', 'class="paddingrightonly"'); - print $form->select_thirdparty_list($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); - print ''; - - print ''; + + print ''; - - print ''; + print ''; @@ -461,0 +368,10 @@ + $classslink, + 'class="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans("AmountTTC"), + $_SERVER["PHP_SELF"], + "amount_ttc", + "", @@ -468 +384 @@ - $langs->trans("AmountTTC"), + $langs->trans("Percentage"), @@ -477,10 +392,0 @@ - print_liste_field_titre( - $langs->trans("Percentage"), - $_SERVER["PHP_SELF"], - "amount_ttc", - "", - $paramslink, - 'class="right"', - $sortfield, - $sortorder - ); @@ -490 +396 @@ - foreach ($name as $key => $value) { + foreach ($name as $key=>$value) { --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_cabyuser.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_cabyuser.php @@ -7 +6,0 @@ - * Copyright (C) 2022 Alexandre Spangaro @@ -28 +26,0 @@ -// Load Dolibarr environment @@ -40,10 +38,4 @@ -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); -} -$hookmanager->initHooks(['cabyuserreportlist']); +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); + @@ -52,12 +44,6 @@ -if (GETPOST("modecompta")) { - $modecompta = GETPOST("modecompta"); -} - -$sortorder = GETPOST("sortorder", 'aZ09comma'); -$sortfield = GETPOST("sortfield", 'aZ09comma'); -if (!$sortorder) { - $sortorder = "asc"; -} -if (!$sortfield) { - $sortfield = "name"; -} +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta"); + +$sortorder = isset($_GET["sortorder"]) ? $_GET["sortorder"] : $_POST["sortorder"]; +$sortfield = isset($_GET["sortfield"]) ? $_GET["sortfield"] : $_POST["sortfield"]; +if (!$sortorder) $sortorder = "asc"; +if (!$sortfield) $sortfield = "name"; @@ -66,12 +52,13 @@ -$year = GETPOST("year", 'int'); -$month = GETPOST("month", 'int'); -$date_startyear = GETPOST("date_startyear", 'int'); -$date_startmonth = GETPOST("date_startmonth", 'int'); -$date_startday = GETPOST("date_startday", 'int'); -$date_endyear = GETPOST("date_endyear", 'int'); -$date_endmonth = GETPOST("date_endmonth", 'int'); -$date_endday = GETPOST("date_endday", 'int'); -if (empty($year)) { - $year_current = dol_print_date(dol_now(), '%Y'); - $month_current = dol_print_date(dol_now(), '%m'); - $year_start = $year_current; +$year = GETPOST("year"); +$month = GETPOST("month"); +$date_startyear = GETPOST("date_startyear"); +$date_startmonth = GETPOST("date_startmonth"); +$date_startday = GETPOST("date_startday"); +$date_endyear = GETPOST("date_endyear"); +$date_endmonth = GETPOST("date_endmonth"); +$date_endday = GETPOST("date_endday"); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); + $year_start = $year_current; @@ -80 +67 @@ - $month_current = dol_print_date(dol_now(), '%m'); + $month_current = strftime("%m", dol_now()); @@ -83,2 +70,2 @@ -$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere +$date_start = dol_mktime(0, 0, 0, $_REQUEST["date_startmonth"], $_REQUEST["date_startday"], $_REQUEST["date_startyear"]); +$date_end = dol_mktime(23, 59, 59, $_REQUEST["date_endmonth"], $_REQUEST["date_endday"], $_REQUEST["date_endyear"]); @@ -86,3 +73,5 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end - $q = GETPOST("q") ? GETPOST("q") : 0; - if ($q == 0) { +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q = GETPOST("q") ?GETPOST("q") : 0; + if ($q == 0) + { @@ -90 +79 @@ - $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); @@ -93,2 +82,4 @@ - if (!GETPOST("month")) { // If month not forced - if (!GETPOST('year') && $month_start > $month_current) { + if (!GETPOST("month")) // If month not forced + { + if (!GETPOST('year') && $month_start > $month_current) + { @@ -99,5 +90,2 @@ - if ($month_end < 1) { - $month_end = 12; - } else { - $year_end++; - } + if ($month_end < 1) $month_end = 12; + else $year_end++; @@ -105,2 +93 @@ - $date_start = dol_get_first_day($year_start, $month_start, false); - $date_end = dol_get_last_day($year_end, $month_end, false); + $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false); @@ -108,17 +95,7 @@ - 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); - } -} else { + 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); } +} +else +{ @@ -140,21 +117,7 @@ -if (!empty($date_startyear)) { - $headerparams['date_startyear'] = $date_startyear; -} -if (!empty($date_startmonth)) { - $headerparams['date_startmonth'] = $date_startmonth; -} -if (!empty($date_startday)) { - $headerparams['date_startday'] = $date_startday; -} -if (!empty($date_endyear)) { - $headerparams['date_endyear'] = $date_endyear; -} -if (!empty($date_endmonth)) { - $headerparams['date_endmonth'] = $date_endmonth; -} -if (!empty($date_endday)) { - $headerparams['date_endday'] = $date_endday; -} -if (!empty($q)) { - $headerparams['q'] = $q; -} +$headerparams['date_startyear'] = $date_startyear; +$headerparams['date_startmonth'] = $date_startmonth; +$headerparams['date_startday'] = $date_startday; +$headerparams['date_endyear'] = $date_endyear; +$headerparams['date_endmonth'] = $date_endmonth; +$headerparams['date_endday'] = $date_endday; +$headerparams['q'] = $q; @@ -162,0 +126,2 @@ +$tableparams['search_categ'] = $selected_cat; +$tableparams['subcat'] = ($subcat === true) ? 'yes' : ''; @@ -169 +133,0 @@ -$paramslink=""; @@ -171 +135 @@ - $paramslink .= '&'.$key.'='.$value; + $paramslink .= '&'.$key.'='.$value; @@ -183,9 +147,2 @@ -if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -} -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} - -$exportlink=""; -$namelink=""; +if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES"; +if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES"; @@ -195,12 +152,11 @@ - $name = $langs->trans("Turnover").', '.$langs->trans("ByUserAuthorOfInvoice"); - $calcmode = $langs->trans("CalcModeDebt"); - //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $description = $langs->trans("RulesCADue"); - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $description .= $langs->trans("DepositsAreNotIncluded"); - } else { - $description .= $langs->trans("DepositsAreIncluded"); - } - $builddate = dol_now(); - //$exportlink=$langs->trans("NotYetAvailable"); -} elseif ($modecompta == "RECETTES-DEPENSES") { + $name = $langs->trans("Turnover").', '.$langs->trans("ByUserAuthorOfInvoice"); + $calcmode = $langs->trans("CalcModeDebt"); + //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $description = $langs->trans("RulesCADue"); + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded"); + else $description .= $langs->trans("DepositsAreIncluded"); + $builddate = dol_now(); + //$exportlink=$langs->trans("NotYetAvailable"); +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -210 +166 @@ - $description = $langs->trans("RulesCAIn"); + $description = $langs->trans("RulesCAIn"); @@ -212,3 +168,5 @@ - $builddate = dol_now(); - //$exportlink=$langs->trans("NotYetAvailable"); -} elseif ($modecompta == "BOOKKEEPING") { + $builddate = dol_now(); + //$exportlink=$langs->trans("NotYetAvailable"); +} +elseif ($modecompta == "BOOKKEEPING") +{ @@ -216 +174,3 @@ -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { +} +elseif ($modecompta == "BOOKKEEPINGCOLLECTED") +{ @@ -219,8 +179,3 @@ -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) { - $periodlink = ''.img_previous().' '.img_next().''; -} else { - $periodlink = ''; -} +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().' '.img_next().''; +else $periodlink = ''; @@ -229,3 +184 @@ -if (!empty($modecompta)) { - $moreparam['modecompta'] = $modecompta; -} +if (!empty($modecompta)) $moreparam['modecompta'] = $modecompta; @@ -235,2 +188,3 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { - print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ + print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); @@ -246,2 +200,3 @@ -foreach ($headerparams as $key => $value) { - print ''; +foreach ($headerparams as $key => $value) +{ + print ''; @@ -251,2 +205,0 @@ -$catotal_ht = 0; - @@ -254,8 +207,8 @@ - $sql = "SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.fk_user_author = u.rowid"; - $sql .= " WHERE f.fk_statut in (1,2)"; - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $sql .= " AND f.type IN (0,1,2,5)"; - } else { - $sql .= " AND f.type IN (0,1,2,3,5)"; + $sql = "SELECT u.rowid as rowid, u.lastname as name, u.firstname as firstname, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.fk_user_author = u.rowid"; + $sql .= " WHERE f.fk_statut in (1,2)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $sql .= " AND f.type IN (0,1,2,5)"; + } else { + $sql .= " AND f.type IN (0,1,2,3,5)"; @@ -264 +217 @@ - $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; @@ -266,5 +219,5 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { - /* - * List of payments (old payments are not seen by this query because on older versions, - * they were not linked via the table llx_paiement_facture. They are added later) - */ +} else { + /* + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) + */ @@ -278 +231 @@ - $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; @@ -280,2 +232,0 @@ -} elseif ($modecompta == "BOOKKEEPING") { -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { @@ -284,3 +235 @@ -if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); -} +if ($socid) $sql .= " AND f.fk_soc = ".$socid; @@ -290,3 +238,0 @@ -$amount = array(); - -dol_syslog("cabyuser", LOG_DEBUG); @@ -295,12 +241,28 @@ - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($result); - - $amount_ht[$obj->rowid] = (empty($obj->amount) ? 0 : $obj->amount); - $amount[$obj->rowid] = $obj->amount_ttc; - $name[$obj->rowid] = $obj->name.' '.$obj->firstname; - - $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount); - $catotal += $obj->amount_ttc; - $i++; + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) { + $obj = $db->fetch_object($result); + $amount_ht[$obj->rowid] = $obj->amount; + $amount[$obj->rowid] = $obj->amount_ttc; + $name[$obj->rowid] = $obj->name.' '.$obj->firstname; + $catotal_ht += $obj->amount; + $catotal += $obj->amount_ttc; + $i++; + } +} else { + dol_print_error($db); +} + +// Adding old-version payments, non-bound by "paiement_facture" then without User +if ($modecompta != 'CREANCES-DETTES') { + $sql = "SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql .= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql .= " WHERE pf.rowid IS NULL"; + $sql .= " AND p.fk_bank = b.rowid"; + $sql .= " AND b.fk_account = ba.rowid"; + $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; + if ($date_start && $date_end) { + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; @@ -308,38 +270,20 @@ -} else { - dol_print_error($db); -} - -// Adding old-version payments, non-bound by table llx_paiement_facture then without User -if ($modecompta == 'RECETTES-DEPENSES') { - $sql = "SELECT -1 as rowidx, '' as name, '' as firstname, sum(DISTINCT p.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql .= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql .= " WHERE pf.rowid IS NULL"; - $sql .= " AND p.fk_bank = b.rowid"; - $sql .= " AND b.fk_account = ba.rowid"; - $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; - if ($date_start && $date_end) { - $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - } - $sql .= " GROUP BY rowidx, name, firstname"; - $sql .= " ORDER BY rowidx"; - - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($result); - $amount[$obj->rowidx] = $obj->amount_ttc; - $name[$obj->rowidx] = $obj->name.' '.$obj->firstname; - $catotal += $obj->amount_ttc; - $i++; - } - } else { - dol_print_error($db); - } -} - -$moreforfilter = ''; + $sql .= " GROUP BY rowidx, name, firstname"; + $sql .= " ORDER BY rowidx"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) { + $obj = $db->fetch_object($result); + $amount[$obj->rowidx] = $obj->amount_ttc; + $name[$obj->rowidx] = $obj->name.' '.$obj->firstname; + $catotal += $obj->amount_ttc; + $i++; + } + } else { + dol_print_error($db); + } +} + +$morefilter = ''; @@ -362,9 +306,9 @@ - print_liste_field_titre( - $langs->trans('AmountHT'), - $_SERVER["PHP_SELF"], - "amount_ht", - "", - $paramslink, - 'class="right"', - $sortfield, - $sortorder + print_liste_field_titre( + $langs->trans('AmountHT'), + $_SERVER["PHP_SELF"], + "amount_ht", + "", + $paramslink, + 'class="right"', + $sortfield, + $sortorder @@ -387,2 +331 @@ - $_SERVER["PHP_SELF"], - "amount_ttc", + $_SERVER["PHP_SELF"], "amount_ttc", @@ -406,125 +349,126 @@ - $arrayforsort = $name; - - // We define arrayforsort - if ($sortfield == 'name' && $sortorder == 'asc') { - asort($name); - $arrayforsort = $name; - } - if ($sortfield == 'name' && $sortorder == 'desc') { - arsort($name); - $arrayforsort = $name; - } - if ($sortfield == 'amount_ht' && $sortorder == 'asc') { - asort($amount_ht); - $arrayforsort = $amount_ht; - } - if ($sortfield == 'amount_ht' && $sortorder == 'desc') { - arsort($amount_ht); - $arrayforsort = $amount_ht; - } - if ($sortfield == 'amount_ttc' && $sortorder == 'asc') { - asort($amount); - $arrayforsort = $amount; - } - if ($sortfield == 'amount_ttc' && $sortorder == 'desc') { - arsort($amount); - $arrayforsort = $amount; - } - - $i = 0; - - foreach ($arrayforsort as $key => $value) { - print '
'; - - // Third party - $fullname = $name[$key]; - if ($key >= 0) { - $linkname = ''.img_object($langs->trans("ShowUser"), 'user').' '.$fullname.''; - } else { - $linkname = $langs->trans("PaymentsNotLinkedToUser"); - } - print "\n"; - - // Amount w/o VAT - print ''; - - // Amount with VAT - print ''; - - // Percent - print ''; - - // Other stats - print ''; - print "\n"; - $i++; - } - - // Total - print ''; - print ''; - if ($modecompta != 'CREANCES-DETTES') { - print ''; - } else { - print ''; - } - print ''; - print ''; - print ''; - print ''; - - $db->free($result); + $arrayforsort = $name; + + // We define arrayforsort + if ($sortfield == 'name' && $sortorder == 'asc') { + asort($name); + $arrayforsort = $name; + } + if ($sortfield == 'name' && $sortorder == 'desc') { + arsort($name); + $arrayforsort = $name; + } + if ($sortfield == 'amount_ht' && $sortorder == 'asc') { + asort($amount_ht); + $arrayforsort = $amount_ht; + } + if ($sortfield == 'amount_ht' && $sortorder == 'desc') { + arsort($amount_ht); + $arrayforsort = $amount_ht; + } + if ($sortfield == 'amount_ttc' && $sortorder == 'asc') { + asort($amount); + $arrayforsort = $amount; + } + if ($sortfield == 'amount_ttc' && $sortorder == 'desc') { + arsort($amount); + $arrayforsort = $amount; + } + + $i = 0; + + foreach ($arrayforsort as $key => $value) { + print ''; + + // Third party + $fullname = $name[$key]; + if ($key >= 0) { + $linkname = ''.img_object($langs->trans("ShowUser"), 'user').' '.$fullname.''; + } else { + $linkname = $langs->trans("PaymentsNotLinkedToUser"); + } + print "\n"; + + // Amount w/o VAT + print ''; + + // Amount with VAT + print ''; + + // Percent + print ''; + + // Other stats + print ''; + print "\n"; + $i++; + } + + // Total + print ''; + print ''; + if ($modecompta != 'CREANCES-DETTES') { + print ''; + } else { + print ''; + } + print ''; + print ''; + print ''; + print ''; + + $db->free($result); --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_casoc.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_casoc.php @@ -9 +8,0 @@ - * Copyright (C) 2022 Alexandre Spangaro @@ -30 +28,0 @@ -// Load Dolibarr environment @@ -45,12 +43,6 @@ -if (GETPOST("modecompta")) { - $modecompta = GETPOST("modecompta"); -} - -$sortorder = GETPOST("sortorder", 'aZ09comma'); -$sortfield = GETPOST("sortfield", 'aZ09comma'); -if (!$sortorder) { - $sortorder = "asc"; -} -if (!$sortfield) { - $sortfield = "nom"; -} +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta"); + +$sortorder = isset($_GET["sortorder"]) ? $_GET["sortorder"] : $_POST["sortorder"]; +$sortfield = isset($_GET["sortfield"]) ? $_GET["sortfield"] : $_POST["sortfield"]; +if (!$sortorder) $sortorder = "asc"; +if (!$sortfield) $sortfield = "nom"; @@ -62,3 +53,0 @@ -if ($selected_cat == -1) { - $selected_cat = ''; -} @@ -67 +56 @@ - $subcat = true; + $subcat = true; @@ -71,12 +60,3 @@ -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); -} - -// Hook -$hookmanager->initHooks(array('casoclist')); +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); @@ -91,9 +71,10 @@ -$date_startyear = GETPOST("date_startyear", 'int'); -$date_startmonth = GETPOST("date_startmonth", 'int'); -$date_startday = GETPOST("date_startday", 'int'); -$date_endyear = GETPOST("date_endyear", 'int'); -$date_endmonth = GETPOST("date_endmonth", 'int'); -$date_endday = GETPOST("date_endday", 'int'); -if (empty($year)) { - $year_current = dol_print_date(dol_now(), '%Y'); - $month_current = dol_print_date(dol_now(), '%m'); +$date_startyear = GETPOST("date_startyear", 'alpha'); +$date_startmonth = GETPOST("date_startmonth", 'alpha'); +$date_startday = GETPOST("date_startday", 'alpha'); +$date_endyear = GETPOST("date_endyear", 'alpha'); +$date_endmonth = GETPOST("date_endmonth", 'alpha'); +$date_endday = GETPOST("date_endday", 'alpha'); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -103 +84 @@ - $month_current = dol_print_date(dol_now(), '%m'); + $month_current = strftime("%m", dol_now()); @@ -106,2 +87,2 @@ -$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere +$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); +$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); @@ -109,3 +90,5 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end - $q = GETPOST("q", "int") ? GETPOST("q", "int") : 0; - if (empty($q)) { +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q = GETPOST("q", "int") ?GETPOST("q", "int") : 0; + if (empty($q)) + { @@ -113 +96 @@ - $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); @@ -116,2 +99,4 @@ - if (!GETPOST("month")) { // If month not forced - if (!GETPOST('year') && $month_start > $month_current) { + if (!GETPOST("month")) // If month not forced + { + if (!GETPOST('year') && $month_start > $month_current) + { @@ -122,5 +107,2 @@ - if ($month_end < 1) { - $month_end = 12; - } else { - $year_end++; - } + if ($month_end < 1) $month_end = 12; + else $year_end++; @@ -128,20 +110,9 @@ - $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); - } -} else { + $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); } +} +else +{ @@ -150 +120,0 @@ -//print dol_print_date($date_start, 'dayhour', 'gmt'); @@ -165,21 +135,7 @@ -if (!empty($date_startyear)) { - $headerparams['date_startyear'] = $date_startyear; -} -if (!empty($date_startmonth)) { - $headerparams['date_startmonth'] = $date_startmonth; -} -if (!empty($date_startday)) { - $headerparams['date_startday'] = $date_startday; -} -if (!empty($date_endyear)) { - $headerparams['date_endyear'] = $date_endyear; -} -if (!empty($date_endmonth)) { - $headerparams['date_endmonth'] = $date_endmonth; -} -if (!empty($date_endday)) { - $headerparams['date_endday'] = $date_endday; -} -if (!empty($q)) { - $headerparams['q'] = $q; -} +$headerparams['date_startyear'] = $date_startyear; +$headerparams['date_startmonth'] = $date_startmonth; +$headerparams['date_startday'] = $date_startday; +$headerparams['date_endyear'] = $date_endyear; +$headerparams['date_endmonth'] = $date_endmonth; +$headerparams['date_endday'] = $date_endday; +$headerparams['q'] = $q; @@ -200 +155,0 @@ -$paramslink=""; @@ -202 +157 @@ - $paramslink .= '&'.$key.'='.$value; + $paramslink .= '&'.$key.'='.$value; @@ -217,9 +172,2 @@ -if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -} -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} - -$exportlink=""; -$namelink=""; +if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES"; +if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES"; @@ -228 +176,2 @@ -if ($modecompta == "CREANCES-DETTES") { +if ($modecompta == "CREANCES-DETTES") +{ @@ -233,5 +182,2 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $description .= $langs->trans("DepositsAreNotIncluded"); - } else { - $description .= $langs->trans("DepositsAreIncluded"); - } + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded"); + else $description .= $langs->trans("DepositsAreIncluded"); @@ -240 +186,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -248,11 +196,10 @@ -} elseif ($modecompta == "BOOKKEEPING") { -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { -} -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) { - $periodlink = ''.img_previous().' '.img_next().''; -} else { - $periodlink = ''; -} +} +elseif ($modecompta == "BOOKKEEPING") +{ +} +elseif ($modecompta == "BOOKKEEPINGCOLLECTED") +{ +} +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().' '.img_next().''; +else $periodlink = ''; @@ -262,2 +209,3 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { - print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ + print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); @@ -271,2 +218,0 @@ -$catotal_ht = 0; - @@ -274,2 +220,2 @@ - $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays,"; - $sql .= " sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc"; + $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,"; + $sql .= " sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; @@ -277,4 +223,7 @@ - if ($selected_cat === -2) { // Without any category - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; - } elseif ($selected_cat) { // Into a specific category - $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs"; + if ($selected_cat === -2) // Without any category + { + $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; + } + elseif ($selected_cat) // Into a specific category + { + $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs"; @@ -283,2 +232,2 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $sql .= " AND f.type IN (0,1,2,5)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $sql .= " AND f.type IN (0,1,2,5)"; @@ -286 +235 @@ - $sql .= " AND f.type IN (0,1,2,3,5)"; + $sql .= " AND f.type IN (0,1,2,3,5)"; @@ -290,10 +239,10 @@ - $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - } - if ($selected_cat === -2) { // Without any category - $sql .= " AND cs.fk_soc is null"; - } elseif ($selected_cat) { // Into a specific category - $sql .= " AND (c.rowid = ".((int) $selected_cat); - if ($subcat) { - $sql .= " OR c.fk_parent = ".((int) $selected_cat); - } - $sql .= ")"; + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + } + if ($selected_cat === -2) // Without any category + { + $sql .= " AND cs.fk_soc is null"; + } + elseif ($selected_cat) { // Into a specific category + $sql .= " AND (c.rowid = ".$db->escape($selected_cat); + if ($subcat) $sql .= " OR c.fk_parent = ".$db->escape($selected_cat); + $sql .= ")"; @@ -302 +251 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} else { @@ -304,2 +253,2 @@ - * List of payments (old payments are not seen by this query because on older versions, - * they were not linked via the table llx_paiement_facture. They are added later) + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) @@ -307 +256 @@ - $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc"; + $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc"; @@ -312,4 +261,7 @@ - if ($selected_cat === -2) { // Without any category - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; - } elseif ($selected_cat) { // Into a specific category - $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs"; + if ($selected_cat === -2) // Without any category + { + $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; + } + elseif ($selected_cat) // Into a specific category + { + $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs"; @@ -321,10 +273,10 @@ - $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - } - if ($selected_cat === -2) { // Without any category - $sql .= " AND cs.fk_soc is null"; - } elseif ($selected_cat) { // Into a specific category - $sql .= " AND (c.rowid = ".((int) $selected_cat); - if ($subcat) { - $sql .= " OR c.fk_parent = ".((int) $selected_cat); - } - $sql .= ")"; + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + } + if ($selected_cat === -2) // Without any category + { + $sql .= " AND cs.fk_soc is null"; + } + elseif ($selected_cat) { // Into a specific category + $sql .= " AND (c.rowid = ".$selected_cat; + if ($subcat) $sql .= " OR c.fk_parent = ".$selected_cat; + $sql .= ")"; @@ -333,15 +285,5 @@ -} elseif ($modecompta == "BOOKKEEPING") { -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { -} -if (!empty($search_societe)) { - $sql .= natural_search('s.nom', $search_societe); -} -if (!empty($search_zip)) { - $sql .= natural_search('s.zip', $search_zip); -} -if (!empty($search_town)) { - $sql .= natural_search('s.town', $search_town); -} -if ($search_country > 0) { - $sql .= ' AND s.fk_pays = '.((int) $search_country); -} +} +if (!empty($search_societe)) $sql .= natural_search('s.nom', $search_societe); +if (!empty($search_zip)) $sql .= natural_search('s.zip', $search_zip); +if (!empty($search_town)) $sql .= natural_search('s.town', $search_town); +if ($search_country > 0) $sql .= ' AND s.fk_pays = '.$search_country.''; @@ -349,4 +291,2 @@ -if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); -} -$sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.zip, s.town, s.fk_pays"; +if ($socid) $sql .= " AND f.fk_soc = ".$socid; +$sql .= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays"; @@ -355,2 +294,0 @@ - -$amount = array(); @@ -365,17 +303,9 @@ - - $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount); - $amount[$obj->socid] = $obj->amount_ttc; - $fullname = $obj->name; - if (!empty($obj->name_alias)) { - $fullname .= ' ('.$obj->name_alias.')'; - } - $name[$obj->socid] = $fullname; - - $address_zip[$obj->socid] = $obj->zip; - $address_town[$obj->socid] = $obj->town; - $address_pays[$obj->socid] = getCountry($obj->fk_pays); - - $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount); - $catotal += $obj->amount_ttc; - - $i++; + $amount_ht[$obj->socid] = $obj->amount; + $amount[$obj->socid] = $obj->amount_ttc; + $name[$obj->socid] = $obj->name.' '.$obj->firstname; + $address_zip[$obj->socid] = $obj->zip; + $address_town[$obj->socid] = $obj->town; + $address_pays[$obj->socid] = getCountry($obj->fk_pays); + $catotal_ht += $obj->amount; + $catotal += $obj->amount_ttc; + $i++; @@ -387,2 +317,2 @@ -// We add the old versions of payments, not linked by table llx_paiement_facture -if ($modecompta == "RECETTES-DEPENSES") { +// On ajoute les paiements anciennes version, non lies par paiement_facture +if ($modecompta != 'CREANCES-DETTES') { @@ -398,3 +328 @@ - if ($date_start && $date_end) { - $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - } + if ($date_start && $date_end) $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; @@ -410,12 +338,5 @@ - - if (empty($amount[$obj->socid])) { - $amount[$obj->socid] = $obj->amount_ttc; - } else { - $amount[$obj->socid] += $obj->amount_ttc; - } - - $name[$obj->socid] = $obj->name; - $address_zip[$obj->socid] = ''; - $address_town[$obj->socid] = ''; - $address_pays[$obj->socid] = ''; - + $amount[$obj->rowid] += $obj->amount_ttc; + $name[$obj->rowid] = $obj->name; + $address_zip[$obj->rowid] = $obj->zip; + $address_town[$obj->rowid] = $obj->town; + $address_pays[$obj->rowid] = getCountry($obj->fk_pays); @@ -423 +343,0 @@ - @@ -437,2 +357,3 @@ -foreach ($headerparams as $key => $value) { - print ''; +foreach ($headerparams as $key => $value) +{ + print ''; @@ -448,3 +369,2 @@ -print '\n"; + print "\n"; @@ -641 +557 @@ - print ''; - print "\n"; - $i++; - } + // Other stats + print ''; + print "\n"; + $i++; + } @@ -712 +628 @@ - print ''; + print ''; @@ -714 +630 @@ - print ''; + print ''; --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_index.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_index.php @@ -6 +6 @@ - * Copyright (C) 2018-2020 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -27 +26,0 @@ -// Load Dolibarr environment @@ -46,3 +45,4 @@ -if (empty($year)) { - $year_current = dol_print_date(dol_now(), "%Y"); - $month_current = dol_print_date(dol_now(), "%m"); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -52,5 +52,5 @@ - $month_current = dol_print_date(dol_now(), "%m"); - $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1); -} -$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear, 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear, 'tzserver'); // We use timezone of server so report is same from everywhere + $month_current = strftime("%m", dol_now()); + $year_start = $year - ($nbofyear - 1); +} +$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); @@ -59,3 +59,5 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end - $q = GETPOST("q") ? GETPOST("q") : 0; - if ($q == 0) { +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q = GETPOST("q") ?GETPOST("q") : 0; + if ($q == 0) + { @@ -63,4 +65,6 @@ - $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1); - $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); - if (!GETPOST('month')) { - if (!$year && $month_start > $month_current) { + $year_end = $year_start + ($nbofyear - 1); + $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) + { @@ -71,26 +75,13 @@ - if ($month_end < 1) { - $month_end = 12; - } - } else { - $month_end = $month_start; - } - $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); - } -} + if ($month_end < 1) $month_end = 12; + } + else $month_end = $month_start; + $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); } +} + +$userid = GETPOST('userid', 'int'); +$socid = GETPOST('socid', 'int'); @@ -99 +89,0 @@ -$mothn_start = $tmps['mon']; @@ -102 +91,0 @@ -$month_end = $tmpe['mon']; @@ -108,8 +97,2 @@ -if (isModEnabled('accounting')) { - $modecompta = 'BOOKKEEPING'; -} -if (GETPOST("modecompta", 'alpha')) { - $modecompta = GETPOST("modecompta", 'alpha'); -} - -$userid = GETPOST('userid', 'int'); +if (!empty($conf->accounting->enabled)) $modecompta = 'BOOKKEEPING'; +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta", 'alpha'); @@ -118,10 +101,3 @@ -$socid = GETPOST('socid', 'int'); -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); -} +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); @@ -136,8 +111,0 @@ -$param = ''; -if ($date_startday && $date_startmonth && $date_startyear) { - $param .= '&date_startday='.$date_startday.'&date_startmonth='.$date_startmonth.'&date_startyear='.$date_startyear; -} -if ($date_endday && $date_endmonth && $date_endyear) { - $param .= '&date_endday='.$date_endday.'&date_endmonth='.$date_endmonth.'&date_endyear='.$date_endyear; -} - @@ -148,4 +115,0 @@ -$exportlink = ''; -$namelink = ''; -$builddate = dol_now(); - @@ -153 +117,2 @@ -if ($modecompta == "CREANCES-DETTES") { +if ($modecompta == "CREANCES-DETTES") +{ @@ -154,0 +120,4 @@ + $calcmode = $langs->trans("CalcModeDebt"); + //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $calcmode .= '
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); @@ -157,5 +126,3 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $description .= $langs->trans("DepositsAreNotIncluded"); - } else { - $description .= $langs->trans("DepositsAreIncluded"); - } + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded"); + else $description .= $langs->trans("DepositsAreIncluded"); + $builddate = dol_now(); @@ -163 +130,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -164,0 +134,4 @@ + $calcmode = $langs->trans("CalcModeEngagement"); + //$calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + //$calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode",'','').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); @@ -167,0 +141 @@ + $builddate = dol_now(); @@ -169 +143,3 @@ -} elseif ($modecompta == "BOOKKEEPING") { +} +elseif ($modecompta == "BOOKKEEPING") +{ @@ -170,0 +147,4 @@ + $calcmode = $langs->trans("CalcModeBookkeeping"); + $calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; + //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); @@ -172 +152,2 @@ - $description = $langs->trans("RulesSalesTurnoverOfIncomeAccounts"); + $description = $langs->trans("RulesCATotalSaleJournal"); + $builddate = dol_now(); @@ -175,3 +155,0 @@ -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); @@ -180,28 +158 @@ -if (!empty($modecompta)) { - $moreparam['modecompta'] = $modecompta; -} - -// Define $calcmode line -$calcmode = ''; -if ($modecompta == "RECETTES-DEPENSES" || $modecompta == "BOOKKEEINGCOLLECTED") { - /*if (isModEnabled('accounting')) { - $calcmode .= ''; - $calcmode .= '
'; - }*/ - $calcmode .= ''; -} else { - if (isModEnabled('accounting')) { - $calcmode .= ''; - $calcmode .= '
'; - } - $calcmode .= ''; -} - +if (!empty($modecompta)) $moreparam['modecompta'] = $modecompta; @@ -210,7 +161,9 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { - print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); -} - - -if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc"; +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ + print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); +} + + +if ($modecompta == 'CREANCES-DETTES') +{ + $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; @@ -219,5 +172,2 @@ - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $sql .= " AND f.type IN (0,1,2,5)"; - } else { - $sql .= " AND f.type IN (0,1,2,3,5)"; - } + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)"; + else $sql .= " AND f.type IN (0,1,2,3,5)"; @@ -225,4 +175,4 @@ - if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } -} elseif ($modecompta == "RECETTES-DEPENSES") { + if ($socid) $sql .= " AND f.fk_soc = ".$socid; +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -233 +183 @@ - $sql = "SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc"; + $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; @@ -240,13 +190,6 @@ - if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } -} elseif ($modecompta == "BOOKKEEPING") { - $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS'); - $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version'); - if (empty($pcgvercode)) { - $pcgvercode = $pcgverid; - } - - $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,"; - $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa"; + if ($socid) $sql .= " AND f.fk_soc = ".$socid; +} +elseif ($modecompta == "BOOKKEEPING") +{ + $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj"; @@ -254,6 +197,4 @@ - $sql .= " AND b.numero_compte = aa.account_number"; - $sql .= " AND b.doc_type = 'customer_invoice'"; - $sql .= " AND aa.entity = ".$conf->entity; - $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'"; - $sql .= " AND aa.pcg_type = 'INCOME'"; // TODO Be able to use a custom group -} + $sql .= " AND aj.entity = ".$conf->entity; + $sql .= " AND b.code_journal = aj.code AND aj.nature = 2"; // @todo currently count amount in sale journal, but we need to define a category group for turnover +} + @@ -267,5 +207,0 @@ -$cum = array(); -$cum_ht = array(); -$total_ht = array(); -$total = array(); - @@ -273 +209,2 @@ -if ($result) { +if ($result) +{ @@ -276 +213,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -278,3 +216,4 @@ - $cum_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount; - $cum[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc; - if ($obj->amount_ttc) { + $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0; + $cum[$obj->dm] = $obj->amount_ttc; + if ($obj->amount_ttc) + { @@ -287 +226,2 @@ -} else { +} +else { @@ -292 +232,2 @@ -if ($modecompta == 'RECETTES-DEPENSES') { +if ($modecompta == 'RECETTES-DEPENSES') +{ @@ -306 +247,2 @@ - if ($result) { + if ($result) + { @@ -309 +251,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -311,7 +254,4 @@ - if (empty($cum[$obj->dm])) { - $cum[$obj->dm] = $obj->amount_ttc; - } else { - $cum[$obj->dm] += $obj->amount_ttc; - } - if ($obj->amount_ttc) { - $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm); + $cum[$obj->dm] += $obj->amount_ttc; + if ($obj->amount_ttc) + { + $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm); @@ -322 +262,3 @@ - } else { + } + else + { @@ -334,9 +276,5 @@ -for ($annee = $year_start; $annee <= $year_end; $annee++) { - if ($modecompta == 'CREANCES-DETTES') { - print '
'; - if ($annee != $year_end) { - print ''; - } + if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1); + if ($modecompta != 'BOOKKEEPING') print ''; + print ''; + if ($annee != $year_end) print ''; @@ -358,11 +290,4 @@ -for ($annee = $year_start; $annee <= $year_end; $annee++) { - if ($modecompta == 'CREANCES-DETTES') { - print ''; - } - print ''; +for ($annee = $year_start; $annee <= $year_end; $annee++) +{ + if ($modecompta == 'CREANCES-DETTES') print ''; + print ''; @@ -370,3 +295 @@ - if ($annee != $year_end) { - print ''; - } + if ($annee != $year_end) print ''; @@ -379,3 +302,2 @@ -$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); -$nowyearmonth = dol_print_date(dol_now(), "%Y%m"); -//$nowyearmonth = strftime("%Y-%m", dol_now()); +$nowyear = strftime("%Y", dol_now()); +$nowyearmonth = strftime("%Y-%m", dol_now()); @@ -387,2 +309,3 @@ -$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOST('date_startmonth', 'int') - 1) : (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 0 : ($conf->global->SOCIETE_FISCAL_MONTH_START - 1)); -for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { +$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0; +for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) +{ @@ -390,3 +313 @@ - if ($mois > 12) { - $mois_modulo = $mois - 12; - } // ajout + if ($mois > 12) {$mois_modulo = $mois - 12; } // ajout @@ -395,5 +315,0 @@ - // If we show only one year or one month, we do not show month before the selected month - if ($mois < $date_startmonth && $year_start <= $date_startyear) { - continue; - } - // If we show only one year or one month, we do not show month after the selected month @@ -410 +326,2 @@ - for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta + for ($annee = $year_start - 1; $annee <= $year_end; $annee++) // We start one year before to have data to be able to make delta + { @@ -412,3 +329 @@ - if ($mois > 12) { - $annee_decalage = $annee + 1; - } + if ($mois > 12) {$annee_decalage = $annee + 1; } @@ -418 +333,2 @@ - if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. + if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. + { @@ -420 +336 @@ - // Value turnover of month w/o VAT + // Valeur CA du mois w/o VAT @@ -422,11 +338,9 @@ - if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { - if (!empty($cum_ht[$case])) { - $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. - print ''.price($cum_ht[$case], 1).''; - } else { - if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { - print '0'; - } else { - print ' '; - } - } + if ($cum_ht[$case]) + { + $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. + print ''.price($cum_ht[$case], 1).''; + } + else + { + if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } + else { print ' '; } @@ -437 +351 @@ - // Value turnover of month + // Valeur CA du mois @@ -439,16 +353,39 @@ - if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { - if (!empty($cum[$case])) { - $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. - if ($modecompta != 'BOOKKEEPING') { - print ''; - } - print price($cum[$case], 1); - if ($modecompta != 'BOOKKEEPING') { - print ''; - } - } else { - if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { - print '0'; - } else { - print ' '; - } + if ($cum[$case]) + { + $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. + if ($modecompta != 'BOOKKEEPING') print ''; + print price($cum[$case], 1); + if ($modecompta != 'BOOKKEEPING') print ''; + } + else + { + if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } + else { print ' '; } + } + print ""; + + // Pourcentage du mois + if ($annee_decalage > $minyear && $case <= $casenow) + { + if ($cum[$caseprev] && $cum[$case]) + { + $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100); + //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; + print ''; + } + if ($cum[$caseprev] && !$cum[$case]) + { + print ''; + } + if (!$cum[$caseprev] && $cum[$case]) + { + //print ''; + print ''; + } + if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case]) + { + print ''; + } + if (!isset($cum[$caseprev]) && !$cum[$case]) + { + print ''; @@ -457,32 +394,6 @@ - print ""; - - // Percentage of month - print ''; - print '-'; - } - if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) { - print '+0%'; - } - if (!isset($cum[$caseprev]) && empty($cum[$case])) { - print '-'; - } - } else { - if ($minyearmonth <= $case && $case <= $maxyearmonth) { - print '-'; - } else { - print ' '; - } - } + else + { + print ''; @@ -490,19 +401,6 @@ - print ''; - - if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) { - print ''; - } - } - - if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { - if (empty($total_ht[$annee])) { - $total_ht[$annee] = (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]); - } else { - $total_ht[$annee] += (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]); - } - if (empty($total[$annee])) { - $total[$annee] = empty($cum[$case]) ? 0 : $cum[$case]; - } else { - $total[$annee] += empty($cum[$case]) ? 0 : $cum[$case]; - } - } + + if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print ''; + } + + $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); + $total[$annee] += $cum[$case]; @@ -579 +477 @@ -// Show total +// Affiche total @@ -581 +479,2 @@ -for ($annee = $year_start; $annee <= $year_end; $annee++) { +for ($annee = $year_start; $annee <= $year_end; $annee++) +{ @@ -584,5 +483,6 @@ - if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { - print '"; - } else { + if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) + { + print '"; + } + else + { @@ -593,6 +493,7 @@ - // Total amount - if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { - print '"; - } else { + // Montant total + if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) + { + print '"; + } + else + { @@ -603,2 +504,3 @@ - if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) { - if (!empty($total[$annee - 1]) && !empty($total[$annee])) { + if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) + { + if ($total[$annee - 1] && $total[$annee]) { @@ -606,5 +508,4 @@ - print ''; - } - if (!empty($total[$annee - 1]) && empty($total[$annee])) { + print ''; + } + if ($total[$annee - 1] && !$total[$annee]) + { @@ -613 +514,2 @@ - if (empty($total[$annee - 1]) && !empty($total[$annee])) { + if (!$total[$annee - 1] && $total[$annee]) + { @@ -616 +518,2 @@ - if (empty($total[$annee - 1]) && empty($total[$annee])) { + if (!$total[$annee - 1] && !$total[$annee]) + { @@ -619 +522,3 @@ - } else { + } + else + { @@ -621,5 +526,2 @@ - if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { - print '-'; - } else { - print ' '; - } + if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { print '-'; } + else { print ' '; } @@ -629,3 +531 @@ - if ($annee != $year_end) { - print ''; - } + if ($annee != $year_end) print ''; @@ -703 +603 @@ - $sql = "SELECT sum(f.total_ht) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc + $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc @@ -712 +612 @@ - $sql .= " AND f.fk_soc = ".((int) $socid); + $sql .= " AND f.fk_soc = ".$socid; --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_supplier_turnover.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_supplier_turnover.php @@ -19 +19 @@ - * \file htdocs/compta/stats/supplier_turnover.php + * \file htdocs/compta/stats/supplier_ca.php @@ -23 +22,0 @@ -// Load Dolibarr environment @@ -42,3 +41,4 @@ -if (empty($year)) { - $year_current = dol_print_date(dol_now(), "%Y"); - $month_current = dol_print_date(dol_now(), "%m"); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -48,5 +48,5 @@ - $month_current = dol_print_date(dol_now(), "%m"); - $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1); -} -$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear, 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear, 'tzserver'); // We use timezone of server so report is same from everywhere + $month_current = strftime("%m", dol_now()); + $year_start = $year - ($nbofyear - 1); +} +$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); @@ -55,3 +55,5 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end - $q = GETPOST("q") ? GETPOST("q") : 0; - if ($q == 0) { +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q = GETPOST("q") ?GETPOST("q") : 0; + if ($q == 0) + { @@ -59,4 +61,6 @@ - $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1); - $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); - if (!GETPOST('month')) { - if (!$year && $month_start > $month_current) { + $year_end = $year_start + ($nbofyear - 1); + $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) + { @@ -67,25 +71,9 @@ - if ($month_end < 1) { - $month_end = 12; - } - } else { - $month_end = $month_start; - } - $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); - } + if ($month_end < 1) $month_end = 12; + } + else $month_end = $month_start; + $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); } @@ -105,6 +93,2 @@ -if (isModEnabled('accounting')) { - $modecompta = 'BOOKKEEPING'; -} -if (GETPOST("modecompta", 'alpha')) { - $modecompta = GETPOST("modecompta", 'alpha'); -} +if (!empty($conf->accounting->enabled)) $modecompta = 'BOOKKEEPING'; +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta", 'alpha'); @@ -113,9 +97,5 @@ -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); -} +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); + + @@ -132,12 +111,0 @@ -$exportlink = ''; -$namelink = ''; -$builddate = dol_now(); - -// TODO Report from bookkeeping not yet available, so we switch on report on business events -/*if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -}*/ -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} - @@ -145 +113,2 @@ -if ($modecompta == "CREANCES-DETTES") { +if ($modecompta == "CREANCES-DETTES") +{ @@ -146,0 +116,4 @@ + $calcmode = $langs->trans("CalcModeDebt"); + //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $calcmode .= '
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); @@ -148,0 +122 @@ + $builddate = dol_now(); @@ -150 +124,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -151,0 +128,4 @@ + $calcmode = $langs->trans("CalcModeEngagement"); + //$calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + //$calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode",'','').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); @@ -153,0 +134 @@ + $builddate = dol_now(); @@ -155 +136,3 @@ -} elseif ($modecompta == "BOOKKEEPING") { +} +elseif ($modecompta == "BOOKKEEPING") +{ @@ -156,0 +140,4 @@ + $calcmode = $langs->trans("CalcModeBookkeeping"); + $calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; + //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); @@ -158 +145,2 @@ - $description = $langs->trans("RulesPurchaseTurnoverOfExpenseAccounts"); + $description = $langs->trans("RulesPurchaseTurnoverTotalPurchaseJournal"); + $builddate = dol_now(); @@ -160,10 +148 @@ -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { - $name = $langs->trans("PurchaseTurnoverCollected"); - $periodlink = ($year_start ? "".img_previous()."".img_next()."" : ""); - $description = $langs->trans("RulesPurchaseTurnoverCollectedOfExpenseAccounts"); - //$exportlink=$langs->trans("NotYetAvailable"); -} - -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); +} @@ -172,29 +151 @@ -if (!empty($modecompta)) { - $moreparam['modecompta'] = $modecompta; -} - -// Define $calcmode line -$calcmode = ''; -if ($modecompta == "RECETTES-DEPENSES" || $modecompta == "BOOKKEEPINGCOLLECTED") { - /*if (isModEnabled('accounting')) { - $calcmode .= ''; - $calcmode .= '
'; - }*/ - $calcmode .= ''; -} else { - if (isModEnabled('accounting')) { - $calcmode .= ''; - $calcmode .= '
'; - } - $calcmode .= ''; -} - - +if (!empty($modecompta)) $moreparam['modecompta'] = $modecompta; @@ -203,6 +154,8 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { - print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); -} - - -if ($modecompta == 'CREANCES-DETTES') { +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ + print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); +} + + +if ($modecompta == 'CREANCES-DETTES') +{ @@ -214,4 +167,4 @@ - if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } -} elseif ($modecompta == "RECETTES-DEPENSES") { + if ($socid) $sql .= " AND f.fk_soc = ".$socid; +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -225,13 +178,6 @@ - if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } -} elseif ($modecompta == "BOOKKEEPING") { - $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS'); - $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version'); - if (empty($pcgvercode)) { - $pcgvercode = $pcgverid; - } - - $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,"; - $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa"; + if ($socid) $sql .= " AND f.fk_soc = ".$socid; +} +elseif ($modecompta == "BOOKKEEPING") +{ + $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj"; @@ -239,7 +185,3 @@ - $sql .= " AND b.doc_type = 'supplier_invoice'"; - $sql .= " AND b.numero_compte = aa.account_number"; - $sql .= " AND aa.entity = ".$conf->entity; - $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'"; - $sql .= " AND aa.pcg_type = 'EXPENSE'"; // TODO Be able to use a custom group -} -//print $sql; + $sql .= " AND aj.entity = ".$conf->entity; + $sql .= " AND b.code_journal = aj.code AND aj.nature = 3"; // @todo currently count amount in sale journal, but we need to define a category group for turnover +} @@ -254,5 +195,0 @@ -$cum = array(); -$cum_ht = array(); -$total_ht = array(); -$total = array(); - @@ -260 +197,2 @@ -if ($result) { +if ($result) +{ @@ -263 +201,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -265,3 +204,4 @@ - $cum_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount; - $cum[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc; - if ($obj->amount_ttc) { + $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0; + $cum[$obj->dm] = $obj->amount_ttc; + if ($obj->amount_ttc) + { @@ -274 +214,2 @@ -} else { +} +else { @@ -285,9 +226,5 @@ -for ($annee = $year_start; $annee <= $year_end; $annee++) { - if ($modecompta == 'CREANCES-DETTES') { - print ''; - if ($annee != $year_end) { - print ''; - } + if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1); + if ($modecompta != 'BOOKKEEPING') print ''; + print ''; + if ($annee != $year_end) print ''; @@ -309,11 +240,4 @@ -for ($annee = $year_start; $annee <= $year_end; $annee++) { - if ($modecompta == 'CREANCES-DETTES') { - print ''; - } - print ''; +for ($annee = $year_start; $annee <= $year_end; $annee++) +{ + if ($modecompta == 'CREANCES-DETTES') print ''; + print ''; @@ -321,3 +245 @@ - if ($annee != $year_end) { - print ''; - } + if ($annee != $year_end) print ''; @@ -330,3 +252,2 @@ -$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); -//$nowyearmonth = strftime("%Y-%m", dol_now()); -$nowyearmonth = dol_print_date(dol_now(), "%Y-%m"); +$nowyear = strftime("%Y", dol_now()); +$nowyearmonth = strftime("%Y-%m", dol_now()); @@ -339 +260,2 @@ -for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { +for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) +{ @@ -341,3 +263 @@ - if ($mois > 12) { - $mois_modulo = $mois - 12; - } // ajout + if ($mois > 12) {$mois_modulo = $mois - 12; } // ajout @@ -356 +276,2 @@ - for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta + for ($annee = $year_start - 1; $annee <= $year_end; $annee++) // We start one year before to have data to be able to make delta + { @@ -358,3 +279 @@ - if ($mois > 12) { - $annee_decalage = $annee + 1; - } + if ($mois > 12) {$annee_decalage = $annee + 1; } @@ -364 +283,2 @@ - if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. + if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. + { @@ -366 +286 @@ - // Value turnover of month w/o VAT + // Valeur CA du mois w/o VAT @@ -368 +288,2 @@ - if (!empty($cum_ht[$case])) { + if ($cum_ht[$case]) + { @@ -371,6 +292,5 @@ - } else { - if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { - print '0'; - } else { - print ' '; - } + } + else + { + if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } + else { print ' '; } @@ -381 +301 @@ - // Value turnover of month + // Valeur CA du mois @@ -383 +303,2 @@ - if (!empty($cum[$case])) { + if ($cum[$case]) + { @@ -385,3 +306 @@ - if ($modecompta != 'BOOKKEEPING') { - print ''; - } + if ($modecompta != 'BOOKKEEPING') print ''; @@ -389,9 +308,6 @@ - if ($modecompta != 'BOOKKEEPING') { - print ''; - } - } else { - if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { - print '0'; - } else { - print ' '; - } + if ($modecompta != 'BOOKKEEPING') print ''; + } + else + { + if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } + else { print ' '; } @@ -401,3 +317,5 @@ - // Percentage of month - if ($annee_decalage > $minyear && $case <= $casenow) { - if (!empty($cum[$caseprev]) && !empty($cum[$case])) { + // Pourcentage du mois + if ($annee_decalage > $minyear && $case <= $casenow) + { + if ($cum[$caseprev] && $cum[$case]) + { @@ -408 +326,2 @@ - if (!empty($cum[$caseprev]) && empty($cum[$case])) { + if ($cum[$caseprev] && !$cum[$case]) + { @@ -411 +330,2 @@ - if (empty($cum[$caseprev]) && !empty($cum[$case])) { + if (!$cum[$caseprev] && $cum[$case]) + { @@ -415 +335,2 @@ - if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) { + if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case]) + { @@ -418 +339,2 @@ - if (!isset($cum[$caseprev]) && empty($cum[$case])) { + if (!isset($cum[$caseprev]) && !$cum[$case]) + { @@ -421 +343,3 @@ - } else { + } + else + { @@ -423,5 +347,2 @@ - if ($minyearmonth <= $case && $case <= $maxyearmonth) { - print '-'; - } else { - print ' '; - } + if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } + else { print ' '; } @@ -431,15 +352,5 @@ - if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) { - print ''; - } - } - - if (empty($total_ht[$annee])) { - $total_ht[$annee] = ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); - } else { - $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); - } - if (empty($total[$annee])) { - $total[$annee] = (empty($cum[$case]) ? 0 : $cum[$case]); - } else { - $total[$annee] += (empty($cum[$case]) ? 0 : $cum[$case]); - } + if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print ''; + } + + $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); + $total[$annee] += $cum[$case]; @@ -453 +364,2 @@ -for ($annee = $year_start; $annee <= $year_end; $annee++) { +for ($annee = $year_start; $annee <= $year_end; $annee++) +{ @@ -456,5 +368,6 @@ - if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { - print '"; - } else { + if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) + { + print '"; + } + else + { @@ -466,3 +379,6 @@ - if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { - print '"; - } else { + if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) + { + print '"; + } + else + { @@ -473 +389,2 @@ - if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) { + if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) + { @@ -476,5 +393,4 @@ - print ''; - } - if (!empty($total[$annee - 1]) && empty($total[$annee])) { + print ''; + } + if ($total[$annee - 1] && !$total[$annee]) + { @@ -483 +399,2 @@ - if (empty($total[$annee - 1]) && !empty($total[$annee])) { + if (!$total[$annee - 1] && $total[$annee]) + { @@ -486 +403,2 @@ - if (empty($total[$annee - 1]) && empty($total[$annee])) { + if (!$total[$annee - 1] && !$total[$annee]) + { @@ -489 +407,3 @@ - } else { + } + else + { @@ -491,5 +411,2 @@ - if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { - print '-'; - } else { - print ' '; - } + if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { print '-'; } + else { print ' '; } @@ -499,3 +416 @@ - if ($annee != $year_end) { - print ''; - } + if ($annee != $year_end) print ''; --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_supplier_turnover_by_prodserv.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_supplier_turnover_by_prodserv.php @@ -23 +22,0 @@ -// Load Dolibarr environment @@ -33,0 +33,7 @@ +// Security pack (data & check) +$socid = GETPOST('socid', 'int'); + +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); + @@ -36,12 +42,6 @@ -if (GETPOST("modecompta")) { - $modecompta = GETPOST("modecompta"); -} - -$sortorder = GETPOST("sortorder", 'aZ09comma'); -$sortfield = GETPOST("sortfield", 'aZ09comma'); -if (!$sortorder) { - $sortorder = "asc"; -} -if (!$sortfield) { - $sortfield = "ref"; -} +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta"); + +$sortorder = isset($_GET["sortorder"]) ? $_GET["sortorder"] : $_POST["sortorder"]; +$sortfield = isset($_GET["sortfield"]) ? $_GET["sortfield"] : $_POST["sortfield"]; +if (!$sortorder) $sortorder = "asc"; +if (!$sortfield) $sortfield = "ref"; @@ -58,6 +58 @@ -if ($selected_type == '') { - $selected_type = -1; -} - -// Hook -$hookmanager->initHooks(array('supplierturnoverbyprodservlist')); +if ($selected_type == '') $selected_type = -1; @@ -74,3 +69,4 @@ -if (empty($year)) { - $year_current = dol_print_date(dol_now(), '%Y'); - $month_current = dol_print_date(dol_now(), '%m'); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -80 +76 @@ - $month_current = dol_print_date(dol_now(), '%m'); + $month_current = strftime("%m", dol_now()); @@ -83,2 +79,2 @@ -$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere +$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); +$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); @@ -86 +82,2 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ @@ -88 +85,2 @@ - if (empty($q)) { + if (empty($q)) + { @@ -90 +88 @@ - $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); @@ -93,2 +91,4 @@ - if (!GETPOST("month")) { // If month not forced - if (!GETPOST('year') && $month_start > $month_current) { + if (!GETPOST("month")) // If month not forced + { + if (!GETPOST('year') && $month_start > $month_current) + { @@ -99,5 +99,2 @@ - if ($month_end < 1) { - $month_end = 12; - } else { - $year_end++; - } + if ($month_end < 1) $month_end = 12; + else $year_end++; @@ -105,19 +102,8 @@ - $date_start = dol_get_first_day($year_start, $month_start, false); - $date_end = dol_get_last_day($year_end, $month_end, false); - } else { - 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); - } + $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false); + } + else + { + 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); } @@ -137,9 +123,3 @@ -if (!empty($modecompta)) { - $commonparams['modecompta'] = $modecompta; -} -if (!empty($sortorder)) { - $commonparams['sortorder'] = $sortorder; -} -if (!empty($sortfield)) { - $commonparams['sortfield'] = $sortfield; -} +if (!empty($modecompta)) $commonparams['modecompta'] = $modecompta; +if (!empty($sortorder)) $commonparams['sortorder'] = $sortorder; +if (!empty($sortfield)) $commonparams['sortfield'] = $sortfield; @@ -148,24 +128,8 @@ -if (!empty($date_startyear)) { - $headerparams['date_startyear'] = $date_startyear; -} -if (!empty($date_startmonth)) { - $headerparams['date_startmonth'] = $date_startmonth; -} -if (!empty($date_startday)) { - $headerparams['date_startday'] = $date_startday; -} -if (!empty($date_endyear)) { - $headerparams['date_endyear'] = $date_endyear; -} -if (!empty($date_endmonth)) { - $headerparams['date_endmonth'] = $date_endmonth; -} -if (!empty($date_endday)) { - $headerparams['date_endday'] = $date_endday; -} -if (!empty($year)) { - $headerparams['year'] = $year; -} -if (!empty($month)) { - $headerparams['month'] = $month; -} +if (!empty($date_startyear)) $headerparams['date_startyear'] = $date_startyear; +if (!empty($date_startmonth)) $headerparams['date_startmonth'] = $date_startmonth; +if (!empty($date_startday)) $headerparams['date_startday'] = $date_startday; +if (!empty($date_endyear)) $headerparams['date_endyear'] = $date_endyear; +if (!empty($date_endmonth)) $headerparams['date_endmonth'] = $date_endmonth; +if (!empty($date_endday)) $headerparams['date_endday'] = $date_endday; +if (!empty($year)) $headerparams['year'] = $year; +if (!empty($month)) $headerparams['month'] = $month; @@ -175,9 +139,3 @@ -if (!empty($selected_cat)) { - $tableparams['search_categ'] = $selected_cat; -} -if (!empty($selected_soc)) { - $tableparams['search_soc'] = $selected_soc; -} -if (!empty($selected_type)) { - $tableparams['search_type'] = $selected_type; -} +if (!empty($selected_cat)) $tableparams['search_categ'] = $selected_cat; +if (!empty($selected_soc)) $tableparams['search_soc'] = $selected_soc; +if (!empty($selected_type)) $tableparams['search_type'] = $selected_type; @@ -191 +148,0 @@ -$paramslink = ''; @@ -194,13 +150,0 @@ -} - -// Security pack (data & check) -$socid = GETPOST('socid', 'int'); - -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); @@ -220,6 +164,2 @@ -if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -} -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} +if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES"; +if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES"; @@ -235 +175,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -242,18 +184,16 @@ -} elseif ($modecompta == "BOOKKEEPING") { -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { -} - -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) { - $periodlink = ''.img_previous().''.img_next().''; -} else { - $periodlink = ''; -} - -$exportlink = ''; - -report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode); - -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { +} +elseif ($modecompta == "BOOKKEEPING") +{ +} +elseif ($modecompta == "BOOKKEEPINGCOLLECTED") +{ +} + +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().''.img_next().''; +else $periodlink = ''; + +report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode); + +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ @@ -272 +212,2 @@ -if ($modecompta == 'CREANCES-DETTES') { +if ($modecompta == 'CREANCES-DETTES') +{ @@ -277,4 +218,2 @@ - if ($selected_soc > 0) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc ON (soc.rowid = f.fk_soc)"; - } - $sql .= ",".MAIN_DB_PREFIX."facture_fourn_det as l"; + if ($selected_soc > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc ON (soc.rowid = f.fk_soc)"; + $sql .= ",".MAIN_DB_PREFIX."facture_fourn_det as l"; @@ -282 +221,2 @@ - if ($selected_cat === -2) { // Without any category + if ($selected_cat === -2) // Without any category + { @@ -284 +224,3 @@ - } elseif ($selected_cat) { // Into a specific category + } + elseif ($selected_cat) // Into a specific category + { @@ -294,4 +236,6 @@ - if ($selected_type >= 0) { - $sql .= " AND l.product_type = ".((int) $selected_type); - } - if ($selected_cat === -2) { // Without any category + if ($selected_type >= 0) + { + $sql .= " AND l.product_type = ".$selected_type; + } + if ($selected_cat === -2) // Without any category + { @@ -299,5 +243,4 @@ - } elseif ($selected_cat) { // Into a specific category - $sql .= " AND (c.rowid = ".((int) $selected_cat); - if ($subcat) { - $sql .= " OR c.fk_parent = ".((int) $selected_cat); - } + } + elseif ($selected_cat) { // Into a specific category + $sql .= " AND (c.rowid = ".$selected_cat; + if ($subcat) $sql .= " OR c.fk_parent = ".$selected_cat; @@ -307,3 +250 @@ - if ($selected_soc > 0) { - $sql .= " AND soc.rowid=".((int) $selected_soc); - } + if ($selected_soc > 0) $sql .= " AND soc.rowid=".$selected_soc; @@ -315,3 +256,3 @@ - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); @@ -320,2 +261 @@ - $obj = $db->fetch_object($resql); - + $obj = $db->fetch_object($result); @@ -327 +266,0 @@ - @@ -331 +269,0 @@ - @@ -343 +281,2 @@ - foreach ($headerparams as $key => $value) { + foreach ($headerparams as $key => $value) + { @@ -347,4 +286,4 @@ - $moreforfilter = ''; - - print '
'; - print '
'; + // type filter (produit/service) + print ' '; + print $langs->trans("Type").': '; + $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', 1, 1, 1); + + //select thirdparty + print '
'; + print $langs->trans("ThirdParty").': '.$form->select_thirdparty_list($selected_soc, 'search_soc', '', 1); + print '
'; @@ -421,3 +329 @@ - print '
".$linkname."'; - if ($modecompta == 'RECETTES-DEPENSES') { - if ($key > 0) { - //print ''; - } else { - //print ''; - } - } elseif ($modecompta == 'CREANCES-DETTES') { - if ($key > 0) { - print ''; - } else { - //print ''; - } - print price($amount_ht[$key]); - if ($key > 0) { - print ''; - } - } - print ''; - if ($modecompta == 'RECETTES-DEPENSES') { - if ($key > 0) { - //print ''; - } else { - //print ''; - } - } elseif ($modecompta == 'CREANCES-DETTES') { - if ($key > 0) { - print ''; - } else { - //print ''; - } - } - print price($amount[$key]); - if ($modecompta == 'RECETTES-DEPENSES') { - if ($key > 0) { - //print ''; - } else { - //print ''; - } - } elseif ($modecompta == 'CREANCES-DETTES') { - if ($key > 0) { - print ''; - } - } - print ''.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : ' ').''; - if (isModEnabled("propal") && $key > 0) { - print ' '.img_picto($langs->trans("ProposalStats"), "stats").' '; - } - if (isModEnabled('commande') && $key > 0) { - print ' '.img_picto($langs->trans("OrderStats"), "stats").' '; - } - if (isModEnabled('facture') && $key > 0) { - print ' '.img_picto($langs->trans("InvoiceStats"), "stats").' '; - } - print '
'.$langs->trans("Total").''.price($catotal_ht).''.price($catotal).'  
".$linkname."'; + if ($modecompta == 'RECETTES-DEPENSES') { + if ($key > 0) { + //print ''; + } else { + //print ''; + } + } + elseif ($modecompta == 'CREANCES-DETTES') { + if ($key > 0) { + print ''; + } else { + //print ''; + } + print price($amount_ht[$key]); + if ($key > 0) print ''; + } + print ''; + if ($modecompta == 'RECETTES-DEPENSES') { + if ($key > 0) { + //print ''; + } else { + //print ''; + } + } + elseif ($modecompta == 'CREANCES-DETTES') { + if ($key > 0) { + print ''; + } else { + //print ''; + } + } + print price($amount[$key]); + if ($modecompta == 'RECETTES-DEPENSES') { + if ($key > 0) { + //print ''; + } else { + //print ''; + } + } + elseif ($modecompta == 'CREANCES-DETTES') { + if ($key > 0) { + print ''; + } + } + print ''.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : ' ').''; + if (!empty($conf->propal->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("ProposalStats"), "stats").' '; + } + if (!empty($conf->commande->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("OrderStats"), "stats").' '; + } + if (!empty($conf->facture->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("InvoiceStats"), "stats").' '; + } + print '
'.$langs->trans("Total").''.price($catotal_ht).''.price($catotal).'  
'; -print img_picto('', 'category', 'class="paddingrightonly"'); -print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', 0, $langs->trans("Category")); +print ''; +print $langs->trans("Category").': '.$formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_cat, 'search_categ', true); @@ -455 +375 @@ - print ' checked'; + print ' checked'; @@ -465 +385 @@ -print ''; +print ''; @@ -468 +388 @@ -print ''; +print ''; @@ -471 +391 @@ -print ''; +print ''; @@ -474 +394 @@ -print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); +print $form->select_country($search_country, 'search_country'); @@ -492,3 +412,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -502,3 +421,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -512,3 +430,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -522,3 +439,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -526,10 +442,10 @@ - print_liste_field_titre( - $langs->trans('AmountHT'), - $_SERVER["PHP_SELF"], - "amount_ht", - "", - $paramslink, - 'class="right"', - $sortfield, - $sortorder - ); + print_liste_field_titre( + $langs->trans('AmountHT'), + $_SERVER["PHP_SELF"], + "amount_ht", + "", + $paramslink, + 'class="right"', + $sortfield, + $sortorder + ); @@ -537 +453 @@ - print_liste_field_titre(''); + print_liste_field_titre(''); @@ -582,2 +498,2 @@ - asort($amount_ht); - $arrayforsort = $amount_ht; + asort($amount_ht); + $arrayforsort = $amount_ht; @@ -586,2 +502,2 @@ - arsort($amount_ht); - $arrayforsort = $amount_ht; + arsort($amount_ht); + $arrayforsort = $amount_ht; @@ -622 +538 @@ - foreach ($arrayforsort as $key => $value) { + foreach ($arrayforsort as $key=>$value) { @@ -628,4 +544,4 @@ - $thirdparty_static->id = $key; - $thirdparty_static->name = $fullname; - $thirdparty_static->client = 1; - $linkname = $thirdparty_static->getNomUrl(1, 'customer'); + $thirdparty_static->id = $key; + $thirdparty_static->name = $fullname; + $thirdparty_static->client = 1; + $linkname = $thirdparty_static->getNomUrl(1, 'customer'); @@ -635 +551 @@ - print ''.$linkname."".$linkname."'; + print ''; @@ -645 +561 @@ - print ''; + print ''; @@ -652,5 +568,5 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } + if ($key > 0) { + print ''; + } else { + print ''; + } @@ -658,6 +574,6 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } - print price($amount_ht[$key]); + if ($key > 0) { + print ''; + } else { + print ''; + } + print price($amount_ht[$key]); @@ -670,5 +586,5 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } + if ($key > 0) { + print ''; + } else { + print ''; + } @@ -676,5 +592,5 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } + if ($key > 0) { + print ''; + } else { + print ''; + } @@ -689,15 +605,15 @@ - // Other stats - print ''; - if (isModEnabled("propal") && $key > 0) { - print ' '.img_picto($langs->trans("ProposalStats"), "stats").' '; - } - if (isModEnabled('commande') && $key > 0) { - print ' '.img_picto($langs->trans("OrderStats"), "stats").' '; - } - if (isModEnabled('facture') && $key > 0) { - print ' '.img_picto($langs->trans("InvoiceStats"), "stats").' '; - } - print '
'; + if (!empty($conf->propal->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("ProposalStats"), "stats").' '; + } + if (!empty($conf->commande->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("OrderStats"), "stats").' '; + } + if (!empty($conf->facture->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("InvoiceStats"), "stats").' '; + } + print '
'.price($catotal_ht).''.price($catotal_ht).''; - } else { - print ''; - } - if ($modecompta != 'BOOKKEEPING') { - print ''; - } +for ($annee = $year_start; $annee <= $year_end; $annee++) +{ + if ($modecompta == 'CREANCES-DETTES') print ''; + else print ''; + if ($modecompta != 'BOOKKEEPING') print ''; @@ -344,10 +282,4 @@ - if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) { - print '-'.($annee + 1); - } - if ($modecompta != 'BOOKKEEPING') { - print ''; - } - print '  '.$langs->trans("AmountHT").''; - if ($modecompta == "BOOKKEEPING") { - print $langs->trans("Amount"); - } else { - print $langs->trans("AmountTTC"); - } - print ''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'  '.($percent >= 0 ? "+$percent" : "$percent").'%-100%+Inf%-+0%-'; - //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end); - if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { - if ($annee_decalage > $minyear && $case <= $casenow) { - if (!empty($cum[$caseprev]) && !empty($cum[$case]) && $cum[$caseprev] != 0) { - $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100); - //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; - print($percent >= 0 ? "+$percent" : "$percent").'%'; - } - if (!empty($cum[$caseprev]) && empty($cum[$case])) { - print '-100%'; - } - if (empty($cum[$caseprev]) && !empty($cum[$case])) { - //print '+Inf%'; + if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } + else { print ' '; } + print '  '; - print(empty($total_ht[$annee]) ? '0' : price($total_ht[$annee])); - print "'.($total_ht[$annee] ?price($total_ht[$annee]) : "0")."'; - print(empty($total[$annee]) ? '0' : price($total[$annee])); - print "'.($total[$annee] ?price($total[$annee]) : "0")."'; - print($percent >= 0 ? "+$percent" : "$percent").'%'; - print ''.($percent >= 0 ? "+$percent" : "$percent").'%   '; - } else { - print ''; - } - if ($modecompta != 'BOOKKEEPING') { - print ''; - } +for ($annee = $year_start; $annee <= $year_end; $annee++) +{ + if ($modecompta == 'CREANCES-DETTES') print ''; + else print ''; + if ($modecompta != 'BOOKKEEPING') print ''; @@ -295,10 +232,4 @@ - if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) { - print '-'.($annee + 1); - } - if ($modecompta != 'BOOKKEEPING') { - print ''; - } - print '  '.$langs->trans("AmountHT").''; - if ($modecompta == "BOOKKEEPING") { - print $langs->trans("Amount"); - } else { - print $langs->trans("AmountTTC"); - } - print ''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'    '; - print($total_ht[$annee] ? price($total_ht[$annee]) : "0"); - print "'.($total_ht[$annee] ?price($total_ht[$annee]) : "0")."'.($total[$annee] ? price($total[$annee]) : "0")."'.($total[$annee] ?price($total[$annee]) : "0")."'; - print($percent >= 0 ? "+$percent" : "$percent").'%'; - print ''.($percent >= 0 ? "+$percent" : "$percent").'%  
'."\n"; + $moreforfilter = ''; + + print '
'; + print '
'."\n"; @@ -355,2 +294 @@ - print img_picto('', 'category', 'class="paddingrightonly"'); - print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', 0, $langs->trans("Category")); + print $langs->trans("Category").': '.$formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', true); @@ -364,12 +302,11 @@ - // type filter (produit/service) - print ' '; - print $langs->trans("Type").': '; - $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', 1, 1, 1); - - //select thirdparty - print '
'; - print img_picto('', 'company', 'class="paddingrightonly"'); - print $form->select_thirdparty_list($selected_soc, 'search_soc', '', $langs->trans("ThirdParty")); - print ''; - - print ''; + + print ''; + print ""; @@ -415,0 +353,10 @@ + $classslink, + 'class="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans("AmountTTC"), + $_SERVER["PHP_SELF"], + "amount_ttc", + "", @@ -422 +369 @@ - $langs->trans("AmountTTC"), + $langs->trans("Percentage"), @@ -431,10 +377,0 @@ - print_liste_field_titre( - $langs->trans("Percentage"), - $_SERVER["PHP_SELF"], - "amount_ttc", - "", - $paramslink, - 'class="right"', - $sortfield, - $sortorder - ); @@ -444 +381 @@ - foreach ($name as $key => $value) { + foreach ($name as $key=>$value) { --- /tmp/dsg/dolibarr/htdocs/compta/stats/github_19.0.3_supplier_turnover_by_thirdparty.php +++ /tmp/dsg/dolibarr/htdocs/compta/stats/client_supplier_turnover_by_thirdparty.php @@ -3 +2,0 @@ - * Copyright (C) 2023 Ferran Marcet @@ -20,2 +19,2 @@ - * \file htdocs/compta/stats/supplier_turnover_by_thirdparty.php - * \brief Page reporting purchase turnover by thirdparty + * \file htdocs/compta/stats/supplier_ca_by_thirdparty.php + * \brief Page reporting purchase turnover by thirdparty @@ -24,2 +22,0 @@ - -// Load Dolibarr environment @@ -26,0 +24,4 @@ +require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -29,4 +29,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; @@ -40,14 +37,6 @@ -if (GETPOST("modecompta")) { - $modecompta = GETPOST("modecompta"); -} - -// Sort Order -$sortorder = GETPOST("sortorder", 'aZ09comma'); -$sortfield = GETPOST("sortfield", 'aZ09comma'); -if (!$sortorder) { - $sortorder = "asc"; -} -if (!$sortfield) { - $sortfield = "nom"; -} - +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta"); + +$sortorder = isset($_GET["sortorder"]) ? $_GET["sortorder"] : $_POST["sortorder"]; +$sortfield = isset($_GET["sortfield"]) ? $_GET["sortfield"] : $_POST["sortfield"]; +if (!$sortorder) $sortorder = "asc"; +if (!$sortfield) $sortfield = "nom"; @@ -61,8 +50,11 @@ - $subcat = true; -} - -// Hook -$hookmanager->initHooks(array('supplierturnoverbythirdpartylist')); - - -// Search Parameters + $subcat = true; +} + +// Security check +if ($user->socid > 0) $socid = $user->socid; +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); + +// Date range +$year = GETPOST("year", 'int'); +$month = GETPOST("month", 'int'); @@ -73,5 +64,0 @@ - - -// Date range -$year = GETPOST("year", 'int'); -$month = GETPOST("month", 'int'); @@ -84,3 +71,4 @@ -if (empty($year)) { - $year_current = dol_print_date(dol_now(), '%Y'); - $month_current = dol_print_date(dol_now(), '%m'); +if (empty($year)) +{ + $year_current = strftime("%Y", dol_now()); + $month_current = strftime("%m", dol_now()); @@ -90 +78 @@ - $month_current = dol_print_date(dol_now(), '%m'); + $month_current = strftime("%m", dol_now()); @@ -93,2 +81,2 @@ -$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere -$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere +$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); +$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); @@ -96,3 +84,5 @@ -if (empty($date_start) || empty($date_end)) { // We define date_start and date_end - $q = GETPOST("q", "int") ? GETPOST("q", "int") : 0; - if (empty($q)) { +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q = GETPOST("q", "int") ?GETPOST("q", "int") : 0; + if (empty($q)) + { @@ -100 +90 @@ - $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); @@ -103,2 +93,4 @@ - if (!GETPOST("month")) { // If month not forced - if (!GETPOST('year') && $month_start > $month_current) { + if (!GETPOST("month")) // If month not forced + { + if (!GETPOST('year') && $month_start > $month_current) + { @@ -109,5 +101,2 @@ - if ($month_end < 1) { - $month_end = 12; - } else { - $year_end++; - } + if ($month_end < 1) $month_end = 12; + else $year_end++; @@ -115,20 +104,9 @@ - $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); - } -} else { + $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); } +} +else +{ @@ -156,0 +135 @@ +$headerparams['q'] = $q; @@ -171 +149,0 @@ -$paramslink = ''; @@ -173,12 +151 @@ - $paramslink .= '&'.$key.'='.$value; -} - -// Security check -if ($user->socid > 0) { - $socid = $user->socid; -} -if (isModEnabled('comptabilite')) { - $result = restrictedArea($user, 'compta', '', '', 'resultat'); -} -if (isModEnabled('accounting')) { - $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); + $paramslink .= '&'.$key.'='.$value; @@ -199,6 +166,2 @@ -if ($modecompta == "BOOKKEEPING") { - $modecompta = "CREANCES-DETTES"; -} -if ($modecompta == "BOOKKEEPINGCOLLECTED") { - $modecompta = "RECETTES-DEPENSES"; -} +if ($modecompta == "BOOKKEEPING") $modecompta = "CREANCES-DETTES"; +if ($modecompta == "BOOKKEEPINGCOLLECTED") $modecompta = "RECETTES-DEPENSES"; @@ -207 +170,2 @@ -if ($modecompta == "CREANCES-DETTES") { +if ($modecompta == "CREANCES-DETTES") +{ @@ -211,0 +176 @@ + $builddate = dol_now(); @@ -213 +178,3 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} +elseif ($modecompta == "RECETTES-DEPENSES") +{ @@ -217,0 +185 @@ + $builddate = dol_now(); @@ -219,16 +187,10 @@ -} elseif ($modecompta == "BOOKKEEPING") { - // TODO -} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") { - // TODO -} -$builddate = dol_now(); -$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -$period .= ' - '; -$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver'); -if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) { - $periodlink = ''.img_previous().' '.img_next().''; -} else { - $periodlink = ''; -} - -$exportlink = ''; +} +elseif ($modecompta == "BOOKKEEPING") +{ +} +elseif ($modecompta == "BOOKKEEPINGCOLLECTED") +{ +} +$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); +if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink = ''.img_previous().' '.img_next().''; +else $periodlink = ''; @@ -238,2 +200,3 @@ -if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') { - print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +{ + print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); @@ -252,4 +215,7 @@ - if ($selected_cat === -2) { // Without any category - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc"; - } elseif ($selected_cat) { // Into a specific category - $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_fournisseur as cs"; + if ($selected_cat === -2) // Without any category + { + $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; + } + elseif ($selected_cat) // Into a specific category + { + $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs"; @@ -261,10 +227,10 @@ - $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - } - if ($selected_cat === -2) { // Without any category - $sql .= " AND cs.fk_soc is null"; - } elseif ($selected_cat) { // Into a specific category - $sql .= " AND (c.rowid = ".((int) $selected_cat); - if ($subcat) { - $sql .= " OR c.fk_parent = ".((int) $selected_cat); - } - $sql .= ")"; + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + } + if ($selected_cat === -2) // Without any category + { + $sql .= " AND cs.fk_soc is null"; + } + elseif ($selected_cat) { // Into a specific category + $sql .= " AND (c.rowid = ".$db->escape($selected_cat); + if ($subcat) $sql .= " OR c.fk_parent = ".$db->escape($selected_cat); + $sql .= ")"; @@ -273 +239 @@ -} elseif ($modecompta == "RECETTES-DEPENSES") { +} else { @@ -279,4 +245,7 @@ - if ($selected_cat === -2) { // Without any category - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc"; - } elseif ($selected_cat) { // Into a specific category - $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_fournisseur as cs"; + if ($selected_cat === -2) // Without any category + { + $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; + } + elseif ($selected_cat) // Into a specific category + { + $sql .= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_societe as cs"; @@ -288,10 +257,10 @@ - $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - } - if ($selected_cat === -2) { // Without any category - $sql .= " AND cs.fk_soc is null"; - } elseif ($selected_cat) { // Into a specific category - $sql .= " AND (c.rowid = ".((int) $selected_cat); - if ($subcat) { - $sql .= " OR c.fk_parent = ".((int) $selected_cat); - } - $sql .= ")"; + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + } + if ($selected_cat === -2) // Without any category + { + $sql .= " AND cs.fk_soc is null"; + } + elseif ($selected_cat) { // Into a specific category + $sql .= " AND (c.rowid = ".$selected_cat; + if ($subcat) $sql .= " OR c.fk_parent = ".$selected_cat; + $sql .= ")"; @@ -301,12 +270,4 @@ -if (!empty($search_societe)) { - $sql .= natural_search('s.nom', $search_societe); -} -if (!empty($search_zip)) { - $sql .= natural_search('s.zip', $search_zip); -} -if (!empty($search_town)) { - $sql .= natural_search('s.town', $search_town); -} -if ($search_country > 0) { - $sql .= ' AND s.fk_pays = '.((int) $search_country); -} +if (!empty($search_societe)) $sql .= natural_search('s.nom', $search_societe); +if (!empty($search_zip)) $sql .= natural_search('s.zip', $search_zip); +if (!empty($search_town)) $sql .= natural_search('s.town', $search_town); +if ($search_country > 0) $sql .= ' AND s.fk_pays = '.$search_country.''; @@ -314,3 +275 @@ -if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); -} +if ($socid) $sql .= " AND f.fk_soc = ".$socid; @@ -321,3 +279,0 @@ -$catotal_ht = 0; -$catotal = 0; - @@ -325,3 +281,3 @@ -$resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); +$result = $db->query($sql); +if ($result) { + $num = $db->num_rows($result); @@ -330,14 +286,10 @@ - $obj = $db->fetch_object($resql); - - $amount_ht[$obj->socid] = (empty($obj->amount) ? 0 : $obj->amount); - $amount[$obj->socid] = $obj->amount_ttc; - $name[$obj->socid] = $obj->name; - - $address_zip[$obj->socid] = $obj->zip; - $address_town[$obj->socid] = $obj->town; - $address_pays[$obj->socid] = getCountry($obj->fk_pays); - - $catotal_ht += (empty($obj->amount) ? 0 : $obj->amount); - $catotal += $obj->amount_ttc; - - $i++; + $obj = $db->fetch_object($result); + $amount_ht[$obj->socid] = $obj->amount; + $amount[$obj->socid] = $obj->amount_ttc; + $name[$obj->socid] = $obj->name.' '.$obj->firstname; + $address_zip[$obj->socid] = $obj->zip; + $address_town[$obj->socid] = $obj->town; + $address_pays[$obj->socid] = getCountry($obj->fk_pays); + $catotal_ht += $obj->amount; + $catotal += $obj->amount_ttc; + $i++; @@ -354,2 +306,3 @@ -foreach ($headerparams as $key => $value) { - print ''; +foreach ($headerparams as $key => $value) +{ + print ''; @@ -366,2 +319 @@ -print img_picto('', 'category', 'class="paddingrightonly"'); -print $formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat, 'search_categ', 0, $langs->trans("Category")); +print $langs->trans("Category").': '.$formother->select_categories(Categorie::TYPE_SUPPLIER, $selected_cat, 'search_categ', true); @@ -372 +324 @@ - print ' checked'; + print ' checked'; @@ -382 +334 @@ -print ''; +print ''; @@ -385 +337 @@ -print ''; +print ''; @@ -388 +340 @@ -print ''; +print ''; @@ -409,3 +361,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -419,3 +370,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -429,3 +379,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -439,3 +388,2 @@ - $sortfield, - $sortorder -); + $sortfield, $sortorder + ); @@ -443,10 +391,10 @@ - print_liste_field_titre( - $langs->trans('AmountHT'), - $_SERVER["PHP_SELF"], - "amount_ht", - "", - $paramslink, - 'class="right"', - $sortfield, - $sortorder - ); + print_liste_field_titre( + $langs->trans('AmountHT'), + $_SERVER["PHP_SELF"], + "amount_ht", + "", + $paramslink, + 'class="right"', + $sortfield, + $sortorder + ); @@ -454 +402 @@ - print_liste_field_titre(''); + print_liste_field_titre(''); @@ -499,2 +447,2 @@ - asort($amount_ht); - $arrayforsort = $amount_ht; + asort($amount_ht); + $arrayforsort = $amount_ht; @@ -503,2 +451,2 @@ - arsort($amount_ht); - $arrayforsort = $amount_ht; + arsort($amount_ht); + $arrayforsort = $amount_ht; @@ -539 +487 @@ - foreach ($arrayforsort as $key => $value) { + foreach ($arrayforsort as $key=>$value) { @@ -545,4 +493,4 @@ - $thirdparty_static->id = $key; - $thirdparty_static->name = $fullname; - $thirdparty_static->client = 1; - $linkname = $thirdparty_static->getNomUrl(1, 'supplier'); + $thirdparty_static->id = $key; + $thirdparty_static->name = $fullname; + $thirdparty_static->client = 1; + $linkname = $thirdparty_static->getNomUrl(1, 'supplier'); @@ -569,5 +517,5 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } + if ($key > 0) { + print ''; + } else { + print ''; + } @@ -575,6 +523,6 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } - print price($amount_ht[$key]); + if ($key > 0) { + print ''; + } else { + print ''; + } + print price($amount_ht[$key]); @@ -587,5 +535,5 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } + if ($key > 0) { + print ''; + } else { + print ''; + } @@ -593,5 +541,5 @@ - if ($key > 0) { - print ''; - } else { - print ''; - } + if ($key > 0) { + print ''; + } else { + print ''; + } @@ -606,15 +554,15 @@ - // Other stats - print ''; - print "\n"; - $i++; - } + // Other stats + print ''; + print "\n"; + $i++; + } @@ -629 +577 @@ - print ''; + print ''; @@ -631 +579 @@ - print ''; + print '';
'; + // type filter (produit/service) + print ' '; + print $langs->trans("Type").': '; + $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', 1, 1, 1); + + //select thirdparty + print '
'; + print $langs->trans("ThirdParty").': '.$form->select_thirdparty_list($selected_soc, 'search_soc', '', 1); + print '
'; @@ -380 +317 @@ - print '
'; - if (isModEnabled('supplier_proposal') && $key > 0) { - print ' '.img_picto($langs->trans("ProposalStats"), "stats").' '; - } - if (isModEnabled("supplier_order") && $key > 0) { - print ' '.img_picto($langs->trans("OrderStats"), "stats").' '; - } - if (isModEnabled("supplier_invoice") && $key > 0) { - print ' '.img_picto($langs->trans("InvoiceStats"), "stats").' '; - } - print '
'; + if (!empty($conf->supplier_proposal->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("ProposalStats"), "stats").' '; + } + if (!empty($conf->fournisseur->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("OrderStats"), "stats").' '; + } + if (!empty($conf->fournisseur->enabled) && $key > 0) { + print ' '.img_picto($langs->trans("InvoiceStats"), "stats").' '; + } + print '
'.price($catotal_ht).''.price($catotal_ht).'