diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 70ea12ba4cb..9cb32aa428e 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -111,7 +111,7 @@ if (isModEnabled('facture')) { } if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) { - print getNumberInvoicesPieChart('fourn'); + print getNumberInvoicesPieChart('suppliers'); print '
'; } diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index 0241431c8b7..3e310ade5bc 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -417,13 +417,16 @@ class Utils } - // TODO Replace with Utils->executeCLI() function but - // we must first introduce the variant with $lowmemorydump into this method. if ($execmethod == 1) { $output_arr = array(); $retval = null; exec($fullcommandclear, $output_arr, $retval); + // TODO Replace this exec with Utils->executeCLI() function. + // We must check that the case for $lowmemorydump works too... + //$utils = new Utils($db); + //$outputfile = $conf->admin->dir_temp.'/dump.tmp'; + //$utils->executeCLI($fullcommandclear, $outputfile, 0); if ($retval != 0) { $langs->load("errors"); @@ -438,6 +441,8 @@ class Utils if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) { continue; } + // Now check into the result file, that the file end with "-- Dump completed" + // This is possible only if $output_arr is the clear dump file, so not possible with $lowmemorydump set because file is already compressed. if (!$lowmemorydump) { fwrite($handle, $read.($execmethod == 2 ? '' : "\n")); if (preg_match('/'.preg_quote('-- Dump completed', '/').'/i', $read)) { diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 0d14b322953..f4aca8ef9a7 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -280,8 +280,9 @@ function supplier_invoice_rec_prepare_head($object) function getNumberInvoicesPieChart($mode) { global $conf, $db, $langs, $user; + if (($mode == 'customers' && isModEnabled('facture') && !empty($user->rights->facture->lire)) - || ($mode = 'suppliers') && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && !empty($user->rights->facture->lire) + || ($mode == 'suppliers' && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && !empty($user->rights->facture->lire)) ) { include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; @@ -406,7 +407,9 @@ function getNumberInvoicesPieChart($mode) dol_print_error($db); } } + return ''; } + /** * Return a HTML table that contains a list with customer invoice drafts * @@ -418,137 +421,140 @@ function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0) { global $conf, $db, $langs, $user, $hookmanager; - $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD); - $result = ''; - $tmpinvoice = new Facture($db); - $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client"; - $sql .= ", f.type, f.fk_statut as status, f.paye"; - $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", sc.fk_soc, sc.fk_user "; - } - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays"; - if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT; - $sql .= " AND f.entity IN (".getEntity('invoice').")"; - if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } + if (isModEnabled('facture') && !empty($user->rights->facture->lire)) { + $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD); - if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } - // Add where from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters); - $sql .= $hookmanager->resPrint; + $tmpinvoice = new Facture($db); - $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,"; - $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,"; - $sql .= " cc.rowid, cc.code"; - if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", sc.fk_soc, sc.fk_user"; - } + $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client"; + $sql .= ", f.type, f.fk_statut as status, f.paye"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", sc.fk_soc, sc.fk_user "; + } + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + } - // Add Group from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters); - $sql .= $hookmanager->resPrint; + if ($socid) { + $sql .= " AND f.fk_soc = ".((int) $socid); + } + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters); + $sql .= $hookmanager->resPrint; - $resql = $db->query($sql); + $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,"; + $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,"; + $sql .= " cc.rowid, cc.code"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", sc.fk_soc, sc.fk_user"; + } - if ($resql) { - $num = $db->num_rows($resql); - $nbofloop = min($num, $maxofloop); + // Add Group from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters); + $sql .= $hookmanager->resPrint; - $result .= '
'; - $result .= ''; + $resql = $db->query($sql); - $result .= ''; - $result .= ''; - $result .= ''; + if ($resql) { + $num = $db->num_rows($resql); + $nbofloop = min($num, $maxofloop); - if ($num) { - $companystatic = new Societe($db); + $result .= '
'; + $result .= '
'; - $result .= $langs->trans("CustomersDraftInvoices").' '; - $result .= ''; - $result .= ''.$num.''; - $result .= ''; - $result .= '
'; - $i = 0; - $othernb = 0; - $tot_ttc = 0; - while ($i < $nbofloop) { - $obj = $db->fetch_object($resql); + $result .= ''; + $result .= ''; + $result .= ''; - if ($i >= $maxCount) { - $othernb += 1; - $i++; + if ($num) { + $companystatic = new Societe($db); + + $i = 0; + $othernb = 0; + $tot_ttc = 0; + while ($i < $nbofloop) { + $obj = $db->fetch_object($resql); + + if ($i >= $maxCount) { + $othernb += 1; + $i++; + $tot_ttc += $obj->total_ttc; + continue; + } + + $tmpinvoice->id = $obj->rowid; + $tmpinvoice->ref = $obj->ref; + $tmpinvoice->date = $db->jdate($obj->date); + $tmpinvoice->type = $obj->type; + $tmpinvoice->total_ht = $obj->total_ht; + $tmpinvoice->total_tva = $obj->total_tva; + $tmpinvoice->total_ttc = $obj->total_ttc; + $tmpinvoice->ref_client = $obj->ref_client; + $tmpinvoice->statut = $obj->status; + $tmpinvoice->paye = $obj->paye; + + $companystatic->id = $obj->socid; + $companystatic->name = $obj->name; + $companystatic->email = $obj->email; + $companystatic->country_id = $obj->country_id; + $companystatic->country_code = $obj->country_code; + $companystatic->client = 1; + $companystatic->code_client = $obj->code_client; + $companystatic->code_fournisseur = $obj->code_fournisseur; + $companystatic->code_compta = $obj->code_compta; + $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; + + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; $tot_ttc += $obj->total_ttc; - continue; + $i++; } - $tmpinvoice->id = $obj->rowid; - $tmpinvoice->ref = $obj->ref; - $tmpinvoice->date = $db->jdate($obj->date); - $tmpinvoice->type = $obj->type; - $tmpinvoice->total_ht = $obj->total_ht; - $tmpinvoice->total_tva = $obj->total_tva; - $tmpinvoice->total_ttc = $obj->total_ttc; - $tmpinvoice->ref_client = $obj->ref_client; - $tmpinvoice->statut = $obj->status; - $tmpinvoice->paye = $obj->paye; + if ($othernb) { + $result .= ''; + $result .= ''; + $result .= "\n"; + } - $companystatic->id = $obj->socid; - $companystatic->name = $obj->name; - $companystatic->email = $obj->email; - $companystatic->country_id = $obj->country_id; - $companystatic->country_code = $obj->country_code; - $companystatic->client = 1; - $companystatic->code_client = $obj->code_client; - $companystatic->code_fournisseur = $obj->code_fournisseur; - $companystatic->code_compta = $obj->code_compta; - $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - - $result .= ''; - $result .= ''; - $result .= ''; - $result .= ''; + $result .= ''; + $result .= ''; $result .= ''; - $tot_ttc += $obj->total_ttc; - $i++; + } else { + $result .= ''; } - - if ($othernb) { - $result .= ''; - $result .= ''; - $result .= "\n"; - } - - $result .= ''; - $result .= ''; - $result .= ''; + $result .= "
'; + $result .= $langs->trans("CustomersDraftInvoices").' '; + $result .= ''; + $result .= ''.$num.''; + $result .= ''; + $result .= '
'; + $result .= $tmpinvoice->getNomUrl(1, ''); + $result .= ''; + $result .= $companystatic->getNomUrl(1, 'customer'); + $result .= ''.price($obj->total_ttc).'
'; + $result .= ''.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').''; + $result .= '
'; - $result .= $tmpinvoice->getNomUrl(1, ''); - $result .= ''; - $result .= $companystatic->getNomUrl(1, 'customer'); - $result .= ''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'
'; - $result .= ''.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').''; - $result .= '
'.$langs->trans("Total").''.price($tot_ttc).'
"; + $db->free($resql); } else { - $result .= ''.$langs->trans("NoInvoice").''; + dol_print_error($db); } - $result .= ""; - $db->free($resql); - } else { - dol_print_error($db); } return $result; @@ -565,119 +571,122 @@ function getDraftSupplierTable($maxCount = 500, $socid = 0) { global $conf, $db, $langs, $user, $hookmanager; - $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD); - $result = ''; - $facturesupplierstatic = new FactureFournisseur($db); - $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye"; - $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays"; - if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT; - $sql .= " AND f.entity IN (".getEntity('invoice').')'; - if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - if ($socid) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } - // Add where from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters); - $sql .= $hookmanager->resPrint; - $resql = $db->query($sql); + if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && !empty($user->rights->facture->lire)) { + $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD); - if ($resql) { - $num = $db->num_rows($resql); - $nbofloop = min($num, $maxofloop); + $facturesupplierstatic = new FactureFournisseur($db); - $result .= '
'; - $result .= ''; + $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT; + $sql .= " AND f.entity IN (".getEntity('invoice').')'; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + } + if ($socid) { + $sql .= " AND f.fk_soc = ".((int) $socid); + } + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters); + $sql .= $hookmanager->resPrint; + $resql = $db->query($sql); - $result .= ''; - $result .= ''; - $result .= ''; + if ($resql) { + $num = $db->num_rows($resql); + $nbofloop = min($num, $maxofloop); - if ($num) { - $companystatic = new Societe($db); + $result .= '
'; + $result .= '
'; - $result .= $langs->trans("SuppliersDraftInvoices").' '; - $result .= ''; - $result .= ''.$num.''; - $result .= ''; - $result .= '
'; - $i = 0; - $othernb = 0; - $tot_ttc = 0; - while ($i < $nbofloop) { - $obj = $db->fetch_object($resql); + $result .= ''; + $result .= ''; + $result .= ''; - if ($i >= $maxCount) { - $othernb += 1; - $i++; + if ($num) { + $companystatic = new Societe($db); + + $i = 0; + $othernb = 0; + $tot_ttc = 0; + while ($i < $nbofloop) { + $obj = $db->fetch_object($resql); + + if ($i >= $maxCount) { + $othernb += 1; + $i++; + $tot_ttc += $obj->total_ttc; + continue; + } + + $facturesupplierstatic->ref = $obj->ref; + $facturesupplierstatic->id = $obj->rowid; + $facturesupplierstatic->total_ht = $obj->total_ht; + $facturesupplierstatic->total_tva = $obj->total_tva; + $facturesupplierstatic->total_ttc = $obj->total_ttc; + $facturesupplierstatic->ref_supplier = $obj->ref_supplier; + $facturesupplierstatic->type = $obj->type; + $facturesupplierstatic->statut = $obj->status; + $facturesupplierstatic->paye = $obj->paye; + + $companystatic->id = $obj->socid; + $companystatic->name = $obj->name; + $companystatic->email = $obj->email; + $companystatic->country_id = $obj->country_id; + $companystatic->country_code = $obj->country_code; + $companystatic->fournisseur = 1; + $companystatic->code_client = $obj->code_client; + $companystatic->code_fournisseur = $obj->code_fournisseur; + $companystatic->code_compta = $obj->code_compta; + $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; + + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; $tot_ttc += $obj->total_ttc; - continue; + $i++; } - $facturesupplierstatic->ref = $obj->ref; - $facturesupplierstatic->id = $obj->rowid; - $facturesupplierstatic->total_ht = $obj->total_ht; - $facturesupplierstatic->total_tva = $obj->total_tva; - $facturesupplierstatic->total_ttc = $obj->total_ttc; - $facturesupplierstatic->ref_supplier = $obj->ref_supplier; - $facturesupplierstatic->type = $obj->type; - $facturesupplierstatic->statut = $obj->status; - $facturesupplierstatic->paye = $obj->paye; + if ($othernb) { + $result .= ''; + $result .= ''; + $result .= "\n"; + } - $companystatic->id = $obj->socid; - $companystatic->name = $obj->name; - $companystatic->email = $obj->email; - $companystatic->country_id = $obj->country_id; - $companystatic->country_code = $obj->country_code; - $companystatic->fournisseur = 1; - $companystatic->code_client = $obj->code_client; - $companystatic->code_fournisseur = $obj->code_fournisseur; - $companystatic->code_compta = $obj->code_compta; - $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - - $result .= ''; - $result .= ''; - $result .= ''; - $result .= ''; + $result .= ''; + $result .= ''; $result .= ''; - $tot_ttc += $obj->total_ttc; - $i++; + } else { + $result .= ''; } - - if ($othernb) { - $result .= ''; - $result .= ''; - $result .= "\n"; - } - - $result .= ''; - $result .= ''; - $result .= ''; + $result .= "
'; + $result .= $langs->trans("SuppliersDraftInvoices").' '; + $result .= ''; + $result .= ''.$num.''; + $result .= ''; + $result .= '
'; + $result .= $facturesupplierstatic->getNomUrl(1, ''); + $result .= ''; + $result .= $companystatic->getNomUrl(1, 'supplier'); + $result .= ''.price($obj->total_ttc).'
'; + $result .= ''.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').''; + $result .= '
'; - $result .= $facturesupplierstatic->getNomUrl(1, ''); - $result .= ''; - $result .= $companystatic->getNomUrl(1, 'supplier'); - $result .= ''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'
'; - $result .= ''.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').''; - $result .= '
'.$langs->trans("Total").''.price($tot_ttc).'
"; + $db->free($resql); } else { - $result .= ''.$langs->trans("NoInvoice").''; + dol_print_error($db); } - $result .= ""; - $db->free($resql); - } else { - dol_print_error($db); } return $result;