-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32088 from alexandre-janniaux/accountingjournal-c…
…reate/1 QUAL accountingjournal: add create() method
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
* | ||
|