Qual: Better compatibility with other databases

This commit is contained in:
Laurent Destailleur 2009-10-28 17:47:44 +00:00
parent 78643ec12a
commit c451386b8e

View File

@ -45,26 +45,26 @@ $result = restrictedArea($user, 'societe',$socid,'');
if ($mode == 'search') if ($mode == 'search')
{ {
if ($mode-search == 'soc') if ($mode-search == 'soc')
{ {
$sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s "; $sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s ";
$sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'"; $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
} }
if ( $db->query($sql) ) if ( $db->query($sql) )
{ {
if ( $db->num_rows() == 1) if ( $db->num_rows() == 1)
{ {
$obj = $db->fetch_object(); $obj = $db->fetch_object();
$socid = $obj->rowid; $socid = $obj->rowid;
} }
$db->free(); $db->free();
} }
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$socid = $user->societe_id; $socid = $user->societe_id;
} }
} }
@ -82,8 +82,8 @@ $form = new Form($db);
if ($socid > 0) if ($socid > 0)
{ {
$societe = new Societe($db); $societe = new Societe($db);
$societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1"; $societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1";
if ($societe->id <= 0) if ($societe->id <= 0)
{ {
dol_print_error($db,$societe->error); dol_print_error($db,$societe->error);
@ -97,60 +97,60 @@ if ($socid > 0)
dol_fiche_head($head, 'compta', $langs->trans("ThirdParty"),0,'company'); dol_fiche_head($head, 'compta', $langs->trans("ThirdParty"),0,'company');
print '<table width="100%" class="notopnoleftnoright">'; print '<table width="100%" class="notopnoleftnoright">';
print '<tr><td valign="top" width="50%" class="notopnoleft">'; print '<tr><td valign="top" width="50%" class="notopnoleft">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="100">'.$langs->trans("Name").'</td><td colspan="3">'.$societe->nom.'</td></tr>'; print '<tr><td width="100">'.$langs->trans("Name").'</td><td colspan="3">'.$societe->nom.'</td></tr>';
// Prefix // Prefix
print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
print ($societe->prefix_comm?$societe->prefix_comm:'&nbsp;'); print ($societe->prefix_comm?$societe->prefix_comm:'&nbsp;');
print '</td>'; print '</td>';
if ($societe->client) if ($societe->client)
{ {
print '<tr>'; print '<tr>';
print '<td nowrap>'.$langs->trans("CustomerCode"). '</td><td colspan="3">'. $societe->code_client . '</td>'; print '<td nowrap>'.$langs->trans("CustomerCode"). '</td><td colspan="3">'. $societe->code_client . '</td>';
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
print '<td nowrap>'.$langs->trans("CustomerAccountancyCode").'</td><td colspan="3">'.$societe->code_compta.'</td>'; print '<td nowrap>'.$langs->trans("CustomerAccountancyCode").'</td><td colspan="3">'.$societe->code_compta.'</td>';
print '</tr>'; print '</tr>';
} }
if ($societe->fournisseur) if ($societe->fournisseur)
{ {
print '<tr>'; print '<tr>';
print '<td nowrap>'.$langs->trans("SupplierCode"). '</td><td colspan="3">'. $societe->code_fournisseur . '</td>'; print '<td nowrap>'.$langs->trans("SupplierCode"). '</td><td colspan="3">'. $societe->code_fournisseur . '</td>';
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
print '<td nowrap>'.$langs->trans("SupplierAccountancyCode").'</td><td colspan="3">'.$societe->code_compta_fournisseur.'</td>'; print '<td nowrap>'.$langs->trans("SupplierAccountancyCode").'</td><td colspan="3">'.$societe->code_compta_fournisseur.'</td>';
print '</tr>'; print '</tr>';
} }
print '<tr><td valign="top">'.$langs->trans("Address").'</td><td colspan="3">'.nl2br($societe->adresse)."</td></tr>"; print '<tr><td valign="top">'.$langs->trans("Address").'</td><td colspan="3">'.nl2br($societe->adresse)."</td></tr>";
print '<tr><td>'.$langs->trans('Zip').'</td><td>'.$societe->cp.'</td>'; print '<tr><td>'.$langs->trans('Zip').'</td><td>'.$societe->cp.'</td>';
print '<td>'.$langs->trans('Town').'</td><td>'.$societe->ville.'</td></tr>'; print '<td>'.$langs->trans('Town').'</td><td>'.$societe->ville.'</td></tr>';
// Country // Country
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
if ($societe->isInEEC()) print $form->textwithpicto($societe->pays,$langs->trans("CountryIsInEEC"),1,0); if ($societe->isInEEC()) print $form->textwithpicto($societe->pays,$langs->trans("CountryIsInEEC"),1,0);
else print $societe->pays; else print $societe->pays;
print '</td></tr>'; print '</td></tr>';
// Phone // Phone
print '<tr><td>'.$langs->trans("Phone").'</td><td>'.dol_print_phone($societe->tel,$societe->pays_code,0,$societe->id,'AC_TEL').'</td>'; print '<tr><td>'.$langs->trans("Phone").'</td><td>'.dol_print_phone($societe->tel,$societe->pays_code,0,$societe->id,'AC_TEL').'</td>';
// Fax // Fax
print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($societe->fax,$societe->pays_code,0,$societe->id,'AC_FAX').'</td></tr>'; print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($societe->fax,$societe->pays_code,0,$societe->id,'AC_FAX').'</td></tr>';
// EMail // EMail
print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($societe->email,0,$societe->id,'AC_EMAIL').'</td></tr>'; print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($societe->email,0,$societe->id,'AC_EMAIL').'</td></tr>';
// Web // Web
print '<tr><td>'.$langs->trans("Web").'</td><td colspan="3">'.dol_print_url($societe->url,'_blank').'</td></tr>'; print '<tr><td>'.$langs->trans("Web").'</td><td colspan="3">'.dol_print_url($societe->url,'_blank').'</td></tr>';
// Assujeti a TVA ou pas // Assujeti a TVA ou pas
print '<tr>'; print '<tr>';
@ -159,185 +159,185 @@ if ($socid > 0)
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// TVA Intra // TVA Intra
print '<tr><td nowrap>'.$langs->trans('VATIntraVeryShort').'</td><td colspan="3">'; print '<tr><td nowrap>'.$langs->trans('VATIntraVeryShort').'</td><td colspan="3">';
print $societe->tva_intra; print $societe->tva_intra;
print '</td></tr>'; print '</td></tr>';
if ($societe->client == 1) if ($societe->client == 1)
{ {
// Remise permanente // Remise permanente
print '<tr><td nowrap>'; print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>'; print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("CustomerRelativeDiscountShort"); print $langs->trans("CustomerRelativeDiscountShort");
print '<td><td align="right">'; print '<td><td align="right">';
if (!$user->societe_id > 0) if (!$user->societe_id > 0)
{ {
print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$societe->id.'">'.img_edit($langs->trans("Modify")).'</a>'; print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$societe->id.'">'.img_edit($langs->trans("Modify")).'</a>';
} }
print '</td></tr></table>'; print '</td></tr></table>';
print '</td><td colspan="3">'.($societe->remise_client?price2num($societe->remise_client,'MT').'%':$langs->trans("DiscountNone")).'</td>'; print '</td><td colspan="3">'.($societe->remise_client?price2num($societe->remise_client,'MT').'%':$langs->trans("DiscountNone")).'</td>';
print '</tr>'; print '</tr>';
// Reductions (Discounts-Drawbacks-Rebates) // Reductions (Discounts-Drawbacks-Rebates)
print '<tr><td nowrap>'; print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding">'; print '<table width="100%" class="nobordernopadding">';
print '<tr><td nowrap>'; print '<tr><td nowrap>';
print $langs->trans("CustomerAbsoluteDiscountShort"); print $langs->trans("CustomerAbsoluteDiscountShort");
print '<td><td align="right">'; print '<td><td align="right">';
if (!$user->societe_id > 0) if (!$user->societe_id > 0)
{ {
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$societe->id.'">'.img_edit($langs->trans("Modify")).'</a>'; print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$societe->id.'">'.img_edit($langs->trans("Modify")).'</a>';
} }
print '</td></tr></table>'; print '</td></tr></table>';
print '</td>'; print '</td>';
print '<td colspan="3">'; print '<td colspan="3">';
$amount_discount=$societe->getAvailableDiscounts(); $amount_discount=$societe->getAvailableDiscounts();
if ($amount_discount < 0) dol_print_error($db,$societe->error); if ($amount_discount < 0) dol_print_error($db,$societe->error);
if ($amount_discount > 0) print price($amount_discount).'&nbsp;'.$langs->trans("Currency".$conf->monnaie); if ($amount_discount > 0) print price($amount_discount).'&nbsp;'.$langs->trans("Currency".$conf->monnaie);
else print $langs->trans("DiscountNone"); else print $langs->trans("DiscountNone");
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }
print "</table>"; print "</table>";
print "</td>\n"; print "</td>\n";
print '<td valign="top" width="50%" class="notopnoleftnoright">'; print '<td valign="top" width="50%" class="notopnoleftnoright">';
// Nbre max d'elements des petites listes // Nbre max d'elements des petites listes
$MAXLIST=5; $MAXLIST=5;
$tableaushown=1; $tableaushown=1;
// Lien recap // Lien recap
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="4"><table width="100%" class="noborder"><tr><td>'.$langs->trans("Summary").'</td>'; print '<td colspan="4"><table width="100%" class="noborder"><tr><td>'.$langs->trans("Summary").'</td>';
print '<td align="right"><a href="'.DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$societe->id.'">'.$langs->trans("ShowAccountancyPreview").'</a></td></tr></table></td>'; print '<td align="right"><a href="'.DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$societe->id.'">'.$langs->trans("ShowAccountancyPreview").'</a></td></tr></table></td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';
print '<br>'; print '<br>';
/* /*
* Last invoices * Last invoices
*/ */
if ($conf->facture->enabled && $user->rights->facture->lire) if ($conf->facture->enabled && $user->rights->facture->lire)
{ {
$facturestatic = new Facture($db); $facturestatic = new Facture($db);
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
$sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.total, f.total_ttc'; $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
$sql.= ', '.$db->pdate("f.datef").' as df, f.paye as paye, f.fk_statut as statut'; $sql.= ' '.$db->pdate("f.datef").' as df, '.$db->pdate("f.datec").' as dc, f.paye as paye, f.fk_statut as statut,';
$sql.= ', s.nom, s.rowid as socid'; $sql.= ' s.nom, s.rowid as socid,';
$sql.= ', sum(pf.amount) as am'; $sql.= ' sum(pf.amount) as am';
$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 = ".$societe->id; $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
$sql.= ' GROUP BY f.rowid'; $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.total_ttc, f.datef, f.datec, f.paye, f.fk_statut, s.nom, s.rowid';
$sql.= " ORDER BY f.datef DESC, f.datec DESC"; $sql.= " ORDER BY f.datef DESC, f.datec DESC";
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$var=true; $var=true;
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
if ($num > 0) if ($num > 0)
{ {
$tableaushown=1; $tableaushown=1;
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="4"><table width="100%" class="noborder"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$societe->id.'">'.$langs->trans("AllBills").' ('.$num.')</a></td></tr></table></td>'; print '<td colspan="4"><table width="100%" class="noborder"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$societe->id.'">'.$langs->trans("AllBills").' ('.$num.')</a></td></tr></table></td>';
print '</tr>'; print '</tr>';
} }
while ($i < $num && $i < $MAXLIST) while ($i < $num && $i < $MAXLIST)
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>'; print '<td>';
$facturestatic->id=$objp->facid; $facturestatic->id=$objp->facid;
$facturestatic->ref=$objp->facnumber; $facturestatic->ref=$objp->facnumber;
$facturestatic->type=$objp->type; $facturestatic->type=$objp->type;
print $facturestatic->getNomUrl(1); print $facturestatic->getNomUrl(1);
print '</td>'; print '</td>';
if ($objp->df > 0) if ($objp->df > 0)
{ {
print "<td align=\"right\">".dol_print_date($objp->df)."</td>\n"; print "<td align=\"right\">".dol_print_date($objp->df)."</td>\n";
} }
else else
{ {
print "<td align=\"right\"><b>!!!</b></td>\n"; print "<td align=\"right\"><b>!!!</b></td>\n";
} }
print "<td align=\"right\">".price($objp->total_ttc)."</td>\n"; print "<td align=\"right\">".price($objp->total_ttc)."</td>\n";
print '<td align="right" nowrap="nowrap">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am))."</td>\n"; print '<td align="right" nowrap="nowrap">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am))."</td>\n";
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
$db->free($resql); $db->free($resql);
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
print "</table>"; print "</table>";
} }
/* /*
* Last project * Last project
*/ */
if ($conf->projet->enabled && $user->rights->projet->lire) if ($conf->projet->enabled && $user->rights->projet->lire)
{ {
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
$sql = "SELECT p.rowid,p.title,p.ref,".$db->pdate("p.dateo")." as do"; $sql = "SELECT p.rowid,p.title,p.ref,".$db->pdate("p.dateo")." as do";
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql .= " WHERE p.fk_soc = $societe->id"; $sql .= " WHERE p.fk_soc = $societe->id";
$sql .= " ORDER by p.dateo"; $sql .= " ORDER by p.dateo";
if ( $db->query($sql) ) if ( $db->query($sql) )
{ {
$var=true; $var=true;
$i = 0 ; $i = 0 ;
$num = $db->num_rows(); $num = $db->num_rows();
if ($num > 0) if ($num > 0)
{ {
$tableaushown=1; $tableaushown=1;
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td colspan="2"><table width="100%" class="noborder"><tr><td>'.$langs->trans("LastProjects",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/projet/index.php?socid='.$societe->id.'">'.$langs->trans("AllProjects").' ('.$num.')</td></tr></table></td>'; print '<td colspan="2"><table width="100%" class="noborder"><tr><td>'.$langs->trans("LastProjects",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/projet/index.php?socid='.$societe->id.'">'.$langs->trans("AllProjects").' ('.$num.')</td></tr></table></td>';
print '</tr>'; print '</tr>';
} }
while ($i < $num && $i < $MAXLIST) while ($i < $num && $i < $MAXLIST)
{ {
$obj = $db->fetch_object(); $obj = $db->fetch_object();
$var = !$var; $var = !$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td><a href="../projet/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowProject"),"project")." ".$obj->title.'</a></td>'; print '<td><a href="../projet/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowProject"),"project")." ".$obj->title.'</a></td>';
print "<td align=\"right\">".dol_print_date($obj->do,"day") ."</td></tr>"; print "<td align=\"right\">".dol_print_date($obj->do,"day") ."</td></tr>";
$i++; $i++;
} }
$db->free(); $db->free();
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
print "</table>"; print "</table>";
} }
print "</td></tr>"; print "</td></tr>";
print "</table></div>\n"; print "</table></div>\n";
/* /*
* Barre d'actions * Barre d'actions
*/ */
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if ($user->societe_id == 0) if ($user->societe_id == 0)
{ {
@ -363,45 +363,45 @@ if ($socid > 0)
} }
} }
if ($conf->agenda->enabled) if ($conf->agenda->enabled)
{ {
if ($user->rights->agenda->myactions->create) if ($user->rights->agenda->myactions->create)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$socid.'">'.$langs->trans("AddAction").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$socid.'">'.$langs->trans("AddAction").'</a>';
} }
else else
{ {
print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>'; print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
} }
} }
if ($user->rights->societe->contact->creer) if ($user->rights->societe->contact->creer)
{ {
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT.'/contact/fiche.php?socid='.$socid."&amp;action=create\">".$langs->trans("AddContact")."</a>"; print "<a class=\"butAction\" href=\"".DOL_URL_ROOT.'/contact/fiche.php?socid='.$socid."&amp;action=create\">".$langs->trans("AddContact")."</a>";
} }
print '</div>'; print '</div>';
print "<br>\n"; print "<br>\n";
/* /*
* Liste des contacts * Liste des contacts
*/ */
show_contacts($conf,$langs,$db,$societe); show_contacts($conf,$langs,$db,$societe);
/* /*
* Listes des actions a faire * Listes des actions a faire
*/ */
show_actions_todo($conf,$langs,$db,$societe); show_actions_todo($conf,$langs,$db,$societe);
/* /*
* Listes des actions effectuees * Listes des actions effectuees
*/ */
show_actions_done($conf,$langs,$db,$societe); show_actions_done($conf,$langs,$db,$societe);
} }
else else
{ {
dol_print_error($db,'Bad value for socid parameter'); dol_print_error($db,'Bad value for socid parameter');
} }
$db->close(); $db->close();