FIX using decimal on stock correction

This commit is contained in:
Laurent Destailleur 2020-09-04 19:34:20 +02:00
parent 4fdbfa8224
commit 0c1a5d9e25

View File

@ -1,14 +1,14 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com> * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2013 Cédric Salvador <csalvador.gpcsolutions.fr> * Copyright (C) 2013 Cédric Salvador <csalvador.gpcsolutions.fr>
* Copyright (C) 2013-2018 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2013-2018 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014-2015 Cédric Gross <c.gross@kreiz-it.fr> * Copyright (C) 2014-2015 Cédric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -67,8 +67,8 @@ $stocklimit = GETPOST('seuil_stock_alerte');
$desiredstock = GETPOST('desiredstock'); $desiredstock = GETPOST('desiredstock');
$cancel = GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
$fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid'; $fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid';
$d_eatby = dol_mktime(0, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']); $d_eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
$d_sellby = dol_mktime(0, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']); $d_sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
$pdluoid = GETPOST('pdluoid', 'int'); $pdluoid = GETPOST('pdluoid', 'int');
$batchnumber = GETPOST('batch_number', 'san_alpha'); $batchnumber = GETPOST('batch_number', 'san_alpha');
if (!empty($batchnumber)) { if (!empty($batchnumber)) {
@ -224,7 +224,8 @@ if ($action == "correct_stock" && !$cancel)
if (!$error) if (!$error)
{ {
$priceunit = price2num(GETPOST("unitprice")); $priceunit = price2num(GETPOST("unitprice"));
if (is_numeric(GETPOST("nbpiece")) && $id) $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
if (is_numeric($nbpiece) && $nbpiece != 0 && $id)
{ {
$origin_element = ''; $origin_element = '';
$origin_id = null; $origin_id = null;
@ -244,14 +245,14 @@ if ($action == "correct_stock" && !$cancel)
$result = $object->correct_stock_batch( $result = $object->correct_stock_batch(
$user, $user,
GETPOST("id_entrepot", 'int'), GETPOST("id_entrepot", 'int'),
GETPOST("nbpiece"), $nbpiece,
GETPOST("mouvement"), GETPOST("mouvement", 'int'),
GETPOST("label", 'alphanohtml'), // label movement GETPOST("label", 'alphanohtml'), // label movement
$priceunit, $priceunit,
$d_eatby, $d_eatby,
$d_sellby, $d_sellby,
$batchnumber, $batchnumber,
GETPOST('inventorycode'), GETPOST('inventorycode', 'alphanohtml'),
$origin_element, $origin_element,
$origin_id $origin_id
); // We do not change value of stock for a correction ); // We do not change value of stock for a correction
@ -259,11 +260,11 @@ if ($action == "correct_stock" && !$cancel)
$result = $object->correct_stock( $result = $object->correct_stock(
$user, $user,
GETPOST("id_entrepot", 'int'), GETPOST("id_entrepot", 'int'),
GETPOST("nbpiece"), $nbpiece,
GETPOST("mouvement"), GETPOST("mouvement", 'int'),
GETPOST("label", 'alphanohtml'), GETPOST("label", 'alphanohtml'),
$priceunit, $priceunit,
GETPOST('inventorycode'), GETPOST('inventorycode', 'alphanohtml'),
$origin_element, $origin_element,
$origin_id $origin_id
); // We do not change value of stock for a correction ); // We do not change value of stock for a correction
@ -361,18 +362,20 @@ if ($action == "transfert_stock" && !$cancel)
$sellby = $d_sellby; $sellby = $d_sellby;
} }
$nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
if (!$error) if (!$error)
{ {
// Remove stock // Remove stock
$result1 = $object->correct_stock_batch( $result1 = $object->correct_stock_batch(
$user, $user,
$srcwarehouseid, $srcwarehouseid,
GETPOST("nbpiece", 'int'), $nbpiece,
1, 1,
GETPOST("label", 'san_alpha'), GETPOST("label", 'alphanohtml'),
$pricesrc, $pricesrc,
$eatby, $sellby, $batch, $eatby, $sellby, $batch,
GETPOST('inventorycode') GETPOST('inventorycode', 'alphanohtml')
); );
if ($result1 < 0) $error++; if ($result1 < 0) $error++;
} }
@ -382,12 +385,12 @@ if ($action == "transfert_stock" && !$cancel)
$result2 = $object->correct_stock_batch( $result2 = $object->correct_stock_batch(
$user, $user,
GETPOST("id_entrepot_destination", 'int'), GETPOST("id_entrepot_destination", 'int'),
GETPOST("nbpiece", 'int'), $nbpiece,
0, 0,
GETPOST("label", 'san_alpha'), GETPOST("label", 'alphanohtml'),
$pricedest, $pricedest,
$eatby, $sellby, $batch, $eatby, $sellby, $batch,
GETPOST('inventorycode') GETPOST('inventorycode', 'alphanohtml')
); );
if ($result2 < 0) $error++; if ($result2 < 0) $error++;
} }
@ -398,11 +401,11 @@ if ($action == "transfert_stock" && !$cancel)
$result1 = $object->correct_stock( $result1 = $object->correct_stock(
$user, $user,
GETPOST("id_entrepot", 'int'), GETPOST("id_entrepot", 'int'),
GETPOST("nbpiece"), $nbpiece,
1, 1,
GETPOST("label"), GETPOST("label", 'alphanohtml'),
$pricesrc, $pricesrc,
GETPOST('inventorycode') GETPOST('inventorycode', 'alphanohtml')
); );
if ($result1 < 0) $error++; if ($result1 < 0) $error++;
} }
@ -412,11 +415,11 @@ if ($action == "transfert_stock" && !$cancel)
$result2 = $object->correct_stock( $result2 = $object->correct_stock(
$user, $user,
GETPOST("id_entrepot_destination", 'int'), GETPOST("id_entrepot_destination", 'int'),
GETPOST("nbpiece"), $nbpiece,
0, 0,
GETPOST("label"), GETPOST("label", 'alphanohtml'),
$pricedest, $pricedest,
GETPOST('inventorycode') GETPOST('inventorycode', 'alphanohtml')
); );
if ($result2 < 0) $error++; if ($result2 < 0) $error++;
} }