Merge pull request #10027 from atm-quentin/NEW_manage_multicompany_for_invoice

New manage multicompany for invoice
This commit is contained in:
Laurent Destailleur 2019-01-16 18:51:01 +01:00 committed by GitHub
commit 3a8afafabd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 94 additions and 68 deletions

View File

@ -157,7 +157,7 @@ class Lettering extends BookKeeping
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = pay.fk_bank AND bk.code_journal='" . $obj->code_journal . "')"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = pay.fk_bank AND bk.code_journal='" . $obj->code_journal . "')";
$sql .= " WHERE payfac.fk_paiement = '" . $obj->url_id . "' "; $sql .= " WHERE payfac.fk_paiement = '" . $obj->url_id . "' ";
$sql .= " AND bk.code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=4 AND entity=".$conf->entity.") "; $sql .= " AND bk.code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=4 AND entity=".$conf->entity.") ";
$sql .= " AND fac.entity = ".$conf->entity; $sql .= " AND fac.entity IN (".getEntity('invoice',0).")";// We don't share object for accountancy
$sql .= " AND ( "; $sql .= " AND ( ";
if (! empty($object->code_compta)) { if (! empty($object->code_compta)) {
$sql .= " bk.subledger_account = '" . $object->code_compta . "' "; $sql .= " bk.subledger_account = '" . $object->code_compta . "' ";
@ -185,7 +185,7 @@ class Lettering extends BookKeeping
$sql .= " FROM " . MAIN_DB_PREFIX . "facture fac "; $sql .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid AND fac.rowid IN (" . implode(',', $ids_fact) . "))"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid AND fac.rowid IN (" . implode(',', $ids_fact) . "))";
$sql .= " WHERE code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=2 AND entity=".$conf->entity.") "; $sql .= " WHERE code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=2 AND entity=".$conf->entity.") ";
$sql .= " AND fac.entity = ".$conf->entity; $sql .= " AND fac.entity IN (".getEntity('invoice',0).")";// We don't share object for accountancy
$sql .= " AND ( "; $sql .= " AND ( ";
if (! empty($object->code_compta)) { if (! empty($object->code_compta)) {
$sql .= " bk.subledger_account = '" . $object->code_compta . "' "; $sql .= " bk.subledger_account = '" . $object->code_compta . "' ";

View File

@ -1146,7 +1146,7 @@ if ($object->id > 0)
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id; $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= ' GROUP BY f.rowid, f.ref, f.type, f.amount, f.total, f.tva, f.total_ttc,'; $sql.= ' GROUP BY f.rowid, f.ref, f.type, f.amount, f.total, f.tva, f.total_ttc,';
$sql.= ' f.datef, f.datec, f.paye, f.fk_statut,'; $sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
$sql.= ' s.nom, s.rowid'; $sql.= ' s.nom, s.rowid';

View File

@ -122,6 +122,12 @@ if ($id > 0 || ! empty($ref))
$search_account = $object->id; // Force the search field on id of account $search_account = $object->id; // Force the search field on id of account
} }
if (! ($object->id > 0) )
{
$langs->load("errors");
print($langs->trans('ErrorRecordNotFound'));
exit;
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('banktransactionlist', $contextpage)); $hookmanager->initHooks(array('banktransactionlist', $contextpage));

View File

@ -103,6 +103,8 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
print '<br>'; print '<br>';
$solde = $object->solde(0); $solde = $object->solde(0);
if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)$colspan = 6;
else $colspan = 5;
// Show next coming entries // Show next coming entries
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
@ -112,10 +114,11 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("DateDue").'</td>'; print '<td>'.$langs->trans("DateDue").'</td>';
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED )print '<td>'.$langs->trans("Entity").'</td>';
print '<td>'.$langs->trans("ThirdParty").'</td>'; print '<td>'.$langs->trans("ThirdParty").'</td>';
print '<td align="right">'.$langs->trans("Debit").'</td>'; print '<td align="right">'.$langs->trans("Debit").'</td>';
print '<td align="right">'.$langs->trans("Credit").'</td>'; print '<td align="right">'.$langs->trans("Credit").'</td>';
print '<td align="right">'.$langs->trans("BankBalance").'</td>'; print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>';
print '</tr>'; print '</tr>';
// Current balance // Current balance
@ -126,7 +129,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td align="left" colspan="5">'.$langs->trans("RemainderToPay").'</td>'; print '<td align="left" colspan="'.$colspan.'">'.$langs->trans("RemainderToPay").'</td>';
print '<td align="right" class="nowrap">&nbsp;</td>'; print '<td align="right" class="nowrap">&nbsp;</td>';
print '</tr>'; print '</tr>';
@ -139,7 +142,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$sql.= " s.rowid as socid, s.nom as name, s.fournisseur"; $sql.= " s.rowid as socid, s.nom as name, s.fournisseur";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
$sql.= " WHERE f.entity = ".$conf->entity; $sql.= " WHERE f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid $sql.= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid
$sql.= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice $sql.= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice
$sql.= " ORDER BY dlr ASC"; $sql.= " ORDER BY dlr ASC";
@ -283,6 +286,12 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
else print $langs->trans("NotDefined"); else print $langs->trans("NotDefined");
print "</td>"; print "</td>";
print "<td>".$ref."</td>"; print "<td>".$ref."</td>";
if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED ){
if($obj->family == 'invoice'){
$mc->getInfo($obj->entity);
print "<td>".$mc->label."</td>";
}else print "<td></td>";
}
print "<td>".$refcomp."</td>"; print "<td>".$refcomp."</td>";
if ($obj->total_ttc < 0) { print "<td align=\"right\">".price(abs($total_ttc))."</td><td>&nbsp;</td>"; }; if ($obj->total_ttc < 0) { print "<td align=\"right\">".price(abs($total_ttc))."</td><td>&nbsp;</td>"; };
if ($obj->total_ttc >= 0) { print "<td>&nbsp;</td><td align=\"right\">".price($total_ttc)."</td>"; }; if ($obj->total_ttc >= 0) { print "<td>&nbsp;</td><td align=\"right\">".price($total_ttc)."</td>"; };
@ -308,7 +317,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
// solde // solde
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td align="left" colspan="5">'.$langs->trans("FutureBalance").' ('.$object->currency_code.')</td>'; print '<td align="left" colspan="'.$colspan.'">'.$langs->trans("FutureBalance").' ('.$object->currency_code.')</td>';
print '<td align="right" class="nowrap">'.price($solde, 0, $langs, 0, 0, -1, $object->currency_code).'</td>'; print '<td align="right" class="nowrap">'.price($solde, 0, $langs, 0, 0, -1, $object->currency_code).'</td>';
print '</tr>'; print '</tr>';

View File

@ -831,7 +831,7 @@ if (empty($reshook))
$db->begin(); $db->begin();
$error = 0; $error = 0;
$originentity = GETPOST('originentity');
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
@ -910,6 +910,9 @@ if (empty($reshook))
if (! $error) if (! $error)
{ {
if(!empty($originentity)){
$object->entity = $originentity;
}
$object->socid = GETPOST('socid','int'); $object->socid = GETPOST('socid','int');
$object->number = $_POST['ref']; $object->number = $_POST['ref'];
$object->date = $dateinvoice; $object->date = $dateinvoice;
@ -2600,7 +2603,6 @@ if ($action == 'create')
// Load objectsrc // Load objectsrc
$remise_absolue = 0; $remise_absolue = 0;
if (! empty($origin) && ! empty($originid)) if (! empty($origin) && ! empty($originid))
{ {
// Parse element/subelement (ex: project_task) // Parse element/subelement (ex: project_task)
@ -2722,6 +2724,7 @@ if ($action == 'create')
print '<input name="ref_int" type="hidden" value="' . $ref_int . '">'; print '<input name="ref_int" type="hidden" value="' . $ref_int . '">';
print '<input type="hidden" name="origin" value="' . $origin . '">'; print '<input type="hidden" name="origin" value="' . $origin . '">';
print '<input type="hidden" name="originid" value="' . $originid . '">'; print '<input type="hidden" name="originid" value="' . $originid . '">';
print '<input type="hidden" name="originentity" value="' . GETPOST('originentity') . '">';
if (!empty($currency_tx)) print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx . '">'; if (!empty($currency_tx)) print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx . '">';
dol_fiche_head(''); dol_fiche_head('');
@ -4802,7 +4805,7 @@ else if ($id > 0 || ! empty($ref))
{ {
if (! $objectidnext) if (! $objectidnext)
{ {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?socid=' . $object->socid .'&amp;fac_avoir=' . $object->id . '&amp;action=create&amp;type=2'.($object->fk_project > 0 ? '&amp;projectid='.$object->fk_project : '').'">' . $langs->trans("CreateCreditNote") . '</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?socid=' . $object->socid .'&amp;fac_avoir=' . $object->id . '&amp;action=create&amp;type=2'.($object->fk_project > 0 ? '&amp;projectid='.$object->fk_project : '').'' . $object->id . '&amp;action=create&amp;type=2'.($object->entity > 0 ? '&amp;originentity='.$object->entity : '').'">' . $langs->trans("CreateCreditNote") . '</a></div>';
} }
} }

View File

@ -947,7 +947,7 @@ class Facture extends CommonInvoice
*/ */
function createFromClone($socid=0) function createFromClone($socid=0)
{ {
global $user,$hookmanager; global $user,$hookmanager, $conf;
$error=0; $error=0;
@ -3349,9 +3349,11 @@ class Facture extends CommonInvoice
$mybool=false; $mybool=false;
$file = $conf->global->FACTURE_ADDON.".php"; $file = $conf->global->FACTURE_ADDON.".php";
$classname = $conf->global->FACTURE_ADDON; $classname = $conf->global->FACTURE_ADDON;
// Include file with class // Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
@ -3485,7 +3487,7 @@ class Facture extends CommonInvoice
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE f.entity = ".$conf->entity; $sql.= " WHERE f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.fk_soc = s.rowid";
if (! $user->rights->societe->client->voir && ! $socid) //restriction if (! $user->rights->societe->client->voir && ! $socid) //restriction
{ {
@ -3557,7 +3559,7 @@ class Facture extends CommonInvoice
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON f.rowid = ff.fk_facture_source"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON f.rowid = ff.fk_facture_source";
$sql.= " WHERE (f.fk_statut = ".self::STATUS_VALIDATED." OR (f.fk_statut = ".self::STATUS_ABANDONED." AND f.close_code = '".self::CLOSECODE_ABANDONED."'))"; $sql.= " WHERE (f.fk_statut = ".self::STATUS_VALIDATED." OR (f.fk_statut = ".self::STATUS_ABANDONED." AND f.close_code = '".self::CLOSECODE_ABANDONED."'))";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.paye = 0"; // Pas classee payee completement $sql.= " AND f.paye = 0"; // Pas classee payee completement
$sql.= " AND pf.fk_paiement IS NULL"; // Aucun paiement deja fait $sql.= " AND pf.fk_paiement IS NULL"; // Aucun paiement deja fait
$sql.= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement $sql.= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement
@ -3606,7 +3608,7 @@ class Facture extends CommonInvoice
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=".self::TYPE_REPLACEMENT.")"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=".self::TYPE_REPLACEMENT.")";
$sql.= " WHERE f.entity = ".$conf->entity; $sql.= " WHERE f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")"; $sql.= " AND f.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
// $sql.= " WHERE f.fk_statut >= 1"; // $sql.= " WHERE f.fk_statut >= 1";
// $sql.= " AND (f.paye = 1"; // Classee payee completement // $sql.= " AND (f.paye = 1"; // Classee payee completement
@ -3822,7 +3824,7 @@ class Facture extends CommonInvoice
$clause = " AND"; $clause = " AND";
} }
$sql.= $clause." f.paye=0"; $sql.= $clause." f.paye=0";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.fk_statut = ".self::STATUS_VALIDATED; $sql.= " AND f.fk_statut = ".self::STATUS_VALIDATED;
if ($user->societe_id) $sql.= " AND f.fk_soc = ".$user->societe_id; if ($user->societe_id) $sql.= " AND f.fk_soc = ".$user->societe_id;
@ -4070,7 +4072,7 @@ class Facture extends CommonInvoice
$sql.= " WHERE sc.fk_user = " .$user->id; $sql.= " WHERE sc.fk_user = " .$user->id;
$clause = "AND"; $clause = "AND";
} }
$sql.= " ".$clause." f.entity = ".$conf->entity; $sql.= " ".$clause." f.entity IN (".getEntity('invoice').")";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)

View File

@ -80,7 +80,7 @@ class FactureStats extends Stats
} }
$this->where = " f.fk_statut > 0"; $this->where = " f.fk_statut > 0";
$this->where.= " AND f.entity = ".$conf->entity; $this->where.= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($mode == 'customer') $this->where.=" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons) if ($mode == 'customer') $this->where.=" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
if ($this->socid) if ($this->socid)

View File

@ -146,7 +146,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$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 = 0"; $sql.= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) if ($socid)
@ -236,7 +236,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture-
$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"; $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 (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$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 = 0"; $sql.= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').')';
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
// Add where from hooks // Add where from hooks
@ -331,7 +331,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.rowid = f.fk_soc"; $sql.= " WHERE s.rowid = f.fk_soc";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
// Add where from hooks // Add where from hooks
@ -823,7 +823,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; $sql.= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').')';
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
// Add where from hooks // Add where from hooks

View File

@ -110,7 +110,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva as ct ON fd.tva_tx = ct.taux AND fd.i
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql.= " JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = fd.fk_facture_fourn"; $sql.= " JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
$sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc" ; $sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc" ;
$sql.= " WHERE f.fk_statut > 0 AND f.entity = ".$conf->entity; $sql.= " WHERE f.fk_statut > 0 AND f.entity IN (".getEntity('invoice').")";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)";
else $sql.= " AND f.type IN (0,1,2,3)"; else $sql.= " AND f.type IN (0,1,2,3)";
if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";

View File

@ -110,7 +110,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql.= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture"; $sql.= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
$sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; $sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'";
$sql.= " WHERE f.entity = ".$conf->entity; $sql.= " WHERE f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.fk_statut > 0"; $sql.= " AND f.fk_statut > 0";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql.= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")"; $sql.= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";

View File

@ -322,7 +322,7 @@ $sql = 'SELECT f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.fk_statut
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
$sql.= ' WHERE pf.fk_facture = f.rowid'; $sql.= ' WHERE pf.fk_facture = f.rowid';
$sql.= ' AND f.fk_soc = s.rowid'; $sql.= ' AND f.fk_soc = s.rowid';
$sql.= ' AND f.entity = '.$conf->entity; $sql.= ' AND f.entity IN ('.getEntity('invoice').')';
$sql.= ' AND pf.fk_paiement = '.$object->id; $sql.= ' AND pf.fk_paiement = '.$object->id;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
@ -342,6 +342,7 @@ if ($resql)
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Bill').'</td>'; print '<td>'.$langs->trans('Bill').'</td>';
print '<td>'.$langs->trans('Company').'</td>'; print '<td>'.$langs->trans('Company').'</td>';
if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED )print '<td>'.$langs->trans('Entity').'</td>';
print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>'; print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>'; print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>'; print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
@ -377,6 +378,13 @@ if ($resql)
print $thirdpartystatic->getNomUrl(1); print $thirdpartystatic->getNomUrl(1);
print '</td>'; print '</td>';
// Expected to pay
if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED ){
print '<td>';
$mc->getInfo($objp->entity);
print $mc->label;
print '</td>';
}
// Expected to pay // Expected to pay
print '<td align="right">'.price($objp->total_ttc).'</td>'; print '<td align="right">'.price($objp->total_ttc).'</td>';

View File

@ -699,7 +699,7 @@ class BonPrelevement extends CommonObject
$sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
//$sql.= " ,".MAIN_DB_PREFIX."c_paiement as cp"; //$sql.= " ,".MAIN_DB_PREFIX."c_paiement as cp";
$sql.= " WHERE f.fk_statut = 1"; $sql.= " WHERE f.fk_statut = 1";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.rowid = pfd.fk_facture"; $sql.= " AND f.rowid = pfd.fk_facture";
$sql.= " AND f.paye = 0"; $sql.= " AND f.paye = 0";
$sql.= " AND pfd.traite = 0"; $sql.= " AND pfd.traite = 0";
@ -740,7 +740,7 @@ class BonPrelevement extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql.= " WHERE f.fk_statut = 1"; $sql.= " WHERE f.fk_statut = 1";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.rowid = pfd.fk_facture"; $sql.= " AND f.rowid = pfd.fk_facture";
$sql.= " AND f.paye = 0"; $sql.= " AND f.paye = 0";
$sql.= " AND pfd.traite = 0"; $sql.= " AND pfd.traite = 0";

View File

@ -294,7 +294,7 @@ class RejetPrelevement
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
$sql.= " WHERE pf.fk_prelevement_lignes = ".$this->id; $sql.= " WHERE pf.fk_prelevement_lignes = ".$this->id;
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)

View File

@ -194,7 +194,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql.= " WHERE s.rowid = f.fk_soc"; $sql.= " WHERE s.rowid = f.fk_soc";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND pfd.traite = 0"; $sql.= " AND pfd.traite = 0";
$sql.= " AND pfd.fk_facture = f.rowid"; $sql.= " AND pfd.fk_facture = f.rowid";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;

View File

@ -75,7 +75,7 @@ $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.rowid = f.fk_soc"; $sql.= " WHERE s.rowid = f.fk_soc";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
if (!$statut) $sql.= " AND pfd.traite = 0"; if (!$statut) $sql.= " AND pfd.traite = 0";

View File

@ -155,7 +155,7 @@ $sql.= " WHERE pf.fk_prelevement_lignes = pl.rowid";
$sql.= " AND pl.fk_prelevement_bons = p.rowid"; $sql.= " AND pl.fk_prelevement_bons = p.rowid";
$sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.fk_soc = s.rowid";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($prev_id) $sql.= " AND p.rowid=".$prev_id; if ($prev_id) $sql.= " AND p.rowid=".$prev_id;
if ($socid) $sql.= " AND s.rowid = ".$socid; if ($socid) $sql.= " AND s.rowid = ".$socid;
$sql.= $db->order($sortfield,$sortorder); $sql.= $db->order($sortfield,$sortorder);

View File

@ -99,7 +99,7 @@ $sql.= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql.= " WHERE s.rowid = f.fk_soc"; $sql.= " WHERE s.rowid = f.fk_soc";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid"; $sql.= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;

View File

@ -272,7 +272,7 @@ if ($id)
$sql.= " AND pl.fk_prelevement_bons = p.rowid"; $sql.= " AND pl.fk_prelevement_bons = p.rowid";
$sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.fk_soc = s.rowid";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND pl.rowid=".$id; $sql.= " AND pl.rowid=".$id;
if ($socid) $sql.= " AND s.rowid = ".$socid; if ($socid) $sql.= " AND s.rowid = ".$socid;
$sql.= " ORDER BY $sortfield $sortorder "; $sql.= " ORDER BY $sortfield $sortorder ";

View File

@ -94,7 +94,7 @@ $sql.= " WHERE pl.fk_prelevement_bons = p.rowid";
$sql.= " AND pf.fk_prelevement_lignes = pl.rowid"; $sql.= " AND pf.fk_prelevement_lignes = pl.rowid";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.fk_soc = s.rowid";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND s.rowid = ".$socid; if ($socid) $sql.= " AND s.rowid = ".$socid;
if ($search_line) $sql.= " AND pl.rowid = '".$db->escape($search_line)."'"; if ($search_line) $sql.= " AND pl.rowid = '".$db->escape($search_line)."'";
if ($search_bon) $sql.= natural_search("p.ref", $search_bon); if ($search_bon) $sql.= natural_search("p.ref", $search_bon);

View File

@ -122,7 +122,7 @@ if ($id > 0)
$sql.= " u.login, u.rowid as userid"; $sql.= " u.login, u.rowid as userid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id; $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.fk_user_valid = u.rowid"; $sql.= " AND f.fk_user_valid = u.rowid";
$sql.= $db->order($sortfield, $sortorder); $sql.= $db->order($sortfield, $sortorder);

View File

@ -371,7 +371,7 @@ else
if (! empty($date_start) && ! empty($date_end)) if (! empty($date_start) && ! empty($date_end))
$sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
} }
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql.= " GROUP BY name, socid"; $sql.= " GROUP BY name, socid";
$sql.= $db->order($sortfield, $sortorder); $sql.= $db->order($sortfield, $sortorder);
@ -991,7 +991,7 @@ else
$sql.= " AND f.type IN (0,1,2,3,5)"; $sql.= " AND f.type IN (0,1,2,3,5)";
if (! empty($date_start) && ! empty($date_end)) if (! empty($date_start) && ! empty($date_end))
$sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$newsortfield = $sortfield; $newsortfield = $sortfield;
if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'dm'; if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'dm';

View File

@ -207,7 +207,7 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo
$sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
} }
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND f.fk_soc = $socid"; if ($socid) $sql.= " AND f.fk_soc = $socid";
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= " ORDER BY dm"; $sql.= " ORDER BY dm";
@ -370,7 +370,7 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco
$sql.= " WHERE f.fk_statut IN (1,2)"; $sql.= " WHERE f.fk_statut IN (1,2)";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if (! empty($date_start) && ! empty($date_end)) if (! empty($date_start) && ! empty($date_end))
$sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";

View File

@ -259,7 +259,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= ")"; $sql.= ")";
$sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid"; $sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
} }
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.fk_product_type"; $sql.= " GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
$sql.= $db->order($sortfield,$sortorder); $sql.= $db->order($sortfield,$sortorder);

View File

@ -232,7 +232,7 @@ if ($modecompta == 'CREANCES-DETTES') {
$sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
} }
} }
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql .= " GROUP BY u.rowid, u.lastname, u.firstname"; $sql .= " GROUP BY u.rowid, u.lastname, u.firstname";
$sql .= " ORDER BY u.rowid"; $sql .= " ORDER BY u.rowid";

View File

@ -291,7 +291,7 @@ if (!empty($search_societe)) $sql.= natural_search('s.nom', $search_societe);
if (!empty($search_zip)) $sql.= natural_search('s.zip', $search_zip); if (!empty($search_zip)) $sql.= natural_search('s.zip', $search_zip);
if (!empty($search_town)) $sql.= natural_search('s.town', $search_town); if (!empty($search_town)) $sql.= natural_search('s.town', $search_town);
if ($search_country > 0) $sql.= ' AND s.fk_pays = '.$search_country.''; if ($search_country > 0) $sql.= ' AND s.fk_pays = '.$search_country.'';
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql.= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays"; $sql.= " GROUP BY s.rowid, s.nom, s.zip, s.town, s.fk_pays";
$sql.= " ORDER BY s.rowid"; $sql.= " ORDER BY s.rowid";

View File

@ -171,7 +171,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " WHERE f.fk_statut in (1,2)"; $sql.= " WHERE f.fk_statut in (1,2)";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
} }
else if ($modecompta=="RECETTES-DEPENSES") else if ($modecompta=="RECETTES-DEPENSES")
@ -186,7 +186,7 @@ else if ($modecompta=="RECETTES-DEPENSES")
$sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
$sql.= " WHERE p.rowid = pf.fk_paiement"; $sql.= " WHERE p.rowid = pf.fk_paiement";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
} }
else if ($modecompta=="BOOKKEEPING") else if ($modecompta=="BOOKKEEPING")

View File

@ -100,7 +100,7 @@ class box_factures extends ModeleBoxes
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ")"; $sql.= ")";
$sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY f.datef DESC, f.ref DESC "; if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY f.datef DESC, f.ref DESC ";

View File

@ -102,7 +102,7 @@ class box_factures_imp extends ModeleBoxes
$sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture "; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
$sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.paye = 0"; $sql.= " AND f.paye = 0";
$sql.= " AND fk_statut = 1"; $sql.= " AND fk_statut = 1";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;

View File

@ -152,7 +152,7 @@ function tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $di
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -191,7 +191,7 @@ function tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $di
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -300,7 +300,7 @@ function tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $di
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -339,7 +339,7 @@ function tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $di
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -621,7 +621,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -660,7 +660,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -769,7 +769,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";
@ -808,7 +808,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d"; $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity($invoicetable).")";
$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely) $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)"; 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)"; else $sql.= " AND f.type IN (0,1,2,3,5)";

View File

@ -152,7 +152,6 @@ class mod_facture_mars extends ModeleNumRefFactures
function getNextValue($objsoc, $invoice, $mode='next') function getNextValue($objsoc, $invoice, $mode='next')
{ {
global $db; global $db;
$prefix=$this->prefixinvoice; $prefix=$this->prefixinvoice;
if ($invoice->type == 1) $prefix=$this->prefixreplacement; if ($invoice->type == 1) $prefix=$this->prefixreplacement;

View File

@ -174,7 +174,6 @@ class mod_facture_terre extends ModeleNumRefFactures
if ($invoice->type == 2) $prefix=$this->prefixcreditnote; if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
else if ($invoice->type == 3) $prefix=$this->prefixdeposit; else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
else $prefix=$this->prefixinvoice; else $prefix=$this->prefixinvoice;
// D'abord on recupere la valeur max // D'abord on recupere la valeur max
$posindice=8; $posindice=8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL

View File

@ -201,7 +201,7 @@ class pdf_paiement
$sql.= " WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid"; $sql.= " WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
if (! empty($conf->banque->enabled)) if (! empty($conf->banque->enabled))
$sql.= " AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid "; $sql.= " AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'"; $sql.= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'";
if (! $user->rights->societe->client->voir && ! $socid) if (! $user->rights->societe->client->voir && ! $socid)
{ {

View File

@ -154,7 +154,7 @@ if ($socid > 0)
$sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d";
$sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.fk_statut > 0"; $sql.= " AND f.fk_statut > 0";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity IN (".getEntity('invoice').")";
$sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND d.fk_facture = f.rowid";
$sql.= " AND f.fk_soc = $socid"; $sql.= " AND f.fk_soc = $socid";
$sql.= " AND d.buy_price_ht IS NOT NULL"; $sql.= " AND d.buy_price_ht IS NOT NULL";

View File

@ -418,7 +418,7 @@ function activitytrim($product_type)
$sql = "SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot"; $sql = "SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
$sql.= " , ".MAIN_DB_PREFIX."paiement as p,".MAIN_DB_PREFIX."paiement_facture as pf"; $sql.= " , ".MAIN_DB_PREFIX."paiement as p,".MAIN_DB_PREFIX."paiement_facture as pf";
$sql.= " WHERE f.entity = " . $conf->entity; $sql.= " WHERE f.entity IN (".getEntity('invoice').")";
$sql.= " AND f.rowid = fd.fk_facture"; $sql.= " AND f.rowid = fd.fk_facture";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND pf.fk_paiement= p.rowid"; $sql.= " AND pf.fk_paiement= p.rowid";

View File

@ -204,7 +204,7 @@ if ($type_element == 'invoice')
$tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d"; $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
$where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid;
$where.= " AND d.fk_facture = f.rowid"; $where.= " AND d.fk_facture = f.rowid";
$where.= " AND f.entity = ".$conf->entity; $where.= " AND f.entity IN (".getEntity('invoice').")";
$dateprint = 'f.datef'; $dateprint = 'f.datef';
$doc_number='f.ref'; $doc_number='f.ref';
$thirdTypeSelect='customer'; $thirdTypeSelect='customer';

View File

@ -770,7 +770,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)';
} }
$sql.= ' WHERE f.entity = '.$conf->entity; $sql.= ' WHERE f.entity IN ('.getEntity('invoice').")";
$sql.= ' AND (f.fk_soc = '.$facture->socid; $sql.= ' AND (f.fk_soc = '.$facture->socid;
if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) { if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
@ -1077,7 +1077,7 @@ if (! GETPOST('action'))
$sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement'; $sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
$sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id'; $sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
$sql.= ' AND f.entity = '.$conf->entity; $sql.= ' AND f.entity IN ('.getEntity('invoice').")";
if ($socid) if ($socid)
{ {
$sql.= ' AND f.fk_soc = '.$socid; $sql.= ' AND f.fk_soc = '.$socid;

View File

@ -128,7 +128,7 @@ $sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND s.fk_pays = cp.rowid"; $sql .= " AND s.fk_pays = cp.rowid";
if (! empty($date_start) && ! empty($date_end)) if (! empty($date_start) && ! empty($date_end))
$sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'"; $sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
$sql .= " AND f.entity = " . $conf->entity; $sql .= " AND f.entity IN (".getEntity('invoice',0).")";
if ($socid) if ($socid)
$sql .= " AND f.fk_soc = " . $socid; $sql .= " AND f.fk_soc = " . $socid;
$sql .= " GROUP BY name"; $sql .= " GROUP BY name";