Ergo: Add option "MAIN_DISABLEDRAFTSTATUS" to reduce nb of clicks

This commit is contained in:
Laurent Destailleur 2011-02-09 14:45:42 +00:00
parent a9a195d291
commit 60aa363a91
4 changed files with 171 additions and 88 deletions

View File

@ -113,10 +113,10 @@ class RemiseCheque extends CommonObject
} }
/** /**
* \brief Create a receipt to send cheques * Create a receipt to send cheques
* \param user Utilisateur qui effectue l'operation * @param user Utilisateur qui effectue l'operation
* \param account_id Compte bancaire concerne * @param account_id Compte bancaire concerne
* \return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function create($user, $account_id) function create($user, $account_id)
{ {
@ -125,6 +125,8 @@ class RemiseCheque extends CommonObject
$this->errno = 0; $this->errno = 0;
$this->id = 0; $this->id = 0;
$now=dol_now();
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
@ -132,17 +134,19 @@ class RemiseCheque extends CommonObject
$sql.= ", date_bordereau"; $sql.= ", date_bordereau";
$sql.= ", fk_user_author"; $sql.= ", fk_user_author";
$sql.= ", fk_bank_account"; $sql.= ", fk_bank_account";
$sql.= ", statut";
$sql.= ", amount"; $sql.= ", amount";
$sql.= ", number"; $sql.= ", number";
$sql.= ", entity"; $sql.= ", entity";
$sql.= ", nbcheque"; $sql.= ", nbcheque";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= $this->db->idate(mktime()); $sql.= $this->db->idate($now);
$sql.= ", ".$this->db->idate(mktime()); $sql.= ", ".$this->db->idate($now);
$sql.= ", ".$user->id; $sql.= ", ".$user->id;
$sql.= ", ".$account_id; $sql.= ", ".$account_id;
$sql.= ", 0"; $sql.= ", 0";
$sql.= ", 0"; $sql.= ", 0";
$sql.= ", 0";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", 0"; $sql.= ", 0";
$sql.= ")"; $sql.= ")";
@ -155,7 +159,7 @@ class RemiseCheque extends CommonObject
if ($this->id == 0) if ($this->id == 0)
{ {
$this->errno = -1024; $this->errno = -1024;
dol_syslog("Remisecheque::Create Erreur Lecture ID ($this->errno)", LOG_ERR); dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
} }
if ($this->id > 0 && $this->errno == 0) if ($this->id > 0 && $this->errno == 0)
@ -169,7 +173,7 @@ class RemiseCheque extends CommonObject
if (! $resql) if (! $resql)
{ {
$this->errno = -1025; $this->errno = -1025;
dol_syslog("RemiseCheque::Create ERREUR UPDATE ($this->errno)", LOG_ERR); dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
} }
} }
@ -197,7 +201,7 @@ class RemiseCheque extends CommonObject
else else
{ {
$this->errno = -1026; $this->errno = -1026;
dol_syslog("RemiseCheque::Create Error ($this->errno)", LOG_ERR); dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
} }
} }
@ -214,7 +218,7 @@ class RemiseCheque extends CommonObject
if (!$resql) if (!$resql)
{ {
$this->errno = -18; $this->errno = -18;
dol_syslog("RemiseCheque::Create Error update bank ($this->errno)", LOG_ERR); dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
} }
} }
} }
@ -224,31 +228,34 @@ class RemiseCheque extends CommonObject
if ($this->updateAmount() <> 0) if ($this->updateAmount() <> 0)
{ {
$this->errno = -1027; $this->errno = -1027;
dol_syslog("RemiseCheque::Create ERREUR ($this->errno)"); dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
} }
} }
} }
else else
{ {
$result = -1; $this->errno = -1;
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
$this->errno=$this->db->lasterrno(); $this->errno=$this->db->lasterrno();
dol_syslog("RemiseCheque::Create Erreur $result INSERT Mysql"); dol_syslog("RemiseCheque::Create Error ".$this->error, LOG_ERR);
} }
if (! $this->errno && ! empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
{
$res=$this->validate($user);
//if ($res < 0) $error++;
}
if ($this->errno == 0) if (! $this->errno)
{ {
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog("RemiseCheque::Create ROLLBACK ($this->errno)"); return $this->errno;
return $this->errno; }
}
} }
/** /**
@ -306,8 +313,9 @@ class RemiseCheque extends CommonObject
} }
/** /**
* Validate receipt * Validate a receipt
* @param user User * @param user User
* @return int <0 if KO, >0 if OK
*/ */
function validate($user) function validate($user)
{ {
@ -317,13 +325,12 @@ class RemiseCheque extends CommonObject
$this->db->begin(); $this->db->begin();
$num=$this->getNextNumber(); $numref=$this->getNextNumber();
if ($this->errno == 0 && $num) if ($this->errno == 0 && $numref)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
$sql.= " SET statut = 1"; $sql.= " SET statut = 1, number = '".$numref."'";
$sql.= ", number = '".$num."'";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$sql.= " AND statut = 0"; $sql.= " AND statut = 0";
@ -336,6 +343,7 @@ class RemiseCheque extends CommonObject
if ($num == 1) if ($num == 1)
{ {
$this->number = $numref;
$this->statut = 1; $this->statut = 1;
} }
else else
@ -355,14 +363,14 @@ class RemiseCheque extends CommonObject
if ($this->errno == 0) if ($this->errno == 0)
{ {
$this->db->commit(); $this->db->commit();
return 1;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR); dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
return $this->errno;
} }
return $this->errno;
} }
@ -446,10 +454,10 @@ class RemiseCheque extends CommonObject
/** /**
* \brief Build document * Build document
* \param model Model name * @param model Model name
* \param outputlangs Object langs * @param outputlangs Object langs
* \return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function generatePdf($model='blochet', $outputlangs) function generatePdf($model='blochet', $outputlangs)
{ {
@ -457,7 +465,7 @@ class RemiseCheque extends CommonObject
if (empty($model)) $model='blochet'; if (empty($model)) $model='blochet';
dol_syslog("RemiseCheque::generatePdf model=".$model, LOG_DEBUG); dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
$dir=DOL_DOCUMENT_ROOT ."/includes/modules/cheque/pdf/"; $dir=DOL_DOCUMENT_ROOT ."/includes/modules/cheque/pdf/";
@ -469,7 +477,7 @@ class RemiseCheque extends CommonObject
require_once($dir.$file); require_once($dir.$file);
$classname='BordereauCheque'.ucfirst($model); $classname='BordereauCheque'.ucfirst($model);
$pdf = new $classname($db); $docmodel = new $classname($db);
$sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq"; $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -488,27 +496,27 @@ class RemiseCheque extends CommonObject
$i = 0; $i = 0;
while ( $objp = $this->db->fetch_object($result) ) while ( $objp = $this->db->fetch_object($result) )
{ {
$pdf->lines[$i]->bank_chq = $objp->banque; $docmodel->lines[$i]->bank_chq = $objp->banque;
$pdf->lines[$i]->emetteur_chq = $objp->emetteur; $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
$pdf->lines[$i]->amount_chq = $objp->amount; $docmodel->lines[$i]->amount_chq = $objp->amount;
$pdf->lines[$i]->num_chq = $objp->num_chq; $docmodel->lines[$i]->num_chq = $objp->num_chq;
$i++; $i++;
} }
} }
$pdf->nbcheque = $this->nbcheque; $docmodel->nbcheque = $this->nbcheque;
$pdf->number = $this->number; $docmodel->number = $this->number;
$pdf->amount = $this->amount; $docmodel->amount = $this->amount;
$pdf->date = $this->date_bordereau; $docmodel->date = $this->date_bordereau;
$account = new Account($this->db); $account = new Account($this->db);
$account->fetch($this->account_id); $account->fetch($this->account_id);
$pdf->account = &$account; $docmodel->account = &$account;
// We save charset_output to restore it because write_file can change it if needed for // We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8. // output format that does not support UTF8.
$sav_charset_output=$outputlangs->charset_output; $sav_charset_output=$outputlangs->charset_output;
$result=$pdf->write_file($conf->banque->dir_output.'/bordereau', $this->number, $outputlangs); $result=$docmodel->write_file($conf->banque->dir_output.'/bordereau', $this->number, $outputlangs);
if ($result > 0) if ($result > 0)
{ {
$outputlangs->charset_output=$sav_charset_output; $outputlangs->charset_output=$sav_charset_output;
@ -518,7 +526,7 @@ class RemiseCheque extends CommonObject
{ {
$outputlangs->charset_output=$sav_charset_output; $outputlangs->charset_output=$sav_charset_output;
dol_syslog("Error"); dol_syslog("Error");
dol_print_error($db,$pdf->error); dol_print_error($db,$docmodel->error);
return 0; return 0;
} }
} }

View File

@ -20,8 +20,8 @@
/** /**
* \file htdocs/compta/paiement/cheque/fiche.php * \file htdocs/compta/paiement/cheque/fiche.php
* \ingroup facture * \ingroup bank, invoice
* \brief Tab cheque deposit * \brief Page for cheque deposits
* \version $Id$ * \version $Id$
*/ */
@ -35,8 +35,8 @@ $langs->load('bills');
$langs->load('banks'); $langs->load('banks');
$langs->load('companies'); $langs->load('companies');
$id = isset($_REQUEST["id"])?$_REQUEST["id"]:''; $id = GETPOST("id");
$ref= isset($_REQUEST["ref"])?$_REQUEST["ref"]:''; $ref= GETPOST("ref");
// Security check // Security check
$fieldid = isset($_GET["ref"])?'number':'rowid'; $fieldid = isset($_GET["ref"])?'number':'rowid';
@ -88,8 +88,24 @@ if ($_GET['action'] == 'create' && $_GET["accountid"] > 0 && $user->rights->banq
$result = $remisecheque->create($user, $_GET["accountid"]); $result = $remisecheque->create($user, $_GET["accountid"]);
if ($result > 0) if ($result > 0)
{ {
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$remisecheque->id); if ($remisecheque->statut == 1) // If statut is validated, we build doc
exit; {
$remisecheque->fetch($remisecheque->id); // To force to reload all properties in correct property name
// Define output language
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
//if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$result = $remisecheque->generatePdf($_POST["model"], $outputlangs);
}
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$remisecheque->id);
exit;
} }
else else
{ {
@ -136,7 +152,19 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' &&
$result = $remisecheque->validate($user); $result = $remisecheque->validate($user);
if ($result >= 0) if ($result >= 0)
{ {
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$remisecheque->id); // Define output language
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
//if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$result = $remisecheque->generatePdf($_POST["model"], $outputlangs);
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$remisecheque->id);
exit; exit;
} }
else else
@ -155,13 +183,15 @@ if ($_POST['action'] == 'builddoc' && $user->rights->banque->cheque)
$remisecheque->setDocModel($user, $_REQUEST['model']); $remisecheque->setDocModel($user, $_REQUEST['model']);
}*/ }*/
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) $newlang='';
{ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
$outputlangs = new Translate("",$conf); //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
$outputlangs->setDefaultLang($_REQUEST['lang_id']); if (! empty($newlang))
} {
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$result = $remisecheque->generatePdf($_POST["model"], $outputlangs); $result = $remisecheque->generatePdf($_POST["model"], $outputlangs);
if ($result <= 0) if ($result <= 0)
{ {

View File

@ -57,8 +57,8 @@ class Project extends CommonObject
var $statuts; var $statuts;
/** /**
* \brief Constructeur de la classe * Constructor of class
* \param DB handler acces base de donnees * @param DB Database access handler
*/ */
function Project($DB) function Project($DB)
{ {
@ -70,12 +70,15 @@ class Project extends CommonObject
} }
/** /**
* \brief Create a project into database * Create a project into database
* \param user Id utilisateur qui cree * @param user User making creation
* \return int <0 si ko, id du projet cree si ok * @return int <0 if KO, id of created project if OK
*/ */
function create($user, $notrigger=0) function create($user, $notrigger=0)
{ {
global $conf;
$error=0;
$ret=0; $ret=0;
// Check parameters // Check parameters
@ -86,12 +89,15 @@ class Project extends CommonObject
return -1; return -1;
} }
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (";
$sql.= "ref"; $sql.= "ref";
$sql.= ", title"; $sql.= ", title";
$sql.= ", description"; $sql.= ", description";
$sql.= ", fk_soc"; $sql.= ", fk_soc";
$sql.= ", fk_user_creat"; $sql.= ", fk_user_creat";
$sql.= ", fk_statut";
$sql.= ", public"; $sql.= ", public";
$sql.= ", datec"; $sql.= ", datec";
$sql.= ", dateo"; $sql.= ", dateo";
@ -102,6 +108,7 @@ class Project extends CommonObject
$sql.= ", '".addslashes($this->description)."'"; $sql.= ", '".addslashes($this->description)."'";
$sql.= ", ".($this->socid > 0?$this->socid:"null"); $sql.= ", ".($this->socid > 0?$this->socid:"null");
$sql.= ", ".$user->id; $sql.= ", ".$user->id;
$sql.= ", 0";
$sql.= ", ".($this->public?1:0); $sql.= ", ".($this->public?1:0);
$sql.= ", ".($this->datec!=''?$this->db->idate($this->datec):'null'); $sql.= ", ".($this->datec!=''?$this->db->idate($this->datec):'null');
$sql.= ", ".($this->dateo!=''?$this->db->idate($this->dateo):'null'); $sql.= ", ".($this->dateo!=''?$this->db->idate($this->dateo):'null');
@ -127,12 +134,28 @@ class Project extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog("Project::Create error -2 ".$this->error, LOG_ERR); $this->errno=$this->db->lasterrno();
$ret = -2; dol_syslog("Project::Create error -2 ".$this->error, LOG_ERR);
$error++;
} }
return $ret; if (! $error && ! empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
{
$res=$this->setValid($user);
if ($res < 0) $error++;
}
if (! $error)
{
$this->db->commit();
return $ret;
}
else
{
$this->db->rollback();
return -1;
}
} }
@ -350,8 +373,9 @@ class Project extends CommonObject
} }
/** /**
* \brief Supprime le projet dans la base * Delete a project from database
* \param Utilisateur * @param user User
* @param notrigger Disable triggers
*/ */
function delete($user, $notrigger=0) function delete($user, $notrigger=0)
{ {
@ -433,11 +457,11 @@ class Project extends CommonObject
} }
/** /**
* \brief Validate a project * Validate a project
* \param user User that validate * @param user User that validate
* \return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function setValid($user, $outputdir) function setValid($user)
{ {
global $langs, $conf; global $langs, $conf;
@ -485,11 +509,11 @@ class Project extends CommonObject
} }
/** /**
* \brief Close a project * Close a project
* \param user User that validate * @param user User that validate
* \return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function setClose($user, $outputdir) function setClose($user)
{ {
global $langs, $conf; global $langs, $conf;

View File

@ -70,6 +70,10 @@ if ($_POST["action"] == 'add' && $user->rights->projet->creer)
if (! $error) if (! $error)
{ {
$error=0;
$db->begin();
$project = new Project($db); $project = new Project($db);
$project->ref = $_POST["ref"]; $project->ref = $_POST["ref"];
@ -86,14 +90,31 @@ if ($_POST["action"] == 'add' && $user->rights->projet->creer)
{ {
// Add myself as project leader // Add myself as project leader
$result = $project->add_contact($user->id, 'PROJECTLEADER', 'internal'); $result = $project->add_contact($user->id, 'PROJECTLEADER', 'internal');
if ($result < 0)
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($project->error).'</div>';
$error++;
}
}
else
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($project->error).'</div>';
$error++;
}
if (! $error)
{
$db->commit();
Header("Location:fiche.php?id=".$project->id); Header("Location:fiche.php?id=".$project->id);
exit; exit;
} }
else else
{ {
$langs->load("errors"); $db->rollback();
$mesg='<div class="error">'.$langs->trans($project->error).'</div>';
$_GET["action"] = 'create'; $_GET["action"] = 'create';
} }
} }
@ -177,7 +198,7 @@ if (GETPOST('action') == 'confirm_validate' && GETPOST('confirm') == 'yes')
$project = new Project($db); $project = new Project($db);
$project->fetch(GETPOST("id")); $project->fetch(GETPOST("id"));
$result = $project->setValid($user, $conf->projet->outputdir); $result = $project->setValid($user);
if ($result <= 0) if ($result <= 0)
{ {
$mesg='<div class="error">'.$project->error.'</div>'; $mesg='<div class="error">'.$project->error.'</div>';
@ -188,7 +209,7 @@ if (GETPOST('action') == 'confirm_close' && GETPOST('confirm') == 'yes')
{ {
$project = new Project($db); $project = new Project($db);
$project->fetch(GETPOST("id")); $project->fetch(GETPOST("id"));
$result = $project->setClose($user, $conf->projet->outputdir); $result = $project->setClose($user);
if ($result <= 0) if ($result <= 0)
{ {
$mesg='<div class="error">'.$project->error.'</div>'; $mesg='<div class="error">'.$project->error.'</div>';
@ -199,7 +220,7 @@ if (GETPOST('action') == 'confirm_reopen' && GETPOST('confirm') == 'yes')
{ {
$project = new Project($db); $project = new Project($db);
$project->fetch(GETPOST("id")); $project->fetch(GETPOST("id"));
$result = $project->setValid($user, $conf->projet->outputdir); $result = $project->setValid($user);
if ($result <= 0) if ($result <= 0)
{ {
$mesg='<div class="error">'.$project->error.'</div>'; $mesg='<div class="error">'.$project->error.'</div>';