Browse Source

Debug price_rule page.

Laurent Destailleur 4 năm trước cách đây
mục cha
commit
d0cb9bc4ed
2 tập tin đã thay đổi với 27 bổ sung29 xóa
  1. 2 2
      htdocs/product/admin/dynamic_prices.php
  2. 25 27
      htdocs/product/admin/price_rules.php

+ 2 - 2
htdocs/product/admin/dynamic_prices.php

@@ -178,7 +178,7 @@ if ($action != 'create_updater' && $action != 'edit_updater')
 			print '<td>'.$entry->code.'</td>';
 			print '<td>'.$entry->description.'</td>';
 			print '<td>'.price($entry->value).'</td>';
-			print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit_variable&token='.newToken().'&selection='.$entry->id.'">'.img_edit().'</a> &nbsp;';
+			print '<td class="right"><a class="editfielda paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=edit_variable&token='.newToken().'&selection='.$entry->id.'">'.img_edit().'</a> &nbsp;';
 			print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_variable&token='.newToken().'&selection='.$entry->id.'">'.img_delete().'</a></td>';
 			print '</tr>';
 		}
@@ -269,7 +269,7 @@ if ($action != 'create_variable' && $action != 'edit_variable')
 			print '<td style="max-width: 250px; word-wrap: break-word; white-space: pre-wrap;">'.$entry->parameters.'</td>';
 			print '<td>'.$entry->update_interval.'</td>';
 			print '<td>'.$entry->getLastUpdated().'</td>';
-			print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit_updater&selection='.$entry->id.'">'.img_edit().'</a> &nbsp;';
+			print '<td class="right"><a class="editfielda paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=edit_updater&selection='.$entry->id.'">'.img_edit().'</a> &nbsp;';
 			print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_updater&token='.newToken().'&selection='.$entry->id.'">'.img_delete().'</a></td>';
 			print '</tr>';
 		}

+ 25 - 27
htdocs/product/admin/price_rules.php

@@ -15,8 +15,8 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
  *
- * Page to set how to autocalculate price for each level when option
- * PRODUCT_MULTIPRICE is on.
+ * Page to set how to autocalculate price for each level when option PRODUCT_MULTIPRICE is on.
+ * This page is a tab in the setup of module Product if option PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL is set.
  */
 
 require '../../main.inc.php';
@@ -32,6 +32,8 @@ $action = GETPOST('action', 'aZ09');
 if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled)))
 	accessforbidden();
 
+$error = 0;
+
 
 /**
  * Actions
@@ -55,6 +57,7 @@ if ($action == 'update') {
 
 		$i_var_percent = 0;
 
+		// Set $i_var_percent, the percent of price for level compared to an other level
 		if ($i != 1) {
 			$i_var_percent = (float) price2num($var_percent[$i]);
 		}
@@ -67,15 +70,12 @@ if ($action == 'update') {
 			$check2 = $i_var_min_percent;
 		} else {
 			$check1 = $i_fk_level >= 1 && $i_fk_level <= $conf->global->PRODUIT_MULTIPRICES_LIMIT;
-			$check2 = $i_var_percent && $i_var_min_percent;
+			$check2 = $i_var_percent && ($i_var_min_percent || (string) $i_var_min_percent === '0');
 		}
 
-		if (!$check1 || !$check2) {
+		if (empty($i_var_percent) && empty($i_var_min_percent)) {
 			//If the level is between range but percent fields are empty, then we ensure it does not exist in DB
-			if ($check1) {
-				$db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".((int) $i));
-			}
-
+			$db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".((int) $i));
 			continue;
 		}
 
@@ -89,11 +89,14 @@ if ($action == 'update') {
 
 			if (!$db->query($sql)) {
 				setEventMessages($langs->trans('ErrorSavingChanges'), null, 'errors');
+				$error++;
 			}
 		}
 	}
 
-	setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
+	if (!$error) {
+		setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
+	}
 }
 
 
@@ -133,32 +136,19 @@ print '<input type="hidden" name="token" value="'.newToken().'">';
 print '<input type="hidden" name="action" value="update">';
 
 $head = product_admin_prepare_head();
-print dol_get_fiche_head($head, 'generator', $tab, 0, 'product');
-
-print $langs->trans("MultiPriceRuleDesc").'<br><br>';
+print dol_get_fiche_head($head, 'generator', $tab, -1, 'product');
 
-print load_fiche_titre($langs->trans('MultipriceRules'), '', '');
+print '<span class="opacitymedium">'.$langs->trans("MultiPriceRuleDesc").'</span><br><br>';
 
-//Array that contains the number of prices available
+// Array that contains the number of prices available
 $price_options = array();
 
 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
 	$price_options[$i] = $langs->trans('SellingPrice').' '.$i;
 }
-
-$genPriceOptions = function ($level) use ($price_options) {
-
-	$return = array();
-
-	for ($i = 1; $i < $level; $i++) {
-		$return[$i] = $price_options[$i];
-	}
-
-	return $return;
-};
 ?>
 
-	<table class="noborder">
+	<table class="noborder centpercent">
 		<tr class="liste_titre">
 			<td style="text-align: center"><?php echo $langs->trans('PriceLevel') ?></td>
 			<td style="text-align: center"><?php echo $langs->trans('Price') ?></td>
@@ -181,7 +171,15 @@ $genPriceOptions = function ($level) use ($price_options) {
 					</td>
 				<td style="text-align: center">
 					<input type="text" style="text-align: right" name="var_percent[<?php echo $i ?>]" size="5" value="<?php echo price(isset($rules[$i]) ? $rules[$i]->var_percent : 0, 2) ?>">
-					<?php echo $langs->trans('PercentVariationOver', Form::selectarray("fk_level[$i]", $genPriceOptions($i), (isset($rules[$i]) ? $rules[$i]->fk_level : null))) ?>
+					<?php
+					$return = array();
+					for ($j = 1; $j < $i; $j++) {
+						$return[$j] = $price_options[$j];
+					}
+					$texttoshow = $langs->trans('PercentVariationOver', '{s1}');
+					$texttoshow = str_replace('{s1}', Form::selectarray("fk_level[$i]", $return, (isset($rules[$i]) ? $rules[$i]->fk_level : null)), $texttoshow);
+					print $texttoshow;
+					?>
 				</td>
 				<td style="text-align: center">
 					<input type="text" style="text-align: right" name="var_min_percent[<?php echo $i ?>]" size="5" value="<?php echo price(isset($rules[$i]) ? $rules[$i]->var_min_percent : 0, 2) ?>">