';
// ThirdParty Type
print '
| '.$langs->trans("ThirdPartyType").' | ';
$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
- print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
+ print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
print ' |
';
// Category
diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php
index 7cbff15f1da..8b4a79f4dda 100644
--- a/htdocs/commande/list.php
+++ b/htdocs/commande/list.php
@@ -489,7 +489,7 @@ if ($resql)
if ($search_zip != '') $param .= '&search_zip='.urlencode($search_zip);
if ($search_state != '') $param .= '&search_state='.urlencode($search_state);
if ($search_country != '') $param .= '&search_country='.urlencode($search_country);
- if ($search_type_thirdparty != '') $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
+ if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
if ($search_product_category != '') $param .= '&search_product_category='.urlencode($search_product_category);
if ($search_categ_cus > 0) $param .= '&search_categ_cus='.urlencode($search_categ_cus);
if ($show_files) $param .= '&show_files='.urlencode($show_files);
@@ -727,7 +727,7 @@ if ($resql)
if (!empty($arrayfields['typent.code']['checked']))
{
print '
';
- print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
+ print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
print ' | ';
}
// Date order
diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php
index 1bbe2c11b19..43980135140 100644
--- a/htdocs/commande/stats/index.php
+++ b/htdocs/commande/stats/index.php
@@ -271,7 +271,7 @@ print '';
// ThirdParty Type
print '
| '.$langs->trans("ThirdPartyType").' | ';
$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
-print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
+print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
print ' |
';
// Category
diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php
index ae0840c5b86..e291d54acca 100644
--- a/htdocs/compta/bank/bankentries_list.php
+++ b/htdocs/compta/bank/bankentries_list.php
@@ -9,6 +9,8 @@
* Copyright (C) 2017-2019 Alexandre Spangaro
* Copyright (C) 2018 Ferran Marcet
* Copyright (C) 2018 Frédéric France
+ * Copyright (C) 2021 Gauthier VERDOL
+
*
* 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
@@ -41,6 +43,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
@@ -367,7 +370,7 @@ $donstatic = new Don($db);
$paymentstatic = new Paiement($db);
$paymentsupplierstatic = new PaiementFourn($db);
$paymentscstatic = new PaymentSocialContribution($db);
-$paymentvatstatic = new Tva($db);
+$paymentvatstatic = new PaymentVAT($db);
$paymentsalstatic = new PaymentSalary($db);
$paymentdonationstatic = new PaymentDonation($db);
$paymentvariousstatic = new PaymentVarious($db);
@@ -1211,7 +1214,8 @@ if ($resql)
$paymentvatstatic->id = $links[$key]['url_id'];
$paymentvatstatic->ref = $links[$key]['url_id'];
print ' '.$paymentvatstatic->getNomUrl(2);
- } elseif ($links[$key]['type'] == 'payment_salary')
+ }
+ elseif ($links[$key]['type'] == 'payment_salary')
{
$paymentsalstatic->id = $links[$key]['url_id'];
$paymentsalstatic->ref = $links[$key]['url_id'];
@@ -1273,7 +1277,10 @@ if ($resql)
{
} elseif ($links[$key]['type'] == 'sc')
{
- } else {
+ }
+ elseif ($links[$key]['type'] == 'vat')
+ {
+ } else {
// Show link with label $links[$key]['label']
if (!empty($objp->label) && !empty($links[$key]['label'])) print ' - ';
print '';
diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php
index 467f6b7b78b..abcc260d9d8 100644
--- a/htdocs/compta/bank/line.php
+++ b/htdocs/compta/bank/line.php
@@ -8,6 +8,7 @@
* Copyright (C) 2015 Jean-François Ferry
* Copyright (C) 2016 Marcos García
* Copyright (C) 2018 Frédéric France
+ * Copyright (C) 2021 Gauthier VERDOL
*
* 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
@@ -355,14 +356,22 @@ if ($result)
print img_object($langs->trans('SocialContribution'), 'bill').' ';
print $langs->trans("SocialContribution").($links[$key]['label'] ? ' - '.$links[$key]['label'] : '');
print '';
- } elseif ($links[$key]['type'] == 'payment_sc') {
+ }
+ elseif ($links[$key]['type'] == 'vat') {
+ print '';
+ print img_object($langs->trans('VATDeclaration'), 'bill').' ';
+ print $langs->trans("VATDeclaration").($links[$key]['label'] ? ' '.$links[$key]['label'] : '');
+ print '';
+ }
+ elseif ($links[$key]['type'] == 'payment_sc') {
print '';
print img_object($langs->trans('Payment'), 'payment').' ';
print $langs->trans("SocialContributionPayment");
print '';
- } elseif ($links[$key]['type'] == 'payment_vat') {
- print '';
- print img_object($langs->trans('VAT'), 'payment').' ';
+ }
+ elseif ($links[$key]['type'] == 'payment_vat') {
+ print '';
+ print img_object($langs->trans('VATPayment'), 'payment').' ';
print $langs->trans("VATPayment");
print '';
} elseif ($links[$key]['type'] == 'payment_salary') {
diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 0a7732bf21c..7b60dd639f6 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -494,7 +494,7 @@ if ($search_town) $sql .= natural_search('s.town', $search_town);
if ($search_zip) $sql .= natural_search("s.zip", $search_zip);
if ($search_state) $sql .= natural_search("state.nom", $search_state);
if ($search_country) $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
-if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
+if ($search_type_thirdparty != '' && $search_type_thirdparty != '-1') $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
if ($search_company) $sql .= natural_search('s.nom', $search_company);
if ($search_company_alias) $sql .= natural_search('s.name_alias', $search_company_alias);
if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1);
@@ -894,7 +894,7 @@ if ($resql)
if (!empty($arrayfields['typent.code']['checked']))
{
print '';
- print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'maxwidth100');
+ print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'maxwidth100', 1);
print ' | ';
}
// Payment mode
diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php
index ee96f7c39df..2a722f8723d 100644
--- a/htdocs/compta/facture/stats/index.php
+++ b/htdocs/compta/facture/stats/index.php
@@ -264,7 +264,7 @@ print '';
// ThirdParty Type
print '| '.$langs->trans("ThirdPartyType").' | ';
$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
-print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
+print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
print ' |
';
diff --git a/htdocs/compta/paiement_vat.php b/htdocs/compta/paiement_vat.php
new file mode 100644
index 00000000000..7db2aa674af
--- /dev/null
+++ b/htdocs/compta/paiement_vat.php
@@ -0,0 +1,342 @@
+
+ * Copyright (C) 2016-2018 Frédéric France
+ * Copyright (C) 2021 Gauthier VERDOL
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/compta/paiement_charge.php
+ * \ingroup tax
+ * \brief Page to add payment of a tax
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array("banks", "bills"));
+
+$chid = GETPOST("id", 'int');
+$action = GETPOST('action', 'alpha');
+$amounts = array();
+
+// Security check
+$socid = 0;
+if ($user->socid > 0)
+{
+ $socid = $user->socid;
+}
+
+
+/*
+ * Actions
+ */
+
+if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes'))
+{
+ $error = 0;
+
+ if ($_POST["cancel"])
+ {
+ $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
+ header("Location: ".$loc);
+ exit;
+ }
+
+ $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int'));
+
+ if (!(GETPOST("paiementtype", 'int') > 0))
+ {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
+ $error++;
+ $action = 'create';
+ }
+ if ($datepaye == '')
+ {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
+ $error++;
+ $action = 'create';
+ }
+ if (!empty($conf->banque->enabled) && !(GETPOST("accountid", 'int') > 0))
+ {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
+ $error++;
+ $action = 'create';
+ }
+
+ if (!$error)
+ {
+ $paymentid = 0;
+
+ // Read possible payments
+ foreach ($_POST as $key => $value)
+ {
+ if (substr($key, 0, 7) == 'amount_')
+ {
+ $other_chid = substr($key, 7);
+ $amounts[$other_chid] = price2num(GETPOST($key));
+ }
+ }
+
+ if (count($amounts) <= 0)
+ {
+ $error++;
+ setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
+ $action = 'create';
+ }
+
+ if (!$error)
+ {
+ $db->begin();
+
+ // Create a line of payments
+ $paiement = new PaymentVAT($db);
+ $paiement->chid = $chid;
+ $paiement->datepaye = $datepaye;
+ $paiement->amounts = $amounts; // Tableau de montant
+ $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml');
+ $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
+ $paiement->note = GETPOST("note", 'restricthtml');
+ $paiement->note_private = GETPOST("note", 'restricthtml');
+
+ if (!$error)
+ {
+ $paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0));
+ 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');
+ $action = 'create';
+ }
+ }
+
+ if (!$error)
+ {
+ $db->commit();
+ $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
+ header('Location: '.$loc);
+ exit;
+ }
+ else {
+ $db->rollback();
+ }
+ }
+ }
+}
+
+
+/*
+ * View
+ */
+
+llxHeader();
+
+$form = new Form($db);
+
+
+// Formulaire de creation d'un paiement de charge
+if ($action == 'create')
+{
+ $tva = new Tva($db);
+ $tva->fetch($chid);
+ $tva->accountid = $tva->fk_account ? $tva->fk_account : $tva->accountid;
+ $tva->paiementtype = $tva->type_payment;
+
+ $total = $tva->amount;
+ if (!empty($conf->use_javascript_ajax))
+ {
+ print "\n".''."\n";
+ }
+
+ print load_fiche_titre($langs->trans("DoPayment"));
+ print "
\n";
+
+ print '\n";
+}
+
+llxFooter();
+$db->close();
diff --git a/htdocs/compta/payment_vat/card.php b/htdocs/compta/payment_vat/card.php
new file mode 100644
index 00000000000..1b085dfe040
--- /dev/null
+++ b/htdocs/compta/payment_vat/card.php
@@ -0,0 +1,331 @@
+
+ * Copyright (C) 2004-2014 Laurent Destailleur
+ * Copyright (C) 2005 Marc Barilley / Ocebo
+ * Copyright (C) 2005-2009 Regis Houssin
+ * Copyright (C) 2021 Gauthier VERDOL
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/compta/payment_vat/card.php
+ * \ingroup facture
+ * \brief Onglet payment of a social contribution
+ * \remarks Fichier presque identique a fournisseur/paiement/card.php
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
+if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+// Load translation files required by the page
+$langs->loadLangs(array('bills', 'banks', 'companies'));
+
+// Security check
+$id = GETPOST("id", 'int');
+$action = GETPOST('action', 'aZ09');
+$confirm = GETPOST('confirm');
+if ($user->socid) $socid = $user->socid;
+// TODO ajouter regle pour restreindre acces paiement
+//$result = restrictedArea($user, 'facture', $id,'');
+
+$object = new PaymentVAT($db);
+if ($id > 0)
+{
+ $result = $object->fetch($id);
+ if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
+}
+
+
+/*
+ * Actions
+ */
+
+// Delete payment
+if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer)
+{
+ $db->begin();
+
+ $result = $object->delete($user);
+ if ($result > 0)
+ {
+ $db->commit();
+ header("Location: ".DOL_URL_ROOT."/compta/tva/payments.php?mode=tvaonly");
+ exit;
+ }
+ else {
+ setEventMessages($object->error, $object->errors, 'errors');
+ $db->rollback();
+ }
+}
+
+// Validate social contribution
+/*
+if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->tax->charges->creer)
+{
+ $db->begin();
+
+ $result=$object->valide();
+
+ if ($result > 0)
+ {
+ $db->commit();
+
+ $factures=array(); // TODO Get all id of invoices linked to this payment
+ foreach($factures as $id)
+ {
+ $fac = new Facture($db);
+ $fac->fetch($id);
+
+ $outputlangs = $langs;
+ if (! empty($_REQUEST['lang_id']))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $fac->generateDocument($fac->modelpdf, $outputlangs);
+ }
+ }
+
+ header('Location: card.php?id='.$object->id);
+ exit;
+ }
+ else
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ $db->rollback();
+ }
+}
+*/
+
+
+/*
+ * View
+ */
+
+llxHeader();
+
+$tva = new TVA($db);
+
+$form = new Form($db);
+
+$h = 0;
+
+$head[$h][0] = DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$id;
+$head[$h][1] = $langs->trans("VATPayment");
+$hselected = $h;
+$h++;
+
+/*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
+$head[$h][1] = $langs->trans("Info");
+$h++;
+*/
+
+
+dol_fiche_head($head, $hselected, $langs->trans("VATPayment"), -1, 'payment');
+
+/*
+ * Deletion confirmation of payment
+ */
+if ($action == 'delete')
+{
+ print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
+}
+
+/*
+ * Validation confirmation of payment
+ */
+/*
+if ($action == 'valide')
+{
+ $facid = $_GET['facid'];
+ print $form->formconfirm('card.php?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
+
+}
+*/
+
+
+$linkback = ''.$langs->trans("BackToList").'';
+
+dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
+
+
+print '';
+print '
';
+
+print '
';
+
+// Ref
+/*print '| '.$langs->trans('Ref').' | ';
+print '';
+print $form->showrefnav($object,'id','',1,'rowid','id');
+print ' |
';*/
+
+// Date
+print '| '.$langs->trans('Date').' | '.dol_print_date($object->datep, 'day').' |
';
+
+// Mode
+print '| '.$langs->trans('Mode').' | '.$langs->trans("PaymentType".$object->type_code).' |
';
+
+// Numero
+print '| '.$langs->trans('Numero').' | '.$object->num_paiement.' |
';
+
+// Montant
+print '| '.$langs->trans('Amount').' | '.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
+
+// Note
+print '| '.$langs->trans('Note').' | '.nl2br($object->note).' |
';
+
+// Bank account
+if (!empty($conf->banque->enabled))
+{
+ if ($object->bank_account)
+ {
+ $bankline = new AccountLine($db);
+ $bankline->fetch($object->bank_line);
+
+ print '';
+ print '| '.$langs->trans('BankTransactionLine').' | ';
+ print '';
+ print $bankline->getNomUrl(1, 0, 'showall');
+ print ' | ';
+ print '
';
+ }
+}
+
+print '
';
+
+print '
';
+
+dol_fiche_end();
+
+
+/*
+ * List of social contributions payed
+ */
+
+$disable_delete = 0;
+$sql = 'SELECT f.rowid as scid, f.label as label, f.paye, f.amount as tva_amount, pf.amount';
+//$sql .= ', pc.libelle as sc_type';
+$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_vat as pf,'.MAIN_DB_PREFIX.'tva as f';
+//$sql .= ', '.MAIN_DB_PREFIX.'c_chargesociales as pc';
+$sql .= ' WHERE pf.fk_tva = f.rowid';
+//$sql .= ' AND f.fk_type = pc.id';
+$sql .= ' AND f.entity = '.$conf->entity;
+$sql .= ' AND pf.rowid = '.$object->id;
+
+dol_syslog("compta/payment_vat/card.php", LOG_DEBUG);
+$resql = $db->query($sql);
+if ($resql)
+{
+ $num = $db->num_rows($resql);
+
+ $i = 0;
+ $total = 0;
+ print '
';
+ print '';
+ print '| '.$langs->trans('VATDeclaration').' | ';
+ //print ''.$langs->trans('Type').' | ';
+ print ''.$langs->trans('Label').' | ';
+ print ''.$langs->trans('ExpectedToPay').' | ';
+ print ''.$langs->trans('Status').' | ';
+ print ''.$langs->trans('PayedByThisPayment').' | ';
+ print "
\n";
+
+ if ($num > 0)
+ {
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($resql);
+
+ print '';
+ // Ref
+ print '| ';
+ $tva->fetch($objp->scid);
+ print $tva->getNomUrl(1);
+ print " | \n";
+ // Type
+ /* print '';
+ print $tva->type_label;4
+ print " | \n";*/
+ // Label
+ print ''.$objp->label.' | ';
+ // Expected to pay
+ print ''.price($objp->tva_amount).' | ';
+ // Status
+ print ''.$tva->getLibStatut(4, $objp->amount).' | ';
+ // Amount payed
+ print ''.price($objp->amount).' | ';
+ print "
\n";
+ if ($objp->paye == 1) // If at least one invoice is paid, disable delete
+ {
+ $disable_delete = 1;
+ }
+ $total = $total + $objp->amount;
+ $i++;
+ }
+ }
+
+
+ print "
\n";
+ $db->free($resql);
+}
+else {
+ dol_print_error($db);
+}
+
+
+
+/*
+ * Boutons Actions
+ */
+print '';
+
+/*
+if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
+{
+ if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
+ {
+ if ($user->rights->facture->paiement)
+ {
+ print '
'.$langs->trans('Valid').'';
+ }
+ }
+}
+*/
+
+if ($action == '')
+{
+ if ($user->rights->tax->charges->supprimer)
+ {
+ if (!$disable_delete)
+ {
+ print '
'.$langs->trans('Delete').'';
+ }
+ else {
+ print '
'.$langs->trans('Delete').'';
+ }
+ }
+}
+
+print '
';
+
+// End of page
+llxFooter();
+$db->close();
diff --git a/htdocs/compta/tva/card.php b/htdocs/compta/tva/card.php
index 493f01ee53c..37ef7d689ab 100644
--- a/htdocs/compta/tva/card.php
+++ b/htdocs/compta/tva/card.php
@@ -4,6 +4,7 @@
* Copyright (C) 2005-2013 Regis Houssin
* Copyright (C) 2015-2017 Alexandre Spangaro
* Copyright (C) 2018 Frédéric France
+ * Copyright (C) 2021 Gauthier VERDOL
*
* 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
@@ -27,15 +28,23 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
+if (!empty($conf->accounting->enabled)) {
+ include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
+}
+
// Load translation files required by the page
$langs->loadLangs(array('compta', 'banks', 'bills'));
$id = GETPOST("id", 'int');
$action = GETPOST("action", "alpha");
+$confirm = GETPOST('confirm');
$refund = GETPOST("refund", "int");
+$auto_create_payment = GETPOST("auto_create_paiement", "int");
+
if (empty($refund)) $refund = 0;
$datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
@@ -73,32 +82,71 @@ if ($action == 'setlib' && $user->rights->tax->charges->creer)
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);
+ $object->fetch($id);
+ $object->datev = $datev;
+ $result = $object->update($user);
+ if ($result < 0) dol_print_error($db, $object->error);
- $action = '';
+ $action = '';
+}
+
+// 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');
+}
+
+// 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');
+ }
+}
+
+// Classify paid
+if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes')
+{
+ $object->fetch($id);
+ $result = $object->set_paid($user);
+}
+
+if ($action == 'reopen' && $user->rights->tax->charges->creer) {
+ $result = $object->fetch($id);
+ if ($object->paye)
+ {
+ $result = $object->set_unpaid($user);
+ if ($result > 0)
+ {
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
+ exit();
+ } else {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
}
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
- $error = 0;
+ $error = 0;
- $object->accountid = GETPOST("accountid", 'int');
- $object->type_payment = GETPOST("type_payment", 'alphanohtml');
+ $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;
+ $object->datep = $datep;
$amount = price2num(GETPOST("amount", 'alpha'));
if ($refund == 1) {
$amount = -$amount;
}
- $object->amount = $amount;
+ $object->amount = $amount;
$object->label = GETPOST("label", 'alpha');
- $object->note_private = GETPOST("note", 'restricthtml');
+ $object->note = GETPOST("note", 'none');
if (empty($object->datep))
{
@@ -110,7 +158,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
$error++;
}
- if (empty($object->type_payment) || $object->type_payment < 0)
+ if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
$error++;
@@ -120,38 +168,81 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
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++;
+ }
if (!$error)
{
- $db->begin();
+ $ret = $object->create($user);
+ if ($ret < 0) $error++;
- $ret = $object->addPayment($user);
- if ($ret > 0)
+ // Auto create payment
+ if (!empty($auto_create_payment) && !$error)
{
- $db->commit();
- header("Location: list.php");
+ $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", 'none');
+
+ 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)
+ {
+ $db->commit();
+ }
+ else {
+ $db->rollback();
+ }
+ }
+ if (empty($error)) {
+ header("Location: card.php?id=" . $object->id);
exit;
- } else {
- $db->rollback();
- setEventMessages($object->error, $object->errors, 'errors');
- $action = "create";
}
}
$action = 'create';
}
-if ($action == 'delete')
+if ($action == 'confirm_delete' && $confirm == 'yes')
{
- $result = $object->fetch($id);
+ $result = $object->fetch($id);
+ $totalpaye = $object->getSommePaiement();
- if ($object->rappro == 0)
+ if (empty($totalpaye))
{
- $db->begin();
+ $db->begin();
- $ret = $object->delete($user);
- if ($ret > 0)
- {
+ $ret = $object->delete($user);
+ if ($ret > 0)
+ {
if ($object->fk_bank)
{
$accountline = new AccountLine($db);
@@ -164,21 +255,99 @@ if ($action == 'delete')
$db->commit();
header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
exit;
- } else {
+ }
+ else {
$object->error = $accountline->error;
$db->rollback();
setEventMessages($object->error, $object->errors, 'errors');
}
- } else {
- $db->rollback();
- setEventMessages($object->error, $object->errors, 'errors');
- }
- } else {
- $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
- setEventMessages($mesg, null, 'errors');
+ }
+ else {
+ $db->rollback();
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
+ else {
+ setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
}
}
+if ($action == 'update' && !$_POST["cancel"] && $user->rights->tax->charges->creer)
+{
+ $amount = price2num(GETPOST('amount'));
+
+ 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 = price2num($amount);
+
+ $result = $object->update($user);
+ if ($result <= 0)
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
+}
+
+// Action clone object
+if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }
+
+if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer))
+{
+ $db->begin();
+
+ $originalId = $id;
+
+ $object->fetch($id);
+
+ if ($object->id > 0)
+ {
+ $object->paye = 0;
+ $object->id = $object->ref = null;
+
+ 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;
+
+ //if ($object->check()) {
+ $id = $object->create($user);
+ if ($id > 0)
+ {
+ $db->commit();
+ $db->close();
+
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
+ exit;
+ }
+ else {
+ $id = $originalId;
+ $db->rollback();
+
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ //}
+ }
+ else {
+ $db->rollback();
+ dol_print_error($db, $object->error);
+ }
+}
/*
* View
@@ -205,11 +374,10 @@ if ($id)
if ($action == 'create')
{
print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
-
if (!empty($conf->use_javascript_ajax))
- {
- print "\n".''."\n";
}
- print '';
+ print '';
}
// View mode
@@ -309,7 +516,40 @@ if ($id)
{
$head = vat_prepare_head($object);
- print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
+ $totalpaye = $object->getSommePaiement();
+
+ // Clone confirmation
+ if ($action === 'clone')
+ {
+ $formquestion = array(
+ array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
+ );
+
+ //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
+ $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
+
+ print $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);
+ }
+
+ if ($action == 'delete')
+ {
+ $text = $langs->trans('ConfirmDeleteVAT');
+ print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
+ }
+
+ if ($action == 'edit')
+ {
+ print "