Fix: A lot of feature was lost because global variables were not propagated into templates.

This commit is contained in:
Laurent Destailleur 2010-09-15 13:29:17 +00:00
parent 24b96584f8
commit 94a5c1c736
11 changed files with 109 additions and 374 deletions

View File

@ -1398,13 +1398,13 @@ if ($id > 0 || ! empty($ref))
$var=true; $var=true;
// Add free products/services // Add free products/services
$propal->showAddFreeProductForm(); $propal->showAddFreeProductForm(0,$mysoc,$soc);
// Add predefined products/services // Add predefined products/services
if ($conf->product->enabled || $conf->service->enabled) if ($conf->product->enabled || $conf->service->enabled)
{ {
$var=!$var; $var=!$var;
$propal->showAddPredefinedProductForm(); $propal->showAddPredefinedProductForm(0,$mysoc,$soc);
} }
// Hook of thirdparty module // Hook of thirdparty module

View File

@ -58,8 +58,6 @@ $socid=0;
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'commande',$comid,''); $result=restrictedArea($user,'commande',$comid,'');
$usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
$mesg=isset($_GET['mesg'])?$_GET['mesg']:''; $mesg=isset($_GET['mesg'])?$_GET['mesg']:'';
$commande = new Commande($db); $commande = new Commande($db);
@ -1677,13 +1675,13 @@ else
{ {
$var=true; $var=true;
$commande->showAddFreeProductForm(1); $commande->showAddFreeProductForm(1,$mysoc,$soc);
// Add predefined products/services // Add predefined products/services
if ($conf->product->enabled || $conf->service->enabled) if ($conf->product->enabled || $conf->service->enabled)
{ {
$var=!$var; $var=!$var;
$commande->showAddPredefinedProductForm(1); $commande->showAddPredefinedProductForm(1,$mysoc,$soc);
} }
// Hook of thirdparty module // Hook of thirdparty module

View File

@ -1380,18 +1380,18 @@ if ($_GET['action'] == 'create')
require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'); require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement); $classname = ucfirst($subelement);
$object = new $classname($db); $objectsrc = new $classname($db);
$object->fetch($_GET['originid']); $objectsrc->fetch($_GET['originid']);
$object->fetch_thirdparty(); $objectsrc->fetch_thirdparty();
$projectid = (!empty($object->fk_project)?$object->fk_project:''); $projectid = (!empty($objectsrc->fk_project)?$object->fk_project:'');
$ref_client = (!empty($object->ref_client)?$object->ref_client:''); $ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:'');
$soc = $object->client; $soc = $objectsrc->client;
$cond_reglement_id = (!empty($object->cond_reglement_id)?$object->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
$mode_reglement_id = (!empty($object->mode_reglement_id)?$object->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
$remise_percent = (!empty($object->remise_percent)?$object->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
$remise_absolue = (!empty($object->remise_absolue)?$object->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
} }
} }
@ -1640,9 +1640,9 @@ if ($_GET['action'] == 'create')
print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>'; print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
print '<td valign="top" colspan="2">'; print '<td valign="top" colspan="2">';
print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">'; print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($object)) if (is_object($objectsrc)) // Take value from source object
{ {
print $object->note_public; print $objectsrc->note_public;
} }
print '</textarea></td></tr>'; print '</textarea></td></tr>';
@ -1653,52 +1653,51 @@ if ($_GET['action'] == 'create')
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>'; print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
print '<td valign="top" colspan="2">'; print '<td valign="top" colspan="2">';
print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">'; print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($object)) if (is_object($objectsrc)) // Take value from source object
{ {
print $object->note; print $objectsrc->note;
} }
print '</textarea></td></tr>'; print '</textarea></td></tr>';
} }
if (is_object($object)) if (is_object($objectsrc))
{ {
// TODO for compatibility // TODO for compatibility
if ($_GET['origin'] == 'contrat') if ($_GET['origin'] == 'contrat')
{ {
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
$object->remise_absolue=$remise_absolue; $objectsrc->remise_absolue=$remise_absolue;
$object->remise_percent=$remise_percent; $objectsrc->remise_percent=$remise_percent;
$object->update_price(); $objectsrc->update_price();
} }
print "\n<!-- ".$classname." info -->"; print "\n<!-- ".$classname." info -->";
print "\n"; print "\n";
print '<input type="hidden" name="amount" value="'.$object->total_ht.'">'."\n"; print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
print '<input type="hidden" name="total" value="'.$object->total_ttc.'">'."\n"; print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
print '<input type="hidden" name="tva" value="'.$object->total_tva.'">'."\n"; print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
print '<input type="hidden" name="origin" value="'.$object->element.'">'; print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
print '<input type="hidden" name="originid" value="'.$object->id.'">'; print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
print '<tr><td>'.$langs->trans($classname).'</td><td colspan="2">'.$object->getNomUrl(1).'</td></tr>'; print '<tr><td>'.$langs->trans($classname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($object->total_ht).'</td></tr>'; print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($object->total_tva)."</td></tr>"; print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
if ($mysoc->pays_code=='ES') if ($mysoc->pays_code=='ES')
{ {
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
{ {
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td><td colspan="2">'.price($object->total_localtax1)."</td></tr>"; print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
} }
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{ {
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td><td colspan="2">'.price($object->total_localtax2)."</td></tr>"; print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
} }
} }
print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($object->total_ttc)."</td></tr>"; print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
} }
else else
{ {
// Show deprecated optional form to add product line here // Show deprecated optional form to add product line here
if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) if ($conf->global->PRODUCT_SHOW_WHEN_CREATE)
{ {
@ -2652,288 +2651,6 @@ else
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
/*
$sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_tx,';
$sql.= ' l.fk_remise_except,';
$sql.= ' l.remise_percent, l.subprice, l.info_bits,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
$sql.= ' l.date_start,';
$sql.= ' l.date_end,';
$sql.= ' l.product_type,';
$sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,';
$sql.= ' p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON l.fk_product=p.rowid';
$sql.= ' WHERE l.fk_facture = '.$object->id;
$sql.= ' ORDER BY l.rang ASC, l.rowid';
$resql = $db->query($sql);
if ($resql)
{
$num_lignes = $db->num_rows($resql);
$i = 0; $total = 0;
$product_static=new Product($db);
print '<table class="noborder" width="100%">';
if ($num_lignes)
{
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Description').'</td>';
print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
print '<td align="right" width="50">'.$langs->trans('TotalHTShort').'</td>';
print '<td width="48" colspan="3">&nbsp;</td>';
print "</tr>\n";
}
$var=true;
while ($i < $num_lignes)
{
$objp = $db->fetch_object($resql);
$var=!$var;
// Show product and description
$type=$objp->product_type?$objp->product_type:$objp->fk_product_type;
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (! empty($objp->date_start)) $type=1;
if (! empty($objp->date_end)) $type=1;
// Show line
if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid)
{
print '<tr '.$bc[$var].'>';
if ($objp->fk_product > 0)
{
print '<td>';
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
// Show product and description
$product_static->type=$objp->fk_product_type;
$product_static->id=$objp->fk_product;
$product_static->ref=$objp->product_ref;
$product_static->libelle=$objp->product_label;
$text=$product_static->getNomUrl(1);
$text.= ' - '.$objp->product_label;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description));
print $html->textwithtooltip($text,$description,3,'','',$i);
// Show range
print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end));
// Add description in form
if ($conf->global->PRODUIT_DESC_IN_FORM) print ($objp->description && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
print '</td>';
}
else
{
print '<td>';
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
if (($objp->info_bits & 2) == 2)
{
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->socid.'">';
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
print '</a>';
if ($objp->description)
{
if ($objp->description == '(CREDIT_NOTE)')
{
$discount=new DiscountAbsolute($db);
$discount->fetch($objp->fk_remise_except);
print ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
}
elseif ($objp->description == '(DEPOSIT)')
{
$discount=new DiscountAbsolute($db);
$discount->fetch($objp->fk_remise_except);
print ' - '.$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
}
else
{
print ' - '.nl2br($objp->description);
}
}
}
else
{
if ($type==1) $text = img_object($langs->trans('Service'),'service');
else $text = img_object($langs->trans('Product'),'product');
print $text.' '.nl2br($objp->description);
// Show range
print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end));
}
print "</td>\n";
}
// VAT
print '<td align="right">'.vatrate($objp->tva_tx,'%',$objp->info_bits).'</td>';
// Unit price
print '<td align="right">'.price($objp->subprice)."</td>\n";
print '<td align="right">';
if (($objp->info_bits & 2) != 2)
{
print $objp->qty;
}
else print '&nbsp;';
print '</td>';
// Remise percent (negative or positive)
if (!empty($objp->remise_percent))
{
print '<td align="right">'.dol_print_reduction($objp->remise_percent,$langs)."</td>\n";
}
else
{
print '<td>&nbsp;</td>';
}
// Montant total HT
print '<td align="right" nowrap="nowrap">'.price($objp->total_ht)."</td>\n";
// Icone d'edition et suppression
if ($object->statut == 0 && $user->rights->facture->creer)
{
print '<td align="center">';
if (($objp->info_bits & 2) == 2)
{
// Ligne remise predefinie, on permet pas modif
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'#'.$objp->rowid.'">';
print img_edit();
print '</a>';
}
print '</td>';
print '<td align="center">';
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=delete_product_line&amp;rowid='.$objp->rowid.'">';
print img_delete();
print '</a></td>';
if ($num_lignes > 1)
{
print '<td align="center">';
if ($i > 0)
{
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=up&amp;rowid='.$objp->rowid.'">';
print img_up();
print '</a>';
}
if ($i < $num_lignes-1)
{
print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=down&amp;rowid='.$objp->rowid.'">';
print img_down();
print '</a>';
}
print '</td>';
}
}
else
{
print '<td colspan="3">&nbsp;</td>';
}
print '</tr>';
}
// Ligne en mode update
if ($_GET['action'] == 'editline' && $user->rights->facture->creer && $_GET['rowid'] == $objp->rowid)
{
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'#'.$objp->rowid.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="facid" value="'.$object->id.'">';
print '<input type="hidden" name="rowid" value="'.$_GET['rowid'].'">';
print '<tr '.$bc[$var].'>';
print '<td>';
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
// Show product and description
if ($objp->fk_product > 0)
{
print '<input type="hidden" name="productid" value="'.$objp->fk_product.'">';
$product_static->type=$objp->fk_product_type;
$product_static->id=$objp->fk_product;
$product_static->ref=$objp->product_ref;
$product_static->libelle=$objp->product_label;
$text=$product_static->getNomUrl(1);
$text.= ' - '.$objp->product_label;
print $text;
print '<br>';
}
else
{
print $html->select_type_of_lines($objp->product_type,'type',1);
if ($conf->product->enabled && $conf->service->enabled) print '<br>';
}
// Description - Editor wysiwyg
$nbrows=ROWS_2;
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
$doleditor=new DolEditor('desc',$objp->description,164,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
$doleditor->Create();
print '</td>';
// VAT
print '<td align="right">';
print $html->select_tva('np_tva_tx',$objp->tva_tx,$mysoc,$soc,'',$objp->info_bits);
print '</td>';
// Unit price
print '<td align="right"><input size="6" type="text" class="flat" name="price" value="'.price($objp->subprice,0,'',0).'"></td>';
print '<td align="right">';
if (($objp->info_bits & 2) != 2)
{
print '<input size="2" type="text" class="flat" name="qty" value="'.$objp->qty.'">';
}
else print '&nbsp;';
print '</td>';
print '<td align="right" nowrap>';
if (($objp->info_bits & 2) != 2)
{
print '<input size="2" type="text" class="flat" name="remise_percent" value="'.$objp->remise_percent.'">%';
}
else print '&nbsp;';
print '</td>';
print '<td align="center" rowspan="1" colspan="5" valign="middle"><input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">';
print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>';
print '</tr>' . "\n";
if ($conf->service->enabled)
{
print '<tr '.$bc[$var].'>';
print '<td colspan="9">'.$langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
print $html->select_date($db->jdate($objp->date_start),'date_start',$usehm,$usehm,$objp->date_start?0:1,"updateligne");
print ' '.$langs->trans('to').' ';
print $html->select_date($db->jdate($objp->date_end),'date_end',$usehm,$usehm,$objp->date_end?0:1,"updateligne");
print '</td>';
print '</tr>';
}
print "</form>\n";
}
$total = $total + ($objp->qty * $objp->price);
$i++;
}
$db->free($resql);
}
else
{
dol_print_error($db);
}
*/
$result = $object->getLinesArray(); $result = $object->getLinesArray();
if (!empty($object->lines)) if (!empty($object->lines))
@ -2949,13 +2666,13 @@ else
{ {
$var=true; $var=true;
$object->showAddFreeProductForm(1); $object->showAddFreeProductForm(1,$mysoc,$soc);
// Add predefined products/services // Add predefined products/services
if ($conf->product->enabled || $conf->service->enabled) if ($conf->product->enabled || $conf->service->enabled)
{ {
$var=!$var; $var=!$var;
$object->showAddPredefinedProductForm(1); $object->showAddPredefinedProductForm(1,$mysoc,$soc);
} }
// Hook of thirdparty module // Hook of thirdparty module

View File

@ -1285,11 +1285,12 @@ class CommonObject
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
* @param $dateSelector 1=Show also date range input fields * @param $dateSelector 1=Show also date range input fields
*/ */
function showAddPredefinedProductForm($dateSelector=0) function showAddPredefinedProductForm($dateSelector,$seller,$buyer)
{ {
global $conf,$langs; global $conf,$langs;
global $html,$bcnd,$var; global $html,$bcnd,$var;
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_create.tpl.php'); include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_create.tpl.php');
} }
@ -1299,11 +1300,12 @@ class CommonObject
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
* @param $dateSelector 1=Show also date range input fields * @param $dateSelector 1=Show also date range input fields
*/ */
function showAddFreeProductForm($dateSelector=0) function showAddFreeProductForm($dateSelector,$seller,$buyer)
{ {
global $conf,$langs; global $conf,$langs;
global $html,$bcnd,$var; global $html,$bcnd,$var;
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_create.tpl.php'); include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_create.tpl.php');
} }
@ -1360,7 +1362,7 @@ class CommonObject
* Return HTML with object lines list * Return HTML with object lines list
* FIXME This must be moved into a html.class file instead of a business class. * FIXME This must be moved into a html.class file instead of a business class.
*/ */
function printLinesList($dateSelector=0) function printLinesList($dateSelector=0,$seller,$buyer)
{ {
$num = count($this->lines); $num = count($this->lines);
$var = true; $var = true;
@ -1376,7 +1378,7 @@ class CommonObject
} }
else else
{ {
$this->printLine($line,$var,$num,$i,$dateSelector); $this->printLine($line,$var,$num,$i,$dateSelector,$seller,$buyer);
} }
$i++; $i++;
@ -1390,10 +1392,12 @@ class CommonObject
* @param $num Number of line * @param $num Number of line
* @param $i * @param $i
* @param $dateSelector 1=Show also date range input fields * @param $dateSelector 1=Show also date range input fields
* @param $seller Object of seller third party
* @param $buyer Object of buyer third party
* TODO This must be moved into a html.class file instead of a business class. * TODO This must be moved into a html.class file instead of a business class.
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
*/ */
function printLine($line,$var=true,$num=0,$i=0,$dateSelector=0) function printLine($line,$var=true,$num=0,$i=0,$dateSelector=0,$seller,$buyer)
{ {
global $conf,$langs,$user; global $conf,$langs,$user;
global $html,$bc; global $html,$bc;
@ -1425,11 +1429,13 @@ class CommonObject
$text.= ' - '.$line->product_label; $text.= ' - '.$line->product_label;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description)); $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
// Use global variables + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_view.tpl.php'); include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_view.tpl.php');
} }
else else
{ {
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_view.tpl.php'); // Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_view.tpl.php');
} }
} }
@ -1438,11 +1444,13 @@ class CommonObject
{ {
if ($line->fk_product > 0) if ($line->fk_product > 0)
{ {
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_edit.tpl.php'); // Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_edit.tpl.php');
} }
else else
{ {
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_edit.tpl.php'); // Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_edit.tpl.php');
} }
} }
} }

View File

@ -357,7 +357,7 @@ class Conf
$this->defaulttx='0'; // Taux par defaut des factures clients $this->defaulttx='0'; // Taux par defaut des factures clients
} }
else { else {
$this->defaulttx=''; // Pas de taux par defaut des factures clients, le premier sera pris $this->defaulttx=''; // Pas de taux par defaut des factures clients, le plus élevé sera pris
} }
// $this->liste_limit = constante de taille maximale des listes // $this->liste_limit = constante de taille maximale des listes

View File

@ -2405,7 +2405,6 @@ class Form
global $langs,$conf,$mysoc; global $langs,$conf,$mysoc;
$return=''; $return='';
$txtva=array(); $txtva=array();
$libtva=array(); $libtva=array();
$nprtva=array(); $nprtva=array();
@ -2415,7 +2414,7 @@ class Form
$defaultnpr=(preg_match('/\*/',$selectedrate) ? 1 : $defaultnpr); $defaultnpr=(preg_match('/\*/',$selectedrate) ? 1 : $defaultnpr);
$defaulttx=str_replace('*','',$selectedrate); $defaulttx=str_replace('*','',$selectedrate);
//print $societe_vendeuse."-".$societe_acheteuse; // Check parameters
if (is_object($societe_vendeuse) && ! $societe_vendeuse->pays_code) if (is_object($societe_vendeuse) && ! $societe_vendeuse->pays_code)
{ {
if ($societe_vendeuse->id == $mysoc->id) if ($societe_vendeuse->id == $mysoc->id)
@ -2429,29 +2428,44 @@ class Form
return $return; return $return;
} }
//var_dump($societe_acheteuse);
//print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->pays_code." buyer=".$societe_acheteuse->pays_code." idprod=$idprod, info_bits=$info_bits";
//exit;
// Get list of all VAT rates to show
// First we defined code_pays to use to find list
if (is_object($societe_vendeuse)) if (is_object($societe_vendeuse))
{ {
if ($societe_vendeuse->isInEEC() && (! empty($societe_vendeuse->tva_intra)) $code_pays="'".$societe_vendeuse->pays_code."'";
&& preg_match('/^([A-Z][A-Z])/',$societe_vendeuse->tva_intra,$reg))
{
$code_pays=$reg[1];
}
else
{
$code_pays=$societe_vendeuse->pays_code;
}
} }
else else
{ {
$code_pays=$mysoc->pays_code; // Pour compatibilite ascendente $code_pays="'".$mysoc->pays_code."'"; // Pour compatibilite ascendente
} }
if (! empty($conf->global->SERVICES_ARE_ECOMMERCE_200238EC))
// Recherche liste des codes TVA du pays vendeur {
$sql = "SELECT t.taux,t.recuperableonly"; // We also add the buyer
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; if (! $idprod) // We don't know type of product
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$code_pays."'"; {
$sql .= " AND t.active = 1"; $code_pays.=",'".$societe_acheteuse->pays_code."'";
$sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC"; }
else
{
$prodstatic=new Product($this->db);
$prodstatic->fetch($idprod);
if ($prodstatic->type == 1) // We know product is a service
{
$code_pays.=",'".$societe_acheteuse->pays_code."'";
}
}
}
// Now we get list
$sql = "SELECT DISTINCT t.taux, t.recuperableonly";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql.= " WHERE t.fk_pays = p.rowid";
$sql.= " AND t.active = 1";
$sql.= " AND p.code in (".$code_pays.")";
$sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -2491,8 +2505,7 @@ class Form
} }
$nbdetaux = sizeof($txtva); $nbdetaux = sizeof($txtva);
if ($nbdetaux > 0)
if (sizeof($txtva))
{ {
$return.= '<select class="flat" name="'.$name.'">'; $return.= '<select class="flat" name="'.$name.'">';

View File

@ -20,7 +20,6 @@
?> ?>
<!-- BEGIN PHP TEMPLATE freeproductline_create.tpl.php --> <!-- BEGIN PHP TEMPLATE freeproductline_create.tpl.php -->
<?php <?php
// TODO à déplacer // TODO à déplacer
if ($conf->global->PRODUIT_USE_MARKUP) $colspan = 'colspan="2"'; if ($conf->global->PRODUIT_USE_MARKUP) $colspan = 'colspan="2"';
@ -58,7 +57,7 @@ if ($conf->global->PRODUIT_USE_MARKUP) $colspan = 'colspan="2"';
<td align="right"> <td align="right">
<?php <?php
if ($soc->tva_assuj == "0") echo '<input type="hidden" name="np_tva_tx" value="0">0'; if ($soc->tva_assuj == "0") echo '<input type="hidden" name="np_tva_tx" value="0">0';
else $html->select_tva('np_tva_tx', $conf->defaulttx, $mysoc, $soc); else $html->select_tva('np_tva_tx', $conf->defaulttx, $seller, $buyer);
?> ?>
</td> </td>
<td align="right"><input type="text" size="5" name="np_price"></td> <td align="right"><input type="text" size="5" name="np_price"></td>
@ -72,9 +71,9 @@ if ($conf->global->PRODUIT_USE_MARKUP) $colspan = 'colspan="2"';
<td colspan="9"> <td colspan="9">
<?php <?php
echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
echo $html->select_date('','date_start',$usehm,$usehm,1,"addproduct"); echo $html->select_date('','date_start',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addproduct");
echo ' '.$langs->trans('to').' '; echo ' '.$langs->trans('to').' ';
echo $html->select_date('','date_end',$usehm,$usehm,1,"addproduct"); echo $html->select_date('','date_end',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addproduct");
?> ?>
</td> </td>
</tr> </tr>

View File

@ -40,7 +40,7 @@
?> ?>
</td> </td>
<td align="right"><?php echo $html->select_tva('tva_tx',$line->tva_tx,$mysoc,$societe,'',$line->info_bits); ?></td> <td align="right"><?php echo $html->select_tva('tva_tx',$line->tva_tx,$seller,$buyer,'',$line->info_bits); ?></td>
<td align="right"><input size="6" type="text" class="flat" name="subprice" value="<?php echo price($line->subprice,0,'',0); ?>"></td> <td align="right"><input size="6" type="text" class="flat" name="subprice" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
@ -68,9 +68,9 @@
<tr <?php echo $bc[$var]; ?>> <tr <?php echo $bc[$var]; ?>>
<td colspan="9"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?> <td colspan="9"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
<?php <?php
echo $html->select_date($line->date_start,'date_start',$usehm,$usehm,$line->date_start?0:1,"updateligne"); echo $html->select_date($line->date_start,'date_start',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$line->date_start?0:1,"updateligne");
echo ' '.$langs->trans('to').' '; echo ' '.$langs->trans('to').' ';
echo $html->select_date($line->date_end,'date_end',$usehm,$usehm,$line->date_end?0:1,"updateligne"); echo $html->select_date($line->date_end,'date_end',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$line->date_end?0:1,"updateligne");
?> ?>
</td> </td>
</tr> </tr>

View File

@ -78,9 +78,9 @@ $colspan = 'colspan="3"';
<td colspan="9"> <td colspan="9">
<?php <?php
echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
echo $html->select_date('','date_start_predef',$usehm,$usehm,1,"addpredefinedproduct"); echo $html->select_date('','date_start_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct");
echo ' '.$langs->trans('to').' '; echo ' '.$langs->trans('to').' ';
echo $html->select_date('','date_end_predef',$usehm,$usehm,1,"addpredefinedproduct"); echo $html->select_date('','date_end_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct");
?> ?>
</td> </td>
</tr> </tr>

View File

@ -49,7 +49,7 @@
?> ?>
</td> </td>
<td align="right"><?php echo $html->select_tva('tva_tx',$line->tva_tx,$mysoc,$societe,'',$line->info_bits); ?></td> <td align="right"><?php echo $html->select_tva('tva_tx',$line->tva_tx,$seller,$buyer,'',$line->info_bits); ?></td>
<td align="right"><input size="6" type="text" class="flat" name="subprice" value="<?php echo price($line->subprice,0,'',0); ?>"></td> <td align="right"><input size="6" type="text" class="flat" name="subprice" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
@ -77,9 +77,9 @@
<tr <?php echo $bc[$var]; ?>> <tr <?php echo $bc[$var]; ?>>
<td colspan="9"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?> <td colspan="9"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
<?php <?php
echo $html->select_date($line->date_start,'date_start',$usehm,$usehm,$line->date_start?0:1,"updateligne"); echo $html->select_date($line->date_start,'date_start',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$line->date_start?0:1,"updateligne");
echo ' '.$langs->trans('to').' '; echo ' '.$langs->trans('to').' ';
echo $html->select_date($line->date_end,'date_end',$usehm,$usehm,$line->date_end?0:1,"updateligne"); echo $html->select_date($line->date_end,'date_end',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$line->date_end?0:1,"updateligne");
?> ?>
</td> </td>
</tr> </tr>

View File

@ -2634,7 +2634,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
if (!is_object($societe_vendeuse)) return -1; if (!is_object($societe_vendeuse)) return -1;
if (!is_object($societe_acheteuse)) return -1; if (!is_object($societe_acheteuse)) return -1;
dol_syslog("get_default_tva: seller use vat=".$societe_vendeuse->tva_assuj.", seller country=".$societe_vendeuse->pays_code.", seller in cee=".$societe_vendeuse->isInEEC().", buyer country=".$societe_acheteuse->pays_code.", buyer in cee=".$societe_acheteuse->isInEEC().", idprod=".$idprod); dol_syslog("get_default_tva: seller use vat=".$societe_vendeuse->tva_assuj.", seller country=".$societe_vendeuse->pays_code.", seller in cee=".$societe_vendeuse->isInEEC().", buyer country=".$societe_acheteuse->pays_code.", buyer in cee=".$societe_acheteuse->isInEEC().", idprod=".$idprod.", SERVICES_ARE_ECOMMERCE_200238EC=".$conf->global->SERVICES_ARE_ECOMMERCE_200238EC);
// Si vendeur non assujeti a TVA (tva_assuj vaut 0/1 ou franchise/reel) // Si vendeur non assujeti a 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) return 0;