* Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2015 Alexandre Spangaro * * 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/tva/card.php * \ingroup tax * \brief Page of VAT payments */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("compta"); $langs->load("banks"); $langs->load("bills"); $id=GETPOST("id",'int'); $action=GETPOST('action'); // Security check $socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); $tva = new Tva($db); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('taxvatcard','globalcard')); /** * Actions */ if ($_POST["cancel"] == $langs->trans("Cancel")) { header("Location: reglement.php"); exit; } if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) { $error=0; $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]); $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]); $tva->accountid=GETPOST("accountid"); $tva->type_payment=GETPOST("type_payment"); $tva->num_payment=GETPOST("num_payment"); $tva->datev=$datev; $tva->datep=$datep; $tva->amount=GETPOST("amount"); $tva->label=GETPOST("label"); $tva->note=GETPOST("note"); if (empty($tva->datev)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateValue")),'errors'); $error++; } if (empty($tva->datep)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DatePayment")),'errors'); $error++; } if (empty($tva->type_payment) || $tva->type_payment < 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentMode")),'errors'); $error++; } if (empty($tva->amount)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")),'errors'); $error++; } if (! $error) { $db->begin(); $ret=$tva->addPayment($user); if ($ret > 0) { $db->commit(); header("Location: reglement.php"); exit; } else { $db->rollback(); setEventMessage($tva->error, 'errors'); $action="create"; } } $action='create'; } if ($action == 'delete') { $result=$tva->fetch($id); if ($tva->rappro == 0) { $db->begin(); $ret=$tva->delete($user); if ($ret > 0) { if ($tva->fk_bank) { $accountline=new AccountLine($db); $result=$accountline->fetch($tva->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/reglement.php'); exit; } else { $tva->error=$accountline->error; $db->rollback(); setEventMessage($tva->error,'errors'); } } else { $db->rollback(); setEventMessage($tva->error,'errors'); } } else { setEventMessage('Error try do delete a line linked to a conciliated bank transaction','errors'); } } /* * View */ llxHeader(); $form = new Form($db); if ($id) { $vatpayment = new Tva($db); $result = $vatpayment->fetch($id); if ($result <= 0) { dol_print_error($db); exit; } } // Formulaire saisie tva if ($action == 'create') { print "
\n"; print ''; print ''; print_fiche_titre($langs->trans("NewVATPayment")); dol_fiche_head(); print ''; print ""; print ''; print ''; // Label print ''; // Amount print ''; if (! empty($conf->banque->enabled)) { print ''; // Type payment print '\n"; print ""; // Number print ''."\n"; } // Other attributes $parameters=array('colspan' => ' colspan="1"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print '
'.$langs->trans("DatePayment").''; print $form->select_date($datep,"datep",'','','','add'); print '
'.$langs->trans("DateValue").''; print $form->select_date($datev,"datev",'','','','add'); print '
'.$langs->trans("Label").'trans("VATPayment")).'">
'.$langs->trans("Amount").'
'.$langs->trans("Account").''; $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant print '
'.$langs->trans("PaymentMode").''; $form->select_types_paiements(GETPOST("type_payment"), "type_payment"); print "
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ if ($id) { $h = 0; $head[$h][0] = DOL_URL_ROOT.'/compta/tva/card.php?id='.$vatpayment->id; $head[$h][1] = $langs->trans('Card'); $head[$h][2] = 'card'; $h++; dol_fiche_head($head, 'card', $langs->trans("VATPayment"), 0, 'payment'); print ''; print ""; print ''; // Label print ''; print ""; print ''; print ''; print ''; if (! empty($conf->banque->enabled)) { if ($vatpayment->fk_account > 0) { $bankline=new AccountLine($db); $bankline->fetch($vatpayment->fk_bank); print ''; print ''; print ''; print ''; } } // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$vatpayment,$action); // Note that $action and $object may have been modified by hook print '
'.$langs->trans("Ref").''; print $vatpayment->ref; print '
'.$langs->trans("Label").''.$vatpayment->label.'
'.$langs->trans("DatePayment").''; print dol_print_date($vatpayment->datep,'day'); print '
'.$langs->trans("DateValue").''; print dol_print_date($vatpayment->datev,'day'); print '
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'.$langs->trans('BankTransactionLine').''; print $bankline->getNomUrl(1,0,'showall'); print '
'; print ''; /* * Boutons d'actions */ print "
\n"; if ($vatpayment->rappro == 0) { if (! empty($user->rights->tax->charges->supprimer)) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans("Delete").''; } } else { print ''.$langs->trans("Delete").''; } print "
"; } $db->close(); llxFooter();