Skip to content

Commit

Permalink
Maxi debug of accountancy expert module
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 4, 2016
1 parent 1e3038d commit 31ce725
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 183 deletions.
7 changes: 6 additions & 1 deletion htdocs/accountancy/bookkeeping/list.php
Expand Up @@ -210,11 +210,16 @@
$deljournal=0;
}

if (! empty($delyear) || ! empty($deljournal)) {
if (! empty($delyear) || ! empty($deljournal))
{
$result = $object->deleteByYearAndJournal($delyear,$deljournal);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
setEventMessages("RecordDeleted", null, 'mesgs');
}
Header("Location: list.php");
exit;
}
Expand Down
48 changes: 29 additions & 19 deletions htdocs/accountancy/class/bookkeeping.class.php
Expand Up @@ -116,7 +116,6 @@ public function create(User $user, $notrigger = false) {
$error = 0;

// Clean parameters

if (isset($this->doc_type)) {
$this->doc_type = trim($this->doc_type);
}
Expand Down Expand Up @@ -163,6 +162,14 @@ public function create(User $user, $notrigger = false) {
$this->piece_num = trim($this->piece_num);
}

// Check parameters
if (empty($this->numero_compte))
{
$this->errors[]='ErrorFieldAccountNotDefined';
return -1;
}


$this->db->begin();

$this->piece_num = 0;
Expand All @@ -174,7 +181,6 @@ public function create(User $user, $notrigger = false) {
$sql .= " AND fk_docdet = " . $this->fk_docdet;
$sql .= " AND numero_compte = '" . $this->numero_compte . "'";

dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);

if ($resql) {
Expand Down Expand Up @@ -274,11 +280,11 @@ public function create(User $user, $notrigger = false) {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
}
} else {
$result = - 3;
$error ++;
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
} 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);
}
} else {
$result = - 5;
Expand Down Expand Up @@ -1012,7 +1018,7 @@ public function delete(User $user, $notrigger = false) {
/**
* Delete bookkepping by importkey
*
* @param string $importkey Import key
* @param string $importkey Import key
* @return int Result
*/
function deleteByImportkey($importkey) {
Expand All @@ -1027,10 +1033,7 @@ function deleteByImportkey($importkey) {

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);
}
dol_syslog(get_class($this)."::delete Error " . $this->db->lasterror(), LOG_ERR);
$this->db->rollback();
return - 1;
}
Expand All @@ -1042,17 +1045,24 @@ function deleteByImportkey($importkey) {
/**
* Delete bookkepping by year
*
* @param string $delyear year to delete
* @return int Result
* @param string $delyear Year to delete
* @param string $journal Journal to delete
* @return int Result
*/
function deleteByYear($delyear) {
function deleteByYearAndJournal($delyear='', $journal='') {
if (empty($delyear) && empty($journal))
{
return -1;
}

$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;

$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql.= " WHERE 1 = 1";
if ($delyear) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between
if ($journal) $sql.= " AND code_journal = ".$journal;
$resql = $this->db->query($sql);

if (! $resql) {
Expand All @@ -1062,7 +1072,7 @@ function deleteByYear($delyear) {
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
}
$this->db->rollback();
return - 1;
return -1;
}

$this->db->commit();
Expand Down

0 comments on commit 31ce725

Please sign in to comment.