25require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
37 public $element =
'propal_merge_pdf_product';
42 public $table_element =
'propal_merge_pdf_product';
46 public $fk_user_author;
52 public $lines = array();
75 public function create($user, $notrigger = 0)
82 if (isset($this->fk_product)) {
83 $this->fk_product = trim($this->fk_product);
85 if (isset($this->file_name)) {
86 $this->file_name = trim($this->file_name);
88 if (isset($this->fk_user_author)) {
89 $this->fk_user_author = trim($this->fk_user_author);
91 if (isset($this->fk_user_mod)) {
92 $this->fk_user_mod = trim($this->fk_user_mod);
94 if (isset($this->lang)) {
95 $this->lang = trim($this->lang);
97 if (isset($this->import_key)) {
98 $this->import_key = trim($this->import_key);
107 $sql =
"INSERT INTO ".$this->db->prefix().
"propal_merge_pdf_product(";
108 $sql .=
"fk_product,";
109 $sql .=
"file_name,";
113 $sql .=
"fk_user_author,";
114 $sql .=
"fk_user_mod,";
116 $sql .=
") VALUES (";
117 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : ((int) $this->fk_product)).
",";
118 $sql .=
" ".(!isset($this->file_name) ?
'NULL' :
"'".$this->db->escape($this->file_name).
"'").
",";
120 $sql .=
" ".(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
",";
122 $sql .=
" ".((int) $user->id).
",";
123 $sql .=
" ".((int) $user->id).
",";
124 $sql .=
" '".$this->db->idate(
dol_now()).
"'";
129 $resql = $this->db->query($sql);
131 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
135 $this->
id = $this->db->last_insert_id($this->db->prefix().
"propal_merge_pdf_product");
140 foreach ($this->errors as $errmsg) {
141 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
142 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
144 $this->db->rollback();
161 global $langs, $conf;
166 $sql .=
" t.fk_product,";
167 $sql .=
" t.file_name,";
169 $sql .=
" t.fk_user_author,";
170 $sql .=
" t.fk_user_mod,";
173 $sql .=
" t.import_key";
176 $sql .=
" FROM ".$this->db->prefix().
"propal_merge_pdf_product as t";
177 $sql .=
" WHERE t.rowid = ".((int) $id);
180 $resql = $this->db->query($sql);
182 if ($this->db->num_rows($resql)) {
183 $obj = $this->db->fetch_object($resql);
185 $this->
id = $obj->rowid;
187 $this->fk_product = $obj->fk_product;
188 $this->file_name = $obj->file_name;
190 $this->lang = $obj->lang;
192 $this->fk_user_author = $obj->fk_user_author;
193 $this->fk_user_mod = $obj->fk_user_mod;
194 $this->datec = $this->db->jdate($obj->datec);
195 $this->tms = $this->db->jdate($obj->tms);
196 $this->import_key = $obj->import_key;
198 $this->db->free($resql);
202 $this->error =
"Error ".$this->db->lasterror();
203 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
219 global $langs, $conf;
224 $sql .=
" t.fk_product,";
225 $sql .=
" t.file_name,";
227 $sql .=
" t.fk_user_author,";
228 $sql .=
" t.fk_user_mod,";
231 $sql .=
" t.import_key";
234 $sql .=
" FROM ".$this->db->prefix().
"propal_merge_pdf_product as t";
235 $sql .=
" WHERE t.fk_product = ".((int) $product_id);
237 $sql .=
" AND t.lang = '".$this->db->escape($lang).
"'";
241 $resql = $this->db->query($sql);
243 if ($this->db->num_rows($resql)) {
244 while ($obj = $this->db->fetch_object($resql)) {
247 $line->id = $obj->rowid;
249 $line->fk_product = $obj->fk_product;
250 $line->file_name = $obj->file_name;
252 $line->lang = $obj->lang;
254 $line->fk_user_author = $obj->fk_user_author;
255 $line->fk_user_mod = $obj->fk_user_mod;
256 $line->datec = $this->db->jdate($obj->datec);
257 $line->tms = $this->db->jdate($obj->tms);
258 $line->import_key = $obj->import_key;
262 $this->lines[$obj->file_name.
'_'.$obj->lang] = $line;
264 $this->lines[$obj->file_name] = $line;
268 $this->db->free($resql);
272 $this->error =
"Error ".$this->db->lasterror();
273 dol_syslog(get_class($this).
"::fetch_by_product ".$this->error, LOG_ERR);
286 public function update($user = 0, $notrigger = 0)
288 global $conf, $langs;
293 if (isset($this->fk_product)) {
294 $this->fk_product = trim($this->fk_product);
296 if (isset($this->file_name)) {
297 $this->file_name = trim($this->file_name);
299 if (isset($this->fk_user_mod)) {
300 $this->fk_user_mod = trim($this->fk_user_mod);
302 if (isset($this->lang)) {
303 $this->lang = trim($this->lang);
310 $sql =
"UPDATE ".$this->db->prefix().
"propal_merge_pdf_product SET";
312 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
313 $sql .=
" file_name=".(isset($this->file_name) ?
"'".$this->db->escape($this->file_name).
"'" :
"null").
",";
315 $sql .=
" lang=".(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
",";
317 $sql .=
" fk_user_mod=".$user->id;
320 $sql .=
" WHERE rowid=".((int) $this->
id);
325 $resql = $this->db->query($sql);
327 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
332 foreach ($this->errors as $errmsg) {
333 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
334 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
336 $this->db->rollback();
352 public function delete($user, $notrigger = 0)
354 global $conf, $langs;
360 $sql =
"DELETE FROM ".$this->db->prefix().
"propal_merge_pdf_product";
361 $sql .=
" WHERE rowid=".((int) $this->
id);
364 $resql = $this->db->query($sql);
366 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
372 foreach ($this->errors as $errmsg) {
373 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
374 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
376 $this->db->rollback();
397 global $conf, $langs;
403 $sql =
"DELETE FROM ".$this->db->prefix().
"propal_merge_pdf_product";
404 $sql .=
" WHERE fk_product = ".((int) $product_id);
407 $sql .=
" AND lang = '".$this->db->escape($lang_id).
"'";
411 $resql = $this->db->query($sql);
413 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
419 foreach ($this->errors as $errmsg) {
420 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
421 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
423 $this->db->rollback();
441 global $conf, $langs;
447 $sql =
"DELETE FROM ".$this->db->prefix().
"propal_merge_pdf_product";
448 $sql .=
" WHERE fk_product = ".((int) $this->fk_product).
" AND file_name = '".$this->db->escape($this->file_name).
"'";
451 $resql = $this->db->query($sql);
453 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
459 foreach ($this->errors as $errmsg) {
460 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
461 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
463 $this->db->rollback();
489 $object->fetch($fromid);
497 $object->context[
'createfromclone'] =
'createfromclone';
498 $result = $object->create($user);
502 $this->error = $object->error;
503 $this->errors = array_merge($this->errors, $object->errors);
510 unset($object->context[
'createfromclone']);
517 $this->db->rollback();
533 $this->fk_product =
'';
534 $this->file_name =
'';
535 $this->fk_user_author =
'';
536 $this->fk_user_mod =
'';
539 $this->import_key =
'';
564 public $fk_user_author;
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Put here description of your class.
create($user, $notrigger=0)
Create object into database.
fetch_by_product($product_id, $lang='')
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id)
Load object in memory from the database.
__construct($db)
Constructor.
delete_by_file($user)
Delete object in database.
update($user=0, $notrigger=0)
Update object into database.
delete_by_product($user, $product_id, $lang_id='', $notrigger=0)
Delete object in database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Class to manage propal merge of product line.
__construct()
Constructor.
Class to manage Dolibarr users.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.