Ajout popup de confirmation ajax

Fix: bug sur l'enregistrement des lignes produits
This commit is contained in:
Regis Houssin 2007-10-06 11:23:38 +00:00
parent 2537cef00d
commit b44066375d
4 changed files with 185 additions and 126 deletions

View File

@ -106,7 +106,7 @@ if (($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes
{ {
$propal = new Propal($db); $propal = new Propal($db);
$propal->fetch($_GET['propalid']); $propal->fetch($_GET['propalid']);
$result = $propal->delete_product($_GET['ligne']); $result = $propal->delete_product($_GET['lineid']);
if ($_REQUEST['lang_id']) if ($_REQUEST['lang_id'])
{ {
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
@ -558,7 +558,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
$propal = new Propal($db); $propal = new Propal($db);
if (! $propal->fetch($_POST['propalid']) > 0) dolibarr_print_error($db); if (! $propal->fetch($_POST['propalid']) > 0) dolibarr_print_error($db);
$result = $propal->updateline($_POST['ligne'], $result = $propal->updateline($_POST['lineid'],
$_POST['subprice'], $_POST['subprice'],
$_POST['qty'], $_POST['qty'],
$_POST['remise_percent'], $_POST['remise_percent'],
@ -719,7 +719,7 @@ if ($_GET['propalid'] > 0)
*/ */
if ($_GET['action'] == 'ask_deleteline' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) if ($_GET['action'] == 'ask_deleteline' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{ {
$html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&ligne='.$_GET["ligne"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline'); $html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline');
print '<br>'; print '<br>';
} }
@ -1050,7 +1050,7 @@ if ($_GET['propalid'] > 0)
$var=!$var; $var=!$var;
// Ligne en mode visu // Ligne en mode visu
if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid) if ($_GET['action'] != 'editline' || $_GET['lineid'] != $objp->rowid)
{ {
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -1216,7 +1216,7 @@ if ($_GET['propalid'] > 0)
} }
else else
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=editline&amp;ligne='.$objp->rowid.'#'.$objp->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=editline&amp;lineid='.$objp->rowid.'#'.$objp->rowid.'">';
print img_edit(); print img_edit();
print '</a>'; print '</a>';
} }
@ -1226,21 +1226,19 @@ if ($_GET['propalid'] > 0)
{ {
if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX) if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX)
{ {
$url = $_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&ligne='.$objp->rowid.'&action=confirm_deleteline&confirm=yes'; $url = $_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&lineid='.$objp->rowid.'&action=confirm_deleteline&confirm=yes';
print '<a href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmDeleteProductLine').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'deleteline'.$i.'\')">'; print '<a href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmDeleteProductLine').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'deleteline'.$i.'\')">';
print img_delete();
} }
else else
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=ask_deleteline&amp;ligne='.$objp->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=ask_deleteline&amp;lineid='.$objp->rowid.'">';
print img_delete();
} }
} }
else else
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=deleteline&amp;ligne='.$objp->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=deleteline&amp;lineid='.$objp->rowid.'">';
print img_delete();
} }
print img_delete();
print '</a></td>'; print '</a></td>';
if ($num > 1) if ($num > 1)
{ {
@ -1269,12 +1267,12 @@ if ($_GET['propalid'] > 0)
} }
// Ligne en mode update // Ligne en mode update
if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid) if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["lineid"] == $objp->rowid)
{ {
print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'#'.$objp->rowid.'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'#'.$objp->rowid.'" method="post">';
print '<input type="hidden" name="action" value="updateligne">'; print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">'; print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<input type="hidden" name="ligne" value="'.$_GET["ligne"].'">'; print '<input type="hidden" name="lineid" value="'.$_GET["lineid"].'">';
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td>'; print '<td>';
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne

View File

@ -642,7 +642,7 @@ class Commande extends CommonObject
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
$txtva = price2num($txtva); $txtva = price2num($txtva);
if ($price_base_type=='HT') $pu=$pu; if ($price_base_type=='HT') $pu=$pu_ht;
else $pu=$pu_ttc; else $pu=$pu_ttc;
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de

View File

@ -82,7 +82,7 @@ if ($_GET["projetid"])
/******************************************************************************/ /******************************************************************************/
// Suppression de la commande // Suppression de la commande
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
{ {
if ($user->rights->commande->supprimer ) if ($user->rights->commande->supprimer )
{ {
@ -97,7 +97,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
/* /*
* Supprime une ligne produit AVEC ou SANS confirmation * Supprime une ligne produit AVEC ou SANS confirmation
*/ */
if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) if (($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
|| ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE))
{ {
if ($user->rights->commande->creer) if ($user->rights->commande->creer)
@ -105,6 +105,8 @@ if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'ye
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']);
$result = $commande->delete_line($_GET['lineid']); $result = $commande->delete_line($_GET['lineid']);
if ($result > 0)
{
if ($_REQUEST['lang_id']) if ($_REQUEST['lang_id'])
{ {
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
@ -112,6 +114,11 @@ if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'ye
} }
commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs); commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
} }
else
{
print $commande->error;
}
}
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']); Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
exit; exit;
} }
@ -350,7 +357,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
$desc=$_POST['np_desc']; $desc=$_POST['np_desc'];
} }
$commande->addline( $result = $commande->addline(
$_POST['id'], $_POST['id'],
$desc, $desc,
$pu, $pu,
@ -364,6 +371,8 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
$pu_ttc $pu_ttc
); );
if ($result > 0)
{
if ($_REQUEST['lang_id']) if ($_REQUEST['lang_id'])
{ {
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
@ -371,6 +380,11 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
} }
commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
} }
else
{
print $commande->error;
}
}
} }
/* /*
@ -413,47 +427,37 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS
exit; exit;
} }
if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider) if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider)
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']);
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($commande->socid); $soc->fetch($commande->socid);
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
$result=$commande->valid($user); $result=$commande->valid($user);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
exit;
} }
if ($_POST['action'] == 'confirm_close' && $_POST['confirm'] == 'yes' && $user->rights->commande->creer) if ($_REQUEST['action'] == 'confirm_close' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->creer)
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']);
$result = $commande->cloture($user); $result = $commande->cloture($user);
} }
if ($_POST['action'] == 'confirm_cancel' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider) if ($_REQUEST['action'] == 'confirm_cancel' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider)
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']);
$result = $commande->cancel($user); $result = $commande->cancel($user);
} }
if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{
if ($user->rights->commande->creer)
{
$commande = new Commande($db);
$commande->fetch($_GET['id']);
$commande->delete_line($_GET['lineid']);
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs);
}
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
exit;
}
if ($_GET['action'] == 'modif' && $user->rights->commande->creer) if ($_GET['action'] == 'modif' && $user->rights->commande->creer)
{ {
/* /*
@ -1013,7 +1017,7 @@ else
/* /*
* Confirmation de la validation * Confirmation de la validation
*/ */
if ($_GET['action'] == 'valid') if ($_GET['action'] == 'validate')
{ {
// on vérifie si la facture est en numérotation provisoire // on vérifie si la facture est en numérotation provisoire
$ref = substr($commande->ref, 1, 4); $ref = substr($commande->ref, 1, 4);
@ -1027,16 +1031,15 @@ else
} }
$text=$langs->trans('ConfirmValidateOrder',$num); $text=$langs->trans('ConfirmValidateOrder',$num);
$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid'); $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_validate');
print '<br />'; print '<br />';
} }
/* /*
* Confirmation de la cloture * Confirmation de la cloture
*/ */
if ($_GET['action'] == 'cloture') if ($_GET['action'] == 'close')
{ {
//$numfa = commande_get_num($soc);
$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close'); $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close');
print '<br />'; print '<br />';
} }
@ -1044,7 +1047,7 @@ else
/* /*
* Confirmation de l'annulation * Confirmation de l'annulation
*/ */
if ($_GET['action'] == 'annuler') if ($_GET['action'] == 'cancel')
{ {
$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel'); $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel');
print '<br />'; print '<br />';
@ -1053,9 +1056,9 @@ else
/* /*
* Confirmation de la suppression d'une ligne produit * Confirmation de la suppression d'une ligne produit
*/ */
if ($_GET['action'] == 'delete_product_line' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) if ($_GET['action'] == 'ask_deleteline' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{ {
$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&amp;lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&amp;lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline');
print '<br>'; print '<br>';
} }
@ -1425,7 +1428,15 @@ else
print '<td align="center">'; print '<td align="center">';
if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE) if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=delete_product_line&amp;lineid='.$objp->rowid.'">'; if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX)
{
$url = $_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$objp->rowid.'&action=confirm_deleteline&confirm=yes';
print '<a href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmDeleteProductLine').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'deleteline'.$i.'\')">';
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=ask_deleteline&amp;lineid='.$objp->rowid.'">';
}
} }
else else
{ {
@ -1649,12 +1660,29 @@ else
print '<div class="tabsAction">'; print '<div class="tabsAction">';
// Valid // Valid
if ($commande->statut == 0) if ($commande->statut == 0 && $commande->total_ttc > 0 && $user->rights->commande->valider)
{ {
if ($user->rights->commande->valider) print '<a class="butAction" ';
if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX)
{ {
print '<a class="butAction" href="fiche.php?id='.$id.'&amp;action=valid">'.$langs->trans('Valid').'</a>'; // on vérifie si la facture est en numérotation provisoire
$ref = substr($commande->ref, 1, 4);
if ($ref == 'PROV')
{
$num = $commande->getNextNumRef($soc);
} }
else
{
$num = $commande->ref;
}
$url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_validate&confirm=yes';
print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmValidateOrder',$num).'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'validate\')"';
}
else
{
print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=validate"';
}
print '>'.$langs->trans('Validate').'</a>';
} }
// Edit // Edit
@ -1711,26 +1739,59 @@ else
} }
} }
// Cloturer
if ($commande->statut == 1 || $commande->statut == 2) if ($commande->statut == 1 || $commande->statut == 2)
{ {
if ($user->rights->commande->cloturer) if ($user->rights->commande->cloturer)
{ {
print '<a class="butAction" href="fiche.php?id='.$id.'&amp;action=cloture">'.$langs->trans('Close').'</a>'; print '<a class="butAction" ';
if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX)
{
$url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_close&confirm=yes';
print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmCloseOrder').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'close\')"';
}
else
{
print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=close"';
}
print '>'.$langs->trans('Close').'</a>';
} }
} }
// Annuler commande
if ($commande->statut == 1) if ($commande->statut == 1)
{ {
$nb_expedition = $commande->nb_expedition(); $nb_expedition = $commande->nb_expedition();
if ($user->rights->commande->annuler && $nb_expedition == 0) if ($user->rights->commande->annuler && $nb_expedition == 0)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$id.'&amp;action=annuler">'.$langs->trans('CancelOrder').'</a>'; print '<a class="butActionDelete" ';
if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX)
{
$url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_cancel&confirm=yes';
print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmCancelOrder').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'cancel\')"';
}
else
{
print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=cancel"';
}
print '>'.$langs->trans('CancelOrder').'</a>';
} }
} }
// Supprimer commande
if ($commande->statut == 0 && $user->rights->commande->supprimer) if ($commande->statut == 0 && $user->rights->commande->supprimer)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" ';
if ($conf->use_ajax && $conf->global->MAIN_CONFIRM_AJAX)
{
$url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_delete&confirm=yes';
print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmDeleteOrder').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'delete\')"';
}
else
{
print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&amp;action=delete"';
}
print '>'.$langs->trans('Delete').'</a>';
} }
print '</div>'; print '</div>';