This commit is contained in:
Alexis Algoud 2016-12-15 11:23:13 +01:00
parent 703b8708e3
commit 81b01cd055
8 changed files with 239 additions and 69 deletions

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,168 @@
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2015 ATM Consulting <support@atm-consulting.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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 = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">'
. $langs->trans("BackToModuleList") . '</a>';
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 '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Parameters").'</td>'."\n";
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="100">'.$langs->trans("Value").'</td>'."\n";
// Example with a yes / no select
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("INVENTORY_GEN_PDF").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300">';
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_INVENTORY_GEN_PDF">';
print $form->selectyesno("INVENTORY_GEN_PDF",$conf->global->INVENTORY_GEN_PDF,1);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</form>';
print '</td></tr>';
// Example with a yes / no select
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("INVENTORY_DISABLE_VIRTUAL").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300">';
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_INVENTORY_DISABLE_VIRTUAL">';
print $form->selectyesno("INVENTORY_DISABLE_VIRTUAL",$conf->global->INVENTORY_DISABLE_VIRTUAL,1);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</form>';
print '</td></tr>';
// Example with a yes / no select
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300">';
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_INVENTORY_USE_MIN_PA_IF_NO_LAST_PA">';
print $form->selectyesno("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA",$conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA,1);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</form>';
print '</td></tr>';
// Example with a yes / no select
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="right" width="300">';
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT">';
print $form->selectyesno("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT",$conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT,1);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</form>';
print '</td></tr>';
print '</table>';
llxFooter();
$db->close();

View File

@ -1,24 +1,21 @@
<?php
require('../config.php');
require('../class/inventory.class.php');
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/inventory/class/inventory.class.php';
$get = GETPOST('get');
$put = GETPOST('put');
$PDOdb=new TPDOdb;
switch ($put) {
case 'qty':
if (!$user->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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

View File

@ -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).'&nbsp;-&nbsp;'.$product->label
,'entrepot'=>$e->getNomUrl(1)
,'barcode' => $product->barcode
,'qty' =>($mode == 'edit' ? '<input type="text" name="qty_to_add['.$k.']" value="'.$qty.'" size="8" style="text-align:center;" />' : $qty )
.($mode =='edit' ? '<a id="a_save_qty_'.$k.'" href="javascript:save_qty('.$k.')">'.img_picto($langs->trans('Add'), 'plus16@inventory').'</a>' : '')
,'qty' =>($mode == 'edit' ? '<input type="text" name="qty_to_add['.$k.']" value="'.$qty.'" size="8" style="text-align:center;" /> <a id="a_save_qty_'.$k.'" href="javascript:save_qty('.$k.')">'.img_picto($langs->trans('Add'), 'plus16@inventory').'</a>' : '' )
,'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 ? '<a onclick="if (!confirm(\'Confirmez-vous la suppression de la ligne ?\')) return false;" href="'.dol_buildpath('inventory/inventory.php?id='.$inventory->id.'&action=delete_line&rowid='.$Inventorydet->id, 1).'">'.img_picto($langs->trans('inventoryDeleteLine'), 'delete').'</a>' : '')
,'pmp_stock'=>round($pmp_actual,2)
,'pmp_actual'=> round($pmp * $Inventorydet->qty_view,2)
,'pmp_new'=>(!empty($user->rights->inventory->changePMP) ? '<input type="text" name="new_pmp['.$k.']" value="'.$Inventorydet->new_pmp.'" size="8" style="text-align:right;" />'
.($mode =='edit' ? '<a id="a_save_new_pmp_'.$k.'" href="javascript:save_pmp('.$k.')">'.img_picto($langs->trans('Save'), 'bt-save.png@inventory').'</a>' : '') : '')
,'pmp_new'=>(!empty($user->rights->inventory->changePMP && $mode =='edit') ? '<input type="text" name="new_pmp['.$k.']" value="'.$Inventorydet->new_pmp.'" size="8" style="text-align:right;" /> <a id="a_save_new_pmp_'.$k.'" href="javascript:save_pmp('.$k.')">'.img_picto($langs->trans('Save'), 'bt-save.png@inventory').'</a>' : 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) {
?>
<tr style="background-color:#dedede;">
<th align="left" width="20%">&nbsp;&nbsp;Produit</th>
<th align="center">Entrepôt</td>
<th align="center"><?php echo $langs->trans('Warehouse'); ?></th>
<?php if (! empty($conf->barcode->enabled)) { ?>
<th align="center">Code-barre</td>
<th align="center"><?php echo $langs->trans('Barcode'); ?></th>
<?php } ?>
<?php if ($view['can_validate'] == 1) { ?>
<th align="center" width="20%">Quantité théorique</th>
<th align="center" width="20%"><?php echo $langs->trans('TheoricalQty'); ?></th>
<?php
if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){
echo '<th align="center" width="20%" colspan="3">Valeur théorique</th>';
echo '<th align="center" width="20%" colspan="3">'.$langs->trans('TheoricalValue').'</th>';
}
else {
echo '<th align="center" width="20%" colspan="2">Valeur théorique</th>';
echo '<th align="center" width="20%" colspan="2">'.$langs->trans('TheoricalValue').'</th>';
}
?>
<?php } ?>
<th align="center" width="20%">Quantité réelle</th>
<th align="center" width="20%"><?php echo $langs->trans('RealQty'); ?></th>
<?php if ($view['can_validate'] == 1) { ?>
<?php
@ -682,39 +680,39 @@ function _headerList($view) {
if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) $colspan++;
if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) $colspan++;
echo '<th align="center" width="20%" colspan="'.$colspan.'">Valeur réelle</th>';
echo '<th align="center" width="20%" colspan="'.$colspan.'">'.$langs->trans('RealValue').'</th>';
?>
<th align="center" width="15%">Quantité régulée</th>
<th align="center" width="15%"><?php echo $langs->trans('RegulatedQty'); ?></th>
<?php } ?>
<?php if ($view['is_already_validate'] != 1) { ?>
<th align="center" width="5%">#</th>
<?php } ?>
<th align="center" width="5%"></th>
</tr>
<?php if ($view['can_validate'] == 1) { ?>
<tr style="background-color:#dedede;">
<th colspan="<?php echo empty($conf->barcode->enabled) ? 3 : 4; ?>">&nbsp;</th>
<th>PMP</th>
<th>Dernier PA</th>
<th><?php echo $langs->trans('PMP'); ?></th>
<th><?php echo $langs->trans('LastPA'); ?></th>
<?php
if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){
echo '<th>PA courant</th>';
echo '<th>'.$langs->trans('CurrentPA').'</th>';
}
?>
<th>&nbsp;</th>
<th>PMP</th>
<th><?php echo $langs->trans('PMP'); ?></th>
<?php
if(!empty($user->rights->inventory->changePMP)) {
echo '<th rel="newPMP">'.$langs->trans('ColumnNewPMP').'</th>';
}
?>
<th>Dernier PA</th>
<th><?php echo $langs->trans('LastPA'); ?></th>
<?php
if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){
echo '<th>PA courant</th>';
echo '<th>'.$langs->trans('CurrentPA').'</th>';
}
?>

View File

@ -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 @@
<td align="right"><?php echo price($row['pmp_actual']); ?></td>
<?php
if(!empty($user->rights->inventory->changePMP)) {
echo '<td>'.$row['pmp_new'].'</td>';
echo '<td align="right">'.$row['pmp_new'].'</td>';
}
?>
<td align="right"><?php echo price($row['pa_actual']); ?></td>