diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 16b388c728e..5f233041282 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -200,6 +200,69 @@ if (empty($reshook))
if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
}
+ // Edit Thirdparty
+ if (! empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action == 'set_thirdparty' && $user->rights->fournisseur->commande->creer && $object->statut == CommandeFournisseur::STATUS_DRAFT)
+ {
+ $new_socid = GETPOST('new_socid', 'int');
+ if(! empty($new_socid) && $new_socid != $object->thirdparty->id) {
+ $db->begin();
+
+ // Update supplier
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur';
+ $sql .= ' SET fk_soc='.$new_socid;
+ $sql.= ' WHERE fk_soc='.$object->thirdparty->id;
+ $sql.= ' AND rowid='.$object->id;
+
+ $res = $db->query($sql);
+
+ if(! $res) $db->rollback();
+ else {
+ $db->commit();
+
+ // Replace prices for each lines by new supplier prices
+ foreach($object->lines as $l) {
+ $sql = 'SELECT price, unitprice, tva_tx, ref_fourn';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
+ $sql.= ' WHERE fk_product='.$l->fk_product;
+ $sql.= ' AND fk_soc='.$new_socid;
+ $sql.= ' ORDER BY unitprice ASC';
+
+ $resql = $db->query($sql);
+ if($resql) {
+ $num_row = $db->num_rows($resql);
+ if(empty($num_row)) {
+ // No product price for this supplier !
+ $l->subprice = 0;
+ $l->total_ht = 0;
+ $l->total_tva = 0;
+ $l->total_ttc = 0;
+ $l->ref_supplier = '';
+ $l->update();
+ }
+ else {
+ // No need for loop to keep best supplier price
+ $obj = $db->fetch_object($resql);
+ $l->subprice = $obj->unitprice;
+ $l->total_ht = $obj->price;
+ $l->tva_tx = $obj->tva_tx;
+ $l->total_tva = $l->total_ht * ($obj->tva_tx/100);
+ $l->total_ttc = $l->total_ht + $l->total_tva;
+ $l->ref_supplier = $obj->ref_fourn;
+ $l->update();
+ }
+ }
+ else {
+ dol_print_error($db);
+ }
+ $db->free($resql);
+ }
+ $object->update_price();
+ }
+ }
+ header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
+ exit;
+ }
+
if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
{
$result = $object->set_remise($user, $_POST['remise_percent']);
@@ -1826,40 +1889,57 @@ elseif (! empty($object->id))
$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', null, null, '', 1);
// Thirdparty
- $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
- if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' ('.$langs->trans("OtherOrders").')';
+ $morehtmlref.='
'.$langs->trans('ThirdParty');
+ if(! empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && ! empty($user->rights->fournisseur->commande->creer) && $action == 'edit_thirdparty') {
+ $morehtmlref .= ' : ';
+ $morehtmlref .= '