Merge pull request #5794 from mrsof/develop

NEW add confirm on reapeatable/template invoice deletion
This commit is contained in:
Laurent Destailleur 2016-09-28 20:01:39 +02:00 committed by GitHub
commit ce1f57786a

View File

@ -7,6 +7,7 @@
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -242,9 +243,9 @@ if ($action == 'add')
}
// Delete
if ($action == 'delete' && $user->rights->facture->supprimer)
if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $user->rights->facture->supprimer)
{
$object->delete($user);
$object->delete();
header("Location: " . $_SERVER['PHP_SELF'] );
exit;
}
@ -368,7 +369,8 @@ if ($action == 'addline' && $user->rights->facture->creer)
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
// Unset extrafield
if (is_array($extralabelsline)) {
if (is_array($extralabelsline))
{
// Get extra fields
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_" . $key . $predef]);
@ -402,7 +404,8 @@ if ($action == 'addline' && $user->rights->facture->creer)
$error ++;
}
if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod)))
{
$ret = $object->fetch($id);
if ($ret < 0) {
dol_print_error($db, $object->error);
@ -464,8 +467,10 @@ if ($action == 'addline' && $user->rights->facture->creer)
$filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id);
$result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
if ($result) {
if (count($prodcustprice->lines) > 0) {
if ($result)
{
if (count($prodcustprice->lines) > 0)
{
$pu_ht = price($prodcustprice->lines[0]->price);
$pu_ttc = price($prodcustprice->lines[0]->price_ttc);
$price_base_type = $prodcustprice->lines[0]->price_base_type;
@ -497,27 +502,32 @@ if ($action == 'addline' && $user->rights->facture->creer)
$desc = '';
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
{
$outputlangs = $langs;
$newlang = '';
if (empty($newlang) && GETPOST('lang_id'))
$newlang = GETPOST('lang_id');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
if (! empty($newlang))
{
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
} else {
}
else
{
$desc = $prod->description;
}
$desc = dol_concatdesc($desc, $product_desc);
// Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
{
$tmptxt = '(';
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
@ -527,11 +537,15 @@ if ($action == 'addline' && $user->rights->facture->creer)
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
$tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt);
}
$type = $prod->type;
$fk_unit = $prod->fk_unit;
} else {
}
else
{
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
$tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
@ -555,10 +569,13 @@ if ($action == 'addline' && $user->rights->facture->creer)
if ($tva_npr)
$info_bits |= 0x01;
if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) {
if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))
{
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
setEventMessages($mesg, null, 'errors');
} else {
}
else
{
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit);
@ -618,7 +635,9 @@ if ($action == 'addline' && $user->rights->facture->creer)
unset($_POST['situations']);
unset($_POST['progress']);
} else {
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
@ -661,9 +680,11 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
// Unset extrafield
if (is_array($extralabelsline)) {
if (is_array($extralabelsline))
{
// Get extra fields
foreach ($extralabelsline as $key => $value) {
foreach ($extralabelsline as $key => $value)
{
unset($_POST["options_" . $key]);
}
}
@ -721,12 +742,29 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('
}
// Update line
if (! $error) {
$result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty,
$vat_rate, GETPOST('productid'), GETPOST('remise_percent'), 'HT', $info_bits, 0, 0, $type,
0, $special_code, $label, GETPOST('units'));
if (! $error)
{
$result = $object->updateline(
GETPOST('lineid'),
$description,
$pu_ht,
$qty,
$vat_rate,
GETPOST('productid'),
GETPOST('remise_percent'),
'HT',
$info_bits,
0,
0,
$type,
0,
$special_code,
$label,
GETPOST('units')
);
if ($result >= 0) {
if ($result >= 0)
{
/*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;
@ -781,7 +819,9 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('
unset($_POST['situations']);
unset($_POST['progress']);
} else {
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
}
@ -1003,6 +1043,11 @@ else
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
}
// Confirm delete of repeatable invoice
if ($action == 'ask_deleteinvoice') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteRepeatableInvoice'), $langs->trans('ConfirmDeleteRepeatableInvoice'), 'confirm_deleteinvoice', '', 'no', 1);
}
print $formconfirm;
$author = new User($db);
@ -1056,9 +1101,12 @@ else
print '</td><td colspan="3">';
if ($object->type != Facture::TYPE_CREDIT_NOTE)
{
if ($action == 'editconditions') {
if ($action == 'editconditions')
{
$form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
} else {
}
else
{
$form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'none');
}
} else {
@ -1102,7 +1150,8 @@ else
print '</tr>';
// Project
if (! empty($conf->projet->enabled)) {
if (! empty($conf->projet->enabled))
{
$langs->load('projects');
print '<tr>';
print '<td>';
@ -1359,7 +1408,7 @@ else
//if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer)
if ($user->rights->facture->supprimer)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=ask_deleteinvoice&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
}
print '</div>';