* Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2018 Frédéric France * * 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'; require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php'; // Load translation files required by the page $langs->loadLangs(array('compta', 'banks', 'bills')); $id=GETPOST("id",'int'); $action=GETPOST("action","alpha"); $refund=GETPOST("refund","int"); if (empty($refund)) $refund=0; // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); $object = new Tva($db); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('taxvatcard','globalcard')); /** * Actions */ if ($_POST["cancel"] == $langs->trans("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 ($action == 'setdatev' && $user->rights->tax->charges->creer) { $object->fetch($id); $object->datev=dol_mktime(12,0,0,GETPOST('datevmonth','int'),GETPOST('datevday','int'),GETPOST('datevyear','int')); $result=$object->update($user); if ($result < 0) dol_print_error($db,$object->error); $action=''; } 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"]); $object->accountid=GETPOST("accountid"); $object->type_payment=GETPOST("type_payment"); $object->num_payment=GETPOST("num_payment"); $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",'none'); if (empty($object->datev)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors'); $error++; } if (empty($object->datep)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors'); $error++; } if (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 (! $error) { $db->begin(); $ret=$object->addPayment($user); if ($ret > 0) { $db->commit(); header("Location: list.php"); exit; } else { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); $action="create"; } } $action='create'; } if ($action == 'delete') { $result=$object->fetch($id); if ($object->rappro == 0) { $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) } 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 { $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'); } } /* * View */ $form = new Form($db); $title=$langs->trans("VAT") . " - " . $langs->trans("Card"); $help_url=''; llxHeader("",$title,$helpurl); if ($id) { $result = $object->fetch($id); if ($result <= 0) { dol_print_error($db); exit; } } // Formulaire saisie tva if ($action == 'create') { print load_fiche_titre($langs->trans("VAT") . ' - ' . $langs->trans("New")); if (! empty($conf->use_javascript_ajax)) { print "\n".''."\n"; } print '
'; print ''; print ''; print '
'; print '
'; print $langs->trans("Type").':   '; print '
'; print ''; print '   '; print ''; print '
'; print "
\n"; dol_fiche_head(); print ''; print ""; print ''; print ''; // Label if ($refund == 1) { $label = $langs->trans("VATRefund"); } else { $label = $langs->trans("VATPayment"); } print ''; // Amount print ''; if (! empty($conf->banque->enabled)) { print ''; } // Type payment print '\n"; print ""; // Number print ''."\n"; // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'.$langs->trans("DatePayment").''; print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1); print '
'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).''; print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1); print '
'.$langs->trans("Label").'
'.$langs->trans("Amount").'
'.$langs->trans("BankAccount").''; $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 '
'; } // View mode if ($id) { $head=vat_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment'); $morehtmlref='
'; // Label of social contribution $morehtmlref.=$form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1); // Project $morehtmlref.='
'; $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); print '
'; print '
'; print ''; // Label //print ''; print ""; print ''; print ''; print ''; if (! empty($conf->banque->enabled)) { if ($object->fk_account > 0) { $bankline=new AccountLine($db); $bankline->fetch($object->fk_bank); print ''; print ''; print ''; print ''; } } // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("DatePayment").''; print dol_print_date($object->datep,'day'); print '
'; print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day'); print ''; print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day'); //print dol_print_date($object->datev,'day'); print '
'.$langs->trans("Amount").''.price($object->amount).'
'.$langs->trans('BankTransactionLine').''; print $bankline->getNomUrl(1,0,'showall'); print '
'; print '
'; dol_fiche_end(); /* * Action buttons */ print "
\n"; if ($object->rappro == 0) { if (! empty($user->rights->tax->charges->supprimer)) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans("Delete").''; } } else { print ''.$langs->trans("Delete").''; } print "
"; } llxFooter(); $db->close();