diff --git a/ChangeLog b/ChangeLog index 8724f49e5b2..16b77f8cc6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ For users: - New: Add object_hour as substitution tag for opendocument generation. - New: Add option MEMBER_PAYONLINE_SENDEMAIL to send email when paypal or paybox payment is done. - New: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). +- New: Clone product/service composition - New: [ task #926 ] Add extrafield feature on order lines - New: [ task #927 ] Add extrafield feature on Proposal lines - New: [ task #928 ] Add extrafield feature on invoice lines diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 2ed75b395e4..43a3b54bc35 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -77,6 +77,7 @@ ContractStatusToRun=A mettre en service ContractNotRunning=This contract is not running ErrorProductAlreadyExists=A product with reference %s already exists. ErrorProductBadRefOrLabel=Wrong value for reference or label. +ErrorProductClone=There was a problem while trying to clone the product or service. Suppliers=Suppliers SupplierRef=Supplier's product ref. ShowProduct=Show product @@ -164,6 +165,7 @@ CloneProduct=Clone product or service ConfirmCloneProduct=Are you sure you want to clone product or service %s ? CloneContentProduct=Clone all main informations of product/service ClonePricesProduct=Clone main informations and prices +CloneCompositionProduct=Clone product/service composition ProductIsUsed=This product is used NewRefForClone=Ref. of new product/service CustomerPrices=Customers prices diff --git a/htdocs/langs/es_ES/products.lang b/htdocs/langs/es_ES/products.lang index 557d5c3803b..c54a27cd4eb 100644 --- a/htdocs/langs/es_ES/products.lang +++ b/htdocs/langs/es_ES/products.lang @@ -77,6 +77,7 @@ ContractStatusToRun=A poner en servicio ContractNotRunning=Este contrato no está en servicio ErrorProductAlreadyExists=Un producto con la referencia %s ya existe. ErrorProductBadRefOrLabel=El valor de la referencia o etiqueta es incorrecto +ErrorProductClone=Ha ocurrido un error al intentar clonar el producto o servicio. Suppliers=Proveedores SupplierRef=Ref. producto proveedor ShowProduct=Mostrar producto @@ -165,6 +166,7 @@ CloneProduct=Clonar producto/servicio ConfirmCloneProduct=¿Está seguro de querer clonar el producto o servicio %s? CloneContentProduct=Clonar solamente la información general del producto/servicio ClonePricesProduct=Clonar la información general y los precios +CloneCompositionProduct=Clonar la composición del producto/servicio ProductIsUsed=Este producto es utilizado NewRefForClone=Ref. del nuevo producto/servicio CustomerPrices=Precios clientes diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 98236be4778..08413318b06 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2007-2011 Jean Heimburger * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2013 Cedric GROSS + * Copyright (C) 2013 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2073,6 +2074,24 @@ class Product extends CommonObject return 1; } + function clone_associations($fromId, $toId) + { + $this->db->begin(); + + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association (rowid, fk_product_pere, fk_product_fils, qty)'; + $sql.= " SELECT null, $toId, fk_product_fils, qty FROM ".MAIN_DB_PREFIX."product_association"; + $sql.= " WHERE fk_product_pere = '".$fromId."'"; + + if (! $this->db->query($sql)) + { + $this->db->rollback(); + return -1; + } + + $this->db->commit(); + return 1; + } + /** * Recopie les fournisseurs et prix fournisseurs d'un produit/service sur un autre * diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 8971b93a3df..7154b7271d3 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -6,6 +6,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Auguria SARL * Copyright (C) 2010-2011 Juanjo Menent + * Copyright (C) 2013 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -320,6 +321,19 @@ if (empty($reshook)) $id = $object->create($user); if ($id > 0) { + if (GETPOST('clone_composition')) + { + $result = $object->clone_associations($originalId, $id); + + if ($result < 1) + { + $db->rollback(); + setEventMessage($langs->trans('ErrorProductClone'), 'errors'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId); + exit; + } + } + // $object->clone_fournisseurs($originalId, $id); $db->commit(); @@ -1234,7 +1248,8 @@ $formquestionclone=array( 'text' => $langs->trans("ConfirmClone"), array('type' => 'text', 'name' => 'clone_ref','label' => $langs->trans("NewRefForClone"), 'value' => $langs->trans("CopyOf").' '.$object->ref, 'size'=>24), array('type' => 'checkbox', 'name' => 'clone_content','label' => $langs->trans("CloneContentProduct"), 'value' => 1), - array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true) + array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true), + array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1) ); // Confirm delete product @@ -1246,7 +1261,7 @@ if ($action == 'delete' && empty($conf->use_javascript_ajax)) // Clone confirmation if ($action == 'clone' && empty($conf->use_javascript_ajax)) { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',230,600); + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',250,600); } @@ -1270,7 +1285,7 @@ if ($action == '' || $action == 'view') if (! empty($conf->use_javascript_ajax)) { print '
'.$langs->trans('ToClone').'
'."\n"; - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',230,600); + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',250,600); } else {