*
* 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/bank/various_expenses/card.php
* \ingroup bank
* \brief Page of various expenses
*/
require '../../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array("compta", "banks", "bills", "users", "accountancy"));
// Get parameters
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
$accountid=GETPOST("accountid") > 0 ? GETPOST("accountid","int") : 0;
$label=GETPOST("label","alpha");
$sens=GETPOST("sens","int");
$amount=GETPOST("amount");
$paymenttype=GETPOST("paymenttype");
$accountancy_code=GETPOST("accountancy_code","int");
$projectid = (GETPOST('projectid','int') ? GETPOST('projectid', 'int') : GETPOST('fk_project','int'));
// Security check
$socid = GETPOST("socid","int");
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'banque', '', '', '');
$object = new PaymentVarious($db);
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('variouscard','globalcard'));
/**
* Actions
*/
$parameters=array();
$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 (empty($reshook))
{
// Link to a project
if ($action == 'classin' && $user->rights->banque->modifier)
{
$object->fetch($id);
$object->setProject(GETPOST('projectid'));
}
if ($cancel)
{
if ($action != 'addlink')
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/compta/bank/various_payment/index.php',1);
header("Location: ".$urltogo);
exit;
}
if ($id > 0 || ! empty($ref)) $ret = $object->fetch($id,$ref);
$action='';
}
if ($action == 'add')
{
$error=0;
$datep=dol_mktime(12,0,0, GETPOST("datepmonth",'int'), GETPOST("datepday",'int'), GETPOST("datepyear",'int'));
$datev=dol_mktime(12,0,0, GETPOST("datevmonth",'int'), GETPOST("datevday",'int'), GETPOST("datevyear",'int'));
if (empty($datev)) $datev=$datep;
$object->ref=''; // TODO
$object->accountid=GETPOST("accountid",'int') > 0 ? GETPOST("accountid","int") : 0;
$object->datev=$datev;
$object->datep=$datep;
$object->amount=price2num(GETPOST("amount",'alpha'));
$object->label=GETPOST("label",'none');
$object->note=GETPOST("note",'none');
$object->type_payment=GETPOST("paymenttype",'int') > 0 ? GETPOST("paymenttype", "int") : 0;
$object->num_payment=GETPOST("num_payment",'alpha');
$object->fk_user_author=$user->id;
$object->accountancy_code=GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code","int") : "";
$object->sens=GETPOST('sens');
$object->fk_project= GETPOST('fk_project','int');
if (empty($datep) || empty($datev))
{
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
$error++;
}
if (empty($object->type_payment) || $object->type_payment < 0)
{
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
$error++;
}
if (empty($object->amount))
{
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
$error++;
}
if (! empty($conf->banque->enabled) && ! $object->accountid > 0)
{
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
$error++;
}
if (! empty($conf->accounting->enabled) && ! $object->accountancy_code)
{
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
$error++;
}
if (! $error)
{
$db->begin();
$ret=$object->create($user);
if ($ret > 0)
{
$db->commit();
header("Location: index.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/bank/various_payment/index.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
{
setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
}
}
}
/*
* View
*/
llxHeader("",$langs->trans("VariousPayment"));
$form = new Form($db);
if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
if (! empty($conf->projet->enabled)) $formproject = new FormProjets($db);
if ($id)
{
$object = new PaymentVarious($db);
$result = $object->fetch($id);
if ($result <= 0)
{
dol_print_error($db);
exit;
}
}
/* ************************************************************************** */
/* */
/* Create mode */
/* */
/* ************************************************************************** */
if ($action == 'create')
{
print '
';
}
/* ************************************************************************** */
/* */
/* View mode */
/* */
/* ************************************************************************** */
if ($id)
{
$head=various_payment_prepare_head($object);
dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, 'payment');
$morehtmlref='';
// Project
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
$morehtmlref.=$langs->trans('Project') . ' ';
if ($user->rights->tax->charges->creer)
{
if ($action != 'classify')
$morehtmlref.='
' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : ';
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref.='
';
} else {
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
}
} else {
if (! empty($object->fk_project)) {
$proj = new Project($db);
$proj->fetch($object->fk_project);
$morehtmlref.='
';
$morehtmlref.=$proj->ref;
$morehtmlref.='';
} else {
$morehtmlref.='';
}
}
}
$morehtmlref.='
';
$linkback = ''.$langs->trans("BackToList").'';
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
print '';
print '
';
print '
';
// Label
print '| '.$langs->trans("Label").' | '.$object->label.' |
';
// Payment date
print "";
print '| '.$langs->trans("DatePayment").' | ';
print dol_print_date($object->datep,'day');
print ' |
';
// Value date
print '| '.$langs->trans("DateValue").' | ';
print dol_print_date($object->datev,'day');
print ' |
';
// Debit / Credit
if ($object->sens == '1') $sens = $langs->trans("Credit"); else $sens = $langs->trans("Debit");
print '| '.$langs->trans("Sens").' | '.$sens.' |
';
print '| '.$langs->trans("Amount").' | '.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).' |
';
// Accountancy code
print '| ';
print $langs->trans("AccountAccounting");
print ' | ';
if (! empty($conf->accounting->enabled))
{
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('',$object->accountancy_code, 1);
print $accountingaccount->getNomUrl(0,1,1,'',1);
} else {
print $object->accountancy_code;
}
print ' |
';
if (! empty($conf->banque->enabled))
{
if ($object->fk_account > 0)
{
$bankline=new AccountLine($db);
$bankline->fetch($object->fk_bank);
print '';
print '| '.$langs->trans('BankTransactionLine').' | ';
print '';
print $bankline->getNomUrl(1,0,'showall');
print ' | ';
print '
';
}
}
// Other attributes
$parameters=array('socid'=>$object->id);
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '
';
print '
';
print '';
print '';
dol_fiche_end();
/*
* Action buttons
*/
print '";
}
llxFooter();
$db->close();