diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 7293797ecc6..ba3c37f1997 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -18,9 +18,9 @@ */ /** - * \file htdocs/accountancy/bookkeeping/card.php - * \ingroup Advanced accountancy - * \brief Page to show book-entry + * \file htdocs/accountancy/bookkeeping/card.php + * \ingroup Advanced accountancy + * \brief Page to show book-entry */ require '../../main.inc.php'; @@ -62,17 +62,17 @@ if (! empty($update)) { } if ($action == "confirm_update") { - + $error = 0; - + if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); $error ++; } - + if (empty($error)) { $book = new BookKeeping($db); - + $result = $book->fetch($id); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -82,7 +82,7 @@ if ($action == "confirm_update") { $book->label_compte = $label_compte; $book->debit = $debit; $book->credit = $credit; - + if (floatval($debit) != 0.0) { $book->montant = $debit; $book->sens = 'D'; @@ -91,7 +91,7 @@ if ($action == "confirm_update") { $book->montant = $credit; $book->sens = 'C'; } - + $result = $book->update($user); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -101,19 +101,19 @@ if ($action == "confirm_update") { } } } -} +} else if ($action == "add") { $error = 0; - + if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); $error ++; } - + if (empty($error)) { $book = new BookKeeping($db); - + $book->numero_compte = $account_number; $book->code_tiers = $code_tiers; $book->label_compte = $label_compte; @@ -126,17 +126,17 @@ else if ($action == "add") { $book->code_journal = GETPOST('code_journal'); $book->fk_doc = GETPOST('fk_doc'); $book->fk_docdet = GETPOST('fk_docdet'); - + if (floatval($debit) != 0.0) { $book->montant = $debit; $book->sens = 'D'; } - + if (floatval($credit) != 0.0) { $book->montant = $credit; $book->sens = 'C'; } - + $result = $book->createStd($user); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -145,15 +145,15 @@ else if ($action == "add") { $action = ''; } } -} +} else if ($action == "confirm_delete") { $book = new BookKeeping($db); - + $result = $book->fetch($id); - + $piece_num = $book->piece_num; - + if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { @@ -163,11 +163,11 @@ else if ($action == "confirm_delete") { } } $action = ''; -} +} else if ($action == "confirm_create") { $book = new BookKeeping($db); - + $book->label_compte = ''; $book->debit = 0; $book->credit = 0; @@ -178,9 +178,9 @@ else if ($action == "confirm_create") { $book->code_journal = GETPOST('code_journal'); $book->fk_doc = 0; $book->fk_docdet = 0; - + $book->montant = 0; - + $result = $book->createStd($user); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -209,15 +209,15 @@ if ($action == 'delete') { if ($action == 'create') { print load_fiche_titre($langs->trans("CreateMvts")); - + $code_journal_array = array ( $conf->global->ACCOUNTING_SELL_JOURNAL => $conf->global->ACCOUNTING_SELL_JOURNAL, $conf->global->ACCOUNTING_PURCHASE_JOURNAL => $conf->global->ACCOUNTING_PURCHASE_JOURNAL, $conf->global->ACCOUNTING_SOCIAL_JOURNAL => $conf->global->ACCOUNTING_SOCIAL_JOURNAL, $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL => $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL, - $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL => $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL + $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL => $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL ); - + $sql = 'SELECT DISTINCT accountancy_journal FROM ' . MAIN_DB_PREFIX . 'bank_account WHERE clos=0'; $resql = $db->query($sql); if (! $resql) { @@ -229,52 +229,52 @@ if ($action == 'create') { } } } - + $book = new BookKeeping($db); $next_num_mvt = $book->getNextNumMvt(); - + print '
'; print '' . "\n"; print '' . "\n"; - + dol_fiche_head(); - + print ''; print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print '
' . $langs->trans("NumMvts") . '' . $next_num_mvt . '
' . $langs->trans("Docdate") . ''; print $html->select_date('', 'doc_date', '', '', '', "create_mvt", 1, 1); print '
' . $langs->trans("Codejournal") . '' . $html->selectarray('code_journal', $code_journal_array) . '
' . $langs->trans("Docref") . '
' . $langs->trans("Doctype") . '
'; - + dol_fiche_end(); - + print '
'; print '     '; print '
'; - + print '
'; } else { $book = new BookKeeping($db); @@ -283,9 +283,9 @@ if ($action == 'create') { setEventMessages($book->error, $book->errors, 'errors'); } if (! empty($book->piece_num)) { - + print load_fiche_titre($langs->trans("UpdateMvts"), '' . $langs->trans('BackToList') . ''); - + print ''; print ''; print ''; @@ -309,14 +309,14 @@ if ($action == 'create') { print ''; print '
' . $langs->trans("NumMvts") . '
'; print '
'; - + $result = $book->fetch_all_per_mvt($piece_num); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - + print load_fiche_titre($langs->trans("ListeMvts")); - + print '
'; print '' . "\n"; print '' . "\n"; @@ -324,15 +324,15 @@ if ($action == 'create') { print '' . "\n"; print '' . "\n"; print '' . "\n"; - + print ""; if (count($book->linesmvt) > 0) { - + $total_debit = 0; $total_credit = 0; - + print ''; - + print_liste_field_titre($langs->trans("AccountAccountingShort")); print_liste_field_titre($langs->trans("Code_tiers")); print_liste_field_titre($langs->trans("Labelcompte")); @@ -341,18 +341,18 @@ if ($action == 'create') { print_liste_field_titre($langs->trans("Amount"), "", "", "", "", 'align="center"'); print_liste_field_titre($langs->trans("Sens"), "", "", "", "", 'align="center"'); print_liste_field_titre($langs->trans("Action"), "", "", "", "", 'width="60" align="center"'); - + print "\n"; - + foreach ( $book->linesmvt as $line ) { $var = ! $var; - print ''; - + print ''; + $total_debit += $line->debit; $total_credit += $line->credit; - + if ($action == 'update' && $line->id == $id) { - + print ''; @@ -376,7 +376,7 @@ if ($action == 'create') { print ''; print ''; print ''; - + print ''; } print "\n"; } - + if ($total_debit != $total_credit) { setEventMessages(null, array ( - 'MvtNotCorrectlyBalanced', - $total_credit, - $total_debit + $langs->trans('MvtNotCorrectlyBalanced', $total_credit, $total_debit) ), 'errors'); } - + if ($action == "" || $action == 'add') { $var = ! $var; - print ''; + print ''; print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index cb5d7caf006..23148213aa0 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -202,14 +202,22 @@ if ($action == 'delbookkeeping') { if ($action == 'delbookkeepingyearconfirm') { $delyear = GETPOST('delyear', 'int'); + if ($delyear==-1) { + $delyear=0; + } + $deljournal = GETPOST('deljournal','alpha'); + if ($deljournal==-1) { + $deljournal=0; + } - if (! empty($delyear)) { - $result = $object->deleteByYear($delyear); + + if (! empty($delyear) || ! empty($deljournal)) { + $result = $object->deleteByYearAndJournal($delyear,$deljournal); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } Header("Location: list.php"); - exit(); + exit; } } if ($action == 'delmouvconfirm') { @@ -222,7 +230,7 @@ if ($action == 'delmouvconfirm') { setEventMessages($object->error, $object->errors, 'errors'); } Header("Location: list.php"); - exit(); + exit; } } if ($action == 'export_csv') { @@ -276,11 +284,13 @@ if ($action == 'delbookkeepingyear') { $form_question = array (); $delyear = GETPOST('delyear'); + $deljournal = GETPOST('deljournal'); if (empty($delyear)) { $delyear = dol_print_date(dol_now(), '%Y'); } $year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); + $journal_array = $formventilation->selectjournal_accountancy_bookkepping($deljournal, 'deljournal', 0, 'array'); $form_question['delyear'] = array ( 'name' => 'delyear', @@ -289,6 +299,13 @@ if ($action == 'delbookkeepingyear') { 'values' => $year_array, 'default' => $delyear ); + $form_question['deljournal'] = array ( + 'name' => 'deljournal', + 'type' => 'select', + 'label' => $langs->trans('DelJournal'), + 'values' => $journal_array, + 'default' => $deljournal + ); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1); print $formconfirm; diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 6f4698413dc..79e66ab7cce 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -54,13 +54,13 @@ class BookKeeping extends CommonObject * @var string Name of table without prefix where object is stored */ public $table_element = 'accounting_bookkeeping'; - + /** * * @var BookKeepingLine[] Lines */ public $lines = array (); - + /** * * @var int ID @@ -84,10 +84,10 @@ class BookKeeping extends CommonObject public $import_key; public $code_journal; public $piece_num; - + /** */ - + /** * Constructor * @@ -97,22 +97,24 @@ class BookKeeping extends CommonObject $this->db = $db; return 1; } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + + global $langs; + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -158,32 +160,32 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + $this->db->begin(); - + $this->piece_num = 0; - + // first check if line not yet in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; + $sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; $sql .= " AND fk_docdet = " . $this->fk_docdet; - $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; - - dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); + $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; + + dol_syslog(get_class($this) . ":: create ", LOG_DEBUG); $resql = $this->db->query($sql); - + if ($resql) { $row = $this->db->fetch_object($resql); if ($row->nb == 0) { - + // Determine piece_num $sqlnum = "SELECT piece_num"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -194,7 +196,7 @@ class BookKeeping extends CommonObject if (empty($this->piece_num)) { $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -202,18 +204,19 @@ class BookKeeping extends CommonObject $this->piece_num = $objnum->maxpiecenum; } } - dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); if (empty($this->piece_num)) { $this->piece_num = 1; } - + + dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); + $now = dol_now(); if (empty($this->date_create)) { $this->date_create = $now; } - + $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; - + $sql .= "doc_date"; $sql .= ", doc_type"; $sql .= ", doc_ref"; @@ -230,33 +233,33 @@ class BookKeeping extends CommonObject $sql .= ", import_key"; $sql .= ", code_journal"; $sql .= ", piece_num"; - + $sql .= ") VALUES ("; - - $sql .= "'" . $this->doc_date . "'"; - $sql .= ",'" . $this->doc_type . "'"; - $sql .= ",'" . $this->doc_ref . "'"; + + $sql .= "'" . $this->db->idate($this->doc_date) . "'"; + $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; + $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; $sql .= "," . $this->fk_doc; $sql .= "," . $this->fk_docdet; - $sql .= ",'" . $this->code_tiers . "'"; - $sql .= ",'" . $this->numero_compte . "'"; + $sql .= ",'" . $this->db->escape($this->code_tiers) . "'"; + $sql .= ",'" . $this->db->escape($this->numero_compte) . "'"; $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; $sql .= "," . $this->debit; $sql .= "," . $this->credit; $sql .= "," . $this->montant; - $sql .= ",'" . $this->sens . "'"; + $sql .= ",'" . $this->db->escape($this->sens) . "'"; $sql .= ",'" . $this->fk_user_author . "'"; $sql .= ",'" . $this->date_create . "'"; - $sql .= ",'" . $this->code_journal . "'"; + $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; $sql .= "," . $this->piece_num; - + $sql .= ")"; - - dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); + + dol_syslog(get_class($this) . ":: create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if ($id > 0) { $this->id = $id; $result = 0; @@ -264,67 +267,67 @@ class BookKeeping extends CommonObject $result = - 2; $error ++; $this->errors[] = 'Error Create Error ' . $result . ' lecture ID'; - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); } } else { $result = - 1; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); } } else { $result = - 3; $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + $this->errors[] = $langs->trans('BookeppingLineAlreayExists'); + dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); } } else { $result = - 5; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' $result='.$result.' '. implode(',', $this->errors), LOG_ERR); } - + if (! $error) { - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $result; } } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function createStd(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -370,13 +373,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add control on parameters values - + // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql .= 'doc_date,'; $sql .= 'doc_type,'; $sql .= 'doc_ref,'; @@ -393,9 +396,9 @@ class BookKeeping extends CommonObject $sql .= 'import_key,'; $sql .= 'code_journal,'; $sql .= 'piece_num'; - + $sql .= ') VALUES ('; - + $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; @@ -412,58 +415,58 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; $sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num); - + $sql .= ')'; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $this->id; } } - + /** * Load object in memory from the database * * @param int $id Id object * @param string $ref Ref - * + * * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = null) { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -480,22 +483,22 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; } else { $sql .= ' WHERE t.rowid = ' . $id; } - + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); if ($numrows) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; - + $this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_type = $obj->doc_type; $this->doc_ref = $obj->doc_ref; @@ -514,7 +517,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; } $this->db->free($resql); - + if ($numrows) { return 1; } else { @@ -523,11 +526,11 @@ class BookKeeping extends CommonObject } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Load object in memory from the database * @@ -537,15 +540,15 @@ class BookKeeping extends CommonObject * @param int $offset offset limit * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) - * + * * @return int <0 if KO, >0 if OK */ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -562,9 +565,9 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -584,11 +587,11 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -596,16 +599,16 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -622,20 +625,20 @@ class BookKeeping extends CommonObject $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Load object in memory from the database * @@ -650,15 +653,15 @@ class BookKeeping extends CommonObject */ public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= " t.numero_compte,"; $sql .= " SUM(t.debit) as debit,"; $sql .= " SUM(t.credit) as credit"; - - + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -678,13 +681,13 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + $sql .= ' GROUP BY t.numero_compte'; - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -692,45 +695,45 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->numero_compte = $obj->numero_compte; $line->debit = $obj->debit; $line->credit = $obj->credit; $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Update object into database * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function update(User $user, $notrigger = false) { $error = 0; - + dol_syslog(__METHOD__, LOG_DEBUG); - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -776,13 +779,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add a control on parameters values - + // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - + $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ','; $sql .= ' doc_type = ' . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ','; $sql .= ' doc_ref = ' . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ','; @@ -799,71 +802,71 @@ class BookKeeping extends CommonObject $sql .= ' import_key = ' . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ','; $sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ','; $sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null"); - + $sql .= ' WHERE rowid=' . $this->id; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error && ! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_MODIFY',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete object in database * * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + $this->db->begin(); - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_DELETE',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } } - + if (! $error) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; - + $resql = $this->db->query($sql); if (! $resql) { $error ++; @@ -871,19 +874,19 @@ class BookKeeping extends CommonObject dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete bookkepping by importkey * @@ -892,14 +895,14 @@ class BookKeeping extends CommonObject */ function deleteByImportkey($importkey) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE import_key = '" . $importkey . "'"; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -909,11 +912,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by year * @@ -922,14 +925,14 @@ class BookKeeping extends CommonObject */ function deleteByYear($delyear) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE YEAR(doc_date) = " . $delyear; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -939,11 +942,54 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + + /** + * Delete bookkepping by year + * + * @param string $delyear year to delete + * @param string $deljournal journal to delete + * @return int Result + */ + function deleteByYearAndJournal($delyear,$deljournal) { + $this->db->begin(); + + $sqlwhere=array(); + + // first check if line not yet in bookkeeping + $sql = "DELETE"; + $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; + if (!empty($delyear)) { + $sqlwhere[] .= " YEAR(doc_date) = " . $delyear; + } + if (!empty($deljournal)) { + $sqlwhere[] .= " code_journal = '" . $this->db->escape($deljournal)."'"; + } + + if (count($sqlwhere)>0) { + $sql.=" WHERE ".implode(' AND ', $sqlwhere); + + $resql = $this->db->query($sql); + + if (! $resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + $this->db->rollback(); + return - 1; + } + + $this->db->commit(); + + } + return 1; + } + /** * Delete bookkepping by piece number * @@ -952,14 +998,14 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -969,57 +1015,57 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone - * + * * @return int New id of clone */ public function createFromClone($fromid) { dol_syslog(__METHOD__, LOG_DEBUG); - + global $user; $error = 0; $object = new Accountingbookkeeping($this->db); - + $this->db->begin(); - + // Load source object $object->fetch($fromid); // Reset object $object->id = 0; - + // Clear fields // ... - + // Create clone $result = $object->create($user); - + // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + // End if (! $error) { $this->db->commit(); - + return $object->id; } else { $this->db->rollback(); - + return - 1; } } - + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -1028,7 +1074,7 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { $this->id = 0; - + $this->doc_date = ''; $this->doc_type = ''; $this->doc_ref = ''; @@ -1046,7 +1092,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1057,12 +1103,12 @@ class BookKeeping extends CommonObject $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - + $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; $this->doc_date = $this->db->jdate($obj->doc_date); @@ -1073,10 +1119,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * @@ -1084,13 +1130,13 @@ class BookKeeping extends CommonObject */ public function getNextNumMvt() { $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); - + if ($result) { $obj = $this->db->fetch_object($result); - + return $obj->max; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1098,7 +1144,7 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Load all informations of accountancy document * @@ -1112,17 +1158,17 @@ class BookKeeping extends CommonObject $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - + while ( $obj = $this->db->fetch_object($result) ) { - + $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1137,7 +1183,7 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesmvt[] = $line; } } else { @@ -1145,10 +1191,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1161,20 +1207,20 @@ class BookKeeping extends CommonObject $sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); - + $resql = $this->db->query($sql); - + if ($resql) { $this->linesexport = array (); - + $num = $this->db->num_rows($resql); while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1189,11 +1235,11 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesexport[] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1201,15 +1247,15 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Description of accounting account * * @param string $account Accounting account - * @return string + * @return string */ function get_compte_desc($account = null) - { + { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; @@ -1226,14 +1272,14 @@ class BookKeeping extends CommonObject if ($resql) { $obj = ''; if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); } - - if(empty($obj->category)){ + + if(empty($obj->category)){ return $obj->label; }else{ return $obj->label.' ('.$obj->category.')'; - + } } else { $this->error = "Error " . $this->db->lasterror(); @@ -1242,7 +1288,7 @@ class BookKeeping extends CommonObject return -1; } } - + } /** diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index e3ae592a47f..9294cf7f6a8 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -58,7 +58,7 @@ class FormVentilation extends Form return Form::selectarray($htmlname, $options, $selectedkey); } - + /** * Return list of accounts with label by chart of accounts * @@ -69,23 +69,23 @@ class FormVentilation extends Form * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1) * @param int $select_out set value returned by select 0=rowid (default), 1=account_number * @param int $aabase set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number - * + * * @return string String with HTML select */ function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') { global $conf; - + require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50; - + $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " AND aa.active = 1"; $sql .= " ORDER BY aa.account_number"; - + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); $resql = $this->db->query($sql); @@ -127,7 +127,7 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } - + /** * Return list of accounts with label by class of accounts * @@ -135,18 +135,18 @@ class FormVentilation extends Form * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options - * + * * @return string String with HTML select */ function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) { global $conf; - + $sql = "SELECT DISTINCT pcg_type "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_type"; - + dol_syslog(get_class($this) . "::select_pcgtype", LOG_DEBUG); $resql = $this->db->query($sql); @@ -168,7 +168,7 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } - + /** * Return list of accounts with label by sub_class of accounts * @@ -176,18 +176,18 @@ class FormVentilation extends Form * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options - * + * * @return string String with HTML select */ function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) { global $conf; - + $sql = "SELECT DISTINCT pcg_subtype "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_subtype"; - + dol_syslog(get_class($this) . "::select_pcgsubtype", LOG_DEBUG); $resql = $this->db->query($sql); @@ -209,7 +209,7 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } - + /** * Return list of auxilary thirdparty accounts * @@ -217,7 +217,7 @@ class FormVentilation extends Form * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options - * + * * @return string String with HTML select */ function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) { @@ -246,7 +246,7 @@ class FormVentilation extends Form // Auxiliary supplier account $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; $sql .= " FROM ".MAIN_DB_PREFIX."societe"; - $sql .= " ORDER BY code_compta"; + $sql .= " ORDER BY code_compta_fournisseur"; dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -268,7 +268,7 @@ class FormVentilation extends Form return $out; } - + /** * Return HTML combo list of years existing into book keepping * @@ -284,7 +284,7 @@ class FormVentilation extends Form $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; - $sql .= " ORDER BY doc_date"; + $sql .= " ORDER BY date_format(doc_date,'%Y')"; dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); @@ -304,4 +304,40 @@ class FormVentilation extends Form return $out_array; } } + + /** + * Return HTML combo list of years existing into book keepping + * + * @param string $selected Preselected value + * @param string $htmlname Name of HTML select object + * @param int $useempty Affiche valeur vide dans liste + * @param string $output_format (html/opton (for option html only)/array (to return options arrays + * @return string/array + */ + function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html') + { + $out_array = array(); + + $sql = "SELECT DISTINCT code_journal"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " ORDER BY code_journal"; + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + + if (!$resql) { + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); + return -1; + } + while ($obj = $this->db->fetch_object($resql)) { + $out_array[$obj->code_journal] = $obj->code_journal; + } + $this->db->free($resql); + + if ($output_format == 'html') { + return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"'); + } else { + return $out_array; + } + } } diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 5ca1197b3e2..f66293b6185 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -138,7 +138,7 @@ if ($result) { //Define array for display vat tx $def_tva[$obj->rowid]=price($obj->tva_tx); - $tabfac[$obj->rowid]["date"] = $obj->df; + $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier . ' (' . $obj->ref . ')'; $tabfac[$obj->rowid]["refsologest"] = $obj->ref; $tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier; @@ -193,7 +193,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->code_tiers = $tabcompany[$key]['code_fournisseur']; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers"); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers"); $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D'; @@ -225,7 +225,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->code_tiers = ''; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . utf8_decode($accountingaccount->label); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $accountingaccount->label; $bookkeeping->numero_compte = $k; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; @@ -256,7 +256,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->code_tiers = ''; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]; + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]; $bookkeeping->numero_compte = $k; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; @@ -297,7 +297,7 @@ if ($action == 'export_csv') { $sep = ";"; foreach ( $tabfac as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); + $date = dol_print_date($val["date"], '%d%m%Y'); // Product / Service foreach ( $tabht[$key] as $k => $mt ) { @@ -340,7 +340,7 @@ if ($action == 'export_csv') { print length_accounta(html_entity_decode($k)) . $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode($companystatic->name) . $sep; + print $companystatic->name . $sep; print $val["ref"]; print "\n"; } @@ -356,7 +356,7 @@ if ($action == 'export_csv') { $invoicestatic->type = $val["type"]; $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32)); - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; @@ -370,7 +370,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . utf8_decode(dol_trunc($accountingaccount->label, 32)) . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; // print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; @@ -384,7 +384,7 @@ if ($action == 'export_csv') { print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; // print '"' . $langs->trans("VAT") . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; print "\n"; @@ -396,8 +396,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - // print '"' . utf8_decode($companystatic->name) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; } @@ -479,7 +478,7 @@ if ($action == 'export_csv') { $invoicestatic->type = $val["type"]; $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32)); - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); // Product / Service foreach ( $tabht[$key] as $k => $mt ) { diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 5da210ca09a..1f21788bc30 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -161,7 +161,7 @@ if ($result) { } // Invoice lines - $tabfac[$obj->rowid]["date"] = $obj->df; + $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); $tabfac[$obj->rowid]["ref"] = $obj->facnumber; $tabfac[$obj->rowid]["type"] = $obj->type; $tabfac[$obj->rowid]["description"] = $obj->label_compte; @@ -220,7 +220,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->code_tiers = $tabcompany[$key]['code_client']; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; // $bookkeeping->label_compte = $tabcompany[$key]['name']; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"); $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt >= 0) ? $mt : 0; @@ -250,7 +250,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . utf8_decode($accountingaccount->label); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0) ? $mt : 0; @@ -280,7 +280,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key]; + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key]; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0) ? $mt : 0; @@ -324,7 +324,7 @@ if ($action == 'export_csv') { $invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; - $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); + $date = dol_print_date($val["date"], '%d%m%Y'); foreach ( $tabttc[$key] as $k => $mt ) { print $date . $sep; @@ -333,8 +333,7 @@ if ($action == 'export_csv') { print length_accounta(html_entity_decode($k)) . $sep; print ($mt < 0 ? 'C' : 'D') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep; - // print utf8_decode($companystatic->name) . $sep; + print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep; print $val["ref"]; print "\n"; } @@ -349,8 +348,7 @@ if ($action == 'export_csv') { print $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . utf8_decode(utf8_decode($accountingaccount_static->label)) . $sep; - // print dol_trunc($accountingaccount_static->label, 32) . $sep; + print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep; print $val["ref"]; print "\n"; } @@ -365,7 +363,7 @@ if ($action == 'export_csv') { print $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep; + print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep; // print $langs->trans("VAT") . $sep; print $val["ref"]; print "\n"; @@ -382,14 +380,13 @@ if ($action == 'export_csv') { $invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); foreach ( $tabttc[$key] as $k => $mt ) { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; - // print '"' . utf8_decode($companystatic->name) . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; print "\n"; @@ -404,8 +401,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . utf8_decode(dol_trunc($accountingaccount->label, 32)) . '"' . $sep; - // print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; print "\n"; @@ -418,8 +414,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep; - // print '"' . $langs->trans("VAT") . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; print "\n"; @@ -497,7 +492,7 @@ if ($action == 'export_csv') { $invoicestatic->ref = $val["ref"]; $invoicestatic->type = $val["type"]; - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); // Third party foreach ( $tabttc[$key] as $k => $mt ) { @@ -527,7 +522,7 @@ if ($action == 'export_csv') { print ""; print ""; // print ""; - print ""; + print ""; print ""; print ""; print ""; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 18742ba0ed7..433d5a0178d 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -84,6 +84,11 @@ AccountingCategory=Accounting category NotMatch=Not Set +DeleteMvt=Delete general ledger lines +DelYear=Year to delete +DelJournal=Journal to delete +ConfirmDeleteMvt=This will delete all line of of the general ledger for year and/or from a specifics journal + DelBookKeeping=Delete the records of the general ledger DescSellsJournal=Sales journal @@ -160,3 +165,4 @@ Formula=Formula ## Error ErrorNoAccountingCategoryForThisCountry=No accounting category are available for this country ExportNotSupported=The export format setuped is not supported into this page +BookeppingLineAlreayExists=Lines already existing into bookeeping
'; print $formventilation->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, ''); print '' . price($line->credit) . '' . price($line->montant) . '' . $line->sens . ''; print ''; print img_edit(); @@ -384,23 +384,21 @@ if ($action == 'create') { print ''; print img_delete(); print ''; - + print '
'; print $formventilation->select_account($account_number, 'account_number', 0, array (), 1, 1, ''); print '" . $invoicestatic->getNomUrl(1) . "" . length_accountg($k) . "" . $accountingaccount->label . "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . utf8_decode(utf8_decode($accountingaccount->label)) . "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label . "" . ($mt < 0 ? price(- $mt) : '') . "" . ($mt >= 0 ? price($mt) : '') . "