Merge pull request #3084 from aspangaro/develop-patch37
Fix: ER button set_paid & merge with old option setPaid
This commit is contained in:
commit
759aec3925
@ -668,123 +668,6 @@ if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == "confirm_paid" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->to_paid)
|
||||
{
|
||||
$object = new ExpenseReport($db);
|
||||
$object->fetch($id);
|
||||
|
||||
$result = $object->setPaid($user);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
// Define output language
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||
{
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$model=$object->modelpdf;
|
||||
$ret = $object->fetch($id); // Reload to get new records
|
||||
|
||||
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
|
||||
{
|
||||
// Send mail
|
||||
|
||||
// TO
|
||||
$destinataire = new User($db);
|
||||
$destinataire->fetch($object->fk_user_author);
|
||||
$emailTo = $destinataire->email;
|
||||
|
||||
// FROM
|
||||
$expediteur = new User($db);
|
||||
$expediteur->fetch($object->fk_user_paid);
|
||||
$emailFrom = $expediteur->email;
|
||||
|
||||
// SUBJECT
|
||||
$subject = "' ERP - Note de frais payée";
|
||||
|
||||
// CONTENT
|
||||
$message = "Bonjour {$destinataire->firstname},\n\n";
|
||||
$message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n";
|
||||
$message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n";
|
||||
$message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
|
||||
$message.= "Bien cordialement,\n' SI";
|
||||
|
||||
// Génération du pdf avant attachement
|
||||
$object->setDocModel($user,"");
|
||||
$resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
|
||||
|
||||
// PREPARE SEND
|
||||
$mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message);
|
||||
|
||||
if(!$mailfile->error):
|
||||
|
||||
// SEND
|
||||
$result=$mailfile->sendfile();
|
||||
if ($result):
|
||||
// Insert écriture dans le compte courant
|
||||
$idTrip = $id;
|
||||
$idAccount = 1;
|
||||
|
||||
$object = new ExpenseReport($db);
|
||||
$object->fetch($idTrip);
|
||||
|
||||
$datePaiement = explode("-",$object->date_paiement);
|
||||
|
||||
$dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]);
|
||||
$operation = $object->code_paiement;
|
||||
$label = "Règlement ".$object->ref;
|
||||
$amount = - price2num($object->total_ttc);
|
||||
$num_chq = '';
|
||||
$cat1 = '';
|
||||
|
||||
$user = new User($db);
|
||||
$user->fetch($object->fk_user_paid);
|
||||
|
||||
$acct=new Account($db,$idAccount);
|
||||
$insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
|
||||
|
||||
if ($insertid > 0):
|
||||
$sql = " UPDATE ".MAIN_DB_PREFIX."expensereport as d";
|
||||
$sql.= " SET integration_compta = 1, fk_bank_account = $idAccount";
|
||||
$sql.= " WHERE rowid = $idTrip";
|
||||
$resql=$db->query($sql);
|
||||
if($result):
|
||||
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
|
||||
exit;
|
||||
else:
|
||||
dol_print_error($db);
|
||||
endif;
|
||||
else:
|
||||
dol_print_error($db,$acct->error);
|
||||
endif;
|
||||
endif;
|
||||
|
||||
else:
|
||||
|
||||
$mesg="Impossible d'envoyer l'email.";
|
||||
|
||||
endif;
|
||||
// END - Send mail
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->creer)
|
||||
{
|
||||
$object = new ExpenseReport($db);
|
||||
@ -829,16 +712,96 @@ if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 &&
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'set_paid')
|
||||
if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid)
|
||||
{
|
||||
if ($object->set_paid($id) >= 0)
|
||||
$object = new ExpenseReport($db);
|
||||
$object->fetch($id);
|
||||
|
||||
$result = $object->set_paid($id, $user);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
|
||||
exit;
|
||||
// Define output language
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||
{
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$model=$object->modelpdf;
|
||||
$ret = $object->fetch($id); // Reload to get new records
|
||||
|
||||
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
|
||||
{
|
||||
// Send mail
|
||||
|
||||
// TO
|
||||
$destinataire = new User($db);
|
||||
$destinataire->fetch($object->fk_user_author);
|
||||
$emailTo = $destinataire->email;
|
||||
|
||||
// FROM
|
||||
$expediteur = new User($db);
|
||||
$expediteur->fetch($user->id);
|
||||
$emailFrom = $expediteur->email;
|
||||
|
||||
// SUBJECT
|
||||
$subject = "'ERP - Note de frais payée";
|
||||
|
||||
// CONTENT
|
||||
$message = "Bonjour {$destinataire->firstname},\n\n";
|
||||
$message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n";
|
||||
$message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n";
|
||||
$message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
|
||||
$message.= "Bien cordialement,\n' SI";
|
||||
|
||||
// Generate pdf before attachment
|
||||
$object->setDocModel($user,"");
|
||||
$resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
|
||||
|
||||
// PREPARE SEND
|
||||
$mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message);
|
||||
|
||||
if(!$mailfile->error):
|
||||
|
||||
// SEND
|
||||
$result=$mailfile->sendfile();
|
||||
if ($result):
|
||||
|
||||
// Retour
|
||||
if($result):
|
||||
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
|
||||
exit;
|
||||
else:
|
||||
dol_print_error($db);
|
||||
endif;
|
||||
|
||||
else:
|
||||
dol_print_error($db,$acct->error);
|
||||
endif;
|
||||
|
||||
else:
|
||||
|
||||
$mesg="Impossible d'envoyer l'email.";
|
||||
|
||||
endif;
|
||||
// END - Send mail
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
else {
|
||||
setEventMessage($object->error, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == "addline")
|
||||
@ -1311,7 +1274,7 @@ else
|
||||
print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
|
||||
print '<td>';
|
||||
$userfee=new User($db);
|
||||
$userfee->fetch($object->fk_user_paid);
|
||||
$userfee->fetch($user->id);
|
||||
print $userfee->getNomUrl(1);
|
||||
print '</td></tr>';
|
||||
|
||||
@ -2005,9 +1968,9 @@ if ($action != 'create' && $action != 'edit')
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/payment/payment.php?id=' . $object->id . '&action=create">' . $langs->trans('DoPayment') . '</a></div>';
|
||||
}
|
||||
|
||||
if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
|
||||
if (round($remaintopay) == 0 && $object->paid == 0)
|
||||
{
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
|
||||
}
|
||||
|
||||
// Cancel
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
|
||||
* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2015 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
|
||||
@ -88,8 +89,6 @@ class ExpenseReport extends CommonObject
|
||||
var $fk_user_approve;
|
||||
|
||||
// Paiement
|
||||
var $date_paiement;
|
||||
var $fk_user_paid;
|
||||
var $user_paid_infos;
|
||||
|
||||
/*
|
||||
@ -241,7 +240,6 @@ class ExpenseReport extends CommonObject
|
||||
$sql.= " , fk_user_author = ".($user->id > 0 ? "'".$user->id."'":"null");
|
||||
$sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
|
||||
$sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null");
|
||||
$sql.= " , fk_user_paid = ".($this->fk_user_paid > 0 ? $this->fk_user_paid:"null");
|
||||
$sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0');
|
||||
$sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null");
|
||||
$sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''");
|
||||
@ -277,9 +275,9 @@ class ExpenseReport extends CommonObject
|
||||
$sql.= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; // ACTIONS
|
||||
$sql.= " d.date_refuse, d.date_cancel,"; // ACTIONS
|
||||
$sql.= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int)
|
||||
$sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valid, d.date_approve, d.date_paiement,"; // DATES (datetime)
|
||||
$sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valid, d.date_approve,"; // DATES (datetime)
|
||||
$sql.= " d.fk_user_author, d.fk_user_validator, d.fk_statut as status, d.fk_c_paiement,";
|
||||
$sql.= " d.fk_user_valid, d.fk_user_approve, d.fk_user_paid,";
|
||||
$sql.= " d.fk_user_valid, d.fk_user_approve,";
|
||||
$sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id";
|
||||
if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'";
|
||||
@ -305,7 +303,6 @@ class ExpenseReport extends CommonObject
|
||||
|
||||
$this->date_debut = $this->db->jdate($obj->date_debut);
|
||||
$this->date_fin = $this->db->jdate($obj->date_fin);
|
||||
$this->date_paiement = $this->db->jdate($obj->date_paiement);
|
||||
$this->date_valid = $this->db->jdate($obj->date_valid);
|
||||
$this->date_approve = $this->db->jdate($obj->date_approve);
|
||||
$this->date_create = $this->db->jdate($obj->date_create);
|
||||
@ -318,7 +315,6 @@ class ExpenseReport extends CommonObject
|
||||
$this->fk_user_refuse = $obj->fk_user_refuse;
|
||||
$this->fk_user_cancel = $obj->fk_user_cancel;
|
||||
$this->fk_user_approve = $obj->fk_user_approve;
|
||||
$this->fk_user_paid = $obj->fk_user_paid;
|
||||
|
||||
$user_author = new User($this->db);
|
||||
if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author);
|
||||
@ -341,13 +337,6 @@ class ExpenseReport extends CommonObject
|
||||
$this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
|
||||
}
|
||||
|
||||
if ($this->fk_statut==6)
|
||||
{
|
||||
$user_paid = new User($this->db);
|
||||
if ($this->fk_user_paid > 0) $user_paid->fetch($this->fk_user_paid);
|
||||
$this->user_paid_infos = dolGetFirstLastname($user_paid->firstname, $user_paid->lastname);
|
||||
}
|
||||
|
||||
$this->libelle_statut = $obj->libelle_statut;
|
||||
$this->libelle_paiement = $obj->libelle_paiement;
|
||||
$this->code_statut = $obj->code_statut;
|
||||
@ -376,13 +365,16 @@ class ExpenseReport extends CommonObject
|
||||
* Classify the expense report as paid
|
||||
*
|
||||
* @param int $id id of expense report
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @param user $fuser User
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function set_paid($id)
|
||||
function set_paid($id, $fuser)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."expensereport SET fk_statut = 6";
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."expensereport";
|
||||
$sql.= " SET fk_statut = 6;
|
||||
$sql.= " WHERE rowid = $id AND fk_statut = 5";
|
||||
|
||||
dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1017,41 +1009,6 @@ class ExpenseReport extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setPaid
|
||||
*
|
||||
* @param User $fuser User
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function setPaid($fuser)
|
||||
{
|
||||
$now= dol_now();
|
||||
|
||||
$this->date_paiement = $this->db->idate($now);
|
||||
if ($this->fk_statut != 6)
|
||||
{
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
|
||||
$sql.= " SET fk_statut = 6, fk_user_paid = ".$fuser->id.",";
|
||||
$sql.= " date_paiement='".$this->db->idate($this->date_paiement)."'";
|
||||
$sql.= ' WHERE rowid = '.$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::setPaid sql=".$sql, LOG_DEBUG);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog(get_class($this)."::set_paid expensereport already with paid status", LOG_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set_unpaid
|
||||
*
|
||||
|
||||
@ -126,9 +126,8 @@ if (isset($_POST['action']))
|
||||
$outputlangs = $langs;
|
||||
$outputlangs->charset_output = 'UTF-8';
|
||||
|
||||
$sql = "SELECT d.rowid, d.ref, d.date_paiement, d.total_ht, d.total_tva, d.total_ttc";
|
||||
$sql = "SELECT d.rowid, d.ref, d.total_ht, d.total_tva, d.total_ttc";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
|
||||
$sql.= " WHERE date_paiement LIKE '".$select_date."%'";
|
||||
$sql.= " ORDER BY d.rowid";
|
||||
|
||||
$result = $db->query($sql);
|
||||
@ -146,7 +145,7 @@ if (isset($_POST['action']))
|
||||
$objet->total_tva = number_format($objet->total_tva,2);
|
||||
$objet->total_ttc = number_format($objet->total_ttc,2);
|
||||
$objet->ref = trim($objet->ref);
|
||||
$ligne.= "{$objet->rowid}, {$objet->ref}, ----, {$objet->date_paiement}, {$objet->total_ht}, {$objet->total_tva}, {$objet->total_ttc}\n";
|
||||
$ligne.= "{$objet->rowid}, {$objet->ref}, ----, {$objet->total_ht}, {$objet->total_tva}, {$objet->total_ttc}\n";
|
||||
|
||||
$ligne.= "--->, Ligne, Type, Description, ----, ----, ----\n";
|
||||
|
||||
|
||||
@ -33,8 +33,6 @@ if ($_GET["action"] == 'confirm_ndf_to_account' && $_GET["confirm"] == "yes"):
|
||||
$expensereport = new ExpenseReport($db);
|
||||
$expensereport->fetch($idTrip,$user);
|
||||
|
||||
$datePaiement = explode("-",$expensereport->date_paiement);
|
||||
|
||||
$dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]);
|
||||
$operation = $expensereport->code_paiement;
|
||||
$label = "Règlement ".$expensereport->ref;
|
||||
@ -43,7 +41,7 @@ if ($_GET["action"] == 'confirm_ndf_to_account' && $_GET["confirm"] == "yes"):
|
||||
$cat1 = '';
|
||||
|
||||
$user = new User($db);
|
||||
$user->fetch($expensereport->fk_user_paid);
|
||||
$user->fetch($user->id);
|
||||
|
||||
$acct=new Account($db,$idAccount);
|
||||
$insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
|
||||
|
||||
@ -231,7 +231,6 @@ CREATE TABLE llx_expensereport (
|
||||
date_approve datetime,
|
||||
date_refuse datetime,
|
||||
date_cancel datetime,
|
||||
date_paiement datetime,
|
||||
tms timestamp,
|
||||
fk_user_author integer NOT NULL,
|
||||
fk_user_modif integer DEFAULT NULL,
|
||||
@ -240,7 +239,6 @@ CREATE TABLE llx_expensereport (
|
||||
fk_user_approve integer DEFAULT NULL,
|
||||
fk_user_refuse integer DEFAULT NULL,
|
||||
fk_user_cancel integer DEFAULT NULL,
|
||||
fk_user_paid integer DEFAULT NULL,
|
||||
fk_statut integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé
|
||||
fk_c_paiement integer DEFAULT NULL,
|
||||
paid smallint default 0 NOT NULL,
|
||||
|
||||
@ -34,7 +34,6 @@ CREATE TABLE llx_expensereport (
|
||||
date_approve datetime,
|
||||
date_refuse datetime,
|
||||
date_cancel datetime,
|
||||
date_paiement datetime,
|
||||
tms timestamp,
|
||||
fk_user_author integer NOT NULL,
|
||||
fk_user_modif integer DEFAULT NULL,
|
||||
@ -43,7 +42,6 @@ CREATE TABLE llx_expensereport (
|
||||
fk_user_approve integer DEFAULT NULL,
|
||||
fk_user_refuse integer DEFAULT NULL,
|
||||
fk_user_cancel integer DEFAULT NULL,
|
||||
fk_user_paid integer DEFAULT NULL,
|
||||
fk_statut integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé
|
||||
fk_c_paiement integer DEFAULT NULL,
|
||||
paid smallint default 0 NOT NULL,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user