diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 6459038d135..37ccdb9d8dc 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -394,8 +394,9 @@ if ((isset($_GET["action"]) && $_GET["action"] == 'edit') // TVA Intra $var=!$var; - print ''.$langs->trans("TVAIntra").''; - print ''; + print ''.$langs->trans("VATIntra").''; + print ''; + print ''; print ''; @@ -524,9 +525,12 @@ else print ''; + print '
'; + // Identifiants de la société (propre au pays) + print '
'; print ''; print ''; $var=true; @@ -607,12 +611,48 @@ else print ''; } - // TVA Intracommunautaire + // TVA + if ($conf->use_javascript) + { + print "\n"; + print ''; + print "\n"; + } $var=!$var; - print ''; + print ''; + print ''; + print ''; print '
'.$langs->trans("CompanyIds").''.$langs->trans("Value").'
'.$langs->trans("TVAIntra").'' . $conf->global->MAIN_INFO_TVAINTRA . '
'.$langs->trans("VATIntra").''; + if ($conf->global->MAIN_INFO_TVAINTRA) + { + $s=''; + $code=substr($conf->global->MAIN_INFO_TVAINTRA,0,2); + $num=substr($conf->global->MAIN_INFO_TVAINTRA,2); + $s.=$conf->global->MAIN_INFO_TVAINTRA; + $s.=''; + $s.=''; + $s.='   '; + if ($conf->use_javascript) + { + $s.=''.$langs->trans("VATIntraCheck").''; + print $form->textwithhelp($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1); + } + else + { + print $s.'id_pays).'" target="_blank" alt="'.$langs->trans("VATIntraCheckableOnEUSite").'">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').''; + } + } + else + { + print ' '; + } + print '
'; - + print '
'; /* * Options fiscale diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 631ea4b53fc..c80c36218c8 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -485,12 +485,18 @@ if ($_GET['action'] == 'modif' && $user->rights->propale->creer) */ if ($_POST['action'] == "addligne" && $user->rights->propale->creer) { - if ($_POST['qty'] && (($_POST['np_price']!=0 && $_POST['np_desc']) || $_POST['idprod'])) + if ($_POST['qty'] && (($_POST['np_price']!='' && $_POST['np_desc']) || $_POST['idprod'])) { $propal = new Propal($db); $ret=$propal->fetch($_POST['propalid']); - $soc = new Societe($db, $propal->socid); - $soc->fetch($propal->socid); + if ($ret < 0) + { + dolibarr_print_error($db,$propal->error); + exit; + } + $ret=$propal->fetch_client(); + + $price_base_type = 'HT'; // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit @@ -500,16 +506,36 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer) $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); - // multiprix + $tva_tx = get_default_tva($mysoc,$propal->client,$prod->tva_tx); + + // On defini prix unitaire if ($conf->global->PRODUIT_MULTIPRICES == 1) { - $pu = $prod->multiprices[$soc->price_level]; + $pu_ht = $prod->multiprices[$fac->client->price_level]; + $pu_ttc = $prod->multiprices_ttc[$fac->client->price_level]; + $price_base_type = $prod->multiprices_base_type[$fac->client->price_level]; } else { - $pu=$prod->price; + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_base_type = $prod->price_base_type; } - + + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } + } + // La description de la ligne est celle saisie ou // celle du produit si PRODUIT_CHANGE_PROD_DESC est défini if ($conf->global->PRODUIT_CHANGE_PROD_DESC) @@ -520,12 +546,10 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer) { $desc = $_POST['np_desc']; } - - $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); } else { - $pu=$_POST['np_price']; + $pu_ht=$_POST['np_price']; $tva_tx=$_POST['np_tva_tx']; $desc=$_POST['np_desc']; } @@ -533,12 +557,13 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer) $propal->addline( $_POST['propalid'], $desc, - $pu, + $pu_ht, $_POST['qty'], $tva_tx, $_POST['idprod'], $_POST['remise_percent'], - 'HT' + $price_base_type, + $pu_ttc ); if ($_REQUEST['lang_id']) diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index d45d90bb7b3..a46a3242be3 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -626,7 +626,7 @@ class Commande extends CommonObject */ function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0) { - dolibarr_syslog("Commande::addline $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc"); + dolibarr_syslog("Commande::addline commandeid=$commandeid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc"); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); if ($this->statut == 0) @@ -641,9 +641,15 @@ class Commande extends CommonObject $pu_ht=price2num($pu_ht); $pu_ttc=price2num($pu_ttc); $txtva = price2num($txtva); - - if ($price_base_type=='HT') $pu=$pu_ht; - else $pu=$pu_ttc; + + if ($price_base_type=='HT') + { + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; + } // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva @@ -654,6 +660,7 @@ class Commande extends CommonObject $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; + // \TODO A virer // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; $remise = 0; @@ -680,7 +687,7 @@ class Commande extends CommonObject $ligne->total_tva=$total_tva; $ligne->total_ttc=$total_ttc; - // Ne plus utiliser + // \TODO Ne plus utiliser $ligne->price=$price; $ligne->remise=$remise; @@ -688,7 +695,7 @@ class Commande extends CommonObject if ($result > 0) { // Mise a jour informations denormalisees au niveau de la commande meme - $result=$this->update_price($this->id); + $result=$this->update_price($commandeid); if ($result > 0) { $this->db->commit(); @@ -1476,9 +1483,6 @@ class Commande extends CommonObject $this->total_tva += ($obj->total_ttc - $obj->total_ht); $this->total_ttc += $obj->total_ttc; - // Anciens indicateurs - $this->amount_ht += ($obj->price * $obj->qty); - $this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne) $tvas[$obj->tva_taux] += ($obj->total_ttc - $obj->total_ht); $i++; } @@ -1487,14 +1491,13 @@ class Commande extends CommonObject // Met a jour indicateurs $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET"; - $sql .= " amount_ht='".price2num($this->amount_ht)."'"; - $sql .= ", total_ht='". price2num($this->total_ht)."'"; - $sql .= ", tva='". price2num($this->total_tva)."'"; - $sql .= ", total_ttc='".price2num($this->total_ttc)."'"; - $sql .= ", remise='".price2num($this->total_remise)."'"; + $sql .= " total_ht='". price2num($this->total_ht)."',"; + $sql .= " tva='". price2num($this->total_tva)."',"; + $sql .= " total_ttc='".price2num($this->total_ttc)."'"; $sql .=" WHERE rowid = ".$this->id; + + dolibarr_syslog("Facture::update_price sql=".$sql); $resql=$this->db->query($sql); - if ($resql) { return 1; @@ -1566,32 +1569,33 @@ class Commande extends CommonObject * \param date_livraison Date de livraison * \return int <0 si ko, >0 si ok */ - function set_date_livraison($user, $date_livraison) - { - if ($user->rights->commande->creer) + function set_date_livraison($user, $date_livraison) { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET date_livraison = ".($date_livraison ? $this->db->idate($date_livraison) : 'null'); - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - $resql=$this->db->query($sql); - if ($resql) - { - $this->date_livraison = $date_livraison; - return 1; - } - else - { - $this->error=$this->db->error(); - dolibarr_syslog("Commande::set_date_livraison Erreur SQL sql=$sql"); - return -1; - } - } - else - { - return -2; - } - } + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET date_livraison = ".($date_livraison ? $this->db->idate($date_livraison) : 'null'); + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + dolibarr_syslog("Commande::set_date_livraison sql=$sql",LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->date_livraison = $date_livraison; + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Commande::set_date_livraison ".$this->error,LOG_ERR); + return -1; + } + } + else + { + return -2; + } + } /** * \brief Définit une adresse de livraison diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 6565bd7b434..932c409f2dd 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -244,11 +244,13 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->commande->creer) if ($_POST['action'] == 'setdate_livraison' && $user->rights->commande->creer) { - $datelivraison=dolibarr_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); - $commande = new Commande($db); - $commande->fetch($_GET['id']); - $result=$commande->set_date_livraison($user,$datelivraison); - if ($result < 0) + //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; + $datelivraison=dolibarr_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); + + $commande = new Commande($db); + $commande->fetch($_GET['id']); + $result=$commande->set_date_livraison($user,$datelivraison); + if ($result < 0) { $mesg='
'.$commande->error.'
'; } @@ -302,12 +304,12 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) { $commande = new Commande($db); $ret=$commande->fetch($_POST['id']); - $ret=$commande->fetch_client(); if ($ret < 0) { dolibarr_print_error($db,$commande->error); exit; } + $ret=$commande->fetch_client(); $price_base_type = 'HT'; @@ -320,39 +322,52 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); - $price_base_type = $prod->price_base_type; - - $libelle = $prod->libelle; + $tva_tx = get_default_tva($mysoc,$commande->client,$prod->tva_tx); // multiprix if ($conf->global->PRODUIT_MULTIPRICES == 1) { - $pu = $prod->multiprices[$commande->client->price_level]; - $pu_ttc = $prod->multiprices_ttc[$commande->client->price_level]; - $price_base_type = $prod->multiprices_base_type[$commande->client->price_level]; + $pu_ht = $prod->multiprices[$commande->client->price_level]; + $pu_ttc = $prod->multiprices_ttc[$commande->client->price_level]; + $price_base_type = $prod->multiprices_base_type[$commande->client->price_level]; } else { - $pu = $prod->price; - $pu_ttc = $prod->price_ttc; + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_base_type = $prod->price_base_type; } - + + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } + } + // La description de la ligne est celle saisie ou // celle du produit si PRODUIT_CHANGE_PROD_DESC est défini + $libelle = $prod->libelle; if ($conf->global->PRODUIT_CHANGE_PROD_DESC) { $desc = $prod->description; } else { - $desc=$_POST['np_desc']; + $desc = $_POST['np_desc']; } - $tva_tx = get_default_tva($mysoc,$commande->client,$prod->tva_tx); } else { - $pu=$_POST['pu']; + $pu_ht=$_POST['pu']; $tva_tx=$_POST['tva_tx']; $desc=$_POST['np_desc']; } @@ -360,7 +375,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) $result = $commande->addline( $_POST['id'], $desc, - $pu, + $pu_ht, $_POST['qty'], $tva_tx, $_POST['idprod'], @@ -715,178 +730,176 @@ $html = new Form($db); *********************************************************************/ if ($_GET['action'] == 'create' && $user->rights->commande->creer) { - print_titre($langs->trans('CreateOrder')); - - if ($mesg) print $mesg.'
'; - - $new_commande = new Commande($db); - - if ($propalid) - { - $sql = 'SELECT s.nom, s.prefix_comm, s.rowid'; - $sql.= ', p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement'; - $sql.= ', '.$db->pdate('p.datep').' as dp'; - $sql.= ', c.id as statut, c.label as lst'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c'; - $sql .= ' WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id'; - $sql .= ' AND p.rowid = '.$propalid; - } - else - { - $sql = 'SELECT s.nom, s.prefix_comm, s.rowid, s.mode_reglement, s.cond_reglement '; - $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s '; - $sql .= 'WHERE s.rowid = '.$_GET['socid']; - } - $resql = $db->query($sql); - if ( $resql ) - { - $num = $db->num_rows($resql); - if ($num) - { - $obj = $db->fetch_object($resql); - - $soc = new Societe($db); - $soc->fetch($obj->rowid); - - $nbrow=7; - - print '
'; - print ''; - print '' ."\n"; - print ''; - print ''; - - print ''; - - // Reference - print ''; - print ''; - - // Reference client - print ''; - print ''; - - // Client - print ''; - - /* - * Contact de la commande - */ - print "'; - - // Ligne info remises tiers - print ''; - - // Date - print ''; - - // Date de livraison - if ($conf->expedition->enabled) - { - print ""; - - // Adresse de livraison - print ''; - } - - // Conditions de réglement - print ''; - - // Mode de réglement - print ''; - - // Projet - if ($conf->projet->enabled) - { - print ''; - } + print_titre($langs->trans('CreateOrder')); - print ''; - print ''; - print '"; - - if ($propalid > 0) - { - $amount = ($obj->price); - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - - print ''; - print ''; - print ''; - print ''; - } - else - { - if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) + if ($mesg) print $mesg.'
'; + + $new_commande = new Commande($db); + + if ($propalid) + { + $sql = 'SELECT s.nom, s.prefix_comm, s.rowid'; + $sql.= ', p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement'; + $sql.= ', '.$db->pdate('p.datep').' as dp'; + $sql.= ', c.id as statut, c.label as lst'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c'; + $sql .= ' WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id'; + $sql .= ' AND p.rowid = '.$propalid; + } + else + { + $sql = 'SELECT s.nom, s.prefix_comm, s.rowid, s.mode_reglement, s.cond_reglement '; + $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s '; + $sql .= 'WHERE s.rowid = '.$_GET['socid']; + } + $resql = $db->query($sql); + if ( $resql ) + { + $num = $db->num_rows($resql); + if ($num) { - /* - * Services/produits prédéfinis - */ - $NBLINES=8; - - print '
'.$langs->trans('Ref').''.$langs->trans("Draft").''.$langs->trans('NotePublic').'
'.$langs->trans('RefCustomer').''; - print '
'.$langs->trans('Customer').''.$soc->getNomUrl(1).'
".$langs->trans("DefaultContact").''; - $html->select_contacts($soc->id,$setcontact,'contactidp',1); - print '
'.$langs->trans('Discounts').''; - if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount(); - print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; - print '
'.$langs->trans('Date').''; - $html->select_date('','re','','','',"crea_commande"); - print '
".$langs->trans("DateDelivery").""; - if ($conf->global->DATE_LIVRAISON_WEEK_DELAY) - { - $tmpdte = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); - $html->select_date($tmpdte,'liv_','','',1,"crea_commande"); - } - else - { - $html->select_date(-1,'liv_','','',1,"crea_commande"); - } - print "
'.$langs->trans('DeliveryAddress').''; - $numaddress = $html->select_adresse_livraison($soc->adresse_livraison_id, $_GET['socid'],'adresse_livraison_id',1); - - if ($numaddress==0) - { - print '   '.$langs->trans("AddAddress").''; - } - - print '
'.$langs->trans('PaymentConditionsShort').''; - $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id',-1,1); - print '
'.$langs->trans('PaymentMode').''; - $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id'); - print '
'.$langs->trans('Project').''; - $numprojet=$html->select_projects($soc->id,$projetid,'projetid'); - if ($numprojet==0) - { - print '   id.'&action=create>'.$langs->trans("AddProject").''; - } - print '
'.$langs->trans('Source').''; - $html->selectSourcesCommande('','source_id',1); - print '
'.$langs->trans('Model').''; - // pdf - include_once(DOL_DOCUMENT_ROOT.'/includes/modules/commande/modules_commande.php'); - $model=new ModelePDFCommandes(); - $liste=$model->liste_modeles($db); - $html->select_array('model',$liste,$conf->global->COMMANDE_ADDON_PDF); - print "
'.$langs->trans('Ref').''.$obj->ref.'
'.$langs->trans('TotalTTC').''.price($amount).'
'.$langs->trans('VAT').''.price($obj->tva).'
'.$langs->trans('TotalTTC').''.price($obj->total).'
'; - - print ''; - print ''; - print ''; - print ''; - print ''; - for ($i = 1 ; $i <= $NBLINES ; $i++) - { + $obj = $db->fetch_object($resql); + + $soc = new Societe($db); + $soc->fetch($obj->rowid); + + $nbrow=9; + + print ''; + print ''; + print '' ."\n"; + print ''; + print ''; + + print '
'.$langs->trans('ProductsAndServices').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').'
'; + + // Reference + print ''; + print ''; + + // Reference client + print ''; + print ''; + + // Client + print ''; + + /* + * Contact de la commande + */ + print "'; + + // Ligne info remises tiers + print ''; + + // Date + print ''; + + // Date de livraison + print ""; + + // Adresse de livraison + print ''; + + // Conditions de réglement + print ''; + + // Mode de réglement + print ''; + + // Projet + if ($conf->projet->enabled) + { + print ''; + } + + print ''; + + print ''; + print '"; + + if ($propalid > 0) + { + $amount = ($obj->price); + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + + print ''; + print ''; + print ''; + print ''; + } + else + { + if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) + { + /* + * Services/produits prédéfinis + */ + $NBLINES=8; + + print '
'.$langs->trans('Ref').''.$langs->trans("Draft").''.$langs->trans('NotePublic').'
'.$langs->trans('RefCustomer').''; + print '
'.$langs->trans('Customer').''.$soc->getNomUrl(1).'
".$langs->trans("DefaultContact").''; + $html->select_contacts($soc->id,$setcontact,'contactidp',1); + print '
'.$langs->trans('Discounts').''; + if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$soc->getCurrentDiscount(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print '
'.$langs->trans('Date').''; + $html->select_date('','re','','','',"crea_commande"); + print '
".$langs->trans("DateDelivery").""; + if ($conf->global->DATE_LIVRAISON_WEEK_DELAY) + { + $tmpdte = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); + $html->select_date($tmpdte,'liv_','','',1,"crea_commande"); + } + else + { + $html->select_date(-1,'liv_','','',1,"crea_commande"); + } + print "
'.$langs->trans('DeliveryAddress').''; + $numaddress = $html->select_adresse_livraison($soc->adresse_livraison_id, $_GET['socid'],'adresse_livraison_id',1); + + if ($numaddress==0) + { + print '   '.$langs->trans("AddAddress").''; + } + + print '
'.$langs->trans('PaymentConditionsShort').''; + $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id',-1,1); + print '
'.$langs->trans('PaymentMode').''; + $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id'); + print '
'.$langs->trans('Project').''; + $numprojet=$html->select_projects($soc->id,$projetid,'projetid'); + if ($numprojet==0) + { + print '   id.'&action=create>'.$langs->trans("AddProject").''; + } + print '
'.$langs->trans('Source').''; + $html->selectSourcesCommande('','source_id',1); + print '
'.$langs->trans('Model').''; + // pdf + include_once(DOL_DOCUMENT_ROOT.'/includes/modules/commande/modules_commande.php'); + $model=new ModelePDFCommandes(); + $liste=$model->liste_modeles($db); + $html->select_array('model',$liste,$conf->global->COMMANDE_ADDON_PDF); + print "
'.$langs->trans('Ref').''.$obj->ref.'
'.$langs->trans('TotalTTC').''.price($amount).'
'.$langs->trans('VAT').''.price($obj->tva).'
'.$langs->trans('TotalTTC').''.price($obj->total).'
'; + + print ''; + print ''; + print ''; + print ''; + print ''; + for ($i = 1 ; $i <= $NBLINES ; $i++) + { print ''; print ''; print ''; print ''; print ''; print ''; print ''; diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 7c85a11937b..1fe64431c8a 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -285,7 +285,7 @@ if ($_GET["propalid"] > 0) // Amount print ''; - print ''; + print ''; print ''; print ''; @@ -304,7 +304,8 @@ if ($_GET["propalid"] > 0) */ $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; - $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; + $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc,'; + $sql.= ' p.rowid as prodid, p.label as product, p.ref, p.fk_product_type, '; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; @@ -424,16 +425,13 @@ if ($_GET["propalid"] > 0) { print ''; } - print '\n"; + print '\n"; print ''; print ''; } - - - $total = $total + ($objp->qty * $objp->price); $i++; } $db->free($resql); @@ -647,9 +645,12 @@ else $pageprev = $page - 1; $pagenext = $page + 1; + $year = $_REQUEST["year"]; + $month = $_REQUEST["month"]; $sql = "SELECT s.nom, s.rowid as socid, s.client,"; - $sql.= " p.rowid as propalid, p.price, p.ref, p.fk_statut,"; + $sql.= " p.rowid as propalid, p.ref, p.fk_statut,"; + $sql.= " p.total_ht, p.tva, p.total,"; $sql.= $db->pdate("p.datep")." as dp, "; $sql.= $db->pdate("p.fin_validite")." as dfin"; if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; @@ -697,7 +698,7 @@ else print_liste_field_titre($langs->trans("Ref"),"propal.php","p.ref","","&year=$year&viewstatut=$viewstatut",'width=20%',$sortfield); print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","&viewstatut=$viewstatut","",'',$sortfield); print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","&viewstatut=$viewstatut","",'align="right"',$sortfield); - print_liste_field_titre($langs->trans("Price"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield); + print_liste_field_titre($langs->trans("AmountHT"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield); print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","&viewstatut=$viewstatut","",'align="right"',$sortfield); print ''; print "\n"; @@ -706,24 +707,23 @@ else print ''; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; print "\n"; print ''; @@ -779,7 +779,7 @@ else print strftime("%Y",$objp->dp)."\n"; // Prix - print "\n"; + print "\n"; print "\n"; print ""; print "\n"; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index eb31a127050..74d65621e71 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -1309,7 +1309,7 @@ class Facture extends CommonObject * \param date_end Date de fin de validité du service * \param ventil Code de ventilation comptable * \param info_bits Bits de type de lignes - * \param fk_remise_exscept Id remise + * \param fk_remise_except Id remise * \param price_base_type HT or TTC * \param pu_ttc Prix unitaire TTC * \return int >0 si ok, <0 si ko @@ -1320,7 +1320,7 @@ class Facture extends CommonObject */ function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='', $price_base_type='HT', $pu_ttc=0) { - dolibarr_syslog("Facture::Addline $facid,$desc,$pu_ht,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$fk_remise_except,$price_base_type,$pu_ttc", LOG_DEBUG); + dolibarr_syslog("Facture::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc", LOG_DEBUG); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); if ($this->brouillon) @@ -1337,8 +1337,14 @@ class Facture extends CommonObject $pu_ttc=price2num($pu_ttc); $txtva=price2num($txtva); - if ($price_base_type=='HT') $pu=$pu_ht; - else $pu=$pu_ttc; + if ($price_base_type=='HT') + { + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; + } // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva @@ -1349,6 +1355,7 @@ class Facture extends CommonObject $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; + // \TODO A virer // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; $remise = 0; @@ -1378,7 +1385,7 @@ class Facture extends CommonObject $ligne->total_tva=$total_tva; $ligne->total_ttc=$total_ttc; - // A ne plus utiliser + // \TODO Ne plus utiliser $ligne->price=$price; $ligne->remise=$remise; @@ -1552,18 +1559,20 @@ class Facture extends CommonObject } } - /** + /** \brief Mise à jour des sommes de la facture et calculs denormalises \param facid id de la facture a modifier \return int <0 si ko, >0 si ok - */ - function update_price($facid) + */ + function update_price($facid) { + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + $tvas=array(); $err=0; - // Liste des lignes factures a sommer (Ne plus utiliser price) - $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price,'; + // Liste des lignes a sommer + $sql = 'SELECT qty, tva_taux, subprice, remise_percent,'; $sql.= ' total_ht, total_tva, total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet'; $sql.= ' WHERE fk_facture = '.$facid; @@ -1575,6 +1584,7 @@ class Facture extends CommonObject $this->total_ht = 0; $this->total_tva = 0; $this->total_ttc = 0; + $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) @@ -1585,9 +1595,6 @@ class Facture extends CommonObject $this->total_tva += ($obj->total_ttc - $obj->total_ht); $this->total_ttc += $obj->total_ttc; - // Ne plus utiliser amount, ni remise - $this->amount_ht += ($obj->price * $obj->qty); - $this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne) $tvas[$obj->tva_taux] += ($obj->total_ttc - $obj->total_ht); $i++; } @@ -1595,15 +1602,14 @@ class Facture extends CommonObject $this->db->free($resql); // Met a jour indicateurs - $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture '; - $sql .= "SET amount ='".price2num($this->amount_ht)."'"; - $sql .= ", remise='". price2num($this->total_remise)."'"; - $sql .= ", total='". price2num($this->total_ht)."'"; - $sql .= ", tva='". price2num($this->total_tva)."'"; - $sql .= ", total_ttc='".price2num($this->total_ttc)."'"; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET'; + $sql .= " total='". price2num($this->total_ht)."',"; + $sql .= " tva='". price2num($this->total_tva)."',"; + $sql .= " total_ttc='".price2num($this->total_ttc)."'"; $sql .= ' WHERE rowid = '.$facid; - $resql=$this->db->query($sql); + dolibarr_syslog("Facture::update_price sql=".$sql); + $resql=$this->db->query($sql); if ($resql) { // \TODO A supprimer car l'utilisation de facture_tva_sum non utilisable diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 725bc2d261b..f8e3a953491 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -2449,7 +2449,7 @@ class Form /** * \brief Selection du taux de tva appliqué par vendeur * \param name Nom champ html - * \param defaulttx Forçage du taux tva présélectionné. Mettre '' pour appliquer règle par défaut. + * \param defaulttx Forçage du taux tva présélectionné. Mettre '' pour aucun forcage. * \param societe_vendeuse Objet société vendeuse * \param societe_acheteuse Objet société acheteuse * \param taux_produit Taux par defaut du produit vendu @@ -2519,11 +2519,11 @@ class Form print ''.$this->db->error().''; } - // Définition du taux à présélectionner - if (("".$defaulttx) == "") $defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$taux_produit); - // Si taux par defaut n'a pu etre trouvé, on prend dernier. + // Définition du taux à présélectionner (si defaulttx non forcé et donc vaut -1 ou '') + if ($defaulttx < 0 || strlen($defaulttx) == 0) $defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$taux_produit); + // Si taux par defaut n'a pu etre déterminé, on prend dernier de la liste. // Comme ils sont triés par ordre croissant, dernier = plus élevé = taux courant - if (("".$defaulttx) == "") $defaulttx = $txtva[sizeof($txtva)-1]; + if ($defaulttx < 0 || strlen($defaulttx) == 0) $defaulttx = $txtva[sizeof($txtva)-1]; $nbdetaux = sizeof($txtva); diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 4a26504f10e..52b860233c5 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -94,9 +94,9 @@ ProfId1PT=NIPC ProfId2PT=Social security number ProfId3PT=Commercial Record number ProfId4PT=Conservatory -TVAIntra=Intracommunautary VAT -VATIntraShort=Intra-communautary VAT code -VATIntraVeryShort=VAT Intra-comm. +VATIntra=VAT number +VATIntraShort=VAT number +VATIntraVeryShort=VAT VATIntraSyntaxIsValid=Syntax is valid VATIntraValueIsValid=Value is valid ProspectCustomer=Prospect / Customer @@ -167,7 +167,7 @@ EditCompany=Edit company ThisUserIsNot=This user is not a prospect, customer nor supplier VATIntraCheck=Check VATIntraCheckDesc=The link %s allows to ask the european VAT checker service. An external internet access from server is required for this service to work. -VATIntraCheckURL=http://europa.eu.int/comm/taxation_customs/vies/fr/vieshome.htm +VATIntraCheckURL=http://ec.europa.eu/taxation_customs/vies/vieshome.do VATIntraCheckableOnEUSite=Check Intracomunnautary VAT on European commision site VATIntraManualCheck=You can also check manually from european web site %s ErrorVATCheckMS_UNAVAILABLE=Check not possible. Check service is not provided by the member state (%s). diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 32f64954327..afdc9c9b738 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -27,7 +27,7 @@ ErrorRecordIsUsedByChild=Failed to delete this record. This record is used by at ErrorWrongValue=Wrong value ErrorWrongValueForParameterX=Wrong value for parameter %s ErrorNoRequestInError=No request in error -ErrorServiceUnavailableTryLater=Service not available or busy for the moment. Try again later. +ErrorServiceUnavailableTryLater=Service not available for the moment. Try again later. ErrorDuplicateField=Duplicate value in a unique field ErrorSomeErrorWereFoundRollbackIsDone=Some errors were found. We rollback changes. ErrorConfigParameterNotDefined=Parameter %s is not defined inside Dolibarr config file conf.php. diff --git a/htdocs/langs/fr_BE/companies.lang b/htdocs/langs/fr_BE/companies.lang index 9f070d1947e..ab394513eee 100644 --- a/htdocs/langs/fr_BE/companies.lang +++ b/htdocs/langs/fr_BE/companies.lang @@ -73,9 +73,9 @@ ProfId1PT= ProfId2PT=Numéro de sécurité sociale ProfId3PT=Numéro d'enregistrement commercial ProfId4PT= -TVAIntra=Numéro de TVA Intracommunautaire -VATIntraShort=Numéro de TVA intra-communautaire -VATIntraVeryShort=TVA intra-comm. +VATIntra=Numéro de TVA +VATIntraShort=Num TVA +VATIntraVeryShort=N° TVA ProspectCustomer=Prospect / Client Prospect=Prospect CustomerCard=Fiche Client @@ -137,7 +137,7 @@ Capital=Capital CapitalOf=Capital de %s EditCompany=Modification société ThisUserIsNot=Cet utilisateur n'est ni un prospect, ni un client, ni un fournisseur -VATIntraCheckURL=http://europa.eu.int/comm/taxation_customs/vies/fr/vieshome.htm +VATIntraCheckURL=http://ec.europa.eu/taxation_customs/vies/vieshome.do VATIntraCheckableOnEUSite=Verifier un numéro de TVA intra-communautaire sur le site de la Commission Européenne NorProspectNorCustomer=Pas un prospect, ni un client JuridicalStatus=Statut juridique diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index c7899f594a1..6be9a0fbb34 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -94,9 +94,9 @@ ProfId1PT=NIPC ProfId2PT=Num sécurité social ProfId3PT=Num enreg. commercial ProfId4PT=Conservatory -TVAIntra=Numéro de TVA Intracommunautaire -VATIntraShort=N° TVA Intra-communautaire -VATIntraVeryShort=TVA Intra-comm. +VATIntra=Numéro de TVA +VATIntraShort=Num TVA +VATIntraVeryShort=N° TVA VATIntraSyntaxIsValid=Syntaxe valide VATIntraValueIsValid=Valeure valide ProspectCustomer=Prospect / Client @@ -167,7 +167,7 @@ EditCompany=Modification soci ThisUserIsNot=Cet utilisateur n'est ni un prospect, ni un client, ni un fournisseur VATIntraCheck=Vérifier VATIntraCheckDesc=Le lien %s permet d'interroger le service européen de contrôle des numéro de TVA intracommunautaire. Un accès au monde internet exterieur depuis le serveur est requis pour que ce service fonctionne. -VATIntraCheckURL=http://europa.eu.int/comm/taxation_customs/vies/fr/vieshome.htm +VATIntraCheckURL=http://ec.europa.eu/taxation_customs/vies/vieshome.do VATIntraCheckableOnEUSite=Vérifier sur le site de la Commission Européenne VATIntraManualCheck=Vous pouvez aussi vérifier manuellement via le site européen %s ErrorVATCheckMS_UNAVAILABLE=Vérification impossible. Le service de vérification n'est pas fourni par ce pays membre (%s). diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 4a8716999c4..b8a42998a17 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -27,7 +27,7 @@ ErrorRecordIsUsedByChild=Impossible de supprimer cet enregistrement. Ce dernier ErrorWrongValue=Valeur incorrecte ErrorWrongValueForParameterX=Valeur incorrecte pour le paramètre %s ErrorNoRequestInError=Aucune requete en erreur -ErrorServiceUnavailableTryLater=Service non disponible ou saturé actuellement. Réessayer plus tard. +ErrorServiceUnavailableTryLater=Service non disponible actuellement. Réessayer plus tard. ErrorDuplicateField=Doublon dans un champ unique ErrorSomeErrorWereFoundRollbackIsDone=Des erreurs ont été trouvés. On rollback les modifications. ErrorConfigParameterNotDefined=Le parametre %s n'est pas défini dans le fichier de configuration Dolibarr conf.php. diff --git a/htdocs/langs/nl_BE/companies.lang b/htdocs/langs/nl_BE/companies.lang index ee58fbfb3a2..2c60a0f17ec 100644 --- a/htdocs/langs/nl_BE/companies.lang +++ b/htdocs/langs/nl_BE/companies.lang @@ -77,9 +77,9 @@ ProfId1PT=NIPC ProfId2PT=Nummer sociale zekerheid ProfId3PT=Nummer Commercial Record ProfId4PT=Conservatory -TVAIntra=Intracommunautary VAT -VATIntraShort=Intra-communautary VAT code -VATIntraVeryShort=VAT Intra-comm. +VATIntra=VAT number +VATIntraShort=VAT number +VATIntraVeryShort=VAT VATIntraSyntaxIsValid=Syntax is geldig VATIntraValueIsValid=Waarde is geldig ProspectCustomer=Prospect / Klant @@ -145,7 +145,7 @@ EditCompany=Aanpassen bedrijf ThisUserIsNot=Deze gebruiker is geen prospect, klant of leverancier VATIntraCheck=Controleer VATIntraCheckDesc=De verbinding %s laat toe de europeese BTW testservice te bevragen. Een toegang tot het internet vanaf de server is vereist om deze dienst te laten werken. -VATIntraCheckURL=http://europa.eu.int/comm/taxation_customs/vies/fr/vieshome.htm +VATIntraCheckURL=http://ec.europa.eu/taxation_customs/vies/vieshome.do VATIntraCheckableOnEUSite=Check Intracomunnautary VAT on European commision site VATIntraManualCheck=U kan ook zelf de test doen via de europese website %s ErrorVATCheckMS_UNAVAILABLE=Test niet mogelijk. Testservice wordt niet voorzien door de lidstaat (%s). diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 9a7954bc1e0..09fbe7cce83 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -641,16 +641,17 @@ function dolibarr_getdate($timestamp,$fast=false) \param month Mois \param day Jour \param year Année - \return date Date + \return timestamp Date en timestamp, '' if error \remarks PHP mktime is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows */ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=0) { //print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -"; - + if (! $month || ! $day) return ''; + $usealternatemethod=false; - if ($timestamp <= 0) $usealternatemethod=true; // <= 1970 - if ($timestamp >= 2145913200) $usealternatemethod=true; // >= 2038 + if ($year <= 1970) $usealternatemethod=true; // <= 1970 + if ($year >= 2038) $usealternatemethod=true; // >= 2038 if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir { @@ -2248,23 +2249,23 @@ function price2num($amount,$rounding='') /** - \brief Fonction qui renvoie la tva d'une ligne (en fonction du vendeur, acheteur et taux du produit) - \remarks Si vendeur non assujeti à TVA, TVA par défaut=0. Fin de règle. - Si le (pays vendeur = pays acheteur) alors TVA par défaut=TVA du produit vendu. Fin de règle. - Si vendeur et acheteur dans Communauté européenne et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par défaut=0 (La TVA doit être payé par acheteur au centre d'impots de son pays et non au vendeur). Fin de règle. - Si vendeur et acheteur dans Communauté européenne et acheteur = particulier ou entreprise sans num TVA intra alors TVA par défaut=TVA du produit vendu. Fin de règle. - Si vendeur et acheteur dans Communauté européenne et acheteur = entreprise avec num TVA intra alors TVA par défaut=0. Fin de règle. - Sinon TVA proposée par défaut=0. Fin de règle. - \param societe_vendeuse Objet société vendeuse - \param societe_acheteuse Objet société acheteuse - \param taux_produit Taux par defaut du produit vendu - \return float Taux de tva de la ligne + \brief Fonction qui renvoie la tva d'une ligne (en fonction du vendeur, acheteur et taux du produit) + \remarks Si vendeur non assujeti à TVA, TVA par défaut=0. Fin de règle. + Si le (pays vendeur = pays acheteur) alors TVA par défaut=TVA du produit vendu. Fin de règle. + Si (vendeur et acheteur dans Communauté européenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par défaut=0 (La TVA doit être payé par acheteur au centre d'impots de son pays et non au vendeur). Fin de règle. + Si (vendeur et acheteur dans Communauté européenne) et (acheteur = particulier ou entreprise sans num TVA intra) alors TVA par défaut=TVA du produit vendu. Fin de règle. + Si (vendeur et acheteur dans Communauté européenne) et (acheteur = entreprise avec num TVA) intra alors TVA par défaut=0. Fin de règle. + Sinon TVA proposée par défaut=0. Fin de règle. + \param societe_vendeuse Objet société vendeuse + \param societe_acheteuse Objet société acheteuse + \param taux_produit Taux par defaut du produit vendu + \return float Taux de tva à appliquer, -1 si ne peut etre déterminé */ function get_default_tva($societe_vendeuse, $societe_acheteuse, $taux_produit) { dolibarr_syslog("get_default_tva vendeur_assujeti=$societe_vendeuse->tva_assuj pays_vendeur=$societe_vendeuse->pays_id, pays_acheteur=$societe_acheteuse->pays_id, taux_produit=$taux_produit"); - if (!is_object($societe_vendeuse)) return 0; + if (!is_object($societe_vendeuse)) return -1; // Si vendeur non assujeti à TVA (tva_assuj vaut 0/1 ou franchise/reel) if (is_numeric($societe_vendeuse->tva_assuj) && ! $societe_vendeuse->tva_assuj) return 0; @@ -2275,25 +2276,28 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $taux_produit) // Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concercné si le test suivant n'est pas suffisant. if (is_object($societe_acheteuse) && ($societe_vendeuse->pays_id == $societe_acheteuse->pays_id)) { + if (strlen($taux_produit) == 0) return -1; // Si taux produit = '', on ne peut déterminer taux tva return $taux_produit; } - // Si vendeur et acheteur dans Communauté européenne et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par défaut=0 (La TVA doit être payé par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de règle. + // Si (vendeur et acheteur dans Communauté européenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par défaut=0 (La TVA doit être payé par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de règle. // Non géré - // Si vendeur et acheteur dans Communauté européenne et acheteur = particulier ou entreprise sans num TVA intra alors TVA par défaut=TVA du produit vendu. Fin de règle. + // Si (vendeur et acheteur dans Communauté européenne) et (acheteur = particulier ou entreprise sans num TVA intra) alors TVA par défaut=TVA du produit vendu. Fin de règle. if (is_object($societe_acheteuse) && ($societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC()) && ! $societe_acheteuse->tva_intra) { + if (strlen($taux_produit) == 0) return -1; // Si taux produit = '', on ne peut déterminer taux tva return $taux_produit; } - // Si vendeur et acheteur dans Communauté européenne et acheteur = entreprise avec num TVA intra alors TVA par défaut=0. Fin de règle. + // Si (vendeur et acheteur dans Communauté européenne) et (acheteur = entreprise avec num TVA intra) alors TVA par défaut=0. Fin de règle. if (is_object($societe_acheteuse) && ($societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC()) && $societe_acheteuse->tva_intra) { return 0; } // Sinon la TVA proposée par défaut=0. Fin de règle. + // Rem: Cela signifie qu'au moins un des 2 est hors Communauté européenne et que le pays diffère return 0; } diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 68cc438db55..2212da87814 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -255,12 +255,13 @@ class Propal extends CommonObject * \brief Ajout d'un produit dans la proposition, en base * \param propalid Id de la propale * \param desc Description de la ligne - * \param pu Prix unitaire + * \param pu_ht Prix unitaire * \param qty Quantité * \param txtva Taux de tva forcé, sinon -1 * \param fk_product Id du produit/service predéfini * \param remise_percent Pourcentage de remise de la ligne * \param price_base_type HT or TTC + * \param pu_ttc Prix unitaire TTC * \return int >0 si ok, <0 si ko * \see add_product * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel @@ -268,9 +269,9 @@ class Propal extends CommonObject * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit) * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) */ - function addline($propalid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT') + function addline($propalid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc) { - dolibarr_syslog("Propal::Addline $propalid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $price_base_type"); + dolibarr_syslog("Propal::Addline propalid=$propalid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc"); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); if ($this->statut == 0) @@ -281,8 +282,18 @@ class Propal extends CommonObject $remise_percent=price2num($remise_percent); $qty=price2num($qty); if (! $qty) $qty=1; - $pu = price2num($pu,'MU'); - $txtva = price2num($txtva,'MU'); + $pu_ht=price2num($pu_ht); + $pu_ttc=price2num($pu_ttc); + $txtva=price2num($txtva); + + if ($price_base_type=='HT') + { + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; + } // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva @@ -296,7 +307,8 @@ class Propal extends CommonObject // \TODO A virer // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; - if ($remise_percent > 0) + $remise = 0; + if ($remise_percent > 0) { $remise = round(($pu * $remise_percent / 100), 2); $price = $pu - $remise; @@ -311,9 +323,10 @@ class Propal extends CommonObject $ligne->tva_tx=$txtva; $ligne->fk_product=$fk_product; $ligne->remise_percent=$remise_percent; - $ligne->subprice=$pu; + $ligne->subprice=$pu_ht; $ligne->rang=-1; $ligne->info_bits=$info_bits; + $ligne->fk_remise_except=$fk_remise_except; $ligne->total_ht=$total_ht; $ligne->total_tva=$total_tva; $ligne->total_ttc=$total_ttc; @@ -326,8 +339,7 @@ class Propal extends CommonObject if ($result > 0) { // Mise a jour informations denormalisees au niveau de la facture meme - $result=$this->update_price($facid); - + $result=$this->update_price($propalid); if ($result > 0) { $this->db->commit(); @@ -582,61 +594,67 @@ class Propal extends CommonObject */ function update_price() { - include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + + $tvas=array(); + $err=0; - // Liste des lignes factures a sommer - $sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."propaldet"; - $sql.= " WHERE fk_propal = ".$this->id; - - dolibarr_syslog("Propal::update_price sql=".$sql); - $result = $this->db->query($sql); - if ($result) - { - $this->total_ht = 0; - $this->total_tva = 0; - $this->total_ttc = 0; - - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($result); - - $this->total_ht += $obj->total_ht; - $this->total_tva += $obj->total_tva; - $this->total_ttc += $obj->total_ttc; - - // Anciens indicateurs - $this->amount_ht += $obj->price * $obj->qty; // \TODO A virer - $this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne) - $i++; - } - - $this->db->free($result); - } + // Liste des lignes a sommer + $sql = "SELECT qty, tva_tx, subprice, remise_percent,"; + $sql.= " total_ht, total_tva, total_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."propaldet"; + $sql.= " WHERE fk_propal = ".$this->id; - // Met a jour en base - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET"; - $sql .= " total_ht=".price2num($this->total_ht).","; - $sql .= " tva=". price2num($this->total_tva).","; - $sql .= " total=". price2num($this->total_ttc).","; - //$sql .= " remise=". price2num($this->total_remise).","; // \TODO A virer - $sql .= " price=". price2num($this->total_ht); // \TODO A virer - $sql .=" WHERE rowid = ".$this->id; + dolibarr_syslog("Propal::update_price sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $this->total_ht = 0; + $this->total_tva = 0; + $this->total_ttc = 0; + + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + + $this->total_ht += $obj->total_ht; + $this->total_tva += ($obj->total_ttc - $obj->total_ht); + $this->total_ttc += $obj->total_ttc; + + $tvas[$obj->tva_taux] += ($obj->total_ttc - $obj->total_ht); + $i++; + } + + $this->db->free($result); - dolibarr_syslog("Propal::update_price sql=".$sql); - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - $this->error=$this->db->error(); - dolibarr_syslog("Propal::update_price error=".$this->error); - return -1; - } - } + // Met a jour indicateurs + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET"; + $sql.= " total_ht=".price2num($this->total_ht).","; + $sql.= " tva=". price2num($this->total_tva).","; + $sql.= " total=". price2num($this->total_ttc); + $sql.= " WHERE rowid = ".$this->id; + + dolibarr_syslog("Propal::update_price sql=".$sql); + if ( $this->db->query($sql) ) + { + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Propal::update_price error=".$this->error); + return -1; + } + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Propal::update_price error=".$this->error,LOG_ERR); + return -1; + } + } /** @@ -770,7 +788,8 @@ class Propal extends CommonObject */ function fetch($rowid) { - $sql = "SELECT p.rowid,ref,total,price,remise,remise_percent,remise_absolue,tva,fk_soc"; + $sql = "SELECT p.rowid,ref,remise,remise_percent,remise_absolue,fk_soc"; + $sql.= ", total, tva, total_ht"; $sql.= ", ".$this->db->pdate("datep")." as dp"; $sql.= ", ".$this->db->pdate("fin_validite")." as dfv"; $sql.= ", ".$this->db->pdate("date_livraison")." as date_livraison"; @@ -782,12 +801,12 @@ class Propal extends CommonObject $sql.= ", p.fk_mode_reglement, cp.code as mode_reglement_code"; $sql.= ", c.label as statut_label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."propal as p"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as cr ON p.fk_cond_reglement = cr.rowid'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as cr ON p.fk_cond_reglement = cr.rowid'; $sql.= " WHERE p.fk_statut = c.id"; $sql.= " AND p.rowid='".$rowid."'"; - dolibarr_syslog("Propal.class::fecth rowid=".$rowid); + dolibarr_syslog("Propal::fecth rowid=".$rowid); $resql=$this->db->query($sql); if ($resql) @@ -803,12 +822,11 @@ class Propal extends CommonObject $this->date = $obj->dp; $this->ref = $obj->ref; $this->ref_client = $obj->ref_client; - $this->price = $obj->price; $this->remise = $obj->remise; $this->remise_percent = $obj->remise_percent; $this->remise_absolue = $obj->remise_absolue; $this->total = $obj->total; - $this->total_ht = $obj->price; + $this->total_ht = $obj->total_ht; $this->total_tva = $obj->tva; $this->total_ttc = $obj->total; $this->socid = $obj->fk_soc; @@ -906,7 +924,7 @@ class Propal extends CommonObject else { $this->error=$this->db->error(); - dolibarr_syslog("Propal.class::Fetch Error $this->error, sql=$sql"); + dolibarr_syslog("Propal::Fetch Error $this->error, sql=$sql"); return -1; } @@ -919,7 +937,7 @@ class Propal extends CommonObject else { $this->error=$this->db->error(); - dolibarr_syslog("Propal.class::Fetch Error sql=$sql ".$this->error); + dolibarr_syslog("Propal::Fetch Error sql=$sql ".$this->error); return -1; } } @@ -2272,7 +2290,7 @@ class PropaleLigne */ function insert() { - dolibarr_syslog("PropaleLigne.class::insert rang=".$this->rang); + dolibarr_syslog("PropaleLigne::insert rang=".$this->rang); $this->db->begin(); // Nettoyage parameteres @@ -2301,7 +2319,7 @@ class PropaleLigne // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet'; $sql.= ' (fk_propal, description, fk_product, fk_remise_except, qty, tva_tx,'; - $sql.= ' subprice, remise_percent, price, remise, '; + $sql.= ' subprice, remise_percent, '; $sql.= ' info_bits, '; $sql.= ' total_ht, total_tva, total_ttc, marge_tx, marque_tx, rang)'; $sql.= " VALUES (".$this->fk_propal.","; @@ -2314,8 +2332,6 @@ class PropaleLigne $sql.= " ".price2num($this->tva_tx).","; $sql.= " ".price2num($this->subprice).","; $sql.= " ".price2num($this->remise_percent).","; - $sql.= " ".price2num($this->price).","; // \TODO A virer - $sql.= " ".price2num($this->remise).","; // \TODO A virer $sql.= " '".$this->info_bits."',"; $sql.= " ".price2num($this->total_ht).","; $sql.= " ".price2num($this->total_tva).","; @@ -2327,7 +2343,7 @@ class PropaleLigne $sql.= ' '.$rangtouse; $sql.= ')'; - dolibarr_syslog("PropaleLigne.class::insert sql=$sql"); + dolibarr_syslog("PropaleLigne::insert sql=$sql"); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/soc.php b/htdocs/soc.php index 3a0350e5ce5..4853620a296 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -515,7 +515,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print $html->selectyesno('assujtva_value',1,1); // Assujeti par défaut en creation print ''; - // Code TVA intra + // Code TVA if ($conf->use_javascript) { print "\n"; @@ -526,7 +526,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print ''; print "\n"; } - print ''; + print ''; print ''; - // Code TVA intra + // Code TVA if ($conf->use_javascript) { print "\n"; print ''; print "\n"; } - print ''; + print ''; print '
'.$langs->trans('ProductsAndServices').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').'
'; // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index d985743f310..4194e7c6b01 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -141,7 +141,7 @@ if ($_GET["id"] > 0) { if ($commande->statut > 0) { - print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); } else { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 2d92fe2a23a..00a073d5779 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -728,6 +728,11 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && { $fac = new Facture($db); $ret=$fac->fetch($_POST['facid']); + if ($ret < 0) + { + dolibarr_print_error($db,$fac->error); + exit; + } $ret=$fac->fetch_client(); $date_start=''; @@ -768,21 +773,36 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); - $price_base_type = $prod->price_base_type; + $tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx); - // multiprix + // On defini prix unitaire if ($conf->global->PRODUIT_MULTIPRICES == 1) { - $pu = $prod->multiprices[$fac->client->price_level]; + $pu_ht = $prod->multiprices[$fac->client->price_level]; $pu_ttc = $prod->multiprices_ttc[$fac->client->price_level]; $price_base_type = $prod->multiprices_base_type[$fac->client->price_level]; } else { - $pu = $prod->price; + $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; + $price_base_type = $prod->price_base_type; } + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } + } + // La description de la ligne est celle saisie ou // celle du produit si PRODUIT_CHANGE_PROD_DESC défini if ($conf->global->PRODUIT_CHANGE_PROD_DESC) @@ -793,12 +813,10 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && { $desc=$_POST['np_desc']; } - - $tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx); } else { - $pu=$_POST['pu']; + $pu_ht=$_POST['pu']; $tva_tx=$_POST['tva_tx']; $desc=$_POST['np_desc']; } @@ -807,7 +825,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $result = $fac->addline( $_POST['facid'], $desc, - $pu, + $pu_ht, $_POST['qty'], $tva_tx, $_POST['idprod'], @@ -1637,14 +1655,14 @@ if ($_GET['action'] == 'create') } else { - /* *************************************************************************** */ - /* */ - /* Fiche en mode visu */ - /* */ - /* *************************************************************************** */ $id = $_GET['facid']; if ($id > 0) { + /* *************************************************************************** */ + /* */ + /* Fiche en mode visu / edition */ + /* */ + /* *************************************************************************** */ if ($mesg) print $mesg.'
'; $fac = New Facture($db); @@ -1652,6 +1670,8 @@ else { if ($user->societe_id>0 && $user->societe_id!=$fac->socid) accessforbidden('',0); + $result=$fac->fetch_client(); + $soc = new Societe($db, $fac->socid); $soc->fetch($fac->socid); $absolute_discount=$soc->getCurrentDiscount(); @@ -2391,9 +2411,9 @@ else print '
'; if(! $soc->tva_assuj) - print '0'; + print '0'; else - print $html->select_tva('tva_tx',$objp->tva_taux,$mysoc,$soc); + print $html->select_tva('tva_tx',$objp->tva_taux,$mysoc,$soc); print ''; @@ -2475,9 +2495,9 @@ else print ''; if($soc->tva_assuj == "0") - print '0'; + print '0'; else - $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); + $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); print '
'.$langs->trans('AmountHT').''.price($propal->price).''.price($propal->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($propal->total_tva).' '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."'.price($objp->total_ht)." 
 
'; + print ''; print ''; print ''; + print ''; print ''; print ''; - print $langs->trans('Month').' : ' . ''; - print ' '.$langs->trans('Year').' : ' . ''; + print ''; + print $langs->trans('Month').': '; + print ' '.$langs->trans('Year').': '; print ''; + print ''; print ''; print ''; - //print ''; + print ''; $html->select_propal_statut($viewstatut); print ''; + print ''; print '
".price($objp->price)."".price($objp->total_ht)."".$propalstatic->LibStatut($objp->fk_statut,5)." 
'.$langs->trans('VATIntraShort').''.$langs->trans('VATIntra').''; $s =''; $s.=''; @@ -806,18 +806,18 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print $form->selectyesno('assujtva_value',$soc->tva_assuj,1); print ''.$langs->trans('VATIntraShort').''.$langs->trans('VATIntra').''; $s =''; $s.=''; @@ -892,7 +892,8 @@ else print ''; } - print ''; + print ''; + print '
'; print ''; @@ -997,32 +998,49 @@ else // Assujeti TVA $html = new Form($db); print ''; - print ''; - print ''; + + // VAT Code + if ($conf->use_javascript) + { + print "\n"; + print ''; + print "\n"; + } + print ''; + + print ''; // Capital print ''; print '
'.$langs->trans('Name').''.$soc->nom.'
'; -/* Pas besoin de gérer l'icone "Modifier" car le champ est déja editable quand société en mode "Edit" - print '
'; - print $langs->trans('VATIsUsed'); - print ''; - if ($user->rights->societe->creer && $_GET['action'] != 'editassujtva') - print 'id.'">'.img_edit($langs->trans('SetMode')).''; - else - print ' '; - print '
'; - print '
'; - if($_GET['action'] == 'editassujtva') - print $html->form_assujetti_tva($_SERVER['PHP_SELF'].'?socid='.$soc->id,$soc->tva_assuj,'assujtva_value'); - else if($soc->tva_assuj == 1) - print 'oui'; - else - print 'non'; - print ''; -*/ print $langs->trans('VATIsUsed'); print ''; print yn($soc->tva_assuj); print ''.$langs->trans('VATIntraShort').''; - print $soc->tva_intra; - print '
'.$langs->trans('VATIntra').''; + if ($soc->tva_intra) + { + $s=''; + $code=substr($soc->tva_intra,0,2); + $num=substr($soc->tva_intra,2); + $s.=$soc->tva_intra; + $s.=''; + $s.=''; + $s.='   '; + if ($conf->use_javascript) + { + $s.=''.$langs->trans("VATIntraCheck").''; + print $form->textwithhelp($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1); + } + else + { + print $s.'id_pays).'" target="_blank" alt="'.$langs->trans("VATIntraCheckableOnEUSite").'">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').''; + } + } + else + { + print ' '; + } + print '
'.$langs->trans('Capital').''; @@ -1106,6 +1124,7 @@ else print '
'; + print ''; print "\n"; /* * diff --git a/mysql/migration/2.1.0-2.2.0.sql b/mysql/migration/2.1.0-2.2.0.sql index 156fbc6721c..6b9c309f42d 100644 --- a/mysql/migration/2.1.0-2.2.0.sql +++ b/mysql/migration/2.1.0-2.2.0.sql @@ -941,4 +941,6 @@ INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (9, 'A6', 'Format A6', '105', '148', 'mm', 1); ALTER TABLE llx_user ADD COLUMN phenix_login varchar(25) after webcal_login; -ALTER TABLE llx_user ADD COLUMN phenix_pass varchar(128) after phenix_login; \ No newline at end of file +ALTER TABLE llx_user ADD COLUMN phenix_pass varchar(128) after phenix_login; + +update llx_propal set total_ht = price where total_ht = 0 and total > 0; diff --git a/mysql/tables/llx_societe.sql b/mysql/tables/llx_societe.sql index ba1cb69dad8..848c1f20367 100644 --- a/mysql/tables/llx_societe.sql +++ b/mysql/tables/llx_societe.sql @@ -50,7 +50,7 @@ create table llx_societe siret varchar(16), -- IDProf2: siret pour france ape varchar(16), -- IDProf3: code ape pour france idprof4 varchar(16), -- IDProf4: nu pour france - tva_intra varchar(20), -- tva intracommunautaire + tva_intra varchar(20), -- tva capital real, -- capital de la société description text, -- fk_stcomm tinyint DEFAULT 0, -- commercial statut