Fix: Fix corrupted data on date of trips

This commit is contained in:
Laurent Destailleur 2011-05-25 18:16:58 +00:00
parent 214c5464da
commit 9e2eccbe4c
6 changed files with 43 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -21,7 +21,7 @@
/**
* \file htdocs/compta/deplacement/class/deplacement.class.php
* \ingroup deplacement
* \brief Fichier de la classe des deplacements
* \brief File of class to manage trips
* \version $Id$
*/
@ -42,6 +42,9 @@ class Deplacement extends CommonObject
var $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $id;
var $datec; // Creation date
var $dated;
var $fk_user_author;
var $fk_user;
var $km;
@ -85,10 +88,13 @@ class Deplacement extends CommonObject
return -1;
}
$this->db->begin();
$now=dol_now();
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."deplacement (";
$sql.= "datec";
//$sql.= ", dated";
$sql.= ", entity";
$sql.= ", fk_user_author";
$sql.= ", fk_user";
@ -98,7 +104,7 @@ class Deplacement extends CommonObject
$sql.= ", fk_projet";
$sql.= ", fk_soc";
$sql.= ") VALUES (";
$sql.= $this->db->idate(mktime());
$sql.= " '".$this->db->idate($now)."'";
$sql.= ", ".$conf->entity;
$sql.= ", ".$user->id;
$sql.= ", ".$this->fk_user;
@ -147,7 +153,12 @@ class Deplacement extends CommonObject
// Check parameters
if (! is_numeric($this->km)) $this->km = 0;
if (empty($this->type) || $this->type < 0)
if (empty($this->date))
{
$this->error='ErrorBadParameter';
return -1;
}
if (empty($this->type) || $this->type < 0)
{
$this->error='ErrorBadParameter';
return -1;

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -69,18 +69,23 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer)
{
$error=0;
$deplacement = new Deplacement($db);
$deplacement->date = dol_mktime(12, 0, 0,
$dated=dol_mktime(12, 0, 0,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]);
$deplacement = new Deplacement($db);
$deplacement->date = $dated;
$deplacement->km = $_POST["km"];
$deplacement->type = $_POST["type"];
$deplacement->socid = $_POST["socid"];
$deplacement->fk_user = $_POST["fk_user"];
if (! $deplacement->date)
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
$error++;
}
if ($deplacement->type == '-1') // Otherwise it is TF_LUNCH,...
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
@ -179,7 +184,7 @@ if ($_GET["action"] == 'create')
{
print_fiche_titre($langs->trans("NewTrip"));
if ($mesg) print $mesg."<br>";
if ($mesg) dol_htmloutput_errors($mesg);
$datec = dol_mktime(12, 0, 0,
$_POST["remonth"],

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (c) 2004-2011 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
@ -66,6 +66,7 @@ $stats = new DeplacementStats($db, $socid);
// Build graphic number of object
// $data = array(array('Lib',val1,val2,val3),...)
//print "$endyear, $startyear";
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
//var_dump($data);

View File

@ -39,17 +39,18 @@ class Stats
/**
* Return nb of entity by month for several years
*
* @param endyear Start year
* @param startyear End year
* @return array Array of values
*/
function getNbByMonthWithPrevYear($endyear,$startyear)
{
if ($startyear > $endyear) return -1;
$datay=array();
$year=$startyear;
while($year <= $endyear)
while ($year <= $endyear)
{
$datay[$year] = $this->getNbByMonth($year);
$year++;
@ -81,7 +82,9 @@ class Stats
*/
function getAmountByMonthWithPrevYear($endyear,$startyear)
{
$datay=array();
if ($startyear > $endyear) return -1;
$datay=array();
$year=$startyear;
while($year <= $endyear)
@ -108,9 +111,9 @@ class Stats
/**
* \brief Return nb of elements by year
* \param sql SQL request
* \return array
* Return nb of elements by year
* @param sql SQL request
* @return array
*/
function _getNbByYear($sql)
{

View File

@ -10,6 +10,9 @@
-- To change type of field: ALTER TABLE llx_table MODIFY name varchar(60);
--
-- Fix correupted data
update llx_deplacement set dated='2010-01-01' where dated < '2000-01-01';
RENAME TABLE llx_c_methode_commande_fournisseur TO llx_c_input_method;
ALTER TABLE llx_adherent MODIFY login varchar(50);
@ -122,7 +125,7 @@ ALTER TABLE llx_expedition ADD COLUMN ref_int varchar(30) AFTER ref_ext;
ALTER TABLE llx_livraison ADD COLUMN ref_ext varchar(30) AFTER fk_soc;
ALTER TABLE llx_livraison ADD COLUMN ref_int varchar(30) AFTER ref_ext;
INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,active) VALUES (4,'LETTREMAX','Lettre max','Courrier suivi et lettre max',0);
INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,active) VALUES (4,'LETTREMAX','Lettre Max','Courrier Suivi et Lettre Max',0);
--Add Chile data (id pays=67)
-- Regions Chile

View File

@ -20,3 +20,5 @@ delete from llx_facture where facnumber = '';
delete from llx_commande where ref = '';
-- V4.1 delete from llx_propaldet where fk_propal in (select rowid from llx_propal where ref = '');
delete from llx_propal where ref = '';
update llx_deplacement set dated='2010-01-01' where dated < '2000-01-01';