diff --git a/htdocs/admin/fiscalyear.php b/htdocs/admin/fiscalyear.php index 7929fd5046f..607630461fb 100644 --- a/htdocs/admin/fiscalyear.php +++ b/htdocs/admin/fiscalyear.php @@ -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='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'
'; - $error++; - } - if (! $object->datestart) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateStart")).'
'; - $error++; - } - if (! $object->dateend) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")).'
'; - $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[]='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Label")).'
'; - $error++; - //$action='create'; - } - if (empty($datestart) || empty($dateend)) - { - $mesgs[]='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; - $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); diff --git a/htdocs/admin/fiscalyear_card.php b/htdocs/admin/fiscalyear_card.php index d18fdbc3ec4..3845e689e79 100644 --- a/htdocs/admin/fiscalyear_card.php +++ b/htdocs/admin/fiscalyear_card.php @@ -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='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'
'; @@ -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 '
' . "\n"; + print ''; print ''; print ''; @@ -182,15 +180,13 @@ if ($action == 'create') print ''.$langs->trans("Label").''; // Date start - print ""; - print ''.$langs->trans("DateStart").''; - print $form->select_date($datestart?$datestart:-1,'','','','','add',1,1); + print ''.$langs->trans("DateStart").''; + print $form->select_date(($date_start?$date_start:''),'fiscalyear'); print ''; - - // Date end - print ""; - print ''.$langs->trans("DateEnd").''; - print $form->select_date($dateend?$dateend:-1,'','','','','add',1,1); + + // Date end + print ''.$langs->trans("DateEnd").''; + print $form->select_date(($date_end?$date_end:-1),'fiscalyearend'); print ''; // 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 '' . "\n"; @@ -224,7 +224,7 @@ else if ($id) // Ref print ""; print ''.$langs->trans("Ref").''; - print $object->rowid; + print $object->ref; print ''; // 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 ''; + + print '
'; $linkback = ''.$langs->trans("BackToList").''; - + // Ref print ''; diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 3d48d47a082..6956884e733 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -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'); } } diff --git a/htdocs/core/lib/fiscalyear.lib.php b/htdocs/core/lib/fiscalyear.lib.php new file mode 100644 index 00000000000..6865c875efa --- /dev/null +++ b/htdocs/core/lib/fiscalyear.lib.php @@ -0,0 +1,51 @@ + + * + * 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 . + * 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; +} \ No newline at end of file diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 0c9d9c92481..e04bbe72483 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -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é
'.$langs->trans("Ref").''; - print $object->rowid; + print $object->ref; print ''; print $linkback; print '