This commit is contained in:
aspangaro 2014-06-29 05:41:24 +02:00
parent 56785f1149
commit 8cfdfbe47d
5 changed files with 130 additions and 223 deletions

View File

@ -52,185 +52,6 @@ $object = new Fiscalyear($db);
* Actions
*/
// Add
if ($action == 'add')
{
if (! GETPOST('cancel','alpha'))
{
$error=0;
$object->label = GETPOST('label','alpha');
$object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
$object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
$object->statut = 0;
if (! $object->label)
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'</div>';
$error++;
}
if (! $object->datestart)
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateStart")).'</div>';
$error++;
}
if (! $object->dateend)
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")).'</div>';
$error++;
}
if (! $error)
{
$id = $object->create();
if ($id > 0)
{
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit;
}
else
{
$mesg=$object->error;
$action='create';
}
}
else
{
$action='create';
}
}
else
{
header("Location: index.php");
exit;
}
if (! GETPOST('cancel','alpha'))
{
$error=0;
// Check values
$datestart = dol_mktime(12, 0, 0, $_POST['startmonth'], $_POST['startday'], $_POST['startyear']);
$dateend = dol_mktime(12, 0, 0, $_POST['endmonth'], $_POST['endday'], $_POST['endyear']);
$label = $_POST['label'];
if (empty($label))
{
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Label")).'</div>';
$error++;
//$action='create';
}
if (empty($datestart) || empty($dateend))
{
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
$error++;
//$action='create';
}
if (! $error)
{
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear";
$sql.= " (label, datestart, dateend, statut, entity)";
$sql.= " VALUES('".$label."',";
$sql.= " '".$datestart."',";
$sql.= " '".$dateend."',";
$sql.= " ' 0,";
$sql.= " ".$conf->entity."'";
$sql.=')';
dol_syslog(get_class($this)."::create_label sql=".$sql);
if ($this->db->query($sql))
{
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->errno=$this->db->lasterrno();
return -1;
}
}
}
}
// Rename field
if ($action == 'update')
{
if ($_POST["button"] != $langs->trans("Cancel"))
{
// Check values
if (! GETPOST('type'))
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type"));
$action = 'create';
}
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring);
$action = 'edit';
}
if (GETPOST('type')=='int' && $extrasize > $maxsizeint)
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint);
$action = 'edit';
}
if (! $error)
{
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
$result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0));
if ($result > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$error++;
$mesg=$extrafields->error;
}
}
else
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
}
}
}
}
// Delete attribute
if ($action == 'delete')
{
if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"]))
{
$result=$extrafields->delete($_GET["attrname"],$elementtype);
if ($result >= 0)
{
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else $mesg=$extrafields->error;
}
else
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
}
}
/*
* View
*/
@ -239,9 +60,9 @@ $form = new Form($db);
llxHeader('',$title);
$title = $langs->trans('Accountancysetup');
$title = $langs->trans('FiscalYears');
print_fiche_titre($langs->trans('Fiscalyear'));
print_fiche_titre($langs->trans('FiscalYears'));
dol_htmloutput_errors($mesg);

View File

@ -17,13 +17,13 @@
/**
* \file htdocs/admin/fiscalyear_card.php
* \brief Page to show a fiscal yeartrip
* \brief Page to show a fiscal year
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/fiscalyear.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$langs->load("admin");
@ -50,12 +50,13 @@ $mesg = '';
$object = new Fiscalyear($db);
$date_start=dol_mktime(0,0,0,GETPOST('fiscalyearmonth','int'),GETPOST('fiscalyearday','int'),GETPOST('fiscalyearyear','int'));
$date_end=dol_mktime(0,0,0,GETPOST('fiscalyearendmonth','int'),GETPOST('fiscalyearendday','int'),GETPOST('fiscalyearendyear','int'));
/*
* Actions
*/
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
if ($action == 'confirm_delete' && $confirm == "yes")
{
$result=$object->delete($id);
@ -76,18 +77,18 @@ else if ($action == 'add')
{
$error=0;
$object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
$object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
$object->label = GETPOST('label','alpha');
$db->begin();
$object->datestart = $date_start;
$object->dateend = $date_end;
$object->label = GETPOST('label','alpha');
$object->statut = GETPOST('statut','int');;
/*
if (empty($object->datestart) && empty($object->dateend))
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
$mesg.=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
$error++;
}
*/
if (empty($object->label))
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'</div>';
@ -116,7 +117,7 @@ else if ($action == 'add')
}
else
{
header("Location: fiscalyear.php");
header("Location: ./fiscalyear.php");
exit;
}
}
@ -169,10 +170,7 @@ if ($action == 'create')
dol_htmloutput_errors($mesg);
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int'));
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int'));
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
@ -182,15 +180,13 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="32" value="' . GETPOST("label") . '"></td></tr>';
// Date start
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
print $form->select_date($datestart?$datestart:-1,'','','','','add',1,1);
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
print $form->select_date(($date_start?$date_start:''),'fiscalyear');
print '</td></tr>';
// Date end
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
print $form->select_date($dateend?$dateend:-1,'','','','','add',1,1);
// Date end
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
print $form->select_date(($date_end?$date_end:-1),'fiscalyearend');
print '</td></tr>';
// Statut
@ -212,6 +208,10 @@ else if ($id)
{
dol_htmloutput_mesg($mesg);
$head = fiscalyear_prepare_head($object);
dol_fiche_head($head, 'card', $langs->trans("FiscalYearCard"), 0, 'cron');
if ($action == 'edit')
{
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
@ -224,7 +224,7 @@ else if ($id)
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $object->rowid;
print $object->ref;
print '</td></tr>';
// Label
@ -262,14 +262,14 @@ else if ($id)
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteFiscalYear"),$langs->trans("ConfirmDeleteFiscalYear"),"confirm_delete");
}
print '<table class="border" width="100%">';
print '<table class="border" width="100%">';
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/fiscalyear.php">'.$langs->trans("BackToList").'</a>';
// Ref
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td width="50%">';
print $object->rowid;
print $object->ref;
print '</td><td width="25%">';
print $linkback;
print '</td></tr>';

View File

@ -18,7 +18,7 @@
/**
* \file htdocs/core/class/fiscalyear.php
* \ingroup fiscal year
* \brief Page d'administration/configuration
* \brief File of class to manage fiscal years
*/
require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
*/
class Fiscalyear
{
public $element='Fiscalyear';
public $element='fiscalyear';
public $table_element='accounting_fiscalyear';
public $table_element_line = '';
public $fk_element = '';
@ -69,11 +69,13 @@ class Fiscalyear
function create()
{
global $conf;
$error = 0;
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear (";
$sql.= " label";
$sql.= "label";
$sql.= ", datestart";
$sql.= ", dateend";
$sql.= ", statut";
@ -216,7 +218,34 @@ class Fiscalyear
return -1;
}
}
/**
* Delete record
*
* @param int $id Id of record to delete
* @return int <0 if KO, >0 if OK
*/
function delete($id)
{
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".$id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Give a label from a status
*
@ -249,23 +278,23 @@ class Fiscalyear
}
if ($mode == 2)
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]);
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]);
}
if ($mode == 3)
{
if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
if ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
if ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
}
if ($mode == 4)
{
if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
if ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
if ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]);
}
if ($mode == 5)
{
if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
if ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
if ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
}
}

View File

@ -0,0 +1,51 @@
<?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, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/lib/fiscalyear.lib.php
* \brief Set basic functions for fiscal years
*/
/**
* Prepare array with list of tabs
*
* @param Object $object Object related to tabs
* @return array Array of tabs to shoc
*/
function fiscalyear_prepare_head($object)
{
global $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT . '/admin/fiscalyear_card.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new 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','remove');
return $head;
}

View File

@ -1504,9 +1504,15 @@ TaskModelModule=Modèles de document de rapport tâches
ECMSetup = Configuration du module GED
ECMAutoTree = L'arborescence automatique est disponible
##### Fiscal Year #####
Fiscalyear=Exercices fiscaux
FiscalYears=Exercices fiscaux
FiscalYear=Exercice fiscal
FiscalYearCard=Fiche exercice fiscal
NewFiscalYear=Nouvel exercice fiscal
EditFiscalYear=Editer exercice fiscal
OpenFiscalYear=Exercice fiscal ouvert
CloseFiscalYear=Exercice fiscal fermé
DeleteFiscalYear=Supprimer exercice fiscal
ConfirmDeleteFiscalYear=Êtes-vous sûr de vouloir supprimer cet exercice fiscal ?
Opened=Ouvert
Closed=Fermé