Skip to content

Commit

Permalink
Merge pull request #32088 from alexandre-janniaux/accountingjournal-c…
Browse files Browse the repository at this point in the history
…reate/1

QUAL accountingjournal: add create() method
  • Loading branch information
eldy authored Jan 13, 2025
2 parents 700efa5 + 678283d commit 19c8eae
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions htdocs/accountancy/class/accountingjournal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2017-2022 OpenDSI <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 Alexandre Janniaux <[email protected]>
*
* 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
Expand Down Expand Up @@ -103,6 +104,50 @@ public function __construct($db)
$this->ismultientitymanaged = 0;
}

/**
* Create a new Accounting Journal.
*
* @param User $user the user that created the journal, currently unused
* @return int Return integer <0 on error, or the ID of the created object
*/
public function create($user)
{
$valid_nature = array(1, 2, 3, 4, 5, 8, 9);
if (!in_array((int) $this->nature, $valid_nature)) {
$this->error = get_class($this)."::Create Error invalid field nature '" . strval($this->nature) . "'";
dol_syslog($this->error, LOG_ERR);
return -1;
}

$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_journal";
$sql .= " (entity, code, label, nature, active)";
$sql .= " VALUES ("
. ((int) $this->entity) .",'"
. $this->db->escape($this->code) ."','"
. $this->db->escape($this->label) ."',"
. ((int) $this->nature) .","
. ((int) $this->active) .")";

dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$this->error = get_class($this)."::Create Error: " . $this->db->lasterror();
dol_syslog($this->error, LOG_ERR);
return -1;
}

$id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_journal");
if ($id <= 0) {
$this->error = get_class($this)."::Create Error " . $id . ": " . $this->db->lasterror();
dol_syslog($this->error, LOG_ERR);
return -2;
}

$this->id = $id;
$this->rowid = $id;
return $id;
}

/**
* Load an object from database
*
Expand Down

0 comments on commit 19c8eae

Please sign in to comment.