forked from Wavyzz/dolibarr
NEW : Can edit supplier on draft order supplier
This commit is contained in:
@@ -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.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' (<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
|
||||
$morehtmlref.='<br>'.$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 .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
|
||||
$morehtmlref .= '<input type="hidden" name="action" value="set_thirdparty">';
|
||||
$morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
|
||||
$morehtmlref .= $form->select_company($object->thirdparty->id, 'new_socid', '', '', 0, 0, array(), 0, 'minwidth300');
|
||||
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
||||
$morehtmlref .= '</form>';
|
||||
}
|
||||
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 .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=edit_thirdparty&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetThirdParty')) . '</a>';
|
||||
}
|
||||
$morehtmlref .= ' : '.$object->thirdparty->getNomUrl(1);
|
||||
if(empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/fourn/commande/list.php?socid=' . $object->thirdparty->id . '&search_company=' . urlencode($object->thirdparty->name) . '">' . $langs->trans("OtherOrders") . '</a>)';
|
||||
}
|
||||
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$langs->load("projects");
|
||||
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
|
||||
if ($user->rights->fournisseur->commande->creer)
|
||||
{
|
||||
if ($action != 'classify')
|
||||
$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
|
||||
if ($action == 'classify') {
|
||||
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
|
||||
$morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
|
||||
$morehtmlref.='<input type="hidden" name="action" value="classin">';
|
||||
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
$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.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
||||
$morehtmlref.='</form>';
|
||||
} 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.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
|
||||
$morehtmlref.=$proj->ref;
|
||||
$morehtmlref.='</a>';
|
||||
} else {
|
||||
$morehtmlref.='';
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($conf->projet->enabled)) {
|
||||
$langs->load("projects");
|
||||
$morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
|
||||
if($user->rights->fournisseur->commande->creer) {
|
||||
if($action != 'classify')
|
||||
$morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
|
||||
if($action == 'classify') {
|
||||
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
|
||||
$morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
|
||||
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
|
||||
$morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
|
||||
$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 .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
||||
$morehtmlref .= '</form>';
|
||||
}
|
||||
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 .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
|
||||
$morehtmlref .= $proj->ref;
|
||||
$morehtmlref .= '</a>';
|
||||
}
|
||||
else {
|
||||
$morehtmlref .= '';
|
||||
}
|
||||
}
|
||||
}
|
||||
$morehtmlref.='</div>';
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user