From 0a23a1157f284d3223abf00ed46ad8bb62a24504 Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Fri, 15 Feb 2019 11:07:25 +0100 Subject: [PATCH] NEW : Can edit supplier on draft order supplier --- htdocs/fourn/commande/card.php | 144 +++++++++++++++++++++++++-------- 1 file changed, 111 insertions(+), 33 deletions(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index a75064178ae..dc80d5336aa 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -200,6 +200,67 @@ 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'; + $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->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->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 +1887,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 .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $form->select_company($object->thirdparty->id, 'new_socid', '', '', 0, 0, array(), 0, 'minwidth300'); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } + if(empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action != 'edit_thirdparty') { + if(! empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $object->statut == CommandeFournisseur::STATUS_DRAFT) { + $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetThirdParty')) . ''; + } + $morehtmlref .= ' : '.$object->thirdparty->getNomUrl(1); + if(empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (' . $langs->trans("OtherOrders") . ')'; + } + // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->fournisseur->commande->creer) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.='
'; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:-1), $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.='
'; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } - } + if(!empty($conf->projet->enabled)) { + $langs->load("projects"); + $morehtmlref .= '
' . $langs->trans('Project') . ' '; + if($user->rights->fournisseur->commande->creer) { + if($action != 'classify') + $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } + else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } + else { + if(!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } + else { + $morehtmlref .= ''; + } + } + } $morehtmlref.='';