diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 7613a556092..75706403069 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -342,10 +342,10 @@ class CoreObject extends CommonObject { $query = array(); $query = $this->set_save_query(); - $query['id']=$this->id; + $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('id')); + $this->db->update($this->table_element,$query,array('rowid')); $this->id = $this->db->last_insert_id($this->table_element); @@ -382,19 +382,22 @@ class CoreObject extends CommonObject { } } - public function delete(){ + public function delete(User &$user){ if($this->id>0){ $this->call_trigger(strtoupper($this->element). '_DELETE', $user); - $this->db->delete($this->table_element,array('id'=>$this->id),array(0=>'id')); - if($this->withChild) { + $this->db->delete($this->table_element,array('rowid'=>$this->id),array('rowid')); + + if($this->withChild && !empty($this->childtables)) { foreach($this->childtables as &$childTable) { $className = ucfirst($childTable); - foreach($this->{$className} as &$object) { - - $object->delete(); - + if(!empty($this->{$className})) { + foreach($this->{$className} as &$object) { + + $object->delete($user); + + } } } diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index 85766c31949..da0717e665b 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -313,7 +313,6 @@ abstract class DoliDB implements Database function update($table,$fields,$key){ foreach ($fields as $k => $v) { - if(is_string($v)) $v=stripslashes($v); if (is_array($key)){ $i=array_search($k , $key ); @@ -328,10 +327,9 @@ abstract class DoliDB implements Database } } - $tmp[] = $k.'='.$this->quote($val); + $tmp[] = $k.'='.$this->quote($v); } - $sql = sprintf( 'UPDATE '.MAIN_DB_PREFIX.$table.' SET %s WHERE %s' , implode( ',', $tmp ) , implode(' AND ',$where) ); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET '.implode( ',', $tmp ).' WHERE ' . implode(' AND ',$where) ; $res = $this->query( $sql ); if($res===false) { @@ -358,7 +356,9 @@ abstract class DoliDB implements Database } - $sql = sprintf( 'INSERT INTO '.MAIN_DB_PREFIX.$table.' ( %s ) values( %s ) ', implode( ",", $keys ) , implode( ",", $values ) ); + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$table.' + ( '.implode( ",", $keys ).' ) + VALUES ( '.implode( ",", $values ).' ) '; $res = $this->query($sql); if($res===false) { @@ -379,26 +379,30 @@ abstract class DoliDB implements Database */ function delete($table,$fields,$key){ foreach ($fields as $k => $v) { - if(is_string($v)) $v=stripslashes($v); - if (is_array($key)){ $i=array_search($k , $key ); if ( $i !== false) { - $where[] = $key[$i]."=" . $this->escape( $v ) ; + $where[] = $key[$i].'=' . $this->quote( $v ) ; continue; } } else { if ( $k == $key) { - $where[] = "$k=" .$this->escape( $v ) ; + $where[] = $k.'='.$this->quote( $v ) ; continue; } } } - $sql = sprintf( 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.implode(' AND ',$where)); + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.implode(' AND ',$where); - return $this->query( $sql ); + $res = $this->query( $sql ); + if($res===false) { + return false; + } + + return true; + } } diff --git a/htdocs/inventory/admin/inventory_setup.php b/htdocs/inventory/admin/inventory_setup.php new file mode 100644 index 00000000000..f55bc092517 --- /dev/null +++ b/htdocs/inventory/admin/inventory_setup.php @@ -0,0 +1,168 @@ + + * Copyright (C) 2015 ATM Consulting + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file admin/inventory.php + * \ingroup inventory + * \brief This file is an example module setup page + * Put some comments here + */ +// Dolibarr environment +$res = @include("../../main.inc.php"); // From htdocs directory +if (! $res) { + $res = @include("../../../main.inc.php"); // From "custom" directory +} + +// Libraries +require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; +require_once '../lib/inventory.lib.php'; + +// Translations +$langs->load("inventory@inventory"); + +// Access control +if (! $user->admin) { + accessforbidden(); +} + +// Parameters +$action = GETPOST('action', 'alpha'); + +/* + * Actions + */ +if (preg_match('/set_(.*)/',$action,$reg)) +{ + $code=$reg[1]; + if (dolibarr_set_const($db, $code, GETPOST($code), 'chaine', 0, '', $conf->entity) > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dol_print_error($db); + } +} + +if (preg_match('/del_(.*)/',$action,$reg)) +{ + $code=$reg[1]; + if (dolibarr_del_const($db, $code, 0) > 0) + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dol_print_error($db); + } +} + +/* + * View + */ +$page_name = "inventorySetup"; +llxHeader('', $langs->trans($page_name)); + +// Subheader +$linkback = '' + . $langs->trans("BackToModuleList") . ''; +print_fiche_titre($langs->trans($page_name), $linkback); + +// Configuration header +$head = inventoryAdminPrepareHead(); +dol_fiche_head( + $head, + 'settings', + $langs->trans("Module104420Name"), + 0, + "inventory@inventory" +); + +// Setup page goes here +$form=new Form($db); +$var=false; +print ''; +print ''; +print ''."\n"; +print ''; +print ''."\n"; + + +// Example with a yes / no select +$var=!$var; +print ''; +print ''; +print ''; +print ''; + +// Example with a yes / no select +$var=!$var; +print ''; +print ''; +print ''; +print ''; + +// Example with a yes / no select +$var=!$var; +print ''; +print ''; +print ''; +print ''; + +// Example with a yes / no select +$var=!$var; +print ''; +print ''; +print ''; +print ''; + +print '
'.$langs->trans("Parameters").' '.$langs->trans("Value").'
'.$langs->trans("INVENTORY_GEN_PDF").' '; +print '
'; +print ''; +print ''; +print $form->selectyesno("INVENTORY_GEN_PDF",$conf->global->INVENTORY_GEN_PDF,1); +print ''; +print '
'; +print '
'.$langs->trans("INVENTORY_DISABLE_VIRTUAL").' '; +print '
'; +print ''; +print ''; +print $form->selectyesno("INVENTORY_DISABLE_VIRTUAL",$conf->global->INVENTORY_DISABLE_VIRTUAL,1); +print ''; +print '
'; +print '
'.$langs->trans("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA").' '; +print '
'; +print ''; +print ''; +print $form->selectyesno("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA",$conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA,1); +print ''; +print '
'; +print '
'.$langs->trans("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT").' '; +print '
'; +print ''; +print ''; +print $form->selectyesno("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT",$conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT,1); +print ''; +print '
'; +print '
'; + +llxFooter(); + +$db->close(); \ No newline at end of file diff --git a/htdocs/inventory/ajax/ajax.inventory.php b/htdocs/inventory/ajax/ajax.inventory.php index 34efecfab8f..f2f5ef54903 100644 --- a/htdocs/inventory/ajax/ajax.inventory.php +++ b/htdocs/inventory/ajax/ajax.inventory.php @@ -1,24 +1,21 @@ rights->inventory->write) { echo -1; exit; } $fk_det_inventory = GETPOST('fk_det_inventory'); - $det = new Inventorydet; - if( $det->load($PDOdb, $fk_det_inventory)) { + $det = new Inventorydet($db); + if( $det->fetch( $fk_det_inventory)) { $det->qty_view+=GETPOST('qty'); - $det->save($PDOdb); + $det->update($user); echo $det->qty_view; } @@ -33,10 +30,10 @@ $fk_det_inventory = GETPOST('fk_det_inventory'); - $det = new Inventorydet; - if( $det->load($PDOdb, $fk_det_inventory)) { + $det = new Inventorydet($db); + if( $det->fetch( $fk_det_inventory)) { $det->new_pmp=price2num(GETPOST('pmp')); - $det->save($PDOdb); + $det->update($user); echo $det->new_pmp; } diff --git a/htdocs/inventory/img/plus.png b/htdocs/inventory/img/plus.png new file mode 100644 index 00000000000..b7072a96960 Binary files /dev/null and b/htdocs/inventory/img/plus.png differ diff --git a/htdocs/inventory/img/plus16.png b/htdocs/inventory/img/plus16.png new file mode 100644 index 00000000000..ad17ac89391 Binary files /dev/null and b/htdocs/inventory/img/plus16.png differ diff --git a/htdocs/inventory/inventory.php b/htdocs/inventory/inventory.php index 1d9ec174257..ccda1b37c0e 100644 --- a/htdocs/inventory/inventory.php +++ b/htdocs/inventory/inventory.php @@ -131,7 +131,7 @@ function _action() if (!$user->rights->inventory->write) accessforbidden(); - $id = __get('id', 0, 'int'); + $id = GETPOST('id'); $inventory = new Inventory($db); $inventory->load($PDOdb, $id); @@ -153,7 +153,7 @@ function _action() case 'regulate': - $id = __get('id', 0, 'int'); + $id = GETPOST('id'); $inventory = new Inventory($db); $inventory->load($PDOdb, $id); @@ -174,10 +174,10 @@ function _action() case 'changePMP': - $id = __get('id', 0, 'int'); + $id = GETPOST('id'); $inventory = new Inventory($db); - $inventory->load($PDOdb, $id); + $inventory->fetch( $id ); $inventory->changePMP($PDOdb); @@ -188,12 +188,11 @@ function _action() case 'add_line': if (!$user->rights->inventory->write) accessforbidden(); - - $id = __get('id', 0, 'int'); - $fk_warehouse = __get('fk_warehouse', 0, 'int'); + $id = GETPOST('id'); + $fk_warehouse = GETPOST('fk_warehouse'); $inventory = new Inventory($db); - $inventory->load($PDOdb, $id); + $inventory->fetch( $id ); $type = (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT) ? 'string' : 'int'); //AA heu ? @@ -245,16 +244,17 @@ function _action() //Cette action devrais se faire uniquement si le status de l'inventaire est à 0 mais aucune vérif - $rowid = __get('rowid', 0, 'int'); - $Inventorydet = new Inventory($db); - $Inventorydet->load($PDOdb, $rowid); - $Inventorydet->delete($PDOdb); - - $id = __get('id', 0, 'int'); + $rowid = GETPOST('rowid'); + $Inventorydet = new Inventorydet($db); + if($Inventorydet->fetch($rowid)>0) { + $Inventorydet->delete($user); + setEventMessage("ProductDeletedFromInventory"); + } + $id = GETPOST('id'); $inventory = new Inventory($db); - $inventory->load($PDOdb, $id); + $inventory->fetch( $id); - _fiche($PDOdb, $user, $db, $conf, $langs, $inventory, 'edit'); + _card($inventory, 'edit'); break; case 'flush': @@ -519,16 +519,14 @@ function _card_line(&$inventory, &$lines, $mode) 'produit' => $product->getNomUrl(1).' - '.$product->label ,'entrepot'=>$e->getNomUrl(1) ,'barcode' => $product->barcode - ,'qty' =>($mode == 'edit' ? '' : $qty ) - .($mode =='edit' ? ''.img_picto($langs->trans('Add'), 'plus16@inventory').'' : '') + ,'qty' =>($mode == 'edit' ? ' '.img_picto($langs->trans('Add'), 'plus16@inventory').'' : '' ) ,'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').'' : '') ,'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').'' : '') : '') + ,'pmp_new'=>(!empty($user->rights->inventory->changePMP && $mode =='edit') ? ' '.img_picto($langs->trans('Save'), 'bt-save.png@inventory').'' : price($Inventorydet->new_pmp)) ,'pa_stock'=>round($last_pa * $stock,2) ,'pa_actual'=>round($last_pa * $Inventorydet->qty_view,2) ,'current_pa_stock'=>round($current_pa * $stock,2) @@ -656,24 +654,24 @@ function _headerList($view) { ?>   Produit - Entrepôt + trans('Warehouse'); ?> barcode->enabled)) { ?> - Code-barre + trans('Barcode'); ?> - Quantité théorique + trans('TheoricalQty'); ?> global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ - echo 'Valeur théorique'; + echo ''.$langs->trans('TheoricalValue').''; } else { - echo 'Valeur théorique'; + echo ''.$langs->trans('TheoricalValue').''; } ?> - Quantité réelle + trans('RealQty'); ?> global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) $colspan++; if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) $colspan++; - echo 'Valeur réelle'; + echo ''.$langs->trans('RealValue').''; ?> - Quantité régulée + trans('RegulatedQty'); ?> # - +   - PMP - Dernier PA + trans('PMP'); ?> + trans('LastPA'); ?> global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ - echo 'PA courant'; + echo ''.$langs->trans('CurrentPA').''; } ?>   - PMP + trans('PMP'); ?> rights->inventory->changePMP)) { echo ''.$langs->trans('ColumnNewPMP').''; } ?> - Dernier PA + trans('LastPA'); ?> global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ - echo 'PA courant'; + echo ''.$langs->trans('CurrentPA').''; } ?> diff --git a/htdocs/inventory/tpl/inventory.tpl.php b/htdocs/inventory/tpl/inventory.tpl.php index 8a3bfd0f2a6..c3c1347446b 100644 --- a/htdocs/inventory/tpl/inventory.tpl.php +++ b/htdocs/inventory/tpl/inventory.tpl.php @@ -8,7 +8,7 @@ $('#a_save_qty_'+k).hide(); $.ajax({ - url:"script/interface.php" + url:"ajax/ajax.inventory.php" ,data:{ 'fk_det_inventory' : fk_det_inventory ,'qty': qty @@ -37,7 +37,7 @@ $('#a_save_new_pmp_'+k).hide(); $.ajax({ - url:"script/interface.php" + url:"ajax/ajax.inventory.php" ,data:{ 'fk_det_inventory' : fk_det_inventory ,'pmp': pmp @@ -137,7 +137,7 @@ rights->inventory->changePMP)) { - echo ''.$row['pmp_new'].''; + echo ''.$row['pmp_new'].''; } ?>