From 131f133e071147497fa5457697f934352133273c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 May 2014 17:59:43 +0200 Subject: [PATCH] New: Merge free product and predefined product area to enter new product (Supplier orders now use same template than customer orders/proposal/invoices). --- htdocs/comm/propal.php | 28 ++-- htdocs/commande/fiche.php | 27 ++-- htdocs/compta/facture.php | 27 ++-- htdocs/contrat/fiche.php | 25 +-- htdocs/core/class/html.form.class.php | 6 +- htdocs/core/lib/ajax.lib.php | 7 +- htdocs/core/tpl/objectline_create.tpl.php | 140 ++++++++++++----- .../class/fournisseur.commande.class.php | 8 +- htdocs/fourn/commande/fiche.php | 147 ++++++++++-------- htdocs/langs/en_US/products.lang | 6 + 10 files changed, 266 insertions(+), 155 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index c49e6fb36cd14..01c9956408bb7 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -572,18 +572,17 @@ } } - if (empty($idprod) && GETPOST('type') < 0) { + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors'); $error ++; } - if (empty($idprod) && $price_ht == '') // Unit price can be 0 but not ''. Also price can be negative for - // proposal. + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && $price_ht == '') // Unit price can be 0 but not ''. Also price can be negative for proposal. { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors'); $error ++; } - if (empty($idprod) && empty($product_desc)) { + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), 'errors'); $error ++; } @@ -754,15 +753,20 @@ unset($_POST ['np_marginRate']); unset($_POST ['np_markRate']); unset($_POST ['dp_desc']); - unset($_POST ['idprod']); - unset($_POST ['qty_predef']); - unset($_POST ['remise_percent_predef']); - unset($_POST ['fournprice_predef']); - unset($_POST ['buying_price_predef']); - unset($_POST ['np_marginRate_predef']); - unset($_POST ['np_markRate_predef']); - unset($_POST ['np_desc']); + + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); } else { $db->rollback(); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index f9aa58ddd1c75..5cd0367bea860 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -513,11 +513,11 @@ setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors'); $error ++; } - if (empty($idprod) && GETPOST('type') < 0) { + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors'); $error ++; } - if (empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors'); $error ++; @@ -526,7 +526,7 @@ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors'); $error ++; } - if (empty($idprod) && empty($product_desc)) { + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors'); $error ++; } @@ -697,15 +697,20 @@ unset($_POST ['np_marginRate']); unset($_POST ['np_markRate']); unset($_POST ['dp_desc']); - unset($_POST ['idprod']); - unset($_POST ['qty_predef']); - unset($_POST ['remise_percent_predef']); - unset($_POST ['fournprice_predef']); - unset($_POST ['buying_price_predef']); - unset($_POST ['np_marginRate_predef']); - unset($_POST ['np_markRate_predef']); - unset($_POST ['np_desc']); + + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); } else { setEventMessage($object->error, 'errors'); } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 2c70be7c4c9fa..37fc2d11ffa11 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1077,11 +1077,11 @@ setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors'); $error ++; } - if (empty($idprod) && GETPOST('type') < 0) { + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors'); $error ++; } - if (empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors'); $error ++; @@ -1090,7 +1090,7 @@ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors'); $error ++; } - if (empty($idprod) && empty($product_desc)) { + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors'); $error ++; } @@ -1269,15 +1269,20 @@ unset($_POST['np_marginRate']); unset($_POST['np_markRate']); unset($_POST['dp_desc']); - unset($_POST['idprod']); - unset($_POST['qty_predef']); - unset($_POST['remise_percent_predef']); - unset($_POST['fournprice_predef']); - unset($_POST['buying_price_predef']); - unset($_POST['np_marginRate_predef']); - unset($_POST['np_markRate_predef']); - unset($_POST['np_desc']); + + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); } else { setEventMessage($object->error, 'errors'); } diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 361940f27e3b2..22db24d292023 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -378,7 +378,7 @@ setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")),'errors'); $error++; } - if ((GETPOST('price_ht') == '' || ! GETPOST('dp_desc')) && ! GETPOST('idprod')) + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")),'errors'); $error++; @@ -526,16 +526,23 @@ unset($_POST['product_desc']); unset($_POST['fournprice']); unset($_POST['buying_price']); + unset($_POST ['np_marginRate']); + unset($_POST ['np_markRate']); unset($_POST['dp_desc']); - unset($_POST['idprod']); - unset($_POST['qty_predef']); - unset($_POST['remise_percent_predef']); - unset($_POST['fournprice_predef']); - unset($_POST['buying_price_predef']); - unset($_POST['np_marginRate_predef']); - unset($_POST['np_markRate_predef']); - unset($_POST['np_desc']); + + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); } else { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 385e6802be39b..1de888a6f11a3 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1697,9 +1697,10 @@ private function constructProductListOption(&$objp, &$opt, &$optJson, $price_lev * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) * @param string $filtre For a SQL filter * @param array $ajaxoptions Options for ajax_autocompleter + * @param int $hidelabel Hide label (0=no, 1=yes) * @return void */ - function select_produits_fournisseurs($socid, $selected='', $htmlname='productid', $filtertype='', $filtre='', $ajaxoptions=array()) + function select_produits_fournisseurs($socid, $selected='', $htmlname='productid', $filtertype='', $filtre='', $ajaxoptions=array(), $hidelabel=0) { global $langs,$conf; global $price_level, $status, $finished; @@ -1709,8 +1710,7 @@ function select_produits_fournisseurs($socid, $selected='', $htmlname='productid // 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; print ajax_autocompleter('', $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); - print $langs->trans("RefOrLabel").' : '; - print '
'; + print ($hidelabel?'':$langs->trans("RefOrLabel").' : ').''; } else { diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 15a797466948d..b09699cbc33cf 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -129,9 +129,12 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt if (ui.item.disabled) { $("#" + options.option_disabled).attr("disabled", "disabled"); if (options.error) { - $.jnotify(options.error, "error", true); + $.jnotify(options.error, "error", true); // Output with jnotify the error message } - } else { + if (options.warning) { + $.jnotify(options.warning, "warning", false); // Output with jnotify the warning message + } + } else { $("#" + options.option_disabled).removeAttr("disabled"); } } diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 50a4d69814955..a2b073c52c0a6 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -1,6 +1,6 @@ - * Copyright (C) 2010-2013 Laurent Destailleur + * Copyright (C) 2010-2014 Laurent Destailleur * Copyright (C) 2012-2013 Christophe Battarel * Copyright (C) 2013 Florian Henry * @@ -22,12 +22,17 @@ * $langs * $dateSelector * $this (invoice, order, ...) - * $line defined + * $inputalsopricewithtax + * $forceall (0 by default, 1 for supplier invoices/orders) + * $senderissupplier (0 by default, 1 for supplier invoices/orders) */ +global $dateSelector, $forceall, $senderissupplier; + $usemargins=0; if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; - +if (empty($forceall)) $forceall=0; +if (empty($senderissupplier)) $senderissupplier=0; ?> @@ -38,6 +43,9 @@ trans('VAT'); ?> trans('PriceUHT'); ?> + + trans('PriceUTTC'); ?> + trans('Qty'); ?> trans('ReductionShort'); ?> global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> - - '; - if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) + // Show radio free line + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) echo ' '; + else echo ''; + // Show type selector + if (empty($conf->product->enabled) && empty($conf->service->enabled)) { - echo ' '; + // If module product and service disabled, by default this is a product except for contracts it is a service + print ''; + } + else { + if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '; + else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Service"); + else if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Product"); + echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,1,$forceall); } - if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '; - else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Service"); - else if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans("FreeLineOfType").' '.$langs->trans("Product"); - echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,1); echo ''; + // Predefined product/service if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { echo '
'; echo ' '; - if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('RecordedProducts'); - else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('RecordedServices'); - else echo $langs->trans('RecordedProductsAndServices'); + if (empty($senderissupplier)) + { + if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToBuy'); + else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToBuy'); + else echo $langs->trans('PredefinedProductsAndServicesToBuy'); + } + else + { + if (! empty($conf->product->enabled) && empty($conf->service->enabled)) echo $langs->trans('PredefinedProductsToPurchase'); + else if (empty($conf->product->enabled) && ! empty($conf->service->enabled)) echo $langs->trans('PredefinedServicesToPurchase'); + else echo $langs->trans('PredefinedProductsAndServicesToPurchase'); + } echo ' '; $filtertype=''; if (! empty($object->element) && $object->element == 'contrat' && empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $filtertype='1'; - $form->select_produits('','idprod',$filtertype,$conf->product->limit_size,$buyer->price_level, 1, 2, '', 3, array(),$buyer->id); + + if (empty($senderissupplier)) + { + $form->select_produits('', 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(),$buyer->id); + } + else + { + $ajaxoptions=array( + 'update' => array('qty'=>'qty','remise_percent' => 'discount'), // html id tag will be edited with which ajax json response key + 'option_disabled' => 'addPredefinedProductButton', // html id to disable once select is done + 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'error' + ); + $form->select_produits_fournisseurs($object->fourn_id, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1); + } echo ''; } - if (is_object($hookmanager)) + if (is_object($hookmanager) && empty($senderissupplier)) { $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line','int')); $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); } + if (is_object($hookmanager) && ! empty($senderissupplier)) + { + $parameters=array('htmlname'=>'addproduct'); + $reshook=$hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action); + } + - //if ((! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($conf->product->enabled) && empty($conf->service->enabled))) echo '
'; - echo '
'; + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) echo '
'; // Editor wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -141,14 +178,25 @@ tva_assuj == "0") echo '0'; - else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer); + if (GETPOST('prod_entry_mode') != 'predef') + { + if ($seller->tva_assuj == "0") echo '0'; + else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer); + } ?> + "> - + + + + + "> + + + "> remise_client); ?>" name="remise_percent">% @@ -229,35 +277,37 @@ if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; } -?> + ?> -> + > element) && $object->element == 'contrat') { print $langs->trans("DateStartPlanned").' '; - $form->select_date('',"date_start",$usehm,$usehm,1,"addproduct"); + $form->select_date($date_start,"date_start",$usehm,$usehm,1,"addproduct"); print '   '.$langs->trans("DateEndPlanned").' '; - $form->select_date('',"date_end",$usehm,$usehm,1,"addproduct"); + $form->select_date($date_end,"date_end",$usehm,$usehm,1,"addproduct"); } else { echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; - echo $form->select_date('','date_start',empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,1,"addproduct"); + echo $form->select_date($date_start,'date_start',empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,1,"addproduct"); echo ' '.$langs->trans('to').' '; - echo $form->select_date('','date_end',empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,1,"addproduct"); + echo $form->select_date($date_end,'date_end',empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,1,"addproduct"); } ?> - - - diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index bc6fede9ab08b..80ad56263fa77 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1066,9 +1066,11 @@ function createFromClone() * @param int $type Type of line (0=product, 1=service) * @param int $info_bits More information * @param int $notrigger Disable triggers + * @param timestamp $date_start Date start of service + * @param timestamp $date_end Date end of service * @return int <=0 if KO, >0 if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $type=0, $info_bits=0, $notrigger=false) + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $type=0, $info_bits=0, $notrigger=false, $date_start='', $date_end='') { global $langs,$mysoc; @@ -1172,12 +1174,14 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f $subprice = price2num($pu,'MU'); $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; - $sql.= " (fk_commande, label, description,"; + $sql.= " (fk_commande, label, description, date_start, date_end,"; $sql.= " fk_product, product_type,"; $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,"; $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc"; $sql.= ")"; $sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',"; + $sql.= " ".($date_start?"'".$this->db->idate($date_start)."'":"null").","; + $sql.= " ".($date_end?"'".$this->db->idate($date_end)."'":"null").","; if ($fk_product) { $sql.= $fk_product.","; } else { $sql.= "null,"; } $sql.= "'".$product_type."',"; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 9d923fcc98d1f..6d3e832233738 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -180,51 +180,45 @@ $error = 0; // Set if we used free entry or predefined product - if (GETPOST('addline_libre') - || (GETPOST('dp_desc') && ! GETPOST('addline_libre') && ! GETPOST('idprod', 'int')>0) // we push enter onto qty field - ) + $predef=''; + $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); + if (GETPOST('prod_entry_mode') == 'free') { - $predef=''; $idprod=0; - $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); $price_ht = GETPOST('price_ht'); - $tva_tx=(GETPOST('tva_tx')?GETPOST('tva_tx'):0); + $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } - if (GETPOST('addline_predefined') - || (! GETPOST('dp_desc') && ! GETPOST('addline_predefined') && GETPOST('idprod', 'int')>0) // we push enter onto qty field - ) + else { - $predef= '_predef'; $idprod=GETPOST('idprod', 'int'); - $product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):'')); $price_ht = ''; $tva_tx = ''; } + $qty = GETPOST('qty'.$predef); $remise_percent=GETPOST('remise_percent'.$predef); - if (GETPOST('addline_libre') && GETPOST('pu') < 0 && $qty < 0) + + if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0) { setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors'); $error++; } - if (GETPOST('addline_libre') && ! GETPOST('idprodfournprice') && GETPOST('type') < 0) + if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('idprodfournprice') && GETPOST('type') < 0) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors'); $error++; } - if (! GETPOST('addline_predefined') && ( GETPOST('pu')==='')) // Unit price can be 0 but not '' + if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='') // Unit price can be 0 but not '' { - setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors'); $error++; } - if (! GETPOST('addline_predefined') && ! GETPOST('np_desc') && ! GETPOST('dp_desc')) + if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('dp_desc')) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors'); $error++; } - if ((! GETPOST('addline_predefined') && (! GETPOST('qty') || GETPOST('qty') == '')) - || (GETPOST('addline_predefined') && (! GETPOST('qty_predef') || GETPOST('qty_predef') == ''))) + if (! GETPOST('qty')) { setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors'); $error++; @@ -233,18 +227,16 @@ // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit - if (GETPOST('addline_predefined') || GETPOST('idprodfournprice')) // With combolist idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or '' + if (GETPOST('prod_entry_mode') != 'free') // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or '' { $idprod=0; $productsupplier = new ProductFournisseur($db); - if (GETPOST('idprodfournprice') == '') - { - $idprod=-1; - } + if (GETPOST('idprodfournprice') == -1 || GETPOST('idprodfournprice') == '') $idprod=-2; // Same behaviour than with combolist. When not select idprodfournprice is now -2 (to avoid conflict with next action that may return -1) + if (GETPOST('idprodfournprice') > 0) { - $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat + $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat. } if ($idprod > 0) @@ -278,7 +270,7 @@ $type ); } - if ($idprod == 0) + if ($idprod == -2 || $idprod == 0) { // Product not selected $error++; @@ -293,37 +285,36 @@ setEventMessage($langs->trans("ErrorQtyTooLowForThisSupplier"), 'errors'); } } - else if( GETPOST('pu')!=='' || GETPOST('amountttc')!=='' ) + else if( GETPOST('price_ht')!=='' || GETPOST('price_ttc')!=='' ) { - $type=$_POST["type"]; - $desc=$_POST['dp_desc']; - $tva_tx = price2num($_POST['tva_tx']); + $pu_ht = price2num($price_ht, 'MU'); + $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); + $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0); + $tva_tx = str_replace('*', '', $tva_tx); + $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); + $desc = $product_desc; + $type = GETPOST('type'); + + $tva_tx = price2num($tva_tx); // When vat is text input field // Local Taxes $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty); $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty); - if (! $product_desc) + if (!empty($_POST['price_ht'])) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), 'errors'); + $price_base_type = 'HT'; + $ht = price2num($_POST['price_ht']); + $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type); } else { - if (!empty($_POST['pu'])) - { - $price_base_type = 'HT'; - $ht = price2num($_POST['pu']); - $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type); - } - else - { - $ttc = price2num($_POST['amountttc']); - $ht = $ttc / (1 + ($tauxtva / 100)); - $price_base_type = 'HT'; - $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type); - } + $ttc = price2num($_POST['price_ttc']); + $ht = $ttc / (1 + ($tauxtva / 100)); + $price_base_type = 'HT'; + $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type); } - } + } //print "xx".$tva_tx; exit; if (! $error && $result > 0) @@ -345,22 +336,35 @@ supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } + unset($_POST ['prod_entry_mode']); + unset($_POST['qty']); unset($_POST['type']); unset($_POST['remise_percent']); - unset($_POST['dp_desc']); unset($_POST['pu']); + unset($_POST['price_ht']); + unset($_POST['price_ttc']); unset($_POST['tva_tx']); unset($_POST['label']); unset($localtax1_tx); unset($localtax2_tx); - - unset($_POST['idprodfournprice']); - unset($_POST['qty_predef']); - unset($_POST['remise_percent_predef']); - unset($_POST['fournprice_predef']); - unset($_POST['buying_price_predef']); - unset($_POST['np_desc']); + unset($_POST['np_marginRate']); + unset($_POST['np_markRate']); + unset($_POST['dp_desc']); + unset($_POST['idprodfournprice']); + + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); } else { @@ -1653,12 +1657,12 @@ if ($object->statut == 0 && $user->rights->fournisseur->commande->creer) { - print 'id.'#'.$line->id.'">'; + print 'id.'#'.$line->id.'">'; print img_edit(); print ''; $actiondelete='delete_product_line'; - print ''; + print ''; print img_delete(); print ''; } @@ -1723,13 +1727,10 @@ $i++; } - /* - * Form to add new line - */ + // Form to add new line if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action <> 'edit_line') { - - print ''; + /*print ''; print ''; print ''; // ancre print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").''; @@ -1738,12 +1739,27 @@ print ''.$langs->trans('Qty').''; print ''.$langs->trans('ReductionShort').''; print ' '; - print ''; - - // TODO Use the predefinedproductline_create.tpl.php file + print '';*/ // Add free products/services form - $var=true; + global $forceall, $senderissupplier, $dateSelector; + $forceall=1; $senderissupplier=1; $dateSelector=0; + if ($object->statut == 0 && $user->rights->propal->creer) + { + if ($action != 'editline') + { + $var = true; + + // Add free products/services + $object->formAddObjectLine(1, $mysoc, $soc); + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + } + } + +/* + $var=true; print ''; print ''; @@ -1805,6 +1821,7 @@ print ''; print ''; + $ajaxoptions=array( 'update' => array('qty_predef'=>'qty','remise_percent_predef' => 'discount'), // html id tag will be edited with which ajax json response key 'option_disabled' => 'addPredefinedProductButton', // html id to disable once select is done @@ -1830,7 +1847,7 @@ print '%'; print ''; print ''; - } + }*/ } print ''; diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 2e549909c600a..47177dc85493e 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -156,6 +156,12 @@ NoSupplierPriceDefinedForThisProduct=No supplier price/qty defined for this prod RecordedProducts=Products recorded RecordedServices=Services recorded RecordedProductsAndServices=Products/services recorded +PredefinedProductsToBuy=Predefined products to buy +PredefinedServicesToBuy=Predefined services to buy +PredefinedProductsAndServicesToBuy=Predefined products/services to buy +PredefinedProductsToPurchase=Predefined product to purchase +PredefinedServicesToPurchase=Predefined services to purchase +PredefinedProductsAndServicesToPurchase=Predefined products/services to puchase GenerateThumb=Generate thumb ProductCanvasAbility=Use special "canvas" addons ServiceNb=Service #%s