*
@@ -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 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
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 @@ else {
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->service->enabled) && $dateSelector)
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 bc6fede9ab0..80ad56263fa 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -1066,9 +1066,11 @@ class CommandeFournisseur extends CommonOrder
* @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 @@ class CommandeFournisseur extends CommonOrder
$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 9d923fcc98d..6d3e8322337 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -180,51 +180,45 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$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 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
// 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 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$type
);
}
- if ($idprod == 0)
+ if ($idprod == -2 || $idprod == 0)
{
// Product not selected
$error++;
@@ -293,37 +285,36 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
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 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
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['np_marginRate']);
+ unset($_POST['np_markRate']);
+ unset($_POST['dp_desc']);
+ unset($_POST['idprodfournprice']);
- 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['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 @@ elseif (! empty($object->id))
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
{
- print 'id.'&action=edit_line&rowid='.$line->id.'#'.$line->id.'">';
+ print ' id.'&action=edit_line&rowid='.$line->id.'#'.$line->id.'">';
print img_edit();
print ' ';
$actiondelete='delete_product_line';
- print 'id.'&action='.$actiondelete.'&lineid='.$line->id.'">';
+ print ' id.'&action='.$actiondelete.'&lineid='.$line->id.'">';
print img_delete();
print ' ';
}
@@ -1723,13 +1727,10 @@ elseif (! empty($object->id))
$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 @@ elseif (! empty($object->id))
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 @@ elseif (! empty($object->id))
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 @@ elseif (! empty($object->id))
print ' % ';
print ' ';
print ' ';
- }
+ }*/
}
print '';
diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 2e549909c60..47177dc8549 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