From 9c0fe61a214edfeecdf20ddafe5570dcde6e86d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Mon, 10 Jun 2013 00:09:16 +0200 Subject: [PATCH 1/2] Fix CR --- htdocs/core/class/html.form.class.php | 30 +++++------ htdocs/core/lib/pdf.lib.php | 54 +++++++++---------- .../modules/facture/doc/pdf_crabe.modules.php | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index d02d0d56789..dae7dad00d4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1654,21 +1654,21 @@ class Form // Add criteria on ref/label if ($filterkey != '') { - $sql.=' AND ('; - $prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on - // For natural search - $scrit = explode(' ', $filterkey); - $i=0; - if (count($scrit) > 1) $sql.="("; - foreach ($scrit as $crit) - { - if ($i > 0) $sql.=" AND "; - $sql.="(pfp.ref_fourn LIKE '".$prefix.$crit."%' OR p.ref LIKE '".$prefix.$crit."%' OR p.label LIKE '".$prefix.$crit."%')"; - $i++; - } - if (count($scrit) > 1) $sql.=")"; - if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$prefix.$filterkey."%'"; - $sql.=')'; + $sql.=' AND ('; + $prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on + // For natural search + $scrit = explode(' ', $filterkey); + $i=0; + if (count($scrit) > 1) $sql.="("; + foreach ($scrit as $crit) + { + if ($i > 0) $sql.=" AND "; + $sql.="(pfp.ref_fourn LIKE '".$prefix.$crit."%' OR p.ref LIKE '".$prefix.$crit."%' OR p.label LIKE '".$prefix.$crit."%')"; + $i++; + } + if (count($scrit) > 1) $sql.=")"; + if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$prefix.$filterkey."%'"; + $sql.=')'; } $sql.= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 5e204ccd840..7f1420cb7ae 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -80,35 +80,35 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') // Define constant for TCPDF define('K_TCPDF_EXTERNAL_CONFIG',1); // this avoid using tcpdf_config file - define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/'); + define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/'); define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/'); dol_mkdir(K_PATH_CACHE); - define('K_BLANK_IMAGE', '_blank.png'); - define('PDF_PAGE_FORMAT', 'A4'); - define('PDF_PAGE_ORIENTATION', 'P'); - define('PDF_CREATOR', 'TCPDF'); - define('PDF_AUTHOR', 'TCPDF'); - define('PDF_HEADER_TITLE', 'TCPDF Example'); - define('PDF_HEADER_STRING', "by Dolibarr ERP CRM"); - define('PDF_UNIT', 'mm'); - define('PDF_MARGIN_HEADER', 5); - define('PDF_MARGIN_FOOTER', 10); - define('PDF_MARGIN_TOP', 27); - define('PDF_MARGIN_BOTTOM', 25); - define('PDF_MARGIN_LEFT', 15); - define('PDF_MARGIN_RIGHT', 15); - define('PDF_FONT_NAME_MAIN', 'helvetica'); - define('PDF_FONT_SIZE_MAIN', 10); - define('PDF_FONT_NAME_DATA', 'helvetica'); - define('PDF_FONT_SIZE_DATA', 8); - define('PDF_FONT_MONOSPACED', 'courier'); - define('PDF_IMAGE_SCALE_RATIO', 1.25); - define('HEAD_MAGNIFICATION', 1.1); - define('K_CELL_HEIGHT_RATIO', 1.25); - define('K_TITLE_MAGNIFICATION', 1.3); - define('K_SMALL_RATIO', 2/3); - define('K_THAI_TOPCHARS', true); - define('K_TCPDF_CALLS_IN_HTML', true); + define('K_BLANK_IMAGE', '_blank.png'); + define('PDF_PAGE_FORMAT', 'A4'); + define('PDF_PAGE_ORIENTATION', 'P'); + define('PDF_CREATOR', 'TCPDF'); + define('PDF_AUTHOR', 'TCPDF'); + define('PDF_HEADER_TITLE', 'TCPDF Example'); + define('PDF_HEADER_STRING', "by Dolibarr ERP CRM"); + define('PDF_UNIT', 'mm'); + define('PDF_MARGIN_HEADER', 5); + define('PDF_MARGIN_FOOTER', 10); + define('PDF_MARGIN_TOP', 27); + define('PDF_MARGIN_BOTTOM', 25); + define('PDF_MARGIN_LEFT', 15); + define('PDF_MARGIN_RIGHT', 15); + define('PDF_FONT_NAME_MAIN', 'helvetica'); + define('PDF_FONT_SIZE_MAIN', 10); + define('PDF_FONT_NAME_DATA', 'helvetica'); + define('PDF_FONT_SIZE_DATA', 8); + define('PDF_FONT_MONOSPACED', 'courier'); + define('PDF_IMAGE_SCALE_RATIO', 1.25); + define('HEAD_MAGNIFICATION', 1.1); + define('K_CELL_HEIGHT_RATIO', 1.25); + define('K_TITLE_MAGNIFICATION', 1.3); + define('K_SMALL_RATIO', 2/3); + define('K_THAI_TOPCHARS', true); + define('K_TCPDF_CALLS_IN_HTML', true); define('K_TCPDF_THROW_EXCEPTION_ERROR', false); diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 7bb397b5019..f574d5b0479 100755 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -466,7 +466,7 @@ class pdf_crabe extends ModelePDFFactures // Pied de page $this->_pagefoot($pdf,$object,$outputlangs); - if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); + if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); $pdf->Close(); From e727100cf0da231d80b8f135b116f2a2c877d9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Mon, 10 Jun 2013 00:11:25 +0200 Subject: [PATCH 2/2] New: Clone product/service composition --- ChangeLog | 1 + htdocs/langs/en_US/products.lang | 2 ++ htdocs/langs/es_ES/products.lang | 2 ++ htdocs/product/class/product.class.php | 19 +++++++++++++++++++ htdocs/product/fiche.php | 21 ++++++++++++++++++--- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fee8521e36..c7197e0af87 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 For translators: - Normalized sort order of all languages files with english ref file. 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 0652171833d..132220deec9 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 @@ -164,6 +165,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 0a8aed4634f..039765c4e99 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 {