From 8079105aaf73036fd39069bd84cead308eeea3ed Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 16 Feb 2021 04:28:55 +0100 Subject: [PATCH 01/31] NEW: VAT report - Optimisation & collapse by rate --- htdocs/compta/tva/index.php | 780 +++++++++++++++------------- htdocs/compta/tva/quadri_detail.php | 679 +++++++++++++----------- htdocs/core/lib/tax.lib.php | 50 +- htdocs/langs/en_US/compta.lang | 1 + 4 files changed, 804 insertions(+), 706 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 081023cd2e8..ec62f28d32a 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -41,55 +41,93 @@ $now = dol_now(); $current_date = dol_getdate($now); if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1; -// Date range -$year = GETPOST("year", "int"); -if (empty($year)) -{ - $year_current = $current_date['year']; - $year_start = $year_current; +$refresh = GETPOSTISSET('submit') ? true : false; + +if ($refresh === false) { + $year_current = intval(strftime('%Y', $now)); + $month_current = intval(strftime('%m', $now)); + + // 1 : Monthly (by default) + // 2 : Quarterly + // 3 : Annual + if ($conf->global->MAIN_INFO_VAT_RETURN == 2) { + // quarterly + $year = $year_current; + if ($month_current >= 7 && $month_current <= 9) { + $month_start = 4; + $month_end = 6; + } elseif ($month_current >= 10 && $month_current <= 12) { + $month_start = 7; + $month_end = 9; + } elseif ($month_current >= 1 && $month_current <= 3) { + $month_start = 10; + $month_end = 12; + $year--; + } else { + $month_start = 1; + $month_end = 3; + } + $date_start = dol_get_first_day($year, $month_start); + $date_end = dol_get_last_day($year, $month_end); + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { + // annual + $date_start = dol_get_first_day($year_current, 1); + $date_end = dol_get_last_day($year_current, 12); + } else { + // monthly by default + $year = $year_current; + $month_last = $month_current - 1; + if ($month_last <= 0) { + $month_last = $month_last + 12; + $year--; + } + $date_start = dol_get_first_day($year, $month_last); + $date_end = dol_get_last_day($year, $month_last); + } } else { - $year_current = $year; - $year_start = $year; -} -$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")); -// Set default period if not defined -if (empty($date_start) || empty($date_end)) // We define date_start and date_end -{ - $q = GETPOST("q", "int"); - if (empty($q)) + // Date range + $year = GETPOST("year", "int"); + if (empty($year)) { + $year_current = strftime("%Y", dol_now()); + if ($conf->global->SOCIETE_FISCAL_MONTH_START > date('m')) $year_current--; + $year_start = $year_current; + } else { + $year_current = $year; + $year_start = $year; + } + $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")); + if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } - else { - if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter - $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); - $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; - } - elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat - if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { - if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year - $year_start--; - } - } else { - if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year - $year_start--; - } - } + $q = GETPOST("q", "int"); + if (empty($q)) { + if (GETPOST("month", "int")) { + $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); + $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); + } else { $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; } - elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month - $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); - $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; + } 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 { - 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); } - } } // Define modetax (0 or 1) @@ -261,366 +299,358 @@ report_header($name, '', $period, $periodlink, $description, $builddate, $export print '
'; -print '
'; +if ($refresh === true) { + print '
'; -print load_fiche_titre($langs->trans("VATSummary"), '', ''); + print load_fiche_titre($langs->trans("VATSummary"), '', ''); -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''."\n"; -print ''."\n"; + print '
'.$langs->trans("Year")." ".$y.''.$langs->trans("VATToPay").''.$langs->trans("VATToCollect").''.$langs->trans("Balance").' 
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '' . "\n"; + print '' . "\n"; -$tmp = dol_getdate($date_start); -$y = $tmp['year']; -$m = $tmp['mon']; -$tmp = dol_getdate($date_end); -$yend = $tmp['year']; -$mend = $tmp['mon']; + $tmp = dol_getdate($date_start); + $y = $tmp['year']; + $m = $tmp['mon']; + $tmp = dol_getdate($date_end); + $yend = $tmp['year']; + $mend = $tmp['mon']; //var_dump($m); -$total = 0; $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0; -$i = 0; $mcursor = 0; + $total = 0; + $subtotalcoll = 0; + $subtotalpaye = 0; + $subtotal = 0; + $i = 0; + $mcursor = 0; -while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop -{ - //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12); - if ($m == 13) $y++; - if ($m > 12) $m -= 12; - $mcursor++; - - $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m); - $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m); - - $x_both = array(); - //now, from these two arrays, get another array with one rate per line - foreach (array_keys($x_coll) as $my_coll_rate) + while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop { - $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; - $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; - $x_both[$my_coll_rate]['paye']['totalht'] = 0; - $x_both[$my_coll_rate]['paye']['vat'] = 0; - $x_both[$my_coll_rate]['coll']['links'] = ''; - $x_both[$my_coll_rate]['coll']['detail'] = array(); - foreach ($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) { - //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; - //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; - //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; - //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]); - $x_both[$my_coll_rate]['coll']['detail'][] = array( - 'id' =>$x_coll[$my_coll_rate]['facid'][$id], - 'descr' =>$x_coll[$my_coll_rate]['descr'][$id], - 'pid' =>$x_coll[$my_coll_rate]['pid'][$id], - 'pref' =>$x_coll[$my_coll_rate]['pref'][$id], - 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], - 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id], - 'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], - 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], - 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], - 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], - 'datef' =>$x_coll[$my_coll_rate]['datef'][$id], - 'datep' =>$x_coll[$my_coll_rate]['datep'][$id], - //'company_link'=>$company_static->getNomUrl(1,'',20), - 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id], - 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], - 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], - 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], - //'link' =>$invoice_customer->getNomUrl(1,'',12) - ); - } - } + //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12); + if ($m == 13) $y++; + if ($m > 12) $m -= 12; + $mcursor++; - // tva paid - foreach (array_keys($x_paye) as $my_paye_rate) { - $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; - $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; - if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) { - $x_both[$my_paye_rate]['coll']['totalht'] = 0; - $x_both[$my_paye_rate]['coll']['vat'] = 0; - } - $x_both[$my_paye_rate]['paye']['links'] = ''; - $x_both[$my_paye_rate]['paye']['detail'] = array(); + $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m); + $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m); - foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) - { - // ExpenseReport - if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') - { - //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id]; - //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id]; - //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id]; - - $x_both[$my_paye_rate]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_rate]['facid'][$id], - 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], - 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], - 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], - 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id], - 'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id], - 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), - 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), - 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], - 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id], - 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], - 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), - 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], - //'link' =>$expensereport->getNomUrl(1) - ); - } - else { - //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; - //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; - //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; - //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]); - $x_both[$my_paye_rate]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_rate]['facid'][$id], - 'descr' =>$x_paye[$my_paye_rate]['descr'][$id], - 'pid' =>$x_paye[$my_paye_rate]['pid'][$id], - 'pref' =>$x_paye[$my_paye_rate]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], - 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id], - 'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], - 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), - 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), - 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], - 'datef' =>$x_paye[$my_paye_rate]['datef'][$id], - 'datep' =>$x_paye[$my_paye_rate]['datep'][$id], - //'company_link'=>$company_static->getNomUrl(1,'',20), - 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id], - 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], - 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), - 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], - //'link' =>$invoice_supplier->getNomUrl(1,'',12) + $x_both = array(); + //now, from these two arrays, get another array with one rate per line + foreach (array_keys($x_coll) as $my_coll_rate) { + $x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; + $x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; + $x_both[$my_coll_rate]['paye']['totalht'] = 0; + $x_both[$my_coll_rate]['paye']['vat'] = 0; + $x_both[$my_coll_rate]['coll']['links'] = ''; + $x_both[$my_coll_rate]['coll']['detail'] = array(); + foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) { + //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; + //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; + //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; + //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]); + $x_both[$my_coll_rate]['coll']['detail'][] = array( + 'id' => $x_coll[$my_coll_rate]['facid'][$id], + 'descr' => $x_coll[$my_coll_rate]['descr'][$id], + 'pid' => $x_coll[$my_coll_rate]['pid'][$id], + 'pref' => $x_coll[$my_coll_rate]['pref'][$id], + 'ptype' => $x_coll[$my_coll_rate]['ptype'][$id], + 'payment_id' => $x_coll[$my_coll_rate]['payment_id'][$id], + 'payment_amount' => $x_coll[$my_coll_rate]['payment_amount'][$id], + 'ftotal_ttc' => $x_coll[$my_coll_rate]['ftotal_ttc'][$id], + 'dtotal_ttc' => $x_coll[$my_coll_rate]['dtotal_ttc'][$id], + 'dtype' => $x_coll[$my_coll_rate]['dtype'][$id], + 'datef' => $x_coll[$my_coll_rate]['datef'][$id], + 'datep' => $x_coll[$my_coll_rate]['datep'][$id], + //'company_link'=>$company_static->getNomUrl(1,'',20), + 'ddate_start' => $x_coll[$my_coll_rate]['ddate_start'][$id], + 'ddate_end' => $x_coll[$my_coll_rate]['ddate_end'][$id], + 'totalht' => $x_coll[$my_coll_rate]['totalht_list'][$id], + 'vat' => $x_coll[$my_coll_rate]['vat_list'][$id], + //'link' =>$invoice_customer->getNomUrl(1,'',12) ); } } + + // tva paid + foreach (array_keys($x_paye) as $my_paye_rate) { + $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; + $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; + if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) { + $x_both[$my_paye_rate]['coll']['totalht'] = 0; + $x_both[$my_paye_rate]['coll']['vat'] = 0; + } + $x_both[$my_paye_rate]['paye']['links'] = ''; + $x_both[$my_paye_rate]['paye']['detail'] = array(); + + foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) { + // ExpenseReport + if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') { + //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id]; + //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id]; + //$expensereport->type=$x_paye[$my_paye_rate]['type'][$id]; + + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id' => $x_paye[$my_paye_rate]['facid'][$id], + 'descr' => $x_paye[$my_paye_rate]['descr'][$id], + 'pid' => $x_paye[$my_paye_rate]['pid'][$id], + 'pref' => $x_paye[$my_paye_rate]['pref'][$id], + 'ptype' => $x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id], + 'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id], + 'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), + 'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), + 'dtype' => $x_paye[$my_paye_rate]['dtype'][$id], + 'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id], + 'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id], + 'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), + 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id], + //'link' =>$expensereport->getNomUrl(1) + ); + } else { + //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; + //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; + //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; + //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]); + $x_both[$my_paye_rate]['paye']['detail'][] = array( + 'id' => $x_paye[$my_paye_rate]['facid'][$id], + 'descr' => $x_paye[$my_paye_rate]['descr'][$id], + 'pid' => $x_paye[$my_paye_rate]['pid'][$id], + 'pref' => $x_paye[$my_paye_rate]['pref'][$id], + 'ptype' => $x_paye[$my_paye_rate]['ptype'][$id], + 'payment_id' => $x_paye[$my_paye_rate]['payment_id'][$id], + 'payment_amount' => $x_paye[$my_paye_rate]['payment_amount'][$id], + 'ftotal_ttc' => price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), + 'dtotal_ttc' => price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), + 'dtype' => $x_paye[$my_paye_rate]['dtype'][$id], + 'datef' => $x_paye[$my_paye_rate]['datef'][$id], + 'datep' => $x_paye[$my_paye_rate]['datep'][$id], + //'company_link'=>$company_static->getNomUrl(1,'',20), + 'ddate_start' => $x_paye[$my_paye_rate]['ddate_start'][$id], + 'ddate_end' => $x_paye[$my_paye_rate]['ddate_end'][$id], + 'totalht' => price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), + 'vat' => $x_paye[$my_paye_rate]['vat_list'][$id], + //'link' =>$invoice_supplier->getNomUrl(1,'',12) + ); + } + } + } + //now we have an array (x_both) indexed by rates for coll and paye + + $action = "tva"; + $object = array(&$x_coll, &$x_paye, &$x_both); + $parameters["mode"] = $modetax; + $parameters["year"] = $y; + $parameters["month"] = $m; + $parameters["type"] = 'vat'; + + // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array + $hookmanager->initHooks(array('externalbalance')); + $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + + if (!is_array($x_coll) && $coll_listbuy == -1) { + $langs->load("errors"); + print ''; + break; + } + if (!is_array($x_paye) && $coll_listbuy == -2) { + print ''; + break; + } + + + print ''; + print ''; + + $x_coll_sum = 0; + foreach (array_keys($x_coll) as $rate) { + $subtot_coll_total_ht = 0; + $subtot_coll_vat = 0; + + foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } + + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { + //print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + } + } + //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } + print ''; + + $x_paye_sum = 0; + foreach (array_keys($x_paye) as $rate) { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; + + foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) { + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } + + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { + //print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + } + } + //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } + } + print ''; + + $subtotalcoll = $subtotalcoll + $x_coll_sum; + $subtotalpaye = $subtotalpaye + $x_paye_sum; + + $diff = $x_coll_sum - $x_paye_sum; + $total = $total + $diff; + $subtotal = price2num($subtotal + $diff, 'MT'); + + print '' . "\n"; + print "\n"; + print "\n"; + + $i++; + $m++; + if ($i > 2) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i = 0; + $subtotalcoll = 0; + $subtotalpaye = 0; + $subtotal = 0; + } } - //now we have an array (x_both) indexed by rates for coll and paye + print ''; + print "\n"; + print ''; - $action = "tva"; - $object = array(&$x_coll, &$x_paye, &$x_both); - $parameters["mode"] = $modetax; - $parameters["year"] = $y; - $parameters["month"] = $m; - $parameters["type"] = 'vat'; - - // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array - $hookmanager->initHooks(array('externalbalance')); - $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - - if (!is_array($x_coll) && $coll_listbuy == -1) - { - $langs->load("errors"); - print ''; - break; - } - if (!is_array($x_paye) && $coll_listbuy == -2) - { - print ''; - break; - } + print '
' . $langs->trans("Year") . " " . $y . '' . $langs->trans("VATToPay") . '' . $langs->trans("VATToCollect") . '' . $langs->trans("Balance") . ' 
' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '
' . $langs->trans("FeatureNotYetAvailable") . '
' . dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y") . '' . price(price2num($x_coll_sum, 'MT')) . '' . price(price2num($x_paye_sum, 'MT')) . '' . price(price2num($diff, 'MT')) . ' 
' . $langs->trans("SubTotal") . ':' . price(price2num($subtotalcoll, 'MT')) . '' . price(price2num($subtotalpaye, 'MT')) . '' . price(price2num($subtotal, 'MT')) . ' 
' . $langs->trans("TotalToPay") . ':' . price(price2num($total, 'MT')) . ' 
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'; - print ''; - print ''.dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y").''; + print '
'; - $x_coll_sum = 0; - foreach (array_keys($x_coll) as $rate) - { - $subtot_coll_total_ht = 0; - $subtot_coll_vat = 0; - - foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) - { - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } - - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) - { - //print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - } - } - //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - $subtot_coll_total_ht += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; - } - } - print ''.price(price2num($x_coll_sum, 'MT')).''; - - $x_paye_sum = 0; - foreach (array_keys($x_paye) as $rate) - { - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; - - foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) - { - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } - - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) - { - //print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - } - } - //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; - } - } - print ''.price(price2num($x_paye_sum, 'MT')).''; - - $subtotalcoll = $subtotalcoll + $x_coll_sum; - $subtotalpaye = $subtotalpaye + $x_paye_sum; - - $diff = $x_coll_sum - $x_paye_sum; - $total = $total + $diff; - $subtotal = price2num($subtotal + $diff, 'MT'); - - print ''.price(price2num($diff, 'MT')).''."\n"; - print " \n"; - print "\n"; - - $i++; $m++; - if ($i > 2) - { - print ''; - print ''.$langs->trans("SubTotal").':'; - print ''.price(price2num($subtotalcoll, 'MT')).''; - print ''.price(price2num($subtotalpaye, 'MT')).''; - print ''.price(price2num($subtotal, 'MT')).''; - print ' '; - $i = 0; - $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0; - } -} -print ''.$langs->trans("TotalToPay").':'.price(price2num($total, 'MT')).''; -print " \n"; -print ''; - -print ''; - - -print '
'; - - - -/* - * Paid - */ - -print load_fiche_titre($langs->trans("VATPaid"), '', ''); - -$sql = ''; - -$sql .= "SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode"; -$sql .= " FROM ".MAIN_DB_PREFIX."tva as tva"; -$sql .= " WHERE tva.entity = ".$conf->entity; -$sql .= " AND (tva.datev >= '".$db->idate($date_start)."' AND tva.datev <= '".$db->idate($date_end)."')"; -$sql .= " GROUP BY dm"; - -$sql .= " UNION "; - -$sql .= "SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode"; -$sql .= " FROM ".MAIN_DB_PREFIX."tva as tva"; -$sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_vat as ptva ON (tva.rowid = ptva.fk_tva)"; -$sql .= " WHERE tva.entity = ".$conf->entity; -$sql .= " AND (tva.datev >= '".$db->idate($date_start)."' AND tva.datev <= '".$db->idate($date_end)."')"; -$sql .= " GROUP BY dm"; - -$sql .= " ORDER BY dm ASC, mode ASC"; -//print $sql; - -pt($db, $sql, $langs->trans("Month")); - - -if (!empty($conf->global->MAIN_FEATURES_LEVEL)) -{ - print '
'; /* - * Recap - */ + * Paid + */ - print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation + print load_fiche_titre($langs->trans("VATPaid"), '', ''); - $sql1 = "SELECT SUM(amount) as mm"; - $sql1 .= " FROM ".MAIN_DB_PREFIX."tva as f"; - $sql1 .= " WHERE f.entity = ".$conf->entity; - $sql1 .= " AND f.datev >= '".$db->idate($date_start)."'"; - $sql1 .= " AND f.datev <= '".$db->idate($date_end)."'"; + $sql = ''; - $result = $db->query($sql1); - if ($result) { - $obj = $db->fetch_object($result); - print ''; + $sql .= "SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode"; + $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva"; + $sql .= " WHERE tva.entity = " . $conf->entity; + $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')"; + $sql .= " GROUP BY dm"; - print ""; - print ''; - print ''; - print "\n"; + $sql .= " UNION "; - print ""; - print ''; - print '\n"; - print "\n"; + $sql .= "SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode"; + $sql .= " FROM " . MAIN_DB_PREFIX . "tva as tva"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_vat as ptva ON (tva.rowid = ptva.fk_tva)"; + $sql .= " WHERE tva.entity = " . $conf->entity; + $sql .= " AND (tva.datev >= '" . $db->idate($date_start) . "' AND tva.datev <= '" . $db->idate($date_end) . "')"; + $sql .= " GROUP BY dm"; - $restopay = $total - $obj->mm; - print ""; - print ''; - print ''; - print "\n"; + $sql .= " ORDER BY dm ASC, mode ASC"; +//print $sql; - print '
'.$langs->trans("VATDue").''.price(price2num($total, 'MT')).'
'.$langs->trans("VATPaid").''.price(price2num($obj->mm, 'MT'))."
'.$langs->trans("RemainToPay").''.price(price2num($restopay, 'MT')).'
'; - } + pt($db, $sql, $langs->trans("Month")); + + + if (!empty($conf->global->MAIN_FEATURES_LEVEL)) { + print '
'; + + /* + * Recap + */ + + print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation + + $sql1 = "SELECT SUM(amount) as mm"; + $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f"; + $sql1 .= " WHERE f.entity = " . $conf->entity; + $sql1 .= " AND f.datev >= '" . $db->idate($date_start) . "'"; + $sql1 .= " AND f.datev <= '" . $db->idate($date_end) . "'"; + + $result = $db->query($sql1); + if ($result) { + $obj = $db->fetch_object($result); + print ''; + + print ""; + print ''; + print ''; + print "\n"; + + print ""; + print ''; + print '\n"; + print "\n"; + + $restopay = $total - $obj->mm; + print ""; + print ''; + print ''; + print "\n"; + + print '
' . $langs->trans("VATDue") . '' . price(price2num($total, 'MT')) . '
' . $langs->trans("VATPaid") . '' . price(price2num($obj->mm, 'MT')) . "
' . $langs->trans("RemainToPay") . '' . price(price2num($restopay, 'MT')) . '
'; + } + } + + print '
'; } -print '
'; - llxFooter(); $db->close(); diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index ba12b08b3b0..504ba78c2d8 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -45,56 +45,59 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class. $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin")); $now = dol_now(); -$current_date = dol_getdate($now); -if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) $conf->global->SOCIETE_FISCAL_MONTH_START = 1; - -// Date range -$year = GETPOST("year", "int"); -if (empty($year)) -{ - $year_current = $current_date['year']; - $year_start = $year_current; +$refresh = GETPOSTISSET('submit') ? true : false; +$invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : ''; +$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1; +$year_current = GETPOSTISSET('year') ? GETPOST('year', 'int') : intval(strftime('%Y', $now)); +$year_start = $year_current; +$month_current = GETPOSTISSET('month') ? GETPOST('month', 'int') : intval(strftime('%m', $now)); +$month_start = $month_current; +if ($refresh===false) { + $date_start = dol_get_first_day($year_start, $month_start); + $date_end = dol_get_last_day($year_start, $month_start); } else { - $year_current = $year; - $year_start = $year; -} -$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")); -// Set default period if not defined -if (empty($date_start) || empty($date_end)) // We define date_start and date_end -{ - $q = GETPOST("q", "int"); - if (empty($q)) + // Date range + //$year=GETPOST("year", "int"); + //if (empty($year)) + //{ + // $year_current = strftime("%Y", dol_now()); + // $year_start = $year_current; + //} else { + // $year_current = $year; + // $year_start = $year; + //} + + $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")); + // Quarter + if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else { - if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter - $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); - $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat - if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { - if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year - $year_start--; - } - } else { - if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year - $year_start--; - } - } - $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); - $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month - $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); - $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; + $q=GETPOST("q", "int"); + if (empty($q)) + { + if (GETPOST("month", "int")) { $date_start=dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end=dol_get_last_day($year_start, GETPOST("month", "int"), false); } + else + { + $date_start=dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START, false); + if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end=dol_time_plus_duree($date_start, 3, 'm') - 1; + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1; + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end=dol_time_plus_duree($date_start, 1, 'm') - 1; } } - } 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 + { + 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); } + } } } +$month_start = strftime('%m', $date_start); +$year_start = strftime('%Y', $date_start); + + $min = price2num(GETPOST("min", "alpha")); if (empty($min)) $min = 0; @@ -389,7 +392,10 @@ if (!is_array($x_coll) || !is_array($x_paye)) { // VAT Rate print ""; - print ''.$langs->trans("Rate").': '.vatrate($rate).'%'; + print ''; + print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; + print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; + print ''; print ''."\n"; foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { @@ -405,171 +411,210 @@ if (!is_array($x_coll) || !is_array($x_paye)) $type = 1; } + // Payment + $ratiopaymentinvoice=1; + if ($modetax != 1) + { + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) + { - print ''; + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + } + } + } - // Ref - print ''.$fields['link'].''; + // Total collected + $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - // Invoice date - print ''.dol_print_date($fields['datef'], 'day').''; + // VAT + $temp_vat=$fields['vat']*$ratiopaymentinvoice; - // Payment date - if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print ''.dol_print_date($fields['datep'], 'day').''; - else print ''; + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } - // Company name - print ''.$fields['company_link'].''; + if ($invoice_type == 'customer' && $vat_rate_show == $rate) { + if (is_array($x_both[$rate]['coll']['detail'])) { + foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } - // Description - print ''; - if ($fields['pid']) - { - $product_static->id = $fields['pid']; - $product_static->ref = $fields['pref']; - $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) { - print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - } - } else { - if ($type) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { - if ($reg[1] == 'DEPOSIT') { - $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); - } elseif ($reg[1] == 'CREDIT_NOTE') { - $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); - } else { - $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); - } - } - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - // Show range - print_date_range($fields['ddate_start'], $fields['ddate_end']); - } - print ''; + print ''; - // Total HT - if ($modetax != 1) - { - print ''; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) - { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - } + // Ref + print '' . $fields['link'] . ''; - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - print ''; - //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) - { - $payment_static->id = $fields['payment_id']; - print $payment_static->getNomUrl(2); - } - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) - { - print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - print price(price2num($fields['payment_amount'], 'MT')); - if (isset($fields['payment_amount'])) { - print ' ('.round($ratiopaymentinvoice * 100, 2).'%)'; - } - } - print ''; - } + // Invoice date + print '' . dol_print_date($fields['datef'], 'day') . ''; - // Total collected - print ''; - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - print price(price2num($temp_ht, 'MT'), 1); - print ''; + // Payment date + if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '' . dol_print_date($fields['datep'], 'day') . ''; + else print ''; - // VAT - print ''; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - print price(price2num($temp_vat, 'MT'), 1); - //print price($fields['vat']); - print ''; - print ''; + // Company name + print '' . $fields['company_link'] . ''; - $subtot_coll_total_ht += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; - } - } - // Total customers for this vat rate - print ''; - print ''; - print ''.$langs->trans("Total").':'; - if ($modetax != 1) { - print ' '; - print ' '; - } - print ''.price(price2num($subtot_coll_total_ht, 'MT')).''; - print ''.price(price2num($subtot_coll_vat, 'MT')).''; - print ''; - } + // Description + print ''; + if ($fields['pid']) { + $product_static->id = $fields['pid']; + $product_static->ref = $fields['pref']; + $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) { + print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + } + } else { + if ($type) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { + if ($reg[1] == 'DEPOSIT') { + $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1] == 'CREDIT_NOTE') { + $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); + } + } + print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - if (count($x_coll) == 0) // Show a total line if nothing shown - { - print ''; - print ''; - print ''.$langs->trans("Total").':'; - if ($modetax != 1) { - print ' '; - print ' '; - } - print ''.price(price2num(0, 'MT')).''; - print ''.price(price2num(0, 'MT')).''; - print ''; - } + // Show range + print_date_range($fields['ddate_start'], $fields['ddate_end']); + } + print ''; - // Blank line - print ' '; + // Total HT + if ($modetax != 1) { + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + } - // Print table headers for this quadri - expenses now - print ''; - print ''.$elementsup.''; - print ''.$langs->trans("DateInvoice").''; - if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").''; - else print ''; - print ''.$namesup.''; - print ''.$productsup.''; - if ($modetax != 1) { - print ''.$amountsup.''; - print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'; - } - print ''.$langs->trans("AmountHTVATRealPaid").''; - print ''.$vatsup.''; - print ''."\n"; + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + print ''; + //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) { + $payment_static->id = $fields['payment_id']; + print $payment_static->getNomUrl(2); + } + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { + print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + print price(price2num($fields['payment_amount'], 'MT')); + if (isset($fields['payment_amount'])) { + print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)'; + } + } + print ''; + } - foreach (array_keys($x_paye) as $rate) - { - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; + // Total collected + print ''; + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + print price(price2num($temp_ht, 'MT'), 1); + print ''; - if (is_array($x_both[$rate]['paye']['detail'])) - { - print ""; - print ''.$langs->trans("Rate").': '.vatrate($rate).'%'; - print ''."\n"; + // VAT + print ''; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + print price(price2num($temp_vat, 'MT'), 1); + //print price($fields['vat']); + print ''; + print ''; + + //$subtot_coll_total_ht += $temp_ht; + //$subtot_coll_vat += $temp_vat; + //$x_coll_sum += $temp_vat; + } + } + } + // Total customers for this vat rate + print ''; + print ''; + print ''.$langs->trans("Total").':'; + if ($modetax != 1) { + print ' '; + print ' '; + } + print ''.price(price2num($subtot_coll_total_ht, 'MT')).''; + print ''.price(price2num($subtot_coll_vat, 'MT')).''; + print ''; + } + + if (count($x_coll) == 0) // Show a total line if nothing shown + { + print ''; + print ''; + print ''.$langs->trans("Total").':'; + if ($modetax != 1) { + print ' '; + print ' '; + } + print ''.price(price2num(0, 'MT')).''; + print ''.price(price2num(0, 'MT')).''; + print ''; + } + + // Blank line + print ' '; + + // Print table headers for this quadri - expenses now + print ''; + print ''.$elementsup.''; + print ''.$langs->trans("DateInvoice").''; + if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").''; + else print ''; + print ''.$namesup.''; + print ''.$productsup.''; + if ($modetax != 1) { + print ''.$amountsup.''; + print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'; + } + print ''.$langs->trans("AmountHTVATRealPaid").''; + print ''.$vatsup.''; + print ''."\n"; + + foreach (array_keys($x_paye) as $rate) + { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; + + if (is_array($x_both[$rate]['paye']['detail'])) + { + print ""; + print ''; + print '' . $langs->trans('Rate') . ' : ' . vatrate($rate) . '%' . ''; + print ''; + print ''."\n"; foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) { // Define type @@ -584,127 +629,161 @@ if (!is_array($x_coll) || !is_array($x_paye)) $type = 1; } + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { - print ''; + } else { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + } + } - // Ref - print ''.$fields['link'].''; + // VAT paid + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - // Invoice date - print ''.dol_print_date($fields['datef'], 'day').''; + // VAT + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - // Payment date - if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.dol_print_date($fields['datep'], 'day').''; - else print ''; + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } - // Company name - print ''.$fields['company_link'].''; + if ($invoice_type == 'supplier' && $vat_rate_show == $rate) { + foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } - // Description - print ''; - if ($fields['pid']) - { - $product_static->id = $fields['pid']; - $product_static->ref = $fields['pref']; - $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) { - print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - } - } else { - if ($type) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { - if ($reg[1] == 'DEPOSIT') { - $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); - } elseif ($reg[1] == 'CREDIT_NOTE') { - $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); - } else { - $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); - } - } - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - // Show range - print_date_range($fields['ddate_start'], $fields['ddate_end']); - } - print ''; + print ''; - // Total HT - if ($modetax != 1) - { - print ''; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) - { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - } + // Ref + print '' . $fields['link'] . ''; - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - print ''; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) - { - $paymentfourn_static->id = $fields['payment_id']; - print $paymentfourn_static->getNomUrl(2); - } + // Invoice date + print '' . dol_print_date($fields['datef'], 'day') . ''; - if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) - { - print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - print price(price2num($fields['payment_amount'], 'MT')); - if (isset($fields['payment_amount'])) { - print ' ('.round($ratiopaymentinvoice * 100, 2).'%)'; - } - } - print ''; - } + // Payment date + if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '' . dol_print_date($fields['datep'], 'day') . ''; + else print ''; - // VAT paid - print ''; - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - print price(price2num($temp_ht, 'MT'), 1); - print ''; + // Company name + print '' . $fields['company_link'] . ''; - // VAT - print ''; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - print price(price2num($temp_vat, 'MT'), 1); - //print price($fields['vat']); - print ''; - print ''; + // Description + print ''; + if ($fields['pid']) { + $product_static->id = $fields['pid']; + $product_static->ref = $fields['pref']; + $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) { + print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + } + } else { + if ($type) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { + if ($reg[1] == 'DEPOSIT') { + $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1] == 'CREDIT_NOTE') { + $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); + } + } + print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; - } - } - // Total suppliers for this vat rate - print ''; - print ''; - print ''.$langs->trans("Total").':'; - if ($modetax != 1) { - print ' '; - print ' '; - } - print ''.price(price2num($subtot_paye_total_ht, 'MT')).''; - print ''.price(price2num($subtot_paye_vat, 'MT')).''; - print ''; - } + // Show range + print_date_range($fields['ddate_start'], $fields['ddate_end']); + } + print ''; + + // Total HT + if ($modetax != 1) { + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + } + + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + print ''; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) { + $paymentfourn_static->id = $fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } + + if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { + print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + print price(price2num($fields['payment_amount'], 'MT')); + if (isset($fields['payment_amount'])) { + print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)'; + } + } + print ''; + } + + // VAT paid + print ''; + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + print price(price2num($temp_ht, 'MT'), 1); + print ''; + + // VAT + print ''; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + print price(price2num($temp_vat, 'MT'), 1); + //print price($fields['vat']); + print ''; + print ''; + + //$subtot_paye_total_ht += $temp_ht; + //$subtot_paye_vat += $temp_vat; + //$x_paye_sum += $temp_vat; + } + } + } + + // Total suppliers for this vat rate + print ''; + print ''; + print ''.$langs->trans("Total").':'; + if ($modetax != 1) { + print ' '; + print ' '; + } + print ''.price(price2num($subtot_paye_total_ht, 'MT')).''; + print ''.price(price2num($subtot_paye_vat, 'MT')).''; + print ''; + } if (count($x_paye) == 0) { // Show a total line if nothing shown print ''; diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 36ce55f7c85..3df8e552e31 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -599,16 +599,14 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; - $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; - $sql .= " ".MAIN_DB_PREFIX."societe as s,"; - $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; + $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture."=f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) 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)"; - $sql .= " AND f.rowid = d.".$fk_facture; - $sql .= " AND s.rowid = f.fk_soc"; if ($y && $m) { $sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, $m, false))."'"; @@ -633,20 +631,16 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; $sql .= " pa.datep as datep"; - $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; - $sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; - $sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; - $sql .= " ".MAIN_DB_PREFIX."societe as s,"; - $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; + $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) 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)"; - $sql .= " AND f.rowid = d.".$fk_facture; - $sql .= " AND s.rowid = f.fk_soc"; - $sql .= " AND pf.".$fk_facture2." = f.rowid"; - $sql .= " AND pa.rowid = pf.".$fk_payment; if ($y && $m) { $sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'"; @@ -741,16 +735,14 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,"; $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; - $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; - $sql .= " ".MAIN_DB_PREFIX."societe as s,"; - $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; + $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) 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)"; - $sql .= " AND f.rowid = d.".$fk_facture; - $sql .= " AND s.rowid = f.fk_soc"; if ($y && $m) { $sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, $m, false))."'"; @@ -775,20 +767,16 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; $sql .= " pa.datep as datep"; - $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,"; - $sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,"; - $sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,"; - $sql .= " ".MAIN_DB_PREFIX."societe as s,"; - $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; + $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) 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)"; - $sql .= " AND f.rowid = d.".$fk_facture; - $sql .= " AND s.rowid = f.fk_soc"; - $sql .= " AND pf.".$fk_facture2." = f.rowid"; - $sql .= " AND pa.rowid = pf.".$fk_payment; if ($y && $m) { $sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'"; @@ -885,9 +873,9 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; $sql .= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; $sql .= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref"; - $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e "; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid "; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid "; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid"; $sql .= " WHERE e.entity = ".$conf->entity; $sql .= " AND e.fk_statut in (6)"; if ($y && $m) diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 23e6cf0d724..62ad01b4f6b 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -191,6 +191,7 @@ VATReportByThirdParties=Sale tax report by third parties VATReportByCustomers=Sale tax report by customer VATReportByCustomersInInputOutputMode=Report by the customer VAT collected and paid VATReportByQuartersInInputOutputMode=Report by Sale tax rate of the tax collected and paid +VATReportShowByRateDetails=Show details of this rate LT1ReportByQuarters=Report tax 2 by rate LT2ReportByQuarters=Report tax 3 by rate LT1ReportByQuartersES=Report by RE rate From 15c2dd483cb6b45c643dd32fbcbbd01049b30922 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 16 Feb 2021 03:38:53 +0000 Subject: [PATCH 02/31] Fixing style errors. --- htdocs/compta/tva/quadri_detail.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 504ba78c2d8..c557812e6d5 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -76,16 +76,14 @@ if ($refresh===false) { if (empty($q)) { if (GETPOST("month", "int")) { $date_start=dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end=dol_get_last_day($year_start, GETPOST("month", "int"), false); } - else - { + else { $date_start=dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START, false); if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end=dol_time_plus_duree($date_start, 3, 'm') - 1; elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1; elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end=dol_time_plus_duree($date_start, 1, 'm') - 1; } } - else - { + 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); } @@ -418,7 +416,6 @@ if (!is_array($x_coll) || !is_array($x_paye)) if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { - } else { if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); @@ -634,7 +631,6 @@ if (!is_array($x_coll) || !is_array($x_paye)) if ($modetax != 1) { if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { - } else { if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); From 8ee1ec7944d153d870059e324935a6736716cef3 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 16 Feb 2021 04:53:09 +0100 Subject: [PATCH 03/31] NEW: VAT report - Optimisation & collapse by rate --- htdocs/compta/tva/quadri_detail.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 504ba78c2d8..29418abbbfa 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -610,11 +610,12 @@ if (!is_array($x_coll) || !is_array($x_paye)) if (is_array($x_both[$rate]['paye']['detail'])) { - print ""; - print ''; - print '' . $langs->trans('Rate') . ' : ' . vatrate($rate) . '%' . ''; - print ''; - print ''."\n"; + print ""; + print ''; + print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; + print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; + print ''; + print ''."\n"; foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) { // Define type From 85d63e05d1fda2dcc5ca7178d28cf16d61afafd4 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 25 Feb 2021 05:07:26 +0100 Subject: [PATCH 04/31] Move to INNER JOIN --- htdocs/core/lib/tax.lib.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 3df8e552e31..155276ded59 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -600,8 +600,8 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture."=f.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture."=f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) @@ -632,10 +632,10 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; $sql .= " pa.datep as datep"; $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid";; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) @@ -736,8 +736,8 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,"; $sql .= " 0 as payment_id, 0 as payment_amount"; $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) @@ -768,10 +768,10 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,"; $sql .= " pa.datep as datep"; $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$paymentfacturetable." as pf ON pf.".$fk_facture2." = f.rowid"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$paymenttable." as pa ON pa.rowid = pf.".$fk_payment; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$invoicedettable." as d ON d.".$fk_facture." = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql .= " WHERE f.entity IN (".getEntity($invoicetable).")"; $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) From 86c83ff72cd84177a1175a5cc6737476fea22b4a Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 28 Feb 2021 06:14:40 +0000 Subject: [PATCH 05/31] Fixing style errors. --- htdocs/compta/tva/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 78d499defc1..85ce27faf85 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -621,7 +621,7 @@ if ($refresh === true) { $sql .= " GROUP BY dm"; $sql .= " ORDER BY dm ASC, mode ASC"; -//print $sql; + //print $sql; pt($db, $sql, $langs->trans("Month")); From e1159f422a48815de66c23011afbddb18fc3e5a4 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 3 Mar 2021 13:11:01 +0000 Subject: [PATCH 06/31] Fixing style errors. --- htdocs/compta/tva/index.php | 3 +- htdocs/compta/tva/quadri_detail.php | 619 ++++++++++++++-------------- 2 files changed, 308 insertions(+), 314 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 62bb687807c..faf4e914a8f 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -343,8 +343,7 @@ if ($refresh === true) { $i = 0; $mcursor = 0; - while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop - { + while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12); if ($m == 13) $y++; if ($m > 12) $m -= 12; diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 173f26bcc14..2dada7165b3 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -71,7 +71,7 @@ if ($refresh === false) { $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")); // Quarter - 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 $q=GETPOST("q", "int"); if (empty($q)) { if (GETPOST("month", "int")) { @@ -446,204 +446,199 @@ if (!is_array($x_coll) || !is_array($x_paye)) { $type = 1; } - // Payment - $ratiopaymentinvoice=1; - if ($modetax != 1) - { - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) - { - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); - } - } - } + // Payment + $ratiopaymentinvoice=1; + if ($modetax != 1) { + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); + } + } + } - // Total collected - $temp_ht=$fields['totalht']*$ratiopaymentinvoice; + // Total collected + $temp_ht=$fields['totalht']*$ratiopaymentinvoice; - // VAT - $temp_vat=$fields['vat']*$ratiopaymentinvoice; + // VAT + $temp_vat=$fields['vat']*$ratiopaymentinvoice; - $subtot_coll_total_ht += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; - } - } + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } - if ($invoice_type == 'customer' && $vat_rate_show == $rate) { - if (is_array($x_both[$rate]['coll']['detail'])) { - foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } + if ($invoice_type == 'customer' && $vat_rate_show == $rate) { + if (is_array($x_both[$rate]['coll']['detail'])) { + foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } - print ''; + print ''; - // Ref - print '' . $fields['link'] . ''; + // Ref + print '' . $fields['link'] . ''; - // Invoice date - print '' . dol_print_date($fields['datef'], 'day') . ''; + // Invoice date + print '' . dol_print_date($fields['datef'], 'day') . ''; - // Payment date - if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '' . dol_print_date($fields['datep'], 'day') . ''; - else print ''; + // Payment date + if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '' . dol_print_date($fields['datep'], 'day') . ''; + else print ''; - // Company name - print '' . $fields['company_link'] . ''; + // Company name + print '' . $fields['company_link'] . ''; - // Description - print ''; - if ($fields['pid']) { - $product_static->id = $fields['pid']; - $product_static->ref = $fields['pref']; - $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) { - print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - } - } else { - if ($type) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { - if ($reg[1] == 'DEPOSIT') { - $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); - } elseif ($reg[1] == 'CREDIT_NOTE') { - $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); - } else { - $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); - } - } - print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + // Description + print ''; + if ($fields['pid']) { + $product_static->id = $fields['pid']; + $product_static->ref = $fields['pref']; + $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) { + print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + } + } else { + if ($type) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { + if ($reg[1] == 'DEPOSIT') { + $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1] == 'CREDIT_NOTE') { + $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); + } + } + print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - // Show range - print_date_range($fields['ddate_start'], $fields['ddate_end']); - } - print ''; + // Show range + print_date_range($fields['ddate_start'], $fields['ddate_end']); + } + print ''; - // Total HT - if ($modetax != 1) { - print ''; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - } + // Total HT + if ($modetax != 1) { + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + } - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) { - print ''; - //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) { - $payment_static->id = $fields['payment_id']; - print $payment_static->getNomUrl(2); - } - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { - print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - print price(price2num($fields['payment_amount'], 'MT')); - if (isset($fields['payment_amount'])) { - print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)'; - } - } - print ''; - } + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + print ''; + //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) { + $payment_static->id = $fields['payment_id']; + print $payment_static->getNomUrl(2); + } + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { + print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + print price(price2num($fields['payment_amount'], 'MT')); + if (isset($fields['payment_amount'])) { + print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)'; + } + } + print ''; + } - // Total collected - print ''; - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - print price(price2num($temp_ht, 'MT'), 1); - print ''; + // Total collected + print ''; + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + print price(price2num($temp_ht, 'MT'), 1); + print ''; - // VAT - print ''; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - print price(price2num($temp_vat, 'MT'), 1); - //print price($fields['vat']); - print ''; - print ''; + // VAT + print ''; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + print price(price2num($temp_vat, 'MT'), 1); + //print price($fields['vat']); + print ''; + print ''; - //$subtot_coll_total_ht += $temp_ht; - //$subtot_coll_vat += $temp_vat; - //$x_coll_sum += $temp_vat; - } - } - } - // Total customers for this vat rate - print ''; - print ''; - print ''.$langs->trans("Total").':'; - if ($modetax != 1) { - print ' '; - print ' '; - } - print ''.price(price2num($subtot_coll_total_ht, 'MT')).''; - print ''.price(price2num($subtot_coll_vat, 'MT')).''; - print ''; - } + //$subtot_coll_total_ht += $temp_ht; + //$subtot_coll_vat += $temp_vat; + //$x_coll_sum += $temp_vat; + } + } + } + // Total customers for this vat rate + print ''; + print ''; + print ''.$langs->trans("Total").':'; + if ($modetax != 1) { + print ' '; + print ' '; + } + print ''.price(price2num($subtot_coll_total_ht, 'MT')).''; + print ''.price(price2num($subtot_coll_vat, 'MT')).''; + print ''; + } - if (count($x_coll) == 0) // Show a total line if nothing shown - { - print ''; - print ''; - print ''.$langs->trans("Total").':'; - if ($modetax != 1) { - print ' '; - print ' '; - } - print ''.price(price2num(0, 'MT')).''; - print ''.price(price2num(0, 'MT')).''; - print ''; - } + if (count($x_coll) == 0) { // Show a total line if nothing shown + print ''; + print ''; + print ''.$langs->trans("Total").':'; + if ($modetax != 1) { + print ' '; + print ' '; + } + print ''.price(price2num(0, 'MT')).''; + print ''.price(price2num(0, 'MT')).''; + print ''; + } - // Blank line - print ' '; + // Blank line + print ' '; - // Print table headers for this quadri - expenses now - print ''; - print ''.$elementsup.''; - print ''.$langs->trans("DateInvoice").''; - if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").''; - else print ''; - print ''.$namesup.''; - print ''.$productsup.''; - if ($modetax != 1) { - print ''.$amountsup.''; - print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'; - } - print ''.$langs->trans("AmountHTVATRealPaid").''; - print ''.$vatsup.''; - print ''."\n"; + // Print table headers for this quadri - expenses now + print ''; + print ''.$elementsup.''; + print ''.$langs->trans("DateInvoice").''; + if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print ''.$langs->trans("DatePayment").''; + else print ''; + print ''.$namesup.''; + print ''.$productsup.''; + if ($modetax != 1) { + print ''.$amountsup.''; + print ''.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')'; + } + print ''.$langs->trans("AmountHTVATRealPaid").''; + print ''.$vatsup.''; + print ''."\n"; - foreach (array_keys($x_paye) as $rate) - { - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; + foreach (array_keys($x_paye) as $rate) { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; - if (is_array($x_both[$rate]['paye']['detail'])) - { + if (is_array($x_both[$rate]['paye']['detail'])) { print ""; print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; @@ -664,163 +659,163 @@ if (!is_array($x_coll) || !is_array($x_paye)) { $type = 1; } - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) { - if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { - } else { - if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - } - } + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { + } else { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + } + } - // VAT paid - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + // VAT paid + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - // VAT - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + // VAT + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; - } + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } - if ($invoice_type == 'supplier' && $vat_rate_show == $rate) { - foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } + if ($invoice_type == 'supplier' && $vat_rate_show == $rate) { + foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } - print ''; + print ''; - // Ref - print '' . $fields['link'] . ''; + // Ref + print '' . $fields['link'] . ''; - // Invoice date - print '' . dol_print_date($fields['datef'], 'day') . ''; + // Invoice date + print '' . dol_print_date($fields['datef'], 'day') . ''; - // Payment date - if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') { - print '' . dol_print_date($fields['datep'], 'day') . ''; + // Payment date + if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') { + print '' . dol_print_date($fields['datep'], 'day') . ''; } else { print ''; } - // Company name - print '' . $fields['company_link'] . ''; + // Company name + print '' . $fields['company_link'] . ''; - // Description - print ''; - if ($fields['pid']) { - $product_static->id = $fields['pid']; - $product_static->ref = $fields['pref']; - $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) { - print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - } - } else { - if ($type) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { - if ($reg[1] == 'DEPOSIT') { - $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); - } elseif ($reg[1] == 'CREDIT_NOTE') { - $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); - } else { - $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); - } - } - print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + // Description + print ''; + if ($fields['pid']) { + $product_static->id = $fields['pid']; + $product_static->ref = $fields['pref']; + $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) { + print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + } + } else { + if ($type) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { + if ($reg[1] == 'DEPOSIT') { + $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1] == 'CREDIT_NOTE') { + $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); + } + } + print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - // Show range - print_date_range($fields['ddate_start'], $fields['ddate_end']); - } - print ''; + // Show range + print_date_range($fields['ddate_start'], $fields['ddate_end']); + } + print ''; - // Total HT - if ($modetax != 1) { - print ''; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print ''; - } + // Total HT + if ($modetax != 1) { + print ''; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print ''; + } - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) { - print ''; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) { - $paymentfourn_static->id = $fields['payment_id']; - print $paymentfourn_static->getNomUrl(2); - } + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + print ''; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) { + $paymentfourn_static->id = $fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } - if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { - print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - print price(price2num($fields['payment_amount'], 'MT')); - if (isset($fields['payment_amount'])) { - print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)'; - } - } - print ''; - } + if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { + print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + print price(price2num($fields['payment_amount'], 'MT')); + if (isset($fields['payment_amount'])) { + print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)'; + } + } + print ''; + } - // VAT paid - print ''; - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - print price(price2num($temp_ht, 'MT'), 1); - print ''; + // VAT paid + print ''; + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + print price(price2num($temp_ht, 'MT'), 1); + print ''; - // VAT - print ''; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - print price(price2num($temp_vat, 'MT'), 1); - //print price($fields['vat']); - print ''; - print ''; + // VAT + print ''; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + print price(price2num($temp_vat, 'MT'), 1); + //print price($fields['vat']); + print ''; + print ''; - //$subtot_paye_total_ht += $temp_ht; - //$subtot_paye_vat += $temp_vat; - //$x_paye_sum += $temp_vat; - } - } - } + //$subtot_paye_total_ht += $temp_ht; + //$subtot_paye_vat += $temp_vat; + //$x_paye_sum += $temp_vat; + } + } + } - // Total suppliers for this vat rate - print ''; - print ''; - print ''.$langs->trans("Total").':'; - if ($modetax != 1) { - print ' '; - print ' '; - } - print ''.price(price2num($subtot_paye_total_ht, 'MT')).''; - print ''.price(price2num($subtot_paye_vat, 'MT')).''; - print ''; - } + // Total suppliers for this vat rate + print ''; + print ''; + print ''.$langs->trans("Total").':'; + if ($modetax != 1) { + print ' '; + print ' '; + } + print ''.price(price2num($subtot_paye_total_ht, 'MT')).''; + print ''.price(price2num($subtot_paye_vat, 'MT')).''; + print ''; + } if (count($x_paye) == 0) { // Show a total line if nothing shown print ''; From de4a76a26603acdc186033794027ced7c89acdac Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 3 Mar 2021 22:00:23 +0100 Subject: [PATCH 07/31] ongoung --- htdocs/projet/event.php | 74 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/event.php b/htdocs/projet/event.php index b033cb95742..95e60b731d1 100644 --- a/htdocs/projet/event.php +++ b/htdocs/projet/event.php @@ -35,14 +35,79 @@ $langs->load('projects', 'eventorganization'); $action = GETPOST('action', 'aZ09'); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'conferenceorboothprojectlist'; +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) +$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? -$mine = $_REQUEST['mode'] == 'mine' ? 1 : 0; -//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects +// Load variable for pagination +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { + $page = 0; +} // If $page is not defined, or '' or -1 or if we click on clear filters +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; -$object = new Project($db); + +$project = new Project($db); include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once +if ($id > 0 || !empty($ref)) { + // fetch optionals attributes and labels + $extrafields->fetch_name_optionals_label($object->table_element); +} + +$extrafields_conf_or_booth->fetch_name_optionals_label($conference_or_booth->table_element); +$search_array_options = $extrafields_conf_or_booth->getOptionalsFromPost($conference_or_booth->table_element, '', 'search_'); + +// Default sort order (if not yet defined by previous GETPOST) +if (!$sortfield) { + reset($object->fields); // Reset is required to avoid key() to return null. + $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. +} +if (!$sortorder) { + $sortorder = "ASC"; +} + +// Initialize array of search criterias +$search = array(); +foreach ($conference_or_booth->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha') !== '') { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } + if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { + $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int')); + $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int')); + } +} + +// Definition of array of fields for columns +$arrayfields = array(); +foreach ($conference_or_booth->fields as $key => $val) { + // If $val['visible']==0, then we never show the field + if (!empty($val['visible'])) { + $visible = (int) dol_eval($val['visible'], 1); + $arrayfields['t.'.$key] = array( + 'label'=>$val['label'], + 'checked'=>(($visible < 0) ? 0 : 1), + 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)), + 'position'=>$val['position'], + 'help'=>$val['help'] + ); + } +} + +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; + +$object->fields = dol_sort_array($object->fields, 'position'); +$arrayfields = dol_sort_array($arrayfields, 'position'); + // Security check $socid = 0; if ($user->socid > 0) { @@ -106,6 +171,9 @@ if ($id > 0 || !empty($ref)) { $head = project_prepare_head($object); print dol_get_fiche_head($head, 'eventorganisation', $langs->trans('ConferenceOrBoothTab'), -1); + // Add $param from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + // Project card $linkback = ''.$langs->trans("BackToList").''; From 339af419bc8d6baad9caf81c109a8a3d4ca80f0d Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 7 Mar 2021 21:59:28 +0100 Subject: [PATCH 08/31] Fix strftime --- htdocs/compta/tva/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index faf4e914a8f..a85500738f8 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -47,8 +47,8 @@ if (empty($conf->global->SOCIETE_FISCAL_MONTH_START)) { $refresh = GETPOSTISSET('submit') ? true : false; if ($refresh === false) { - $year_current = intval(strftime('%Y', $now)); - $month_current = intval(strftime('%m', $now)); + $year_current = dol_print_date('%Y', $now); + $month_current = dol_print_date('%m', $now); // 1 : Monthly (by default) // 2 : Quarterly @@ -91,7 +91,7 @@ if ($refresh === false) { // Date range $year = GETPOST("year", "int"); if (empty($year)) { - $year_current = strftime("%Y", dol_now()); + $year_current = dol_print_date("%Y", dol_now()); if ($conf->global->SOCIETE_FISCAL_MONTH_START > date('m')) $year_current--; $year_start = $year_current; } else { From b5c84bfc4fe4c7b4ba09729e892fa456b28a899a Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 9 Mar 2021 05:02:37 +0100 Subject: [PATCH 09/31] Resolve some mistakes --- htdocs/compta/tva/index.php | 4 ++-- htdocs/compta/tva/quadri_detail.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index a85500738f8..a2fa47fca61 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -91,8 +91,8 @@ if ($refresh === false) { // Date range $year = GETPOST("year", "int"); if (empty($year)) { - $year_current = dol_print_date("%Y", dol_now()); - if ($conf->global->SOCIETE_FISCAL_MONTH_START > date('m')) $year_current--; + $year_current = dol_print_date(dol_now(), "%Y"); + if ($conf->global->SOCIETE_FISCAL_MONTH_START > dol_print_date(dol_now(), "%m")) $year_current--; $year_start = $year_current; } else { $year_current = $year; diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 2dada7165b3..5f416e10c77 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -429,7 +429,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ""; print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; - print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; + print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; print ''; print ''."\n"; From c75fade6497549ad298362feb3fe3e08cbd258c0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 10 Mar 2021 17:07:44 +0100 Subject: [PATCH 10/31] Fix regression --- htdocs/compta/tva/index.php | 48 +++++-------------------------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index a2fa47fca61..2b396fe6006 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -345,8 +345,12 @@ if ($refresh === true) { while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12); - if ($m == 13) $y++; - if ($m > 12) $m -= 12; + if ($m == 13) { + $y++; + } + if ($m > 12) { + $m -= 12; + } $mcursor++; $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m); @@ -622,46 +626,6 @@ if ($refresh === true) { pt($db, $sql, $langs->trans("Month")); - if (!empty($conf->global->MAIN_FEATURES_LEVEL)) { - print '
'; - - /* - * Recap - */ - - print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation - - $sql1 = "SELECT SUM(amount) as mm"; - $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f"; - $sql1 .= " WHERE f.entity = " . $conf->entity; - $sql1 .= " AND f.datev >= '" . $db->idate($date_start) . "'"; - $sql1 .= " AND f.datev <= '" . $db->idate($date_end) . "'"; - - $result = $db->query($sql1); - if ($result) { - $obj = $db->fetch_object($result); - print ''; - - print ""; - print ''; - print ''; - print "\n"; - - print ""; - print ''; - print '\n"; - print "\n"; - - $restopay = $total - $obj->mm; - print ""; - print ''; - print ''; - print "\n"; - - print '
' . $langs->trans("VATDue") . '' . price(price2num($total, 'MT')) . '
' . $langs->trans("VATPaid") . '' . price(price2num($obj->mm, 'MT')) . "
' . $langs->trans("RemainToPay") . '' . price(price2num($restopay, 'MT')) . '
'; - } - } - print '
'; } From 862926316a78bb0da46cb9745242e333b98714c4 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 11 Mar 2021 19:09:42 +0100 Subject: [PATCH 11/31] working on list --- htdocs/comm/action/class/actioncomm.class.php | 2 +- htdocs/core/class/commonobject.class.php | 7 +- htdocs/core/lib/project.lib.php | 2 +- .../class/conferenceorbooth.class.php | 29 +- .../conferenceorbooth_list.php | 278 ++++++++---- .../modulebuilder/template/myobject_list.php | 4 +- htdocs/projet/class/project.class.php | 1 + htdocs/projet/contact.php | 12 +- htdocs/projet/element.php | 8 + htdocs/projet/event.php | 426 ------------------ htdocs/projet/tasks.php | 28 +- htdocs/projet/tasks/time.php | 12 +- htdocs/societe/class/societe.class.php | 1 + 13 files changed, 272 insertions(+), 538 deletions(-) delete mode 100644 htdocs/projet/event.php diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 4470310e4d0..ab6de76f340 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1038,7 +1038,7 @@ class ActionComm extends CommonObject * @param int $notrigger 1 = disable triggers, 0 = enable triggers * @return int <0 if KO, >0 if OK */ - public function update($user, $notrigger = 0) + public function update(User $user, $notrigger = 0) { global $langs, $conf, $hookmanager; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a392fd793d5..a2aff11defe 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1619,6 +1619,9 @@ abstract class CommonObject if ($idtofetch) { $thirdparty = new Societe($this->db); $result = $thirdparty->fetch($idtofetch); + if ($result<0) { + $this->errors=array_merge($this->errors, $thirdparty->errors); + } $this->thirdparty = $thirdparty; // Use first price level if level not defined for third party @@ -5704,7 +5707,7 @@ abstract class CommonObject return 0; } } else { - dol_print_error($this->db); + $this->errors[]=$this->db->lasterror; return -1; } } @@ -8258,7 +8261,7 @@ abstract class CommonObject * @param string $alias String of alias of table for fields. For example 't'. * @return string list of alias fields */ - protected function getFieldList($alias = '') + public function getFieldList($alias = '') { $keys = array_keys($this->fields); if (!empty($alias)) { diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index c5820b42d89..f2dbacc3ab4 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -208,7 +208,7 @@ function project_prepare_head(Project $project) $langs->load('eventorganization'); //TODO : Count $nbConfOrBooth = 1; - $head[$h][0] = DOL_URL_ROOT . '/projet/event.php?id=' . $project->id; + $head[$h][0] = DOL_URL_ROOT . '/eventorganization/conferenceorbooth_list.php?projectid=' . $project->id; $head[$h][1] = $langs->trans("ConferenceOrBoothTab"); if ($nbContact > 0) { $head[$h][1] .= '' . $nbConfOrBooth . ''; diff --git a/htdocs/eventorganization/class/conferenceorbooth.class.php b/htdocs/eventorganization/class/conferenceorbooth.class.php index 53f09bb4786..186bd57811b 100644 --- a/htdocs/eventorganization/class/conferenceorbooth.class.php +++ b/htdocs/eventorganization/class/conferenceorbooth.class.php @@ -208,11 +208,13 @@ class ConferenceOrBooth extends ActionComm * * @param int $id Id object * @param string $ref Ref + * @param string $ref_ext Ref ext to get + * @param string $email_msgid Email msgid * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = null) + public function fetch($id, $ref = null, $ref_ext = '', $email_msgid = '') { - $result = parent::fetch($id, $ref); + $result = parent::fetch($id, $ref, $ref_ext, $email_msgid); return $result; } @@ -238,7 +240,7 @@ class ConferenceOrBooth extends ActionComm $records = array(); $sql = 'SELECT '; - $sql .= $this->getFieldList(); + $sql .= $this->getFieldList('t'); $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')'; @@ -314,11 +316,10 @@ class ConferenceOrBooth extends ActionComm /** * Delete object in database * - * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers * @return int <0 if KO, >0 if OK */ - public function delete(User $user, $notrigger = false) + public function delete($notrigger = false) { //TODO delete attendees and subscription return parent::delete($notrigger); @@ -496,13 +497,16 @@ class ConferenceOrBooth extends ActionComm * Return a link to the object card (with optionaly the picto) * * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param int $maxlength Not use here just for declaration method compatibility with parent classes + * @param string $classname Not use here just for declaration method compatibility with parent classes * @param string $option On what the link point to ('nolink', ...) + * @param int $overwritepicto Not use here just for declaration method compatibility with parent classes * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param string $morecss Add more css on link * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) + public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1, $morecss = '') { global $conf, $langs, $hookmanager; @@ -603,11 +607,12 @@ class ConferenceOrBooth extends ActionComm * Return the label of the status * * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @param int $hidenastatus Not use here just for declaration method compatibility with parent classes * @return string Label of status */ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0, $hidenastatus = 0) { - return $this->LibStatut($this->status, $mode); + return $this->LibStatutEvent($this->status, $mode); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -618,7 +623,7 @@ class ConferenceOrBooth extends ActionComm * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label of status */ - public function LibStatut($status, $mode = 0) + public function LibStatutEvent($status, $mode = 0) { // phpcs:enable if (empty($this->labelStatus) || empty($this->labelStatusShort)) { @@ -627,13 +632,13 @@ class ConferenceOrBooth extends ActionComm $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft'); $this->labelStatus[self::STATUS_SUGGESTED] = $langs->trans('Suggested'); $this->labelStatus[self::STATUS_CONFIRMED] = $langs->trans('Confirmed'); - $this->labelStatus[self::STATUS_NOTSELECTED] = $langs->trans('NotSelected'); + $this->labelStatus[self::STATUS_NOT_QUALIFIED] = $langs->trans('NotSelected'); $this->labelStatus[self::STATUS_DONE] = $langs->trans('Done'); $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled'); $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft'); $this->labelStatusShort[self::STATUS_SUGGESTED] = $langs->trans('Suggested'); $this->labelStatusShort[self::STATUS_CONFIRMED] = $langs->trans('Confirmed'); - $this->labelStatusShort[self::STATUS_NOTSELECTED] = $langs->trans('NotSelected'); + $this->labelStatusShort[self::STATUS_NOT_QUALIFIED] = $langs->trans('NotSelected'); $this->labelStatusShort[self::STATUS_DONE] = $langs->trans('Done'); $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled'); } diff --git a/htdocs/eventorganization/conferenceorbooth_list.php b/htdocs/eventorganization/conferenceorbooth_list.php index b3c76ef2493..374ea25f68c 100644 --- a/htdocs/eventorganization/conferenceorbooth_list.php +++ b/htdocs/eventorganization/conferenceorbooth_list.php @@ -22,70 +22,22 @@ * \brief List page for conferenceorbooth */ -//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db -//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user -//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs -//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters -//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters -//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on). -//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on) -//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data -//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu -//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library -//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too. -//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip -//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value -//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler -//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message -//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies -//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET -//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification - -// Load Dolibarr environment -$res = 0; -// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) -if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { - $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; -} -// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; -while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { - $i--; $j--; -} -if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { - $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; -} -if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { - $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; -} -// Try main.inc.php using relative path -if (!$res && file_exists("../main.inc.php")) { - $res = @include "../main.inc.php"; -} -if (!$res && file_exists("../../main.inc.php")) { - $res = @include "../../main.inc.php"; -} -if (!$res && file_exists("../../../main.inc.php")) { - $res = @include "../../../main.inc.php"; -} -if (!$res) { - die("Include of main fails"); -} - +require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - -// load eventorganization libraries -require_once __DIR__.'/class/conferenceorbooth.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php'; +if ($conf->categorie->enabled) { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} // for other modules //dol_include_once('/othermodule/class/otherobject.class.php'); // Load translation files required by the page -$langs->loadLangs(array("eventorganization@eventorganization", "other")); +$langs->loadLangs(array("eventorganization", "other")); $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) @@ -98,6 +50,7 @@ $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $id = GETPOST('id', 'int'); +$projectid = GETPOST('projectid', 'int'); // Load variable for pagination $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; @@ -174,9 +127,9 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); -$permissiontoread = $user->rights->eventorganization->conferenceorbooth->read; -$permissiontoadd = $user->rights->eventorganization->conferenceorbooth->write; -$permissiontodelete = $user->rights->eventorganization->conferenceorbooth->delete; +$permissiontoread = $user->rights->eventorganization->read; +$permissiontoadd = $user->rights->eventorganization->write; +$permissiontodelete = $user->rights->eventorganization->delete; // Security check if (empty($conf->eventorganization->enabled)) { @@ -243,22 +196,193 @@ if (empty($reshook)) { /* * View */ - $form = new Form($db); - $now = dol_now(); //$help_url="EN:Module_ConferenceOrBooth|FR:Module_ConferenceOrBooth_FR|ES:Módulo_ConferenceOrBooth"; $help_url = ''; $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("ConferenceOrBooths")); +if ($projectid > 0) { + $project = new Project($db); + $result=$project->fetch($projectid); + if ($result < 0) { + setEventMessages(null, $project->errors, 'errors'); + } + $result=$project->fetch_thirdparty(); + if ($result < 0) { + setEventMessages(null, $project->errors, 'errors'); + } + $result = $project->fetch_optionals(); + if ($result < 0) { + setEventMessages(null, $project->errors, 'errors'); + } + + $help_url = "EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos"; + $title = $langs->trans("Project") . ' - ' . $langs->trans("ConferenceOrBooths") . ' - ' . $project->ref . ' ' . $project->name; + if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $project->name) { + $title = $project->ref . ' ' . $project->name . ' - ' . $langs->trans("ConferenceOrBooths"); + } +} + +// Output page +// -------------------------------------------------------------------- + +llxHeader('', $title, $help_url); + +// Example : Adding jquery code +print ''; + +if ($projectid > 0) { + // To verify role of users + //$userAccess = $object->restrictedProjectArea($user,'read'); + $userWrite = $project->restrictedProjectArea($user, 'write'); + //$userDelete = $object->restrictedProjectArea($user,'delete'); + //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete; + + $head = project_prepare_head($project); + print dol_get_fiche_head($head, 'eventorganisation', $langs->trans("Project"), -1, ($project->public ? 'projectpub' : 'project')); + + // Project card + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + // Title + $morehtmlref .= $project->title; + // Thirdparty + if ($project->thirdparty->id > 0) { + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$project->thirdparty->getNomUrl(1, 'project'); + } + $morehtmlref .= '
'; + + // Define a complementary filter for search of next/prev ref. + if (!$user->rights->project->all->lire) { + $objectsListId = $project->getProjectsAuthorizedForUser($user, 0, 0); + $project->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")"; + } + + dol_banner_tab($project, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + print '
'; + print '
'; + print '
'; + + print ''; + + // Usage + print ''; + print ''; + + // Visibility + print ''; + + // Date start - end + print ''; + + // Budget + print ''; + + // Other attributes + $cols = 2; + $objectconf=$object; + $object = $project; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + $object = $objectconf; + + print '
'; + print $langs->trans("Usage"); + print ''; + if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { + print 'usage_opportunity ? ' checked="checked"' : '').'"> '; + $htmltext = $langs->trans("ProjectFollowOpportunity"); + print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext); + print '
'; + } + if (empty($conf->global->PROJECT_HIDE_TASKS)) { + print 'usage_task ? ' checked="checked"' : '').'"> '; + $htmltext = $langs->trans("ProjectFollowTasks"); + print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext); + print '
'; + } + if (!empty($conf->global->PROJECT_BILL_TIME_SPENT)) { + print 'usage_bill_time ? ' checked="checked"' : '').'"> '; + $htmltext = $langs->trans("ProjectBillTimeDescription"); + print $form->textwithpicto($langs->trans("BillTime"), $htmltext); + print '
'; + } + if (!empty($conf->eventorganization->enabled)) { + print 'usage_organize_event ? ' checked="checked"' : '')).'"> '; + $htmltext = $langs->trans("EventOrganizationDescriptionLong"); + print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); + } + print '
'.$langs->trans("Visibility").''; + if ($project->public) { + print $langs->trans('SharedProject'); + } else { + print $langs->trans('PrivateProject'); + } + print '
'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").''; + $start = dol_print_date($project->date_start, 'day'); + print ($start ? $start : '?'); + $end = dol_print_date($project->date_end, 'day'); + print ' - '; + print ($end ? $end : '?'); + if ($object->hasDelay()) { + print img_warning("Late"); + } + print '
'.$langs->trans("Budget").''; + if (strcmp($project->budget_amount, '')) { + print price($project->budget_amount, '', $langs, 1, 0, 0, $conf->currency); + } + print '
'; + + print '
'; + print '
'; + print '
'; + print '
'; + + print ''; + + // Description + print ''; + + // Categories + if ($conf->categorie->enabled) { + print '"; + } + + print '
'.$langs->trans("Description").''; + print nl2br($project->description); + print '
'.$langs->trans("Categories").''; + print $form->showCategories($project->id, Categorie::TYPE_PROJECT, 1); + print "
'; + + print '
'; + print '
'; + print '
'; + + print '
'; + + + print dol_get_fiche_end(); +} // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; -foreach ($object->fields as $key => $val) { - $sql .= 't.'.$key.', '; -} +$sql .= $object->getFieldList('t'); // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { @@ -274,6 +398,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; } +$sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as cact ON cact.id=t.fk_action AND cact.module LIKE '%@eventorganization'"; // Add table from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook @@ -376,27 +501,6 @@ if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $ exit; } - -// Output page -// -------------------------------------------------------------------- - -llxHeader('', $title, $help_url); - -// Example : Adding jquery code -print ''; - $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; @@ -440,7 +544,7 @@ if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'pr } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); -print '
'."\n"; +print ''."\n"; if ($optioncss != '') { print ''; } @@ -451,7 +555,7 @@ print ''; print ''; print ''; -$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/eventorganization/conferenceorbooth_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); +$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/eventorganization/conferenceorbooth_card.php', 1).'?action=create'.(!empty($projectid)?'&fk_project='.$projectid:'').'&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1); diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index ee8c2e6677e..8609a2eed1a 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -258,9 +258,7 @@ $morecss = array(); // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; -foreach ($object->fields as $key => $val) { - $sql .= 't.'.$key.', '; -} +$sql .= $object->getFieldList('t'); // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index f28eccf3982..bb6c4201f14 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -621,6 +621,7 @@ class Project extends CommonObject return 0; } else { $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); return -1; } } diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php index fed592a808c..7f6c6c4f009 100644 --- a/htdocs/projet/contact.php +++ b/htdocs/projet/contact.php @@ -33,7 +33,12 @@ if ($conf->categorie->enabled) { } // Load translation files required by the page -$langs->loadLangs(array('projects', 'companies')); +$langsLoad=array('projects', 'companies'); +if (!empty($conf->eventorganization->enabled)) { + $langsLoad[]='eventorganization'; +} + +$langs->loadLangs($langsLoad); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); @@ -330,6 +335,11 @@ if ($id > 0 || !empty($ref)) { print $form->textwithpicto($langs->trans("BillTime"), $htmltext); print '
'; } + if (!empty($conf->eventorganization->enabled)) { + print 'usage_organize_event ? ' checked="checked"' : '')).'"> '; + $htmltext = $langs->trans("EventOrganizationDescriptionLong"); + print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); + } print ''; // Visibility diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 353fff374fc..ac8ed3879cd 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -134,6 +134,9 @@ if (!empty($conf->salaries->enabled)) { if (!empty($conf->mrp->enabled)) { $langs->load("mrp"); } +if (!empty($conf->eventorganization->enabled)) { + $langs->load("eventorganization"); +} $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); @@ -254,6 +257,11 @@ if (!empty($conf->global->PROJECT_BILL_TIME_SPENT)) { print $form->textwithpicto($langs->trans("BillTime"), $htmltext); print '
'; } +if (!empty($conf->eventorganization->enabled)) { + print 'usage_organize_event ? ' checked="checked"' : '')).'"> '; + $htmltext = $langs->trans("EventOrganizationDescriptionLong"); + print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); +} print ''; // Visibility diff --git a/htdocs/projet/event.php b/htdocs/projet/event.php deleted file mode 100644 index 95e60b731d1..00000000000 --- a/htdocs/projet/event.php +++ /dev/null @@ -1,426 +0,0 @@ - - * Copyright (C) 2012 Laurent Destailleur - * Copyright (C) 2021 florian.henry@scopen.fr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/projet/event.php - * \ingroup project - * \brief Tab event organization - */ - -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - -// Load translation files required by the page -$langs->load('projects', 'eventorganization'); - -$action = GETPOST('action', 'aZ09'); -$id = GETPOST('id', 'int'); -$ref = GETPOST('ref', 'alpha'); -$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'conferenceorboothprojectlist'; -$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) -$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ? - -// Load variable for pagination -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { - $page = 0; -} // If $page is not defined, or '' or -1 or if we click on clear filters -$offset = $limit * $page; -$pageprev = $page - 1; -$pagenext = $page + 1; - - -$project = new Project($db); - -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once - -if ($id > 0 || !empty($ref)) { - // fetch optionals attributes and labels - $extrafields->fetch_name_optionals_label($object->table_element); -} - -$extrafields_conf_or_booth->fetch_name_optionals_label($conference_or_booth->table_element); -$search_array_options = $extrafields_conf_or_booth->getOptionalsFromPost($conference_or_booth->table_element, '', 'search_'); - -// Default sort order (if not yet defined by previous GETPOST) -if (!$sortfield) { - reset($object->fields); // Reset is required to avoid key() to return null. - $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. -} -if (!$sortorder) { - $sortorder = "ASC"; -} - -// Initialize array of search criterias -$search = array(); -foreach ($conference_or_booth->fields as $key => $val) { - if (GETPOST('search_'.$key, 'alpha') !== '') { - $search[$key] = GETPOST('search_'.$key, 'alpha'); - } - if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { - $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int')); - $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int')); - } -} - -// Definition of array of fields for columns -$arrayfields = array(); -foreach ($conference_or_booth->fields as $key => $val) { - // If $val['visible']==0, then we never show the field - if (!empty($val['visible'])) { - $visible = (int) dol_eval($val['visible'], 1); - $arrayfields['t.'.$key] = array( - 'label'=>$val['label'], - 'checked'=>(($visible < 0) ? 0 : 1), - 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)), - 'position'=>$val['position'], - 'help'=>$val['help'] - ); - } -} - -// Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - -$object->fields = dol_sort_array($object->fields, 'position'); -$arrayfields = dol_sort_array($arrayfields, 'position'); - -// Security check -$socid = 0; -if ($user->socid > 0) { - $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement. -} -$result = restrictedArea($user, 'eventorganization', $id); - -$permissiontoread = $user->rights->eventorganization->read; -$permissiontoadd = $user->rights->eventorganization->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php -$permissiontodelete = $user->rights->eventorganization->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); - -/* - * Actions - */ - -if ($action == 'update' && empty(GETPOST('cancel')) && $permissiontoadd) { - $error = 0; - $object->oldcopy = clone $object; - - $object->accept_conference_suggestions=(GETPOST('accept_conference_suggestions', 'alpha') == 'on' ? 1 : 0); - $object->accept_booth_suggestions=(GETPOST('accept_booth_suggestions', 'alpha') == 'on' ? 1 : 0); - $object->price_registration=price2num(GETPOST('price_registration', 'alphanohtml'));; - $object->price_booth=price2num(GETPOST('price_booth', 'alphanohtml'));; - - $result = $object->update($user); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $db->rollback(); - $action = 'edit'; - } else { - $db->commit(); - if (GETPOST('socid', 'int') > 0) { - $object->fetch_thirdparty(GETPOST('socid', 'int')); - } else { - unset($object->thirdparty); - } - $action=''; - } -} - - - -/* - * View - */ - -$title = $langs->trans("Project").' - '.$langs->trans("ConferenceOrBoothTab").' - '.$object->ref.' '.$object->name; -if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { - $title = $object->ref.' '.$object->name.' - '.$langs->trans("Note"); -} -//TODO Make wiki docs -$help_url = ''; -llxHeader("", $title, $help_url); - -$form = new Form($db); -$userstatic = new User($db); - -$now = dol_now(); - -if ($id > 0 || !empty($ref)) { - $head = project_prepare_head($object); - print dol_get_fiche_head($head, 'eventorganisation', $langs->trans('ConferenceOrBoothTab'), -1); - - // Add $param from extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; - - // Project card - - $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - // Title - $morehtmlref .= $object->title; - // Thirdparty - if ($object->thirdparty->id > 0) { - $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project'); - } - $morehtmlref .= '
'; - - // Define a complementary filter for search of next/prev ref. - if (!$user->rights->projet->all->lire) { - $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0); - $object->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")"; - } - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - - print '
'; - print '
'; - print '
'; - - print ''; - - // Usage - print ''; - print ''; - - // Visibility - print ''; - - if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) { - // Opportunity status - print ''; - - // Opportunity percent - print ''; - - // Opportunity Amount - print ''; - - // Opportunity Weighted Amount - print ''; - } - - // Date start - end - print ''; - - // Budget - print ''; - - // Other attributes - $cols = 2; - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - print '
'; - print $langs->trans("Usage"); - print ''; - if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { - print 'usage_opportunity ? ' checked="checked"' : '')).'"> '; - $htmltext = $langs->trans("ProjectFollowOpportunity"); - print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext); - print '
'; - } - if (empty($conf->global->PROJECT_HIDE_TASKS)) { - print 'usage_task ? ' checked="checked"' : '')).'"> '; - $htmltext = $langs->trans("ProjectFollowTasks"); - print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext); - print '
'; - } - if (!empty($conf->global->PROJECT_BILL_TIME_SPENT)) { - print 'usage_bill_time ? ' checked="checked"' : '')).'"> '; - $htmltext = $langs->trans("ProjectBillTimeDescription"); - print $form->textwithpicto($langs->trans("BillTime"), $htmltext); - print '
'; - } - - if (!empty($conf->eventorganization->enabled)) { - print 'usage_organize_event ? ' checked="checked"' : '')).'"> '; - $htmltext = $langs->trans("EventOrganizationDescriptionLong"); - print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); - } - print '
'.$langs->trans("Visibility").''; - if ($object->public) { - print $langs->trans('SharedProject'); - } else { - print $langs->trans('PrivateProject'); - } - print '
'.$langs->trans("OpportunityStatus").''; - $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code'); - if ($code) { - print $langs->trans("OppStatus".$code); - } - print '
'.$langs->trans("OpportunityProbability").''; - if (strcmp($object->opp_percent, '')) { - print price($object->opp_percent, 0, $langs, 1, 0).' %'; - } - print '
'.$langs->trans("OpportunityAmount").''; - /*if ($object->opp_status) - { - print price($obj->opp_amount, 1, $langs, 1, 0, -1, $conf->currency); - }*/ - if (strcmp($object->opp_amount, '')) { - print price($object->opp_amount, 0, $langs, 1, 0, -1, $conf->currency); - } - print '
'.$langs->trans('OpportunityWeightedAmount').''; - if (strcmp($object->opp_amount, '') && strcmp($object->opp_percent, '')) { - print price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency); - } - print '
'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").''; - $start = dol_print_date($object->date_start, 'day'); - print ($start ? $start : '?'); - $end = dol_print_date($object->date_end, 'day'); - print ' - '; - print ($end ? $end : '?'); - if ($object->hasDelay()) { - print img_warning("Late"); - } - print '
'.$langs->trans("Budget").''; - if (strcmp($object->budget_amount, '')) { - print price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency); - } - print '
'; - - print '
'; - print '
'; - print '
'; - print '
'; - - if ($action == 'edit') { - print ''; - print ''; - print ''; - print ''; - } - - print ''; - - // Description - print ''; - - // Categories - if ($conf->categorie->enabled) { - print '"; - } - - if ($action == 'edit' && $permissiontoadd) { - //Allow unknown people to suggest conferences - print '"; - - //Allow unknown people to suggest booth - print '"; - - //Price of registration - print '"; - - //Price of registration - print '"; - } else { - //Allow unknown people to suggest conferences - print '"; - - //Allow unknown people to suggest booth - print '"; - - //Price of registration - print '"; - - //Price of registration - print '"; - } - - //ICS Link - print '"; - - print '
'.$langs->trans("Description").''; - print dol_htmlentitiesbr($object->description); - print '
'.$langs->trans("Categories").''; - print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1); - print "
' . $langs->trans("AllowUnknownPeopleSuggestConf") . $form->textwithpicto('', $langs->trans("AllowUnknownPeopleSuggestConfHelp")) . ''; - print 'accept_conference_suggestions ? ' checked="checked"' : '')) . '"> '; - print "
' . $langs->trans("AllowUnknownPeopleSuggestBooth") . $form->textwithpicto('', $langs->trans("AllowUnknownPeopleSuggestBoothHelp")) . ''; - print 'accept_booth_suggestions ? ' checked="checked"' : '')) . '"> '; - print "
' . $langs->trans("PriceOfRegistration") . ''; - print ''; - print "
' . $langs->trans("PriceOfBooth") . ''; - print ''; - print "
' . $langs->trans("AllowUnknownPeopleSuggestConf") . $form->textwithpicto('', $langs->trans("AllowUnknownPeopleSuggestConfHelp")) . ''; - print 'accept_conference_suggestions ? ' checked="checked"' : '')) . '"> '; - print "
' . $langs->trans("AllowUnknownPeopleSuggestBooth") . $form->textwithpicto('', $langs->trans("AllowUnknownPeopleSuggestBoothHelp")) . ''; - print 'accept_booth_suggestions ? ' checked="checked"' : '')) . '"> '; - print "
' . $langs->trans("PriceOfRegistration") . ''; - if (strcmp($object->price_registration, '')) { - print price($object->price_registration, 0, $langs, 1, 0, 0, $conf->currency); - } - print "
' . $langs->trans("PriceOfBooth") . ''; - if (strcmp($object->price_booth, '')) { - print price($object->price_booth, 0, $langs, 1, 0, 0, $conf->currency); - } - print "
'.$langs->trans("EventOrganizationICSLink").''; - //TODO ICS Link - //print 'ICS'; - print "
'; - - print ''; - - print '
'; - print '
'; - print '
'; - - print '
'; -} - -print dol_get_fiche_end(); - -if ($action == 'edit' && $permissiontoadd > 0) { - print '
'; - print '     '; - print ''; - print '
'; - - print ''; -} - - -/* - * Actions Buttons - */ -print '
'; -$parameters = array(); -$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been -// modified by hook -if (empty($reshook)) { - // Modify - if ($object->statut != Project::STATUS_CLOSED && $action=='') { - if ($permissiontoadd > 0) { - print ''.$langs->trans("Modify").''; - } else { - print ''.$langs->trans('Modify').''; - } - } -} - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 32a12ff36fd..eb5b0ae7b0a 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -36,7 +36,12 @@ if ($conf->categorie->enabled) { } // Load translation files required by the page -$langs->loadLangs(array('projects', 'users', 'companies')); +$langsLoad=array('projects', 'users', 'companies'); +if (!empty($conf->eventorganization->enabled)) { + $langsLoad[]='eventorganization'; +} + +$langs->loadLangs($langsLoad); $action = GETPOST('action', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); @@ -351,9 +356,19 @@ llxHeader("", $title, $help_url); if ($id > 0 || !empty($ref)) { - $object->fetch($id, $ref); - $object->fetch_thirdparty(); - $res = $object->fetch_optionals(); + $result = $object->fetch($id, $ref); + if ($result < 0) { + setEventMessages(null, $object->errors, 'errors'); + } + $result = $object->fetch_thirdparty(); + if ($result < 0) { + setEventMessages(null, $object->errors, 'errors'); + } + $result = $object->fetch_optionals(); + if ($result < 0) { + setEventMessages(null, $object->errors, 'errors'); + } + // To verify role of users //$userAccess = $object->restrictedProjectArea($user,'read'); @@ -469,6 +484,11 @@ if ($id > 0 || !empty($ref)) { print $form->textwithpicto($langs->trans("BillTime"), $htmltext); print '
'; } + if (!empty($conf->eventorganization->enabled)) { + print 'usage_organize_event ? ' checked="checked"' : '')).'"> '; + $htmltext = $langs->trans("EventOrganizationDescriptionLong"); + print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); + } print ''; // Visibility diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index d95fba9d48f..0beacab18a0 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -37,7 +37,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; // Load translation files required by the page -$langs->loadLangs(array('projects', 'bills', 'orders')); +$langsLoad=array('projects', 'bills', 'orders'); +if (!empty($conf->eventorganization->enabled)) { + $langsLoad[]='eventorganization'; +} + +$langs->loadLangs($langsLoad); $action = GETPOST('action', 'alpha'); $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) @@ -629,6 +634,11 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print $form->textwithpicto($langs->trans("BillTime"), $htmltext); print '
'; } + if (!empty($conf->eventorganization->enabled)) { + print 'usage_organize_event ? ' checked="checked"' : '')).'"> '; + $htmltext = $langs->trans("EventOrganizationDescriptionLong"); + print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext); + } print ''; // Visibility diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index fa8ed580ac0..07276cce1d3 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1812,6 +1812,7 @@ class Societe extends CommonObject $this->db->free($resql); } else { $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); $result = -3; } From 3de691788ff646b1be22d4e391d845829e8853fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:11:09 +0100 Subject: [PATCH 12/31] Create index.htlk --- htdocs/workstation/index.htlk | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/workstation/index.htlk diff --git a/htdocs/workstation/index.htlk b/htdocs/workstation/index.htlk new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/workstation/index.htlk @@ -0,0 +1 @@ + From 840c32e8bb03dc478fe7b8098c54f046f19c98cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:12:36 +0100 Subject: [PATCH 13/31] Rename index.htlk to index.html --- htdocs/workstation/{index.htlk => index.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename htdocs/workstation/{index.htlk => index.html} (100%) diff --git a/htdocs/workstation/index.htlk b/htdocs/workstation/index.html similarity index 100% rename from htdocs/workstation/index.htlk rename to htdocs/workstation/index.html From b9a81b673c7d4397bc8b9574c8ad1df2f453c970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:12:57 +0100 Subject: [PATCH 14/31] Create index.html --- htdocs/workstation/lib/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/workstation/lib/index.html diff --git a/htdocs/workstation/lib/index.html b/htdocs/workstation/lib/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/workstation/lib/index.html @@ -0,0 +1 @@ + From bf8c677b791093d24ed5d6d609bdf1cd5b35b248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:13:15 +0100 Subject: [PATCH 15/31] Create index.html --- htdocs/workstation/class/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/workstation/class/index.html diff --git a/htdocs/workstation/class/index.html b/htdocs/workstation/class/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/workstation/class/index.html @@ -0,0 +1 @@ + From 69514b00035e228da1b0b0f6aa6a2457733c5c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:15:11 +0100 Subject: [PATCH 16/31] Create index.html --- htdocs/eventorganization/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/eventorganization/index.html diff --git a/htdocs/eventorganization/index.html b/htdocs/eventorganization/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/eventorganization/index.html @@ -0,0 +1 @@ + From 03992257f667433f2387128a1d7af76de48b24c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:15:25 +0100 Subject: [PATCH 17/31] Create index.html --- htdocs/eventorganization/lib/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/eventorganization/lib/index.html diff --git a/htdocs/eventorganization/lib/index.html b/htdocs/eventorganization/lib/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/eventorganization/lib/index.html @@ -0,0 +1 @@ + From 0d310a7a82feaf491ecb24aab55365ff862b067e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:15:40 +0100 Subject: [PATCH 18/31] Create index.html --- htdocs/eventorganization/class/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/eventorganization/class/index.html diff --git a/htdocs/eventorganization/class/index.html b/htdocs/eventorganization/class/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/eventorganization/class/index.html @@ -0,0 +1 @@ + From 2c5eb37f965ba1b74ff6530bba47217fd6e8b4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:17:23 +0100 Subject: [PATCH 19/31] Create index.html --- htdocs/recruitment/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/recruitment/index.html diff --git a/htdocs/recruitment/index.html b/htdocs/recruitment/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/recruitment/index.html @@ -0,0 +1 @@ + From c12568c9c76c8201dab758b37587152577f66dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:17:39 +0100 Subject: [PATCH 20/31] Create index.html --- htdocs/recruitment/lib/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/recruitment/lib/index.html diff --git a/htdocs/recruitment/lib/index.html b/htdocs/recruitment/lib/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/recruitment/lib/index.html @@ -0,0 +1 @@ + From ae3019f7dab4b9abc56a136871f37067248b262e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:17:57 +0100 Subject: [PATCH 21/31] Create index.html --- htdocs/recruitment/core/modules/recruitment/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/recruitment/core/modules/recruitment/index.html diff --git a/htdocs/recruitment/core/modules/recruitment/index.html b/htdocs/recruitment/core/modules/recruitment/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/recruitment/core/modules/recruitment/index.html @@ -0,0 +1 @@ + From 66cff32aeffbe85129b5c652538e8be00db34bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:18:11 +0100 Subject: [PATCH 22/31] Create index.html --- htdocs/recruitment/core/modules/recruitment/doc/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/recruitment/core/modules/recruitment/doc/index.html diff --git a/htdocs/recruitment/core/modules/recruitment/doc/index.html b/htdocs/recruitment/core/modules/recruitment/doc/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/recruitment/core/modules/recruitment/doc/index.html @@ -0,0 +1 @@ + From 9c1e4064d2657fb8b30b00fde8d400f3c3fab388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:18:29 +0100 Subject: [PATCH 23/31] Create index.html --- htdocs/recruitment/class/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/recruitment/class/index.html diff --git a/htdocs/recruitment/class/index.html b/htdocs/recruitment/class/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/recruitment/class/index.html @@ -0,0 +1 @@ + From d50eca4189670d04ba669e46a6b6a9e65606123c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:18:47 +0100 Subject: [PATCH 24/31] Create index.html --- htdocs/recruitment/admin/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/recruitment/admin/index.html diff --git a/htdocs/recruitment/admin/index.html b/htdocs/recruitment/admin/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/recruitment/admin/index.html @@ -0,0 +1 @@ + From 64db6f81c662727f0e71724da483d7a4e9dbb55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:20:20 +0100 Subject: [PATCH 25/31] Create index.html --- htdocs/asset/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/asset/index.html diff --git a/htdocs/asset/index.html b/htdocs/asset/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/asset/index.html @@ -0,0 +1 @@ + From 78566437052c83074ff57dfc5a1a8384c9fbca8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:20:32 +0100 Subject: [PATCH 26/31] Create index.html --- htdocs/asset/class/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/asset/class/index.html diff --git a/htdocs/asset/class/index.html b/htdocs/asset/class/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/asset/class/index.html @@ -0,0 +1 @@ + From 7997598fd98c7c59c92eaa8c972c9cfefb26448a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 14:20:59 +0100 Subject: [PATCH 27/31] Create index.html --- htdocs/asset/admin/index.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 htdocs/asset/admin/index.html diff --git a/htdocs/asset/admin/index.html b/htdocs/asset/admin/index.html new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/htdocs/asset/admin/index.html @@ -0,0 +1 @@ + From c3c03e9de3acd12341d6ab6d4d137a9fd50603d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 13 Mar 2021 18:42:50 +0100 Subject: [PATCH 28/31] fix php8 fatal error --- htdocs/core/lib/memory.lib.php | 4 ++-- htdocs/main.inc.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index ce603415009..1300c1b771f 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -93,7 +93,7 @@ function dol_setcache($memoryid, $data, $expire = 0) $dolmemcache->add($memoryid, $data, $expire); // This fails if key already exists $rescode = $dolmemcache->getResultCode(); if ($rescode == 0) { - return count($data); + return is_countable($data) ? count($data) : 0; } else { return -$rescode; } @@ -113,7 +113,7 @@ function dol_setcache($memoryid, $data, $expire = 0) //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); $result = $dolmemcache->add($memoryid, $data, false, $expire); // This fails if key already exists if ($result) { - return count($data); + return is_countable($data) ? count($data) : 0; } else { return -1; } diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index f72a933c688..2c799e21591 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -48,6 +48,18 @@ if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) { } } +if (!function_exists('is_countable')) { + /** + * function is_countable (to remove when php version supported will be >= 7.3) + * @param mixed $c data to check if countable + * @return bool + */ + function is_countable($c) + { + return is_array($c) || $c instanceof Countable; + } +} + /** * Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF). * Warning: Such a protection can't be enough. It is not reliable as it will alwyas be possible to bypass this. Good protection can From 523b189017a40c134dab7b0b3a9aa82f1cd99984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 15 Mar 2021 00:23:07 +0100 Subject: [PATCH 29/31] fix php8 warnings --- htdocs/fichinter/card-rec.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/fichinter/card-rec.php b/htdocs/fichinter/card-rec.php index 775f83ef500..7b944869b6a 100644 --- a/htdocs/fichinter/card-rec.php +++ b/htdocs/fichinter/card-rec.php @@ -8,7 +8,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2016-2018 Charlie Benke - * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2018-2021 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,6 +68,8 @@ if ($page == -1) { $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; +$sortorder = GETPOST('sortorder', 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); if ($sortorder == "") { $sortorder = "DESC"; } @@ -102,13 +104,13 @@ $arrayfields = array( // Create predefined intervention if ($action == 'add') { - if (!GETPOST('titre')) { + if (!GETPOSTISSET('titre')) { setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors'); $action = "create"; $error++; } - if (!GETPOST('socid')) { + if (!GETPOSTISSET('socid')) { setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Customer")), null, 'errors'); $action = "create"; $error++; From 9f5d0dbb6bea000d2a3f95c43a9bc73847bce531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 15 Mar 2021 11:11:41 +0100 Subject: [PATCH 30/31] Update card-rec.php --- htdocs/fichinter/card-rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fichinter/card-rec.php b/htdocs/fichinter/card-rec.php index 7b944869b6a..e87d94fb506 100644 --- a/htdocs/fichinter/card-rec.php +++ b/htdocs/fichinter/card-rec.php @@ -104,13 +104,13 @@ $arrayfields = array( // Create predefined intervention if ($action == 'add') { - if (!GETPOSTISSET('titre')) { + if (!GETPOST('titre')) { setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors'); $action = "create"; $error++; } - if (!GETPOSTISSET('socid')) { + if (!GETPOST('socid')) { setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Customer")), null, 'errors'); $action = "create"; $error++; From 29d86adcb3659a06bed0da6808a01009f0170e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 15 Mar 2021 11:20:15 +0100 Subject: [PATCH 31/31] move function declaration --- htdocs/main.inc.php | 12 ------------ htdocs/master.inc.php | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 336748d0c03..31fbc0ee4b3 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -49,18 +49,6 @@ if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) { } } -if (!function_exists('is_countable')) { - /** - * function is_countable (to remove when php version supported will be >= 7.3) - * @param mixed $c data to check if countable - * @return bool - */ - function is_countable($c) - { - return is_array($c) || $c instanceof Countable; - } -} - /** * Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF). * Warning: Such a protection can't be enough. It is not reliable as it will alwyas be possible to bypass this. Good protection can diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index c63ace353b3..371d687b9b7 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -35,6 +35,17 @@ require_once 'filefunc.inc.php'; // May have been already require by main.inc.php. But may not by scripts. +if (!function_exists('is_countable')) { + /** + * function is_countable (to remove when php version supported will be >= 7.3) + * @param mixed $c data to check if countable + * @return bool + */ + function is_countable($c) + { + return is_array($c) || $c instanceof Countable; + } +} /* * Create $conf object