Переглянути джерело

Fix : thirdparty global discount page

hystepik 2 роки тому
батько
коміт
1aae4f1cce
2 змінених файлів з 79 додано та 59 видалено
  1. 77 59
      htdocs/comm/remx.php
  2. 2 0
      htdocs/langs/en_US/bills.lang

+ 77 - 59
htdocs/comm/remx.php

@@ -246,7 +246,9 @@ if ($socid > 0) {
 
 	print dol_get_fiche_head($head, 'absolutediscount', $langs->trans("ThirdParty"), -1, 'company');
 
-	dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
+	$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
+
+	dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
 
 	print '<div class="fichecenter">';
 
@@ -280,9 +282,9 @@ if ($socid > 0) {
 		$resql = $db->query($sql);
 		if ($resql) {
 			$obj = $db->fetch_object($resql);
-			$remise_all += $obj->amount;
-			if ($obj->fk_user == $user->id) {
-				$remise_user += $obj->amount;
+			$remise_all += (!empty($obj->amount) ? $obj->amount : 0);
+			if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
+				$remise_user += (!empty($obj->amount) ? $obj->amount : 0);
 			}
 		} else {
 			dol_print_error($db);
@@ -310,9 +312,9 @@ if ($socid > 0) {
 		$resql = $db->query($sql);
 		if ($resql) {
 			$obj = $db->fetch_object($resql);
-			$remise_all += $obj->amount;
-			if ($obj->fk_user == $user->id) {
-				$remise_user += $obj->amount;
+			$remise_all += (!empty($obj->amount) ? $obj->amount : 0);
+			if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
+				$remise_user += (!empty($obj->amount) ? $obj->amount : 0);
 			}
 		} else {
 			dol_print_error($db);
@@ -335,65 +337,71 @@ if ($socid > 0) {
 	print dol_get_fiche_end();
 
 
-	if ($user->rights->societe->creer) {
-		print '<br>';
+	if ($action == 'create_remise') {
+		if ($user->rights->societe->creer) {
+			print '<br>';
 
-		print load_fiche_titre($langs->trans("NewGlobalDiscount"), '', '');
+			$discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
+			if ($isCustomer && $isSupplier) {
+				$discounttypelabel = $discount_type == 1 ? 'NewSupplierGlobalDiscount' : 'NewClientGlobalDiscount';
+			} else {
+				$discounttypelabel = 'NewGlobalDiscount';
+			}
 
+			print load_fiche_titre($langs->trans($discounttypelabel), '', '');
 
-		if ($isCustomer && !$isSupplier) {
-			print '<input type="hidden" name="discount_type" value="0" />';
-		}
-
-		if (!$isCustomer && $isSupplier) {
-			print '<input type="hidden" name="discount_type" value="1" />';
-		}
+			if ($isSupplier && $discount_type == 1) {
+				print '<input type="hidden" name="discount_type" value="1" />';
+			} else {
+				print '<input type="hidden" name="discount_type" value="0" />';
+			}
 
-		print dol_get_fiche_head();
+			print dol_get_fiche_head();
 
 
-		print '<div class="div-table-responsive-no-min">';
-		print '<table class="border centpercent">';
-		if ($isCustomer && $isSupplier) {
-			print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
-			print '<td><input type="radio" name="discount_type" id="discount_type_0" checked="checked" value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
-			print ' &nbsp; <input type="radio" name="discount_type" id="discount_type_1" value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
+			print '<div class="div-table-responsive-no-min">';
+			print '<table class="border centpercent">';
+			/*if ($isCustomer && $isSupplier) {
+				print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
+				print '<td><input type="radio" name="discount_type" id="discount_type_0" '.($discount_type != 1 ? 'checked="checked" ' : '').'value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
+				print ' &nbsp; <input type="radio" name="discount_type" id="discount_type_1" '.($discount_type == 1 ? 'checked="checked" ' : '').'value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
+				print '</td></tr>';
+			}*/
+
+			// Amount
+			print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Amount").'</td>';
+			print '<td><input type="text" size="5" name="amount" value="'.price2num(GETPOST("amount")).'" autofocus>';
+			print '<span class="hideonsmartphone">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
+
+			// Price base (HT / TTC)
+			print '<tr><td class="titlefield">'.$langs->trans("PriceBase").'</td>';
+			print '<td>';
+			print $form->selectPriceBaseType(GETPOST("price_base_type"), "price_base_type");
 			print '</td></tr>';
-		}
 
-		// Amount
-		print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Amount").'</td>';
-		print '<td><input type="text" size="5" name="amount" value="'.price2num(GETPOST("amount")).'" autofocus>';
-		print '<span class="hideonsmartphone">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
-
-		// Price base (HT / TTC)
-		print '<tr><td class="titlefield">'.$langs->trans("PriceBase").'</td>';
-		print '<td>';
-		print $form->selectPriceBaseType(GETPOST("price_base_type"), "price_base_type");
-		print '</td></tr>';
-
-		// VAT
-		print '<tr><td>'.$langs->trans("VAT").'</td>';
-		print '<td>';
-		print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0, $mysoc, $object, 0, 0, '', 0, 1);
-		print '</td></tr>';
-		print '<tr><td class="fieldrequired" >'.$langs->trans("NoteReason").'</td>';
-		print '<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST('desc', 'alphanohtml').'"></td></tr>';
+			// VAT
+			print '<tr><td>'.$langs->trans("VAT").'</td>';
+			print '<td>';
+			print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0, $mysoc, $object, 0, 0, '', 0, 1);
+			print '</td></tr>';
+			print '<tr><td class="fieldrequired" >'.$langs->trans("NoteReason").'</td>';
+			print '<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST('desc', 'alphanohtml').'"></td></tr>';
 
-		print "</table>";
-		print '</div>';
+			print "</table>";
+			print '</div>';
 
-		print dol_get_fiche_end();
-	}
+			print dol_get_fiche_end();
+		}
 
-	if ($user->rights->societe->creer) {
-		print '<div class="center">';
-		print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
-		if (!empty($backtopage)) {
-			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
-			print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
+		if ($user->rights->societe->creer) {
+			print '<div class="center">';
+			print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
+			if (!empty($backtopage)) {
+				print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+				print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
+			}
+			print '</div>';
 		}
-		print '</div>';
 	}
 
 	print '</form>';
@@ -410,13 +418,22 @@ if ($socid > 0) {
 	 * List not consumed available credits (= linked to no invoice and no invoice line)
 	 */
 
-	print load_fiche_titre($langs->trans("DiscountStillRemaining"));
+	if ($isCustomer && !$isSupplier) {
+		$newcardbutton = dolGetButtonTitle($langs->trans("NewGlobalDiscount"), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create_remise&id='.$id.'&discount_type=0&backtopage='.$_SERVER["PHP_SELF"].'?id='.$id.'&token='.newToken());
+	} elseif (!$isCustomer && $isSupplier) {
+		$newcardbutton = dolGetButtonTitle($langs->trans("NewGlobalDiscount"), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create_remise&id='.$id.'&discount_type=1&backtopage='.$_SERVER["PHP_SELF"].'?id='.$id.'&token='.newToken());
+	} else {
+		$newcardbutton = '';
+	}
+
+	print load_fiche_titre($langs->trans("DiscountStillRemaining"), $newcardbutton);
 
 	if ($isCustomer) {
+		$newcardbutton = dolGetButtonTitle($langs->trans("NewClientGlobalDiscount"), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create_remise&id='.$id.'&discount_type=0&backtopage='.$_SERVER["PHP_SELF"].'?id='.$id.'&token='.newToken());
 		if ($isSupplier) {
 			print '<div class="fichecenter">';
 			print '<div class="fichehalfleft fichehalfleft-lg">';
-			print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
+			print load_fiche_titre($langs->trans("CustomerDiscounts"), $newcardbutton, '');
 		}
 
 		$sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
@@ -514,7 +531,7 @@ if ($socid > 0) {
 					}
 					print '</tr>';
 
-					if ($_GET["action"] == 'split' && GETPOST('remid') == $obj->rowid) {
+					if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
 						$showconfirminfo['rowid'] = $obj->rowid;
 						$showconfirminfo['amount_ttc'] = $obj->amount_ttc;
 					}
@@ -549,9 +566,10 @@ if ($socid > 0) {
 
 	if ($isSupplier) {
 		if ($isCustomer) {
+			$newcardbutton = dolGetButtonTitle($langs->trans("NewSupplierGlobalDiscount"), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create_remise&id='.$id.'&discount_type=1&backtopage='.$_SERVER["PHP_SELF"].'?id='.$id.'&token='.newToken());
 			print '</div>'; // class="fichehalfleft"
 			print '<div class="fichehalfright fichehalfright-lg">';
-			print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
+			print load_fiche_titre($langs->trans("SupplierDiscounts"), $newcardbutton, '');
 		}
 
 		/*
@@ -652,7 +670,7 @@ if ($socid > 0) {
 					}
 					print '</tr>';
 
-					if ($_GET["action"] == 'split' && GETPOST('remid') == $obj->rowid) {
+					if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
 						$showconfirminfo['rowid'] = $obj->rowid;
 						$showconfirminfo['amount_ttc'] = $obj->amount_ttc;
 					}

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

@@ -330,6 +330,8 @@ DiscountFromExcessPaid=Payments in excess of invoice %s
 AbsoluteDiscountUse=This kind of credit can be used on invoice before its validation
 CreditNoteDepositUse=Invoice must be validated to use this kind of credits
 NewGlobalDiscount=New absolute discount
+NewSupplierGlobalDiscount=New supplier absolute discount
+NewClientGlobalDiscount=New client absolute discount
 NewRelativeDiscount=New relative discount
 DiscountType=Discount type
 NoteReason=Note/Reason