*
* 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/salaries/fiche.php
* \ingroup tax
* \brief Page of salaries payments
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->load("compta");
$langs->load("banks");
$langs->load("bills");
$langs->load("users");
$langs->load("salaries");
$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');
$sal = new PaymentSalary($db);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('taxsalarycard'));
/**
* Actions
*/
if ($_POST["cancel"] == $langs->trans("Cancel"))
{
header("Location: index.php");
exit;
}
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$db->begin();
$datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
$datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
$datesp=dol_mktime(12,0,0, $_POST["datespmonth"], $_POST["datespday"], $_POST["datespyear"]);
$dateep=dol_mktime(12,0,0, $_POST["dateepmonth"], $_POST["dateepday"], $_POST["dateepyear"]);
$sal->accountid=$_POST["accountid"];
$sal->paymenttype=$_POST["paiementtype"];
$sal->fk_user=$_POST["fk_user"];
$sal->datev=$datev;
$sal->datep=$datep;
$sal->amount=$_POST["amount"];
$sal->label=$_POST["label"];
$sal->datesp=$datesp;
$sal->dateep=$dateep;
$ret=$sal->addPayment($user);
if ($ret > 0)
{
$db->commit();
header("Location: index.php");
exit;
}
else
{
$db->rollback();
setEventMessage($sal->error, 'errors');
$action="create";
}
}
if ($action == 'delete')
{
$result=$sal->fetch($id);
if ($sal->rappro == 0)
{
$db->begin();
$ret=$sal->delete($user);
if ($ret > 0)
{
if ($sal->fk_bank)
{
$accountline=new AccountLine($db);
$result=$accountline->fetch($sal->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/salaries/index.php');
exit;
}
else
{
$sal->error=$accountline->error;
$db->rollback();
setEventMessage($sal->error,'errors');
}
}
else
{
$db->rollback();
setEventMessage($sal->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)
{
$salpayment = new PaymentSalary($db);
$result = $salpayment->fetch($id);
if ($result <= 0)
{
dol_print_error($db);
exit;
}
}
// Formulaire saisie salaire
if ($action == 'create')
{
$year_current = strftime("%Y",dol_now());
$pastmonth = strftime("%m",dol_now()) - 1;
$pastmonthyear = $year_current;
if ($pastmonth == 0)
{
$pastmonth = 12;
$pastmonthyear--;
}
$datesp=dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
$dateep=dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
if (empty($datesp) || empty($dateep)) // We define date_start and date_end
{
$datesp=dol_get_first_day($pastmonthyear,$pastmonth,false); $dateep=dol_get_last_day($pastmonthyear,$pastmonth,false);
}
print "
';
}
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
if ($id)
{
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/salaries/fiche.php?id='.$salpayment->id;
$head[$h][1] = $langs->trans('Card');
$head[$h][2] = 'card';
$h++;
dol_fiche_head($head, 'card', $langs->trans("SalaryPayment"), 0, 'payment');
print '';
print "";
print '| '.$langs->trans("Ref").' | ';
print $salpayment->ref;
print ' |
';
// Person
print '| '.$langs->trans("Person").' | ';
$usersal=new User($db);
$usersal->fetch($salpayment->fk_user);
print $usersal->getNomUrl(1);
print ' |
';
// Label
print '| '.$langs->trans("Label").' | '.$salpayment->label.' |
';
print "";
print '| '.$langs->trans("DateStartPeriod").' | ';
print dol_print_date($salpayment->datesp,'day');
print ' |
';
print '| '.$langs->trans("DateEndPeriod").' | ';
print dol_print_date($salpayment->dateep,'day');
print ' |
';
print "";
print '| '.$langs->trans("DatePayment").' | ';
print dol_print_date($salpayment->datep,'day');
print ' |
';
print '| '.$langs->trans("DateValue").' | ';
print dol_print_date($salpayment->datev,'day');
print ' |
';
print '| '.$langs->trans("Amount").' | '.price($salpayment->amount).' |
';
if (! empty($conf->banque->enabled))
{
if ($salpayment->fk_account > 0)
{
$bankline=new AccountLine($db);
$bankline->fetch($salpayment->fk_bank);
print '';
print '| '.$langs->trans('BankTransactionLine').' | ';
print '';
print $bankline->getNomUrl(1,0,'showall');
print ' | ';
print '
';
}
}
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$salpayment,$action); // Note that $action and $object may have been modified by hook
print '
';
print '';
/*
* Boutons d'actions
*/
print "";
}
$db->close();
llxFooter();
?>