diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index c1a6769216b..591efd295ce 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1025,7 +1025,7 @@ class Adherent extends CommonObject $sql = "SELECT d.rowid, d.civilite, d.prenom as firstname, d.nom as lastname, d.societe, d.fk_soc, d.statut, d.public, d.adresse as address, d.cp as zip, d.ville as town, d.note,"; $sql.= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass,"; - $sql.= " d.photo, d.fk_adherent_type, d.morphy,"; + $sql.= " d.photo, d.fk_adherent_type, d.morphy, d.entity,"; $sql.= " d.datec as datec,"; $sql.= " d.tms as datem,"; $sql.= " d.datefin as datefin,"; @@ -1057,63 +1057,66 @@ class Adherent extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->ref = $obj->rowid; - $this->id = $obj->rowid; - $this->civilite_id = $obj->civilite; - $this->prenom = $obj->firstname; // deprecated - $this->firstname = $obj->firstname; - $this->nom = $obj->lastname; // deprecated - $this->lastname = $obj->lastname; - $this->login = $obj->login; - $this->pass = $obj->pass; - $this->societe = $obj->societe; - $this->fk_soc = $obj->fk_soc; - $this->adresse = $obj->address; // deprecated - $this->address = $obj->address; - $this->cp = $obj->zip; // deprecated - $this->zip = $obj->zip; - $this->ville = $obj->town; // deprecated - $this->town = $obj->town; + $this->entity = $obj->entity; + $this->ref = $obj->rowid; + $this->id = $obj->rowid; + $this->civilite_id = $obj->civilite; + $this->prenom = $obj->firstname; // deprecated + $this->firstname = $obj->firstname; + $this->nom = $obj->lastname; // deprecated + $this->lastname = $obj->lastname; + $this->login = $obj->login; + $this->pass = $obj->pass; + $this->societe = $obj->societe; + $this->fk_soc = $obj->fk_soc; + $this->adresse = $obj->address; // deprecated + $this->address = $obj->address; + $this->cp = $obj->zip; // deprecated + $this->zip = $obj->zip; + $this->ville = $obj->town; // deprecated + $this->town = $obj->town; - $this->state_id = $obj->fk_departement; - $this->state_code = $obj->fk_departement?$obj->state_code:''; - $this->state = $obj->fk_departement?$obj->state:''; - $this->fk_departement = $obj->fk_departement; // deprecated - $this->departement_code = $obj->fk_departement?$obj->state_code:''; // deprecated - $this->departement = $obj->fk_departement?$obj->state:''; // deprecated + $this->state_id = $obj->fk_departement; + $this->state_code = $obj->fk_departement?$obj->state_code:''; + $this->state = $obj->fk_departement?$obj->state:''; + $this->fk_departement = $obj->fk_departement; // deprecated + $this->departement_code = $obj->fk_departement?$obj->state_code:''; // deprecated + $this->departement = $obj->fk_departement?$obj->state:''; // deprecated - $this->country_id = $obj->country_id; - $this->country_code = $obj->country_code; - if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code); - else $this->country=$obj->country; - $this->pays_id = $obj->country_id; // deprecated - $this->pays_code = $obj->country_code; // deprecated - $this->pays = $this->country; // deprecated + $this->country_id = $obj->country_id; + $this->country_code = $obj->country_code; + if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) + $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code); + else + $this->country=$obj->country; + $this->pays_id = $obj->country_id; // deprecated + $this->pays_code = $obj->country_code; // deprecated + $this->pays = $this->country; // deprecated - $this->phone = $obj->phone; - $this->phone_perso = $obj->phone_perso; - $this->phone_mobile = $obj->phone_mobile; - $this->email = $obj->email; + $this->phone = $obj->phone; + $this->phone_perso = $obj->phone_perso; + $this->phone_mobile = $obj->phone_mobile; + $this->email = $obj->email; - $this->photo = $obj->photo; - $this->statut = $obj->statut; - $this->public = $obj->public; + $this->photo = $obj->photo; + $this->statut = $obj->statut; + $this->public = $obj->public; - $this->datec = $this->db->jdate($obj->datec); - $this->datem = $this->db->jdate($obj->datem); - $this->datefin = $this->db->jdate($obj->datefin); - $this->datevalid = $this->db->jdate($obj->datev); - $this->naiss = $this->db->jdate($obj->datenaiss); + $this->datec = $this->db->jdate($obj->datec); + $this->datem = $this->db->jdate($obj->datem); + $this->datefin = $this->db->jdate($obj->datefin); + $this->datevalid = $this->db->jdate($obj->datev); + $this->naiss = $this->db->jdate($obj->datenaiss); - $this->note = $obj->note; - $this->morphy = $obj->morphy; + $this->note = $obj->note; + $this->morphy = $obj->morphy; - $this->typeid = $obj->fk_adherent_type; - $this->type = $obj->type; + $this->typeid = $obj->fk_adherent_type; + $this->type = $obj->type; $this->need_subscription = ($obj->cotisation=='yes'?1:0); - $this->user_id = $obj->user_id; - $this->user_login = $obj->user_login; + $this->user_id = $obj->user_id; + $this->user_login = $obj->user_login; // Load other properties $result=$this->fetch_subscriptions(); diff --git a/htdocs/admin/agenda_xcal.php b/htdocs/admin/agenda_xcal.php index d398f3631a0..59f5de846e8 100644 --- a/htdocs/admin/agenda_xcal.php +++ b/htdocs/admin/agenda_xcal.php @@ -131,10 +131,10 @@ clearstatcache(); print "
"; -// Define $urlwithroot -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file -//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current +// Define $urlwithroot +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); +$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file +//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current // Show message diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9d71b10a20b..32fd57ec3c5 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3908,26 +3908,29 @@ class Form { global $conf; + $entity = (! empty($object->entity) ? $object->entity : $conf->entity); + $id = (! empty($object->id) ? $object->id : $object->rowid); + $ret='';$dir='';$file='';$altfile='';$email=''; if ($modulepart=='societe') { - $dir=$conf->societe->multidir_output[$object->entity]; + $dir=$conf->societe->multidir_output[$entity]; $smallfile=$object->logo; $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile); - if ($object->logo) $file=$object->id.'/logos/thumbs/'.$smallfile; + if ($object->logo) $file=$id.'/logos/thumbs/'.$smallfile; } else if ($modulepart=='userphoto') { $dir=$conf->user->dir_output; - if ($object->photo) $file=get_exdir($object->id,2).$object->photo; + if ($object->photo) $file=get_exdir($id, 2).$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; } else if ($modulepart=='memberphoto') { $dir=$conf->adherent->dir_output; - if ($object->photo) $file=get_exdir($object->id,2).'photos/'.$object->photo; + if ($object->photo) $file=get_exdir($id, 2).'photos/'.$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; } @@ -3938,14 +3941,14 @@ class Form if ($file && file_exists($dir."/".$file)) { // TODO Link to large image - $ret.=''; - $ret.=''; + $ret.=''; + $ret.=''; $ret.=''; } else if ($altfile && file_exists($dir."/".$altfile)) { - $ret.=''; - $ret.=''; + $ret.=''; + $ret.=''; $ret.=''; } else diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index 0c87ba3bc80..2564e4b0574 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -1,286 +1,286 @@ - - * Copyright (C) 2006-2008 Laurent Destailleur - * Copyright (C) 2010-2012 Juanjo Menent - * Copyright (C) 2012 Christophe Battarel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/core/lib/price.lib.php - * \brief Library with functions to calculate prices - */ - - -/** - * Calculate totals (net, vat, ...) of a line. - * Value for localtaxX_type are '0' : local tax not applied - * '1' : local tax apply on products and services without vat (vat is not applied for local tax calculation) - * '2' : local tax apply on products and services before vat (vat is calculated on amount + localtax) - * '3' : local tax apply on products without vat (vat is not applied for local tax calculation) - * '4' : local tax apply on products before vat (vat is calculated on amount + localtax) - * '5' : local tax apply on services without vat (vat is not applied for local tax calculation) - * '6' : local tax apply on services before vat (vat is calculated on amount + localtax) - * '7' : local tax is a fix amount applied on global invoice - * - * @param int $qty Quantity - * @param float $pu Unit price (HT or TTC selon price_base_type) - * @param float $remise_percent_ligne Discount for line - * @param float $txtva 0=do not apply standard tax, Vat rate=apply - * @param float $uselocaltax1_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller - * @param float $uselocaltax2_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller - * @param float $remise_percent_global 0 - * @param string $price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC - * @param int $info_bits Miscellanous informations on line - * @param int $type 0/1=Product/service - * @param string $seller Thirdparty seller (we need $seller->country_code property). Provided only if seller is the supplier. - * @return result[ 0=total_ht, - * 1=total_vat, - * 2=total_ttc, - * 3=pu_ht, - * 4=pu_tva, - * 5=pu_ttc, - * 6=total_ht_without_discount, - * 7=total_vat_without_discount, - * 8=total_ttc_without_discount, - * 9=amount tax1 for total_ht, - * 10=amount tax2 for total_ht, - * 11=amount tax1 for pu_ht, - * 12=amount tax2 for pu_ht, - * 13=not used???, - * 14=amount tax1 for total_ht_without_discount, - * 15=amount tax1 for total_ht_without_discount] - */ -function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '') -{ - global $conf,$mysoc,$db; - - $result=array(); - - if (empty($seller) || ! is_object($seller)) - { - if (! is_object($mysoc)) // mysoc may be not defined (during migration process) - { - $mysoc=new Societe($db); - $mysoc->getMysoc($conf); - } - $seller=$mysoc; // If seller is a customer, $seller is not provided, we use $mysoc - //var_dump($seller->country_id);exit; - } - - $countryid=$seller->country_id; - if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj; - if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj; - - // Now we search localtaxes information ourself (rates and types). - $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as cv"; - //$sql.= ", ".MAIN_DB_PREFIX."c_pays as cc"; - $sql.= " WHERE cv.taux = ".$txtva; - //$sql.= " AND cv.fk_pays = cc.rowid and cc.code = '".$mysoc->country_code."'"; - $sql.= " AND cv.fk_pays = ".$countryid; - dol_syslog("search vat information sql=".$sql); - $resql = $db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - if ($obj) - { - $localtax1_rate=$obj->localtax1; - $localtax2_rate=$obj->localtax2; - $localtax1_type=$obj->localtax1_type; - $localtax2_type=$obj->localtax2_type; - //var_dump($localtax1_rate.' '.$localtax2_rate.' '.$localtax1_type.' '.$localtax2_type);exit; - } - } - else dol_print_error($db); - - // initialize total (may be HT or TTC depending on price_base_type) - $tot_sans_remise = $pu * $qty; - $tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100)); - $tot_avec_remise = $tot_avec_remise_ligne * (1 - ($remise_percent_global / 100)); - - // initialize result - for ($i=0; $i <= 15; $i++) $result[$i] = 0; - - // if there's some localtax including vat, we calculate localtaxes (we will add later) - $localtaxes = array(0,0,0); - $apply_tax = false; - switch($localtax1_type) { - case '2': // localtax on product or service - $apply_tax = true; - break; - case '4': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '6': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax1_rate && $apply_tax) { - $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); - $localtaxes[0] += $result[14]; - - $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); - $localtaxes[1] += $result[9]; - - $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); - $localtaxes[2] += $result[11]; - } - - $apply_tax = false; - switch($localtax2_type) { - case '2': // localtax on product or service - $apply_tax = true; - break; - case '4': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '6': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax2_rate && $apply_tax) { - $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); - $localtaxes[0] += $result[15]; - - $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); - $localtaxes[1] += $result[10]; - - $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); - $localtaxes[2] += $result[12]; - } - - //dol_syslog("price.lib::calcul_price_total $qty, $pu, $remise_percent_ligne, $txtva, $price_base_type $info_bits"); - if ($price_base_type == 'HT') - { - // We work to define prices using the price without tax - $result[6] = price2num($tot_sans_remise, 'MT'); - $result[8] = price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result8bis= price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[7] = price2num($result8bis - ($result[6] + $localtaxes[0]), 'MT'); - - $result[0] = price2num($tot_avec_remise, 'MT'); - $result[2] = price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result2bis= price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax) - - $result[3] = price2num($pu, 'MU'); - $result[5] = price2num(($pu + $localtaxes[2]) * (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non - $result5bis= price2num(($pu + $localtaxes[2]) * (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) - $result[4] = price2num($result5bis - ($result[3] + $localtaxes[2]), 'MU'); - } - else - { - // We work to define prices using the price with tax - $result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT'); - $result[6] = price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result6bis= price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[7] = price2num($result[8] - ($result6bis + $localtaxes[0]), 'MT'); - - $result[2] = price2num($tot_avec_remise + $localtaxes[1], 'MT'); - $result[0] = price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result0bis= price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT'); // Total VAT = TTC - HT - - $result[5] = price2num(($pu + $localtaxes[2]), 'MU'); - $result[3] = price2num(($pu + $localtaxes[2]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non - $result3bis= price2num(($pu + $localtaxes[2]) / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) - $result[4] = price2num($result[5] - ($result3bis + $localtaxes[2]), 'MU'); - } - - // if there's some localtax without vat, we calculate localtaxes (we will add them at end) - - //If price is 'TTC' we need to have the totals without VAT for a correct calculation - if ($price_base_type=='TTC') - { - $tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)),'MU'); - $tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)),'MU'); - $pu = price2num($pu / (1 + ($txtva / 100)),'MU'); - } - - $apply_tax = false; - switch($localtax1_type) { - case '1': // localtax on product or service - $apply_tax = true; - break; - case '3': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '5': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax1_rate && $apply_tax) { - - $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax1 for total_ht_without_discount - $result[8] += $result[14]; // total_ttc_without_discount + tax1 - - $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax1 for total_ht - $result[2] += $result[9]; // total_ttc + tax1 - - $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); // amount tax1 for pu_ht - $result[5] += $result[11]; // pu_ht + tax1 - } - - $apply_tax = false; - switch($localtax2_type) { - case '1': // localtax on product or service - $apply_tax = true; - break; - case '3': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '5': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax2_rate && $apply_tax) { - $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax2 for total_ht_without_discount - $result[8] += $result[15]; // total_ttc_without_discount + tax2 - - $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax2 for total_ht - $result[2] += $result[10]; // total_ttc + tax2 - - $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); // amount tax2 for pu_ht - $result[5] += $result[12]; // pu_ht + tax2 - } - - // If rounding is not using base 10 (rare) - if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) - { - if ($price_base_type == 'HT') - { - $result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[2]=price2num($result[0]+$result[1], 'MT'); - $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - } - else - { - $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[0]=price2num($result[2]-$result[0], 'MT'); - $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - } - } - - //print "Price.lib::calcul_price_total ".$result[0]."-".$result[1]."-".$result[2]; - - return $result; -} - + + * Copyright (C) 2006-2008 Laurent Destailleur + * Copyright (C) 2010-2012 Juanjo Menent + * Copyright (C) 2012 Christophe Battarel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/lib/price.lib.php + * \brief Library with functions to calculate prices + */ + + +/** + * Calculate totals (net, vat, ...) of a line. + * Value for localtaxX_type are '0' : local tax not applied + * '1' : local tax apply on products and services without vat (vat is not applied for local tax calculation) + * '2' : local tax apply on products and services before vat (vat is calculated on amount + localtax) + * '3' : local tax apply on products without vat (vat is not applied for local tax calculation) + * '4' : local tax apply on products before vat (vat is calculated on amount + localtax) + * '5' : local tax apply on services without vat (vat is not applied for local tax calculation) + * '6' : local tax apply on services before vat (vat is calculated on amount + localtax) + * '7' : local tax is a fix amount applied on global invoice + * + * @param int $qty Quantity + * @param float $pu Unit price (HT or TTC selon price_base_type) + * @param float $remise_percent_ligne Discount for line + * @param float $txtva 0=do not apply standard tax, Vat rate=apply + * @param float $uselocaltax1_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller + * @param float $uselocaltax2_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller + * @param float $remise_percent_global 0 + * @param string $price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC + * @param int $info_bits Miscellanous informations on line + * @param int $type 0/1=Product/service + * @param string $seller Thirdparty seller (we need $seller->country_code property). Provided only if seller is the supplier. + * @return result[ 0=total_ht, + * 1=total_vat, + * 2=total_ttc, + * 3=pu_ht, + * 4=pu_tva, + * 5=pu_ttc, + * 6=total_ht_without_discount, + * 7=total_vat_without_discount, + * 8=total_ttc_without_discount, + * 9=amount tax1 for total_ht, + * 10=amount tax2 for total_ht, + * 11=amount tax1 for pu_ht, + * 12=amount tax2 for pu_ht, + * 13=not used???, + * 14=amount tax1 for total_ht_without_discount, + * 15=amount tax1 for total_ht_without_discount] + */ +function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '') +{ + global $conf,$mysoc,$db; + + $result=array(); + + if (empty($seller) || ! is_object($seller)) + { + if (! is_object($mysoc)) // mysoc may be not defined (during migration process) + { + $mysoc=new Societe($db); + $mysoc->getMysoc($conf); + } + $seller=$mysoc; // If seller is a customer, $seller is not provided, we use $mysoc + //var_dump($seller->country_id);exit; + } + + $countryid=$seller->country_id; + if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj; + if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj; + + // Now we search localtaxes information ourself (rates and types). + $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as cv"; + //$sql.= ", ".MAIN_DB_PREFIX."c_pays as cc"; + $sql.= " WHERE cv.taux = ".$txtva; + //$sql.= " AND cv.fk_pays = cc.rowid and cc.code = '".$mysoc->country_code."'"; + $sql.= " AND cv.fk_pays = ".$countryid; + dol_syslog("search vat information sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) + { + $localtax1_rate=$obj->localtax1; + $localtax2_rate=$obj->localtax2; + $localtax1_type=$obj->localtax1_type; + $localtax2_type=$obj->localtax2_type; + //var_dump($localtax1_rate.' '.$localtax2_rate.' '.$localtax1_type.' '.$localtax2_type);exit; + } + } + else dol_print_error($db); + + // initialize total (may be HT or TTC depending on price_base_type) + $tot_sans_remise = $pu * $qty; + $tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100)); + $tot_avec_remise = $tot_avec_remise_ligne * (1 - ($remise_percent_global / 100)); + + // initialize result + for ($i=0; $i <= 15; $i++) $result[$i] = 0; + + // if there's some localtax including vat, we calculate localtaxes (we will add later) + $localtaxes = array(0,0,0); + $apply_tax = false; + switch($localtax1_type) { + case '2': // localtax on product or service + $apply_tax = true; + break; + case '4': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '6': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax1_rate && $apply_tax) { + $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); + $localtaxes[0] += $result[14]; + + $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); + $localtaxes[1] += $result[9]; + + $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); + $localtaxes[2] += $result[11]; + } + + $apply_tax = false; + switch($localtax2_type) { + case '2': // localtax on product or service + $apply_tax = true; + break; + case '4': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '6': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax2_rate && $apply_tax) { + $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); + $localtaxes[0] += $result[15]; + + $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); + $localtaxes[1] += $result[10]; + + $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); + $localtaxes[2] += $result[12]; + } + + //dol_syslog("price.lib::calcul_price_total $qty, $pu, $remise_percent_ligne, $txtva, $price_base_type $info_bits"); + if ($price_base_type == 'HT') + { + // We work to define prices using the price without tax + $result[6] = price2num($tot_sans_remise, 'MT'); + $result[8] = price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result8bis= price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[7] = price2num($result8bis - ($result[6] + $localtaxes[0]), 'MT'); + + $result[0] = price2num($tot_avec_remise, 'MT'); + $result[2] = price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result2bis= price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax) + + $result[3] = price2num($pu, 'MU'); + $result[5] = price2num(($pu + $localtaxes[2]) * (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non + $result5bis= price2num(($pu + $localtaxes[2]) * (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) + $result[4] = price2num($result5bis - ($result[3] + $localtaxes[2]), 'MU'); + } + else + { + // We work to define prices using the price with tax + $result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT'); + $result[6] = price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result6bis= price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[7] = price2num($result[8] - ($result6bis + $localtaxes[0]), 'MT'); + + $result[2] = price2num($tot_avec_remise + $localtaxes[1], 'MT'); + $result[0] = price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result0bis= price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT'); // Total VAT = TTC - HT + + $result[5] = price2num(($pu + $localtaxes[2]), 'MU'); + $result[3] = price2num(($pu + $localtaxes[2]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non + $result3bis= price2num(($pu + $localtaxes[2]) / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) + $result[4] = price2num($result[5] - ($result3bis + $localtaxes[2]), 'MU'); + } + + // if there's some localtax without vat, we calculate localtaxes (we will add them at end) + + //If price is 'TTC' we need to have the totals without VAT for a correct calculation + if ($price_base_type=='TTC') + { + $tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)),'MU'); + $tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)),'MU'); + $pu = price2num($pu / (1 + ($txtva / 100)),'MU'); + } + + $apply_tax = false; + switch($localtax1_type) { + case '1': // localtax on product or service + $apply_tax = true; + break; + case '3': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '5': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax1_rate && $apply_tax) { + + $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax1 for total_ht_without_discount + $result[8] += $result[14]; // total_ttc_without_discount + tax1 + + $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax1 for total_ht + $result[2] += $result[9]; // total_ttc + tax1 + + $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); // amount tax1 for pu_ht + $result[5] += $result[11]; // pu_ht + tax1 + } + + $apply_tax = false; + switch($localtax2_type) { + case '1': // localtax on product or service + $apply_tax = true; + break; + case '3': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '5': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax2_rate && $apply_tax) { + $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax2 for total_ht_without_discount + $result[8] += $result[15]; // total_ttc_without_discount + tax2 + + $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax2 for total_ht + $result[2] += $result[10]; // total_ttc + tax2 + + $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); // amount tax2 for pu_ht + $result[5] += $result[12]; // pu_ht + tax2 + } + + // If rounding is not using base 10 (rare) + if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) + { + if ($price_base_type == 'HT') + { + $result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[2]=price2num($result[0]+$result[1], 'MT'); + $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + } + else + { + $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[0]=price2num($result[2]-$result[0], 'MT'); + $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + } + } + + //print "Price.lib::calcul_price_total ".$result[0]."-".$result[1]."-".$result[2]; + + return $result; +} + diff --git a/htdocs/core/modules/rapport/pdf_paiement.class.php b/htdocs/core/modules/rapport/pdf_paiement.class.php index ffe6fa6ffde..f7a1e779ee2 100644 --- a/htdocs/core/modules/rapport/pdf_paiement.class.php +++ b/htdocs/core/modules/rapport/pdf_paiement.class.php @@ -67,13 +67,13 @@ class pdf_paiement $this->posxinvoice=82; $this->posxinvoiceamount=122; $this->posxpaymentamount=162; - if ($this->page_largeur < 210) // To work with US executive format - { + if ($this->page_largeur < 210) // To work with US executive format + { $this->posxpaymenttype-=10; $this->posxinvoice-=0; $this->posxinvoiceamount-=10; $this->posxpaymentamount-=20; - } + } } @@ -237,7 +237,7 @@ class pdf_paiement // Do not add the BACKGROUND as this is a report //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); - $default_font_size = pdf_getPDFFontSize($outputlangs); + $default_font_size = pdf_getPDFFontSize($outputlangs); $title=$outputlangs->transnoentities("ListOfCustomerPayments"); $title.=' - '.dol_print_date(dol_mktime(0,0,0,$this->month,1,$this->year),"%B %Y",false,$outputlangs,true); @@ -291,7 +291,7 @@ class pdf_paiement */ function Body(&$pdf, $page, $lines, $outputlangs) { - $default_font_size = pdf_getPDFFontSize($outputlangs); + $default_font_size = pdf_getPDFFontSize($outputlangs); $pdf->SetFont('','', $default_font_size - 1); $oldprowid = 0; diff --git a/htdocs/public/members/public_card.php b/htdocs/public/members/public_card.php index d9b6c1c58d3..14f7d06db12 100644 --- a/htdocs/public/members/public_card.php +++ b/htdocs/public/members/public_card.php @@ -72,7 +72,7 @@ llxHeaderVierge($langs->trans("MemberCard")); $extralabels=$extrafields->fetch_name_optionals_label('member'); if ($id > 0) { - $res=$object->fetch($id,$ref); + $res=$object->fetch($id); if ($res < 0) { dol_print_error($db,$object->error); exit; } $res=$object->fetch_optionals($object->id,$extralabels); @@ -87,27 +87,22 @@ if ($id > 0) print ''; print '\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if (isset($object->photo) && $object->photo !=''){ - print ''; + if (isset($object->photo) && $object->photo !='') + { + $form = new Form($db); + print ''."\n"; } // foreach($objecto->attribute_label as $key=>$value){ // print "\n"; diff --git a/htdocs/public/members/public_list.php b/htdocs/public/members/public_list.php index 7cfe37c5067..0cef6387de8 100644 --- a/htdocs/public/members/public_list.php +++ b/htdocs/public/members/public_list.php @@ -67,10 +67,10 @@ function llxHeaderVierge($title, $head = "") } /** -* Show footer for member list -* -* @return void -*/ + * Show footer for member list + * + * @return void + */ function llxFooterVierge() { printCommonFooter('public'); @@ -88,8 +88,8 @@ $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -$filter=$_GET["filter"]; -$statut=isset($_GET["statut"])?$_GET["statut"]:''; +$filter=GETPOST('filter'); +$statut=GETPOST('statut'); if (! $sortorder) { $sortorder="ASC"; } if (! $sortfield) { $sortfield="nom"; } @@ -101,8 +101,7 @@ if (! $sortfield) { $sortfield="nom"; } llxHeaderVierge($langs->trans("ListOfValidatedPublicMembers")); - -$sql = "SELECT rowid, prenom, nom, societe, cp, ville, email, naiss, photo"; +$sql = "SELECT rowid, prenom, nom, societe, cp as zip, ville as town, email, naiss, photo"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent"; $sql.= " WHERE entity = ".$entity; $sql.= " AND statut = 1"; @@ -122,12 +121,14 @@ if ($result) $param="&statut=$statut&sortorder=$sortorder&sortfield=$sortfield"; print_barre_liste($langs->trans("ListOfValidatedPublicMembers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, ''); - print "
'.$langs->trans("Type").''.$object->type."
'.$langs->trans("Person").''.$object->morphy.'
'.$langs->trans("Firstname").''.$object->firstname.' 
'.$langs->trans("Lastname").''.$object->lastname.' 
'.$langs->trans("Company").''.$object->societe.' 
'.$langs->trans("Address").''.nl2br($object->address).' 
'.$langs->trans("Zip").' '.$langs->trans("Town").''.$object->zip.' '.$object->town.' 
'.$langs->trans("Country").''.$object->pays.' 
'.$langs->trans("EMail").''.$object->email.' 
'.$langs->trans("Birthday").''.$object->naiss.' 
URL Photo'."photo\">photo\">".' 
URL Photo'; + print $form->showphoto('memberphoto', $object, 64); + print '
$value".$object->array_options["options_$key"]." 
"; + print '
'; print ''; - print "\n"; - print_liste_field_titre($langs->trans("DateToBirth"),"public_list.php","naiss","",$param,$sortfield,$sortorder); - print_liste_field_titre($langs->trans("EMail"),"public_list.php","email","",$param,$sortfield,$sortorder); + print ''."\n"; + //print_liste_field_titre($langs->trans("DateToBirth"),"public_list.php","naiss",'',$param,$sortfield,$sortorder); // est-ce nécessaire ?? + print_liste_field_titre($langs->trans("EMail"),"public_list.php","email",'',$param,$sortfield,$sortorder); print_liste_field_titre($langs->trans("Zip"),"public_list.php","cp","",$param,$sortfield,$sortorder); print_liste_field_titre($langs->trans("Town"),"public_list.php","ville","",$param,$sortfield,$sortorder); print "\n"; @@ -139,14 +140,17 @@ if ($result) $objp = $db->fetch_object($result); $var=!$var; print ""; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - if (isset($objp->photo) && $objp->photo!= '') + print ''."\n"; + //print "\n"; // est-ce nécessaire ?? + print ''."\n"; + print ''."\n"; + print ''."\n"; + if (isset($objp->photo) && $objp->photo != '') { - print "\n"; + $form = new Form($db); + print ''."\n"; } else { diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php index bdb605d4aa5..15bed9df242 100755 --- a/htdocs/public/paypal/newpayment.php +++ b/htdocs/public/paypal/newpayment.php @@ -240,7 +240,7 @@ if (GETPOST("action") == 'dopayment') dol_syslog("SCRIPT_URI: ".(empty($_SERVER["SCRIPT_URI"])?'':$_SERVER["SCRIPT_URI"]), LOG_DEBUG); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO //$_SESSION["PaymentType"]=$PAYPAL_PAYMENT_TYPE; //$_SESSION["currencyCodeType"]=$PAYPAL_API_DEVISE; - //$_SESSION["Payment_Amount"]=$PAYPAL_API_PRICE; + //$_SESSION["Payment_Amount"]=$PAYPAL_API_PRICE; // A redirect is added if API call successfull print_paypal_redirect($PAYPAL_API_PRICE,$PAYPAL_API_DEVISE,$PAYPAL_PAYMENT_TYPE,$PAYPAL_API_OK,$PAYPAL_API_KO, $FULLTAG); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index dc6a52ae811..eeb069cf46e 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1463,9 +1463,9 @@ class User extends CommonObject } // Define $urlwithroot - //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); - //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file - $urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); + //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + $urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current // TODO Use outputlangs to translate messages if (! $changelater) diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index c6198f1b79a..0d48dc1cef2 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -89,10 +89,10 @@ $form = new Form($db); $object = new User($db); $extrafields = new ExtraFields($db); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); -$hookmanager->initHooks(array('usercard')); +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('usercard')); diff --git a/htdocs/webservices/admin/webservices.php b/htdocs/webservices/admin/webservices.php index dccfce8ed82..05e5dc2bf7e 100644 --- a/htdocs/webservices/admin/webservices.php +++ b/htdocs/webservices/admin/webservices.php @@ -123,6 +123,11 @@ if (! empty($conf->fournisseur->enabled)) $url=DOL_MAIN_URL_ROOT.'/webservices/server_supplier_invoice.php?wsdl'; print img_picto('','object_globe.png').' '.$url."
\n"; } +if (! empty($conf->agenda->enabled)) +{ + $url=DOL_MAIN_URL_ROOT.'/webservices/server_actioncomm.php?wsdl'; + print img_picto('','object_globe.png').' '.$url."
\n"; +} print '
'; @@ -150,6 +155,11 @@ if (! empty($conf->fournisseur->enabled)) $url=DOL_MAIN_URL_ROOT.'/webservices/server_supplier_invoice.php'; print img_picto('','object_globe.png').' '.$url."
\n"; } +if (! empty($conf->agenda->enabled)) +{ + $url=DOL_MAIN_URL_ROOT.'/webservices/server_actioncomm.php'; + print img_picto('','object_globe.png').' '.$url."
\n"; +} print '
'; diff --git a/htdocs/webservices/demo_wsclient_actioncomm.php-NORUN b/htdocs/webservices/demo_wsclient_actioncomm.php-NORUN new file mode 100755 index 00000000000..cb7cdf68311 --- /dev/null +++ b/htdocs/webservices/demo_wsclient_actioncomm.php-NORUN @@ -0,0 +1,165 @@ + + * Copyright (C) 2012 Florian Henry + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/webservices/demo_wsclient_actioncomm.php + * \brief Demo page to make a client call to Dolibarr WebServices "server_other" + */ + +// This is to make Dolibarr working with Plesk +set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs'); + +require_once '../master.inc.php'; +require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP + +$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_actioncomm.php'; +//$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with / +$WS_METHOD_GET = 'getActionComm'; +$WS_METHOD_CREATE = 'createActionComm'; +$WS_METHOD_GET_C_LIST = 'getListActionCommType'; +$ns='http://www.dolibarr.org/ns/'; + +//Chosse action to do +//$action='get'; +//$action='getlist'; +$action='create'; + + +// Set the WebService URL +dol_syslog("Create nusoap_actioncomm for URL=".$WS_DOL_URL); +$soapclient = new nusoap_client($WS_DOL_URL); +if ($soapclient) +{ + $soapclient->soap_defencoding='UTF-8'; + $soapclient->decodeUTF8(false); +} + +// Call the WebService method and store its result in $result. +$authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin_dolibarDev', + 'password'=>'homedread', + 'entity'=>'1'); + + +// Test URL +if ($action=='get') +{ + $WS_METHOD=$WS_METHOD_GET; + $parameters = array('authentication'=>$authentication,'id'=>1); + dol_syslog("Call method ".$WS_METHOD_GET); + $result = $soapclient->call($WS_METHOD_GET,$parameters,$ns,''); + if (! $result) + { + print $soapclient->error_str; + print "
\n\n"; + print $soapclient->request; + print "
\n\n"; + print $soapclient->response; + exit; + } +} + + +// Test URL +if ($action=='getlist') +{ + $WS_METHOD=$WS_METHOD_GET_C_LIST; + $parameters = array('authentication'=>$authentication); + dol_syslog("Call method ".$WS_METHOD_GET_C_LIST); + $result = $soapclient->call($WS_METHOD_GET_C_LIST,$parameters,$ns,''); + if (! $result) + { + print $soapclient->error_str; + print "
\n\n"; + print $soapclient->request; + print "
\n\n"; + print $soapclient->response; + exit; + } +} + +// Test URL +if ($action=='create') +{ + $WS_METHOD=$WS_METHOD_CREATE; + $new=array( + 'datep'=>dol_mktime(13, 30, 00, 12, 16, 2012), + 'datef'=>dol_mktime(15, 30, 00, 12, 16, 2012), + 'type_code'=>'AC_RDV', + 'socid'=>'1', + 'projectid'=>'', + 'note'=>'This is note', + 'contactid'=>'', + 'usertodo'=>'1', + 'userdone'=>'1', + 'label'=>'Ceci est les titre de l\'envenement', + 'percentage'=>'100', + 'location'=>'Location1' + ); + + + $parameters = array('authentication'=>$authentication,'actioncomm'=>$new); + dol_syslog("Call method ".$WS_METHOD_CREATE); + $result = $soapclient->call($WS_METHOD_CREATE,$parameters,$ns,''); + if (! $result) + { + print $soapclient->error_str; + print "
\n\n"; + print $soapclient->request; + print "
\n\n"; + print $soapclient->response; + exit; + } +} + + +/* + * View + */ + +header("Content-type: text/html; charset=utf8"); +print ''."\n"; +echo ''."\n"; +echo ''; +echo 'WebService Test: '.$WS_METHOD.''; +echo ''."\n"; + +echo ''."\n"; +echo 'NUSOAP_PATH='.NUSOAP_PATH.'
'; + +echo "

Request:

"; +echo '

Function

'; +echo $WS_METHOD; +echo '

SOAP Message

'; +echo '
' . htmlspecialchars($soapclient->request, ENT_QUOTES) . '
'; + +echo '
'; + +echo "

Response:

"; +echo '

Result

'; +echo '
';
+print_r($result);
+echo '
'; +echo '

SOAP Message

'; +echo '
' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '
'; + +echo ''."\n";; +echo ''."\n";; +?> diff --git a/htdocs/webservices/server_actioncomm.php b/htdocs/webservices/server_actioncomm.php new file mode 100644 index 00000000000..933719075c4 --- /dev/null +++ b/htdocs/webservices/server_actioncomm.php @@ -0,0 +1,481 @@ + + * Copyright (C) 2012 Florian Henry + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/webservices/server_actioncomm.php + * \brief File that is entry point to call Dolibarr WebServices + * \version $Id: server_actioncomm.php,v 1.7 2010/12/19 11:49:37 eldy Exp $ + */ + +// This is to make Dolibarr working with Plesk +set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs'); + +require_once("../master.inc.php"); +require_once(NUSOAP_PATH.'/nusoap.php'); // Include SOAP +require_once(DOL_DOCUMENT_ROOT."/core/lib/ws.lib.php"); + +require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php"); +require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php"); +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + + +dol_syslog("Call ActionComm webservices interfaces"); + +// Enable and test if module web services is enabled +if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) +{ + $langs->load("admin"); + dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled"); + print $langs->trans("WarningModuleNotActive",'WebServices').'.

'; + print $langs->trans("ToActivateModule"); + exit; +} + +// Create the soap Object +$server = new nusoap_server(); +$server->soap_defencoding='UTF-8'; +$server->decode_utf8=false; +$ns='http://www.dolibarr.org/ns/'; +$server->configureWSDL('WebServicesDolibarrActionComm',$ns); +$server->wsdl->schemaTargetNamespace=$ns; + + +// Define WSDL Authentication object +$server->wsdl->addComplexType( + 'authentication', + 'complexType', + 'struct', + 'all', + '', + array( + 'dolibarrkey' => array('name'=>'dolibarrkey','type'=>'xsd:string'), + 'sourceapplication' => array('name'=>'sourceapplication','type'=>'xsd:string'), + 'login' => array('name'=>'login','type'=>'xsd:string'), + 'password' => array('name'=>'password','type'=>'xsd:string'), + 'entity' => array('name'=>'entity','type'=>'xsd:string'), + ) +); + +// Define WSDL Return object +$server->wsdl->addComplexType( + 'result', + 'complexType', + 'struct', + 'all', + '', + array( + 'result_code' => array('name'=>'result_code','type'=>'xsd:string'), + 'result_label' => array('name'=>'result_label','type'=>'xsd:string'), + ) +); + + +$actioncomm_fields= array( + 'id' => array('name'=>'id','type'=>'xsd:string'), + 'ref' => array('name'=>'ref','type'=>'xsd:string'), + 'ref_ext' => array('name'=>'ref_ext','type'=>'xsd:string'), + 'type_id' => array('name'=>'type_id','type'=>'xsd:string'), + 'type_code' => array('name'=>'type_code','type'=>'xsd:string'), + 'type' => array('name'=>'type','type'=>'xsd:string'), + 'label' => array('name'=>'label','type'=>'xsd:string'), + 'datep' => array('name'=>'datep','type'=>'xsd:dateTime'), + 'datef' => array('name'=>'datef','type'=>'xsd:dateTime'), + 'datec' => array('name'=>'datec','type'=>'xsd:dateTime'), + 'datem' => array('name'=>'datem','type'=>'xsd:dateTime'), + 'note' => array('name'=>'note','type'=>'xsd:string'), + 'percentage' => array('name'=>'percentage','type'=>'xsd:string'), + 'author' => array('name'=>'author','type'=>'xsd:string'), + 'usermod' => array('name'=>'usermod','type'=>'xsd:string'), + 'usertodo' => array('name'=>'usertodo','type'=>'xsd:string'), + 'userdone' => array('name'=>'userdone','type'=>'xsd:string'), + 'priority' => array('name'=>'priority','type'=>'xsd:string'), + 'fulldayevent' => array('name'=>'fulldayevent','type'=>'xsd:string'), + 'location' => array('name'=>'location','type'=>'xsd:string'), + 'socid' => array('name'=>'socid','type'=>'xsd:string'), + 'contactid' => array('name'=>'contactid','type'=>'xsd:string'), + 'projectid' => array('name'=>'projectid','type'=>'xsd:string'), + 'fk_element' => array('name'=>'fk_element','type'=>'xsd:string'), + 'elementtype' => array('name'=>'elementtype','type'=>'xsd:string')); + +//Retreive all extrafield for actioncomm +// fetch optionals attributes and labels +$extrafields=new ExtraFields($db); +$extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); +if (count($extrafields)>0) { + $extrafield_array = array(); +} +foreach($extrafields->attribute_label as $key=>$label) +{ + $type =$extrafields->attribute_type[$key]; + if ($type=='date' || $type=='datetime') {$type='xsd:dateTime';} + else {$type='xsd:string';} + + $extrafield_array['options_'.$key]=array('name'=>'options_'.$key,'type'=>$type); +} + +$actioncomm_fields=array_merge($actioncomm_fields,$extrafield_array); + +// Define other specific objects +$server->wsdl->addComplexType( + 'actioncomm', + 'complexType', + 'struct', + 'all', + '', + $actioncomm_fields +); + + +$server->wsdl->addComplexType( + 'actioncommtype', + 'complexType', + 'array', + 'sequence', + '', + array( + 'code' => array('name'=>'code','type'=>'xsd:string'), + 'libelle' => array('name'=>'libelle','type'=>'xsd:string') + ) +); + +$server->wsdl->addComplexType( + 'actioncommtypes', + 'complexType', + 'array', + 'sequence', + '', + array( + 'actioncommtype' => array( + 'name' => 'actioncommtype', + 'type' => 'tns:actioncommtype', + 'minOccurs' => '0', + 'maxOccurs' => 'unbounded' + ) + ) +); + + +// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped +// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model. +// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/ +$styledoc='rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages) +$styleuse='encoded'; // encoded/literal/literal wrapped +// Better choice is document/literal wrapped but literal wrapped not supported by nusoap. + + +// Register WSDL +$server->register( + 'getListActionCommType', + // Entry values + array('authentication'=>'tns:authentication'), + // Exit values + array('result'=>'tns:result','actioncommtypes'=>'tns:actioncommtypes'), + $ns, + $ns.'#getListActionCommType', + $styledoc, + $styleuse, + 'WS to get actioncommType' +); + +// Register WSDL +$server->register( + 'getActionComm', + // Entry values + array('authentication'=>'tns:authentication','id'=>'xsd:string'), + // Exit values + array('result'=>'tns:result','actioncomm'=>'tns:actioncomm'), + $ns, + $ns.'#getActionComm', + $styledoc, + $styleuse, + 'WS to get actioncomm' +); + +// Register WSDL +$server->register( + 'createActionComm', + // Entry values + array('authentication'=>'tns:authentication','actioncomm'=>'tns:actioncomm'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string'), + $ns, + $ns.'#createActionComm', + $styledoc, + $styleuse, + 'WS to create a actioncomm' +); + + + + +/** + * Get ActionComm + * + * @param array $authentication Array of authentication information + * @param int $id Id of object + * @param string $ref Ref of object + * @param ref_ext $ref_ext Ref external of object + * @return mixed + */ +function getActionComm($authentication,$id) +{ + global $db,$conf,$langs; + + dol_syslog("Function: getActionComm login=".$authentication['login']." id=".$id); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + // Check parameters + if ($error || (! $id)) + { + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; + } + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->agenda->allactions->read) + { + $actioncomm=new ActionComm($db); + $result=$actioncomm->fetch($id); + if ($result > 0) + { + + $actioncomm_result_fields=array( + 'id' => $actioncomm->id, + 'ref'=> $actioncomm->ref, + 'ref_ext'=> $actioncomm->ref_ext, + 'type_id'=> $actioncomm->type_id, + 'type_code'=> $actioncomm->type_code, + 'type'=> $actioncomm->type, + 'label'=> $actioncomm->label, + 'datep'=> dol_print_date($actioncomm->datep,'dayhourrfc'), + 'datef'=> dol_print_date($actioncomm->datef,'dayhourrfc'), + 'datec'=> dol_print_date($actioncomm->datec,'dayhourrfc'), + 'datem'=> dol_print_date($actioncomm->datem,'dayhourrfc'), + 'note'=> $actioncomm->note, + 'percentage'=> $actioncomm->percentage, + 'author'=> $actioncomm->author->id, + 'usermod'=> $actioncomm->usermod->id, + 'usertodo'=> $actioncomm->usertodo->id, + 'userdone'=> $actioncomm->userdone->id, + 'priority'=> $actioncomm->priority, + 'fulldayevent'=> $actioncomm->fulldayevent, + 'location'=> $actioncomm->location, + 'socid'=> $actioncomm->societe->id, + 'contactid'=> $actioncomm->contact->id, + 'projectid'=> $actioncomm->fk_project, + 'fk_element'=> $actioncomm->fk_element, + 'elementtype'=> $actioncomm->elementtype); + + //Retreive all extrafield for actioncomm + // fetch optionals attributes and labels + $extrafields=new ExtraFields($db); + $extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); + //Get extrafield values + $actioncomm->fetch_optionals($actioncomm->id,$extralabels); + + foreach($extrafields->attribute_label as $key=>$label) + { + $actioncomm_result_fields=array_merge($actioncomm_result_fields,array('options_'.$key => $actioncomm->array_options['options_'.$key])); + } + + // Create + $objectresp = array( + 'result'=>array('result_code'=>'OK', 'result_label'=>''), + 'actioncomm'=>$actioncomm_result_fields); + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + } + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + + +/** + * Get getListActionCommType + * + * @param array $authentication Array of authentication information + * @return mixed + */ +function getListActionCommType($authentication) +{ + global $db,$conf,$langs; + + dol_syslog("Function: getListActionCommType login=".$authentication['login']); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->agenda->myactions->read) + { + $cactioncomm=new CActionComm($db); + $result=$cactioncomm->liste_array('','code'); + if ($result > 0) + { + $resultarray=array(); + foreach($cactioncomm->liste_array as $code=>$libeller) { + $resultarray[]=array('code'=>$code,'libelle'=>$libeller); + } + + $objectresp = array( + 'result'=>array('result_code'=>'OK', 'result_label'=>''), + 'actioncommtypes'=>$resultarray); + + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + } + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + + +/** + * Create ActionComm + * + * @param array $authentication Array of authentication information + * @param ActionComm $actioncomm $actioncomm + * @return array Array result + */ +function createActionComm($authentication,$actioncomm) +{ + global $db,$conf,$langs; + + $now=dol_now(); + + dol_syslog("Function: createActionComm login=".$authentication['login']); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + if (! $error) + { + $newobject=new ActionComm($db); + + $newobject->datep=$actioncomm['datep']; + $newobject->datef=$actioncomm['datef']; + $newobject->type_code=$actioncomm['type_code']; + $newobject->societe->id=$actioncomm['socid']; + $newobject->fk_project=$actioncomm['projectid']; + $newobject->note=$actioncomm['note']; + $newobject->contact->id=$actioncomm['contactid']; + $newobject->usertodo->id=$actioncomm['usertodo']; + $newobject->userdone->id=$actioncomm['userdone']; + $newobject->label=$actioncomm['label']; + $newobject->percentage=$actioncomm['percentage']; + $newobject->priority=$actioncomm['priority']; + $newobject->fulldayevent=$actioncomm['fulldayevent']; + $newobject->location=$actioncomm['location']; + $newobject->fk_element=$actioncomm['fk_element']; + $newobject->elementtype=$actioncomm['elementtype']; + + //Retreive all extrafield for actioncomm + // fetch optionals attributes and labels + $extrafields=new ExtraFields($db); + $extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); + foreach($extrafields->attribute_label as $key=>$label) + { + $key='options_'.$key; + $newobject->array_options[$key]=$actioncomm[$key]; + } + + $db->begin(); + + $result=$newobject->add($fuser); + if ($result <= 0) + { + $error++; + } + + if (! $error) + { + $db->commit(); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref); + } + else + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$newobject->error; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + +// Return the results. +$server->service($HTTP_RAW_POST_DATA); + +?>
".$langs->trans("Firstname")." ".$langs->trans("Lastname")." / ".$langs->trans("Company")."'.$langs->trans("Firstname").''; + print ' '.$langs->trans("Lastname").''; + print ' / '.$langs->trans("Company").'".$langs->trans("Photo")."
rowid\">".$objp->prenom." ".$objp->nom.($objp->societe?" / ".$objp->societe:"")."$objp->naiss$objp->email$objp->cp$objp->ville'.$objp->prenom.' '.$objp->nom.($objp->societe?' / '.$objp->societe:'').'$objp->naiss'.$objp->email.''.$objp->zip.''.$objp->town.'photo\">photo\" height=\"64\" width=\"64\">'; + print $form->showphoto('memberphoto', $objp, 64); + print '