コード例 #1
0
ファイル: index.php プロジェクト: TAASA/Dolibarr-ERP-3.8.1
/**
 * print function
 *
 * @param   DoliDB $db          Database
 * @param   string $sql     sql
 * @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>&nbsp;</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 >&nbsp;</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>&nbsp;</td></tr>";
        print "</table>";
        $db->free($result);
    } else {
        dol_print_error($db);
    }
}
コード例 #2
0
ファイル: tax.lib.php プロジェクト: Samara94/dolibarr
/**
 *  Look for collectable VAT clients in the chosen year (and month)
 *
 *  @param	DoliDB	$db          	Database handle
 *  @param  int		$y           	Year
 *  @param  string	$date_start  	Start date
 *  @param  string	$date_end    	End date
 *  @param  int		$modetax     	0 or 1 (option vat on debit, 1 => $modecompta = 'CREANCES-DETTES')
 *  @param  string	$direction   	'sell' or 'buy'
 *  @param  int		$m				Month
 *  @return array       			List of customers third parties with vat, -1 if no accountancy module, -2 if not yet developped, -3 if error
 */
function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction, $m = 0)
{
    global $conf;
    $list = array();
    if ($direction == 'sell') {
        $invoicetable = 'facture';
        $total_ht = 'total';
        $total_tva = 'tva';
    }
    if ($direction == 'buy') {
        $invoicetable = 'facture_fourn';
        $total_ht = 'total_ht';
        $total_tva = 'total_tva';
    }
    // Define sql request
    $sql = '';
    if ($modetax == 1) {
        // If vat paid on due invoices (non draft)
        $sql = "SELECT s.rowid as socid, s.nom as name, s.siren as tva_intra, s.tva_assuj as assuj,";
        $sql .= " sum(f.{$total_ht}) as amount, sum(f." . $total_tva . ") as tva,";
        $sql .= " sum(f.localtax1) as localtax1,";
        $sql .= " sum(f.localtax2) as localtax2";
        $sql .= " FROM " . MAIN_DB_PREFIX . $invoicetable . " as f,";
        $sql .= " " . MAIN_DB_PREFIX . "societe as s";
        $sql .= " WHERE f.entity = " . $conf->entity;
        $sql .= " AND f.fk_statut in (1,2)";
        // Validated or paid (partially or completely)
        if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
            $sql .= " AND f.type IN (0,1,2,5)";
        } else {
            $sql .= " AND f.type IN (0,1,2,3,5)";
        }
        if ($y && $m) {
            $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, $m, false)) . "'";
            $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, $m, false)) . "'";
        } else {
            if ($y) {
                $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
                $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
            }
        }
        if ($date_start && $date_end) {
            $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
        }
        $sql .= " AND s.rowid = f.fk_soc";
        $sql .= " GROUP BY s.rowid, s.nom, s.tva_intra, s.tva_assuj";
    } else {
        // Tva sur factures payes (should be on payment)
        /*      $sql = "SELECT s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj,";
                $sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva";
                $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s";
                $sql.= " WHERE ";
                $sql.= " f.fk_statut in (2)";   // Paid (partially or completely)
                if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
        		else $sql.= " AND f.type IN (0,1,2,3,5)";
                if ($y && $m)
                {
                    $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
                    $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
                }
                else if ($y)
                {
                    $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
                    $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
                }
                if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
                $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
                $sql.= " GROUP BY s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj";
        */
    }
    if (!$sql) {
        return -1;
    }
    dol_syslog("Tax.lib:thirdparty", LOG_DEBUG);
    $resql = $db->query($sql);
    if ($resql) {
        while ($assoc = $db->fetch_object($resql)) {
            $list[] = $assoc;
        }
        $db->free($resql);
        return $list;
    } else {
        dol_print_error($db);
        return -3;
    }
}
コード例 #3
0
ファイル: tax.lib.php プロジェクト: nrjacker4/crm-php
/**
 *  Look for collectable VAT clients in the chosen year (and month)
 *
 *  @param	DoliDB	$db          	Database handle
 *  @param  int		$y           	Year
 *  @param  string	$date_start  	Start date
 *  @param  string	$date_end    	End date
 *  @param  int		$modetax     	0 or 1 (option vat on debit)
 *  @param  string	$direction   	'sell' or 'buy'
 *  @param  int		$m				Month
 *  @return array       			List of customers third parties with vat, -1 if no accountancy module, -2 if not yet developped, -3 if error
 */
function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction, $m = 0)
{
    global $conf;
    $list = array();
    //print "xx".$conf->global->MAIN_MODULE_ACCOUNTING;
    //print "xx".$conf->global->MAIN_MODULE_COMPTABILITE;
    if ($direction == 'sell') {
        $invoicetable = 'facture';
        $invoicedettable = 'facturedet';
        $fk_facture = 'fk_facture';
        $total_tva = 'total_tva';
        $total_localtax1 = 'total_localtax1';
        $total_localtax2 = 'total_localtax2';
    }
    if ($direction == 'buy') {
        $invoicetable = 'facture_fourn';
        $invoicedettable = 'facture_fourn_det';
        $fk_facture = 'fk_facture_fourn';
        $total_tva = 'tva';
        $total_localtax1 = 'total_localtax1';
        $total_localtax2 = 'total_localtax2';
    }
    // Define sql request
    $sql = '';
    if ($modetax == 1) {
        // If vat paid on due invoices (non draft)
        if ($conf->global->MAIN_MODULE_ACCOUNTING) {
            // TODO a ce jour on se sait pas la compter car le montant tva d'un payment
            // n'est pas stocke dans la table des payments.
            // Seul le module compta expert peut resoudre ce probleme.
            // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
            // detail part tva et part ht).
            $sql = 'TODO';
        }
        if ($conf->global->MAIN_MODULE_COMPTABILITE) {
            $sql = "SELECT s.rowid as socid, s.nom as nom, s.siren as tva_intra, s.tva_assuj as assuj,";
            $sql .= " sum(fd.total_ht) as amount, sum(fd." . $total_tva . ") as tva,";
            $sql .= " sum(fd." . $total_localtax1 . ") as localtax1,";
            $sql .= " sum(fd." . $total_localtax2 . ") as localtax2";
            $sql .= " FROM " . MAIN_DB_PREFIX . $invoicetable . " as f,";
            $sql .= " " . MAIN_DB_PREFIX . $invoicedettable . " as fd,";
            $sql .= " " . MAIN_DB_PREFIX . "societe as s";
            $sql .= " WHERE f.entity = " . $conf->entity;
            $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)";
            } else {
                $sql .= " AND f.type IN (0,1,2,3)";
            }
            if ($y && $m) {
                $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, $m, false)) . "'";
                $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, $m, false)) . "'";
            } else {
                if ($y) {
                    $sql .= " AND f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
                    $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
                }
            }
            if ($date_start && $date_end) {
                $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
            }
            $sql .= " AND s.rowid = f.fk_soc AND f.rowid = fd." . $fk_facture;
            $sql .= " GROUP BY s.rowid, s.nom, s.tva_intra, s.tva_assuj";
        }
    } else {
        if ($conf->global->MAIN_MODULE_ACCOUNTING) {
            // If vat paid on payments
            // TODO a ce jour on se sait pas la compter car le montant tva d'un payment
            // n'est pas stocke dans la table des payments.
            // Seul le module compta expert peut resoudre ce probleme.
            // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
            // detail part tva et part ht).
            $sql = 'TODO';
        }
        if ($conf->global->MAIN_MODULE_COMPTABILITE) {
            // Tva sur factures payes (should be on payment)
            /*          $sql = "SELECT s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj,";
                        $sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva";
                        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s";
                        $sql.= " WHERE ";
                        $sql.= " f.fk_statut in (2)";   // Paid (partially or completely)
                    	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)";
                        if ($y && $m)
                        {
                            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
                            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
                        }
                        else if ($y)
                        {
                            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
                            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
                        }
                        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
                        $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
                        $sql.= " GROUP BY s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj";
            */
            $sql = 'TODO';
        }
    }
    if (!$sql) {
        return -1;
    }
    if ($sql == 'TODO') {
        return -2;
    }
    if ($sql != 'TODO') {
        dol_syslog("Tax.lib:thirdparty sql=" . $sql);
        $resql = $db->query($sql);
        if ($resql) {
            while ($assoc = $db->fetch_object($resql)) {
                $list[] = $assoc;
            }
            $db->free($resql);
            return $list;
        } else {
            dol_print_error($db);
            return -3;
        }
    }
}
コード例 #4
0
 /**
  * Return all batch detail records for given product and warehouse
  *
  *  @param	DoliDB		$db    				database object
  *  @param	int			$fk_product_stock	id product_stock for objet
  *  @param	int			$with_qty    		doesn't return line with 0 quantity
  *  @return int         					<0 if KO, >0 if OK
  */
 public static function findAll($db, $fk_product_stock, $with_qty = 0)
 {
     global $langs;
     $ret = array();
     $sql = "SELECT";
     $sql .= " t.rowid,";
     $sql .= " t.tms,";
     $sql .= " t.fk_product_stock,";
     $sql .= " t.sellby,";
     $sql .= " t.eatby,";
     $sql .= " t.batch,";
     $sql .= " t.qty,";
     $sql .= " t.import_key";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product_batch as t";
     $sql .= " WHERE fk_product_stock=" . $fk_product_stock;
     if ($with_qty) {
         $sql .= " AND qty<>0";
     }
     dol_syslog("productbatch::findAll", LOG_DEBUG);
     $resql = $db->query($sql);
     if ($resql) {
         $num = $db->num_rows($resql);
         $i = 0;
         while ($i < $num) {
             $obj = $db->fetch_object($resql);
             $tmp = new productbatch($db);
             $tmp->id = $obj->rowid;
             $tmp->tms = $db->jdate($obj->tms);
             $tmp->fk_product_stock = $obj->fk_product_stock;
             $tmp->sellby = $db->jdate($obj->sellby);
             $tmp->eatby = $db->jdate($obj->eatby);
             $tmp->batch = $obj->batch;
             $tmp->qty = $obj->qty;
             $tmp->import_key = $obj->import_key;
             array_push($ret, $tmp);
             $i++;
         }
         $db->free($resql);
         return $ret;
     } else {
         $error = "Error " . $db->lasterror();
         return -1;
     }
 }
コード例 #5
0
 /**
  *	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.
     // In future, this constant will be forced to 'UTC' so PHP server timezone will not have effect anymore.
     //$this->global->MAIN_SERVER_TZ='Europe/Paris';
     if (!empty($this->global->MAIN_SERVER_TZ) && $this->global->MAIN_SERVER_TZ != 'auto') {
         try {
             date_default_timezone_set($this->global->MAIN_SERVER_TZ);
         } catch (Exception $e) {
             dol_syslog("Error: Bad value for parameter MAIN_SERVER_TZ=" . $this->global->MAIN_SERVER_TZ, LOG_ERR);
         }
     }
     // Object $mc
     if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled)) {
         global $mc;
         $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
         if ($ret) {
             $mc = new ActionsMulticompany($db);
         }
     }
     // Clean some variables
     if (empty($this->global->MAIN_MENU_STANDARD)) {
         $this->global->MAIN_MENU_STANDARD = "eldy_menu.php";
     }
     if (empty($this->global->MAIN_MENUFRONT_STANDARD)) {
         $this->global->MAIN_MENUFRONT_STANDARD = "eldy_menu.php";
     }
     if (empty($this->global->MAIN_MENU_SMARTPHONE)) {
         $this->global->MAIN_MENU_SMARTPHONE = "eldy_menu.php";
     }
     // Use eldy by default because smartphone does not work on all phones
     if (empty($this->global->MAIN_MENUFRONT_SMARTPHONE)) {
         $this->global->MAIN_MENUFRONT_SMARTPHONE = "eldy_menu.php";
     }
     // Use eldy by default because smartphone does not work on all phones
     // Clean var use vat for company
     if (!isset($this->global->FACTURE_TVAOPTION)) {
         $this->global->FACTURE_TVAOPTION = 1;
     } else {
         if (!empty($this->global->FACTURE_TVAOPTION) && !is_numeric($this->global->FACTURE_TVAOPTION)) {
             // Old value of option, we clean to use new value (0 or 1)
             if ($this->global->FACTURE_TVAOPTION != "franchise") {
                 $this->global->FACTURE_TVAOPTION = 1;
             } else {
                 $this->global->FACTURE_TVAOPTION = 0;
             }
         }
     }
     // Variable globales LDAP
     if (empty($this->global->LDAP_FIELD_FULLNAME)) {
         $this->global->LDAP_FIELD_FULLNAME = '';
     }
     if (!isset($this->global->LDAP_KEY_USERS)) {
         $this->global->LDAP_KEY_USERS = $this->global->LDAP_FIELD_FULLNAME;
     }
     if (!isset($this->global->LDAP_KEY_GROUPS)) {
         $this->global->LDAP_KEY_GROUPS = $this->global->LDAP_FIELD_FULLNAME;
     }
     if (!isset($this->global->LDAP_KEY_CONTACTS)) {
         $this->global->LDAP_KEY_CONTACTS = $this->global->LDAP_FIELD_FULLNAME;
     }
     if (!isset($this->global->LDAP_KEY_MEMBERS)) {
         $this->global->LDAP_KEY_MEMBERS = $this->global->LDAP_FIELD_FULLNAME;
     }
     // Load translation object with current language
     if (empty($this->global->MAIN_LANG_DEFAULT)) {
         $this->global->MAIN_LANG_DEFAULT = "en_US";
     }
     // By default, we repeat info on all tabs
     if (!isset($this->global->MAIN_REPEATCONTACTONEACHTAB)) {
         $this->global->MAIN_REPEATCONTACTONEACHTAB = 1;
     }
     if (!isset($this->global->MAIN_REPEATADDRESSONEACHTAB)) {
         $this->global->MAIN_REPEATADDRESSONEACHTAB = 1;
     }
     $rootfordata = DOL_DATA_ROOT;
     $rootforuser = DOL_DATA_ROOT;
     // If multicompany module is enabled, we redefine the root of data
     if (!empty($this->multicompany->enabled) && !empty($this->entity) && $this->entity > 1) {
         $rootfordata .= '/' . $this->entity;
     }
     // Define default dir_output and dir_temp for directories of modules
     foreach ($this->modules as $module) {
         // For multicompany sharings
         $this->{$module}->multidir_output = array($this->entity => $rootfordata . "/" . $module);
         $this->{$module}->multidir_temp = array($this->entity => $rootfordata . "/" . $module . "/temp");
         // For backward compatibility
         $this->{$module}->dir_output = $rootfordata . "/" . $module;
         $this->{$module}->dir_temp = $rootfordata . "/" . $module . "/temp";
     }
     // External modules storage
     if (!empty($this->modules_parts['dir'])) {
         foreach ($this->modules_parts['dir'] as $module => $dirs) {
             foreach ($dirs as $type => $name) {
                 $subdir = $type == 'temp' ? '/temp' : '';
                 // For multicompany sharings
                 $varname = 'multidir_' . $type;
                 $this->{$module}->{$varname} = array($this->entity => $rootfordata . "/" . $name . $subdir);
                 // For backward compatibility
                 $varname = 'dir_' . $type;
                 $this->{$module}->{$varname} = $rootfordata . "/" . $name . $subdir;
             }
         }
     }
     // For mycompany storage
     $this->mycompany->dir_output = $rootfordata . "/mycompany";
     $this->mycompany->dir_temp = $rootfordata . "/mycompany/temp";
     // For admin storage
     $this->admin->dir_output = $rootfordata . '/admin';
     $this->admin->dir_temp = $rootfordata . '/admin/temp';
     // For user storage
     $this->user->multidir_output = array($this->entity => $rootfordata . "/users");
     $this->user->multidir_temp = array($this->entity => $rootfordata . "/users/temp");
     // For backward compatibility
     $this->user->dir_output = $rootforuser . "/users";
     $this->user->dir_temp = $rootforuser . "/users/temp";
     // For propal storage
     $this->propal->dir_output = $rootfordata . "/propale";
     $this->propal->dir_temp = $rootfordata . "/propale/temp";
     // Exception: Some dir are not the name of module. So we keep exception here
     // for backward compatibility.
     // Sous module bons d'expedition
     $this->expedition_bon->enabled = defined("MAIN_SUBMODULE_EXPEDITION") ? MAIN_SUBMODULE_EXPEDITION : 0;
     // Sous module bons de livraison
     $this->livraison_bon->enabled = defined("MAIN_SUBMODULE_LIVRAISON") ? MAIN_SUBMODULE_LIVRAISON : 0;
     // Module fournisseur
     if (!empty($this->fournisseur)) {
         $this->fournisseur->commande = new stdClass();
         $this->fournisseur->commande->dir_output = $rootfordata . "/fournisseur/commande";
         $this->fournisseur->commande->dir_temp = $rootfordata . "/fournisseur/commande/temp";
         $this->fournisseur->facture = new stdClass();
         $this->fournisseur->facture->dir_output = $rootfordata . "/fournisseur/facture";
         $this->fournisseur->facture->dir_temp = $rootfordata . "/fournisseur/facture/temp";
     }
     // Module product/service
     $this->product->multidir_output = array($this->entity => $rootfordata . "/produit");
     $this->product->multidir_temp = array($this->entity => $rootfordata . "/produit/temp");
     $this->service->multidir_output = array($this->entity => $rootfordata . "/produit");
     $this->service->multidir_temp = array($this->entity => $rootfordata . "/produit/temp");
     // For backward compatibility
     $this->product->dir_output = $rootfordata . "/produit";
     $this->product->dir_temp = $rootfordata . "/produit/temp";
     $this->service->dir_output = $rootfordata . "/produit";
     $this->service->dir_temp = $rootfordata . "/produit/temp";
     // Module contrat
     $this->contrat->dir_output = $rootfordata . "/contracts";
     $this->contrat->dir_temp = $rootfordata . "/contracts/temp";
     // Set some default values
     // societe
     if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) {
         $this->global->SOCIETE_CODECLIENT_ADDON = "mod_codeclient_leopard";
     }
     if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) {
         $this->global->SOCIETE_CODECOMPTA_ADDON = "mod_codecompta_panicum";
     }
     // Security
     if (empty($this->global->USER_PASSWORD_GENERATED)) {
         $this->global->USER_PASSWORD_GENERATED = 'standard';
     }
     // Default password generator
     if (empty($this->global->MAIN_UMASK)) {
         $this->global->MAIN_UMASK = '0664';
     }
     // Default mask
     // conf->use_javascript_ajax
     $this->use_javascript_ajax = 1;
     if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) {
         $this->use_javascript_ajax = !$this->global->MAIN_DISABLE_JAVASCRIPT;
     }
     // If no javascript_ajax, Ajax features are disabled.
     if (empty($this->use_javascript_ajax)) {
         unset($this->global->PRODUIT_USE_SEARCH_TO_SELECT);
         unset($this->global->COMPANY_USE_SEARCH_TO_SELECT);
         unset($this->global->CONTACT_USE_SEARCH_TO_SELECT);
         unset($this->global->PROJECT_USE_SEARCH_TO_SELECT);
     }
     if (!empty($conf->productbatch->enabled)) {
         $this->global->STOCK_CALCULATE_ON_BILL = 0;
         $this->global->STOCK_CALCULATE_ON_VALIDATE_ORDER = 0;
         $this->global->STOCK_CALCULATE_ON_SHIPMENT = 1;
         $this->global->STOCK_CALCULATE_ON_SUPPLIER_BILL = 0;
         $this->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER = 0;
         $this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER = 1;
     }
     // conf->currency
     if (empty($this->global->MAIN_MONNAIE)) {
         $this->global->MAIN_MONNAIE = 'EUR';
     }
     $this->currency = $this->global->MAIN_MONNAIE;
     // conf->global->ACCOUNTING_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...)
     if (empty($this->global->ACCOUNTING_MODE)) {
         $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES';
     }
     // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES'
     // By default, suppliers objects can be linked to all projects
     $this->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS = 1;
     // conf->liste_limit = constante de taille maximale des listes
     if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) {
         $this->global->MAIN_SIZE_LISTE_LIMIT = 25;
     }
     $this->liste_limit = $this->global->MAIN_SIZE_LISTE_LIMIT;
     // conf->product->limit_size = constante de taille maximale des select de produit
     if (!isset($this->global->PRODUIT_LIMIT_SIZE)) {
         $this->global->PRODUIT_LIMIT_SIZE = 100;
     }
     $this->product->limit_size = $this->global->PRODUIT_LIMIT_SIZE;
     // conf->theme et $this->css
     if (empty($this->global->MAIN_THEME)) {
         $this->global->MAIN_THEME = "eldy";
     }
     if (!empty($this->global->MAIN_FORCETHEME)) {
         $this->global->MAIN_THEME = $this->global->MAIN_FORCETHEME;
     }
     $this->theme = $this->global->MAIN_THEME;
     $this->css = "/theme/" . $this->theme . "/style.css.php";
     // conf->email_from = email pour envoi par dolibarr des mails automatiques
     $this->email_from = "*****@*****.**";
     if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) {
         $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM;
     }
     // conf->notification->email_from = email pour envoi par Dolibarr des notifications
     $this->notification->email_from = $this->email_from;
     if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) {
         $this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM;
     }
     // conf->mailing->email_from = email pour envoi par Dolibarr des mailings
     $this->mailing->email_from = $this->email_from;
     if (!empty($this->global->MAILING_EMAIL_FROM)) {
         $this->mailing->email_from = $this->global->MAILING_EMAIL_FROM;
     }
     // Format for date (used by default when not found or not searched in lang)
     $this->format_date_short = "%d/%m/%Y";
     // Format of day with PHP/C tags (strftime functions)
     $this->format_date_short_java = "dd/MM/yyyy";
     // Format of day with Java tags
     $this->format_hour_short = "%H:%M";
     $this->format_hour_short_duration = "%H:%M";
     $this->format_date_text_short = "%d %b %Y";
     $this->format_date_text = "%d %B %Y";
     $this->format_date_hour_short = "%d/%m/%Y %H:%M";
     $this->format_date_hour_sec_short = "%d/%m/%Y %H:%M:%S";
     $this->format_date_hour_text_short = "%d %b %Y %H:%M";
     $this->format_date_hour_text = "%d %B %Y %H:%M";
     // Duration of workday
     if (!isset($this->global->MAIN_DURATION_OF_WORKDAY)) {
         $this->global->MAIN_DURATION_OF_WORKDAY = 86400;
     }
     // Limites decimales si non definie (peuvent etre egale a 0)
     if (!isset($this->global->MAIN_MAX_DECIMALS_UNIT)) {
         $this->global->MAIN_MAX_DECIMALS_UNIT = 5;
     }
     if (!isset($this->global->MAIN_MAX_DECIMALS_TOT)) {
         $this->global->MAIN_MAX_DECIMALS_TOT = 2;
     }
     if (!isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) {
         $this->global->MAIN_MAX_DECIMALS_SHOWN = 8;
     }
     // Default pdf use dash between lines
     if (!isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) {
         $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1;
     }
     // Set default value to MAIN_SHOW_LOGO
     if (!isset($this->global->MAIN_SHOW_LOGO)) {
         $this->global->MAIN_SHOW_LOGO = 1;
     }
     // Default max file size for upload
     $this->maxfilesize = empty($this->global->MAIN_UPLOAD_DOC) ? 0 : $this->global->MAIN_UPLOAD_DOC * 1024;
     // Define list of limited modules
     if (!isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) {
         $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,askpricesupplier,facture,categorie,commande,fournisseur,contact,propal,projet,contrat,societe,ficheinter,expedition,agenda,adherent';
     }
     // '' means 'all'. Note that contact is added here as it should be a module later.
     // Enable select2
     if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT)) {
         $this->global->MAIN_USE_JQUERY_MULTISELECT = 'select2';
     }
     // Timeouts
     if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) {
         $this->global->MAIN_USE_CONNECT_TIMEOUT = 10;
     }
     if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) {
         $this->global->MAIN_USE_RESPONSE_TIMEOUT = 30;
     }
     // Set default variable to calculate VAT as if option tax_mode was 0 (standard)
     if (empty($this->global->TAX_MODE_SELL_PRODUCT)) {
         $this->global->TAX_MODE_SELL_PRODUCT = 'invoice';
     }
     if (empty($this->global->TAX_MODE_BUY_PRODUCT)) {
         $this->global->TAX_MODE_BUY_PRODUCT = 'invoice';
     }
     if (empty($this->global->TAX_MODE_SELL_SERVICE)) {
         $this->global->TAX_MODE_SELL_SERVICE = 'payment';
     }
     if (empty($this->global->TAX_MODE_BUY_SERVICE)) {
         $this->global->TAX_MODE_BUY_SERVICE = 'payment';
     }
     // Delay before warnings
     // Avoid strict errors. TODO: Replace xxx->warning_delay with a property ->warning_delay_xxx
     $this->propal->cloture = new stdClass();
     $this->propal->facturation = new stdClass();
     $this->commande->client = new stdClass();
     $this->commande->fournisseur = new stdClass();
     $this->facture->client = new stdClass();
     $this->facture->fournisseur = new stdClass();
     $this->contrat->services = new stdClass();
     $this->contrat->services->inactifs = new stdClass();
     $this->contrat->services->expires = new stdClass();
     $this->adherent->cotisation = new stdClass();
     $this->bank->rappro = new stdClass();
     $this->bank->cheque = new stdClass();
     $this->expensereport->payment = new stdClass();
     $this->actions->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 24 * 60 * 60;
     $this->commande->client->warning_delay = (isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_ORDERS_TO_PROCESS : 2) * 24 * 60 * 60;
     $this->commande->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS : 7) * 24 * 60 * 60;
     $this->propal->cloture->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE) ? $this->global->MAIN_DELAY_PROPALS_TO_CLOSE : 0) * 24 * 60 * 60;
     $this->propal->facturation->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_BILL) ? $this->global->MAIN_DELAY_PROPALS_TO_BILL : 0) * 24 * 60 * 60;
     $this->facture->client->warning_delay = (isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED) ? $this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED : 0) * 24 * 60 * 60;
     $this->facture->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY) ? $this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY : 0) * 24 * 60 * 60;
     $this->contrat->services->inactifs->warning_delay = (isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES) ? $this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES : 0) * 24 * 60 * 60;
     $this->contrat->services->expires->warning_delay = (isset($this->global->MAIN_DELAY_RUNNING_SERVICES) ? $this->global->MAIN_DELAY_RUNNING_SERVICES : 0) * 24 * 60 * 60;
     $this->adherent->cotisation->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? $this->global->MAIN_DELAY_MEMBERS : 0) * 24 * 60 * 60;
     $this->bank->rappro->warning_delay = (isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE) ? $this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE : 0) * 24 * 60 * 60;
     $this->bank->cheque->warning_delay = (isset($this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT) ? $this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT : 0) * 24 * 60 * 60;
     $this->expensereport->payment->warning_delay = (isset($this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY) ? $this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY : 0) * 24 * 60 * 60;
     // For modules that want to disable top or left menu
     if (!empty($this->global->MAIN_HIDE_TOP_MENU)) {
         $this->dol_hide_topmenu = $this->global->MAIN_HIDE_TOP_MENU;
     }
     if (!empty($this->global->MAIN_HIDE_LEFT_MENU)) {
         $this->dol_hide_leftmenu = $this->global->MAIN_HIDE_LEFT_MENU;
     }
     // For backward compatibility
     if (isset($this->product)) {
         $this->produit = $this->product;
     }
     if (isset($this->facture)) {
         $this->invoice = $this->facture;
     }
     if (isset($this->commande)) {
         $this->order = $this->commande;
     }
     if (isset($this->contrat)) {
         $this->contract = $this->contrat;
     }
     if (isset($this->categorie)) {
         $this->category = $this->categorie;
     }
     // Object $mc
     if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled)) {
         if (is_object($mc)) {
             $mc->setValues($this);
         }
     }
     // We init log handlers
     if (defined('SYSLOG_HANDLERS')) {
         $handlers = json_decode(constant('SYSLOG_HANDLERS'));
     } else {
         $handlers = array();
     }
     foreach ($handlers as $handler) {
         $file = DOL_DOCUMENT_ROOT . '/core/modules/syslog/' . $handler . '.php';
         if (!file_exists($file)) {
             throw new Exception('Missing log handler file ' . $handler . '.php');
         }
         require_once $file;
         $loghandlerinstance = new $handler();
         if (!$loghandlerinstance instanceof LogHandlerInterface) {
             throw new Exception('Log handler does not extend LogHandlerInterface');
         }
         if (empty($conf->loghandlers[$handler])) {
             $this->loghandlers[$handler] = $loghandlerinstance;
         }
     }
 }
コード例 #6
0
 /**
  *      Return a label for a key.
  *      Search into translation array, then into cache, then if still not found, search into database.
  *      Store key-label found into cache variable $this->cache_labels to save SQL requests to get labels.
  *
  * 		@param	DoliDB	$db				Database handler
  * 		@param	string	$key			Translation key to get label (key in language file)
  * 		@param	string	$tablename		Table name without prefix
  * 		@param	string	$fieldkey		Field for key
  * 		@param	string	$fieldlabel		Field for label
  *      @param	string	$keyforselect	Use another value than the translation key for the where into select
  *      @return string					Label in UTF8 (but without entities)
  *      @see dol_getIdFromCode
  */
 function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '')
 {
     // If key empty
     if ($key == '') {
         return '';
     }
     //print 'param: '.$key.'-'.$keydatabase.'-'.$this->trans($key); exit;
     // Check if a translation is available (this can call getTradFromKey)
     if ($this->transnoentitiesnoconv($key) != $key) {
         return $this->transnoentitiesnoconv($key);
         // Found in language array
     }
     // Check in cache
     if (isset($this->cache_labels[$tablename][$key])) {
         return $this->cache_labels[$tablename][$key];
         // Found in cache
     }
     $sql = "SELECT " . $fieldlabel . " as label";
     $sql .= " FROM " . MAIN_DB_PREFIX . $tablename;
     $sql .= " WHERE " . $fieldkey . " = '" . ($keyforselect ? $keyforselect : $key) . "'";
     dol_syslog(get_class($this) . '::getLabelFromKey', LOG_DEBUG);
     $resql = $db->query($sql);
     if ($resql) {
         $obj = $db->fetch_object($resql);
         if ($obj) {
             $this->cache_labels[$tablename][$key] = $obj->label;
         } else {
             $this->cache_labels[$tablename][$key] = $key;
         }
         $db->free($resql);
         return $this->cache_labels[$tablename][$key];
     } else {
         $this->error = $db->lasterror();
         return -1;
     }
 }
コード例 #7
0
 /**
  * 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;
     }
 }
コード例 #8
0
/**
 * Return HTML table with list of projects and number of opened tasks
 *
 * @param	DoliDB	$db					Database handler
 * @param   int		$socid				Id thirdparty
 * @param   int		$projectsListId     Id of project i have permission on
 * @param   int		$mytasks            Limited to task i am contact to
 * @return	void
 */
function print_projecttasks_array($db, $socid, $projectsListId, $mytasks = 0)
{
    global $langs, $conf, $user, $bc;
    require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
    $projectstatic = new Project($db);
    $sortfield = '';
    $sortorder = '';
    print '<table class="noborder" width="100%">';
    print '<tr class="liste_titre">';
    print_liste_field_titre($langs->trans("Project"), "index.php", "", "", "", "", $sortfield, $sortorder);
    print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder);
    print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder);
    print "</tr>\n";
    $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, COUNT(t.rowid) as nb";
    $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p";
    if ($mytasks) {
        $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t";
        $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec";
        $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc";
    } else {
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet";
    }
    $sql .= " WHERE p.entity = " . $conf->entity;
    $sql .= " AND p.rowid IN (" . $projectsListId . ")";
    if ($socid) {
        $sql .= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")";
    }
    if ($mytasks) {
        $sql .= " AND p.rowid = t.fk_projet";
        $sql .= " AND ec.element_id = t.rowid";
        $sql .= " AND ctc.rowid = ec.fk_c_type_contact";
        $sql .= " AND ctc.element = 'project_task'";
        $sql .= " AND ec.fk_socpeople = " . $user->id;
    }
    $sql .= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut";
    $sql .= " ORDER BY p.title, p.ref";
    $var = true;
    $resql = $db->query($sql);
    if ($resql) {
        $num = $db->num_rows($resql);
        $i = 0;
        while ($i < $num) {
            $objp = $db->fetch_object($resql);
            $projectstatic->id = $objp->projectid;
            $projectstatic->user_author_id = $objp->fk_user_creat;
            $projectstatic->public = $objp->public;
            // Check is user has read permission on project
            $userAccess = $projectstatic->restrictedProjectArea($user);
            if ($userAccess >= 0) {
                $var = !$var;
                print "<tr " . $bc[$var] . ">";
                print '<td class="nowrap">';
                $projectstatic->ref = $objp->ref;
                print $projectstatic->getNomUrl(1);
                print ' - ' . dol_trunc($objp->title, 24) . '</td>';
                print '<td align="right">' . $objp->nb . '</td>';
                $projectstatic->statut = $objp->fk_statut;
                print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>';
                print "</tr>\n";
            }
            $i++;
        }
        $db->free($resql);
    } else {
        dol_print_error($db);
    }
    print "</table>";
}
コード例 #9
0
/**
 *    	Show html area with actions to do
 *
 * 		@param	Conf		$conf		Object conf
 * 		@param	Translate	$langs		Object langs
 * 		@param	DoliDB		$db			Object db
 * 		@param	Object		$object		Object third party or member
 * 		@param	Contact		$objcon		Object contact
 *      @param  int			$noprint	Return string but does not output it
 *      @return	mixed					Return html part or void if noprint is 1
 */
function show_actions_todo($conf, $langs, $db, $object, $objcon = '', $noprint = 0)
{
    global $bc, $user;
    // Check parameters
    if (!is_object($object)) {
        dol_print_error('', 'BadParameter');
    }
    $now = dol_now('tzuser');
    $out = '';
    if (!empty($conf->agenda->enabled)) {
        require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
        $actionstatic = new ActionComm($db);
        $userstatic = new User($db);
        $contactstatic = new Contact($db);
        $out .= "\n";
        $out .= '<table width="100%" class="noborder">';
        $out .= '<tr class="liste_titre">';
        $out .= '<td colspan="2">';
        if (get_class($object) == 'Societe') {
            $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/listactions.php?socid=' . $object->id . '&amp;status=todo">';
        }
        $out .= $langs->trans("ActionsToDoShort");
        if (get_class($object) == 'Societe') {
            $out .= '</a>';
        }
        $out .= '</td>';
        $out .= '<td colspan="5" align="right">';
        $permok = $user->rights->agenda->myactions->create;
        if (($object->id || $objcon->id) && $permok) {
            $out .= '<a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?action=create';
            if (get_class($object) == 'Societe') {
                $out .= '&amp;socid=' . $object->id;
            }
            $out .= (!empty($objcon->id) ? '&amp;contactid=' . $objcon->id : '') . '&amp;backtopage=1&amp;percentage=-1">';
            $out .= $langs->trans("AddAnAction") . ' ';
            $out .= img_picto($langs->trans("AddAnAction"), 'filenew');
            $out .= "</a>";
        }
        $out .= '</td>';
        $out .= '</tr>';
        $sql = "SELECT a.id, a.label,";
        $sql .= " a.datep as dp,";
        $sql .= " a.datea as da,";
        $sql .= " a.percent,";
        $sql .= " a.fk_user_author, a.fk_contact,";
        $sql .= " a.fk_element, a.elementtype,";
        $sql .= " c.code as acode, c.libelle,";
        $sql .= " u.login, u.rowid";
        if (get_class($object) == 'Adherent') {
            $sql .= ", m.lastname, m.firstname";
        }
        if (get_class($object) == 'Societe') {
            $sql .= ", sp.lastname, sp.firstname";
        }
        $sql .= " FROM " . MAIN_DB_PREFIX . "c_actioncomm as c, " . MAIN_DB_PREFIX . "user as u, " . MAIN_DB_PREFIX . "actioncomm as a";
        if (get_class($object) == 'Adherent') {
            $sql .= ", " . MAIN_DB_PREFIX . "adherent as m";
        }
        if (get_class($object) == 'Societe') {
            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
        }
        $sql .= " WHERE u.rowid = a.fk_user_author";
        $sql .= " AND a.entity IN (" . getEntity('agenda', 1) . ")";
        if (get_class($object) == 'Adherent') {
            $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
            if (!empty($object->id)) {
                $sql .= " AND a.fk_element = " . $object->id;
            }
        }
        if (get_class($object) == 'Societe' && $object->id) {
            $sql .= " AND a.fk_soc = " . $object->id;
        }
        if (!empty($objcon->id)) {
            $sql .= " AND a.fk_contact = " . $objcon->id;
        }
        $sql .= " AND c.id=a.fk_action";
        $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) . "'))";
        $sql .= " ORDER BY a.datep DESC, a.id DESC";
        dol_syslog("company.lib::show_actions_todo sql=" . $sql);
        $result = $db->query($sql);
        if ($result) {
            $i = 0;
            $num = $db->num_rows($result);
            $var = true;
            if ($num) {
                while ($i < $num) {
                    $var = !$var;
                    $obj = $db->fetch_object($result);
                    $datep = $db->jdate($obj->dp);
                    $out .= "<tr " . $bc[$var] . ">";
                    $out .= '<td width="120" align="left" class="nowrap">' . dol_print_date($datep, 'dayhour') . "</td>\n";
                    // Picto warning
                    $out .= '<td width="16">';
                    if ($obj->percent >= 0 && $datep && $datep < $now - $conf->global->MAIN_DELAY_ACTIONS_TODO * 60 * 60 * 24) {
                        $out .= ' ' . img_warning($langs->trans("Late"));
                    } else {
                        $out .= '&nbsp;';
                    }
                    $out .= '</td>';
                    $actionstatic->type_code = $obj->acode;
                    $transcode = $langs->trans("Action" . $obj->acode);
                    $libelle = $transcode != "Action" . $obj->acode ? $transcode : $obj->libelle;
                    //$actionstatic->libelle=$libelle;
                    $actionstatic->libelle = $obj->label;
                    $actionstatic->id = $obj->id;
                    //$out.='<td width="140">'.$actionstatic->getNomUrl(1,16).'</td>';
                    // Title of event
                    //$out.='<td colspan="2">'.dol_trunc($obj->label,40).'</td>';
                    $out .= '<td colspan="2">' . $actionstatic->getNomUrl(1, 40) . '</td>';
                    // Contact pour cette action
                    if (empty($objcon->id) && $obj->fk_contact > 0) {
                        $contactstatic->lastname = $obj->lastname;
                        $contactstatic->firstname = $obj->firstname;
                        $contactstatic->id = $obj->fk_contact;
                        $out .= '<td width="120">' . $contactstatic->getNomUrl(1, '', 10) . '</td>';
                    } else {
                        $out .= '<td>&nbsp;</td>';
                    }
                    $out .= '<td width="80" class="nowrap">';
                    $userstatic->id = $obj->fk_user_author;
                    $userstatic->login = $obj->login;
                    $out .= $userstatic->getLoginUrl(1);
                    $out .= '</td>';
                    // Statut
                    $out .= '<td class="nowrap" width="20">' . $actionstatic->LibStatut($obj->percent, 3) . '</td>';
                    $out .= "</tr>\n";
                    $i++;
                }
            } else {
                // Aucun action a faire
            }
            $db->free($result);
        } else {
            dol_print_error($db);
        }
        $out .= "</table>\n";
        $out .= "<br>\n";
    }
    if ($noprint) {
        return $out;
    } else {
        print $out;
    }
}
コード例 #10
0
 /**
  *      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 = "******")";
     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;
     }
 }
コード例 #11
0
ファイル: upgrade2.php プロジェクト: ADDAdev/Dolibarr
/**
 * Mise a jour des totaux lignes de commande fournisseur
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_price_commande_fournisseur($db, $langs, $conf)
{
    $db->begin();
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationSupplierOrder') . "</b><br>\n";
    // Liste des lignes commande non a jour
    $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as tva_taux, cd.info_bits,";
    $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
    $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet as cd, " . MAIN_DB_PREFIX . "commande_fournisseur as c";
    $sql .= " WHERE cd.fk_commande = c.rowid";
    $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
    dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur", LOG_DEBUG);
    $resql = $db->query($sql);
    if ($resql) {
        $num = $db->num_rows($resql);
        $i = 0;
        if ($num) {
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $rowid = $obj->rowid;
                $qty = $obj->qty;
                $pu = $obj->subprice;
                $txtva = $obj->tva_taux;
                $remise_percent = $obj->remise_percent;
                $remise_percent_global = $obj->remise_percent_global;
                $info_bits = $obj->info_bits;
                // On met a jour les 3 nouveaux champs
                $commandeligne = new CommandeFournisseurLigne($db);
                $commandeligne->fetch($rowid);
                $result = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, $remise_percent_global, 'HT', $info_bits, 0);
                $total_ht = $result[0];
                $total_tva = $result[1];
                $total_ttc = $result[2];
                $commandeligne->total_ht = $total_ht;
                $commandeligne->total_tva = $total_tva;
                $commandeligne->total_ttc = $total_ttc;
                dolibarr_install_syslog("upgrade2: Line {$rowid}: commandeid={$obj->rowid} pu={$pu} qty={$qty} tva_taux={$txtva} remise_percent={$remise_percent} remise_global={$remise_percent_global} -> {$total_ht}, {$total_tva}, {$total_ttc}");
                print ". ";
                $commandeligne->update_total();
                /* On touche pas a facture mere
                   $commande = new Commande($db);
                   $commande->id = $obj->rowid;
                   if ( $commande->fetch($commande->id) >= 0 )
                   {
                   if ( $commande->update_price() > 0 )
                   {
                   print ". ";
                   }
                   else
                   {
                   print "Error id=".$commande->id;
                   }
                   }
                   else
                   {
                   print "Error #3";
                   }
                   */
                $i++;
            }
        } else {
            print $langs->trans("AlreadyDone");
        }
        $db->free($resql);
        /*
        $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
        $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
        $resql=$db->query($sql);
        if (! $resql)
        {
        dol_print_error($db);
        }
        */
        $db->commit();
    } else {
        print "Error #1 " . $db->error();
        $db->rollback();
    }
    print '<br>';
    print '</td></tr>';
}
コード例 #12
0
ファイル: functions.lib.php プロジェクト: ADDAdev/Dolibarr
/**
 *      Return an id or code from a code or id. Store also Code-Id into a cache for next use.
 *
 * 		@param	DoliDB	$db			Database handler
 * 		@param	string	$key		Code to get Id
 * 		@param	string	$tablename	Table name without prefix
 * 		@param	string	$fieldkey	Field for code
 * 		@param	string	$fieldid	Field for id
 *      @return int					<0 if KO, Id of code if OK
 *      @see getLabelFromKey
 */
function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id')
{
    global $cache_codes;
    // If key empty
    if ($key == '') {
        return '';
    }
    // Check in cache
    if (isset($cache_codes[$tablename][$key])) {
        return $cache_codes[$tablename][$key];
        // Found in cache
    }
    $sql = "SELECT " . $fieldid . " as id";
    $sql .= " FROM " . MAIN_DB_PREFIX . $tablename;
    $sql .= " WHERE " . $fieldkey . " = '" . $key . "'";
    dol_syslog('dol_getIdFromCode', LOG_DEBUG);
    $resql = $db->query($sql);
    if ($resql) {
        $obj = $db->fetch_object($resql);
        if ($obj) {
            $cache_codes[$tablename][$key] = $obj->id;
        } else {
            $cache_codes[$tablename][$key] = '';
        }
        $db->free($resql);
        return $cache_codes[$tablename][$key];
    } else {
        return -1;
    }
}
コード例 #13
0
ファイル: project.lib.php プロジェクト: ADDAdev/Dolibarr
/**
 * Return HTML table with list of projects and number of opened tasks
 *
 * @param	DoliDB	$db					Database handler
 * @param   int		$socid				Id thirdparty
 * @param   int		$projectsListId     Id of project i have permission on
 * @param   int		$mytasks            Limited to task i am contact to
 * @param	int		$statut				-1=No filter on statut, 0 or 1 = Filter on status
 * @return	void
 */
function print_projecttasks_array($db, $socid, $projectsListId, $mytasks = 0, $statut = -1)
{
    global $langs, $conf, $user, $bc;
    require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
    $projectstatic = new Project($db);
    $sortfield = '';
    $sortorder = '';
    $project_year_filter = 0;
    $title = $langs->trans("Project");
    if ($statut == 0) {
        $title = $langs->trans("ProjectDraft");
    }
    if ($statut == 1) {
        $title = $langs->trans("Project") . ' (' . $langs->trans("Validated") . ')';
    }
    print '<table class="noborder" width="100%">';
    print '<tr class="liste_titre">';
    print_liste_field_titre($title, "index.php", "", "", "", "", $sortfield, $sortorder);
    print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder);
    print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder);
    print "</tr>\n";
    $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, COUNT(t.rowid) as nb";
    $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p";
    if ($mytasks) {
        $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t";
        $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec";
        $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc";
    } else {
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet";
    }
    $sql .= " WHERE p.entity = " . $conf->entity;
    $sql .= " AND p.rowid IN (" . $projectsListId . ")";
    if ($socid) {
        $sql .= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")";
    }
    if ($mytasks) {
        $sql .= " AND p.rowid = t.fk_projet";
        $sql .= " AND ec.element_id = t.rowid";
        $sql .= " AND ctc.rowid = ec.fk_c_type_contact";
        $sql .= " AND ctc.element = 'project_task'";
        $sql .= " AND ec.fk_socpeople = " . $user->id;
    }
    if ($statut >= 0) {
        $sql .= " AND p.fk_statut = " . $statut;
    }
    if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
        $project_year_filter = GETPOST("project_year_filter");
        //Check if empty or invalid year. Wildcard ignores the sql check
        if ($project_year_filter != "*") {
            if (empty($project_year_filter) || !ctype_digit($project_year_filter)) {
                //
                $project_year_filter = date("Y");
            }
            $sql .= " AND (p.dateo IS NULL OR p.dateo <= " . $db->idate(dol_get_last_day($project_year_filter, 12, false)) . ")";
            $sql .= " AND (p.datee IS NULL OR p.datee >= " . $db->idate(dol_get_first_day($project_year_filter, 1, false)) . ")";
        }
    }
    $sql .= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut";
    $sql .= " ORDER BY p.title, p.ref";
    $var = true;
    $resql = $db->query($sql);
    if ($resql) {
        $num = $db->num_rows($resql);
        $i = 0;
        while ($i < $num) {
            $objp = $db->fetch_object($resql);
            $projectstatic->id = $objp->projectid;
            $projectstatic->user_author_id = $objp->fk_user_creat;
            $projectstatic->public = $objp->public;
            // Check is user has read permission on project
            $userAccess = $projectstatic->restrictedProjectArea($user);
            if ($userAccess >= 0) {
                $var = !$var;
                print "<tr " . $bc[$var] . ">";
                print '<td class="nowrap">';
                $projectstatic->ref = $objp->ref;
                print $projectstatic->getNomUrl(1);
                print ' - ' . dol_trunc($objp->title, 24) . '</td>';
                print '<td align="right">' . $objp->nb . '</td>';
                $projectstatic->statut = $objp->fk_statut;
                print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>';
                print "</tr>\n";
            }
            $i++;
        }
        $db->free($resql);
    } else {
        dol_print_error($db);
    }
    print "</table>";
    if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
        //Add the year filter input
        print '<table width="100%">';
        print '<tr>';
        print '<td>' . $langs->trans("Year") . '</td>';
        print '<form method="get" action="' . $_SERVER["PHP_SELF"] . '">';
        print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="' . $project_year_filter . '"/>';
        print '</form>';
        print "</tr>\n";
        print '</table>';
    }
}