diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index a64a166d7af75df14d74bc1e0711445cb955a260..6b6faa5732fb0629f8bae5b0ebbe5b5888bed85e 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -680,6 +680,24 @@ else if ($action == "addline" && $user->rights->propale->creer) $price_base_type = $prod->price_base_type; } + // Update if prices fields are defined + if (GETPOST('dp_price_ht') || GETPOST('dp_price_ttc')) + { + $price_ht=price2num(GETPOST('dp_price_ht'), 'MU'); + $price_ttc=price2num(GETPOST('dp_price_ttc'), 'MU'); + + if ($price_base_type == 'TTC' && $price_ttc != $pu_ttc) + { + $pu_ttc = $price_ttc; + $pu_ht = price2num($price_ttc / (1 + ($prod->tva_tx / 100)),'MU'); + } + else if ($price_base_type != 'TTC' && $price_ht != $pu_ht) + { + $pu_ht = $price_ht; + $pu_ttc = price2num($price_ht * (1 + ($prod->tva_tx / 100)),'MU'); + } + } + // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). if ($tva_tx != $prod->tva_tx) @@ -714,19 +732,23 @@ else if ($action == "addline" && $user->rights->propale->creer) $desc = $prod->description; } - $desc.= ($desc && GETPOST('np_desc')) ? ((dol_textishtml($desc) || dol_textishtml(GETPOST('np_desc')))?"<br />\n":"\n") : ""; - $desc.= GETPOST('np_desc'); + $desc.= ($desc && GETPOST('dp_desc')) ? ((dol_textishtml($desc) || dol_textishtml(GETPOST('dp_desc')))?"<br />\n":"\n") : ""; + $desc.= GETPOST('dp_desc'); $type = $prod->type; + $fournprice=(GETPOST('dp_fournprice')?GETPOST('dp_fournprice'):''); + $buyingprice=(GETPOST('dp_buying_price')?GETPOST('dp_buying_price'):''); } else { $pu_ht=GETPOST('np_price'); $tva_tx=str_replace('*','',GETPOST('np_tva_tx')); $tva_npr=preg_match('/\*/',GETPOST('np_tva_tx'))?1:0; - $desc=GETPOST('dp_desc'); + $desc=GETPOST('np_desc'); $type=GETPOST('type'); $localtax1_tx=get_localtax($tva_tx,1,$object->client); $localtax2_tx=get_localtax($tva_tx,2,$object->client); + $fournprice=(GETPOST('np_fournprice')?GETPOST('np_fournprice'):''); + $buyingprice=(GETPOST('np_buying_price')?GETPOST('np_buying_price'):''); } $info_bits=0; @@ -757,8 +779,8 @@ else if ($action == "addline" && $user->rights->propale->creer) -1, 0, GETPOST('fk_parent_line'), - GETPOST('np_fournprice'), - GETPOST('np_buying_price') + $fournprice, + $buyingprice ); if ($result > 0) @@ -781,11 +803,17 @@ else if ($action == "addline" && $user->rights->propale->creer) unset($_POST['qty']); unset($_POST['type']); + unset($_POST['np_price']); - unset($_POST['dp_desc']); unset($_POST['np_tva_tx']); unset($_POST['np_desc']); + unset($_POST['np_fournprice']); unset($_POST['np_buying_price']); + + unset($_POST['dp_desc']); + unset($_POST['dp_price']); + unset($_POST['dp_fournprice']); + unset($_POST['dp_buying_price']); } else { @@ -914,8 +942,8 @@ else if ($action == 'remove_file' && $user->rights->propale->creer) $upload_dir = $conf->propal->dir_output; $file = $upload_dir . '/' . GETPOST('file'); $ret=dol_delete_file($file,0,0,0,$object); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); + if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); + else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 3d62245868f212a4f67ec4a129243ce4b2037c88..69efb5ea5b28856706c0db36cfaba53fd824ab3f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1080,15 +1080,16 @@ class Form * @param int $finished 2=all, 1=finished, 0=raw material * @param string $selected_input_value Value of preselected input text (with ajax) * @param int $hidelabel Hide label + * @param array $ajaxoptions Options for ajax_autocompleter * @return void */ - function select_produits($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$status=1,$finished=2,$selected_input_value='',$hidelabel=0) + function select_produits($selected='', $htmlname='productid', $filtertype='', $limit=20, $price_level=0, $status=1, $finished=2, $selected_input_value='', $hidelabel=0, $ajaxoptions=array()) { global $langs,$conf; $price_level = (! empty($price_level) ? $price_level : 0); - if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { if ($selected && empty($selected_input_value)) { @@ -1098,7 +1099,8 @@ class Form $selected_input_value=$product->ref; } // mode=1 means customers products - print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', 'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT); + $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished; + print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); if (! $hidelabel) print $langs->trans("RefOrLabel").' : '; print '<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'" />'; } @@ -1131,13 +1133,13 @@ class Form $sql = "SELECT "; $sql.= " p.rowid, p.label, p.ref, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.duration, p.stock"; // Multilang : we add translation - if ($conf->global->MAIN_MULTILANGS) + if (! empty($conf->global->MAIN_MULTILANGS)) { $sql.= ", pl.label as label_translated"; } $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; // Multilang : we add translation - if ($conf->global->MAIN_MULTILANGS) + if (! empty($conf->global->MAIN_MULTILANGS)) { $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='". $langs->getDefaultLang() ."'"; } @@ -1162,13 +1164,13 @@ class Form if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) // Can use index { $sql.=" AND (p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%'"; - if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label LIKE '".$filterkey."%'"; + if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '".$filterkey."%'"; $sql.=")"; } else { $sql.=" AND (p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%'"; - if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label LIKE '%".$filterkey."%'"; + if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '%".$filterkey."%'"; $sql.=")"; } } @@ -1194,6 +1196,9 @@ class Form $outkey=''; $outval=''; $outref=''; + $outprice_ht=''; + $outprice_ttc=''; + $outpricebasetype=''; $objp = $this->db->fetch_object($result); @@ -1206,7 +1211,7 @@ class Form $opt = '<option value="'.$objp->rowid.'"'; $opt.= ($objp->rowid == $selected)?' selected="selected"':''; - if ($conf->stock->enabled && $objp->fk_product_type == 0 && isset($objp->stock)) + if (! empty($conf->stock->enabled) && $objp->fk_product_type == 0 && isset($objp->stock)) { if ($objp->stock > 0) { @@ -1258,6 +1263,9 @@ class Form $opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC"); $outval.= price($objp2->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC"); } + $outprice_ht=price($objp2->price); + $outprice_ttc=price($objp2->price_ttc); + $outpricebasetype=$objp2->price_base_type; } } else @@ -1279,9 +1287,12 @@ class Form $opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC"); $outval.= price($objp->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC"); } + $outprice_ht=price($objp->price); + $outprice_ttc=price($objp->price_ttc); + $outpricebasetype=$objp->price_base_type; } - if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0) + if (! empty($conf->stock->enabled) && isset($objp->stock) && $objp->fk_product_type == 0) { $opt.= ' - '.$langs->trans("Stock").':'.$objp->stock; $outval.=' - '.$langs->transnoentities("Stock").':'.$objp->stock; @@ -1309,7 +1320,7 @@ class Form // "key" value of json key array is used by jQuery automatically as selected value // "label" value of json key array is used by jQuery automatically as text for combo box $outselect.=$opt; - array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval)); + array_push($outjson, array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype)); $i++; } @@ -1343,7 +1354,7 @@ class Form global $langs,$conf; global $price_level, $status, $finished; - if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { // mode=2 means suppliers products $urloption=($socid > 0?'socid='.$socid.'&':'').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished; @@ -2055,7 +2066,7 @@ class Form print '<select id="select'.$htmlname.'" class="flat selectbankaccount" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>'; if ($useempty == 1 || ($useempty == 2 && $num > 1)) { - print '<option value="'.$obj->rowid.'"> </option>'; + print '<option value="-1"> </option>'; } while ($i < $num) diff --git a/htdocs/core/tpl/freeproductline_create.tpl.php b/htdocs/core/tpl/freeproductline_create.tpl.php index af25761a5f8e455263c874e538ac1c4d04ae1d2c..233279adbeb02f47a42c094324bea6e5ba07fc6b 100644 --- a/htdocs/core/tpl/freeproductline_create.tpl.php +++ b/htdocs/core/tpl/freeproductline_create.tpl.php @@ -23,7 +23,7 @@ * $dateSelector * $this (invoice, order, ...) * $line defined - */ + */ ?> <!-- BEGIN PHP TEMPLATE freeproductline_create.tpl.php --> @@ -35,7 +35,7 @@ <td align="right"><?php echo $langs->trans('ReductionShort'); ?></td> <?php $colspan = 4; -if (! empty($conf->margin->enabled)) { +if (! empty($conf->margin->enabled)) { ?> <td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td> <?php @@ -69,7 +69,7 @@ if (! empty($conf->margin->enabled)) { require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $nbrows=ROWS_2; if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('dp_desc',$_POST["dp_desc"],'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor=new DolEditor('np_desc',$_POST["np_desc"],'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); $doleditor->Create(); ?> </td> @@ -85,7 +85,7 @@ if (! empty($conf->margin->enabled)) { <td align="right" nowrap><input type="text" size="1" value="<?php echo $buyer->remise_client; ?>" name="remise_percent">%</td> <?php $colspan = 4; -if (! empty($conf->margin->enabled)) { +if (! empty($conf->margin->enabled)) { ?> <td align="right"><input type="text" size="5" name="np_buying_price" value="<?php echo (isset($_POST["np_buying_price"])?$_POST["np_buying_price"]:''); ?>"></td> <?php @@ -99,12 +99,12 @@ if (! empty($conf->margin->enabled)) { </tr> -<?php if ($conf->service->enabled && $dateSelector) { +<?php if ($conf->service->enabled && $dateSelector) { if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; else $colspan = 9; -if (! empty($conf->margin->enabled)) { +if (! empty($conf->margin->enabled)) { if($conf->global->DISPLAY_MARGIN_RATES) $colspan++; if($conf->global->DISPLAY_MARK_RATES) diff --git a/htdocs/core/tpl/predefinedproductline_create.tpl.php b/htdocs/core/tpl/predefinedproductline_create.tpl.php index e1a75dcd2a078d0197a51360015c0bf24dcab1a1..40adc831a5c8fc053c5242dbdf30c00beb0e5a71 100644 --- a/htdocs/core/tpl/predefinedproductline_create.tpl.php +++ b/htdocs/core/tpl/predefinedproductline_create.tpl.php @@ -29,7 +29,7 @@ <!-- BEGIN PHP TEMPLATE predefinedproductline_create.tpl.php --> <tr class="liste_titre nodrag nodrop"> - <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> + <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="3"' : ' colspan="2"'); ?>> <?php echo $langs->trans("AddNewLine").' - '; if ($conf->service->enabled) @@ -38,6 +38,8 @@ echo $langs->trans('RecordedProducts'); ?> </td> + <td align="right"><?php echo $langs->trans('PriceUHT'); ?></td> + <td align="right"><?php echo $langs->trans('PriceUTTC'); ?></td> <td align="right"><?php echo $langs->trans('Qty'); ?></td> <td align="right"><?php echo $langs->trans('ReductionShort'); ?></td> <?php @@ -63,16 +65,22 @@ if (! empty($conf->margin->enabled)) { <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#idprod').change(function() { - jQuery('#np_desc').focus(); + jQuery('#dp_desc').focus(); }); }); </script> <tr <?php echo $bcnd[$var]; ?>> - <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> + <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="3"' : ' colspan="2"'); ?>> <?php - $form->select_produits('','idprod','',$conf->product->limit_size,$buyer->price_level); + $ajaxoptions=array( + 'update' => array( + 'dp_price_ht' => 'price_ht', + 'dp_price_ttc' => 'price_ttc' + ) + ); + $form->select_produits('', 'idprod', '', $conf->product->limit_size, $buyer->price_level, 1, 2, '', 0, $ajaxoptions); if (is_object($hookmanager)) { @@ -84,19 +92,21 @@ jQuery(document).ready(function() { require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $nbrows=ROWS_2; if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('np_desc',$_POST["np_desc"],'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor=new DolEditor('dp_desc',$_POST["dp_desc"],'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); $doleditor->Create(); ?> </td> + <td align="right"><input type="text" size="6" id="dp_price_ht" name="dp_price_ht" value="<?php echo (isset($_POST["dp_price_ht"])?$_POST["dp_price_ht"]:''); ?>"></td> + <td align="right"><input type="text" size="6" id="dp_price_ttc" name="dp_price_ttc" value="<?php echo (isset($_POST["dp_price_ttc"])?$_POST["dp_price_ttc"]:''); ?>"></td> <td align="right"><input type="text" size="2" name="qty" value="1"></td> - <td align="right" nowrap><input type="text" size="1" name="remise_percent" value="<?php echo $buyer->remise_client; ?>">%</td> + <td align="right" nowrap="nowrap"><input type="text" size="1" name="remise_percent" value="<?php echo $buyer->remise_client; ?>">%</td> <?php $colspan = 4; if (! empty($conf->margin->enabled)) { ?> <td align="right"> - <select id="np_fournprice" name="np_fournprice" style="display: none;"></select> - <input type="text" size="5" id="np_buying_price" name="np_buying_price" value="<?php echo (isset($_POST["np_buying_price"])?$_POST["np_buying_price"]:''); ?>"> + <select id="dp_fournprice" name="dp_fournprice" style="display: none;"></select> + <input type="text" size="5" id="dp_buying_price" name="dp_buying_price" value="<?php echo (isset($_POST["dp_buying_price"])?$_POST["dp_buying_price"]:''); ?>"> </td> <?php if($conf->global->DISPLAY_MARGIN_RATES)