Fix and uniformize code for payment of salaries.
This commit is contained in:
parent
4828d1e89a
commit
59042a30e1
@ -185,7 +185,7 @@ if ($_GET["action"] == 'create')
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$charge->lib."</td></tr>\n";
|
||||
print '<tr><td>'.$langs->trans("DateDue")."</td><td colspan=\"2\">".dol_print_date($charge->date_ech,'day')."</td></tr>\n";
|
||||
|
||||
print '<tr><td>'.$langs->trans("AmountTTC")."</td><td colspan=\"2\"><b>".price($charge->amount).'</b> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("Amount")."</td><td colspan=\"2\">".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
|
||||
$sql = "SELECT sum(p.amount) as total";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
|
||||
@ -197,8 +197,8 @@ if ($_GET["action"] == 'create')
|
||||
$sumpaid = $obj->total;
|
||||
$db->free();
|
||||
}
|
||||
print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2"><b>'.price($sumpaid).'</b> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
|
||||
print "<tr><td valign=\"top\">".$langs->trans("RemainderToPay")."</td><td colspan=\"3\"><b>".price($total - $sumpaid).'</b> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2">'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
print "<tr><td valign=\"top\">".$langs->trans("RemainderToPay")."</td><td colspan=\"3\">".price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
|
||||
print "<tr class=\"liste_titre\"><td colspan=\"3\">".$langs->trans("Payment").'</td>';
|
||||
|
||||
@ -223,9 +223,10 @@ if ($_GET["action"] == 'create')
|
||||
$form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '',1); // Show opend bank account list
|
||||
print '</td></tr>';
|
||||
|
||||
// Number
|
||||
print '<tr><td>'.$langs->trans('Numero');
|
||||
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
|
||||
print "<td><input name=\"num_paiement\" type=\"text\"></td></tr>\n";
|
||||
print '<td><input name="num_paiement" type="text" value="'.GETPOST('num_paiement').'"></td></tr>'."\n";
|
||||
|
||||
/*
|
||||
* Autres charges impayees
|
||||
@ -238,7 +239,7 @@ if ($_GET["action"] == 'create')
|
||||
print '<tr class="liste_titre">';
|
||||
//print '<td>'.$langs->trans("SocialContribution").'</td>';
|
||||
print '<td align="left">'.$langs->trans("DateDue").'</td>';
|
||||
print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Amount").'</td>';
|
||||
print '<td align="right">'.$langs->trans("AlreadyPaid").'</td>';
|
||||
print '<td align="right">'.$langs->trans("RemainderToPay").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Amount").'</td>';
|
||||
@ -296,7 +297,7 @@ if ($_GET["action"] == 'create')
|
||||
{
|
||||
// Print total
|
||||
print "<tr ".$bc[!$var].">";
|
||||
print '<td colspan="2" align="left">'.$langs->trans("TotalTTC").':</td>';
|
||||
print '<td colspan="2" align="left">'.$langs->trans("Total").':</td>';
|
||||
print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
|
||||
print "<td align=\"right\"><b>".price($totalrecu)."</b></td>";
|
||||
print "<td align=\"right\"><b>".price($total_ttc - $totalrecu)."</b></td>";
|
||||
@ -304,29 +305,18 @@ if ($_GET["action"] == 'create')
|
||||
print "</tr>\n";
|
||||
}
|
||||
print "</table></td></tr>\n";
|
||||
// }
|
||||
// $db->free();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// print $sql ."<br>".$db->error();
|
||||
// }
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
print "</table>";
|
||||
|
||||
print '<br><center>';
|
||||
//print '<tr><td colspan="3" align="center">';
|
||||
|
||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
|
||||
print '</center>';
|
||||
//print '</td></tr>';
|
||||
|
||||
print "</form>\n";
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
<?php
|
||||
/* Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/salaries/class/paymentsalary.class.php
|
||||
@ -26,270 +26,199 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
|
||||
|
||||
|
||||
/**
|
||||
* Put here description of your class
|
||||
* Class to manage salary payments
|
||||
*/
|
||||
class PaymentSalary extends CommonObject
|
||||
{
|
||||
//public $element='payment_salary'; //!< Id that identify managed objects
|
||||
//public $table_element='payment_salary'; //!< Name of table without prefix where object is stored
|
||||
|
||||
var $id;
|
||||
var $ref;
|
||||
var $id;
|
||||
var $ref;
|
||||
|
||||
var $tms;
|
||||
var $fk_user;
|
||||
var $datep;
|
||||
var $datep;
|
||||
var $datev;
|
||||
var $amount;
|
||||
var $type_payment;
|
||||
var $num_payment;
|
||||
var $label;
|
||||
var $datesp;
|
||||
var $dateep;
|
||||
var $datesp;
|
||||
var $dateep;
|
||||
var $note;
|
||||
var $fk_bank;
|
||||
var $fk_user_creat;
|
||||
var $fk_user_modif;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->element = 'payment_salary';
|
||||
$this->table_element = 'payment_salary';
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->element = 'payment_salary';
|
||||
$this->table_element = 'payment_salary';
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update database
|
||||
*
|
||||
* @param User $user User that modify
|
||||
* @param int $notrigger 0=no, 1=yes (no update trigger)
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update($user=0, $notrigger=0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
/**
|
||||
* Create in database
|
||||
*
|
||||
* @param User $user User that create
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf, $langs;
|
||||
$error=0;
|
||||
|
||||
$error=0;
|
||||
// Clean parameters
|
||||
$this->fk_user=trim($this->fk_user);
|
||||
$this->amount=trim($this->amount);
|
||||
$this->label=trim($this->label);
|
||||
$this->note=trim($this->note);
|
||||
$this->fk_bank=trim($this->fk_bank);
|
||||
$this->fk_user_creat=trim($this->fk_user_creat);
|
||||
$this->fk_user_modif=trim($this->fk_user_modif);
|
||||
|
||||
// Clean parameters
|
||||
$this->fk_user=trim($this->fk_user);
|
||||
$this->amount=trim($this->amount);
|
||||
$this->label=trim($this->label);
|
||||
$this->note=trim($this->note);
|
||||
$this->fk_bank=trim($this->fk_bank);
|
||||
$this->fk_user_creat=trim($this->fk_user_creat);
|
||||
$this->fk_user_modif=trim($this->fk_user_modif);
|
||||
// Check parameters
|
||||
if (empty($this->fk_user) || $this->fk_user < 0)
|
||||
{
|
||||
$this->error='ErrorBadParameter';
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
// Update request
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary(";
|
||||
$sql.= "tms,";
|
||||
$sql.= "fk_user,";
|
||||
$sql.= "datep,";
|
||||
$sql.= "datev,";
|
||||
$sql.= "amount,";
|
||||
$sql.= "label,";
|
||||
$sql.= "datesp,";
|
||||
$sql.= "dateep,";
|
||||
$sql.= "note,";
|
||||
$sql.= "fk_bank,";
|
||||
$sql.= "fk_user_creat,";
|
||||
$sql.= "fk_user_modif";
|
||||
$sql.= " tms=".$this->db->idate($this->tms).",";
|
||||
$sql.= " fk_user='".$this->fk_user."',";
|
||||
$sql.= " datep=".$this->db->idate($this->datep).",";
|
||||
$sql.= " datev=".$this->db->idate($this->datev).",";
|
||||
$sql.= " amount='".$this->amount."',";
|
||||
$sql.= " fk_typepayment=".$this->fk_typepayment."',";
|
||||
$sql.= " num_payment='".$this->num_payment."',";
|
||||
$sql.= " label='".$this->db->escape($this->label)."',";
|
||||
$sql.= " datesp=".$this->db->idate($this->datesp).",";
|
||||
$sql.= " dateep=".$this->db->idate($this->dateep).",";
|
||||
$sql.= " note='".$this->db->escape($this->note)."',";
|
||||
$sql.= " fk_bank=".($this->fk_bank > 0 ? "'".$this->fk_bank."'":"null").",";
|
||||
$sql.= " fk_user_creat='".$this->fk_user_creat."',";
|
||||
$sql.= " fk_user_modif='".$this->fk_user_modif."'";
|
||||
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
$sql.= " '".$this->db->idate($this->tms).",";
|
||||
$sql.= " '".$this->fk_user."',";
|
||||
$sql.= " '".$this->db->idate($this->datep)."',";
|
||||
$sql.= " '".$this->db->idate($this->datev)."',";
|
||||
$sql.= " '".$this->amount."',";
|
||||
$sql.= " '".$this->label."',";
|
||||
$sql.= " '".$this->db->idate($this->datesp)."',";
|
||||
$sql.= " '".$this->db->idate($this->dateep)."',";
|
||||
$sql.= " '".$this->note."',";
|
||||
$sql.= " ".($this->fk_bank <= 0 ? "NULL" : "'".$this->fk_bank."'").",";
|
||||
$sql.= " '".$this->fk_user_creat."',";
|
||||
$sql.= " '".$this->fk_user_modif."'";
|
||||
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
|
||||
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_CREATE',$this,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update database
|
||||
*
|
||||
* @param User $user User that modify
|
||||
* @param int $notrigger 0=no, 1=yes (no update trigger)
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update($user=0, $notrigger=0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
// Clean parameters
|
||||
$this->fk_user=trim($this->fk_user);
|
||||
$this->amount=trim($this->amount);
|
||||
$this->label=trim($this->label);
|
||||
$this->note=trim($this->note);
|
||||
$this->fk_bank=trim($this->fk_bank);
|
||||
$this->fk_user_creat=trim($this->fk_user_creat);
|
||||
$this->fk_user_modif=trim($this->fk_user_modif);
|
||||
|
||||
// Check parameters
|
||||
if (empty($this->fk_user) || $this->fk_user < 0)
|
||||
{
|
||||
$this->error='ErrorBadParameter';
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update request
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
|
||||
|
||||
$sql.= " tms=".$this->db->idate($this->tms).",";
|
||||
$sql.= " fk_user='".$this->fk_user."',";
|
||||
$sql.= " datep=".$this->db->idate($this->datep).",";
|
||||
$sql.= " datev=".$this->db->idate($this->datev).",";
|
||||
$sql.= " amount='".$this->amount."',";
|
||||
$sql.= " label='".$this->db->escape($this->label)."',";
|
||||
$sql.= " datesp=".$this->db->idate($this->datesp).",";
|
||||
$sql.= " dateep=".$this->db->idate($this->dateep).",";
|
||||
$sql.= " note='".$this->db->escape($this->note)."',";
|
||||
$sql.= " fk_bank='".$this->fk_bank."',";
|
||||
$sql.= " fk_user_creat='".$this->fk_user_creat."',";
|
||||
$sql.= " fk_user_modif='".$this->fk_user_modif."'";
|
||||
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_MODIFY',$this,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
}
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_MODIFY',$this,$user,$langs,$conf);
|
||||
if ($result < 0) {
|
||||
$error++; $this->errors=$interface->errors;
|
||||
}
|
||||
// Fin appel triggers
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load object in memory from database
|
||||
*
|
||||
* @param int $id id object
|
||||
* @param User $user User that load
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function fetch($id, $user=0)
|
||||
{
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " s.rowid,";
|
||||
/**
|
||||
* Load object in memory from database
|
||||
*
|
||||
* @param int $id id object
|
||||
* @param User $user User that load
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function fetch($id, $user=0)
|
||||
{
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " s.rowid,";
|
||||
|
||||
$sql.= " s.tms,";
|
||||
$sql.= " s.fk_user,";
|
||||
$sql.= " s.datep,";
|
||||
$sql.= " s.datev,";
|
||||
$sql.= " s.amount,";
|
||||
$sql.= " s.label,";
|
||||
$sql.= " s.datesp,";
|
||||
$sql.= " s.dateep,";
|
||||
$sql.= " s.note,";
|
||||
$sql.= " s.fk_bank,";
|
||||
$sql.= " s.fk_user_creat,";
|
||||
$sql.= " s.fk_user_modif,";
|
||||
$sql.= " b.fk_account,";
|
||||
$sql.= " b.fk_type,";
|
||||
$sql.= " b.rappro";
|
||||
$sql.= " s.tms,";
|
||||
$sql.= " s.fk_user,";
|
||||
$sql.= " s.datep,";
|
||||
$sql.= " s.datev,";
|
||||
$sql.= " s.amount,";
|
||||
$sql.= " s.fk_typepayment,";
|
||||
$sql.= " s.num_payment,";
|
||||
$sql.= " s.label,";
|
||||
$sql.= " s.datesp,";
|
||||
$sql.= " s.dateep,";
|
||||
$sql.= " s.note,";
|
||||
$sql.= " s.fk_bank,";
|
||||
$sql.= " s.fk_user_creat,";
|
||||
$sql.= " s.fk_user_modif,";
|
||||
$sql.= " b.fk_account,";
|
||||
$sql.= " b.fk_type,";
|
||||
$sql.= " b.rappro";
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
|
||||
$sql.= " WHERE s.rowid = ".$id;
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
|
||||
$sql.= " WHERE s.rowid = ".$id;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->rowid;
|
||||
$this->tms = $this->db->jdate($obj->tms);
|
||||
$this->fk_user = $obj->fk_user;
|
||||
$this->datep = $this->db->jdate($obj->datep);
|
||||
$this->datev = $this->db->jdate($obj->datev);
|
||||
$this->amount = $obj->amount;
|
||||
$this->label = $obj->label;
|
||||
$this->datesp = $this->db->jdate($obj->datesp);
|
||||
$this->dateep = $this->db->jdate($obj->dateep);
|
||||
$this->note = $obj->note;
|
||||
$this->fk_bank = $obj->fk_bank;
|
||||
$this->fk_user_creat = $obj->fk_user_creat;
|
||||
$this->fk_user_modif = $obj->fk_user_modif;
|
||||
$this->fk_account = $obj->fk_account;
|
||||
$this->fk_type = $obj->fk_type;
|
||||
$this->rappro = $obj->rappro;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->rowid;
|
||||
$this->tms = $this->db->jdate($obj->tms);
|
||||
$this->fk_user = $obj->fk_user;
|
||||
$this->datep = $this->db->jdate($obj->datep);
|
||||
$this->datev = $this->db->jdate($obj->datev);
|
||||
$this->amount = $obj->amount;
|
||||
$this->type_payement = $obj->fk_typepayment;
|
||||
$this->num_payment = $obj->num_payment;
|
||||
$this->label = $obj->label;
|
||||
$this->datesp = $this->db->jdate($obj->datesp);
|
||||
$this->dateep = $this->db->jdate($obj->dateep);
|
||||
$this->note = $obj->note;
|
||||
$this->fk_bank = $obj->fk_bank;
|
||||
$this->fk_user_creat = $obj->fk_user_creat;
|
||||
$this->fk_user_modif = $obj->fk_user_modif;
|
||||
$this->fk_account = $obj->fk_account;
|
||||
$this->fk_type = $obj->fk_type;
|
||||
$this->rappro = $obj->rappro;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete object in database
|
||||
*
|
||||
* @param User $user User that delete
|
||||
* @param User $user User that delete
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function delete($user)
|
||||
@ -301,32 +230,34 @@ class PaymentSalary extends CommonObject
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_DELETE',$this,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_DELETE',$this,$user,$langs,$conf);
|
||||
if ($result < 0) {
|
||||
$error++; $this->errors=$interface->errors;
|
||||
}
|
||||
// Fin appel triggers
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise an instance with random values.
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
* Initialise an instance with random values.
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function initAsSpecimen()
|
||||
{
|
||||
@ -334,7 +265,7 @@ class PaymentSalary extends CommonObject
|
||||
|
||||
$this->tms='';
|
||||
$this->fk_user='';
|
||||
$this->datep='';
|
||||
$this->datep='';
|
||||
$this->datev='';
|
||||
$this->amount='';
|
||||
$this->label='';
|
||||
@ -346,192 +277,198 @@ class PaymentSalary extends CommonObject
|
||||
$this->fk_user_modif='';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute un paiement de salaire
|
||||
*
|
||||
/**
|
||||
* Ajoute un paiement de salaire
|
||||
*
|
||||
* @param User $user Object user that insert
|
||||
* @return int <0 if KO, rowid in tva table if OK
|
||||
*/
|
||||
function addPayment($user)
|
||||
{
|
||||
global $conf,$langs;
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
$this->db->begin();
|
||||
// Clean parameters
|
||||
$this->amount=price2num(trim($this->amount));
|
||||
|
||||
// Clean parameters
|
||||
$this->amount=price2num(trim($this->amount));
|
||||
// Check parameters
|
||||
if (! $this->label)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
|
||||
return -3;
|
||||
}
|
||||
if ($this->fk_user < 0 || $this->fk_user == '')
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Employee"));
|
||||
return -4;
|
||||
}
|
||||
if ($this->amount < 0 || $this->amount == '')
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"));
|
||||
return -5;
|
||||
}
|
||||
if (! empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account"));
|
||||
return -6;
|
||||
}
|
||||
if (! empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
|
||||
return -6;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (! $this->label)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
|
||||
return -3;
|
||||
}
|
||||
if ($this->fk_user < 0 || $this->fk_user == '')
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Employee"));
|
||||
return -4;
|
||||
}
|
||||
if ($this->amount < 0 || $this->amount == '')
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"));
|
||||
return -5;
|
||||
}
|
||||
if (! empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Account"));
|
||||
return -6;
|
||||
}
|
||||
if (! empty($conf->banque->enabled) && (empty($this->paymenttype) || $this->paymenttype <= 0))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
|
||||
return -6;
|
||||
}
|
||||
$this->db->begin();
|
||||
|
||||
// Insertion dans table des paiement salaires
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (fk_user";
|
||||
$sql.= ", datep";
|
||||
$sql.= ", datev";
|
||||
$sql.= ", amount";
|
||||
if ($this->note) $sql.=", note";
|
||||
if ($this->label) $sql.=", label";
|
||||
$sql.= ", datesp";
|
||||
$sql.= ", dateep";
|
||||
$sql.= ", fk_user_creat";
|
||||
$sql.= ", fk_bank";
|
||||
$sql.= ", entity";
|
||||
$sql.= ") ";
|
||||
$sql.= " VALUES (";
|
||||
$sql.= "'".$this->fk_user."'";
|
||||
$sql.= ", '".$this->db->idate($this->datep)."'";
|
||||
$sql.= ", '".$this->db->idate($this->datev)."'";
|
||||
$sql.= ", ".$this->amount;
|
||||
if ($this->note) $sql.= ", '".$this->db->escape($this->note)."'";
|
||||
if ($this->label) $sql.= ", '".$this->db->escape($this->label)."'";
|
||||
$sql.= ", '".$this->db->idate($this->datesp)."'";
|
||||
$sql.= ", '".$this->db->idate($this->dateep)."'";
|
||||
$sql.= ", '".$user->id."'";
|
||||
$sql.= ", NULL";
|
||||
$sql.= ", ".$conf->entity;
|
||||
$sql.= ")";
|
||||
// Insertion dans table des paiement salaires
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (fk_user";
|
||||
$sql.= ", datep";
|
||||
$sql.= ", datev";
|
||||
$sql.= ", amount";
|
||||
$sql.= ", fk_typepayment";
|
||||
$sql.= ", num_payment";
|
||||
$sql.=", note";
|
||||
$sql.=", label";
|
||||
$sql.= ", datesp";
|
||||
$sql.= ", dateep";
|
||||
$sql.= ", fk_user_creat";
|
||||
$sql.= ", fk_bank";
|
||||
$sql.= ", entity";
|
||||
$sql.= ") ";
|
||||
$sql.= " VALUES (";
|
||||
$sql.= "'".$this->fk_user."'";
|
||||
$sql.= ", '".$this->db->idate($this->datep)."'";
|
||||
$sql.= ", '".$this->db->idate($this->datev)."'";
|
||||
$sql.= ", ".$this->amount;
|
||||
$sql.= ", ".$this->type_payment;
|
||||
$sql.= ", ".$this->num_payment;
|
||||
$sql.= ", '".$this->db->escape($this->note)."'";
|
||||
$sql.= ", '".$this->db->escape($this->label)."'";
|
||||
$sql.= ", '".$this->db->idate($this->datesp)."'";
|
||||
$sql.= ", '".$this->db->idate($this->dateep)."'";
|
||||
$sql.= ", '".$user->id."'";
|
||||
$sql.= ", NULL";
|
||||
$sql.= ", ".$conf->entity;
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::addPayment sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary"); // TODO devrait s'appeler payment_salary
|
||||
dol_syslog(get_class($this)."::create sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary"); // TODO devrait s'appeler payment_salary
|
||||
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_ADDPAYMENT',$this,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
// Appel des triggers
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('PAYMENT_SALARY_CREATE',$this,$user,$langs,$conf);
|
||||
if ($result < 0) {
|
||||
$error++; $this->errors=$interface->errors;
|
||||
}
|
||||
// Fin appel triggers
|
||||
|
||||
if ($this->id > 0)
|
||||
{
|
||||
$ok=1;
|
||||
if (! empty($conf->banque->enabled) && ! empty($this->amount))
|
||||
{
|
||||
// Insertion dans llx_bank
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
if ($this->id > 0)
|
||||
{
|
||||
$ok=1;
|
||||
if (! empty($conf->banque->enabled) && ! empty($this->amount))
|
||||
{
|
||||
// Insertion dans llx_bank
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
|
||||
$acc = new Account($this->db);
|
||||
$result=$acc->fetch($this->accountid);
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
$acc = new Account($this->db);
|
||||
$result=$acc->fetch($this->accountid);
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
|
||||
// Insert payment into llx_bank
|
||||
// Add link 'payment_salary' in bank_url between payment and bank transaction
|
||||
$bank_line_id = $acc->addline(
|
||||
$this->datep,
|
||||
$this->paymenttype,
|
||||
$this->label,
|
||||
-abs($this->amount),
|
||||
'',
|
||||
'',
|
||||
$user
|
||||
);
|
||||
// Insert payment into llx_bank
|
||||
// Add link 'payment_salary' in bank_url between payment and bank transaction
|
||||
$bank_line_id = $acc->addline(
|
||||
$this->datep,
|
||||
$this->type_payment,
|
||||
$this->label,
|
||||
-abs($this->amount),
|
||||
$this->num_payment,
|
||||
'',
|
||||
$user
|
||||
);
|
||||
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$this->update_fk_bank($bank_line_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$ok=0;
|
||||
}
|
||||
// Mise a jour fk_bank dans llx_paiement.
|
||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||
if ($bank_line_id > 0)
|
||||
{
|
||||
$this->update_fk_bank($bank_line_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$ok=0;
|
||||
}
|
||||
|
||||
// Add link 'payment_salary' in bank_url between payment and bank transaction
|
||||
$url=DOL_URL_ROOT.'/compta/salaries/fiche.php?id=';
|
||||
// Add link 'payment_salary' in bank_url between payment and bank transaction
|
||||
$url=DOL_URL_ROOT.'/compta/salaries/fiche.php?id=';
|
||||
|
||||
$result=$acc->add_url_line($bank_line_id, $this->id, $url, "(SalaryPayment)", "payment_salary");
|
||||
if ($result <= 0)
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$ok=0;
|
||||
}
|
||||
$result=$acc->add_url_line($bank_line_id, $this->id, $url, "(SalaryPayment)", "payment_salary");
|
||||
if ($result <= 0)
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$ok=0;
|
||||
}
|
||||
|
||||
// Add link 'user' in bank_url between operation and bank transaction
|
||||
$linkaddedforthirdparty=array();
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
$sal = new PaymentSalary($this->db);
|
||||
// Add link 'user' in bank_url between operation and bank transaction
|
||||
$linkaddedforthirdparty=array();
|
||||
foreach ($this->amounts as $key => $value)
|
||||
{
|
||||
$sal = new PaymentSalary($this->db);
|
||||
|
||||
$sal->fetch($key);
|
||||
$sal->fetch_user($this->fk_user);
|
||||
$sal->fetch($key);
|
||||
$sal->fetch_user($this->fk_user);
|
||||
|
||||
if (! in_array($sal->user->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
|
||||
{
|
||||
$result=$acc->add_url_line(
|
||||
$bank_line_id,
|
||||
$sal->user->id,
|
||||
DOL_URL_ROOT.'/user/fiche.php?id=',
|
||||
$sal->user->lastname,
|
||||
'user'
|
||||
);
|
||||
if (! in_array($sal->user->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
|
||||
{
|
||||
$result=$acc->add_url_line(
|
||||
$bank_line_id,
|
||||
$sal->user->id,
|
||||
DOL_URL_ROOT.'/user/fiche.php?id=',
|
||||
$sal->user->lastname,
|
||||
'user'
|
||||
);
|
||||
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
$linkaddedforthirdparty[$sal->user->id]=$sal->user->id; // Mark as done for this thirdparty
|
||||
}
|
||||
if ($result <= 0) dol_print_error($this->db);
|
||||
$linkaddedforthirdparty[$sal->user->id]=$sal->user->id; // Mark as done for this thirdparty
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mise a jour du lien entre le paiement salaire et la ligne générée dans llx_bank
|
||||
*
|
||||
* @param int $id_bank Id compte bancaire
|
||||
/**
|
||||
* Mise a jour du lien entre le paiement salaire et la ligne générée dans llx_bank
|
||||
*
|
||||
* @param int $id_bank Id compte bancaire
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
*/
|
||||
function update_fk_bank($id_bank)
|
||||
{
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_salary SET fk_bank = '.$id_bank;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
|
||||
* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
@ -17,7 +18,7 @@
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/salaries/fiche.php
|
||||
* \ingroup tax
|
||||
* \ingroup salaries
|
||||
* \brief Page of salaries payments
|
||||
*/
|
||||
|
||||
@ -59,50 +60,73 @@ if ($_POST["cancel"] == $langs->trans("Cancel"))
|
||||
|
||||
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
|
||||
{
|
||||
$db->begin();
|
||||
$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"]);
|
||||
$datesp=dol_mktime(12,0,0, $_POST["datespmonth"], $_POST["datespday"], $_POST["datespyear"]);
|
||||
$dateep=dol_mktime(12,0,0, $_POST["dateepmonth"], $_POST["dateepday"], $_POST["dateepyear"]);
|
||||
$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=GETPOST("accountid");
|
||||
$sal->fk_user=GETPOST("fk_user");
|
||||
$sal->datev=$datev;
|
||||
$sal->datep=$datep;
|
||||
$sal->amount=price2num(GETPOST("amount"));
|
||||
$sal->label=GETPOST("label");
|
||||
$sal->datesp=$datesp;
|
||||
$sal->dateep=$dateep;
|
||||
$sal->type_payment=GETPOST("paymenttype");
|
||||
$sal->num_payment=GETPOST('num_payment');
|
||||
|
||||
$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;
|
||||
if (empty($sal->fk_user) || $sal->fk_user < 0)
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Employee")),'errors');
|
||||
$error++;
|
||||
}
|
||||
if (empty($sal->type_payment) || $sal->type_payment < 0)
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentMode")),'errors');
|
||||
$error++;
|
||||
}
|
||||
if (empty($sal->amount))
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")),'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
$ret=$sal->addPayment($user);
|
||||
if ($ret > 0)
|
||||
{
|
||||
$db->commit();
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
setEventMessage($sal->error, 'errors');
|
||||
$action="create";
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$ret=$sal->create($user);
|
||||
if ($ret > 0)
|
||||
{
|
||||
$db->commit();
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
setEventMessage($sal->error, 'errors');
|
||||
$action="create";
|
||||
}
|
||||
}
|
||||
|
||||
$action='create';
|
||||
}
|
||||
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$result=$sal->fetch($id);
|
||||
$result=$sal->fetch($id);
|
||||
|
||||
if ($sal->rappro == 0)
|
||||
{
|
||||
$db->begin();
|
||||
$db->begin();
|
||||
|
||||
$ret=$sal->delete($user);
|
||||
if ($ret > 0)
|
||||
{
|
||||
$ret=$sal->delete($user);
|
||||
if ($ret > 0)
|
||||
{
|
||||
if ($sal->fk_bank)
|
||||
{
|
||||
$accountline=new AccountLine($db);
|
||||
@ -122,23 +146,23 @@ if ($action == 'delete')
|
||||
$db->rollback();
|
||||
setEventMessage($sal->error,'errors');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$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');
|
||||
setEventMessage('Error try do delete a line linked to a conciliated bank transaction','errors');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
|
||||
@ -146,7 +170,7 @@ $form = new Form($db);
|
||||
|
||||
if ($id)
|
||||
{
|
||||
$salpayment = new PaymentSalary($db);
|
||||
$salpayment = new PaymentSalary($db);
|
||||
$result = $salpayment->fetch($id);
|
||||
if ($result <= 0)
|
||||
{
|
||||
@ -158,86 +182,93 @@ if ($id)
|
||||
// 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--;
|
||||
}
|
||||
$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);
|
||||
$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);
|
||||
}
|
||||
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 "<form name='add' action=\"fiche.php\" method=\"post\">\n";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print "<form name='add' action=\"fiche.php\" method=\"post\">\n";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
|
||||
print_fiche_titre($langs->trans("NewSalaryPayment"));
|
||||
print_fiche_titre($langs->trans("NewSalaryPayment"));
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
|
||||
print $form->select_date($datep,"datep",'','','','add');
|
||||
print '</td></tr>';
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
|
||||
print $form->select_date($datep,"datep",'','','','add');
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("DateValue").'</td><td>';
|
||||
print $form->select_date($datev,"datev",'','','','add');
|
||||
print '</td></tr>';
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("DateValue").'</td><td>';
|
||||
print $form->select_date($datev,"datev",'','','','add');
|
||||
print '</td></tr>';
|
||||
|
||||
// Employee
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("Employee").'</td><td>';
|
||||
print $form->select_dolusers(GETPOST('fk_user','int'),'fk_user',1);
|
||||
print '</td></tr>';
|
||||
// Employee
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("Employee").'</td><td>';
|
||||
print $form->select_dolusers(GETPOST('fk_user','int'),'fk_user',1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" value="'.($_POST["label"]?$_POST["label"]:$langs->trans("SalaryPayment")).'"></td></tr>';
|
||||
// Label
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" value="'.($_POST["label"]?$_POST["label"]:$langs->trans("SalaryPayment")).'"></td></tr>';
|
||||
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("DateStartPeriod").'</td><td>';
|
||||
print $form->select_date($datesp,"datesp",'','','','add');
|
||||
print '</td></tr>';
|
||||
print "<tr>";
|
||||
print '<td class="fieldrequired">'.$langs->trans("DateStartPeriod").'</td><td>';
|
||||
print $form->select_date($datesp,"datesp",'','','','add');
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("DateEndPeriod").'</td><td>';
|
||||
print $form->select_date($dateep,"dateep",'','','','add');
|
||||
print '</td></tr>';
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("DateEndPeriod").'</td><td>';
|
||||
print $form->select_date($dateep,"dateep",'','','','add');
|
||||
print '</td></tr>';
|
||||
|
||||
// Amount
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.$_POST["amount"].'"></td></tr>';
|
||||
// Amount
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
|
||||
|
||||
// Bank
|
||||
if (! empty($conf->banque->enabled))
|
||||
{
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
|
||||
$form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
|
||||
print '</td></tr>';
|
||||
// Bank
|
||||
if (! empty($conf->banque->enabled))
|
||||
{
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
|
||||
$form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
|
||||
$form->select_types_paiements($_POST["paiementtype"], "paiementtype");
|
||||
print "</td>\n";
|
||||
print "</tr>";
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
// TYpe payment
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
|
||||
$form->select_types_paiements(GETPOST("paymenttype"), "paymenttype");
|
||||
print "</td>\n";
|
||||
print "</tr>";
|
||||
|
||||
// Number
|
||||
print '<tr><td>'.$langs->trans('Numero');
|
||||
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
|
||||
print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\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 '</table>';
|
||||
print '</table>';
|
||||
|
||||
print "<br>";
|
||||
print "<br>";
|
||||
|
||||
print '<center><input type="submit" class="button" value="'.$langs->trans("Save").'"> ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
|
||||
print '<center><input type="submit" class="button" value="'.$langs->trans("Save").'"> ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
|
||||
|
||||
print '</form>';
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
|
||||
@ -265,17 +296,17 @@ if ($id)
|
||||
print $salpayment->ref;
|
||||
print '</td></tr>';
|
||||
|
||||
// Person
|
||||
print '<tr><td>'.$langs->trans("Person").'</td><td>';
|
||||
$usersal=new User($db);
|
||||
$usersal->fetch($salpayment->fk_user);
|
||||
print $usersal->getNomUrl(1);
|
||||
print '</td></tr>';
|
||||
// Person
|
||||
print '<tr><td>'.$langs->trans("Person").'</td><td>';
|
||||
$usersal=new User($db);
|
||||
$usersal->fetch($salpayment->fk_user);
|
||||
print $usersal->getNomUrl(1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$salpayment->label.'</td></tr>';
|
||||
|
||||
print "<tr>";
|
||||
print "<tr>";
|
||||
print '<td>'.$langs->trans("DateStartPeriod").'</td><td colspan="3">';
|
||||
print dol_print_date($salpayment->datesp,'day');
|
||||
print '</td></tr>';
|
||||
@ -293,34 +324,34 @@ if ($id)
|
||||
print dol_print_date($salpayment->datev,'day');
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="3">'.price($salpayment->amount).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="3">'.price($salpayment->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
|
||||
if (! empty($conf->banque->enabled))
|
||||
{
|
||||
if ($salpayment->fk_account > 0)
|
||||
{
|
||||
$bankline=new AccountLine($db);
|
||||
$bankline->fetch($salpayment->fk_bank);
|
||||
$bankline=new AccountLine($db);
|
||||
$bankline->fetch($salpayment->fk_bank);
|
||||
|
||||
print '<tr>';
|
||||
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
|
||||
print '<td colspan="3">';
|
||||
print $bankline->getNomUrl(1,0,'showall');
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
print '<tr>';
|
||||
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
|
||||
print '<td colspan="3">';
|
||||
print $bankline->getNomUrl(1,0,'showall');
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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 '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
/*
|
||||
* Boutons d'actions
|
||||
* Boutons d'actions
|
||||
*/
|
||||
print "<div class=\"tabsAction\">\n";
|
||||
if ($salpayment->rappro == 0)
|
||||
@ -342,7 +373,8 @@ if ($id)
|
||||
}
|
||||
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter();
|
||||
?>
|
||||
|
||||
$db->close();
|
||||
?>
|
||||
@ -17,8 +17,8 @@
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/salaries/index.php
|
||||
* \ingroup tax
|
||||
* \brief List of salaries payments
|
||||
* \ingroup salaries
|
||||
* \brief List of salaries payments
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
@ -26,6 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
|
||||
|
||||
$langs->load("compta");
|
||||
$langs->load("salaries");
|
||||
$langs->load("bills");
|
||||
|
||||
// Security check
|
||||
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
|
||||
@ -46,8 +47,11 @@ $userstatic = new User($db);
|
||||
|
||||
print_fiche_titre($langs->trans("SalariesPayments"));
|
||||
|
||||
$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, s.rowid, s.fk_user, s.amount, s.label, s.datev as dm";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s, ".MAIN_DB_PREFIX."user as u";
|
||||
$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, s.rowid, s.fk_user, s.amount, s.label, s.datev as dm, s.num_payment,";
|
||||
$sql.= " pst.code as payment_code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."user as u";
|
||||
$sql.= " WHERE u.rowid = s.fk_user";
|
||||
$sql.= " AND s.entity = ".$conf->entity;
|
||||
$sql.= " ORDER BY dm DESC";
|
||||
@ -65,6 +69,7 @@ if ($result)
|
||||
print "<td>".$langs->trans("Person")."</td>";
|
||||
print "<td>".$langs->trans("Label")."</td>";
|
||||
print '<td class="nowrap" align="left">'.$langs->trans("DatePayment").'</td>';
|
||||
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"c.libelle","",$paramlist,"",$sortfield,$sortorder);
|
||||
print "<td align=\"right\">".$langs->trans("PayedByThisPayment")."</td>";
|
||||
print "</tr>\n";
|
||||
$var=1;
|
||||
@ -78,20 +83,23 @@ if ($result)
|
||||
$userstatic->lastname=$obj->lastname;
|
||||
$userstatic->firstname=$obj->firstname;
|
||||
$salstatic->id=$obj->rowid;
|
||||
$salstatic->ref=$obj->rowid;
|
||||
$salstatic->ref=$obj->rowid;
|
||||
print "<td>".$salstatic->getNomUrl(1)."</td>\n";
|
||||
print "<td>".$userstatic->getNomUrl(1)."</td>\n";
|
||||
print "<td>".$userstatic->getNomUrl(1)."</td>\n";
|
||||
print "<td>".dol_trunc($obj->label,40)."</td>\n";
|
||||
print '<td align="left">'.dol_print_date($db->jdate($obj->dm),'day')."</td>\n";
|
||||
$total = $total + $obj->amount;
|
||||
|
||||
print "<td align=\"right\">".price($obj->amount)."</td>";
|
||||
// Type
|
||||
print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
|
||||
// Amount
|
||||
print "<td align=\"right\">".price($obj->amount,0,$outputlangs,1,-1,-1,$conf->currency)."</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
$total = $total + $obj->amount;
|
||||
|
||||
$i++;
|
||||
}
|
||||
print '<tr class="liste_total"><td colspan="4">'.$langs->trans("Total").'</td>';
|
||||
print "<td align=\"right\"><b>".price($total)."</b></td></tr>";
|
||||
print '<tr class="liste_total"><td colspan="5" class="liste_total">'.$langs->trans("Total").'</td>';
|
||||
print '<td class="liste_total" align="right">'.price($total,0,$outputlangs,1,-1,-1,$conf->currency)."</td></tr>";
|
||||
|
||||
print "</table>";
|
||||
$db->free($result);
|
||||
|
||||
@ -226,7 +226,7 @@ if ($action == 'create')
|
||||
print $form->select_date(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1);
|
||||
print '</td>';
|
||||
|
||||
print '<td align="right"><input type="text" size="6" name="amount" class="flat"></td>';
|
||||
print '<td align="right"><input type="text" size="6" name="amount" class="flat" value="'.GETPOST('amount').'"></td>';
|
||||
|
||||
print '<td align="center">';
|
||||
print $form->select_date(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1);
|
||||
|
||||
@ -1044,6 +1044,7 @@ CREATE TABLE llx_expeditiondet_batch (
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
--Salary payment in tax module
|
||||
--DROP TABLE llx_payment_salary
|
||||
CREATE TABLE llx_payment_salary (
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
@ -1051,6 +1052,8 @@ CREATE TABLE llx_payment_salary (
|
||||
datep date,
|
||||
datev date,
|
||||
amount real NOT NULL DEFAULT 0,
|
||||
fk_typepayment integer NOT NULL,
|
||||
num_payment varchar(50),
|
||||
label varchar(255),
|
||||
datesp date, -- date de début de la période
|
||||
dateep date, -- date de fin de la période
|
||||
|
||||
@ -24,6 +24,8 @@ create table llx_payment_salary
|
||||
datep date, -- date de paiement
|
||||
datev date, -- date de valeur
|
||||
amount real NOT NULL DEFAULT 0,
|
||||
fk_typepayment integer NOT NULL,
|
||||
num_payment varchar(50),
|
||||
label varchar(255),
|
||||
datesp date, -- date de début de la période
|
||||
dateep date, -- date de fin de la période
|
||||
|
||||
Loading…
Reference in New Issue
Block a user