diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 061ace6c4f0..6f665a381df 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -6,7 +6,7 @@ * Copyright (C) 2010-2019 Juanjo Menent * Copyright (C) 2014 Cedric Gross * Copyright (C) 2016 Florian Henry - * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2017-2020 Ferran Marcet * Copyright (C) 2018 Frédéric France * Copyright (C) 2019-2020 Christophe Battarel * @@ -243,7 +243,7 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { - $dto = GETPOST("dto_".$reg[1].'_'.$reg[2]); + $dto = GETPOST("dto_".$reg[1].'_'.$reg[2], 'int'); if (!empty($dto)) { $unit_price = price2num(GETPOST("pu_".$reg[1]) * (100 - $dto) / 100, 'MU'); } @@ -269,14 +269,14 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) if (!$error && !empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { - $dto = GETPOST("dto_".$reg[1].'_'.$reg[2]); + $dto = GETPOST("dto_".$reg[1].'_'.$reg[2], 'int'); //update supplier price if (GETPOSTISSET($saveprice)) { // TODO Use class $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql .= " SET unitprice='".GETPOST($pu)."'"; $sql .= ", price=".GETPOST($pu)."*quantity"; - $sql .= ", remise_percent='".$dto."'"; + $sql .= ", remise_percent='".(!empty($dto)?$dto:0)."'"; $sql .= " WHERE fk_soc=".$object->socid; $sql .= " AND fk_product=".GETPOST($prod, 'int'); @@ -306,6 +306,16 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2]; + if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { + if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { + $dto = GETPOST("dto_".$reg[1].'_'.$reg[2], 'int'); + if (!empty($dto)) { + $unit_price = price2num(GETPOST("pu_".$reg[1]) * (100 - $dto) / 100, 'MU'); + } + $saveprice = "saveprice_".$reg[1].'_'.$reg[2]; + } + } + // We ask to move a qty if (GETPOST($qty) > 0) { if (!(GETPOST($ent, 'int') > 0)) { @@ -328,6 +338,24 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) setEventMessages($object->error, $object->errors, 'errors'); $error++; } + + if (!$error && !empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { + if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { + $dto = GETPOST("dto_".$reg[1].'_'.$reg[2], 'int'); + //update supplier price + if (GETPOSTISSET($saveprice)) { + // TODO Use class + $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " SET unitprice='".GETPOST($pu)."'"; + $sql .= ", price=".GETPOST($pu)."*quantity"; + $sql .= ", remise_percent='".(!empty($dto)?$dto:0)."'"; + $sql .= " WHERE fk_soc=".$object->socid; + $sql .= " AND fk_product=".GETPOST($prod, 'int'); + + $resql = $db->query($sql); + } + } + } } } }