本文整理汇总了PHP中DoliDB类的典型用法代码示例。如果您正苦于以下问题:PHP DoliDB类的具体用法?PHP DoliDB怎么用?PHP DoliDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DoliDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pt
/**
* pt
*
* @param DoliDB $db Database handler
* @param string $sql SQL Request
* @param string $date Date
* @return void
*/
function pt($db, $sql, $date)
{
global $conf, $bc, $langs;
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$total = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td class="nowrap" width="60%">' . $date . '</td>';
print '<td align="right">' . $langs->trans("Amount") . '</td>';
print '<td> </td>' . "\n";
print "</tr>\n";
$var = True;
while ($i < $num) {
$obj = $db->fetch_object($result);
$var = !$var;
print '<tr ' . $bc[$var] . '>';
print '<td class="nowrap">' . $obj->dm . "</td>\n";
$total = $total + $obj->mm;
print '<td class="nowrap" align="right">' . price($obj->mm) . "</td><td > </td>\n";
print "</tr>\n";
$i++;
}
print '<tr class="liste_total"><td align="right">' . $langs->trans("Total") . " :</td><td class=\"nowrap\" align=\"right\"><b>" . price($total) . "</b></td><td> </td></tr>";
print "</table>";
$db->free($result);
} else {
dol_print_error($db);
}
}
示例2: migrate_event_assignement
/**
* Migrate event assignement to owner
*
* @param DoliDB $db Database handler
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return void
*/
function migrate_event_assignement($db, $langs, $conf)
{
print '<tr><td colspan="4">';
print '<br>';
print '<b>' . $langs->trans('MigrationEvents') . "</b><br>\n";
$error = 0;
dolibarr_install_syslog("upgrade2::migrate_event_assignement");
$db->begin();
$sqlSelect = "SELECT a.id, a.fk_user_action";
$sqlSelect .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
$sqlSelect .= " LEFT JOIN " . MAIN_DB_PREFIX . "actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'user' AND ar.fk_element = a.fk_user_action";
$sqlSelect .= " WHERE fk_user_action > 0 AND fk_user_action NOT IN (SELECT fk_element FROM " . MAIN_DB_PREFIX . "actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'user')";
$sqlSelect .= " ORDER BY a.id";
//print $sqlSelect;
$resql = $db->query($sqlSelect);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
if ($num) {
while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
$sqlUpdate .= "VALUES(" . $obj->id . ", 'user', " . $obj->fk_user_action . ")";
$result = $db->query($sqlUpdate);
if (!$result) {
$error++;
dol_print_error($db);
}
print ". ";
$i++;
}
} else {
print $langs->trans('AlreadyDone') . "<br>\n";
}
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
} else {
dol_print_error($db);
$db->rollback();
}
print '</td></tr>';
}
示例3:
/**
* Return if a code is used (by other element)
*
* @param DoliDB $db Handler acces base
* @param string $code Code a verifier
* @param Product $product Objet product
* @return int 0 if available, <0 if KO
*/
function verif_dispo($db, $code, $product)
{
$sql = "SELECT barcode FROM " . MAIN_DB_PREFIX . "product";
$sql .= " WHERE barcode = '" . $code . "'";
if ($product->id > 0) {
$sql .= " AND rowid <> " . $product->id;
}
$resql = $db->query($sql);
if ($resql) {
if ($db->num_rows($resql) == 0) {
return 0;
} else {
return -1;
}
} else {
return -2;
}
}
示例4: print_left_auguria_menu
/**
* Core function to output left menu auguria
*
* @param DoliDB $db Database handler
* @param array $menu_array_before Table of menu entries to show before entries of menu handler
* @param array $menu_array_after Table of menu entries to show after entries of menu handler
* @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
* @param Menu $menu Object Menu to return back list of menu entries
* @param int $noout Disable output (Initialise &$menu only).
* @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x'
* @param string $forceleftmenu 'all'=Force leftmenu to '' (= all)
* @param array $moredata An array with more data to output
* @return int Nb of entries
*/
function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null)
{
global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
$newmenu = $menu;
$mainmenu = $forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"];
$leftmenu = $forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]);
// Show logo company
if (empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$mysoc->logo_mini = $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
if (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_mini)) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=companylogo&file=' . urlencode('thumbs/' . $mysoc->logo_mini);
} else {
$urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
}
$title = $langs->trans("GoIntoSetupToChangeLogo");
print "\n" . '<!-- Show logo on menu -->' . "\n";
print '<div class="blockvmenuimpair blockvmenulogo">' . "\n";
print '<div class="menu_titre" id="menu_titre_logo"></div>';
print '<div class="menu_top" id="menu_top_logo"></div>';
print '<div class="menu_contenu" id="menu_contenu_logo">';
print '<div class="center"><img title="' . dol_escape_htmltag($title) . '" alt="" src="' . $urllogo . '" style="max-width: 80%"></div>' . "\n";
print '</div>';
print '<div class="menu_end" id="menu_end_logo"></div>';
print '</div>' . "\n";
}
if (is_array($moredata) && !empty($moredata['searchform'])) {
print "\n";
print "<!-- Begin SearchForm -->\n";
print '<div id="blockvmenusearch" class="blockvmenusearch">' . "\n";
print $moredata['searchform'];
print '</div>' . "\n";
print "<!-- End SearchForm -->\n";
}
// We update newmenu with entries found into database
$menuArbo = new Menubase($db, 'auguria');
$newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, $user->societe_id ? 1 : 0, 'auguria', $tabMenu);
// We update newmenu for special dynamic menus
if ($conf->banque->enabled && $user->rights->banque->lire && $mainmenu == 'bank') {
$sql = "SELECT rowid, label, courant, rappro, courant";
$sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
$sql .= " WHERE entity = " . $conf->entity;
$sql .= " AND clos = 0";
$sql .= " ORDER BY label";
$resql = $db->query($sql);
if ($resql) {
$numr = $db->num_rows($resql);
$i = 0;
if ($numr > 0) {
$newmenu->add('/compta/bank/index.php', $langs->trans("BankAccounts"), 0, $user->rights->banque->lire);
}
while ($i < $numr) {
$objp = $db->fetch_object($resql);
$newmenu->add('/compta/bank/card.php?id=' . $objp->rowid, $objp->label, 1, $user->rights->banque->lire);
if ($objp->rappro && $objp->courant != 2 && empty($objp->clos)) {
$newmenu->add('/compta/bank/rappro.php?account=' . $objp->rowid, $langs->trans("Conciliate"), 2, $user->rights->banque->consolidate);
}
$i++;
}
} else {
dol_print_error($db);
}
$db->free($resql);
}
if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->mouvements->lire) && $mainmenu == 'accountancy') {
$newmenu->add('/accountancy/journal/index.php?leftmenu=journal', $langs->trans("Journaux"), 0, $user->rights->banque->lire);
if ($leftmenu == 'journal') {
$sql = "SELECT rowid, label, accountancy_journal";
$sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
$sql .= " WHERE entity = " . $conf->entity;
$sql .= " AND clos = 0";
$sql .= " ORDER BY label";
$resql = $db->query($sql);
if ($resql) {
$numr = $db->num_rows($resql);
$i = 0;
if ($numr > 0) {
while ($i < $numr) {
$objp = $db->fetch_object($resql);
$newmenu->add('/accountancy/journal/bankjournal.php?id_account=' . $objp->rowid, $langs->trans("Journal") . ' - ' . $objp->label, 1, $user->rights->accounting->comptarapport->lire);
$i++;
}
}
} else {
dol_print_error($db);
}
$db->free($resql);
//.........这里部分代码省略.........
示例5: tva_paye
/**
* Gets VAT to pay for the given month of the given year
* The function gets the VAT in split results, as the VAT declaration asks
* to report the amounts for different VAT rates as different lines
*
* @param DoliDB $db Database handler object
* @param int $y Year
* @param int $q Year quarter (1-4)
* @return array
*/
function tva_paye($db, $y, $q)
{
global $conf;
if ($conf->global->ACCOUNTING_MODE == "CREANCES-DETTES") {
// Si on paye la tva sur les factures dues (non brouillon)
$sql = "SELECT d.fk_facture_fourn as facid, f.ref_supplier as facnum, d.tva_tx as rate, d.total_ht as totalht, d.tva as amount";
$sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
$sql .= ", " . MAIN_DB_PREFIX . "facture_fourn_det as d";
$sql .= ", " . MAIN_DB_PREFIX . "societe as s";
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity = " . $conf->entity;
$sql .= " AND f.fk_statut = 1 ";
$sql .= " AND f.rowid = d.fk_facture_fourn ";
$sql .= " AND date_format(f.datef,'%Y') = '" . $y . "'";
$sql .= " AND (round(date_format(f.datef,'%m')) > " . ($q - 1) * 3;
$sql .= " AND round(date_format(f.datef,'%m')) <= " . $q * 3 . ")";
$sql .= " ORDER BY rate, facid ";
} else {
// Si on paye la tva sur les payments
}
$resql = $db->query($sql);
if ($resql) {
$list = array();
$rate = -1;
while ($assoc = $db->fetch_array($resql)) {
if ($assoc['rate'] != $rate) {
//new rate
$list[$assoc['rate']]['totalht'] = $assoc['totalht'];
$list[$assoc['rate']]['vat'] = $assoc['amount'];
$list[$assoc['rate']]['facid'][] = $assoc['facid'];
$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
} else {
$list[$assoc['rate']]['totalht'] += $assoc['totalht'];
$list[$assoc['rate']]['vat'] += $assoc['amount'];
if (!in_array($assoc['facid'], $list[$assoc['rate']]['facid'])) {
$list[$assoc['rate']]['facid'][] = $assoc['facid'];
$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
}
}
$rate = $assoc['rate'];
}
return $list;
} else {
dol_print_error($db);
}
}
示例6: AddNotification
/**
* Add a notification
*
* @param DoliDB $db database handler
* @param User $user notification user
* @param string $action notification action
* @return int 0 if OK, <0 if KO
*/
function AddNotification($db, $user, $action)
{
$result = 0;
if ($this->DeleteNotification($user, $action) == 0) {
$now = dol_now();
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
$sql .= " VALUES (" . $db->idate($now) . "," . $user . ", 'NULL', 'NULL', '" . $action . "')";
dol_syslog("adnotiff: " . $sql);
if ($this->db->query($sql)) {
$result = 0;
} else {
$result = -1;
dol_syslog(get_class($this) . "::AddNotification Error {$result}");
}
}
return $result;
}
示例7: setValues
/**
* Load setup values into conf object (read llx_const)
* Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setValues is called.
*
* @param DoliDB $db Database handler
* @return int < 0 if KO, >= 0 if OK
*/
function setValues($db)
{
global $conf;
dol_syslog(get_class($this) . "::setValues");
/*
* Definition de toutes les constantes globales d'environnement
* - En constante php (TODO a virer)
* - En $this->global->key=value
*/
$sql = "SELECT " . $db->decrypt('name') . " as name,";
$sql .= " " . $db->decrypt('value') . " as value, entity";
$sql .= " FROM " . MAIN_DB_PREFIX . "const";
if (!empty($this->multicompany->transverse_mode)) {
$sql .= " WHERE entity IN (0,1," . $this->entity . ")";
} else {
$sql .= " WHERE entity IN (0," . $this->entity . ")";
}
$sql .= " ORDER BY entity";
// This is to have entity 0 first, then entity 1 that overwrite.
$resql = $db->query($sql);
if ($resql) {
$i = 0;
$numr = $db->num_rows($resql);
while ($i < $numr) {
$objp = $db->fetch_object($resql);
$key = $objp->name;
$value = $objp->value;
if ($key) {
if (!defined("{$key}")) {
define("{$key}", $value);
}
// In some cases, the constant might be already forced (Example: SYSLOG_HANDLERS during install)
$this->global->{$key} = $value;
if ($value && preg_match('/^MAIN_MODULE_/', $key)) {
// If this is constant for a new tab page activated by a module. It initializes modules_parts['tabs'].
if (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)_TABS_/i', $key)) {
$partname = 'tabs';
$params = explode(':', $value, 2);
if (!isset($this->modules_parts[$partname]) || !is_array($this->modules_parts[$partname])) {
$this->modules_parts[$partname] = array();
}
$this->modules_parts[$partname][$params[0]][] = $value;
// $value may be a string or an array
} elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)_([A-Z]+)$/i', $key, $reg)) {
$modulename = strtolower($reg[1]);
$partname = strtolower($reg[2]);
if (!isset($this->modules_parts[$partname]) || !is_array($this->modules_parts[$partname])) {
$this->modules_parts[$partname] = array();
}
$arrValue = json_decode($value, true);
if (is_array($arrValue) && !empty($arrValue)) {
$value = $arrValue;
} else {
if (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl'))) {
$value = '/' . $modulename . '/core/' . $partname . '/';
} else {
if (in_array($partname, array('models', 'theme'))) {
$value = '/' . $modulename . '/';
} else {
if (in_array($partname, array('sms'))) {
$value = $modulename;
} else {
if ($value == 1) {
$value = '/' . $modulename . '/core/modules/' . $partname . '/';
}
}
}
}
}
// ex: partname = societe
$this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value));
// $value may be a string or an array
} elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)$/i', $key, $reg)) {
$modulename = strtolower($reg[1]);
if ($modulename == 'propale') {
$modulename = 'propal';
}
if (!isset($this->{$modulename}) || !is_object($this->{$modulename})) {
$this->{$modulename} = new stdClass();
}
$this->{$modulename}->enabled = true;
$this->modules[] = $modulename;
// Add this module in list of enabled modules
}
}
}
$i++;
}
$db->free($resql);
}
//var_dump($this->modules);
//var_dump($this->modules_parts['theme']);
// If you can't set timezone of your PHP, set this constant. Better is to set it to UTC.
//.........这里部分代码省略.........
示例8: commonReplaceThirdparty
/**
* Function used to replace a thirdparty id with another one.
* This function is meant to be called from replaceThirdparty with the appropiate tables
* Column name fk_soc MUST be used to identify thirdparties
*
* @param DoliDB $db Database handler
* @param int $origin_id Old thirdparty id (the thirdparty to delete)
* @param int $dest_id New thirdparty id (the thirdparty that will received element of the other)
* @param array $tables Tables that need to be changed
* @return bool
*/
public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables)
{
foreach ($tables as $table) {
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $table . ' SET fk_soc = ' . $dest_id . ' WHERE fk_soc = ' . $origin_id;
if (!$db->query($sql)) {
return false;
}
}
return true;
}
示例9: cleanCorruptedTree
/**
* Clean corrupted tree (orphelins linked to a not existing parent), record linked to themself and child-parent loop
*
* @param DoliDB $db Database handler
* @param string $tabletocleantree Table to clean
* @param string $fieldfkparent Field name that contains id of parent
* @return int Nb of records fixed/deleted
*/
function cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
{
$totalnb = 0;
$listofid = array();
$listofparentid = array();
// Get list of all id in array listofid and all parents in array listofparentid
$sql = 'SELECT rowid, ' . $fieldfkparent . ' as parent_id FROM ' . MAIN_DB_PREFIX . $tabletocleantree;
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql);
$listofid[] = $obj->rowid;
if ($obj->parent_id > 0) {
$listofparentid[$obj->rowid] = $obj->parent_id;
}
$i++;
}
} else {
dol_print_error($db);
}
if (count($listofid)) {
print 'Code requested to clean tree (may be to solve data corruption), so we check/clean orphelins and loops.' . "<br>\n";
// Check loops on each other
$sql = "UPDATE " . MAIN_DB_PREFIX . $tabletocleantree . " SET " . $fieldfkparent . " = 0 WHERE " . $fieldfkparent . " = rowid";
// So we update only records linked to themself
$resql = $db->query($sql);
if ($resql) {
$nb = $db->affected_rows($sql);
if ($nb > 0) {
print '<br>Some record that were parent of themself were cleaned.';
}
$totalnb += $nb;
}
//else dol_print_error($db);
// Check other loops
$listofidtoclean = array();
foreach ($listofparentid as $id => $pid) {
// Check depth
//print 'Analyse record id='.$id.' with parent '.$pid.'<br>';
$cursor = $id;
$arrayidparsed = array();
// We start from child $id
while ($cursor > 0) {
$arrayidparsed[$cursor] = 1;
if ($arrayidparsed[$listofparentid[$cursor]]) {
print 'Found a loop between id ' . $id . ' - ' . $cursor . '<br>';
unset($arrayidparsed);
$listofidtoclean[$cursor] = $id;
break;
}
$cursor = $listofparentid[$cursor];
}
if (count($listofidtoclean)) {
break;
}
}
$sql = "UPDATE " . MAIN_DB_PREFIX . $tabletocleantree;
$sql .= " SET " . $fieldfkparent . " = 0";
$sql .= " WHERE rowid IN (" . join(',', $listofidtoclean) . ")";
// So we update only records detected wrong
$resql = $db->query($sql);
if ($resql) {
$nb = $db->affected_rows($sql);
if ($nb > 0) {
// Removed orphelins records
print '<br>Some records were detected to have parent that is a child, we set them as root record for id: ';
print join(',', $listofidtoclean);
}
$totalnb += $nb;
}
//else dol_print_error($db);
// Check and clean orphelins
$sql = "UPDATE " . MAIN_DB_PREFIX . $tabletocleantree;
$sql .= " SET " . $fieldfkparent . " = 0";
$sql .= " WHERE " . $fieldfkparent . " NOT IN (" . join(',', $listofid) . ")";
// So we update only records linked to a non existing parent
$resql = $db->query($sql);
if ($resql) {
$nb = $db->affected_rows($sql);
if ($nb > 0) {
// Removed orphelins records
print '<br>Some orphelins were found and modified to be parent so records are visible again for id: ';
print join(',', $listofid);
}
$totalnb += $nb;
}
//else dol_print_error($db);
print '<br>We fixed ' . $totalnb . ' record(s). Some records may still be corrupted. New check may be required.';
return $totalnb;
}
//.........这里部分代码省略.........
示例10: show_subsidiaries
/**
* Show html area for list of subsidiaries
*
* @param Conf $conf Object conf
* @param Translate $langs Object langs
* @param DoliDB $db Database handler
* @param Societe $object Third party object
* @return void
*/
function show_subsidiaries($conf, $langs, $db, $object)
{
global $user;
global $bc;
$i = -1;
$sql = "SELECT s.rowid, s.nom as name, s.address, s.zip, s.town, s.code_client, s.canvas";
$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
$sql .= " WHERE s.parent = " . $object->id;
$sql .= " AND s.entity IN (" . getEntity('societe', 1) . ")";
$sql .= " ORDER BY s.nom";
$result = $db->query($sql);
$num = $db->num_rows($result);
if ($num) {
$socstatic = new Societe($db);
print_titre($langs->trans("Subsidiaries"));
print "\n" . '<table class="noborder" width="100%">' . "\n";
print '<tr class="liste_titre"><td>' . $langs->trans("Company") . '</td>';
print '<td>' . $langs->trans("Address") . '</td><td>' . $langs->trans("Zip") . '</td>';
print '<td>' . $langs->trans("Town") . '</td><td>' . $langs->trans("CustomerCode") . '</td>';
print "<td> </td>";
print "</tr>";
$i = 0;
$var = true;
while ($i < $num) {
$obj = $db->fetch_object($result);
$var = !$var;
print "<tr " . $bc[$var] . ">";
print '<td>';
$socstatic->id = $obj->rowid;
$socstatic->name = $obj->name;
$socstatic->canvas = $obj->canvas;
print $socstatic->getNomUrl(1);
print '</td>';
print '<td>' . $obj->address . '</td>';
print '<td>' . $obj->zip . '</td>';
print '<td>' . $obj->town . '</td>';
print '<td>' . $obj->code_client . '</td>';
print '<td align="center">';
print '<a href="' . DOL_URL_ROOT . '/societe/soc.php?socid=' . $obj->rowid . '&action=edit">';
print img_edit();
print '</a></td>';
print "</tr>\n";
$i++;
}
print "\n</table>\n";
}
print "<br>\n";
return $i;
}
示例11:
/**
* Renvoi si un code est pris ou non (par autre tiers)
*
* @param DoliDB $db Handler acces base
* @param string $code Code a verifier
* @param Societe $soc Objet societe
* @return int 0 if available, <0 if KO
*/
function verif_dispo($db, $code, $soc)
{
$sql = "SELECT code_client FROM " . MAIN_DB_PREFIX . "societe";
$sql .= " WHERE code_client = '" . $code . "'";
if ($soc->id > 0) {
$sql .= " AND rowid <> " . $soc->id;
}
$resql = $db->query($sql);
if ($resql) {
if ($db->num_rows($resql) == 0) {
return 0;
} else {
return -1;
}
} else {
return -2;
}
}
示例12: getEMailTemplate
/**
* Return template of email
* Search into table c_email_templates
*
* @param DoliDB $db Database handler
* @param string $type_template Get message for key module
* @param string $user Use template public or limited to this user
* @param Translate $outputlangs Output lang object
* @param int $id Id template to find
* @return array array('topic'=>,'content'=>,..)
*/
private function getEMailTemplate($db, $type_template, $user, $outputlangs, $id = 0)
{
$ret = array();
$sql = "SELECT label, topic, content, lang";
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_email_templates';
$sql .= " WHERE type_template='" . $db->escape($type_template) . "'";
$sql .= " AND entity IN (" . getEntity("c_email_templates") . ")";
$sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = " . $user->id . ")";
if (is_object($outputlangs)) {
$sql .= " AND (lang = '" . $outputlangs->defaultlang . "' OR lang IS NULL OR lang = '')";
}
if (!empty($id)) {
$sql .= " AND rowid=" . $id;
}
$sql .= $db->order("lang,label", "ASC");
//print $sql;
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
// Get first found
if ($obj) {
$ret['label'] = $obj->label;
$ret['topic'] = $obj->topic;
$ret['content'] = $obj->content;
$ret['lang'] = $obj->lang;
} else {
$defaultmessage = '';
if ($type_template == 'facture_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice");
} elseif ($type_template == 'facture_relance') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder");
} elseif ($type_template == 'propal_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal");
} elseif ($type_template == 'askpricesupplier_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendAskPriceSupplier");
} elseif ($type_template == 'order_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder");
} elseif ($type_template == 'order_supplier_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder");
} elseif ($type_template == 'invoice_supplier_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice");
} elseif ($type_template == 'shipping_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping");
} elseif ($type_template == 'fichinter_send') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter");
} elseif ($type_template == 'thirdparty') {
$defaultmessage = $outputlangs->transnoentities("PredefinedMailContentThirdparty");
}
$ret['label'] = 'default';
$ret['topic'] = '';
$ret['content'] = $defaultmessage;
$ret['lang'] = $outputlangs->defaultlang;
}
$db->free($resql);
return $ret;
} else {
dol_print_error($db);
return -1;
}
}
示例13: verif
/**
* Return if a code is available
*
* @param DoliDB $db Database handler
* @param string $code Code of third party
* @param Societe $societe Object third party
* @param string $type 'supplier' or 'customer'
* @return int 0 if OK but not available, >0 if OK and available, <0 if KO
*/
function verif($db, $code, $societe, $type)
{
$sql = "SELECT ";
if ($type == 'customer') {
$sql .= "code_compta";
} else {
if ($type == 'supplier') {
$sql .= "code_compta_fournisseur";
}
}
$sql .= " FROM " . MAIN_DB_PREFIX . "societe";
$sql .= " WHERE ";
if ($type == 'customer') {
$sql .= "code_compta";
} else {
if ($type == 'supplier') {
$sql .= "code_compta_fournisseur";
}
}
$sql .= " = '" . $this->db->escape($code) . "'";
if (!empty($societe->id)) {
$sql .= " AND rowid <> " . $societe->id;
}
$resql = $db->query($sql);
if ($resql) {
if ($db->num_rows($resql) == 0) {
dol_syslog("mod_codecompta_aquarium::verif code '" . $code . "' available");
return 1;
// Dispo
} else {
dol_syslog("mod_codecompta_aquarium::verif code '" . $code . "' not available");
return 0;
// Non dispo
}
} else {
$this->error = $db->error() . " sql=" . $sql;
dol_syslog("mod_codecompta_aquarium::verif error" . $this->error, LOG_ERR);
return -1;
// Erreur
}
}
示例14: fetchAll
/**
* Retrieve all batch number details link to a shipment line
*
* @param DoliDB $db Database object
* @param int $id_line_expdet id of shipment line
* @return variant -1 if KO, array of ExpeditionLineBatch if OK
*/
static function fetchAll($db, $id_line_expdet)
{
$sql = "SELECT rowid,";
$sql .= "fk_expeditiondet";
$sql .= ", sellby";
$sql .= ", eatby";
$sql .= ", batch";
$sql .= ", qty";
$sql .= ", fk_origin_stock";
$sql .= " FROM " . MAIN_DB_PREFIX . self::$_table_element;
$sql .= " WHERE fk_expeditiondet=" . (int) $id_line_expdet;
dol_syslog(__METHOD__ . "", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$tmp = new self($db);
$obj = $db->fetch_object($resql);
$tmp->sellby = $db->jdate($obj->sellby);
$tmp->eatby = $db->jdate($obj->eatby);
$tmp->batch = $obj->batch;
$tmp->id = $obj->rowid;
$tmp->fk_origin_stock = $obj->fk_origin_stock;
$tmp->fk_expeditiondet = $obj->fk_expeditiondet;
$tmp->dluo_qty = $obj->qty;
$ret[] = $tmp;
$i++;
}
$db->free($resql);
return $ret;
} else {
return -1;
}
}
示例15: replaceThirdparty
/**
* Function used to replace a thirdparty id with another one.
* It must be used within a transaction to avoid trouble
*
* @param DoliDB $db Database handler
* @param int $origin_id Old thirdparty id
* @param int $dest_id New thirdparty id
* @return bool
*/
public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
{
/**
* Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some
* Because this function is meant to be executed within a transaction, we won't take care of it.
*/
$sql = 'SELECT rowid
FROM llx_societe_commerciaux
WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN (
SELECT fk_user
FROM llx_societe_commerciaux
WHERE fk_soc = '.(int) $origin_id.'
);';
$query = $db->query($sql);
while ($result = $db->fetch_object($query)) {
$db->query('DELETE FROM llx_societe_commerciaux WHERE rowid = '.$result->rowid);
}
/**
* llx_societe_extrafields table must not be here because we don't care about the old thirdparty data
* Do not include llx_societe because it will be replaced later
*/
$tables = array(
'societe_address',
'societe_commerciaux',
'societe_log',
'societe_prices',
'societe_remise',
'societe_remise_except',
'societe_rib'
);
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
}