diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 85fccbc543b..754dd262369 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -190,14 +190,14 @@ class BookKeeping extends CommonObject if ($resql) { $row = $this->db->fetch_object($resql); - if ($row->nb == 0) { - + 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 . "'"; + $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; // For example doc_type = 'bank' + $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ... + $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; // ref of source object $sqlnum .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); @@ -276,13 +276,13 @@ class BookKeeping extends CommonObject $this->id = $id; $result = 0; } else { - $result = - 2; + $result = -2; $error ++; $this->errors[] = 'Error Create Error ' . $result . ' lecture ID'; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { - $result = - 1; + $result = -1; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); @@ -290,11 +290,11 @@ class BookKeeping extends CommonObject } else { // Already exists $result = -3; $error++; - $this->errors[] = 'Error Transaction for ('.$this->doc_type.', '.$this->doc_ref.', '.$this->fk_docdet.') were already recorded'; - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_WARNING); + $this->error='BookkeepingRecordAlreadyExists'; + dol_syslog(__METHOD__ . ' ' . $this->error, LOG_WARNING); } } else { - $result = - 5; + $result = -5; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); @@ -316,11 +316,9 @@ class BookKeeping extends CommonObject // Commit or rollback if ($error) { $this->db->rollback(); - - return - 1 * $error; + return -1 * $error; } else { $this->db->commit(); - return $result; } } diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index 2c538e7a627..376e5b00d56 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -30,10 +30,10 @@ */ class FormVentilation extends Form { - + private $options_cache = array(); - - + + /** * Return select filter with date of transaction * @@ -87,21 +87,22 @@ class FormVentilation extends Form if ($usecache && ! empty($this->options_cache[$usecache])) { $options = $this->options_cache[$usecache]; + $selected=$selectid; } else { $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); - + if (!$resql) { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); @@ -109,16 +110,16 @@ class FormVentilation extends Form } $out = ajax_combobox($htmlname, $event); - + $selected = 0; - while ($obj = $this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { $label = length_accountg($obj->account_number) . ' - ' . $obj->label; $label = dol_trunc($label, $trunclength); - + $select_value_in = $obj->rowid; $select_value_out = $obj->rowid; - + // Try to guess if we have found default value if ($select_in == 1) { $select_value_in = $obj->account_number; @@ -132,19 +133,19 @@ class FormVentilation extends Form //var_dump("Found ".$selectid." ".$select_value_in); $selected = $select_value_out; } - + $options[$select_value_out] = $label; } $this->db->free($resql); - + if ($usecache) { $this->options_cache[$usecache] = $options; } } - + $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1); - + return $out; } @@ -303,7 +304,7 @@ class FormVentilation extends Form function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html') { global $conf; - + $out_array = array(); $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear"; @@ -342,7 +343,7 @@ class FormVentilation extends Form function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html') { global $conf,$langs; - + $out_array = array(); $sql = "SELECT DISTINCT code_journal"; diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 1db3189e69f..4aab9a09fcc 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -153,7 +153,8 @@ if ($result) { // one line for bank jounral = tabbq // one line for thirdparty journal = tabtp $i = 0; - while ( $i < $num ) { + while ( $i < $num ) + { $obj = $db->fetch_object($result); // Set accountancy code (for bank and thirdparty) @@ -314,7 +315,8 @@ if (! $error && $action == 'writebookkeeping') { if (! $errorforline) { // Line into bank account - foreach ( $tabbq[$key] as $k => $mt ) { + foreach ( $tabbq[$key] as $k => $mt ) + { $bookkeeping = new BookKeeping($db); $bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_ref = $val["ref"]; @@ -363,9 +365,18 @@ if (! $error && $action == 'writebookkeeping') { $result = $bookkeeping->create($user); if ($result < 0) { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } } } } @@ -463,16 +474,6 @@ if (! $error && $action == 'writebookkeeping') { $action = ''; } - - - -/* - * View - */ - -$form = new Form($db); - - // Export if ($action == 'export_csv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; @@ -633,6 +634,15 @@ if ($action == 'export_csv') { } } + + + +/* + * View + */ + +$form = new Form($db); + if (empty($action) || $action == 'view') { $invoicestatic = new Facture($db); $invoicesupplierstatic = new FactureFournisseur($db); @@ -689,7 +699,8 @@ if (empty($action) || $action == 'view') { print "
| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ||
| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ||
| '.$langs->trans("TotalSizeOfAttachedFiles").' | '.$totalsize.' '.$langs->trans("bytes").' | ||
| '.$langs->trans('Discount').' | '; + if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$object->thirdparty->getAvailableDiscounts(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print ' | ||
| '.$langs->trans("Ref").' | '; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); - print " | ||
| ".$langs->trans("Customer")." | "; - print ''.$object->thirdparty->getNomUrl(1).' | ||
| '.$langs->trans('Discount').' | '; - if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$object->thirdparty->getAvailableDiscounts(); - print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; - print ' | ||
| '; + print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,0); + print ' | '; + print $form->editfieldval("Date",'date_contrat',$object->date_contrat,$object,0,'datehourpicker'); + print ' | '; + print '||
| '.$langs->trans('Ref').' | '.$form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '').' | ||
| '.$langs->trans("Customer").' | '; - print ''.$object->thirdparty->getNomUrl(1).' | ||
| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ||
| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ||
| '.$langs->trans("TotalSizeOfAttachedFiles").' | '.$totalsize.' '.$langs->trans("bytes").' | ||
| '; -dol_print_object_info($contrat); +dol_print_object_info($object); print ' |
| '.$langs->trans('Ref').' | '.$form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '').' | ||||
| '.$langs->trans("Customer").' | '; - print ''.$object->thirdparty->getNomUrl(1).' | ||||
| '.$langs->trans('Discount').' | '; - if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$object->thirdparty->getAvailableDiscounts(); - print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; - print ' | ||||
| '.$langs->trans('Discount').' | '; + if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$object->thirdparty->getAvailableDiscounts(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print ' | ||
| '; + print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,0); + print ' | '; + print $form->editfieldval("Date",'date_contrat',$object->date_contrat,$object,0,'datehourpicker'); + print ' | '; + print '||
| '.$langs->trans("Ref").' | '; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); - print " | ||
| ".$langs->trans("Company")." | "; - print ''.$object->thirdparty->getNomUrl(1).' | ||
| '.$langs->trans("Ref").' | '; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); - print ' | ||
| ".$langs->trans("Company")." | ".$object->thirdparty->getNomUrl(1)." | ||
| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ||
| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' | ||
| '.$langs->trans("TotalSizeOfAttachedFiles").' | '.$totalsize.' '.$langs->trans("bytes").' | ||
| '; dol_print_object_info($object); @@ -65,5 +118,7 @@ print ' |
| '.$langs->trans('Ref').' | '; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); - print ' |
| '.$langs->trans('Company').' | '.$societe->getNomUrl(1).' |