Bug fix & add tab info

This commit is contained in:
aspangaro 2014-07-05 08:47:01 +02:00
parent a2ac578712
commit be78e96313
8 changed files with 200 additions and 48 deletions

View File

@ -66,7 +66,7 @@ print_fiche_titre($langs->trans('FiscalYears'));
dol_htmloutput_errors($mesg); dol_htmloutput_errors($mesg);
$sql = "SELECT f.rowid, f.label, f.datestart, f.dateend, f.statut, f.entity"; $sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut, f.entity";
$sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f"; $sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f";
$sql.= " WHERE f.entity = ".$conf->entity; $sql.= " WHERE f.entity = ".$conf->entity;
@ -103,8 +103,8 @@ if ($result)
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td><a href="fiscalyear_card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowFiscalYear"),"technic").' '.$obj->rowid.'</a></td>'; print '<td><a href="fiscalyear_card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowFiscalYear"),"technic").' '.$obj->rowid.'</a></td>';
print '<td align="left">'.$obj->label.'</td>'; print '<td align="left">'.$obj->label.'</td>';
print '<td align="left">'.dol_print_date($db->jdate($obj->datestart),'day').'</td>'; print '<td align="left">'.dol_print_date($db->jdate($obj->date_start),'day').'</td>';
print '<td align="left">'.dol_print_date($db->jdate($obj->dateend),'day').'</td>'; print '<td align="left">'.dol_print_date($db->jdate($obj->date_end),'day').'</td>';
print '<td>'.$fiscalyearstatic->LibStatut($obj->statut,5).'</td>'; print '<td>'.$fiscalyearstatic->LibStatut($obj->statut,5).'</td>';
print '</tr>'; print '</tr>';
$var=!$var; $var=!$var;

View File

@ -79,12 +79,13 @@ else if ($action == 'add')
$db->begin(); $db->begin();
$object->datestart = $date_start; $object->date_start = $date_start;
$object->dateend = $date_end; $object->date_end = $date_end;
$object->label = GETPOST('label','alpha'); $object->label = GETPOST('label','alpha');
$object->statut = GETPOST('statut','int');; $object->statut = GETPOST('statut','int');
$object->datec = dol_now();
if (empty($object->datestart) && empty($object->dateend)) if (empty($object->date_start) && empty($object->date_end))
{ {
$mesg.=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")); $mesg.=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
$error++; $error++;
@ -129,8 +130,8 @@ else if ($action == 'update')
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
$object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); $object->date_start = empty($_POST["fiscalyear"])?'':$date_start;
$object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int')); $object->date_end = empty($_POST["fiscalyearend"])?'':$date_end;
$object->label = GETPOST('label','alpha'); $object->label = GETPOST('label','alpha');
$object->statut = GETPOST('statut','int'); $object->statut = GETPOST('statut','int');
@ -180,19 +181,21 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="' . GETPOST("label") . '"></td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="' . GETPOST("label") . '"></td></tr>';
// Date start // Date start
print '<tr><td>'.$langs->trans("DateStart").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
print $form->select_date(($date_start?$date_start:''),'fiscalyear'); print $form->select_date(($date_start?$date_start:''),'fiscalyear');
print '</td></tr>'; print '</td></tr>';
// Date end // Date end
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
print $form->select_date(($date_end?$date_end:-1),'fiscalyearend'); print $form->select_date(($date_end?$date_end:-1),'fiscalyearend');
print '</td></tr>'; print '</td></tr>';
// Statut // Statut
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("Statut").'</td><td class="valeur">'.$form->selectarray('statut',$statut2label,GETPOST('statut')).'</td>'; print '<td class="fieldrequired">'.$langs->trans("Statut").'</td>';
print '</tr>'; print '<td class="valeur">';
print $form->selectarray('statut',$statut2label,GETPOST('statut'));
print '</td></tr>';
print '</table>'; print '</table>';
@ -234,12 +237,17 @@ else if ($id)
// Date start // Date start
print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
print $form->select_date($object->datestart,'','','','','update'); print $form->select_date($object->date_start?$object->date_start:-1,'fiscalyear');
print '</td></tr>'; print '</td></tr>';
// Date end // Date end
print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
print $form->select_date($object->dateend,'','','','','update'); print $form->select_date($object->date_end?$object->date_end:-1,'fiscalyearend');
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Statut").'</td><td>';
print $form->selectarray('statut',$statut2label,$object->statut);
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
@ -283,16 +291,16 @@ else if ($id)
// Date start // Date start
print '<tr><td>'; print '<tr><td>';
print $form->editfieldkey("Date",'datestart',$object->datestart,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); print $form->editfieldkey("Date",'date_start',$object->date_start,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker');
print '</td><td colspan="2">'; print '</td><td colspan="2">';
print $form->editfieldval("Date",'datestart',$object->datestart,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); print $form->editfieldval("Date",'date_start',$object->date_start,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker');
print '</td></tr>'; print '</td></tr>';
// Date end // Date end
print '<tr><td>'; print '<tr><td>';
print $form->editfieldkey("Date",'dateend',$object->dateend,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); print $form->editfieldkey("Date",'date_end',$object->date_end,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker');
print '</td><td colspan="2">'; print '</td><td colspan="2">';
print $form->editfieldval("Date",'dateend',$object->dateend,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); print $form->editfieldval("Date",'date_end',$object->date_end,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker');
print '</td></tr>'; print '</td></tr>';
// Statut // Statut

View File

@ -0,0 +1,60 @@
<?php
/* Copyright (C) 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, seehttp://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/fiscalyear_card.php
* \brief Page to show info of a fiscal year
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/fiscalyear.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
$langs->load("admin");
$langs->load("compta");
// Security check
if (! $user->admin) accessforbidden();
$id = GETPOST('id','int');
// View
llxHeader();
if ($id)
{
$object = new Fiscalyear($db);
$object->fetch($id);
$object->info($id);
$head = fiscalyear_prepare_head($object);
dol_fiche_head($head, 'info', $langs->trans("FiscalYearCard"), 0, 'cron');
print '<table width="100%"><tr><td>';
dol_print_object_info($object);
print '</td></tr></table>';
print '</div>';
}
$db->close();
llxFooter();

View File

@ -38,8 +38,8 @@ class Fiscalyear
var $rowid; var $rowid;
var $label; var $label;
var $datestart; var $date_start;
var $dateend; var $date_end;
var $statut; // 0=open, 1=closed var $statut; // 0=open, 1=closed
var $entity; var $entity;
@ -72,23 +72,29 @@ class Fiscalyear
$error = 0; $error = 0;
$now=dol_now();
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear (";
$sql.= "label"; $sql.= "label";
$sql.= ", datestart"; $sql.= ", date_start";
$sql.= ", dateend"; $sql.= ", date_end";
$sql.= ", statut"; $sql.= ", statut";
$sql.= ", entity"; $sql.= ", entity";
$sql.= ", datec";
$sql.= ", fk_user_author";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= " '".$this->label; $sql.= " '".$this->label."'";
$sql.= "', ".$this->db->idate($this->datestart); $sql.= ", '".$this->db->idate($this->date_start)."'";
$sql.= ", ".$this->db->idate($this->dateend); $sql.= ", '".$this->db->idate($this->date_end)."'";
$sql.= ", ".$this->statut; $sql.= ", ".$this->statut;
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->idate($now)."'";
$sql.= ", ". $user->id;
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -117,7 +123,7 @@ class Fiscalyear
return $this->rowid; return $this->rowid;
} }
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::create=", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -155,7 +161,7 @@ class Fiscalyear
global $langs; global $langs;
// Check parameters // Check parameters
if (empty($this->datestart) && empty($this->dateend)) if (empty($this->date_start) && empty($this->date_end))
{ {
$this->error='ErrorBadParameter'; $this->error='ErrorBadParameter';
return -1; return -1;
@ -164,13 +170,15 @@ class Fiscalyear
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear "; $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear ";
$sql .= " SET label = ".$this->label; $sql .= " SET label = '".$this->label."'";
$sql .= " , datestart = '".$this->db->idate($this->datestart)."'"; $sql .= ", date_start = '".$this->db->idate($this->date_start)."'";
$sql .= " , dateend = '".$this->db->idate($this->dateend)."'"; $sql .= ", date_end = '".$this->db->idate($this->date_end)."'";
$sql .= " , statut = '".$this->statut."'"; $sql .= ", statut = '".$this->statut."'";
$sql .= ", datec = " . ($this->datec != '' ? $this->db->idate($this->datec) : 'null');
$sql .= ", fk_user_modif = " . $user->id;
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::update", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -193,11 +201,11 @@ class Fiscalyear
*/ */
function fetch($id) function fetch($id)
{ {
$sql = "SELECT rowid, label, datestart, dateend, statut"; $sql = "SELECT rowid, label, date_start, date_end, statut";
$sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; $sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ( $result ) if ( $result )
{ {
@ -205,8 +213,8 @@ class Fiscalyear
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->datestart = $this->db->jdate($obj->datestart); $this->date_start = $this->db->jdate($obj->date_start);
$this->dateend = $this->db->jdate($obj->dateend); $this->date_end = $this->db->jdate($obj->date_end);
$this->label = $obj->label; $this->label = $obj->label;
$this->statut = $obj->statut; $this->statut = $obj->statut;
@ -231,7 +239,7 @@ class Fiscalyear
$sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".$id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".$id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -298,4 +306,49 @@ class Fiscalyear
} }
} }
/**
* Information on record
*
* @param int $id Id of record
* @return void
*/
function info($id)
{
$sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,';
$sql.= ' fy.tms';
$sql.= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy';
$sql.= ' WHERE fy.rowid = '.$id;
dol_syslog(get_class($this)."::fetch info", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
if ($obj->fk_user_author)
{
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif)
{
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser;
}
$this->date_creation = $this->db->jdate($obj->datec);
$this->date_modification = $this->db->jdate($obj->tms);
}
$this->db->free($result);
}
else
{
dol_print_error($this->db);
}
}
} }

View File

@ -45,6 +45,11 @@ function fiscalyear_prepare_head($object)
// $this->tabs = array('entity:-tabname); to remove a tab // $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'fiscalyear'); complete_head_from_modules($conf,$langs,$object,$head,$h,'fiscalyear');
$head[$h][0] = DOL_URL_ROOT . '/admin/fiscalyear_info.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'fiscalyear','remove'); complete_head_from_modules($conf,$langs,$object,$head,$h,'fiscalyear','remove');
return $head; return $head;

View File

@ -58,3 +58,19 @@ ALTER TABLE llx_c_tva MODIFY COLUMN localtax2 varchar(10);
ALTER TABLE llx_localtax ADD COLUMN localtaxtype tinyint(4) after entity; ALTER TABLE llx_localtax ADD COLUMN localtaxtype tinyint(4) after entity;
ALTER TABLE llx_societe ADD COLUMN localtax1_value double(6,3) after localtax1_assuj; ALTER TABLE llx_societe ADD COLUMN localtax1_value double(6,3) after localtax1_assuj;
ALTER TABLE llx_societe ADD COLUMN localtax2_value double(6,3) after localtax2_assuj; ALTER TABLE llx_societe ADD COLUMN localtax2_value double(6,3) after localtax2_assuj;
-- Fiscal years
create table llx_accounting_fiscalyear
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
label varchar(128) NOT NULL,
date_start date,
date_end date,
statut tinyint DEFAULT 0 NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id
datec datetime NOT NULL,
tms timestamp NULL,
fk_user_author integer NULL,
fk_user_modif integer NULL
)ENGINE=innodb;

View File

@ -20,8 +20,12 @@ create table llx_accounting_fiscalyear
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
label varchar(128) NOT NULL, label varchar(128) NOT NULL,
datestart date, date_start date,
dateend date, date_end date,
statut tinyint DEFAULT 0 NOT NULL, statut tinyint DEFAULT 0 NOT NULL,
entity integer DEFAULT 1 NOT NULL -- multi company id entity integer DEFAULT 1 NOT NULL, -- multi company id
datec datetime NOT NULL,
tms timestamp DEFAULT NULL,
fk_user_author integer DEFAULT NULL,
fk_user_modif integer DEFAULT NULL
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -1514,9 +1514,15 @@ TaskModelModule=Tasks reports document model
ECMSetup = GED Setup ECMSetup = GED Setup
ECMAutoTree = Automatic tree folder and document ECMAutoTree = Automatic tree folder and document
##### Fiscal Year ##### ##### Fiscal Year #####
Fiscalyear=Fiscal years FiscalYears=Fiscal years
FiscalYear=Fiscal year
FiscalYearCard=Fiscal year card
NewFiscalYear=New fiscal year
EditFiscalYear=Edit fiscal year
OpenFiscalYear=Open fiscal year OpenFiscalYear=Open fiscal year
CloseFiscalYear=Close fiscal year CloseFiscalYear=Close fiscal year
DeleteFiscalYear=Delete fiscal year
ConfirmDeleteFiscalYear=Are you sure to delete this fiscal year ?
Opened=Opened Opened=Opened
Closed=Closed Closed=Closed