Browse Source

NEW add sorting of product price list by customer (#26483)

* added sorting of product price list by customer

* add search and sort in same time

* Update price.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
atm-sami 1 year ago
parent
commit
53b48173f6

+ 2 - 0
htdocs/langs/en_US/products.lang

@@ -80,6 +80,8 @@ SoldAmount=Sold amount
 PurchasedAmount=Purchased amount
 NewPrice=New price
 MinPrice=Min. selling price
+MinPriceHT=Min. selling price (excl. tax)
+MinPriceTTC=Prix de vente min (inc. tax)
 EditSellingPriceLabel=Edit selling price label
 CantBeLessThanMinPrice=The selling price can't be lower than minimum allowed for this product (%s without tax). This message can also appear if you type a significant discount.
 CantBeLessThanMinPriceInclTax=The selling price can't be lower than minimum allowed for this product (%s including taxes). This message can also appears if you type a too important discount.

+ 2 - 0
htdocs/langs/fr_FR/products.lang

@@ -80,6 +80,8 @@ SoldAmount=Solde
 PurchasedAmount=Montant des achats
 NewPrice=Nouveau prix
 MinPrice=Prix de vente min.
+MinPriceHT=Prix de vente min. HT
+MinPriceTTC=Prix de vente min. TTC
 EditSellingPriceLabel=Modifier le libellé du prix de vente
 CantBeLessThanMinPrice=Le prix de vente ne doit pas être inférieur au minimum pour ce produit (%s HT). Ce message peut aussi être provoqué par une remise trop importante.
 CantBeLessThanMinPriceInclTax=Le prix de vente ne peut pas être inférieur au minimum autorisé pour ce produit (%s taxes comprises). Ce message peut également apparaître si vous saisissez une remise trop importante.

+ 17 - 0
htdocs/product/class/productcustomerprice.class.php

@@ -28,6 +28,23 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  */
 class ProductCustomerPrice extends CommonObject
 {
+	/**
+	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
+	 */
+	public $fields = array(
+		'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", 'showoncombobox'=>'1', 'noteditable'=>1),
+		'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:0', 'label'=>'Product', 'enabled'=>'$conf->product->enabled', 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce", 'css'=>'maxwidth300', 'csslist'=>'tdoverflowmax100', 'picto'=>'product'),
+		'ref_customer' => array('type'=>'varchar(128)', 'label'=>'RefCustomer', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1,),
+		'datec' => array('type'=>'datetime', 'label'=>'AppliedPricesFrom', 'enabled'=>1, 'visible'=>1, 'position'=>500, 'notnull'=>1,),
+		'price_base_type' => array('type' => 'varchar(255)', 'label' => 'PriceBase', 'enabled' => 1, 'visible' => 1, 'position' => 11, 'notnull' => -1, 'comment' => 'Price Base Type'),
+		'tva_tx' => array('type' => 'decimal(20,6)', 'label' => 'VAT', 'enabled' => 1, 'visible' => 1, 'position' => 12, 'notnull' => -1, 'comment' => 'TVA Tax Rate'),
+		'price' => array('type' => 'decimal(20,6)', 'label' => 'HT', 'enabled' => 1, 'visible' => 1, 'position' => 8, 'notnull' => -1, 'comment' => 'Price HT'),
+		'price_ttc' => array('type' => 'decimal(20,6)', 'label' => 'TTC', 'enabled' => 1, 'visible' => 1, 'position' => 8, 'notnull' => -1, 'comment' => 'Price TTC'),
+		'price_min' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceHT', 'enabled' => 1, 'visible' => 1, 'position' => 9, 'notnull' => -1, 'comment' => 'Minimum Price'),
+		'price_min_ttc' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceTTC', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => -1, 'comment' => 'Minimum Price TTC'),
+		'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>1, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'user.rowid', 'csslist'=>'tdoverflowmax100'),
+	);
+
 	/**
 	 * @var string ID to identify managed object
 	 */

+ 60 - 26
htdocs/societe/price.php

@@ -308,6 +308,8 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
 		print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
 		print '<input type="hidden" name="token" value="'.newToken().'">';
 		print '<input type="hidden" name="action" value="add_customer_price_confirm">';
+		print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
+		print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
 		print '<input type="hidden" name="socid" value="'.$object->id.'">';
 		print '<table class="border centpercent">';
 		print '<tr>';
@@ -536,6 +538,22 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
 		print "\n</div>\n";
 
 
+		$arrayfields = array();
+		foreach ($prodcustprice->fields as $key => $val) {
+			// If $val['visible']==0, then we never show the field
+			if (!empty($val['visible'])) {
+				$visible = (int) dol_eval($val['visible'], 1, 1, '1');
+				$arrayfields['t.'.$key] = array(
+					'label'=>$val['label'],
+					'checked'=>(($visible < 0) ? 0 : 1),
+					'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
+					'position'=>$val['position'],
+					'help'=> isset($val['help']) ? $val['help'] : ''
+				);
+			}
+		}
+		$arrayfields = dol_sort_array($arrayfields, 'position');
+
 		// Count total nb of records
 		$nbtotalofrecords = '';
 		if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
@@ -556,22 +574,38 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
 		print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
 		print '<input type="hidden" name="token" value="'.newToken().'">';
 		print '<input type="hidden" name="id" value="'.$object->id.'">';
-
+		if (!empty($sortfield)) {
+			print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
+		}
+		if (!empty($sortorder)) {
+			print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
+		}
 		print '<div class="div-table-responsive-no-min">';
-		print '<table class="noborder centpercent">';
+		print '<table class="noborder centpercent liste">';
+
+		$param = 'socid='.$object->id.'&';
+		if ($search_prod) {
+			$param .= '&search_prod='.urlencode($search_prod);
+		}
+		if ($search_label) {
+			$param .= '&search_label='.urlencode($search_label);
+		}
+		if ($search_price) {
+			$param .= '&search_price='.urlencode($search_price);
+		}
+		if ($search_price) {
+			$param .= '&search_price='.urlencode($search_price);
+		}
+		if ($search_price_ttc) {
+			$param .= '&search_price_ttc='.urlencode($search_price_ttc);
+		}
 
 		print '<tr class="liste_titre">';
-		print '<td>'.$langs->trans("Ref").'</td>';
-		print '<td>'.$langs->trans("Product").'</td>';
-		print '<td>'.$langs->trans('RefCustomer').'</td>';
-		print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
-		print '<td class="center">'.$langs->trans("PriceBase").'</td>';
-		print '<td class="right">'.$langs->trans("VAT").'</td>';
-		print '<td class="right">'.$langs->trans("HT").'</td>';
-		print '<td class="right">'.$langs->trans("TTC").'</td>';
-		print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
-		print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
-		print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
+		foreach ($prodcustprice->fields as $key => $val) {
+			if (!empty($arrayfields['t.'.$key]['checked'])) {
+				print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], $key, '', $param, '', $sortfield, $sortorder)."\n";
+			}
+		}
 		print '<td></td>';
 		print '</tr>';
 
@@ -583,8 +617,8 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
 			print '<td class="liste_titre"></td>';
 			print '<td class="liste_titre"></td>';
 			print '<td class="liste_titre"></td>';
-			print '<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price" value="'.$search_price.'"></td>';
-			print '<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price_ttc" value="'.$search_price_ttc.'"></td>';
+			print '<td class="liste_titre left"><input type="text" class="flat width75" name="search_price" value="'.$search_price.'"></td>';
+			print '<td class="liste_titre left"><input type="text" class="flat width75" name="search_price_ttc" value="'.$search_price_ttc.'"></td>';
 			print '<td class="liste_titre"></td>';
 			print '<td class="liste_titre"></td>';
 			print '<td class="liste_titre"></td>';
@@ -606,18 +640,18 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
 
 				print '<tr class="oddeven">';
 
-				print "<td>".$staticprod->getNomUrl(1)."</td>";
-				print "<td>".$staticprod->label."</td>";
-				print '<td>'.$line->ref_customer.'</td>';
-				print "<td>".dol_print_date($line->datec, "dayhour")."</td>";
-				print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
-				print '<td class="right">'.vatrate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), true, $line->recuperableonly)."</td>";
-				print '<td class="right">'.price($line->price)."</td>";
-				print '<td class="right">'.price($line->price_ttc)."</td>";
-				print '<td class="right">'.price($line->price_min).'</td>';
-				print '<td class="right">'.price($line->price_min_ttc).'</td>';
+				print '<td class="left">'.$staticprod->getNomUrl(1)."</td>";
+				print '<td class="left">'.$staticprod->label."</td>";
+				print '<td class="left">'.$line->ref_customer.'</td>';
+				print '<td class="left">'.dol_print_date($line->datec, "dayhour")."</td>";
+				print '<td class="left">'.$langs->trans($line->price_base_type)."</td>";
+				print '<td class="left">'.vatrate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), true, $line->recuperableonly)."</td>";
+				print '<td class="left">'.price($line->price)."</td>";
+				print '<td class="left">'.price($line->price_ttc)."</td>";
+				print '<td class="left">'.price($line->price_min).'</td>';
+				print '<td class="left">'.price($line->price_min_ttc).'</td>';
 				// User
-				print '<td class="right">';
+				print '<td class="left">';
 				print $userstatic->getNomUrl(-1);
 				print '</td>';
 				// Action