New: Support save of NPR vat in order and invoice

This commit is contained in:
Laurent Destailleur 2008-03-18 23:24:24 +00:00
parent 17b633b776
commit 71186b44dc
7 changed files with 108 additions and 92 deletions

View File

@ -524,7 +524,8 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
$prod->fetch($_POST['idprod']);
$tva_tx = get_default_tva($mysoc,$propal->client,$prod->tva_tx);
$tva_npr = get_default_npr($mysoc,$propal->client,$prod->tva_tx);
// On defini prix unitaire
if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
@ -560,10 +561,15 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
else
{
$pu_ht=$_POST['np_price'];
$tva_tx=$_POST['np_tva_tx'];
$tva_tx=eregi_replace('\*','',$_POST['np_tva_tx']);
$tva_npr=eregi('\*',$_POST['np_tva_tx'])?1:0;
$desc=$_POST['dp_desc'];
}
$info_bit=0;
if ($tva_npr) $info_bit |= 0x01;
// Insert line
$result=$propal->addline(
$_POST['propalid'],
$desc,
@ -573,7 +579,8 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
$_POST['idprod'],
$_POST['remise_percent'],
$price_base_type,
$pu_ttc
$pu_ttc,
$info_bit
);
if ($result > 0)
@ -1212,7 +1219,7 @@ if ($_GET['propalid'] > 0)
}
// VAT Rate
print '<td align="right">'.vatrate($objp->tva_tx).'%</td>';
print '<td align="right">'.vatrate($objp->tva_tx,'%',$objp->info_bits).'</td>';
// U.P HT
print '<td align="right">'.price($objp->subprice)."</td>\n";
@ -1346,14 +1353,7 @@ if ($_GET['propalid'] > 0)
print '<td align="right">'.vatrate($objp->marge_tx).'%</td>';
}
print '<td align="right">';
if($societe->tva_assuj == "0")
{
print '<input type="hidden" name="tva_tx" value="0">0';
}
else
{
print $html->select_tva("tva_tx",$objp->tva_tx,$mysoc,$societe);
}
print $html->select_tva('tva_tx',$objp->tva_tx,$mysoc,$societe,'',$objp->info_bits);
print '</td>';
print '<td align="right"><input size="6" type="text" class="flat" name="subprice" value="'.price($objp->subprice,0,'',0).'"></td>';
print '<td align="right">';

View File

@ -26,14 +26,14 @@
/**
\class CommonObject
\brief Classe mere pour héritage des classes metiers
\brief Classe mere pour h<EFBFBD>ritage des classes metiers
*/
class CommonObject
{
/**
* \brief Ajoute un contact associé au l'entité finie dans $this->element
* \brief Ajoute un contact associ<EFBFBD> au l'entit<EFBFBD> d<EFBFBD>finie dans $this->element
* \param fk_socpeople Id du contact a ajouter
* \param type_contact Type de contact (code ou id)
* \param source external=Contact externe (llx_socpeople), internal=Contact interne (llx_user)
@ -45,7 +45,7 @@ class CommonObject
dolibarr_syslog("CommonObject::add_contact $fk_socpeople, $type_contact, $source");
// Vérification parametres
// V<EFBFBD>rification parametres
if ($fk_socpeople <= 0)
{
$this->error=$langs->trans("ErrorWrongValueForParameter","1");
@ -114,7 +114,7 @@ class CommonObject
/**
* \brief Mise a jour du statut d'un contact
* \param rowid La reference du lien contact-entité
* \param rowid La reference du lien contact-entit<EFBFBD>
* \param statut Le nouveau statut
* \param type_contact_id Description du type de contact
* \return int <0 si erreur, =0 si ok
@ -158,8 +158,8 @@ class CommonObject
}
/**
* \brief Récupère les lignes de contact de l'objet
* \param statut Statut des lignes detail à récupérer
* \brief R<EFBFBD>cup<EFBFBD>re les lignes de contact de l'objet
* \param statut Statut des lignes detail <EFBFBD> r<EFBFBD>cup<EFBFBD>rer
* \param source Source du contact external (llx_socpeople) ou internal (llx_user)
* \return array Tableau des rowid des contacts
*/
@ -214,7 +214,7 @@ class CommonObject
}
/**
* \brief Le détail d'un contact
* \brief Le d<EFBFBD>tail d'un contact
* \param rowid L'identifiant du contact
* \return object L'objet construit par DoliDb.fetch_object
*/
@ -224,7 +224,7 @@ class CommonObject
$sql.= " tc.code, tc.libelle,";
$sql.= " s.fk_soc";
$sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est lié à une societe
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est li<EFBFBD> <20> une societe
$sql.= " WHERE ec.rowid =".$rowid;
$sql.= " AND ec.fk_c_type_contact=tc.rowid";
$sql.= " AND tc.element = '".$this->element."'";
@ -285,7 +285,7 @@ class CommonObject
}
/**
* \brief Retourne id des contacts d'une source et d'un type actif donné
* \brief Retourne id des contacts d'une source et d'un type actif donn<EFBFBD>
* Exemple: contact client de facturation ('external', 'BILLING')
* Exemple: contact client de livraison ('external', 'SHIPPING')
* Exemple: contact interne suivi paiement ('internal', 'SALESREPFOLL')
@ -391,10 +391,10 @@ class CommonObject
}
/**
* \brief Retourne la liste déroulante des sociétés
* \brief Retourne la liste d<EFBFBD>roulante des soci<EFBFBD>t<EFBFBD>s
* \param object Fetch du document
* \param var_id Nom de la variable de l'id du document
* \param selected Societe présélectionnée
* \param selected Societe pr<EFBFBD>s<EFBFBD>lectionn<EFBFBD>e
* \param htmlname Nom champ formulaire
*/
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
@ -543,7 +543,7 @@ class CommonObject
/**
* \brief On récupère les id de liste_contact
* \brief On r<EFBFBD>cup<EFBFBD>re les id de liste_contact
* \param source Source du contact external (llx_socpeople) ou internal (llx_user)
* \return array
*/
@ -629,7 +629,7 @@ class CommonObject
/**
* \brief Stocke un numéro de rang pour toutes les lignes de
* \brief Stocke un num<EFBFBD>ro de rang pour toutes les lignes de
* detail d'une facture qui n'en ont pas.
*/
function line_order()
@ -856,7 +856,7 @@ class CommonObject
$obj = $this->db->fetch_object($resql);
$this->total_ht += $obj->total_ht;
$this->total_tva += ($obj->total_ttc - $obj->total_ht);
$this->total_tva += $obj->total_tva;
$this->total_ttc += $obj->total_ttc;
$i++;

View File

@ -828,7 +828,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
$info_bit=0;
if ($tva_npr) $info_bit |= 0x01;
// Insere ligne
// Insert line
$result = $fac->addline(
$_POST['facid'],
$desc,
@ -2407,7 +2407,7 @@ else
}
print "</td>\n";
}
print '<td align="right">'.vatrate($objp->tva_taux).'%'.($objp->info_bits & 1?' *':'').'</td>';
print '<td align="right">'.vatrate($objp->tva_taux,'%',$objp->info_bits).'</td>';
print '<td align="right">'.price($objp->subprice)."</td>\n";
print '<td align="right">';
if (($objp->info_bits & 2) != 2)

View File

@ -1290,7 +1290,7 @@ class Facture extends CommonObject
{
$this->db->begin();
// Nettoyage paramètres
// Clean parameters
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (! $qty) $qty=1;
@ -1336,7 +1336,7 @@ class Facture extends CommonObject
$product_type=$product->type;
}
// Insertion ligne
// Insert line
$ligne=new FactureLigne($this->db);
$ligne->fk_facture=$facid;

View File

@ -1823,18 +1823,28 @@ function print_fleche_navigation($page,$file,$options='',$nextpage,$betweenarrow
/**
* \brief Fonction qui retourne un taux de tva formaté pour visualisation
* \remarks Fonction utilisée dans les pdf et les pages html
* \param rate Taux a formater (19.6 19,6 19.6% 19,6%...)
* \return string Chaine avec montant formaté (19,6 ou 19,6%)
* \param rate Rate value to format (19.6 19,6 19.6% 19,6%,...)
* \param foundpercent Add a percent % sign in output
* \param info_bits Miscellanous information on vat
* \return string Chaine avec montant formaté (19,6 ou 19,6% ou 8.5% *)
*/
function vatrate($rate)
function vatrate($rate,$foundpercent=false,$info_bits=0)
{
$foundpercent=false;
// Test for compatibility
if (eregi('%',$rate))
{
$rate=eregi_replace('%','',$rate);
$foundpercent=true;
}
return price($rate,0,'',0,0).($foundpercent?'%':'');
if (eregi('\*',$rate))
{
$rate=eregi_replace('\*','',$rate);
$info_bits |= 1;
}
$ret=price($rate,0,'',0,0).($foundpercent?'%':'');
if ($info_bits & 1) $ret.=' *';
return $ret;
}

View File

@ -28,8 +28,8 @@
/**
\brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de
facture, propale, commande ou autre depuis:
quantité, prix unitaire, remise_percent_ligne, txtva, remise_percent_global
\param qty Quantité
quantity, unit price, remise_percent_ligne, txtva, remise_percent_global
\param qty Quantity
\param pu Prix unitaire (HT ou TTC selon price_base_type)
\param remise_percent_ligne Remise ligne
\param txtva Taux tva
@ -52,15 +52,17 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
$tot_avec_remise_ligne = $tot_sans_remise * ( 1 - ($remise_percent_ligne / 100));
$tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100));
$result[0] = price2num($tot_avec_remise, 'MT');
$result[2] = price2num($tot_avec_remise * ( 1 + ($txtva / 100)), 'MT');
$result[1] = $result[2] - $result[0];
$result[2] = price2num($tot_avec_remise * ( 1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result2bis= price2num($tot_avec_remise * ( 1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[1] = $result2bis - $result[0];
$result[3] = price2num($pu, 'MU');
$result[5] = price2num($pu * ( 1 + ($txtva / 100)), 'MU');
$result[4] = $result[5] - $result[3];
$result[5] = price2num($pu * ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
$result5bis= price2num($pu * ( 1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
$result[4] = $result5bis - $result[3];
}
else
{
// On cacule à l'envers en partant du prix TTC
// On cacule a l'envers en partant du prix TTC
// Utilise pour les produits a prix TTC reglemente (livres, ...)
$tot_sans_remise = $pu * $qty;
@ -68,11 +70,13 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
$tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100));
$result[2] = price2num($tot_avec_remise, 'MT');
$result[0] = price2num($tot_avec_remise / ( 1 + ($txtva / 100)), 'MT');
$result[1] = $result[2] - $result[0];
$result[0] = price2num($tot_avec_remise / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result0bis= price2num($tot_avec_remise / ( 1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[1] = $result[2] - $result0bis;
$result[5] = price2num($pu, 'MU');
$result[3] = price2num($pu / ( 1 + ($txtva / 100)), 'MU');
$result[4] = $result[5] - $result[3];
$result[3] = price2num($pu / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
$result3bis= price2num($pu / ( 1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
$result[4] = $result[5] - $result3bis;
}
return $result;

View File

@ -253,49 +253,50 @@ class Propal extends CommonObject
* \param remise_percent Pourcentage de remise de la ligne
* \param price_base_type HT or TTC
* \param pu_ttc Prix unitaire TTC
* \param info_bits Bits de type de lignes
* \return int >0 si ok, <0 si ko
* \see add_product
* \remarks Les parametres sont deja cens<EFBFBD> etre juste et avec valeurs finales a l'appel
* \remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete d<EFBFBD>fini
* 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_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0)
function addline($propalid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0)
{
global $conf;
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");
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, info_bits=$info_bits");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0)
{
$this->db->begin();
// Nettoyage param<61>tres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty)
{
$qty=0;
}
else if (! $qty)
{
$qty=1;
}
$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
$this->db->begin();
// Clean parameters
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty)
{
$qty=0;
}
else if (! $qty)
{
$qty=1;
}
$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
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
@ -314,7 +315,7 @@ class Propal extends CommonObject
$price = $pu - $remise;
}
// Insertion ligne
// Insert line
$ligne=new PropaleLigne($this->db);
$ligne->fk_propal=$propalid;
@ -343,16 +344,15 @@ class Propal extends CommonObject
{
// Mise a jour informations denormalisees au niveau de la propale meme
$result=$this->update_price();
if ($result > 0)
{
if ($result > 0)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -1;
}
@ -361,22 +361,23 @@ class Propal extends CommonObject
{
$this->error=$ligne->error;
$this->db->rollback();
return -2;
}
}
}
return -2;
}
}
}
/**
* \brief Mise <EFBFBD> jour d'une ligne de produit
* \brief Mise a jour d'une ligne de produit
* \param rowid Id de la ligne
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
* \param qty Quantit<EFBFBD>
* \param remise_percent Remise effectu<EFBFBD>e sur le produit
* \param qty Quantity
* \param remise_percent Remise effectuee sur le produit
* \param txtva Taux de TVA
* \param desc Description
* \param price_base_type HT ou TTC
* \return int 0 en cas de succ<EFBFBD>s
* \param info_bits Miscellanous informations
* \return int 0 en cas de succes
*/
function updateline($rowid, $pu, $qty, $remise_percent=0, $txtva, $desc='', $price_base_type='HT', $info_bits=0)
{
@ -431,6 +432,7 @@ class Propal extends CommonObject
$sql.= " , total_ht=".price2num($total_ht);
$sql.= " , total_tva=".price2num($total_tva);
$sql.= " , total_ttc=".price2num($total_ttc);
$sql.= " , info_bits=".$info_bits;
if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty)
{
$sql.= " , special_code=3";
@ -446,7 +448,7 @@ class Propal extends CommonObject
{
$this->update_price();
$this->db->commit();
return 0;
return $result;
}
else
{