diff --git a/htdocs/accountancy/admin/journals_card.php b/htdocs/accountancy/admin/journals_card.php index c9c45f9a4e5..9e04d75ce9f 100644 --- a/htdocs/accountancy/admin/journals_card.php +++ b/htdocs/accountancy/admin/journals_card.php @@ -122,6 +122,15 @@ else if ($action == 'update') { $object->label = GETPOST('label', 'alpha'); $object->nature = GETPOST('nature', 'int'); + if (empty($object->code)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Code")), null, 'errors'); + $error ++; + } + if (empty($object->label)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + $error ++; + } + $result = $object->update($user); if ($result > 0) { @@ -161,15 +170,15 @@ if ($action == 'create') print ''; // Code - print ''; + print ''; // Label - print ''; + print ''; // Nature print ''; - print ''; + print ''; print ''; @@ -188,10 +197,10 @@ if ($action == 'create') } else if ($id) { $result = $object->fetch($id); if ($result > 0) { - $head = fiscalyear_prepare_head($object); + $head = accounting_journal_prepare_head($object); if ($action == 'edit') { - dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron'); + dol_fiche_head($head, 'card', $langs->trans("AccountingJournal"), 0, 'cron'); print '' . "\n"; print ''; @@ -200,10 +209,10 @@ if ($action == 'create') print '
' . $langs->trans("Code") . '
' . $langs->trans("Code") . '
' . $langs->trans("Label") . '
' . $langs->trans("Label") . '
' . $langs->trans("Status") . '' . $langs->trans("Type") . ''; print $form->selectarray('nature', $type2label, GETPOST('nature')); print '
'; - // Ref + // Code print ""; - print ''; // Label @@ -211,20 +220,9 @@ if ($action == 'create') print ''; print ''; - // Date start - print ''; - - // Date end - print ''; - // Nature print ''; print '
' . $langs->trans("Ref") . ''; - print $object->ref; + print '' . $langs->trans("Code") . ''; + print ''; print '
' . $langs->trans("DateStart") . ''; - print $form->select_date($object->date_start ? $object->date_start : - 1, 'fiscalyear'); - print '
' . $langs->trans("DateEnd") . ''; - print $form->select_date($object->date_end ? $object->date_end : - 1, 'fiscalyearend'); - print '
' . $langs->trans("Type") . ''; - // print $form->selectarray('statut', $statut2label, $object->statut); - print $object->getLibStatut(4); + print $form->selectarray('nature', $type2label, $object->nature); print '
'; @@ -246,15 +244,15 @@ if ($action == 'create') print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete"); } - dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron'); + dol_fiche_head($head, 'card', $langs->trans("AccountingJournal"), 0, 'cron'); print ''; - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = '' . $langs->trans("BackToList") . ''; // Ref - print ''; @@ -267,7 +265,7 @@ if ($action == 'create') print ""; // Nature - print ''; + print ''; print "
' . $langs->trans("Ref") . ''; - print $object->ref; + print '
' . $langs->trans("Code") . ''; + print $object->code; print ''; print $linkback; print '
' . $langs->trans("Type") . '' . $object->getLibType(0) . '
' . $langs->trans("Type") . '' . $object->getLibType(0) . '
"; @@ -281,9 +279,9 @@ if ($action == 'create') print '
'; print '' . $langs->trans('Modify') . ''; - - // print '' . $langs->trans('Delete') . ''; - + + print '' . $langs->trans('Delete') . ''; + print '
'; } } diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index 7b34c4171d8..d7cc61d6418 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -26,24 +26,18 @@ */ class AccountingJournal extends CommonObject { - var $db; - var $error; - var $errors; - var $id; + public $element='accounting_journal'; + public $table_element='accounting_journal'; + public $fk_element = ''; + protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + var $rowid; - var $datec; // Creation date - var $fk_pcg_version; - var $pcg_type; - var $pcg_subtype; - var $account_number; - var $account_parent; - var $account_category; + + var $code; var $label; - var $fk_user_author; - var $fk_user_modif; - var $active; // duplicate with status - var $status; - + var $nature; // 0:various operations, 1:sale, 2:purchase, 3:bank, 9: has-new + var $active; + /** * Constructor * @@ -54,133 +48,75 @@ class AccountingJournal extends CommonObject } /** - * Load record in memory - * - * @param int $rowid Id - * @param string $account_number Account number - * @param int $limittocurrentchart 1=Do not load record if it is into another accounting system - * @return int <0 if KO, Id of record if OK and found - */ - function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0) { - global $conf; - - if ($rowid || $account_number) { - $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; - $sql .= ", ca.label as category_label"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; - $sql .= " WHERE"; - if ($rowid) { - $sql .= " a.rowid = '" . $rowid . "'"; - } elseif ($account_number) { - $sql .= " a.account_number = '" . $account_number . "'"; - } - if (! empty($limittocurrentchart)) { - $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - } + * 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, code, label, nature, active"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; + $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); - - if ($obj) { - $this->id = $obj->rowid; - $this->rowid = $obj->rowid; - $this->datec = $obj->datec; - $this->tms = $obj->tms; - $this->fk_pcg_version = $obj->fk_pcg_version; - $this->pcg_type = $obj->pcg_type; - $this->pcg_subtype = $obj->pcg_subtype; - $this->account_number = $obj->account_number; - $this->account_parent = $obj->account_parent; - $this->label = $obj->label; - $this->account_category = $obj->fk_accounting_category; - $this->account_category_label = $obj->category_label; - $this->fk_user_author = $obj->fk_user_author; - $this->fk_user_modif = $obj->fk_user_modif; - $this->active = $obj->active; - $this->status = $obj->active; - - return $this->id; - } else { - return 0; - } - } else { - $this->error = "Error " . $this->db->lasterror(); - $this->errors[] = "Error " . $this->db->lasterror(); - } + 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->code = $obj->code; + $this->ref = $obj->code; + $this->label = $obj->label; + $this->nature = $obj->nature; + $this->active = $obj->active; + + return 1; + } + else + { + $this->error=$this->db->lasterror(); + return -1; } - return - 1; } /** - * Insert new accounting account in chart of accounts + * Insert journal in database * - * @param User $user Use making action - * @param int $notrigger Disable triggers - * @return int <0 if KO, >0 if OK + * @param User $user Use making action + * @param int $notrigger Disable triggers + * @return int <0 if KO, >0 if OK */ - function create($user, $notrigger = 0) { + function create($user, $notrigger = 0) + { global $conf; $error = 0; $now = dol_now(); // Clean parameters - if (isset($this->fk_pcg_version)) - $this->fk_pcg_version = trim($this->fk_pcg_version); - if (isset($this->pcg_type)) - $this->pcg_type = trim($this->pcg_type); - if (isset($this->pcg_subtype)) - $this->pcg_subtype = trim($this->pcg_subtype); - if (isset($this->account_number)) - $this->account_number = trim($this->account_number); - if (isset($this->account_parent)) - $this->account_parent = trim($this->account_parent); + if (isset($this->code)) + $this->code = trim($this->code); if (isset($this->label)) $this->label = trim($this->label); - if (isset($this->account_category)) - $this->account_category = trim($this->account_category); - if (isset($this->fk_user_author)) - $this->fk_user_author = trim($this->fk_user_author); - if (isset($this->active)) - $this->active = trim($this->active); - - if (empty($this->pcg_type) || $this->pcg_type == '-1') - { - $this->pcg_type = 'XXXXXX'; - } - if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') - { - $this->pcg_subtype = 'XXXXXX'; - } + // Check parameters - // Put here code to add control on parameters values - + if (empty($this->nature) || $this->nature == '-1') + { + $this->nature = '0'; + } + // Insert request - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account("; - $sql .= "datec"; - $sql .= ", entity"; - $sql .= ", fk_pcg_version"; - $sql .= ", pcg_type"; - $sql .= ", pcg_subtype"; - $sql .= ", account_number"; - $sql .= ", account_parent"; + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_journal("; + $sql .= "code"; $sql .= ", label"; - $sql .= ", fk_accounting_category"; - $sql .= ", fk_user_author"; + $sql .= ", nature"; $sql .= ", active"; $sql .= ") VALUES ("; - $sql .= " '" . $this->db->idate($now) . "'"; - $sql .= ", " . $conf->entity; - $sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'"); - $sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'"); - $sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->pcg_subtype . "'"); - $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->account_number . "'"); - $sql .= ", " . (empty($this->account_parent) ? 'NULL' : "'" . $this->db->escape($this->account_parent) . "'"); + $sql .= " " . (empty($this->code) ? 'NULL' : "'" . $this->db->escape($this->code) . "'"); $sql .= ", " . (empty($this->label) ? 'NULL' : "'" . $this->db->escape($this->label) . "'"); - $sql .= ", " . (empty($this->account_category) ? 'NULL' : "'" . $this->db->escape($this->account_category) . "'"); - $sql .= ", " . $user->id; + $sql .= ", " . (empty($this->nature) ? '0' : "'" . $this->db->escape($this->nature) . "'"); $sql .= ", " . (! isset($this->active) ? 'NULL' : $this->db->escape($this->active)); $sql .= ")"; @@ -194,7 +130,7 @@ class AccountingJournal extends CommonObject } if (! $error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_journal"); // if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -232,26 +168,17 @@ class AccountingJournal extends CommonObject function update($user) { // Check parameters - if (empty($this->pcg_type) || $this->pcg_type == '-1') + if (empty($this->nature) || $this->nature == '-1') { - $this->pcg_type = 'XXXXXX'; + $this->nature = '0'; } - if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') - { - $this->pcg_subtype = 'XXXXXX'; - } - + $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; - $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); - $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); - $sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null"); - $sql .= " , account_number = '" . $this->account_number . "'"; - $sql .= " , account_parent = '" . $this->account_parent . "'"; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_journal "; + $sql .= " SET code = " . ($this->code ? "'" . $this->db->escape($this->code) . "'" : "null"); $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "null"); - $sql .= " , fk_accounting_category = '" . $this->account_category . "'"; - $sql .= " , fk_user_modif = " . $user->id; + $sql .= " , nature = " . ($this->nature ? "'" . $this->db->escape($this->nature) . "'" : "0"); $sql .= " , active = '" . $this->active . "'"; $sql .= " WHERE rowid = " . $this->id; @@ -268,7 +195,7 @@ class AccountingJournal extends CommonObject } /** - * Check usage of accounting code + * Check usage of accounting journal * * @return int <0 if KO, >0 if OK */ @@ -287,7 +214,7 @@ class AccountingJournal extends CommonObject if ($resql) { $num = $this->db->num_rows($resql); if ($num > 0) { - $this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse'); + $this->error = $langs->trans('ErrorAccountingJournalIsAlreadyUse'); return 0; } else { return 1; @@ -329,7 +256,7 @@ class AccountingJournal extends CommonObject // } if (! $error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account"; + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_journal"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql); @@ -360,85 +287,47 @@ class AccountingJournal extends CommonObject /** * Return clicable name (with picto eventually) * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @return string Chaine avec URL + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @return string Chaine avec URL */ function getNomUrl($withpicto = 0) { global $langs; $result = ''; - $link = ''; + $link = ''; $linkend = ''; $picto = 'billr'; - $label = $langs->trans("Show") . ': ' . $this->account_number . ' - ' . $this->label; + $label = $langs->trans("Show") . ': ' . $this->code . ' - ' . $this->label; if ($withpicto) $result .= ($link . img_object($label, $picto) . $linkend); if ($withpicto && $withpicto != 2) $result .= ' '; if ($withpicto != 2) - require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - $result .= $link . length_accountg($this->account_number) . ' - ' . $this->label . $linkend; + $result .= $link . $this->code . ' - ' . $this->label . $linkend; return $result; } /** - * Information on record - * - * @param int $id of record - * @return void - */ - function info($id) { - $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a'; - $sql .= ' WHERE a.rowid = ' . $id; - - dol_syslog(get_class($this) . '::info sql=' . $sql); - $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); - } - } - - /** - * Account desactivate + * Deactivate journal * * @param int $id Id * @return int <0 if KO, >0 if OK */ - function account_desactivate($id) { + function journal_deactivate($id) { $result = $this->checkUsage(); if ($result > 0) { $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_journal "; $sql .= "SET active = '0'"; $sql .= " WHERE rowid = " . $this->db->escape($id); - dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::deactivate sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -455,15 +344,15 @@ class AccountingJournal extends CommonObject } /** - * Account activate + * Activate journal * * @param int $id Id * @return int <0 if KO, >0 if OK */ - function account_activate($id) { + function journal_activate($id) { $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_journal "; $sql .= "SET active = '1'"; $sql .= " WHERE rowid = " . $this->db->escape($id); diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 205acb9ba80..56fdc8e6de9 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -91,6 +91,35 @@ function accounting_prepare_head(AccountingAccount $object) return $head; } +/** + * Prepare array with list of tabs + * + * @param AccountingAccount $object Accounting account + * @return array Array of tabs to show + */ +function accounting_journal_prepare_head(AccountingJournal $object) +{ + global $langs, $conf; + + $h = 0; + $head = array (); + + $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journals_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, 'accounting_journal'); + + complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_journal', 'remove'); + + return $head; +} + /** * Return accounting account without zero on the right * diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index f35b61055ad..42c5c519d2c 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -199,13 +199,17 @@ ApplyMassCategories=Apply mass categories AddAccountFromBookKeepingWithNoCategories=Add acccount already used with no categories CategoryDeleted=Category for the accounting account has been removed AccountingJournals=Accounting journals +AccountingJournal=Accounting journal NewAccountingJournal=New accounting journal ShowAccoutingJournal=Show accounting journal +Code=Code +Nature=Nature AccountingJournalTypeVariousOperation=Various operation AccountingJournalTypeSale=Sale AccountingJournalTypePurchase=Purchase AccountingJournalTypeBank=Bank AccountingJournalTypeHasNew=Has-new +ErrorAccountingJournalIsAlreadyUse=This journal is already use ## Export Exports=Exports