diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php
index 50b59761b1d..2022844d6fe 100644
--- a/htdocs/core/class/coreobject.class.php
+++ b/htdocs/core/class/coreobject.class.php
@@ -35,6 +35,7 @@ class CoreObject extends CommonObject {
public $date_0 = '1001-01-01 00:00:00'; //TODO there is a solution for this ?
+ public $error = '';
/*
* @var Array $_fields Fields to synchronize with Database
*/
@@ -244,6 +245,8 @@ class CoreObject extends CommonObject {
return $this->id;
}
else {
+ $this->error = $this->db->lasterror();
+
return false;
}
@@ -335,7 +338,7 @@ class CoreObject extends CommonObject {
if(empty($this->id )) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed
if(isset($this->to_delete) && $this->to_delete==true) {
- $this->delete();
+ $this->delete($user);
}
else {
@@ -345,13 +348,21 @@ class CoreObject extends CommonObject {
$query['rowid']=$this->id;
if(empty($this->no_update_tms))$query['tms'] = date('Y-m-d H:i:s');
- $this->db->update($this->table_element,$query,array('rowid'));
+ $res = $this->db->update($this->table_element,$query,array('rowid'));
- $this->id = $this->db->last_insert_id($this->table_element);
+ if($res) {
+
+ $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
- $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
+ $this->saveChild($user);
+
+ return true;
+ }
+ else{
+ $this->error = $this->db->lasterror();
- $this->saveChild($user);
+ return false;
+ }
}
return $this->id;
@@ -378,6 +389,9 @@ class CoreObject extends CommonObject {
return $this->id;
}
else{
+
+ $this->error = $this->db->lasterror();
+
return false;
}
diff --git a/htdocs/inventory/class/inventory.class.php b/htdocs/inventory/class/inventory.class.php
index b02d601854d..b39445807e9 100644
--- a/htdocs/inventory/class/inventory.class.php
+++ b/htdocs/inventory/class/inventory.class.php
@@ -86,7 +86,7 @@ class Inventory extends CoreObject
}
- private function sort_det()
+ public function sort_det()
{
if(!empty($this->Inventorydet)) usort($this->Inventorydet, array('Inventory', 'customSort'));
@@ -129,22 +129,23 @@ class Inventory extends CoreObject
return $r;
}
- public function changePMP() {
-
- foreach ($this->Inventorydet as $k => &$Inventorydet)
- {
-
- if($Inventorydet->new_pmp>0) {
- $Inventorydet->pmp = $Inventorydet->new_pmp;
- $Inventorydet->new_pmp = 0;
-
- $db->query("UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".$Inventorydet->pmp."
- WHERE rowid = ".$Inventorydet->fk_product );
+ public function changePMP(User &$user) {
+ if(!empty($this->Inventorydet)) {
+ foreach ($this->Inventorydet as $k => &$Inventorydet)
+ {
+ if($Inventorydet->new_pmp>0) {
+ $Inventorydet->pmp = $Inventorydet->new_pmp;
+ $Inventorydet->new_pmp = 0;
+
+ $this->db->query("UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".$Inventorydet->pmp."
+ WHERE rowid = ".$Inventorydet->fk_product );
+
+ }
}
}
- parent::save($PDOdb);
+ return parent::update($user);
}
@@ -214,6 +215,7 @@ class Inventory extends CoreObject
if(empty($date))$date = $this->get_date('datec', 'Y-m-d');
$det->setStockDate( $date , $fk_entrepot);
+ return true;
}
public function correct_stock($fk_product, $fk_warehouse, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
@@ -233,6 +235,9 @@ class Inventory extends CoreObject
$datem = empty($conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT) ? dol_now() : $this->date_inventory;
$movementstock=new MouvementStock($db);
+ $movementstock->origin = new stdClass();
+ $movementstock->origin->element = 'inventory';
+ $movementstock->origin->id = $this->id;
$result=$movementstock->_create($user,$fk_product,$fk_warehouse,$op[$movement],$movement,$price,$label,$inventorycode, $datem);
if ($result >= 0)
@@ -289,10 +294,7 @@ class Inventory extends CoreObject
$href = dol_buildpath('/inventory/inventory.php?id='.$this->id.'&action=view', 1);
- if(empty($this->title))
- $this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock', $href, $this->id));
- else
- $this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStockWithNomInventaire', $href, $this->title));
+ $this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock'));
}
}
@@ -304,12 +306,15 @@ class Inventory extends CoreObject
return 1;
}
- public function getNomUrl($picto = 1) {
+ public function getTitle() {
global $langs;
- $title = !empty($this->title) ? $this->title : $langs->trans('inventoryTitle').' '.$this->id;
-
- return ''.($picto ? img_picto('','object_list.png','',0).' ' : '').$title.'';
+ return !empty($this->title) ? $this->title : $langs->trans('inventoryTitle').' '.$this->id;
+ }
+
+ public function getNomUrl($picto = 1) {
+
+ return ''.($picto ? img_picto('','object_list.png','',0).' ' : '').$this->getTitle().'';
}
diff --git a/htdocs/inventory/inventory.php b/htdocs/inventory/inventory.php
index b03627d326a..5a87eb94ceb 100644
--- a/htdocs/inventory/inventory.php
+++ b/htdocs/inventory/inventory.php
@@ -77,16 +77,25 @@ function _action()
$inventory->set_values($_POST);
$fk_inventory = $inventory->create($user);
-
- $fk_category = (int)GETPOST('fk_category');
- $fk_supplier = (int)GETPOST('fk_supplier');
- $fk_warehouse = (int)GETPOST('fk_warehouse');
- $only_prods_in_stock = (int)GETPOST('OnlyProdsInStock');
+ if($fk_inventory>0) {
+
+ $fk_category = (int)GETPOST('fk_category');
+ $fk_supplier = (int)GETPOST('fk_supplier');
+ $fk_warehouse = (int)GETPOST('fk_warehouse');
+ $only_prods_in_stock = (int)GETPOST('OnlyProdsInStock');
+
+ $inventory->add_products_for($fk_warehouse,$fk_category,$fk_supplier,$only_prods_in_stock);
+ $inventory->update($user);
+
+ header('Location: '.dol_buildpath('/inventory/inventory.php?id='.$inventory->id.'&action=edit', 1));
+
+ }
+ else{
+
+ setEventMessage($inventory->error,'errors');
+ header('Location: '.dol_buildpath('/inventory/inventory.php?action=create', 1));
+ }
- $inventory->add_products_for($fk_warehouse,$fk_category,$fk_supplier,$only_prods_in_stock);
- $inventory->update($user);
-
- header('Location: '.dol_buildpath('inventory/inventory.php?id='.$inventory->id.'&action=edit', 1));
break;
case 'edit':
@@ -118,14 +127,14 @@ function _action()
}
else
{
- $inventory->save($PDOdb);
+ $inventory->udpate($user);
header('Location: '.dol_buildpath('inventory/inventory.php?id='.$inventory->getId().'&action=view', 1));
}
break;
- case 'regulate':
-
+ case 'confirm_regulate':
+ if (!$user->rights->inventory->write) accessforbidden();
$id = GETPOST('id');
$inventory = new Inventory($db);
@@ -145,14 +154,14 @@ function _action()
break;
- case 'changePMP':
+ case 'confirm_changePMP':
$id = GETPOST('id');
$inventory = new Inventory($db);
$inventory->fetch( $id );
- $inventory->changePMP($PDOdb);
+ $inventory->changePMP($user);
_card( $inventory, 'view');
@@ -167,35 +176,33 @@ function _action()
$inventory = new Inventory($db);
$inventory->fetch( $id );
- $type = (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) ? 'string' : 'int'); //AA heu ?
-
- $fk_product = __get('fk_product', 0, $type);
-
- if ($fk_product)
+ $fk_product = GETPOST('fk_product');
+ if ($fk_product>0)
{
$product = new Product($db);
- $product->fetch($fk_product); // ! ref TODO vérifier quand même
- if($product->type != 0) {
+ if($product->fetch($fk_product)<=0 || $product->type != 0) {
setEventMessage($langs->trans('ThisIsNotAProduct'),'errors');
}
else{
//Check product not already exists
$alreadyExists = false;
- foreach ($inventory->Inventorydet as $invdet)
- {
- if ($invdet->fk_product == $product->id
- && $invdet->fk_warehouse == $fk_warehouse)
+ if(!empty($inventory->Inventorydet)) {
+ foreach ($inventory->Inventorydet as $invdet)
{
- $alreadyExists = true;
- break;
+ if ($invdet->fk_product == $product->id
+ && $invdet->fk_warehouse == $fk_warehouse)
+ {
+ $alreadyExists = true;
+ break;
+ }
}
}
-
if (!$alreadyExists)
{
- $inventory->add_product($PDOdb, $product->id, $fk_warehouse);
-
+ if($inventory->add_product($product->id, $fk_warehouse)) {
+ setEventMessage($langs->trans('ProductAdded'));
+ }
}
else
{
@@ -204,7 +211,7 @@ function _action()
}
- $inventory->save($PDOdb);
+ $inventory->update($user);
$inventory->sort_det();
}
@@ -212,7 +219,7 @@ function _action()
break;
- case 'delete_line':
+ case 'confirm_delete_line':
if (!$user->rights->inventory->write) accessforbidden();
@@ -230,7 +237,7 @@ function _action()
_card($inventory, 'edit');
break;
- case 'flush':
+ case 'confirm_flush':
if (!$user->rights->inventory->create) accessforbidden();
@@ -239,15 +246,15 @@ function _action()
$inventory = new Inventory($db);
$inventory->fetch($id);
- $inventory->deleteAllLine($PDOdb);
+ $inventory->deleteAllLine($user);
- setEventMessage('Inventaire vidé');
+ setEventMessage($langs->trans('InventoryFlushed'));
_card( $inventory, 'edit');
break;
- case 'delete':
+ case 'confirm_delete':
if (!$user->rights->inventory->create) accessforbidden();
@@ -258,7 +265,9 @@ function _action()
$inventory->delete($user);
- header('Location: '.dol_buildpath('/inventory/inventory.php', 1));
+ setEventMessage($langs->trans('InventoryDeleted'));
+
+ header('Location: '.dol_buildpath('/inventory/inventory.php?action=list', 1));
exit;
//_list();
@@ -407,19 +416,53 @@ function _card_warehouse(&$inventory)
llxFooter('');
}
-function _card(&$inventory, $mode='edit')
+function _card(&$inventory, $action='edit')
{
- global $langs, $conf, $db, $user;
+ global $langs, $conf, $db, $user,$form;
llxHeader('',$langs->trans('inventoryEdit'),'','');
+ if($action == 'changePMP') {
+
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('ApplyNewPMP')
+ ,$langs->trans('ConfirmApplyNewPMP',$inventory->getTitle()),'confirm_changePMP'
+ ,array(),'no',1);
+
+ }
+ else if($action == 'flush') {
+
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('FlushInventory')
+ ,$langs->trans('ConfirmFlushInventory',$inventory->getTitle()),'confirm_flush'
+ ,array(),'no',1);
+
+ }
+ else if($action == 'delete') {
+
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('Delete')
+ ,$langs->trans('ConfirmDelete',$inventory->getTitle()),'confirm_delete'
+ ,array(),'no',1);
+
+ }
+ else if($action == 'delete_line') {
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id.'&rowid='.GETPOST('rowid'),$langs->trans('DeleteLine')
+ ,$langs->trans('ConfirmDeleteLine',$inventory->getTitle()),'confirm_delete_line'
+ ,array(),'no',1);
+
+ }
+ else if($action == 'regulate') {
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$inventory->id,$langs->trans('RegulateStock')
+ ,$langs->trans('ConfirmRegulateStock',$inventory->getTitle()),'confirm_regulate'
+ ,array(),'no',1);
+
+ }
+
$warehouse = new Entrepot($db);
$warehouse->fetch($inventory->fk_warehouse);
- print dol_get_fiche_head(inventoryPrepareHead($inventory, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($mode) ? '': '&action='.$mode));
+ print dol_get_fiche_head(inventoryPrepareHead($inventory, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($action) ? '': '&action='.$action));
$lines = array();
- _card_line($inventory, $lines, $mode);
+ _card_line($inventory, $lines, $action);
print ''.$langs->trans('inventoryOnDate')." ".$inventory->get_date('date_inventory').'
';
@@ -439,7 +482,7 @@ function _card(&$inventory, $mode='edit')
$view_url = dol_buildpath('/inventory/inventory.php', 1);
$view = array(
- 'mode' => $mode
+ 'mode' => $action
,'url' => dol_buildpath('/inventory/inventory.php', 1)
,'can_validate' => (int) $user->rights->inventory->validate
,'is_already_validate' => (int) $inventory->status
@@ -486,7 +529,7 @@ function _card_line(&$inventory, &$lines, $mode)
,'qty_view' => $Inventorydet->qty_view ? $Inventorydet->qty_view : 0
,'qty_stock' => $stock
,'qty_regulated' => $Inventorydet->qty_regulated ? $Inventorydet->qty_regulated : 0
- ,'action' => ($user->rights->inventory->write ? ''.img_picto($langs->trans('inventoryDeleteLine'), 'delete').'' : '')
+ ,'action' => ($user->rights->inventory->write && $mode=='edit' ? ''.img_picto($langs->trans('inventoryDeleteLine'), 'delete').'' : '')
,'pmp_stock'=>round($pmp_actual,2)
,'pmp_actual'=> round($pmp * $Inventorydet->qty_view,2)
,'pmp_new'=>(!empty($user->rights->inventory->changePMP && $mode =='edit') ? ' '.img_picto($langs->trans('Save'), 'bt-save.png@inventory').'' : price($Inventorydet->new_pmp))
diff --git a/htdocs/inventory/tpl/inventory.tpl.php b/htdocs/inventory/tpl/inventory.tpl.php
index c3c1347446b..d707ec581b1 100644
--- a/htdocs/inventory/tpl/inventory.tpl.php
+++ b/htdocs/inventory/tpl/inventory.tpl.php
@@ -159,44 +159,40 @@
}
_footerList($view,$total_pmp,$total_pmp_actual,$total_pa,$total_pa_actual, $total_current_pa,$total_current_pa_actual);
- ?>
-
-
+ ?>
-
+ status != 1) { ?>