From f3cd9da73d74ad10c8631dab575dcd5a45d08c38 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Wed, 12 Aug 2015 21:48:00 +0200 Subject: [PATCH 1/9] Resource fixes --- htdocs/resource/card.php | 24 ++++++++++++++++++++++++ htdocs/resource/class/resource.class.php | 12 ++++++------ htdocs/resource/element_resource.php | 22 ++++++++-------------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index abb07820fa0..5007c70e867 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -44,6 +44,7 @@ $id = GETPOST('id','int'); $action = GETPOST('action','alpha'); $ref = GETPOST('ref'); $description = GETPOST('description'); +$confirm = GETPOST('confirm'); $fk_code_type_resource = GETPOST('fk_code_type_resource','alpha'); // Protection if external user @@ -111,6 +112,29 @@ if (empty($reshook)) $action='edit'; } } + + if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && $confirm === 'yes') + { + $res = $object->fetch($id); + if($res > 0) + { + $result = $object->delete($id); + + if ($result >= 0) + { + setEventMessage($langs->trans('RessourceSuccessfullyDeleted')); + Header('Location: '.DOL_URL_ROOT.'/resource/list.php'); + exit; + } + else { + setEventMessage($object->error,'errors'); + } + } + else + { + setEventMessage($object->error,'errors'); + } + } } diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php index cac917fa85b..3c3f0ee6e49 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/resource.class.php @@ -84,7 +84,7 @@ class Resource extends CommonObject // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."resource("; + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; $sql.= " entity,"; $sql.= "ref,"; @@ -114,7 +114,7 @@ class Resource extends CommonObject if (! $error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."place"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); if (! $notrigger) { @@ -164,7 +164,7 @@ class Resource extends CommonObject $sql.= " t.note_private,"; $sql.= " t.tms,"; $sql.= " ty.label as type_label"; - $sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; $sql.= " WHERE t.rowid = ".$this->db->escape($id); @@ -216,7 +216,7 @@ class Resource extends CommonObject if (isset($this->description)) $this->description=trim($this->description); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."resource SET"; + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; $sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").","; @@ -340,7 +340,7 @@ class Resource extends CommonObject // End call triggers } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."resource"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " WHERE rowid =".$rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -386,7 +386,7 @@ class Resource extends CommonObject $sql.= " t.fk_code_type_resource,"; $sql.= " t.tms,"; $sql.= " ty.label as type_label"; - $sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; $sql.= " WHERE t.entity IN (".getEntity('resource',1).")"; diff --git a/htdocs/resource/element_resource.php b/htdocs/resource/element_resource.php index 123673654c9..148d2d3b39d 100644 --- a/htdocs/resource/element_resource.php +++ b/htdocs/resource/element_resource.php @@ -34,16 +34,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $langs->load("resource"); $langs->load("other"); -// Get parameters -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$mode = GETPOST('mode','alpha'); -$lineid = GETPOST('lineid','int'); -$element = GETPOST('element','alpha'); -$element_id = GETPOST('element_id','int'); -$resource_id = GETPOST('resource_id','int'); -$resource_type = GETPOST('resource_type','alpha'); - /* $sortorder = GETPOST('sortorder','alpha'); $sortfield = GETPOST('sortfield','alpha'); @@ -80,7 +70,11 @@ $confirm = GETPOST('confirm','alpha'); if($action == 'add_element_resource' && ! $cancel) { $objstat = fetchObjectByElement($element_id,$element); - $res = $objstat->add_element_resource($resource_id,$resource_type,$busy,$mandatory); + $res = 0; + if ($resource_id >= 0) + { + $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); + } if($res > 0) { setEventMessage($langs->trans('ResourceLinkedWithSuccess'),'mesgs'); @@ -89,7 +83,7 @@ if($action == 'add_element_resource' && ! $cancel) } else { - setEventMessage($langs->trans('ErrorWhenLinkingResource'),'errors'); + setEventMessage($langs->trans('ErrorWhenLinkingResource') . " " . $objstat->error, 'errors'); header("Location: ".$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_type.'&element='.$element.'&element_id='.$element_id); exit; } @@ -142,7 +136,7 @@ if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->dele } } -$parameters=array('resource_id'=>resource_id); +$parameters=array('resource_id'=>$resource_id); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -254,7 +248,7 @@ else - foreach ($object->available_resources as $modresources => $resources) + foreach ($object->available_resources as $modresources => $resources) { $resources=(array) $resources; // To be sure $resources is an array foreach($resources as $resource_obj) From 2e1e9017c6961ef23b7183e00c255a04091e6717 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Wed, 12 Aug 2015 22:00:51 +0200 Subject: [PATCH 2/9] Missed the file --- htdocs/core/tpl/resource_add.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/resource_add.tpl.php b/htdocs/core/tpl/resource_add.tpl.php index d16b8b629f8..f63e8385f69 100644 --- a/htdocs/core/tpl/resource_add.tpl.php +++ b/htdocs/core/tpl/resource_add.tpl.php @@ -14,7 +14,7 @@ $out .= ''; $out .= ''; $out .= ''; $out .= ''; -$out .= ''; +$out .= ''; // Place From 2abb90713e1bfa999aa75739eaafd1e2f9e9095b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Aug 2015 17:35:05 +0200 Subject: [PATCH 3/9] Fix list of resource not visible --- htdocs/core/class/commonobject.class.php | 6 +++--- htdocs/core/lib/functions2.lib.php | 20 ++++++++++---------- htdocs/core/tpl/resource_add.tpl.php | 4 ++-- htdocs/resource/element_resource.php | 11 ++++------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 69f1c6df145..58597862f8c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3277,12 +3277,12 @@ abstract class CommonObject * Need $this->element & $this->id * * @param int $resource_id Resource id - * @param string $resource_element Resource element + * @param string $resource_type 'resource' * @param int $busy Busy or not * @param int $mandatory Mandatory or not * @return int <=0 if KO, >0 if OK */ - function add_element_resource($resource_id,$resource_element,$busy=0,$mandatory=0) + function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) { $this->db->begin(); @@ -3295,7 +3295,7 @@ abstract class CommonObject $sql.= ", mandatory"; $sql.= ") VALUES ("; $sql.= $resource_id; - $sql.= ", '".$resource_element."'"; + $sql.= ", '".$resource_type."'"; $sql.= ", '".$this->id."'"; $sql.= ", '".$this->element."'"; $sql.= ", '".$busy."'"; diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index de3b112e37f..9c77729ac5a 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1791,10 +1791,10 @@ function cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent) /** * Get an array with properties of an element -* -* @param string $element_type Element type. ex : project_task or object@modulext or object_under@module -* @return array (module, classpath, element, subelement, classfile, classname) -*/ + * + * @param string $element_type Element type: 'action', 'facture', 'project_task' or 'object@modulext'... + * @return array (module, classpath, element, subelement, classfile, classname) + */ function getElementProperties($element_type) { // Parse element/subelement (ex: project_task) @@ -1887,15 +1887,15 @@ function getElementProperties($element_type) } /** - * Fetch an object with element_type and its id + * Fetch an object from its id and element_type * Inclusion classes is automatic * - * @param int $element_id Element id - * @param string $element_type Element type - * @return object || 0 || -1 if error + * @param int $element_id Element id + * @param string $element_type Element type + * @return int|object object || 0 || -1 if error */ -function fetchObjectByElement($element_id,$element_type) { - +function fetchObjectByElement($element_id, $element_type) +{ global $conf; global $db,$conf; diff --git a/htdocs/core/tpl/resource_add.tpl.php b/htdocs/core/tpl/resource_add.tpl.php index d16b8b629f8..38733726b85 100644 --- a/htdocs/core/tpl/resource_add.tpl.php +++ b/htdocs/core/tpl/resource_add.tpl.php @@ -14,7 +14,7 @@ $out .= ''; $out .= ''; $out .= ''; $out .= ''; -$out .= ''; +$out .= ''; // Place @@ -37,4 +37,4 @@ $out .= '
'; print $out; -// FIN DU TPL +// END BEGIN TPL RESOURCE_ADD.TPL.PHP diff --git a/htdocs/resource/element_resource.php b/htdocs/resource/element_resource.php index 123673654c9..c7acae78333 100644 --- a/htdocs/resource/element_resource.php +++ b/htdocs/resource/element_resource.php @@ -63,23 +63,23 @@ $id = GETPOST('id','int'); $action = GETPOST('action','alpha'); $mode = GETPOST('mode','alpha'); $lineid = GETPOST('lineid','int'); -$element = GETPOST('element','alpha'); +$element = GETPOST('element','alpha'); // element_type $element_id = GETPOST('element_id','int'); $resource_id = GETPOST('fk_resource','int'); $resource_type = GETPOST('resource_type','alpha'); $busy = GETPOST('busy','int'); $mandatory = GETPOST('mandatory','int'); $cancel = GETPOST('cancel','alpha'); -$confirm = GETPOST('confirm','alpha'); +$confirm = GETPOST('confirm','alpha'); /* * Actions */ -if($action == 'add_element_resource' && ! $cancel) +if ($action == 'add_element_resource' && ! $cancel) { - $objstat = fetchObjectByElement($element_id,$element); + $objstat = fetchObjectByElement($element_id, $element); $res = $objstat->add_element_resource($resource_id,$resource_type,$busy,$mandatory); if($res > 0) { @@ -261,9 +261,6 @@ else { $element_prop = getElementProperties($resource_obj); - - - //print '/'.$modresources.'/class/'.$resource_obj.'.class.php
'; $path = ''; From 10d3c41358e04347aea95895f17c404325299ec6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Aug 2015 20:07:11 +0200 Subject: [PATCH 4/9] Fix Bad value into popup --- htdocs/comm/action/class/actioncomm.class.php | 7 ++++--- htdocs/core/class/html.formactions.class.php | 5 +---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index bc5bf9da9e3..b4336936181 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1041,9 +1041,9 @@ class ActionComm extends CommonObject * Use $this->id, $this->type_code, $this->label and $this->type_label * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $maxlength Nombre de caracteres max dans libelle + * @param int $maxlength Max number of charaters into label. If negative, use the ref as label. * @param string $classname Force style class on a link - * @param string $option ''=Link to action,'birthday'=Link to contact + * @param string $option ''=Link to action, 'birthday'=Link to contact * @param int $overwritepicto 1=Overwrite picto * @return string Chaine avec URL */ @@ -1075,7 +1075,8 @@ class ActionComm extends CommonObject { $libelle=(empty($this->libelle)?$label:$this->libelle.(($label && $label != $this->libelle)?' '.$label:'')); if (! empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($libelle)) $libelle=($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code)?$langs->transnoentities("Action".$this->type_code):$this->type_label; - $libelleshort=dol_trunc($libelle,$maxlength); + if ($maxlength < 0) $libelleshort=$this->ref; + else $libelleshort=dol_trunc($libelle,$maxlength); } if ($withpicto) diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 9322680a682..15bb1b8b43d 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -196,10 +196,7 @@ class FormActions foreach($listofactions as $action) { - $savlabel=$action->label; - $action->label=$action->ref; - $ref=$action->getNomUrl(1); - $action->label=$savlabel; + $ref=$action->getNomUrl(1,-1); $label=$action->getNomUrl(0,38); $var=!$var; From d4081936571c728b93bf7a83d712a0eded61cef3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Aug 2015 20:37:20 +0200 Subject: [PATCH 5/9] Fix: When stock is empty, no information was visible to explain why create button does not work. --- htdocs/expedition/card.php | 63 ++++++++++++++++++++------------ htdocs/langs/en_US/sendings.lang | 1 + 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 9cee623b679..af1c4d4db13 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -669,9 +669,10 @@ if ($action == 'create') print ''.$langs->trans("QtyOrdered").''; print ''.$langs->trans("QtyShipped").''; print ''.$langs->trans("QtyToShip"); - if (empty($conf->productbatch->enabled)) { - print '
('.$langs->trans("Fill").''; - print ' / '.$langs->trans("Reset").')'; + if (empty($conf->productbatch->enabled)) + { + print '
('.$langs->trans("Fill").''; + print ' / '.$langs->trans("Reset").')'; } print ''; if (! empty($conf->stock->enabled)) @@ -848,31 +849,45 @@ if ($action == 'create') else { print ''; // end line and start a new one for lot/serial + + $staticwarehouse=new Entrepot($db); + $staticwarehouse->fetch($warehouse_id); + $subj=0; print ''; - foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) + if (count($product->stock_warehouse[$warehouse_id]->detail_batch)) { - //var_dump($dbatch); - $substock=$dbatch->qty +0 ; - print ''; - print ''; - print ''; - - print ''; - - $staticwarehouse=new Entrepot($db); - $staticwarehouse->fetch($warehouse_id); - print $staticwarehouse->getNomUrl(0).' / '; - - print ''; - print ''; - print $langs->trans("DetailBatchFormat", $dbatch->batch, dol_print_date($dbatch->eatby,"day"), dol_print_date($dbatch->sellby,"day"), $dbatch->qty); - if ($defaultqty<=0) { - $defaultqty=0; - } else { - $defaultqty -=min($defaultqty,$substock); + foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) + { + //var_dump($dbatch); + $substock=$dbatch->qty +0 ; // To get a numeric + print ''; + print ''; + print ''; + + print ''; + + print $staticwarehouse->getNomUrl(0).' / '; + + print ''; + print ''; + print $langs->trans("DetailBatchFormat", $dbatch->batch, dol_print_date($dbatch->eatby,"day"), dol_print_date($dbatch->sellby,"day"), $dbatch->qty); + if ($defaultqty<=0) { + $defaultqty=0; + } else { + $defaultqty -= min($defaultqty,$substock); + } + $subj++; } - $subj++; + } + else + { + print ''; + print ' '; + print ''; + + print ''; + print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->libelle); } } diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 4d4aca48cd9..53a4e4dae7a 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -69,6 +69,7 @@ ProductQtyInCustomersOrdersRunning=Product quantity into opened customers orders ProductQtyInSuppliersOrdersRunning=Product quantity into opened suppliers orders ProductQtyInShipmentAlreadySent=Product quantity from opened customer order already sent ProductQtyInSuppliersShipmentAlreadyRecevied=Product quantity from opened supplier order already received +NoProductToShipFoundIntoStock=No product to ship found into warehouse %s. Correct sotck or go back to choose another warehouse. # Sending methods SendingMethodCATCH=Catch by customer From 3bdd342df15ba1961eded3a4486cc65a1dccd64f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Aug 2015 23:53:59 +0200 Subject: [PATCH 6/9] Fix #3116 --- htdocs/expedition/card.php | 39 ++++++---- htdocs/expedition/class/expedition.class.php | 64 ++++++++++------ htdocs/product/class/productbatch.class.php | 21 ++++-- .../stock/class/mouvementstock.class.php | 74 ++++++++++++------- 4 files changed, 131 insertions(+), 67 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index af1c4d4db13..ffc453d395c 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -76,7 +76,7 @@ $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($co $object = new Expedition($db); -// Load object +// Load object. Make an object->fetch include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -160,6 +160,7 @@ if (empty($reshook)) $num=count($objectsrc->lines); $totalqty=0; + for ($i = 0; $i < $num; $i++) { $idl="idl".$i; @@ -178,11 +179,12 @@ if (empty($reshook)) while (isset($_POST[$batch])) { // save line of detail into sub_qty - $sub_qty[$j]['q']=GETPOST($qty,'int'); - $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); - + $sub_qty[$j]['q']=GETPOST($qty,'int'); // the qty we want to move for this stock record + $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); // the id into llx_product_batch of stock record to move $subtotalqty+=$sub_qty[$j]['q']; - + + //var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']); + $j++; $batch="batchl".$i."_".$j; $qty = "qtyl".$i.'_'.$j; @@ -200,6 +202,8 @@ if (empty($reshook)) if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int'); } } + + //var_dump($batch_line[2]); if ($totalqty > 0) // There is at least one thing to ship { @@ -208,7 +212,8 @@ if (empty($reshook)) { $qty = "qtyl".$i; if (! isset($batch_line[$i])) - { // not batch mode + { + // not batch mode if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) { $ent = "entl".$i; @@ -225,7 +230,8 @@ if (empty($reshook)) } } else - { // batch mode + { + // batch mode if ($batch_line[$i]['qty']>0) { $ret=$object->addline_batch($batch_line[$i]); @@ -1257,8 +1263,8 @@ else if ($id || $ref) print "\n"; /* - * Lignes produits - */ + * Lines of products + */ print '
'; print ''; if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) @@ -1417,12 +1423,19 @@ else if ($id || $ref) if (isset($lines[$i]->detail_batch)) { print ''; } else { print ''; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 3699399bdca..5863161a995 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -391,7 +391,7 @@ class Expedition extends CommonObject /** - * Create a expedition line with eat-by date + * Create the detail (eat-by date) of the expedition line * * @param object $line_ext full line informations * @return int <0 if KO, >0 if OK @@ -626,9 +626,12 @@ class Expedition extends CommonObject // Loop on each product line to add a stock movement // TODO possibilite d'expedier a partir d'une propale ou autre origine - $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid"; + $sql = "SELECT cd.fk_product, cd.subprice,"; + $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,"; + $sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty, edb.fk_origin_stock"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,"; $sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid"; $sql.= " WHERE ed.fk_expedition = ".$this->id; $sql.= " AND cd.rowid = ed.fk_origin_line"; @@ -640,27 +643,38 @@ class Expedition extends CommonObject for ($i = 0; $i < $cpt; $i++) { $obj = $this->db->fetch_object($resql); - if($obj->qty <= 0) continue; - dol_syslog(get_class($this)."::valid movement index ".$i); + if ($obj->qty <= 0) continue; + dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid); //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; - // We decrement stock of product (and sub-products) - // We use warehouse selected for each line - $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref)); - if ($result < 0) { $error++; break; } - - if (! empty($conf->productbatch->enabled)) + + if (empty($obj->edbrowid)) { - $details=ExpeditionLineBatch::fetchAll($this->db,$obj->rowid); - if (! empty($details)) + // line without batch detail + + // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record + $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref)); + if ($result < 0) { + $error++; break; + } + } + else + { + // line with batch detail + + // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record + $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref), '', $obj->eatby, $obj->sellby, $obj->batch); + if ($result < 0) { + $error++; break; + } + + // We update content of table llx_product_batch (will be rename into llx_product_stock_batch inantoher version) + if (! empty($conf->productbatch->enabled)) { - foreach ($details as $dbatch) - { - $result=$mouvS->livraison_batch($dbatch->fk_origin_stock,$dbatch->dluo_qty); - if ($result < 0) { $error++; $this->errors[]=$mouvS->$error; break 2; } - } + $result=$mouvS->livraison_batch($obj->fk_origin_stock, $obj->qty); // ->fk_origin_stock = id into table llx_product_batch (will be rename into llx_product_stock_batch in another version) + if ($result < 0) { $error++; $this->errors[]=$mouvS->error; break; } } } } @@ -672,7 +686,7 @@ class Expedition extends CommonObject return -2; } } - + if (! $error && ! $notrigger) { // Call trigger @@ -843,6 +857,10 @@ class Expedition extends CommonObject { if ($value['q']>0) { + // $value['q']=qty to move + // $value['id_batch']=id into llx_product_batch of record to move + //var_dump($value); + $linebatch = new ExpeditionLineBatch($this->db); $ret=$linebatch->fetchFromStock($value['id_batch']); // load serial, sellby, eatby if ($ret<0) @@ -857,13 +875,16 @@ class Expedition extends CommonObject { // TODO } - + + //var_dump($linebatch); } } $line->entrepot_id = $linebatch->entrepot_id; $line->origin_line_id = $dbatch['ix_l']; $line->qty = $dbatch['qty']; $line->detail_batch=$tab; + + //var_dump($line); $this->lines[$num] = $line; } } @@ -1146,9 +1167,9 @@ class Expedition extends CommonObject $sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked"; $sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva"; $sql.= ", cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.price, cd.subprice, cd.remise_percent"; - $sql.= ", ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; + $sql.= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; $sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type"; - $sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, ed.rowid as line_id"; + $sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch"; $sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,"; $sql.= " ".MAIN_DB_PREFIX."commandedet as cd)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product"; @@ -1202,6 +1223,7 @@ class Expedition extends CommonObject $line->product_ref = $obj->product_ref; $line->product_label = $obj->product_label; $line->libelle = $obj->product_label; // TODO deprecated + $line->product_tobatch = $obj->product_tobatch; $line->label = $obj->custom_label; $line->description = $obj->description; $line->qty_asked = $obj->qty_asked; diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index 5495584ea5f..8eac443c244 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -135,7 +135,7 @@ class Productbatch extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object + * @param int $id Id object * @return int <0 if KO, >0 if OK */ function fetch($id) @@ -201,6 +201,12 @@ class Productbatch extends CommonObject // Clean parameters $this->clean_param(); + // TODO Check qty is ok for stock move. Negative may not be allowed. + if ($this->qty < 0) + { + + } + // Update request $sql = "UPDATE ".MAIN_DB_PREFIX.self::$_table_element." SET"; $sql.= " fk_product_stock=".(isset($this->fk_product_stock)?$this->fk_product_stock:"null").","; @@ -389,11 +395,12 @@ class Productbatch extends CommonObject } /** - * Clean fields (triming) + * Clean fields (triming) * * @return void */ - private function clean_param() { + private function clean_param() + { if (isset($this->fk_product_stock)) $this->fk_product_stock=(int) trim($this->fk_product_stock); if (isset($this->batch)) $this->batch=trim($this->batch); if (isset($this->qty)) $this->qty=(float) trim($this->qty); @@ -403,11 +410,11 @@ class Productbatch extends CommonObject /** * Find first detail record that match eather eat-by or sell-by or batch within given warehouse * - * @param int $fk_product_stock id product_stock for objet - * @param date $eatby eat-by date for objet - * @param date $sellby sell-by date for objet + * @param int $fk_product_stock id product_stock for objet + * @param date $eatby eat-by date for objet + * @param date $sellby sell-by date for objet * @param string $batch_number batch number for objet - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK */ function find($fk_product_stock=0, $eatby='',$sellby='',$batch_number='') { diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 2e9fcfab68e..52c69b16ec6 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -229,8 +229,8 @@ class MouvementStock extends CommonObject $num = 0; if (! $error) { - $sql = "SELECT rowid, reel, pmp FROM ".MAIN_DB_PREFIX."product_stock"; - $sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product; + $sql = "SELECT rowid, reel FROM ".MAIN_DB_PREFIX."product_stock"; + $sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product; // This is a unique key dol_syslog(get_class($this)."::_create", LOG_DEBUG); $resql=$this->db->query($sql); @@ -327,7 +327,7 @@ class MouvementStock extends CommonObject $this->errors[]=$this->db->lasterror(); $error = -3; } - else if(empty($fk_product_stock)) + else if (empty($fk_product_stock)) { $fk_product_stock = $this->db->last_insert_id(MAIN_DB_PREFIX."product_stock"); } @@ -452,19 +452,22 @@ class MouvementStock extends CommonObject * @param int $price Price * @param string $label Label of stock movement * @param string $datem Force date of movement + * @param date $eatby eat-by date + * @param date $sellby sell-by date + * @param string $batch batch number * @return int <0 if KO, >0 if OK */ - function livraison($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $datem='') + function livraison($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $datem='', $eatby='', $sellby='', $batch='') { - return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label, '', $datem,'','','',true); + return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label, '', $datem, $eatby, $sellby, $batch, true); } /** * Decrease stock for batch record * * @param int $id_stock_dluo Id product_dluo - * @param int $qty Quantity - * @return int <0 if KO, >0 if OK + * @param int $qty Quantity + * @return int <0 if KO, >0 if OK */ function livraison_batch($id_stock_dluo, $qty) { @@ -543,10 +546,12 @@ class MouvementStock extends CommonObject } /** - * Create or update batch record + * Create or update batch record (update table llx_product_batch) * - * @param variant $dluo Could be either int if id of product_batch or array with at leat fk_product_stock - * @param int $qty Quantity of product with batch number + * @param array|int $dluo Could be either + * - int if id of product_batch + * - or complete array('fk_product_stock'=>, 'eatby'=>, 'sellby'=> , 'batchnumber'=>) + * @param int $qty Quantity of product with batch number. May be a negative amount. * @return int <0 if KO, else return productbatch id */ function _create_batch($dluo, $qty) @@ -555,44 +560,63 @@ class MouvementStock extends CommonObject $result=0; - // Try to find an existing record with batch same batch number or id - if (is_numeric($dluo)) { + // Try to find an existing record with same batch number or id + if (is_numeric($dluo)) + { $result=$pdluo->fetch($dluo); - } else if (is_array($dluo)) { - if (isset($dluo['fk_product_stock'])) { + if (empty($pdluo->id)) + { + // We didn't find the line. May be it was deleted before by a previous move in same transaction. + $this->error = 'Error. You ask a move on a record for a serial that does not exists anymore. May be you take the same serial on samewarehouse several times in same shipment or it was used by another shipment. Remove this shipment and prepare another one.'; + $this->errors[] = $this->error; + $result = -2; + } + } + else if (is_array($dluo)) + { + if (isset($dluo['fk_product_stock'])) + { $vfk_product_stock=$dluo['fk_product_stock']; $veatby = $dluo['eatby']; $vsellby = $dluo['sellby']; $vbatchnumber = $dluo['batchnumber']; + $result = $pdluo->find($vfk_product_stock,$veatby,$vsellby,$vbatchnumber); - } else { + } + else + { dol_syslog(get_class($this)."::_create_batch array param dluo must contain at least key fk_product_stock".$error, LOG_ERR); $result = -1; } - } else { + } + else + { dol_syslog(get_class($this)."::_create_batch error invalid param dluo".$error, LOG_ERR); $result = -1; } - // Batch record found so we update it - if ($result>0) + if ($result >= 0) { - if ($pdluo->id >0) + // No error + if ($pdluo->id > 0) // product_batch record found { - $pdluo->qty +=$qty; - if ($pdluo->qty == 0) { + //print "Avant ".$pdluo->qty." Apres ".($pdluo->qty + $qty)."
"; + $pdluo->qty += $qty; + if ($pdluo->qty == 0) + { $result=$pdluo->delete(0,1); } else { $result=$pdluo->update(0,1); } } - else + else // product_batch record not found { $pdluo->fk_product_stock=$vfk_product_stock; $pdluo->qty = $qty; $pdluo->eatby = $veatby; $pdluo->sellby = $vsellby; $pdluo->batch = $vbatchnumber; + $result=$pdluo->create(0,1); if ($result < 0) { @@ -600,11 +624,9 @@ class MouvementStock extends CommonObject $this->errors=$pdluo->errors; } } - return $result; - } else { - return -1; } - + + return $result; } /** From d9b3069813754d88f750edf9bee33149b4bf39d6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 15 Aug 2015 02:34:15 +0200 Subject: [PATCH 7/9] Fix: When validation and approval where done in same step, label of action used always label for validation. --- .../triggers/interface_50_modAgenda_ActionsAuto.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 8a77bf86b4f..0912e7aee10 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -678,10 +678,10 @@ class InterfaceActionsAuto extends DolibarrTriggers // Add entry in event table $now=dol_now(); - if(isset($_SESSION['listofnames'])) + if (isset($_SESSION['listofnames'])) { $attachs=$_SESSION['listofnames']; - if($attachs && strpos($action,'SENTBYMAIL')) + if ($attachs && strpos($action,'SENTBYMAIL')) { $object->actionmsg.="\n".$langs->transnoentities("AttachedFiles").': '.$attachs; } @@ -719,6 +719,9 @@ class InterfaceActionsAuto extends DolibarrTriggers $actioncomm->elementtype = $object->element; $ret=$actioncomm->add($user); // User qui saisit l'action + + unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse vallue of first action. + if ($ret > 0) { $_SESSION['LAST_ACTION_CREATED'] = $ret; From 52240eec9aa7e688b999886ff356f837e6583b18 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 15 Aug 2015 02:44:05 +0200 Subject: [PATCH 8/9] Fix removed warnings --- htdocs/core/class/html.formactions.class.php | 2 +- htdocs/core/lib/functions.lib.php | 4 ++-- htdocs/fourn/commande/card.php | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 15bb1b8b43d..60fbdc0c467 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -179,7 +179,7 @@ class FormActions elseif ($typeelement == 'fichinter') $title=$langs->trans('ActionsOnFicheInter'); else $title=$langs->trans("Actions"); - print_titre($title); + print load_fiche_titre($title,'',''); $total = 0; $var=true; print '
'; - $detail = ''; - foreach ($lines[$i]->detail_batch as $dbatch) + if ($lines[$i]->product_tobatch) { - $detail.= $langs->trans("DetailBatchFormat",$dbatch->batch,dol_print_date($dbatch->eatby,"day"),dol_print_date($dbatch->sellby,"day"),$dbatch->dluo_qty).'
'; + $detail = ''; + foreach ($lines[$i]->detail_batch as $dbatch) + { + $detail.= $langs->trans("DetailBatchFormat",$dbatch->batch,dol_print_date($dbatch->eatby,"day"),dol_print_date($dbatch->sellby,"day"),$dbatch->dluo_qty).'
'; + } + print $form->textwithtooltip($langs->trans("DetailBatchNumber"),$detail); + } + else + { + print $langs->trans("NA"); } - print $form->textwithtooltip($langs->trans("DetailBatchNumber"),$detail); print '
'; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5f45496b950..e0a7ec1b9f2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2730,8 +2730,8 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m * * @param string $title Title to show * @return string Title to show - * @deprecated Use print_fiche_titre instead - * @see print_fiche_titre + * @deprecated Use load_fiche_titre instead + * @see print_fiche_titre, load_fiche_titre */ function print_titre($title) { diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 9ca609c154c..9b0001e79d6 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1612,9 +1612,10 @@ if ($action=='create') print "\n"; // Show origin lines - if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) + { $title = $langs->trans('ProductsAndServices'); - print_titre($title); + print load_fiche_titre($title,'',''); print '
'; @@ -2395,7 +2396,7 @@ elseif (! empty($object->id)) 'entity'=>'' ); - print_titre($langs->trans('CreateRemoteOrder')); + print load_fiche_titre($langs->trans('CreateRemoteOrder'),''); //Is everything filled? if (empty($ws_url) || empty($ws_key)) { From f3c4e20db2857ad649fee53a97c7dc4e141c6844 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 15 Aug 2015 03:41:57 +0200 Subject: [PATCH 9/9] Fix centering of message on logon page --- htdocs/core/tpl/login.tpl.php | 2 +- htdocs/core/tpl/passwordforgotten.tpl.php | 4 ++-- htdocs/theme/eldy/style.css.php | 13 ++++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index e82650eda83..c0af2a25b74 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -222,7 +222,7 @@ if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file -