From dce9c2bc76820a1bdd2d934dc4e487dd027a5c91 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 28 May 2014 05:34:10 +0200 Subject: [PATCH 1/4] Fiscal year - 1st step --- htdocs/admin/fiscalyear.php | 315 +++++++++++++++++ htdocs/admin/fiscalyear_card.php | 325 ++++++++++++++++++ htdocs/core/class/fiscalyear.class.php | 272 +++++++++++++++ htdocs/core/menus/init_menu_auguria.sql | 19 +- htdocs/core/menus/standard/eldy.lib.php | 1 + htdocs/core/menus/standard/empty.php | 1 + .../tables/llx_accounting_fiscalyear.sql | 27 ++ htdocs/langs/en_US/admin.lang | 9 +- htdocs/langs/fr_FR/admin.lang | 7 +- 9 files changed, 964 insertions(+), 12 deletions(-) create mode 100644 htdocs/admin/fiscalyear.php create mode 100644 htdocs/admin/fiscalyear_card.php create mode 100644 htdocs/core/class/fiscalyear.class.php create mode 100644 htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql diff --git a/htdocs/admin/fiscalyear.php b/htdocs/admin/fiscalyear.php new file mode 100644 index 00000000000..7929fd5046f --- /dev/null +++ b/htdocs/admin/fiscalyear.php @@ -0,0 +1,315 @@ + + * + * 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 . + */ + +/** + * \file htdocs/admin/fiscalyear.php + * \ingroup fiscal year + * \brief Setup page to configure fiscal year + */ + +require '../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php'; + +$action=GETPOST('action'); + +$langs->load("admin"); +$langs->load("compta"); + +if (! $user->admin) accessforbidden(); + +$error=0; + +// List of statut +static $tmpstatut2label=array( + '0'=>'OpenFiscalYear', + '1'=>'CloseFiscalYear' +); +$statut2label=array(''); +foreach ($tmpstatut2label as $key => $val) $statut2label[$key]=$langs->trans($val); + +$mesg=''; +$errors=array(); + +$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 + */ + +$form = new Form($db); + +llxHeader('',$title); + +$title = $langs->trans('Accountancysetup'); + +print_fiche_titre($langs->trans('Fiscalyear')); + +dol_htmloutput_errors($mesg); + +$sql = "SELECT f.rowid, f.label, f.datestart, f.dateend, f.statut, f.entity"; +$sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f"; +$sql.= " WHERE f.entity = ".$conf->entity; + +$result = $db->query($sql); + +$max=10; + +if ($result) +{ + $var=false; + $num = $db->num_rows($result); + + $i = 0; + + // Load attribute_label + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + if ($num) + { + $fiscalyearstatic=new Fiscalyear($db); + + while ($i < $num && $i < $max) + { + $obj = $db->fetch_object($result); + $fiscalyearstatic->ref=$obj->rowid; + $fiscalyearstatic->id=$obj->rowid; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var=!$var; + $i++; + } + + } + else + { + print ''; + } + + print '
'.$langs->trans("Ref").''.$langs->trans("Label").''.$langs->trans("DateStart").''.$langs->trans("DateEnd").''.$langs->trans("Statut").'
'.img_object($langs->trans("ShowFiscalYear"),"technic").' '.$obj->rowid.''.$obj->label.''.dol_print_date($db->jdate($obj->datestart),'day').''.dol_print_date($db->jdate($obj->dateend),'day').''.$fiscalyearstatic->LibStatut($obj->statut,5).'
'.$langs->trans("None").'
'; + print ''; +} +else +{ + dol_print_error($db); +} + +dol_fiche_end(); + +// Buttons +print ''; + +llxFooter(); +$db->close(); \ No newline at end of file diff --git a/htdocs/admin/fiscalyear_card.php b/htdocs/admin/fiscalyear_card.php new file mode 100644 index 00000000000..d18fdbc3ec4 --- /dev/null +++ b/htdocs/admin/fiscalyear_card.php @@ -0,0 +1,325 @@ + + * + * 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 . + */ + +/** + * \file htdocs/admin/fiscalyear_card.php + * \brief Page to show a fiscal yeartrip + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.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"); +$langs->load("compta"); + +// Security check +if (! $user->admin) accessforbidden(); + +$error=0; + +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm','alpha'); +$id = GETPOST('id','int'); + +// List of statut +static $tmpstatut2label=array( + '0'=>'OpenFiscalYear', + '1'=>'CloseFiscalYear' +); +$statut2label=array(''); +foreach ($tmpstatut2label as $key => $val) $statut2label[$key]=$langs->trans($val); + +$mesg = ''; + +$object = new Fiscalyear($db); + +/* + * 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); + if ($result >= 0) + { + header("Location: fiscalyear.php"); + exit; + } + else + { + $mesg=$object->error; + } +} + +else if ($action == 'add') +{ + if (! GETPOST('cancel','alpha')) + { + $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'); + $object->statut = GETPOST('statut','int');; + + /* + if (empty($object->datestart) && empty($object->dateend)) + { + $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")); + $error++; + } + */ + if (empty($object->label)) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Label")).'
'; + $error++; + } + + if (! $error) + { + $id = $object->create($user); + + if ($id > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + $mesg=$object->error; + $action='create'; + } + } + else + { + $action='create'; + } + } + else + { + header("Location: fiscalyear.php"); + exit; + } +} + +// Update record +else if ($action == 'update') +{ + if (! GETPOST('cancel','alpha')) + { + $result = $object->fetch($id); + + $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'); + $object->statut = GETPOST('statut','int'); + + $result = $object->update($user); + + if ($result > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + $mesg=$object->error; + } + } + else + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } +} + +/* + * View + */ + +llxHeader(); + +$form = new Form($db); + +/* + * Action create +*/ +if ($action == 'create') +{ + print_fiche_titre($langs->trans("NewFiscalYear")); + + 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 ''; + + // Label + print ''; + + // Date start + print ""; + print ''; + + // Date end + print ""; + print ''; + + // Statut + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Label").'
'.$langs->trans("DateStart").''; + print $form->select_date($datestart?$datestart:-1,'','','','','add',1,1); + print '
'.$langs->trans("DateEnd").''; + print $form->select_date($dateend?$dateend:-1,'','','','','add',1,1); + print '
'.$langs->trans("Statut").''.$form->selectarray('statut',$statut2label,GETPOST('statut')).'
'; + + print '
    '; + print ''; +} +else if ($id) +{ + $result = $object->fetch($id); + if ($result > 0) + { + dol_htmloutput_mesg($mesg); + + if ($action == 'edit') + { + print '' . "\n"; + print ''; + print ''; + print ''; + + print ''; + + // Ref + print ""; + print ''; + + // Label + print ''; + + // Date start + print ''; + + // Date end + print ''; + + print '
'.$langs->trans("Ref").''; + print $object->rowid; + print '
'.$langs->trans("Label").''; + print ''; + print '
'.$langs->trans("DateStart").''; + print $form->select_date($object->datestart,'','','','','update'); + print '
'.$langs->trans("DateEnd").''; + print $form->select_date($object->dateend,'','','','','update'); + print '
'; + + print '
  '; + print ''; + print '
'; + + print ''; + + print ''; + } + else + { + /* + * Confirm delete + */ + if ($action == 'delete') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteFiscalYear"),$langs->trans("ConfirmDeleteFiscalYear"),"confirm_delete"); + + } + + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + // Label + print '"; + + // Date start + print ''; + + // Date end + print ''; + + // Statut + print ''; + + print "
'.$langs->trans("Ref").''; + print $object->rowid; + print ''; + print $linkback; + print '
'; + print $form->editfieldkey("Label",'label',$object->label,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'alpha:32'); + print ''; + print $form->editfieldval("Label",'label',$object->label,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'alpha:32'); + print "
'; + print $form->editfieldkey("Date",'datestart',$object->datestart,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); + print ''; + print $form->editfieldval("Date",'datestart',$object->datestart,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); + print '
'; + print $form->editfieldkey("Date",'dateend',$object->dateend,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); + print ''; + print $form->editfieldval("Date",'dateend',$object->dateend,$object,$conf->global->MAIN_EDIT_ALSO_INLINE,'datepicker'); + print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'

"; + + print ''; + + /* + * Barre d'actions + */ + + print '
'; + + print ''.$langs->trans('Modify').''; + + print ''.$langs->trans('Delete').''; + + print '
'; + } + } + else + { + dol_print_error($db); + } +} + +llxFooter(); +$db->close(); diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php new file mode 100644 index 00000000000..3d48d47a082 --- /dev/null +++ b/htdocs/core/class/fiscalyear.class.php @@ -0,0 +1,272 @@ + + * + * 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 . + */ + +/** + * \file htdocs/core/class/fiscalyear.php + * \ingroup fiscal year + * \brief Page d'administration/configuration + */ + +require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; + +/** + * Class to manage fiscal year + */ +class Fiscalyear +{ + public $element='Fiscalyear'; + public $table_element='accounting_fiscalyear'; + public $table_element_line = ''; + public $fk_element = ''; + protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + + var $id; + var $rowid; + + var $label; + var $datestart; + var $dateend; + var $statut; // 0=open, 1=closed + var $entity; + + var $statuts=array(); + var $statuts_short=array(); + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + + $this->statuts_short = array(0 => 'Opened', 1 => 'Closed'); + $this->statuts = array(0 => 'Opened', 1 => 'Closed'); + + return 1; + } + + /** + * Create object in database + * + * @return int <0 if KO, >0 if OK + */ + function create() + { + global $conf; + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; + $sql.= " label"; + $sql.= ", datestart"; + $sql.= ", dateend"; + $sql.= ", statut"; + $sql.= ", entity"; + $sql.= ") VALUES ("; + $sql.= " '".$this->label; + $sql.= "', ".$this->db->idate($this->datestart); + $sql.= ", ".$this->db->idate($this->dateend); + $sql.= ", ".$this->statut; + $sql.= ", ".$conf->entity; + $sql.= ")"; + + dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $error++; $this->errors[]="Error ".$this->db->lasterror(); + } + + if (! $error) + { + $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return $this->rowid; + } + + dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); + + $result=$this->update($user); + if ($result > 0) + { + $this->db->commit(); + return $this->rowid; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return $result; + } + } + else + { + $this->error=$this->db->error()." sql=".$sql; + $this->db->rollback(); + return -1; + } + } + + /** + * Update record + * + * @param User $user User making update + * @return int <0 if KO, >0 if OK + */ + function update($user) + { + global $langs; + + // Check parameters + if (empty($this->datestart) && empty($this->dateend)) + { + $this->error='ErrorBadParameter'; + return -1; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear "; + $sql .= " SET label = ".$this->label; + $sql .= " , datestart = '".$this->db->idate($this->datestart)."'"; + $sql .= " , dateend = '".$this->db->idate($this->dateend)."'"; + $sql .= " , statut = '".$this->statut."'"; + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } + + /** + * Load an object from database + * + * @param int $id Id of record to load + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + $sql = "SELECT rowid, label, datestart, dateend, statut"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql.= " WHERE rowid = ".$id; + + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ( $result ) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->datestart = $this->db->jdate($obj->datestart); + $this->dateend = $this->db->jdate($obj->dateend); + $this->label = $obj->label; + $this->statut = $obj->statut; + + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + + /** + * Give a label from a status + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } + + /** + * Give a label from a status + * + * @param int $statut Id status + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function LibStatut($statut,$mode=0) + { + global $langs; + + if ($mode == 0) + { + return $langs->trans($this->statuts[$statut]); + } + if ($mode == 1) + { + return $langs->trans($this->statuts_short[$statut]); + } + 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 ($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 ($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 ($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'); + } + } + +} \ No newline at end of file diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index f8e5828bbd1..b5e85d7830d 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -25,16 +25,17 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 101__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/company.php?leftmenu=setup', 'MenuCompanySetup', 1, 'admin', '', '', 2, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 102__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/ihm.php?leftmenu=setup', 'GUISetup', 1, 'admin', '', '', 2, 4, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 103__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/modules.php?leftmenu=setup', 'Modules', 1, 'admin', '', '', 2, 2, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 104__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/boxes.php?leftmenu=setup', 'Boxes', 1, 'admin', '', '', 2, 5, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 104__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/boxes.php?leftmenu=setup', 'Boxes', 1, 'admin', '', '', 2, 6, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 105__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/menus.php?leftmenu=setup', 'Menus', 1, 'admin', '', '', 2, 3, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 106__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/delais.php?leftmenu=setup', 'Alerts', 1, 'admin', '', '', 2, 6, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 108__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/proxy.php?leftmenu=setup', 'Security', 1, 'admin', '', '', 2, 7, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 110__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/limits.php?leftmenu=setup', 'MenuLimits', 1, 'admin', '', '', 2, 8, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 107__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/pdf.php?leftmenu=setup', 'PDF', 1, 'admin', '', '', 2, 9, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 109__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/mails.php?leftmenu=setup', 'Emails', 1, 'admin', '', '', 2, 10, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 113__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/sms.php?leftmenu=setup', 'SMS', 1, 'admin', '', '', 2, 11, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 111__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/dict.php?leftmenu=setup', 'Dictionary', 1, 'admin', '', '', 2, 12, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 112__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/const.php?leftmenu=setup', 'OtherSetup', 1, 'admin', '', '', 2, 13, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 114__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/fiscalyear.php?leftmenu=setup', 'Fiscalyear', 1, 'admin', '', '', 2, 5, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 106__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/delais.php?leftmenu=setup', 'Alerts', 1, 'admin', '', '', 2, 7, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 108__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/proxy.php?leftmenu=setup', 'Security', 1, 'admin', '', '', 2, 8, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 110__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/limits.php?leftmenu=setup', 'MenuLimits', 1, 'admin', '', '', 2, 9, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 107__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/pdf.php?leftmenu=setup', 'PDF', 1, 'admin', '', '', 2, 10, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 109__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/mails.php?leftmenu=setup', 'Emails', 1, 'admin', '', '', 2, 11, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 113__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/sms.php?leftmenu=setup', 'SMS', 1, 'admin', '', '', 2, 12, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 111__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/dict.php?leftmenu=setup', 'Dictionary', 1, 'admin', '', '', 2, 13, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="setup"', __HANDLER__, 'left', 112__+MAX_llx_menu__, 'home', '', 100__+MAX_llx_menu__, '/admin/const.php?leftmenu=setup', 'OtherSetup', 1, 'admin', '', '', 2, 14, __ENTITY__); -- Home - Sytem info insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$user->admin', __HANDLER__, 'left', 300__+MAX_llx_menu__, 'home', 'admintools', 1__+MAX_llx_menu__, '/admin/tools/index.php?leftmenu=admintools', 'SystemTools', 0, 'admin', '', '', 2, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="admintools"', __HANDLER__, 'left', 201__+MAX_llx_menu__, 'home', '', 300__+MAX_llx_menu__, '/admin/system/dolibarr.php?leftmenu=admintools', 'InfoDolibarr', 1, 'admin', '', '', 2, 0, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 35b3f78c5e7..29ad35214cd 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -501,6 +501,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/admin/modules.php?mainmenu=home", $langs->trans("Modules").$warnpicto,1); $newmenu->add("/admin/menus.php?mainmenu=home", $langs->trans("Menus"),1); $newmenu->add("/admin/ihm.php?mainmenu=home", $langs->trans("GUISetup"),1); + $newmenu->add("/admin/fiscalyear.php?mainmenu=home", $langs->trans("Fiscalyear"),1); if (! in_array($langs->defaultlang,array('en_US','en_GB','en_NZ','en_AU','fr_FR','fr_BE','es_ES','ca_ES'))) { if (empty($leftmenu) || $leftmenu=="setup") $newmenu->add("/admin/translation.php", $langs->trans("Translation"),1); diff --git a/htdocs/core/menus/standard/empty.php b/htdocs/core/menus/standard/empty.php index f316d334928..a6063c84d18 100644 --- a/htdocs/core/menus/standard/empty.php +++ b/htdocs/core/menus/standard/empty.php @@ -115,6 +115,7 @@ class MenuManager $this->menu->add("/admin/modules.php", $langs->trans("Modules"),1); $this->menu->add("/admin/menus.php", $langs->trans("Menus"),1); $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"),1); + $this->menu->add("/admin/fiscalyear.php", $langs->trans("Fiscalyear"),1); $this->menu->add("/admin/boxes.php", $langs->trans("Boxes"),1); $this->menu->add("/admin/delais.php",$langs->trans("Alerts"),1); $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1); diff --git a/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql b/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql new file mode 100644 index 00000000000..fe8563d7250 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql @@ -0,0 +1,27 @@ +-- ============================================================================ +-- Copyright (C) 2014 Alexandre Spangaro +-- +-- 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 . +-- +-- ============================================================================ + +create table llx_accounting_fiscalyear +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + label varchar(128) NOT NULL, + datestart date, + dateend date, + statut tinyint DEFAULT 0 NOT NULL, + entity integer DEFAULT 1 NOT NULL -- multi company id +)ENGINE=innodb; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index d22e27c1cbf..1f3cb7ed0c1 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1496,7 +1496,12 @@ TasksNumberingModules=Tasks numbering module TaskModelModule=Tasks reports document model ##### ECM (GED) ##### ECMSetup = GED Setup -ECMAutoTree = Automatic tree folder and document - +ECMAutoTree = Automatic tree folder and document +##### Fiscal Year ##### +Fiscalyear=Fiscal years +OpenFiscalYear=Open fiscal year +CloseFiscalYear=Close fiscal year +Opened=Opened +Closed=Closed Format=Format \ No newline at end of file diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 059e3e4bac2..bc29d977ed2 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1497,6 +1497,11 @@ TaskModelModule=Modèles de document de rapport tâches ##### ECM (GED) ##### ECMSetup = Configuration du module GED ECMAutoTree = L'arborescence automatique est disponible - +##### Fiscal Year ##### +Fiscalyear=Exercices fiscaux +OpenFiscalYear=Exercice fiscal ouvert +CloseFiscalYear=Exercice fiscal fermé +Opened=Ouvert +Closed=Fermé Format=Format From 8cfdfbe47d0a8c9532233e451adf48a7a27275fe Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 29 Jun 2014 05:41:24 +0200 Subject: [PATCH 2/4] Update --- htdocs/admin/fiscalyear.php | 183 +------------------------ htdocs/admin/fiscalyear_card.php | 58 ++++---- htdocs/core/class/fiscalyear.class.php | 53 +++++-- htdocs/core/lib/fiscalyear.lib.php | 51 +++++++ htdocs/langs/fr_FR/admin.lang | 8 +- 5 files changed, 130 insertions(+), 223 deletions(-) create mode 100644 htdocs/core/lib/fiscalyear.lib.php 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é From be78e963138e33fdb617034f38113d2032ee9ac3 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 5 Jul 2014 08:47:01 +0200 Subject: [PATCH 3/4] Bug fix & add tab info --- htdocs/admin/fiscalyear.php | 6 +- htdocs/admin/fiscalyear_card.php | 44 +++++---- htdocs/admin/fiscalyear_info.php | 60 ++++++++++++ htdocs/core/class/fiscalyear.class.php | 93 +++++++++++++++---- htdocs/core/lib/fiscalyear.lib.php | 5 + .../install/mysql/migration/3.6.0-3.7.0.sql | 16 ++++ .../tables/llx_accounting_fiscalyear.sql | 16 ++-- htdocs/langs/en_US/admin.lang | 8 +- 8 files changed, 200 insertions(+), 48 deletions(-) create mode 100644 htdocs/admin/fiscalyear_info.php diff --git a/htdocs/admin/fiscalyear.php b/htdocs/admin/fiscalyear.php index 607630461fb..1cc06281a66 100644 --- a/htdocs/admin/fiscalyear.php +++ b/htdocs/admin/fiscalyear.php @@ -66,7 +66,7 @@ print_fiche_titre($langs->trans('FiscalYears')); 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.= " WHERE f.entity = ".$conf->entity; @@ -103,8 +103,8 @@ if ($result) print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; $var=!$var; diff --git a/htdocs/admin/fiscalyear_card.php b/htdocs/admin/fiscalyear_card.php index 3845e689e79..81860a07ae1 100644 --- a/htdocs/admin/fiscalyear_card.php +++ b/htdocs/admin/fiscalyear_card.php @@ -79,12 +79,13 @@ else if ($action == 'add') $db->begin(); - $object->datestart = $date_start; - $object->dateend = $date_end; + $object->date_start = $date_start; + $object->date_end = $date_end; $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")); $error++; @@ -129,10 +130,10 @@ else if ($action == 'update') { $result = $object->fetch($id); - $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'); - $object->statut = GETPOST('statut','int'); + $object->date_start = empty($_POST["fiscalyear"])?'':$date_start; + $object->date_end = empty($_POST["fiscalyearend"])?'':$date_end; + $object->label = GETPOST('label','alpha'); + $object->statut = GETPOST('statut','int'); $result = $object->update($user); @@ -180,19 +181,21 @@ if ($action == 'create') print ''; // Date start - print ''; // Date end - print ''; // Statut print ''; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("Ref").''; - print $object->rowid; + print $object->ref; print ''; print $linkback; print '
'.img_object($langs->trans("ShowFiscalYear"),"technic").' '.$obj->rowid.''.$obj->label.''.dol_print_date($db->jdate($obj->datestart),'day').''.dol_print_date($db->jdate($obj->dateend),'day').''.dol_print_date($db->jdate($obj->date_start),'day').''.dol_print_date($db->jdate($obj->date_end),'day').''.$fiscalyearstatic->LibStatut($obj->statut,5).'
'.$langs->trans("Label").'
'.$langs->trans("DateStart").''; + print '
'.$langs->trans("DateStart").''; print $form->select_date(($date_start?$date_start:''),'fiscalyear'); print '
'.$langs->trans("DateEnd").''; + print '
'.$langs->trans("DateEnd").''; print $form->select_date(($date_end?$date_end:-1),'fiscalyearend'); print '
'.$langs->trans("Statut").''.$form->selectarray('statut',$statut2label,GETPOST('statut')).'
'.$langs->trans("Statut").''; + print $form->selectarray('statut',$statut2label,GETPOST('statut')); + print '
'; @@ -234,13 +237,18 @@ else if ($id) // Date start print ''.$langs->trans("DateStart").''; - print $form->select_date($object->datestart,'','','','','update'); + print $form->select_date($object->date_start?$object->date_start:-1,'fiscalyear'); print ''; // Date end print ''.$langs->trans("DateEnd").''; - print $form->select_date($object->dateend,'','','','','update'); + print $form->select_date($object->date_end?$object->date_end:-1,'fiscalyearend'); print ''; + + // Statut + print ''.$langs->trans("Statut").''; + print $form->selectarray('statut',$statut2label,$object->statut); + print ''; print ''; @@ -283,16 +291,16 @@ else if ($id) // Date start print ''; - 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 ''; - 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 ''; // Date end print ''; - 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 ''; - 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 ''; // Statut diff --git a/htdocs/admin/fiscalyear_info.php b/htdocs/admin/fiscalyear_info.php new file mode 100644 index 00000000000..c59d75c8376 --- /dev/null +++ b/htdocs/admin/fiscalyear_info.php @@ -0,0 +1,60 @@ + + * + * 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 '
'; + dol_print_object_info($object); + print '
'; + + print ''; +} + +$db->close(); + +llxFooter(); diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 6956884e733..21dfa6f2381 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -38,8 +38,8 @@ class Fiscalyear var $rowid; var $label; - var $datestart; - var $dateend; + var $date_start; + var $date_end; var $statut; // 0=open, 1=closed var $entity; @@ -71,24 +71,30 @@ class Fiscalyear global $conf; $error = 0; + + $now=dol_now(); $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; $sql.= "label"; - $sql.= ", datestart"; - $sql.= ", dateend"; + $sql.= ", date_start"; + $sql.= ", date_end"; $sql.= ", statut"; $sql.= ", entity"; + $sql.= ", datec"; + $sql.= ", fk_user_author"; $sql.= ") VALUES ("; - $sql.= " '".$this->label; - $sql.= "', ".$this->db->idate($this->datestart); - $sql.= ", ".$this->db->idate($this->dateend); + $sql.= " '".$this->label."'"; + $sql.= ", '".$this->db->idate($this->date_start)."'"; + $sql.= ", '".$this->db->idate($this->date_end)."'"; $sql.= ", ".$this->statut; $sql.= ", ".$conf->entity; + $sql.= ", '".$this->db->idate($now)."'"; + $sql.= ", ". $user->id; $sql.= ")"; - dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -117,7 +123,7 @@ class Fiscalyear 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); if ($result) { @@ -155,7 +161,7 @@ class Fiscalyear global $langs; // Check parameters - if (empty($this->datestart) && empty($this->dateend)) + if (empty($this->date_start) && empty($this->date_end)) { $this->error='ErrorBadParameter'; return -1; @@ -164,13 +170,15 @@ class Fiscalyear $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear "; - $sql .= " SET label = ".$this->label; - $sql .= " , datestart = '".$this->db->idate($this->datestart)."'"; - $sql .= " , dateend = '".$this->db->idate($this->dateend)."'"; - $sql .= " , statut = '".$this->statut."'"; + $sql .= " SET label = '".$this->label."'"; + $sql .= ", date_start = '".$this->db->idate($this->date_start)."'"; + $sql .= ", date_end = '".$this->db->idate($this->date_end)."'"; + $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; - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::update", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -193,11 +201,11 @@ class Fiscalyear */ 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.= " 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); if ( $result ) { @@ -205,8 +213,8 @@ class Fiscalyear $this->id = $obj->rowid; $this->ref = $obj->rowid; - $this->datestart = $this->db->jdate($obj->datestart); - $this->dateend = $this->db->jdate($obj->dateend); + $this->date_start = $this->db->jdate($obj->date_start); + $this->date_end = $this->db->jdate($obj->date_end); $this->label = $obj->label; $this->statut = $obj->statut; @@ -231,7 +239,7 @@ class Fiscalyear $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); if ($result) { @@ -297,5 +305,50 @@ class Fiscalyear if ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut8'); } } + + /** + * 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); + } + } } \ No newline at end of file diff --git a/htdocs/core/lib/fiscalyear.lib.php b/htdocs/core/lib/fiscalyear.lib.php index 6865c875efa..60b2c810294 100644 --- a/htdocs/core/lib/fiscalyear.lib.php +++ b/htdocs/core/lib/fiscalyear.lib.php @@ -44,6 +44,11 @@ function fiscalyear_prepare_head($object) // $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'); + + $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'); diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index f5757a39754..e1c5285f603 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -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_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; + +-- 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; + diff --git a/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql b/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql index fe8563d7250..eba284e4002 100644 --- a/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql +++ b/htdocs/install/mysql/tables/llx_accounting_fiscalyear.sql @@ -18,10 +18,14 @@ create table llx_accounting_fiscalyear ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - label varchar(128) NOT NULL, - datestart date, - dateend date, - statut tinyint DEFAULT 0 NOT NULL, - entity integer DEFAULT 1 NOT NULL -- multi company id + 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 DEFAULT NULL, + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL )ENGINE=innodb; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index a10074e0f04..a4ba3d464ab 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1514,9 +1514,15 @@ TaskModelModule=Tasks reports document model ECMSetup = GED Setup ECMAutoTree = Automatic tree folder and document ##### 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 CloseFiscalYear=Close fiscal year +DeleteFiscalYear=Delete fiscal year +ConfirmDeleteFiscalYear=Are you sure to delete this fiscal year ? Opened=Opened Closed=Closed From e294fe1eddc150399c5aacd05ab0d98bddc52cf3 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 5 Jul 2014 21:58:39 +0200 Subject: [PATCH 4/4] Update --- htdocs/core/class/fiscalyear.class.php | 38 ++++---------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 21dfa6f2381..39e72ff7416 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -62,11 +62,12 @@ class Fiscalyear } /** - * Create object in database + * Create object in database * - * @return int <0 if KO, >0 if OK + * @param User $user User making creation + * @return int <0 if KO, >0 if OK */ - function create() + function create($user) { global $conf; @@ -97,35 +98,6 @@ class Fiscalyear dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) - { - $error++; $this->errors[]="Error ".$this->db->lasterror(); - } - - if (! $error) - { - $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return $this->rowid; - } - - dol_syslog(get_class($this)."::create=", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); @@ -133,7 +105,7 @@ class Fiscalyear if ($result > 0) { $this->db->commit(); - return $this->rowid; + return $this->id; } else {