Browse Source

NEW Upload file with drag and drop for VATs

Laurent Destailleur 2 năm trước cách đây
mục cha
commit
c4dc0b3c35

+ 1 - 0
ChangeLog

@@ -15,6 +15,7 @@ NEW: Accountancy - Add specific page to export accounting data rather than the j
 NEW: Accountancy - Add sub-account balance FPC22
 NEW: Accountancy - Manage customer retained warranty FPC21+
 NEW: Accountancy - Manage intra-community VAT on supplier invoices - FPC22
+NEW: Can upload a file with drag and drop on purchase invoice, vats, salaries and social contributions 
 NEW: adapt category and product pictures sizes on takepos
 NEW: Add ability of ODT support to supplier invoices
 NEW: Add a public virtual card page for each user

+ 0 - 3
htdocs/compta/sociales/card.php

@@ -453,9 +453,6 @@ if ($action == 'create') {
 
 // View mode
 if ($id > 0) {
-	$object = new ChargeSociales($db);
-	$result = $object->fetch($id);
-
 	$formconfirm = '';
 
 	if ($result > 0) {

+ 229 - 219
htdocs/compta/tva/card.php

@@ -43,9 +43,9 @@ if (isModEnabled('accounting')) {
 // Load translation files required by the page
 $langs->loadLangs(array('compta', 'banks', 'bills'));
 
-$id = GETPOST("id", 'int');
+$id = GETPOST('id', 'int');
 $ref = GETPOST('ref', 'alpha');
-$action = GETPOST("action", "aZ09");
+$action = GETPOST('action', 'aZ09');
 $confirm = GETPOST('confirm', 'alpha');
 $cancel = GETPOST('cancel', 'aZ09');
 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
@@ -80,8 +80,8 @@ if (empty($action) && empty($id) && empty($ref)) {
 }
 
 // Load object
-if ($id > 0) {
-	$object->fetch($id);
+if ($id > 0 || $ref) {
+	$object->fetch($id, $ref);
 }
 
 $permissiontoread = $user->rights->tax->charges->lire;
@@ -96,277 +96,282 @@ $socid = GETPOST('socid', 'int');
 if ($user->socid) {
 	$socid = $user->socid;
 }
-$result = restrictedArea($user, 'tax', '', 'tva', 'charges');
+$result = restrictedArea($user, 'tax', $object->id, 'tva', 'charges');
 
 
 /*
  * Actions
  */
 
-$parameters = array();
+$parameters = array('socid' => $socid);
 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
 if ($reshook < 0) {
 	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 }
 
-if ($cancel && !$id) {
-	header("Location: list.php");
-	exit;
-}
-
-if ($action == 'setlib' && $user->rights->tax->charges->creer) {
-	$object->fetch($id);
-	$result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
-	if ($result < 0) {
-		setEventMessages($object->error, $object->errors, 'errors');
+if (empty($reshook)) {
+	if ($cancel && !$id) {
+		header("Location: list.php");
+		exit;
 	}
-}
 
-if ($action == 'setdatev' && $user->rights->tax->charges->creer) {
-	$object->fetch($id);
-	$object->datev = $datev;
-	$result = $object->update($user);
-	if ($result < 0) {
-		dol_print_error($db, $object->error);
+	if ($action == 'setlib' && $user->rights->tax->charges->creer) {
+		$object->fetch($id);
+		$result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
+		if ($result < 0) {
+			setEventMessages($object->error, $object->errors, 'errors');
+		}
 	}
 
-	$action = '';
-}
+	if ($action == 'setdatev' && $user->rights->tax->charges->creer) {
+		$object->fetch($id);
+		$object->datev = $datev;
+		$result = $object->update($user);
+		if ($result < 0) {
+			dol_print_error($db, $object->error);
+		}
 
-// payment mode
-if ($action == 'setmode' && $user->rights->tax->charges->creer) {
-	$object->fetch($id);
-	$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
-	if ($result < 0) {
-		setEventMessages($object->error, $object->errors, 'errors');
+		$action = '';
 	}
-}
 
-// Bank account
-if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
-	$object->fetch($id);
-	$result = $object->setBankAccount(GETPOST('fk_account', 'int'));
-	if ($result < 0) {
-		setEventMessages($object->error, $object->errors, 'errors');
+	// payment mode
+	if ($action == 'setmode' && $user->rights->tax->charges->creer) {
+		$object->fetch($id);
+		$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
+		if ($result < 0) {
+			setEventMessages($object->error, $object->errors, 'errors');
+		}
 	}
-}
 
-// Classify paid
-if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') {
-	$object->fetch($id);
-	$result = $object->setPaid($user);
-}
-
-if ($action == 'reopen' && $user->rights->tax->charges->creer) {
-	$result = $object->fetch($id);
-	if ($object->paye) {
-		$result = $object->setUnpaid($user);
-		if ($result > 0) {
-			header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
-			exit();
-		} else {
+	// Bank account
+	if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
+		$object->fetch($id);
+		$result = $object->setBankAccount(GETPOST('fk_account', 'int'));
+		if ($result < 0) {
 			setEventMessages($object->error, $object->errors, 'errors');
 		}
 	}
-}
 
-if ($action == 'add' && !$cancel) {
-	$error = 0;
+	// Classify paid
+	if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') {
+		$object->fetch($id);
+		$result = $object->setPaid($user);
+	}
 
-	$object->fk_account = GETPOST("accountid", 'int');
-	$object->type_payment = GETPOST("type_payment", 'alphanohtml');
-	$object->num_payment = GETPOST("num_payment", 'alphanohtml');
+	if ($action == 'reopen' && $user->rights->tax->charges->creer) {
+		$result = $object->fetch($id);
+		if ($object->paye) {
+			$result = $object->setUnpaid($user);
+			if ($result > 0) {
+				header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
+				exit();
+			} else {
+				setEventMessages($object->error, $object->errors, 'errors');
+			}
+		}
+	}
 
-	$object->datev = $datev;
-	$object->datep = $datep;
+	if ($action == 'add' && !$cancel) {
+		$error = 0;
 
-	$amount = price2num(GETPOST("amount", 'alpha'));
-	if ($refund == 1) {
-		$amount = -$amount;
-	}
-	$object->amount = $amount;
-	$object->label = GETPOST("label", 'alpha');
-	$object->note = GETPOST("note", 'restricthtml');
-	$object->note_private = GETPOST("note", 'restricthtml');
-
-	if (empty($object->datep)) {
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
-		$error++;
-	}
-	if (empty($object->datev)) {
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
-		$error++;
-	}
-	if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) {
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
-		$error++;
-	}
-	if (empty($object->amount)) {
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
-		$error++;
-	}
-	if (!empty($auto_create_payment) && ($object->fk_account <= 0)) {
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors');
-		$error++;
-	}
+		$object->fk_account = GETPOST("accountid", 'int');
+		$object->type_payment = GETPOST("type_payment", 'alphanohtml');
+		$object->num_payment = GETPOST("num_payment", 'alphanohtml');
+
+		$object->datev = $datev;
+		$object->datep = $datep;
+
+		$amount = price2num(GETPOST("amount", 'alpha'));
+		if ($refund == 1) {
+			$amount = -$amount;
+		}
+		$object->amount = $amount;
+		$object->label = GETPOST("label", 'alpha');
+		$object->note = GETPOST("note", 'restricthtml');
+		$object->note_private = GETPOST("note", 'restricthtml');
 
-	if (!$error) {
-		$ret = $object->create($user);
-		if ($ret < 0) {
+		if (empty($object->datep)) {
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
+			$error++;
+		}
+		if (empty($object->datev)) {
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
+			$error++;
+		}
+		if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) {
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
+			$error++;
+		}
+		if (empty($object->amount)) {
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
+			$error++;
+		}
+		if (!empty($auto_create_payment) && ($object->fk_account <= 0)) {
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors');
 			$error++;
 		}
 
-		// Auto create payment
-		if (!empty($auto_create_payment) && !$error) {
-			$db->begin();
+		if (!$error) {
+			$ret = $object->create($user);
+			if ($ret < 0) {
+				$error++;
+			}
 
-			// Create a line of payments
-			$paiement = new PaymentVAT($db);
-			$paiement->chid         = $object->id;
-			$paiement->datepaye     = $datep;
-			$paiement->amounts      = array($object->id=>$amount); // Tableau de montant
-			$paiement->paiementtype = GETPOST("type_payment", 'alphanohtml');
-			$paiement->num_payment  = GETPOST("num_payment", 'alphanohtml');
-			$paiement->note = GETPOST("note", 'restricthtml');
-
-			if (!$error) {
-				$paymentid = $paiement->create($user, (int) GETPOST('closepaidtva'));
-				if ($paymentid < 0) {
-					$error++;
-					setEventMessages($paiement->error, null, 'errors');
-					$action = 'create';
+			// Auto create payment
+			if (!empty($auto_create_payment) && !$error) {
+				$db->begin();
+
+				// Create a line of payments
+				$paiement = new PaymentVAT($db);
+				$paiement->chid         = $object->id;
+				$paiement->datepaye     = $datep;
+				$paiement->amounts      = array($object->id=>$amount); // Tableau de montant
+				$paiement->paiementtype = GETPOST("type_payment", 'alphanohtml');
+				$paiement->num_payment  = GETPOST("num_payment", 'alphanohtml');
+				$paiement->note = GETPOST("note", 'restricthtml');
+
+				if (!$error) {
+					$paymentid = $paiement->create($user, (int) GETPOST('closepaidtva'));
+					if ($paymentid < 0) {
+						$error++;
+						setEventMessages($paiement->error, null, 'errors');
+						$action = 'create';
+					}
 				}
-			}
 
-			if (!$error) {
-				$result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
-				if (!($result > 0)) {
-					$error++;
-					setEventMessages($paiement->error, null, 'errors');
+				if (!$error) {
+					$result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
+					if (!($result > 0)) {
+						$error++;
+						setEventMessages($paiement->error, null, 'errors');
+					}
 				}
-			}
 
-			if (!$error) {
-				$db->commit();
-			} else {
-				$db->rollback();
+				if (!$error) {
+					$db->commit();
+				} else {
+					$db->rollback();
+				}
+			}
+			if (empty($error)) {
+				header("Location: card.php?id=" . $object->id);
+				exit;
 			}
 		}
-		if (empty($error)) {
-			header("Location: card.php?id=" . $object->id);
-			exit;
-		}
-	}
 
-	$action = 'create';
-}
+		$action = 'create';
+	}
 
-if ($action == 'confirm_delete' && $confirm == 'yes') {
-	$result = $object->fetch($id);
-	$totalpaid = $object->getSommePaiement();
+	if ($action == 'confirm_delete' && $confirm == 'yes') {
+		$result = $object->fetch($id);
+		$totalpaid = $object->getSommePaiement();
 
-	if (empty($totalpaid)) {
-		$db->begin();
+		if (empty($totalpaid)) {
+			$db->begin();
 
-		$ret = $object->delete($user);
-		if ($ret > 0) {
-			if ($object->fk_bank) {
-				$accountline = new AccountLine($db);
-				$result = $accountline->fetch($object->fk_bank);
-				if ($result > 0) {
-					$result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
+			$ret = $object->delete($user);
+			if ($ret > 0) {
+				if ($object->fk_bank) {
+					$accountline = new AccountLine($db);
+					$result = $accountline->fetch($object->fk_bank);
+					if ($result > 0) {
+						$result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
+					}
 				}
-			}
 
-			if ($result >= 0) {
-				$db->commit();
-				header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
-				exit;
+				if ($result >= 0) {
+					$db->commit();
+					header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
+					exit;
+				} else {
+					$object->error = $accountline->error;
+					$db->rollback();
+					setEventMessages($object->error, $object->errors, 'errors');
+				}
 			} else {
-				$object->error = $accountline->error;
 				$db->rollback();
 				setEventMessages($object->error, $object->errors, 'errors');
 			}
 		} else {
-			$db->rollback();
-			setEventMessages($object->error, $object->errors, 'errors');
+			setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
 		}
-	} else {
-		setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
 	}
-}
 
-if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) {
-	$amount = price2num(GETPOST('amount', 'alpha'), 'MT');
+	if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) {
+		$amount = price2num(GETPOST('amount', 'alpha'), 'MT');
 
-	if (empty($amount)) {
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
-		$action = 'edit';
-	} elseif (!is_numeric($amount)) {
-		setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
-		$action = 'create';
-	} else {
-		$result = $object->fetch($id);
+		if (empty($amount)) {
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
+			$action = 'edit';
+		} elseif (!is_numeric($amount)) {
+			setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
+			$action = 'create';
+		} else {
+			$result = $object->fetch($id);
 
-		$object->amount	= $amount;
+			$object->amount	= $amount;
 
-		$result = $object->update($user);
-		if ($result <= 0) {
-			setEventMessages($object->error, $object->errors, 'errors');
+			$result = $object->update($user);
+			if ($result <= 0) {
+				setEventMessages($object->error, $object->errors, 'errors');
+			}
 		}
 	}
-}
 
-// Action clone object
-if ($action == 'confirm_clone' && $confirm != 'yes') {
-	$action = '';
-}
+	// Action clone object
+	if ($action == 'confirm_clone' && $confirm != 'yes') {
+		$action = '';
+	}
 
-if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) {
-	$db->begin();
+	if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) {
+		$db->begin();
 
-	$originalId = $id;
+		$originalId = $id;
 
-	$object->fetch($id);
+		$object->fetch($id);
 
-	if ($object->id > 0) {
-		$object->id = $object->ref = null;
-		$object->paye = 0;
+		if ($object->id > 0) {
+			$object->id = $object->ref = null;
+			$object->paye = 0;
 
-		if (GETPOST('amount', 'alphanohtml')) {
-			$object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
-		}
+			if (GETPOST('amount', 'alphanohtml')) {
+				$object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
+			}
 
-		if (GETPOST('clone_label', 'alphanohtml')) {
-			$object->label = GETPOST('clone_label', 'alphanohtml');
-		} else {
-			$object->label = $langs->trans("CopyOf").' '.$object->label;
-		}
+			if (GETPOST('clone_label', 'alphanohtml')) {
+				$object->label = GETPOST('clone_label', 'alphanohtml');
+			} else {
+				$object->label = $langs->trans("CopyOf").' '.$object->label;
+			}
 
-		$newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
-		if ($newdateperiod) {
-			$object->datev = $newdateperiod;
-		}
+			$newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
+			if ($newdateperiod) {
+				$object->datev = $newdateperiod;
+			}
 
-		//if ($object->check()) {
-		$id = $object->create($user);
-		if ($id > 0) {
-			$db->commit();
-			$db->close();
+			//if ($object->check()) {
+			$id = $object->create($user);
+			if ($id > 0) {
+				$db->commit();
+				$db->close();
 
-			header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
-			exit;
+				header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
+				exit;
+			} else {
+				$id = $originalId;
+				$db->rollback();
+
+				setEventMessages($object->error, $object->errors, 'errors');
+			}
+			//}
 		} else {
-			$id = $originalId;
 			$db->rollback();
-
-			setEventMessages($object->error, $object->errors, 'errors');
+			dol_print_error($db, $object->error);
 		}
-		//}
-	} else {
-		$db->rollback();
-		dol_print_error($db, $object->error);
 	}
+
+	// Actions to build doc
+	include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
 }
 
 
@@ -382,16 +387,7 @@ $title = $langs->trans("VAT")." - ".$langs->trans("Card");
 $help_url = '';
 llxHeader('', $title, $help_url);
 
-
-if ($id) {
-	$result = $object->fetch($id);
-	if ($result <= 0) {
-		dol_print_error($db);
-		exit;
-	}
-}
-
-// Form to enter VAT
+// Form to create a VAT
 if ($action == 'create') {
 	print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
 
@@ -532,6 +528,8 @@ if ($action == 'create') {
 
 // View mode
 if ($id > 0) {
+	$formconfirm = '';
+
 	$head = vat_prepare_head($object);
 
 	$totalpaid = $object->getSommePaiement();
@@ -546,25 +544,37 @@ if ($id > 0) {
 		$formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
 		$formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
 
-		print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
+		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
 	}
 
 	if ($action == 'paid') {
 		$text = $langs->trans('ConfirmPayVAT');
-		print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
+		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
 	}
 
 	if ($action == 'delete') {
 		$text = $langs->trans('ConfirmDeleteVAT');
-		print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
+		$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
 	}
 
 	if ($action == 'edit') {
-		print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
+		print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
 		print '<input type="hidden" name="token" value="'.newToken().'">';
+		print '<input type="hidden" name="action" value="update">';
+	}
+	// Call Hook formConfirm
+	$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
+	$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+	if (empty($reshook)) {
+		$formconfirm .= $hookmanager->resPrint;
+	} elseif ($reshook > 0) {
+		$formconfirm = $hookmanager->resPrint;
 	}
 
-	print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
+	print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment', 0, '', '', 0, '', 1);
+
+	// Print form confirm
+	print $formconfirm;
 
 	$morehtmlref = '<div class="refidno">';
 	// Label of social contribution

+ 3 - 6
htdocs/compta/tva/class/tva.class.php

@@ -299,15 +299,13 @@ class Tva extends CommonObject
 	 *  Load object in memory from database
 	 *
 	 *  @param	int		$id         id object
-	 *  @param  User	$user       User that load
+	 *  @param  string	$ref        Ref of VAT (not used yet)
 	 *  @return int         		<0 if KO, >0 if OK
 	 */
-	public function fetch($id, $user = null)
+	public function fetch($id, $ref = '')
 	{
-		global $langs;
 		$sql = "SELECT";
 		$sql .= " t.rowid,";
-
 		$sql .= " t.tms,";
 		$sql .= " t.datep,";
 		$sql .= " t.datev,";
@@ -320,12 +318,11 @@ class Tva extends CommonObject
 		$sql .= " t.fk_user_creat,";
 		$sql .= " t.fk_user_modif,";
 		$sql .= " t.fk_account";
-
 		$sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
-		//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid";
 		$sql .= " WHERE t.rowid = ".((int) $id);
 
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
+
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			if ($this->db->num_rows($resql)) {

+ 8 - 1
htdocs/core/lib/functions.lib.php

@@ -11268,7 +11268,7 @@ function getElementProperties($element_type)
 
 	$regs = array();
 
-	$classfile = $classname = $classpath = $dir_output = '';
+	$classfile = $classname = $classpath = $subdir = $dir_output = '';
 
 	// Parse element/subelement
 	$module = $element_type;
@@ -11439,6 +11439,10 @@ function getElementProperties($element_type)
 	} elseif ($element_type == 'chargesociales') {
 		$classpath = 'compta/sociales/class';
 		$module = 'tax';
+	} elseif ($element_type == 'tva') {
+		$classpath = 'compta/tva/class';
+		$module = 'tax';
+		$subdir = '/vat';
 	}
 
 	if (empty($classfile)) {
@@ -11451,6 +11455,8 @@ function getElementProperties($element_type)
 		$classpath = $module.'/class';
 	}
 
+	//print 'getElementProperties subdir='.$subdir;
+
 	// Set dir_output
 	if ($module && isset($conf->$module)) {	// The generic case
 		if (!empty($conf->$module->multidir_output[$conf->entity])) {
@@ -11468,6 +11474,7 @@ function getElementProperties($element_type)
 	} elseif ($element == 'invoice_supplier') {
 		$dir_output = $conf->fournisseur->facture->dir_output;
 	}
+	$dir_output .= $subdir;
 
 	$element_properties = array(
 		'module' => $module,