';
+
+ // Ref
+ print ''.$langs->trans('Ref').' '.$propal->ref_url.' ';
+
+ // Ref client
+ print '';
+ print '';
+ print ' ';
+ if ($user->rights->propale->creer && $_GET['action'] == 'refclient')
+ {
+ print '';
+ }
+ else
+ {
+ print $propal->ref_client;
+ }
+ print ' ';
+ print ' ';
+
+ $rowspan=8;
+
+ // Société
+ print ''.$langs->trans('Company').' '.$societe->getNomUrl(1).' ';
+ print ' ';
+
+ // Ligne info remises tiers
+ print ''.$langs->trans('Discounts').' ';
+ if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client);
+ else print $langs->trans("CompanyHasNoRelativeDiscount");
+ $absolute_discount=$societe->getCurrentDiscount();
+ print '. ';
+ if ($absolute_discount)
+ {
+ print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
+ print '.';
+// print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id);
+ }
+ else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
+ print ' ';
+
+ // Dates
+ print ''.$langs->trans('Date').' ';
+ print dolibarr_print_date($propal->date,'%a %d %B %Y');
+ print ' ';
+
+ if ($conf->projet->enabled) $rowspan++;
+ if ($conf->global->PROPAL_ADD_SHIPPING_DATE) $rowspan++;
+ if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS) $rowspan++;
+
+ // Notes
+ print ''.$langs->trans('NotePublic').' : '. nl2br($propal->note_public).' ';
+ print ' ';
+
+ // Date fin propal
+ print '';
+ print '';
+ print '';
+ print ' ';
+ if ($propal->brouillon && $_GET['action'] == 'editecheance')
+ {
+ print '';
+ }
+ else
+ {
+ if ($propal->fin_validite)
+ {
+ print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y');
+ if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
+ }
+ else
+ {
+ print ' ';
+ }
+ }
+ print ' ';
+ print ' ';
+
+
+ // date de livraison (conditonné sur PROPAL_ADD_SHIPPING_DATE car carac à
+ // gérer par les commandes et non les propal
+ if ($conf->global->PROPAL_ADD_SHIPPING_DATE)
+ {
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editdate_livraison')
+ {
+ print '';
+ }
+ else
+ {
+ print dolibarr_print_date($propal->date_livraison,'%a %d %B %Y');
+ }
+ print ' ';
+ print ' ';
+ }
+
+ // adresse de livraison
+ if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS)
+ {
+ print '';
+ print '';
+ print ' ';
+
+ if ($_GET['action'] == 'editdelivery_adress')
+ {
+ $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'adresse_livraison_id','propal',$propal->id);
+ }
+ else
+ {
+ $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'none','propal',$propal->id);
+ }
+ print ' ';
+ }
+
+ // Conditions et modes de réglement
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editconditions')
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id');
+ }
+ else
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none');
+ }
+ print ' ';
+ print ' ';
+
+ // Mode paiement
+ print '';
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editmode')
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id');
+ }
+ else
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none');
+ }
+ print ' ';
+
+ // Destinataire
+/* On gère les contacts sur onglet contact
+ $langs->load('mails');
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editcontact')
+ {
+ $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'contactidp');
+ }
+ else
+ {
+ $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none');
+ }
+ print ' ';
+ print ' ';
+*/
+
+ // Projet
+ if ($conf->projet->enabled)
+ {
+ $langs->load("projects");
+ print ''.$langs->trans('Project').' ';
+ $numprojet = $societe->has_projects();
+ if (! $numprojet)
+ {
+ print '';
+ print $langs->trans("NoProject").' ';
+ print 'id.'&action=create>'.$langs->trans('AddProject').' ';
+ print ' ';
+ }
+ else
+ {
+ if ($propal->statut == 0 && $user->rights->propale->creer)
+ {
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print ' ';
+ }
+ else
+ {
+ if (!empty($propal->projetidp))
+ {
+ print '';
+ $proj = new Project($db);
+ $proj->fetch($propal->projetidp);
+ print '';
+ print $proj->title;
+ print ' ';
+ print ' ';
+ }
+ else {
+ print ' ';
+ }
+ }
+ }
+ print ' ';
+ }
+
+ // Amount
+ print ''.$langs->trans('AmountHT').' ';
+ print ''.price($propal->price).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+
+ print ''.$langs->trans('AmountVAT').' '.price($propal->total_tva).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+ print ''.$langs->trans('AmountTTC').' '.price($propal->total_ttc).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+
+ // Statut
+ print ''.$langs->trans('Status').' '.$propal->getLibStatut(4).' ';
+ print '
';
+
+ $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice,';
+ $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,';
+ $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';
+ $sql.= ' WHERE pt.fk_propal = '.$propal->id;
+ $sql.= ' ORDER BY pt.rang ASC, pt.rowid';
$resql = $db->query($sql);
if ($resql)
{
- if ($db->num_rows($resql))
+ $num = $db->num_rows($resql);
+ $i = 0; $total = 0;
+
+ if ($num)
{
- $obj = $db->fetch_object($resql);
-
- $societe = new Societe($db);
- $societe->fetch($obj->idp);
-
- print '';
-
- // Ref
- print ''.$langs->trans('Ref').' '.$propal->ref_url.' ';
-
- // Ref client
- print '';
- print '';
- print ' ';
- if ($user->rights->propale->creer && $_GET['action'] == 'refclient')
- {
- print '';
- }
- else
- {
- print $propal->ref_client;
- }
- print ' ';
- print ' ';
-
- $rowspan=9;
-
- // Société
- print ''.$langs->trans('Company').' '.$societe->getNomUrl(1).' ';
- print ' ';
-
- // Ligne info remises tiers
- print ''.$langs->trans('Discounts').' ';
- if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- $absolute_discount=$societe->getCurrentDiscount();
- print '. ';
- if ($absolute_discount)
- {
- print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
- print '.';
-// print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id);
- }
- else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
- print ' ';
-
- // Dates
- print ''.$langs->trans('Date').' ';
- print dolibarr_print_date($propal->date,'%a %d %B %Y');
- print ' ';
-
- if ($conf->projet->enabled) $rowspan++;
- if ($conf->global->PROPAL_ADD_SHIPPING_DATE) $rowspan++;
- if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS) $rowspan++;
-
- // Notes
- print ''.$langs->trans('NotePublic').' : '. nl2br($propal->note_public).' ';
- print ' ';
-
- // Date fin propal
- print '';
- print '';
- print '';
- print ' ';
- if ($propal->brouillon && $_GET['action'] == 'editecheance')
- {
- print '';
- }
- else
- {
- if ($propal->fin_validite)
- {
- print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y');
- if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
- }
- else
- {
- print ' ';
- }
- }
- print ' ';
- print ' ';
-
-
- // date de livraison (conditonné sur PROPAL_ADD_SHIPPING_DATE car carac à
- // gérer par les commandes et non les propal
- if ($conf->global->PROPAL_ADD_SHIPPING_DATE)
- {
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editdate_livraison')
- {
- print '';
- }
- else
- {
- print dolibarr_print_date($propal->date_livraison,'%a %d %B %Y');
- }
- print ' ';
- print ' ';
- }
-
- // adresse de livraison
- if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS)
- {
- print '';
- print '';
- print ' ';
-
- if ($_GET['action'] == 'editdelivery_adress')
- {
- $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'adresse_livraison_id','propal',$propal->id);
- }
- else
- {
- $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'none','propal',$propal->id);
- }
- print ' ';
- }
-
- // Conditions et modes de réglement
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editconditions')
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id');
- }
- else
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none');
- }
- print ' ';
- print ' ';
-
- // Mode paiement
- print '';
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editmode')
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id');
- }
- else
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none');
- }
- print ' ';
-
- // Destinataire
- $langs->load('mails');
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editcontact')
- {
- $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'contactidp');
- }
- else
- {
- $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none');
- }
- print ' ';
- print ' ';
-
- // Projet
- if ($conf->projet->enabled)
- {
- $langs->load("projects");
- print ''.$langs->trans('Project').' ';
- $numprojet = $societe->has_projects();
- if (! $numprojet)
- {
- print '';
- print $langs->trans("NoProject").' ';
- print 'id.'&action=create>'.$langs->trans('AddProject').' ';
- print ' ';
- }
- else
- {
- if ($propal->statut == 0 && $user->rights->propale->creer)
- {
- print '';
- print ' ';
- print ' ';
- print '';
- print ' ';
- }
- else
- {
- if (!empty($propal->projetidp))
- {
- print '';
- $proj = new Project($db);
- $proj->fetch($propal->projetidp);
- print '';
- print $proj->title;
- print ' ';
- print ' ';
- }
- else {
- print ' ';
- }
- }
- }
- print ' ';
- }
-
- // Amount
- print ''.$langs->trans('AmountHT').' ';
- print ''.price($propal->price).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
-
- print ''.$langs->trans('AmountVAT').' '.price($propal->total_tva).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
- print ''.$langs->trans('AmountTTC').' '.price($propal->total_ttc).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
-
- // Statut
- print ''.$langs->trans('Status').' '.$propal->getLibStatut(4).' ';
- print '
';
-
- /*
- * Lignes de propale
- */
- print '';
-
- $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice,';
- $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,';
- $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';
- $sql.= ' WHERE pt.fk_propal = '.$propal->id;
- $sql.= ' ORDER BY pt.rang ASC, pt.rowid';
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0; $total = 0;
-
- if ($num)
- {
- print '';
- print ''.$langs->trans('Description').' ';
- print ''.$langs->trans('VAT').' ';
- print ''.$langs->trans('PriceUHT').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('ReductionShort').' ';
- print ''.$langs->trans('AmountHT').' ';
- print ' ';
- print ' ';
- print ' ';
- print " \n";
- }
- $var=true;
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
- $var=!$var;
-
- // Ligne en mode visu
- if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid)
- {
- print '';
- if ($objp->fk_product > 0)
- {
- print '';
- if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
- else print img_object($langs->trans('ShowProduct'),'product');
- print ' '.$objp->ref.' ';
- print ' - '.nl2br(stripslashes($objp->product));
-
- if ($conf->global->PROP_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC)
- {
- print ' '.nl2br(stripslashes($objp->product_desc));
- }
-
- if ($objp->date_start && $objp->date_end)
- {
- print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
- }
- if ($objp->date_start && ! $objp->date_end)
- {
- print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
- }
- if (! $objp->date_start && $objp->date_end)
- {
- print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
- }
- print ($objp->description && $objp->description!=$objp->product)?' '.stripslashes(nl2br($objp->description)):'';
- print ' ';
- }
- else
- {
- print ''.stripslashes(nl2br($objp->description));
- if ($objp->date_start && $objp->date_end)
- {
- print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
- }
- if ($objp->date_start && ! $objp->date_end)
- {
- print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
- }
- if (! $objp->date_start && $objp->date_end)
- {
- print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
- }
- print " \n";
- }
- print ''.$objp->tva_tx.'% ';
- print ''.price($objp->subprice)." \n";
- print ''.$objp->qty.' ';
- if ($objp->remise_percent > 0)
- {
- print ''.$objp->remise_percent."% \n";
- }
- else
- {
- print ' ';
- }
- print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." \n";
-
- // Icone d'edition et suppression
- if ($propal->statut == 0 && $user->rights->propale->creer)
- {
- print 'id.'&action=editline&ligne='.$objp->rowid.'">';
- print img_edit();
- print ' ';
- if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE)
- {
- print 'id.'&action=delete_product_line&ligne='.$objp->rowid.'">';
- }
- else
- {
- print ' id.'&action=del_ligne&ligne='.$objp->rowid.'">';
- }
- print img_delete();
- print ' ';
- print '';
- if ($i > 0)
- {
- print 'id.'&action=up&rowid='.$objp->rowid.'">';
- print img_up();
- print ' ';
- }
- if ($i < $num-1)
- {
- print 'id.'&action=down&rowid='.$objp->rowid.'">';
- print img_down();
- print ' ';
- }
- print ' ';
- }
- else
- {
- print ' ';
- }
-
- print ' ';
- }
-
- // Ligne en mode update
- if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid)
- {
- print '\n";
- }
-
- $total = $total + ($objp->qty * $objp->price);
- $i++;
- }
-
- $db->free($resql);
- }
- else
- {
- dolibarr_print_error($db);
- }
-
-
- /*
- * Lignes de remise
- */
-
- // Réductions relatives (Remises-Ristournes-Rabbais)
- /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
- $var=!$var;
- print '';
- print ' ';
- print ' ';
- print '';
- print $langs->trans('CustomerRelativeDiscount');
- if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).') ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print '';
- if ($_GET['action'] == 'editrelativediscount')
- {
- print ' %';
- }
- else
- {
- print $propal->remise_percent?$propal->remise_percent.'%':' ';
- }
- print ' ';
- print '';
- if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone");
- else print ' ';
- print ' ';
- if ($_GET['action'] != 'editrelativediscount')
- {
- if ($propal->brouillon && $user->rights->propale->creer)
- {
- print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' ';
- }
- else
- {
- print ' ';
- }
- if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent)
- {
- print 'id.'&action=setremisepercent&rowid='.$objp->rowid.'">';
- print img_delete();
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- print ' ';
- */
-
- // Réductions absolues (Remises-Ristournes-Rabbais)
- /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
- $var=!$var;
- print '';
- print ' ';
- print ' ';
- print '';
- print $langs->trans('CustomerAbsoluteDiscount');
- if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).') ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print '';
- if ($_GET['action'] == 'editabsolutediscount')
- {
- print '- ';
- }
- else
- {
- print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone");
- }
- print ' ';
- if ($_GET['action'] != 'editabsolutediscount')
- {
- if ($propal->brouillon && $user->rights->propale->creer)
- {
- print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' ';
- }
- else
- {
- print ' ';
- }
- if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue)
- {
- print 'id.'&action=setremiseabsolue&rowid='.$objp->rowid.'">';
- print img_delete();
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- }
- else
- {
- print ' ';
- }
- print ' ';
- print ' ';
- */
-
- /*
- * Ajouter une ligne
- */
- if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline')
- {
- print '';
- print ''.$langs->trans('Description').' ';
- print ''.$langs->trans('VAT').' ';
- print ''.$langs->trans('PriceUHT').' ';
- print ''.$langs->trans('Qty').' ';
- print ''.$langs->trans('ReductionShort').' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print " \n";
-
- // Ajout produit produits/services personalisés
- print 'id.'" method="post">';
- print ' ';
- print ' ';
-
- $var=true;
-
- print '\n";
- print ' ';
- print '';
- if($societe->tva_assuj == "0")
- {
- print ' 0';
- }
- else
- {
- $html->select_tva('np_tva_tx', $conf->defaulttx, $mysoc, $societe);
- }
- print " \n";
- print ' ';
- print ' ';
- print ' % ';
- print ' ';
- print ' ';
-
- print ' ';
-
- // Ajout de produits/services prédéfinis
- if ($conf->produit->enabled)
- {
- print 'id.'" method="post">';
- print ' ';
- print ' ';
-
- $var=!$var;
-
- print '';
- print '';
- // multiprix
- if($conf->global->PRODUIT_MULTIPRICES == 1)
- {
- $html->select_produits('','idprod','',$conf->produit->limit_size,$societe->price_level);
- }
- else
- {
- $html->select_produits('','idprod','',$conf->produit->limit_size);
- }
- if (! $conf->use_ajax) print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' ';
- print ' % ';
-
- print ' ';
- print ' '."\n";
-
- print ' ';
- }
- }
-
- print '
';
+ print '';
+ print ''.$langs->trans('Description').' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('ReductionShort').' ';
+ print ''.$langs->trans('AmountHT').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print " \n";
}
+ $var=true;
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+ $var=!$var;
+
+ // Ligne en mode visu
+ if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid)
+ {
+ print '';
+ if ($objp->fk_product > 0)
+ {
+ print '';
+ if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
+ else print img_object($langs->trans('ShowProduct'),'product');
+ print ' '.$objp->ref.' ';
+ print ' - '.nl2br(stripslashes($objp->product));
+
+ if ($conf->global->PROP_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC)
+ {
+ print ' '.nl2br(stripslashes($objp->product_desc));
+ }
+
+ if ($objp->date_start && $objp->date_end)
+ {
+ print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
+ }
+ if ($objp->date_start && ! $objp->date_end)
+ {
+ print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
+ }
+ if (! $objp->date_start && $objp->date_end)
+ {
+ print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
+ }
+ print ($objp->description && $objp->description!=$objp->product)?' '.stripslashes(nl2br($objp->description)):'';
+ print ' ';
+ }
+ else
+ {
+ print ''.stripslashes(nl2br($objp->description));
+ if ($objp->date_start && $objp->date_end)
+ {
+ print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
+ }
+ if ($objp->date_start && ! $objp->date_end)
+ {
+ print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
+ }
+ if (! $objp->date_start && $objp->date_end)
+ {
+ print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
+ }
+ print " \n";
+ }
+ print ''.$objp->tva_tx.'% ';
+ print ''.price($objp->subprice)." \n";
+ print ''.$objp->qty.' ';
+ if ($objp->remise_percent > 0)
+ {
+ print ''.$objp->remise_percent."% \n";
+ }
+ else
+ {
+ print ' ';
+ }
+ print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." \n";
+
+ // Icone d'edition et suppression
+ if ($propal->statut == 0 && $user->rights->propale->creer)
+ {
+ print 'id.'&action=editline&ligne='.$objp->rowid.'">';
+ print img_edit();
+ print ' ';
+ if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE)
+ {
+ print 'id.'&action=delete_product_line&ligne='.$objp->rowid.'">';
+ }
+ else
+ {
+ print ' id.'&action=del_ligne&ligne='.$objp->rowid.'">';
+ }
+ print img_delete();
+ print ' ';
+ print '';
+ if ($i > 0)
+ {
+ print 'id.'&action=up&rowid='.$objp->rowid.'">';
+ print img_up();
+ print ' ';
+ }
+ if ($i < $num-1)
+ {
+ print 'id.'&action=down&rowid='.$objp->rowid.'">';
+ print img_down();
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+
+ print ' ';
+ }
+
+ // Ligne en mode update
+ if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid)
+ {
+ print 'id.'" method="post">';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ print '';
+ if ($objp->fk_product > 0)
+ {
+ print '';
+ if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service');
+ else print img_object($langs->trans('ShowProduct'),'product');
+ print ' '.$objp->ref.' ';
+ print ' - '.stripslashes(nl2br($objp->product));
+ print ' ';
+ }
+ print ''.stripslashes($objp->description).' ';
+ print '';
+ if($societe->tva_assuj == "0")
+ print ' 0';
+ else
+ print $html->select_tva("tva_tx",$objp->tva_tx,$mysoc,$societe);
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
+ print ' ';
+ print ' ' . "\n";
+ /*
+ if ($conf->service->enabled)
+ {
+ print "";
+ print 'Si produit de type service à durée limitée: Du ';
+ print $html->select_date($objp->date_start,"date_start",0,0,$objp->date_start?0:1);
+ print ' au ';
+ print $html->select_date($objp->date_end,"date_end",0,0,$objp->date_end?0:1);
+ print ' ';
+ print ' ' . "\n";
+ }
+ */
+ print " \n";
+ }
+
+ $total = $total + ($objp->qty * $objp->price);
+ $i++;
+ }
+
+ $db->free($resql);
}
else
{
dolibarr_print_error($db);
}
+
+ /*
+ * Lignes de remise
+ */
+
+ // Réductions relatives (Remises-Ristournes-Rabbais)
+ /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
+ $var=!$var;
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print $langs->trans('CustomerRelativeDiscount');
+ if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).') ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ if ($_GET['action'] == 'editrelativediscount')
+ {
+ print ' %';
+ }
+ else
+ {
+ print $propal->remise_percent?$propal->remise_percent.'%':' ';
+ }
+ print ' ';
+ print '';
+ if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone");
+ else print ' ';
+ print ' ';
+ if ($_GET['action'] != 'editrelativediscount')
+ {
+ if ($propal->brouillon && $user->rights->propale->creer)
+ {
+ print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent)
+ {
+ print 'id.'&action=setremisepercent&rowid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ print ' ';
+ */
+
+ // Réductions absolues (Remises-Ristournes-Rabbais)
+ /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
+ $var=!$var;
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print $langs->trans('CustomerAbsoluteDiscount');
+ if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).') ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ if ($_GET['action'] == 'editabsolutediscount')
+ {
+ print '- ';
+ }
+ else
+ {
+ print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone");
+ }
+ print ' ';
+ if ($_GET['action'] != 'editabsolutediscount')
+ {
+ if ($propal->brouillon && $user->rights->propale->creer)
+ {
+ print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue)
+ {
+ print 'id.'&action=setremiseabsolue&rowid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ print ' ';
+ */
+
+ /*
+ * Ajouter une ligne
+ */
+ if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline')
+ {
+ print '';
+ print ''.$langs->trans('Description').' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('ReductionShort').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print " \n";
+
+ // Ajout produit produits/services personalisés
+ print 'id.'" method="post">';
+ print ' ';
+ print ' ';
+
+ $var=true;
+
+ print '\n";
+ print ' ';
+ print '';
+ if($societe->tva_assuj == "0")
+ {
+ print ' 0';
+ }
+ else
+ {
+ $html->select_tva('np_tva_tx', $conf->defaulttx, $mysoc, $societe);
+ }
+ print " \n";
+ print ' ';
+ print ' ';
+ print ' % ';
+ print ' ';
+ print ' ';
+
+ print ' ';
+
+ // Ajout de produits/services prédéfinis
+ if ($conf->produit->enabled)
+ {
+ print 'id.'" method="post">';
+ print ' ';
+ print ' ';
+
+ $var=!$var;
+
+ print '';
+ print '';
+ // multiprix
+ if($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $html->select_produits('','idprod','',$conf->produit->limit_size,$societe->price_level);
+ }
+ else
+ {
+ $html->select_produits('','idprod','',$conf->produit->limit_size);
+ }
+ if (! $conf->use_ajax) print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' % ';
+
+ print ' ';
+ print ' '."\n";
+
+ print ' ';
+ }
+ }
+
+ print '
';
+
print '';
print "\n";
@@ -1274,6 +1253,7 @@ if ($_GET['propalid'] > 0)
print ''.$langs->trans("CloseAs").' ';
print ' ';
print '';
+ print ' ';
print ''.$propal->labelstatut[2].' ';
print ''.$propal->labelstatut[3].' ';
print ' ';
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index 927133cc80d..6974aa67dcd 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -2158,20 +2158,21 @@ class Commande
class CommandeLigne
{
- // From llx_propaldet
- var $qty;
- var $tva_tx;
- var $subprice;
- var $remise_percent;
- var $price;
- var $product_id;
- var $desc; // Description ligne
- var $coef;
+ // From llx_commandedet
+ var $qty;
+ var $tva_tx;
+ var $subprice;
+ var $remise_percent;
+ var $price;
+ var $product_id; // Id produit prédéfini
+ var $desc; // Description ligne
+ var $coef;
- // From llx_product
- var $libelle; // Label produit
- var $product_desc; // Description produit
- var $ref;
+ // From llx_product
+ var $libelle; // Label produit
+ var $product_desc; // Description produit
+ var $ref; // Reference produit
+
function CommandeLigne()
{
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index ab3b4549973..470bc069c46 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -242,12 +242,11 @@ if ($_POST['action'] == 'add')
{
for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++)
{
- $liblignefac=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle);
+ $desc=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle);
$result = $facture->addline(
$facid,
- addslashes($liblignefac),
- $prop->lignes[$i]->desc,
+ $desc,
$prop->lignes[$i]->subprice,
$prop->lignes[$i]->qty,
$prop->lignes[$i]->tva_tx,
@@ -281,10 +280,11 @@ if ($_POST['action'] == 'add')
$lines = $comm->fetch_lignes();
for ($i = 0 ; $i < sizeof($lines) ; $i++)
{
+ $desc=($lignes[$i]->description ? $lignes[$i]->description : $lignes[$i]->libelle);
+
$result = $facture->addline(
$facid,
- addslashes($lines[$i]->description),
- $lines[$i]->desc,
+ $desc,
$lines[$i]->subprice,
$lines[$i]->qty,
$lines[$i]->tva_tx,
@@ -319,7 +319,7 @@ if ($_POST['action'] == 'add')
for ($i = 0 ; $i < sizeof($lines) ; $i++)
{
- $liblignefac=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle);
+ $desc=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle);
// Plage de dates
$date_start=$contrat->lignes[$i]->date_debut_prevue;
@@ -329,8 +329,7 @@ if ($_POST['action'] == 'add')
$result = $facture->addline(
$facid,
- addslashes($liblignefac),
- '',
+ $desc,
$lines[$i]->subprice,
$lines[$i]->qty,
$lines[$i]->tva_tx,
@@ -367,6 +366,9 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
{
$fac = new Facture($db);
$fac->fetch($_POST['facid']);
+ $soc = new Societe($db);
+ $soc->fetch($fac->socidp);
+
$datestart='';
$dateend='';
// Si ajout champ produit libre
@@ -393,13 +395,42 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
$dateend=$_POST['date_end_predefyear'].'-'.$_POST['date_end_predefmonth'].'-'.$_POST['date_end_predefday'];
}
}
+
+ // Ecrase $pu par celui du produit
+ // Ecrase $desc par celui du produit
+ // Ecrase $txtva par celui du produit
+ if ($_POST['idprod'])
+ {
+ $prod = new Product($db, $_POST['idprod']);
+ $prod->fetch($_POST['idprod']);
+ // multiprix
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
+ {
+ $pu = $prod->multiprices[$soc->price_level];
+ }
+ else
+ {
+ $pu=$prod->price;
+ }
+ $desc=$_POST['desc'];
+ if (! $desc) $desc = $prod->description;
+ if ($conf->global->PRODUIT_CHANGE_PROD_DESC) $prod->description;
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
+ }
+ else
+ {
+ $pu=$_POST['pu'];
+ $tva_tx=$_POST['tva_tx'];
+ $desc=$_POST['desc'];
+ }
+
+ // Insere ligne
$result = $fac->addline(
$_POST['facid'],
- $_POST['desc'],
- $_POST['product_desc'],
- $_POST['pu'],
+ $desc,
+ $pu,
$_POST['qty'],
- $_POST['tva_tx'],
+ $tva_tx,
$_POST['idprod'],
$_POST['remise_percent'],
$datestart,
@@ -1933,7 +1964,7 @@ else
$html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level);
else
$html->select_produits('','idprod','',$conf->produit->limit_size);
- print ' ';
+ if (! $conf->use_ajax) print ' ';
print ' ';
print ' ';
print ' ';
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index f535d5daf6b..cc2c0187f29 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -118,430 +118,425 @@ $html = new Form($db);
*/
if ($_GET["propalid"] > 0)
{
- if ($mesg) print "$mesg ";
+ if ($mesg) print "$mesg ";
+
+ $propal = new Propal($db);
+ $propal->fetch($_GET['propalid']);
+
+ $societe = new Societe($db);
+ $societe->fetch($propal->soc_id);
- $propal = new Propal($db);
- $propal->fetch($_GET["propalid"]);
-
$head = propal_prepare_head($propal);
dolibarr_fiche_head($head, 'compta', $langs->trans('Proposal'));
-
+
/*
* Fiche propal
*
*/
- $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref,'.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst, p.note,';
- $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture, p.fk_cond_reglement, p.fk_mode_reglement';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c, '.MAIN_DB_PREFIX.'socpeople as x';
- $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND x.idp = p.fk_soc_contact AND p.rowid = '.$propal->id;
- if ($socidp) $sql .= ' AND s.idp = '.$socidp;
+ print '';
+
+ // Ref
+ print ''.$langs->trans('Ref').' '.$propal->ref_url.' ';
+
+ // Ref client
+ print '';
+ print '';
+ print ' ';
+ print $propal->ref_client;
+ print ' ';
+ print ' ';
+
+ $rowspan=8;
- $resql = $db->query($sql);
- if ($resql)
+ // Société
+ print ''.$langs->trans('Company').' '.$societe->getNomUrl(1).' ';
+
+ // Ligne info remises tiers
+ print ''.$langs->trans('Discounts').' ';
+ if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client);
+ else print $langs->trans("CompanyHasNoRelativeDiscount");
+ $absolute_discount=$societe->getCurrentDiscount();
+ print '. ';
+ if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
+ else print $langs->trans("CompanyHasNoAbsoluteDiscount");
+ print '.';
+ print ' ';
+
+ // Dates
+ print ''.$langs->trans('Date').' ';
+ print dolibarr_print_date($propal->date,'%a %d %B %Y');
+ print ' ';
+
+ if ($conf->projet->enabled) $rowspan++;
+
+ // Note
+ print ''.$langs->trans('NotePublic').' : '. nl2br($propal->note_public).' ';
+ print ' ';
+
+ // Date fin propal
+ print '';
+ print ''.$langs->trans('DateEndPropal').' ';
+ if ($propal->fin_validite)
{
- if ($db->num_rows($resql))
+ print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y');
+ if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
+ }
+ else
+ {
+ print $langs->trans("Unknown");
+ }
+ print ' ';
+ print ' ';
+
+ // Conditions et modes de réglement
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editconditions')
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id');
+ }
+ else
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none');
+ }
+ print ' ';
+
+ // Mode de paiement
+ print '';
+ print '';
+ print '';
+ print ' ';
+ if ($_GET['action'] == 'editmode')
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id');
+ }
+ else
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none');
+ }
+ print ' ';
+
+ // Destinataire
+/* Remplacé par contacts de propal
+ $langs->load('mails');
+ print '';
+ print ''.$langs->trans('MailTo').' ';
+
+ if ($propal->statut == 0 && $user->rights->propale->creer)
+ {
+ print '';
+ $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none');
+ print ' ';
+ }
+ else
+ {
+ if (!empty($propal->contactid))
{
- $obj = $db->fetch_object($resql);
-
- $societe = new Societe($db);
- $societe->fetch($obj->idp);
-
- print '';
-
- // Ref
- print ''.$langs->trans('Ref').' '.$propal->ref_url.' ';
-
- $rowspan=9;
-
- // Société
- print ''.$langs->trans('Company').' '.$societe->getNomUrl(1).' ';
-
- // Ligne info remises tiers
- print ''.$langs->trans('Discounts').' ';
- if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- $absolute_discount=$societe->getCurrentDiscount();
- print '. ';
- if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie));
- else print $langs->trans("CompanyHasNoAbsoluteDiscount");
- print '.';
- print ' ';
-
- // Dates
- print ''.$langs->trans('Date').' ';
- print dolibarr_print_date($propal->date,'%a %d %B %Y');
+ print ' ';
+ $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none');
print ' ';
-
- if ($conf->projet->enabled) $rowspan++;
-
- // Note
- print ''.$langs->trans('NotePublic').' : '. nl2br($propal->note_public).' ';
- print ' ';
-
- // Date fin propal
- print '';
- print ''.$langs->trans('DateEndPropal').' ';
- if ($propal->fin_validite)
- {
- print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y');
- if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
- }
- else
- {
- print $langs->trans("Unknown");
- }
+ }
+ else {
+ print ' ';
+ }
+ }
+*/
+
+ // Projet
+ if ($conf->projet->enabled)
+ {
+ $langs->load("projects");
+ print ' '.$langs->trans('Project').' ';
+ $numprojet = $societe->has_projects();
+ if (! $numprojet)
+ {
+ print '';
+ print $langs->trans("NoProject").' ';
+ print 'id.'&action=create>'.$langs->trans('AddProject').' ';
print ' ';
- print ' ';
-
- // Conditions et modes de réglement
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editconditions')
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id');
- }
- else
- {
- $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none');
- }
- print ' ';
-
- // Mode de paiement
- print '';
- print '';
- print '';
- print ' ';
- if ($_GET['action'] == 'editmode')
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id');
- }
- else
- {
- $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none');
- }
- print ' ';
-
- // Destinataire
- $langs->load('mails');
- print '';
- print ''.$langs->trans('MailTo').' ';
-
+ }
+ else
+ {
if ($propal->statut == 0 && $user->rights->propale->creer)
{
print '';
- $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none');
+ $html->select_projects($societe->id, $propal->projetidp, 'projetidp');
print ' ';
}
else
{
- if (!empty($propal->contactid))
+ if (!empty($propal->projetidp))
{
print '';
- $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none');
+ $proj = new Project($db);
+ $proj->fetch($propal->projetidp);
+ print '';
+ print $proj->title;
+ print ' ';
print ' ';
}
else {
print ' ';
}
}
-
- // Projet
- if ($conf->projet->enabled)
+ }
+ print ' ';
+ }
+
+ // Amount
+ print ''.$langs->trans('AmountHT').' ';
+ print ''.price($propal->price).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+
+ print ''.$langs->trans('AmountVAT').' '.price($propal->total_tva).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+ print ''.$langs->trans('AmountTTC').' '.price($propal->total_ttc).' ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' ';
+
+
+ // Statut
+ print ''.$langs->trans('Status').' '.$propal->getLibStatut(4).' ';
+ print '
';
+
+ /*
+ * Lignes de propale
+ *
+ */
+ $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
+ $sql .= ' WHERE pt.fk_propal = '.$propal->id;
+ $sql .= ' ORDER BY pt.rowid ASC';
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num_lignes = $db->num_rows($resql);
+ $i = 0;
+ $total = 0;
+
+ print '';
+ if ($num_lignes)
+ {
+ print '';
+ print ''.$langs->trans('Description').' ';
+ print ''.$langs->trans('VAT').' ';
+ print ''.$langs->trans('PriceUHT').' ';
+ print ''.$langs->trans('Qty').' ';
+ print ''.$langs->trans('Discount').' ';
+ print ''.$langs->trans('AmountHT').' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print " \n";
+ }
+ $var=true;
+ while ($i < $num_lignes)
+ {
+ $objp = $db->fetch_object($resql);
+ $var=!$var;
+ if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid)
{
- $langs->load("projects");
- print ''.$langs->trans('Project').' ';
- $numprojet = $societe->has_projects();
- if (! $numprojet)
+ print '';
+ if ($objp->fk_product > 0)
{
- print '';
- print $langs->trans("NoProject").' ';
- print 'id.'&action=create>'.$langs->trans('AddProject').' ';
+ print ' ';
+ if ($objp->fk_product_type)
+ print img_object($langs->trans('ShowService'),'service');
+ else
+ print img_object($langs->trans('ShowProduct'),'product');
+ print ' '.$objp->ref.' - '.stripslashes(nl2br($objp->product));
+ if ($objp->date_start && $objp->date_end)
+ {
+ print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
+ }
+ if ($objp->date_start && ! $objp->date_end)
+ {
+ print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
+ }
+ if (! $objp->date_start && $objp->date_end)
+ {
+ print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
+ }
+ print ($objp->description && $objp->description!=$objp->product)?' '.stripslashes(nl2br($objp->description)):'';
print ' ';
}
else
{
- if ($propal->statut == 0 && $user->rights->propale->creer)
+ print ''.stripslashes(nl2br($objp->description));
+ if ($objp->date_start && $objp->date_end)
{
- print ' ';
- $html->select_projects($societe->id, $propal->projetidp, 'projetidp');
- print ' ';
+ print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
}
- else
+ if ($objp->date_start && ! $objp->date_end)
{
- if (!empty($propal->projetidp))
- {
- print '';
- $proj = new Project($db);
- $proj->fetch($propal->projetidp);
- print '';
- print $proj->title;
- print ' ';
- print ' ';
- }
- else {
- print ' ';
- }
+ print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
}
+ if (! $objp->date_start && $objp->date_end)
+ {
+ print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
+ }
+ print "\n";
}
+ print ''.$objp->tva_tx.'% ';
+ print ''.price($objp->subprice)." \n";
+ print ''.$objp->qty.' ';
+ if ($objp->remise_percent > 0)
+ {
+ print ''.$objp->remise_percent."% \n";
+ }
+ else
+ {
+ print ' ';
+ }
+ print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." \n";
+
+ print ' ';
+
print ' ';
}
-
- // Amount
- print ''.$langs->trans('AmountHT').' ';
- print ''.price($propal->price).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
-
- print ''.$langs->trans('AmountVAT').' '.price($propal->total_tva).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
- print ''.$langs->trans('AmountTTC').' '.price($propal->total_ttc).' ';
- print ''.$langs->trans("Currency".$conf->monnaie).' ';
- // Statut
- print ''.$langs->trans('Status').' '.$propal->getLibStatut(4).' ';
- print '
';
-
- /*
- * Lignes de propale
- *
- */
- $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
- $sql .= ' WHERE pt.fk_propal = '.$propal->id;
- $sql .= ' ORDER BY pt.rowid ASC';
- $resql = $db->query($sql);
- if ($resql)
- {
- $num_lignes = $db->num_rows($resql);
- $i = 0;
- $total = 0;
-
- print '';
-
+ $total = $total + ($objp->qty * $objp->price);
+ $i++;
}
+ $db->free($resql);
}
else
{
dolibarr_print_error($db);
}
+
+ /*
+ * Lignes de remise
+ */
+
+ // Réductions relatives (Remises-Ristournes-Rabbais)
+/* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
+et non globalement
+ $var=!$var;
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print $langs->trans('CustomerRelativeDiscount');
+ if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).') ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ if ($_GET['action'] == 'editrelativediscount')
+ {
+ print ' %';
+ }
+ else
+ {
+ print $propal->remise_percent?$propal->remise_percent.'%':' ';
+ }
+ print ' ';
+ print '';
+ if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone");
+ else print ' ';
+ print ' ';
+ if ($_GET['action'] != 'editrelativediscount')
+ {
+ if ($propal->brouillon && $user->rights->propale->creer)
+ {
+ print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent)
+ {
+ print 'id.'&action=setremisepercent&rowid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ print ' ';
+*/
+
+ // Remise absolue
+/* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
+ $var=!$var;
+ print '';
+ print ' ';
+ print ' ';
+ print '';
+ print $langs->trans('CustomerAbsoluteDiscount');
+ if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).') ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print '';
+ if ($_GET['action'] == 'editabsolutediscount')
+ {
+ print '- ';
+ }
+ else
+ {
+ print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone");
+ }
+ print ' ';
+ if ($_GET['action'] != 'editabsolutediscount')
+ {
+ if ($propal->brouillon && $user->rights->propale->creer)
+ {
+ print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue)
+ {
+ print 'id.'&action=setremiseabsolue&rowid='.$objp->rowid.'">';
+ print img_delete();
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' ';
+ print ' ';
+*/
+ print '
';
+
print '';
@@ -688,7 +683,7 @@ if ($_GET["propalid"] > 0)
*/
$sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ;
$sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
- $sql .= ' WHERE a.fk_soc = '.$obj->idp.' AND a.propalrowid = '.$propal->id ;
+ $sql .= ' WHERE a.fk_soc = '.$societe->id.' AND a.propalrowid = '.$propal->id ;
$resql = $db->query($sql);
if ($resql)
{
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 3c0cab25658..dbf211e284c 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -107,7 +107,7 @@ class Facture
*/
function create($user)
{
- global $langs,$conf;
+ global $langs,$conf,$mysoc;
$this->db->begin();
@@ -198,10 +198,7 @@ class Facture
$res=$prod->fetch($this->products[$i]);
$soc = new Societe($this->db);
$soc->fetch($this->socidp);
- if($soc->tva_assuj == "0")
- $tva_tx ="0";
- else
- $tva_tx=$prod->tva_tx;
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
$price = $prod->multiprices[$soc->price_level];
@@ -239,8 +236,9 @@ class Facture
if ($_facrec->lignes[$i]->produit_id)
{
$prod = new Product($this->db, $_facrec->lignes[$i]->produit_id);
- $prod->fetch($_facrec->lignes[$i]->produit_id);
+ $res=$prod->fetch($_facrec->lignes[$i]->produit_id);
}
+ $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
$result_insert = $this->addline(
$this->id,
@@ -400,7 +398,7 @@ class Facture
*/
$sql = 'SELECT l.rowid, l.fk_product, l.description, l.price, l.qty, l.tva_taux, l.remise, l.remise_percent, l.subprice,';
$sql.= ' '.$this->db->pdate('l.date_start').' as date_start,'.$this->db->pdate('l.date_end').' as date_end,';
- $sql.= ' l.info_bits, l.total_ht, l.total_ttc,';
+ $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
$sql.= ' p.label as label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
@@ -432,6 +430,7 @@ class Facture
$faclig->date_end = $objp->date_end;
$faclig->info_bits = $objp->info_bits;
$faclig->total_ht = $objp->total_ht;
+ $faclig->total_tva = $objp->total_tva;
$faclig->total_ttc = $objp->total_ttc;
$this->lignes[$i] = $faclig;
$i++;
@@ -996,23 +995,23 @@ class Facture
}
/**
- * \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non)
- * \param facid id de la facture
- * \param desc description de la ligne
- * \param product_desc surcharge description produit
- * \param pu prix unitaire
- * \param qty quantit
- * \param txtva taux de tva
- * \param fk_product id du produit/service predéfini
- * \param remise_percent pourcentage de remise de la ligne
- * \param datestart date de debut de validité du service
- * \param dateend date de fin de validité du service
- * \param ventil code de ventilation comptable
- * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
- * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini
- * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
- */
- function addline($facid, $desc, $product_desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart='', $dateend='', $ventil = 0)
+ * \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non)
+ * \param facid id de la facture
+ * \param desc description de la ligne
+ * \param pu 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 datestart date de debut de validité du service
+ * \param dateend date de fin de validité du service
+ * \param ventil code de ventilation comptable
+ * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
+ * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete dé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($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart='', $dateend='', $ventil = 0)
{
global $conf;
dolibarr_syslog("facture.class.php::addline($facid,$desc,$product_desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$datestart,$dateend,$ventil)");
@@ -1028,19 +1027,6 @@ class Facture
if (! $qty) $qty=1;
if (! $ventil) $ventil=0;
if (! $info_bits) $info_bits=0;
- if ($fk_product && ! $pu)
- {
- $prod = new Product($this->db, $fk_product);
- $prod->fetch($fk_product);
- $product_desc = $prod->description;
- // multiprix
- if($conf->global->PRODUIT_MULTIPRICES == 1)
- $pu = $prod->multiprices[$soc->price_level];
- else
- {
- $pu=$prod->price;
- }
- }
$pu = price2num($pu);
$txtva=price2num($txtva);
@@ -1082,34 +1068,15 @@ class Facture
return -1;
}
- if ($conf->global->PRODUIT_CHANGE_PROD_DESC)
- {
- if (!$product_desc)
- {
- $product_desc = $desc;
- }
- }
-
// Insertion dans base de la ligne
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' (fk_facture, description, price, qty, tva_taux,';
$sql.= ' fk_product, remise_percent, subprice, remise, date_start, date_end, fk_code_ventilation, rang,';
$sql.= ' info_bits, total_ht, total_tva, total_ttc)';
- if ($conf->global->PRODUIT_CHANGE_PROD_DESC)
- {
- $sql.= " VALUES ($facid, '".addslashes($product_desc)."',";
- $sql.= "'".price2num($price)."',";
- $sql.= "'".price2num($qty)."',";
- $sql.= "'".price2num($txtva)."',";
- }
- else
- {
- $sql.= " VALUES ($facid, '".addslashes($desc)."',";
- $sql.= "'".price2num($price)."',";
- $sql.= "'".price2num($qty)."',";
- $sql.= "'".price2num($txtva)."',";
- }
-
+ $sql.= " VALUES (".$facid.", '".addslashes($desc)."',";
+ $sql.= "'".price2num($price)."',";
+ $sql.= "'".price2num($qty)."',";
+ $sql.= "'".price2num($txtva)."',";
if ($fk_product) { $sql.= "'$fk_product',"; }
else { $sql.='0,'; }
$sql.= " '".price2num($remise_percent)."',";
@@ -1265,7 +1232,7 @@ class Facture
$err=0;
// Lit les lignes detail
- $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price, total_ht, total_ttc';
+ $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price, total_ht, total_tva, total_ttc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' WHERE fk_facture = '.$facid;
$result = $this->db->query($sql);
diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang
index c9cc7368409..8be1b641e62 100644
--- a/htdocs/langs/en_US/companies.lang
+++ b/htdocs/langs/en_US/companies.lang
@@ -89,6 +89,7 @@ Supplier=Supplier
CompanyList=Companies' list
AddContact=Add contact
Contact=Contact
+DefaultContact=Default contact
AddCompany=Add company
DeleteACompany=Delete a company
PersonalInformations=Personal data
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index c9319ed0ca6..12edb91a364 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -104,6 +104,7 @@ Family=Family
Description=Description
Designation=Description
Model=Model
+DefaultModel=Default model
Action=Action
About=About
WelcomeString=We are %s, and you are connected as user %s
diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang
index 72b79a6bbd9..4c6fee2c102 100644
--- a/htdocs/langs/fr_FR/companies.lang
+++ b/htdocs/langs/fr_FR/companies.lang
@@ -89,6 +89,7 @@ Supplier=Fournisseur
CompanyList=Liste des sociétés
AddContact=Créer contact
Contact=Contact
+DefaultContact=Contact par défaut
AddCompany=Créer société
DeleteACompany=Supprimer une société
PersonalInformations=Informations personnelles
diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang
index 2786338e49c..3e4a0264f9d 100644
--- a/htdocs/langs/fr_FR/main.lang
+++ b/htdocs/langs/fr_FR/main.lang
@@ -104,6 +104,7 @@ Description=Description
Designation=Désignation
Action=Action
Model=Modèle
+DefaultModel=Modèle par défaut
About=À propos
WelcomeString=Nous sommes le %s, et vous êtes connecté(e) en tant que %s
Number=Nombre
diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php
index 1802ef57120..065ba484649 100644
--- a/htdocs/lib/functions.inc.php
+++ b/htdocs/lib/functions.inc.php
@@ -1702,10 +1702,13 @@ function price2num($amount)
* \param taux_produit Taux par defaut du produit vendu
* \return float Taux de tva de la ligne
*/
-function get_default_tva($societe_vendeuse='', $societe_acheteuse='', $taux_produit='')
+function get_default_tva($societe_vendeuse, $societe_acheteuse, $taux_produit)
{
- // Si vendeur non assujeti à TVA
- if (! $societe_vendeuse->tva_assuj) return 0;
+ 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");
+
+ // 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;
+ if (! is_numeric($societe_vendeuse->tva_assuj) && $societe_vendeuse->tva_assuj=='franchise') return 0;
// Si le (pays vendeur = pays acheteur) alors la TVA par défaut=TVA du produit vendu. Fin de règle.
if ($societe_vendeuse->pays_id == $societe_acheteuse->pays_id)
diff --git a/htdocs/lib/price.lib.php b/htdocs/lib/price.lib.php
index d583f0b2c42..f868f45e667 100644
--- a/htdocs/lib/price.lib.php
+++ b/htdocs/lib/price.lib.php
@@ -33,22 +33,25 @@
/**
\brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de
- facture, propale ou autre depuis son prix unitaire, quantité et remise ligne.
+ facture, propale ou autre depuis:
+ Prix unitaire, quantité, remise_percent_ligne, txtva, remise_percent_global.
\param qty
\param pu
- \param remise_percent
+ \param remise_percent_ligne
\param txtva
+ \param remise_percent_global
\return result[0] total_ht
result[1] total_tva
result[2] total_ttc
*/
-function calcul_price_total($qty, $pu, $remise_percent, $txtva)
+function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_percent_global=0)
{
$result=array();
$tot_sans_remise = $pu * $qty;
- $tot_avec_remise = $tot_sans_remise - ($tot_sans_remise * $remise_percent / 100);
+ $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] = round($tot_avec_remise, 2);
- $result[2] = round($tot_avec_remise + ($tot_avec_remise * $txtva / 100), 2);
+ $result[2] = round($tot_avec_remise * ( 1 + ($txtva / 100)), 2);
$result[1] = $result[2] - $result[0];
return $result;
}
diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php
index 067c0f145c9..0ea01714d42 100644
--- a/htdocs/master.inc.php
+++ b/htdocs/master.inc.php
@@ -174,7 +174,27 @@ $mysoc->nom=$conf->global->MAIN_INFO_SOCIETE_NOM;
$mysoc->adresse=$conf->global->MAIN_INFO_SOCIETE_ADRESSE;
$mysoc->cp=$conf->global->MAIN_INFO_SOCIETE_CP;
$mysoc->ville=$conf->global->MAIN_INFO_SOCIETE_VILLE;
-$mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS;
+// Si dans MAIN_INFO_SOCIETE_PAYS on a un id de pays, on recupere code
+if (is_numeric($conf->global->MAIN_INFO_SOCIETE_PAYS))
+{
+ $mysoc->pays_id=$conf->global->MAIN_INFO_SOCIETE_PAYS;
+ $sql = "SELECT code from ".MAIN_DB_PREFIX."c_pays";
+ $sql .= " WHERE rowid = ".$conf->global->MAIN_INFO_SOCIETE_PAYS;
+ $result=$db->query($sql);
+ if ($result)
+ {
+ $obj = $db->fetch_object();
+ $mysoc->pays_code=$obj->code;
+ }
+ else {
+ dolibarr_print_error($db);
+ }
+}
+// Si dans MAIN_INFO_SOCIETE_PAYS on a deja un code, tout est fait
+else
+{
+ $mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS;
+}
$mysoc->tel=$conf->global->MAIN_INFO_SOCIETE_TEL;
$mysoc->fax=$conf->global->MAIN_INFO_SOCIETE_FAX;
$mysoc->url=$conf->global->MAIN_INFO_SOCIETE_WEB;
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index 12756fd2d76..6636ad9936d 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -780,6 +780,7 @@ class Product
if (! $id && ! $ref)
{
$this->error=$langs->trans('ErrorWrongParameters');
+ dolibarr_error("Product::fetch ".$this->error);
return -1;
}
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index 061762cced0..334370dddf4 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -1,7 +1,7 @@
* Copyright (C) 2004 Éric Seigne
- * Copyright (C) 2004-2005 Laurent Destailleur
+ * Copyright (C) 2004-2006 Laurent Destailleur
* Copyright (C) 2005 Marc Barilley / Ocebo
* Copyright (C) 2005-2006 Regis Houssin
* Copyright (C) 2006 Andre Cianfarani
@@ -55,9 +55,6 @@ class Propal
var $status;
var $datep;
var $fin_validite;
-
- var $products;
- var $products_qty;
var $price;
var $cond_reglement_id;
var $cond_reglement_code;
@@ -69,9 +66,12 @@ class Propal
var $note;
var $note_public;
- var $date_livraison;
+ var $date_livraison;
var $adresse_livraison_id;
+ var $products;
+ var $products_qty;
+
var $labelstatut=array();
var $labelstatut_short=array();
@@ -125,7 +125,6 @@ class Propal
* \return void
* \see insert_product
*/
-
function add_product($idproduct, $qty, $remise_percent=0)
{
if ($idproduct > 0)
@@ -150,25 +149,31 @@ class Propal
* \return int >0 si ok, <0 si ko
* \see add_product
*/
- function insert_discount($idproduct, $qty, $remise_percent=0, $p_desc='')
+ function insert_discount($idproduct, $qty, $remise_percent=0, $desc='')
{
}
/**
- * \brief Ajout d'un produit dans la proposition, en base
- * \param idproduct Id du produit à ajouter
- * \param qty Quantité
- * \param remise_percent Remise relative effectuée sur le produit
- * \param p_desc Descriptif optionnel
- * \return int >0 si ok, <0 si ko
- * \see add_product
+ * \brief Ajout d'un produit dans la proposition, en base
+ * \param idproduct Id du produit à ajouter
+ * \param qty Quantité
+ * \param remise_percent Remise relative effectuée sur le produit
+ * \param desc Descriptif optionnel
+ * \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
+ * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete dé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 insert_product($idproduct, $qty, $remise_percent=0, $p_desc='')
+ function insert_product($idproduct, $qty, $remise_percent=0, $desc='')
{
- global $conf;
- dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $p_desc");
+ global $conf,$mysoc;
+ dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $desc");
+ include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
+
if ($this->statut == 0)
{
// Nettoyage parametres
@@ -180,14 +185,10 @@ class Propal
$prod = new Product($this->db, $idproduct);
if ($prod->fetch($idproduct) > 0)
{
- $p_product_desc = $prod->description;
- $this -> fetch_client();
- if($this->client->tva_assuj == "0")
- $txtva ="0";
- else
- $txtva=$prod->tva_tx;
+ $this->fetch_client();
+
// multiprix
- if($conf->global->PRODUIT_MULTIPRICES == 1)
+ if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
$price = price2num($prod->multiprices[$this->client->price_level]);
$subprice = price2num($prod->multiprices[$this->client->price_level]);
@@ -197,28 +198,37 @@ class Propal
$price = price2num($prod->price);
$subprice = price2num($prod->price);
}
- /*
+ $txtva = get_default_tva($mysoc,$this->client,$prod->tva_tx);
+ if (! $desc) $desc = $prod->description;
+ if ($conf->global->PRODUIT_CHANGE_PROD_DESC) $desc=$prod->description;
- */
+ // 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.
+ $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva);
+ $total_ht = $tabprice[0];
+ $total_tva = $tabprice[1];
+ $total_ttc = $tabprice[2];
- // Calcul remise et nouveau prix
+ // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
$remise = 0;
if ($remise_percent > 0)
{
$remise = round(($prod->price * $remise_percent / 100), 2);
$price = $prod->price - $remise;
}
- if ($conf->global->PRODUIT_CHANGE_PROD_DESC)
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
- $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price)."','".$txtva."','".addslashes($p_product_desc)."','".price2num($remise_percent)."','".price2num($subprice)."')";
- }
- else
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
- $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price) ."','".$txtva."','".addslashes($p_desc?$p_desc:$prod->label)."','".price2num($remise_percent)."','".price2num($subprice)."')";
- }
- if ($this->db->query($sql) )
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice,";
+ $sql.= " total_ht, total_tva, total_ttc)";
+ $sql.= " VALUES ";
+ $sql.= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price) ."','".$txtva."','".addslashes($desc?$desc:$prod->label)."','".price2num($remise_percent)."','".price2num($subprice)."',";
+ $sql.= " '".price2num($total_ht) ."',";
+ $sql.= " '".price2num($total_tva)."',";
+ $sql.= " '".price2num($total_ttc)."'";
+ $sql.= ")";
+
+ if ($this->db->query($sql))
{
$this->update_price();
return 1;
@@ -226,6 +236,7 @@ class Propal
else
{
$this->error=$this->db->error();
+ dolibarr_syslog("Error sql=$sql, error=".$this->error);
return -1;
}
}
@@ -244,39 +255,61 @@ class Propal
/**
- * \brief Ajout d'un produit dans la proposition, en base
- * \param p_desc Descriptif optionnel
- * \param p_price Prix
- * \param p_qty Quantité
- * \param p_tva_tx Taux tva
- * \param remise_percent Remise effectuée sur le produit
- * \return int >0 si ok, <0 si ko
- * \see add_product
+ * \brief Ajout d'un produit dans la proposition, en base
+ * \param desc Descriptif optionnel
+ * \param pu Prix
+ * \param qty Quantité
+ * \param tva_tx Taux tva
+ * \param remise_percent Remise effectuée sur le produit
+ * \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
+ * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete dé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 insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent=0)
+ function insert_product_generic($desc, $pu, $qty, $tva_tx, $remise_percent=0)
{
- dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent");
+ global $conf,$mysoc;
+ dolibarr_syslog("propal.class.php::insert_product_generic $desc, $pu, $qty, $tva_tx, $remise_percent");
+ include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
+
if ($this->statut == 0)
{
// Nettoyage paramètres
$remise_percent=price2num($remise_percent);
- $p_qty=price2num($p_qty);
- if (strlen(trim($p_qty))==0) $p_qty=1;
- $p_price = price2num($p_price);
+ $qty=price2num($qty);
+ if (! $qty) $qty=1;
+ $pu = price2num($pu);
+ $tva_tx = price2num($tva_tx);
- $price = $p_price;
- $subprice = $p_price;
+ // 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.
+ $tabprice=calcul_price_total($qty, $pu, $remise_percent, $tva_tx);
+ $total_ht = $tabprice[0];
+ $total_tva = $tabprice[1];
+ $total_ttc = $tabprice[2];
+ // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
+ $price = $pu;
+ $subprice = $pu;
if ($remise_percent > 0)
{
- $remise = round(($p_price * $remise_percent / 100), 2);
- $price = $p_price - $remise;
+ $remise = round(($pu * $remise_percent / 100), 2);
+ $price = $pu - $remise;
}
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
- $sql .= " (".$this->id.", 0,'". $p_qty."','". price2num($price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".price2num($subprice)."') ; ";
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice, total_ht, total_tva, total_ttc)";
+ $sql.= " VALUES ";
+ $sql.= " (".$this->id.", 0,'". $qty."','". price2num($price)."','".$tva_tx."','".addslashes($desc)."','$remise_percent', '".price2num($subprice)."',";
+ $sql.= " '".price2num($total_ht) ."',";
+ $sql.= " '".price2num($total_tva)."',";
+ $sql.= " '".price2num($total_ttc)."'";
+ $sql.= ")";
- if ($this->db->query($sql) )
+ if ($this->db->query($sql))
{
if ($this->update_price() > 0)
@@ -290,6 +323,8 @@ class Propal
}
else
{
+ $this->error=$this->db->error();
+ dolibarr_syslog("Error sql=$sql, error=".$this->error);
return -2;
}
}
@@ -306,23 +341,39 @@ class Propal
* \param desc Description
* \return int 0 en cas de succès
*/
-
- function UpdateLigne($id, $subprice, $qty, $remise_percent=0, $tva_tx, $desc='')
+ function UpdateLigne($id, $pu, $qty, $remise_percent=0, $tva_tx, $desc='')
{
+ global $conf,$mysoc;
+ dolibarr_syslog("propal.class.php::updateligne $id, $pu, $qty, $remise_percent, $tva_tx, $desc");
+ include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
+
if ($this->statut == 0)
{
- // Nettoyage paramètres
- $subprice=price2num($subprice);
- $price = $subprice;
+ // Nettoyage paramètres
$remise_percent=price2num($remise_percent);
- $tva_tx=price2num($tva_tx);
+ $qty=price2num($qty);
+ if (! $qty) $qty=1;
+ $pu = price2num($pu);
+ $tva_tx = price2num($tva_tx);
+
+ // 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.
+ $tabprice=calcul_price_total($qty, $pu, $remise_percent, $tva_tx);
+ $total_ht = $tabprice[0];
+ $total_tva = $tabprice[1];
+ $total_ttc = $tabprice[2];
+ // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
+ $price = $pu;
+ $subprice = $pu;
if ($remise_percent > 0)
{
- $remise = round(($subprice * $remise_percent / 100), 2);
- $price = $subprice - $remise;
+ $remise = round(($pu * $remise_percent / 100), 2);
+ $price = $pu - $remise;
}
-
+
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet ";
$sql.= " SET qty='".$qty."'";
$sql.= " , price='". price2num($price)."'";
@@ -330,6 +381,9 @@ class Propal
$sql.= " , subprice='".$subprice."'";
$sql.= " , tva_tx='".$tva_tx."'";
$sql.= " , description='".addslashes($desc)."'";
+ $sql.= " , total_ht='".price2num($total_ht)."'";
+ $sql.= " , total_tva='".price2num($total_tva)."'";
+ $sql.= " , total_ttc='".price2num($total_ttc)."'";
$sql.= " WHERE rowid = '".$id."';";
if ($this->db->query($sql))
@@ -340,7 +394,7 @@ class Propal
else
{
$this->error=$this->db->error();
- dolibarr_syslog("Propal::UpdateLigne Erreur -1");
+ dolibarr_syslog("Propal::UpdateLigne Erreur sql=$sql, error=".$this->error);
return -1;
}
}
@@ -693,9 +747,12 @@ class Propal
function create()
{
global $langs,$conf;
- // Définition paramètres
+
+ // Nettoyage/définition paramètres
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
+ dolibarr_syslog("Propal::create ref=".$this->ref);
+
$this->db->begin();
// Insertion dans la base
@@ -744,6 +801,7 @@ class Propal
$result=$this->db->query($sql);
}
+ // Mise a journ infos dénormalisés
$resql=$this->update_price();
if ($resql)
{
@@ -782,36 +840,53 @@ class Propal
*/
function update_price()
{
- include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
+ include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
/*
* Liste des produits a ajouter
*/
- $sql = "SELECT price, qty, tva_tx FROM ".MAIN_DB_PREFIX."propaldet";
+ $sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc";
+ $sql.= " FROM ".MAIN_DB_PREFIX."propaldet";
$sql.= " WHERE fk_propal = ".$this->id;
- if ( $this->db->query($sql) )
+ $result = $this->db->query($sql);
+ if ($result)
{
- $num = $this->db->num_rows();
+ $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();
+ $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;
+
+ // Anciens indicateurs
+ $this->amount_ht += $obj->price * $obj->qty;
+ $this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne)
+/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
$products[$i][0] = $obj->price;
$products[$i][1] = $obj->qty;
$products[$i][2] = $obj->tva_tx;
+*/
$i++;
}
- }
- $calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue);
+ $this->db->free($result);
+ }
+/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
+ $calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue);
$this->total_remise = $calculs[3];
$this->amount_ht = $calculs[4];
$this->total_ht = $calculs[0];
$this->total_tva = $calculs[1];
$this->total_ttc = $calculs[2];
$tvas = $calculs[5];
-
+*/
// Met a jour en base
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
$sql .= " price='". price2num($this->total_ht)."'";
@@ -976,8 +1051,9 @@ class Propal
$sql.= " WHERE fk_statut = c.id";
$sql.= " AND rowid='".$rowid."';";
+ dolibarr_syslog("Propal::fecth rowid=".$rowid);
+
$resql=$this->db->query($sql);
-
if ($resql)
{
if ($this->db->num_rows($resql))
@@ -1010,8 +1086,8 @@ class Propal
$this->statut_libelle = $obj->statut_label;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->mode_reglement_id = $obj->fk_mode_reglement;
- $this->date_livraison = $obj->date_livraison;
- $this->adresse_livraison_id = $obj->fk_adresse_livraison;
+ $this->date_livraison = $obj->date_livraison;
+ $this->adresse_livraison_id = $obj->fk_adresse_livraison;
$this->user_author_id = $obj->fk_user_author;
@@ -1061,7 +1137,8 @@ class Propal
* Lignes propales liées à un produit ou non
*/
$sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice, d.fk_product,";
- $sql.= " p.label, p.description as product_desc, p.ref";
+ $sql.= " d.total_ht, d.total_tva, d.total_ttc,";
+ $sql.= " p.ref, p.label, p.description as product_desc";
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
$sql.= " WHERE d.fk_propal = ".$this->id;
@@ -1077,7 +1154,7 @@ class Propal
{
$objp = $this->db->fetch_object($result);
- $ligne = new PropaleLigne();
+ $ligne = new PropaleLigne($this->db);
$ligne->desc = $objp->description; // Description ligne
$ligne->qty = $objp->qty;
@@ -1085,6 +1162,11 @@ class Propal
$ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price;
+
+ $ligne->total_ht = $objp->total_ht;
+ $ligne->total_tva = $objp->total_tva;
+ $ligne->total_ttc = $objp->total_ttc;
+
$ligne->product_id = $objp->fk_product;
$ligne->coef = $objp->coef;
@@ -1101,7 +1183,7 @@ class Propal
}
else
{
- dolibarr_syslog("Propal::Fetch Erreur lecture des produits");
+ dolibarr_syslog("Propal::Fetch Erreur lecture des produits sql=$sql");
return -1;
}
@@ -2282,13 +2364,13 @@ class PropaleLigne
var $subprice;
var $remise_percent;
var $price;
- var $product_id;
var $desc; // Description ligne
+ var $product_id; // Id produit prédéfini
// From llx_product
var $libelle; // Label produit
var $product_desc; // Description produit
- var $ref;
+ var $ref; // Reference produit
function PropaleLigne()
{
diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql
index 129c4da09b3..02b1889038c 100644
--- a/mysql/migration/2.0.0-2.1.0.sql
+++ b/mysql/migration/2.0.0-2.1.0.sql
@@ -115,7 +115,11 @@ ALTER TABLE llx_facturedet ADD COLUMN total_tva real AFTER total_ht;
ALTER TABLE llx_facturedet ADD COLUMN total_ttc real AFTER total_tva;
ALTER TABLE llx_facturedet ADD COLUMN info_bits integer DEFAULT 0 AFTER date_end;
-
+ALTER TABLE llx_propaldet ADD COLUMN total_ht real AFTER price;
+ALTER TABLE llx_propaldet ADD COLUMN total_tva real AFTER total_ht;
+ALTER TABLE llx_propaldet ADD COLUMN total_ttc real AFTER total_tva;
+ALTER TABLE llx_propaldet ADD COLUMN info_bits integer DEFAULT 0 AFTER total_ttc;
+
ALTER TABLE llx_commande ADD INDEX idx_commande_fk_soc (fk_soc);
ALTER TABLE llx_commande ADD CONSTRAINT fk_commande_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
diff --git a/mysql/tables/llx_propaldet.sql b/mysql/tables/llx_propaldet.sql
index 1f23be7931f..b43d9fde123 100644
--- a/mysql/tables/llx_propaldet.sql
+++ b/mysql/tables/llx_propaldet.sql
@@ -32,6 +32,10 @@ create table llx_propaldet
fk_remise_except integer NULL, -- Lien vers table des remises fixes
subprice real, -- prix avant remise
price real, -- prix final
+ total_ht real, -- Total HT de la ligne toute quantité et incluant remise ligne et globale
+ total_tva real, -- Total TVA de la ligne toute quantité et incluant remise ligne et globale
+ total_ttc real, -- Total TTC de la ligne toute quantité et incluant remise ligne et globale
+ info_bits integer DEFAULT 0, -- TVA NPR ou non
coef real, -- coefficient de marge
rang integer DEFAULT 0
)type=innodb;