30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'project';
46 public $table_element =
'projet';
51 public $table_element_line =
'projet_task';
56 public $table_element_date;
61 public $fk_element =
'fk_projet';
67 public $ismultientitymanaged = 1;
72 public $picto =
'project';
116 public $date_start_event;
121 public $date_end_event;
134 public $thirdparty_name;
141 public $fk_user_close;
146 public $user_close_id;
152 public $budget_amount;
157 public $usage_opportunity;
167 public $usage_bill_time;
172 public $usage_organize_event;
177 public $accept_conference_suggestions;
182 public $accept_booth_suggestions;
187 public $price_registration;
197 public $max_attendees;
199 public $statuts_short;
200 public $statuts_long;
205 public $fk_opp_status;
212 public $weekWorkLoad;
213 public $weekWorkLoadPerTask;
272 public $fields = array(
273 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
274 'ref' =>array(
'type'=>
'varchar(50)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>15,
'searchall'=>1),
275 'title' =>array(
'type'=>
'varchar(255)',
'label'=>
'ProjectLabel',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>17,
'showoncombobox'=>2,
'searchall'=>1),
276 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>19),
277 'fk_soc' =>array(
'type'=>
'integer',
'label'=>
'Thirdparty',
'enabled'=>1,
'visible'=>0,
'position'=>20),
278 'dateo' =>array(
'type'=>
'date',
'label'=>
'DateStart',
'enabled'=>1,
'visible'=>1,
'position'=>30),
279 'datee' =>array(
'type'=>
'date',
'label'=>
'DateEnd',
'enabled'=>1,
'visible'=>1,
'position'=>35),
280 'description' =>array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>3,
'position'=>55,
'searchall'=>1),
281 'public' =>array(
'type'=>
'integer',
'label'=>
'Visibility',
'enabled'=>1,
'visible'=>1,
'position'=>65),
282 'fk_opp_status' =>array(
'type'=>
'integer',
'label'=>
'OpportunityStatusShort',
'enabled'=>
'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")',
'visible'=>1,
'position'=>75),
283 'opp_percent' =>array(
'type'=>
'double(5,2)',
'label'=>
'OpportunityProbabilityShort',
'enabled'=>
'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")',
'visible'=>1,
'position'=>80),
284 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>85,
'searchall'=>1),
285 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>90,
'searchall'=>1),
286 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPdf',
'enabled'=>1,
'visible'=>0,
'position'=>95),
287 'date_close' =>array(
'type'=>
'datetime',
'label'=>
'DateClosing',
'enabled'=>1,
'visible'=>0,
'position'=>105),
288 'fk_user_close' =>array(
'type'=>
'integer',
'label'=>
'UserClosing',
'enabled'=>1,
'visible'=>0,
'position'=>110),
289 'opp_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'OpportunityAmountShort',
'enabled'=>1,
'visible'=>
'getDolGlobalString("PROJECT_USE_OPPORTUNITIES")',
'position'=>115),
290 'budget_amount' =>array(
'type'=>
'double(24,8)',
'label'=>
'Budget',
'enabled'=>1,
'visible'=>1,
'position'=>119),
291 'usage_bill_time' =>array(
'type'=>
'integer',
'label'=>
'UsageBillTimeShort',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
292 'usage_opportunity' =>array(
'type'=>
'integer',
'label'=>
'UsageOpportunity',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
293 'usage_task' =>array(
'type'=>
'integer',
'label'=>
'UsageTasks',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
294 'usage_organize_event' =>array(
'type'=>
'integer',
'label'=>
'UsageOrganizeEvent',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
296 'date_start_event' =>array(
'type'=>
'date',
'label'=>
'DateStartEvent',
'enabled'=>1,
'visible'=>1,
'position'=>200),
297 'date_end_event' =>array(
'type'=>
'date',
'label'=>
'DateEndEvent',
'enabled'=>1,
'visible'=>1,
'position'=>201),
298 'location' =>array(
'type'=>
'text',
'label'=>
'Location',
'enabled'=>1,
'visible'=>3,
'position'=>55,
'searchall'=>202),
299 'accept_conference_suggestions' =>array(
'type'=>
'integer',
'label'=>
'AllowUnknownPeopleSuggestConf',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
300 'accept_booth_suggestions' =>array(
'type'=>
'integer',
'label'=>
'AllowUnknownPeopleSuggestBooth',
'enabled'=>1,
'visible'=>-1,
'position'=>211),
301 'price_registration' =>array(
'type'=>
'double(24,8)',
'label'=>
'PriceOfRegistration',
'enabled'=>1,
'visible'=>-1,
'position'=>212),
302 'price_booth' =>array(
'type'=>
'double(24,8)',
'label'=>
'PriceOfBooth',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
303 'max_attendees' =>array(
'type'=>
'integer',
'label'=>
'MaxNbOfAttendees',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
305 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreationShort',
'enabled'=>1,
'visible'=>-2,
'position'=>400),
306 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModificationShort',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>405),
307 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserCreation',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>410),
308 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModification',
'enabled'=>1,
'visible'=>0,
'position'=>415),
309 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>420),
310 'email_msgid'=>array(
'type'=>
'varchar(255)',
'label'=>
'EmailMsgID',
'enabled'=>1,
'visible'=>-1,
'position'=>450,
'help'=>
'EmailMsgIDWhenSourceisEmail'),
311 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>500),
341 $this->statuts_short = array(0 =>
'Draft', 1 =>
'Opened', 2 =>
'Closed');
342 $this->statuts_long = array(0 =>
'Draft', 1 =>
'Opened', 2 =>
'Closed');
346 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
347 $this->fields[
'rowid'][
'visible'] = 0;
350 if (empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
351 $this->fields[
'fk_opp_status'][
'enabled'] = 0;
352 $this->fields[
'opp_percent'][
'enabled'] = 0;
353 $this->fields[
'opp_amount'][
'enabled'] = 0;
354 $this->fields[
'usage_opportunity'][
'enabled'] = 0;
357 if (!empty($conf->global->PROJECT_HIDE_TASKS)) {
358 $this->fields[
'usage_bill_time'][
'visible'] = 0;
359 $this->fields[
'usage_task'][
'visible'] = 0;
362 if (empty($conf->eventorganization->enabled)) {
363 $this->fields[
'usage_organize_event'][
'visible'] = 0;
364 $this->fields[
'accept_conference_suggestions'][
'enabled'] = 0;
365 $this->fields[
'accept_booth_suggestions'][
'enabled'] = 0;
366 $this->fields[
'price_registration'][
'enabled'] = 0;
367 $this->fields[
'price_booth'][
'enabled'] = 0;
368 $this->fields[
'max_attendees'][
'enabled'] = 0;
379 public function create($user, $notrigger = 0)
381 global $conf, $langs;
389 $this->note_private =
dol_substr($this->note_private, 0, 65535);
390 $this->note_public =
dol_substr($this->note_public, 0, 65535);
393 if (!trim($this->
ref)) {
394 $this->error =
'ErrorFieldsRequired';
395 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
398 if (!empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) && !($this->socid > 0)) {
399 $this->error =
'ErrorFieldsRequired';
400 dol_syslog(get_class($this).
"::create error -1 thirdparty not defined and option PROJECT_THIRDPARTY_REQUIRED is set", LOG_ERR);
407 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"projet (";
410 $sql .=
", description";
412 $sql .=
", fk_user_creat";
413 $sql .=
", fk_statut";
414 $sql .=
", fk_opp_status";
415 $sql .=
", opp_percent";
420 $sql .=
", opp_amount";
421 $sql .=
", budget_amount";
422 $sql .=
", usage_opportunity";
423 $sql .=
", usage_task";
424 $sql .=
", usage_bill_time";
425 $sql .=
", usage_organize_event";
426 $sql .=
", accept_conference_suggestions";
427 $sql .=
", accept_booth_suggestions";
428 $sql .=
", price_registration";
429 $sql .=
", price_booth";
430 $sql .=
", max_attendees";
431 $sql .=
", date_start_event";
432 $sql .=
", date_end_event";
433 $sql .=
", location";
434 $sql .=
", email_msgid";
435 $sql .=
", note_private";
436 $sql .=
", note_public";
439 $sql .=
") VALUES (";
440 $sql .=
"'".$this->db->escape($this->
ref).
"'";
441 $sql .=
", '".$this->db->escape($this->title).
"'";
442 $sql .=
", '".$this->db->escape($this->
description).
"'";
443 $sql .=
", ".($this->socid > 0 ? $this->socid :
"null");
444 $sql .=
", ".((int) $user->id);
445 $sql .=
", ".(is_numeric($this->statut) ? ((int) $this->statut) :
'0');
446 $sql .=
", ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? ((
int) $this->opp_status) :
'NULL');
447 $sql .=
", ".(is_numeric($this->opp_percent) ? ((int) $this->opp_percent) :
'NULL');
448 $sql .=
", ".($this->public ? 1 : 0);
449 $sql .=
", '".$this->db->idate($now).
"'";
450 $sql .=
", ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
451 $sql .=
", ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
452 $sql .=
", ".(strcmp($this->opp_amount,
'') ?
price2num($this->opp_amount) :
'null');
453 $sql .=
", ".(strcmp($this->budget_amount,
'') ?
price2num($this->budget_amount) :
'null');
454 $sql .=
", ".($this->usage_opportunity ? 1 : 0);
455 $sql .=
", ".($this->usage_task ? 1 : 0);
456 $sql .=
", ".($this->usage_bill_time ? 1 : 0);
457 $sql .=
", ".($this->usage_organize_event ? 1 : 0);
458 $sql .=
", ".($this->accept_conference_suggestions ? 1 : 0);
459 $sql .=
", ".($this->accept_booth_suggestions ? 1 : 0);
460 $sql .=
", ".(strcmp($this->price_registration,
'') ?
price2num($this->price_registration) :
'null');
461 $sql .=
", ".(strcmp($this->price_booth,
'') ?
price2num($this->price_booth) :
'null');
462 $sql .=
", ".(strcmp($this->max_attendees,
'') ? ((int) $this->max_attendees) :
'null');
463 $sql .=
", ".($this->date_start_event !=
'' ?
"'".$this->db->idate($this->date_start_event).
"'" :
'null');
464 $sql .=
", ".($this->date_end_event !=
'' ?
"'".$this->db->idate($this->date_end_event).
"'" :
'null');
465 $sql .=
", ".($this->location ?
"'".$this->db->escape($this->location).
"'" :
'null');
466 $sql .=
", ".($this->email_msgid ?
"'".$this->db->escape($this->email_msgid).
"'" :
'null');
467 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
'null');
468 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null');
469 $sql .=
", ".((int) $conf->entity);
470 $sql .=
", ".(!isset($this->ip) ?
'NULL' :
"'".$this->db->escape($this->ip).
"'");
473 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
476 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"projet");
488 $this->error = $this->
db->lasterror();
489 $this->errno = $this->
db->lasterrno();
501 if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) {
512 $this->
db->rollback();
524 public function update($user, $notrigger = 0)
526 global $langs, $conf;
531 $this->title = trim($this->title);
533 if ($this->opp_amount < 0) {
534 $this->opp_amount =
'';
536 if ($this->opp_percent < 0) {
537 $this->opp_percent =
'';
539 if ($this->date_end && $this->date_end < $this->date_start) {
540 $this->error = $langs->trans(
"ErrorDateEndLowerThanDateStart");
541 $this->errors[] = $this->error;
542 $this->
db->rollback();
543 dol_syslog(get_class($this).
"::update error -3 ".$this->error, LOG_ERR);
547 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
552 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet SET";
553 $sql .=
" ref='".$this->db->escape($this->
ref).
"'";
554 $sql .=
", title = '".$this->db->escape($this->title).
"'";
555 $sql .=
", description = '".$this->db->escape($this->
description).
"'";
556 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->socid :
"null");
557 $sql .=
", fk_statut = ".((int) $this->statut);
558 $sql .=
", fk_opp_status = ".((is_numeric($this->opp_status) && $this->opp_status > 0) ? $this->opp_status :
'null');
559 $sql .=
", opp_percent = ".((is_numeric($this->opp_percent) && $this->opp_percent !=
'') ? $this->opp_percent :
'null');
560 $sql .=
", public = ".($this->public ? 1 : 0);
561 $sql .=
", datec = ".($this->date_c !=
'' ?
"'".$this->db->idate($this->date_c).
"'" :
'null');
562 $sql .=
", dateo = ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
'null');
563 $sql .=
", datee = ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
'null');
564 $sql .=
", date_close = ".($this->date_close !=
'' ?
"'".$this->db->idate($this->date_close).
"'" :
'null');
565 $sql .=
", fk_user_close = ".($this->fk_user_close > 0 ? $this->fk_user_close :
"null");
566 $sql .=
", opp_amount = ".(strcmp($this->opp_amount,
'') ?
price2num($this->opp_amount) :
"null");
567 $sql .=
", budget_amount = ".(strcmp($this->budget_amount,
'') ?
price2num($this->budget_amount) :
"null");
568 $sql .=
", fk_user_modif = ".$user->id;
569 $sql .=
", usage_opportunity = ".($this->usage_opportunity ? 1 : 0);
570 $sql .=
", usage_task = ".($this->usage_task ? 1 : 0);
571 $sql .=
", usage_bill_time = ".($this->usage_bill_time ? 1 : 0);
572 $sql .=
", usage_organize_event = ".($this->usage_organize_event ? 1 : 0);
573 $sql .=
", accept_conference_suggestions = ".($this->accept_conference_suggestions ? 1 : 0);
574 $sql .=
", accept_booth_suggestions = ".($this->accept_booth_suggestions ? 1 : 0);
575 $sql .=
", price_registration = ".(strcmp($this->price_registration,
'') ?
price2num($this->price_registration) :
"null");
576 $sql .=
", price_booth = ".(strcmp($this->price_booth,
'') ?
price2num($this->price_booth) :
"null");
577 $sql .=
", max_attendees = ".(strcmp($this->max_attendees,
'') ?
price2num($this->max_attendees) :
"null");
578 $sql .=
", date_start_event = ".($this->date_start_event !=
'' ?
"'".$this->db->idate($this->date_start_event).
"'" :
'null');
579 $sql .=
", date_end_event = ".($this->date_end_event !=
'' ?
"'".$this->db->idate($this->date_end_event).
"'" :
'null');
580 $sql .=
", location = '".$this->db->escape($this->location).
"'";
581 $sql .=
", entity = ".((int) $this->entity);
582 $sql .=
" WHERE rowid = ".((int) $this->
id);
584 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
595 if (!$error && !$notrigger) {
604 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
606 if ($conf->project->dir_output) {
609 if (file_exists($olddir)) {
610 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
611 $res = @rename($olddir, $newdir);
613 $langs->load(
"errors");
614 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
624 $this->
db->rollback();
628 $this->error = $this->
db->lasterror();
629 $this->errors[] = $this->error;
630 $this->
db->rollback();
631 if ($this->
db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
636 dol_syslog(get_class($this).
"::update error ".$result.
" ".$this->error, LOG_ERR);
639 dol_syslog(get_class($this).
"::update ref null");
655 public function fetch($id, $ref =
'', $ref_ext =
'', $email_msgid =
'')
659 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
660 dol_syslog(get_class($this).
"::fetch Bad parameters", LOG_WARNING);
664 $sql =
"SELECT rowid, entity, ref, title, description, public, datec, opp_amount, budget_amount,";
665 $sql .=
" tms, dateo as date_start, datee as date_end, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut as status, fk_opp_status, opp_percent,";
666 $sql .=
" note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid,";
667 $sql .=
" accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees, date_start_event, date_end_event, location";
668 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet";
670 $sql .=
" WHERE rowid = ".((int) $id);
672 $sql .=
" WHERE entity IN (".getEntity(
'project').
")";
674 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
675 } elseif (!empty($ref_ext)) {
676 $sql .=
" AND ref_ext = '".$this->db->escape($ref_ext).
"'";
678 $sql .=
" AND email_msgid = '".$this->db->escape($email_msgid).
"'";
682 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
685 $num_rows = $this->
db->num_rows(
$resql);
688 $obj = $this->
db->fetch_object(
$resql);
690 $this->
id = $obj->rowid;
691 $this->entity = $obj->entity;
692 $this->
ref = $obj->ref;
693 $this->title = $obj->title;
695 $this->date_c = $this->
db->jdate($obj->datec);
696 $this->datec = $this->
db->jdate($obj->datec);
697 $this->date_m = $this->
db->jdate($obj->tms);
698 $this->datem = $this->
db->jdate($obj->tms);
699 $this->date_start = $this->
db->jdate($obj->date_start);
700 $this->date_end = $this->
db->jdate($obj->date_end);
701 $this->date_close = $this->
db->jdate($obj->date_close);
702 $this->note_private = $obj->note_private;
703 $this->note_public = $obj->note_public;
704 $this->socid = $obj->fk_soc;
705 $this->user_author_id = $obj->fk_user_creat;
706 $this->user_modification_id = $obj->fk_user_modif;
707 $this->user_close_id = $obj->fk_user_close;
708 $this->
public = $obj->public;
709 $this->statut = $obj->status;
710 $this->status = $obj->status;
711 $this->opp_status = $obj->fk_opp_status;
712 $this->opp_amount = $obj->opp_amount;
713 $this->opp_percent = $obj->opp_percent;
714 $this->budget_amount = $obj->budget_amount;
715 $this->model_pdf = $obj->model_pdf;
716 $this->modelpdf = $obj->model_pdf;
717 $this->usage_opportunity = (int) $obj->usage_opportunity;
718 $this->usage_task = (
int) $obj->usage_task;
719 $this->usage_bill_time = (int) $obj->usage_bill_time;
720 $this->usage_organize_event = (
int) $obj->usage_organize_event;
721 $this->accept_conference_suggestions = (int) $obj->accept_conference_suggestions;
722 $this->accept_booth_suggestions = (
int) $obj->accept_booth_suggestions;
723 $this->price_registration = $obj->price_registration;
724 $this->price_booth = $obj->price_booth;
725 $this->max_attendees = $obj->max_attendees;
726 $this->date_start_event = $this->
db->jdate($obj->date_start_event);
727 $this->date_end_event = $this->
db->jdate($obj->date_end_event);
728 $this->location = $obj->location;
729 $this->email_msgid = $obj->email_msgid;
744 $this->error = $this->
db->lasterror();
745 $this->errors[] = $this->
db->lasterror();
762 public function get_element_list($type, $tablename, $datefieldname =
'', $date_start =
'', $date_end =
'', $projectkey =
'fk_projet')
770 if ($this->
id <= 0) {
776 if ($type ==
'agenda') {
777 $sql =
"SELECT id as rowid FROM ".MAIN_DB_PREFIX.
"actioncomm WHERE fk_project IN (".$this->
db->sanitize($ids).
") AND entity IN (".
getEntity(
'agenda').
")";
778 } elseif ($type ==
'expensereport') {
779 $sql =
"SELECT ed.rowid FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".
getEntity(
'expensereport').
") AND ed.fk_projet IN (".$this->
db->sanitize($ids).
")";
780 } elseif ($type ==
'project_task') {
781 $sql =
"SELECT DISTINCT pt.rowid FROM ".MAIN_DB_PREFIX.
"projet_task as pt WHERE pt.fk_projet IN (".$this->
db->sanitize($ids).
")";
782 } elseif ($type ==
'project_task_time') {
783 $sql =
"SELECT DISTINCT pt.rowid, ptt.fk_user FROM ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet_task_time as ptt WHERE pt.rowid = ptt.fk_task AND pt.fk_projet IN (".$this->
db->sanitize($ids).
")";
784 } elseif ($type ==
'stock_mouvement') {
785 $sql =
"SELECT ms.rowid, ms.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX.
"stock_mouvement as ms, ".MAIN_DB_PREFIX.
"entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
") AND ms.origintype = 'project' AND ms.fk_origin IN (".$this->
db->sanitize($ids).
") AND ms.type_mouvement = 1";
786 } elseif ($type ==
'loan') {
787 $sql =
"SELECT l.rowid, l.fk_user_author as fk_user FROM ".MAIN_DB_PREFIX.
"loan as l WHERE l.entity IN (".
getEntity(
'loan').
") AND l.fk_projet IN (".$this->
db->sanitize($ids).
")";
789 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.$tablename.
" WHERE ".$projectkey.
" IN (".$this->
db->sanitize($ids).
") AND entity IN (".
getEntity($type).
")";
792 if ($date_start > 0 && $type ==
'loan') {
793 $sql .=
" AND (dateend > '".$this->db->idate($date_start).
"' OR dateend IS NULL)";
794 } elseif ($date_start > 0 && ($type !=
'project_task')) {
795 if (empty($datefieldname) && !empty($this->table_element_date)) {
796 $datefieldname = $this->table_element_date;
798 if (empty($datefieldname)) {
799 return 'Error this object has no date field defined';
801 $sql .=
" AND (".$datefieldname.
" >= '".$this->
db->idate($date_start).
"' OR ".$datefieldname.
" IS NULL)";
804 if ($date_end > 0 && $type ==
'loan') {
805 $sql .=
" AND (datestart < '".$this->db->idate($date_end).
"' OR datestart IS NULL)";
806 } elseif ($date_end > 0 && ($type !=
'project_task')) {
807 if (empty($datefieldname) && !empty($this->table_element_date)) {
808 $datefieldname = $this->table_element_date;
810 if (empty($datefieldname)) {
811 return 'Error this object has no date field defined';
813 $sql .=
" AND (".$datefieldname.
" <= '".$this->
db->idate($date_end).
"' OR ".$datefieldname.
" IS NULL)";
819 'tablename' => $tablename,
820 'datefieldname' => $datefieldname,
821 'dates' => $date_start,
822 'datee' => $date_end,
823 'fk_projet' => $projectkey,
826 $reshook = $hookmanager->executeHooks(
'getElementList', $parameters);
828 $sql = $hookmanager->resPrint;
830 $sql .= $hookmanager->resPrint;
838 dol_syslog(get_class($this).
"::get_element_list", LOG_DEBUG);
839 $result = $this->
db->query($sql);
841 $nump = $this->
db->num_rows($result);
845 $obj = $this->
db->fetch_object($result);
847 $elements[$i] = $obj->rowid.(empty($obj->fk_user) ?
'' :
'_'.$obj->fk_user);
851 $this->
db->free($result);
868 public function delete($user, $notrigger = 0)
870 global $langs, $conf;
871 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
881 $this->error =
'ErrorFailToDeleteLinkedContact';
883 $this->
db->rollback();
889 $listoftables = array(
890 'propal'=>
'fk_projet',
'commande'=>
'fk_projet',
'facture'=>
'fk_projet',
891 'supplier_proposal'=>
'fk_projet',
'commande_fournisseur'=>
'fk_projet',
'facture_fourn'=>
'fk_projet',
892 'expensereport_det'=>
'fk_projet',
'contrat'=>
'fk_projet',
893 'fichinter'=>
'fk_projet',
894 'don'=>array(
'field'=>
'fk_projet',
'module'=>
'don'),
895 'actioncomm'=>
'fk_project',
896 'mrp_mo'=>
'fk_project',
897 'entrepot'=>
'fk_project'
899 foreach ($listoftables as $key => $value) {
900 if (is_array($value)) {
904 $fieldname = $value[
'field'];
908 $sql =
"UPDATE ".MAIN_DB_PREFIX.$key.
" SET ".$fieldname.
" = NULL where ".$fieldname.
" = ".((int) $this->
id);
912 $this->errors[] = $this->
db->lasterror();
920 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_project";
921 $sql .=
" WHERE fk_project = ".((int) $this->
id);
923 $result = $this->
db->query($sql);
926 $this->errors[] = $this->
db->lasterror();
942 $elements = array(
'categorie_project');
943 foreach ($elements as $table) {
945 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$table;
946 $sql .=
" WHERE fk_project = ".((int) $this->
id);
948 $result = $this->
db->query($sql);
951 $this->errors[] = $this->
db->lasterror();
958 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet_extrafields";
959 $sql .=
" WHERE fk_object = ".((int) $this->
id);
963 $this->errors[] = $this->
db->lasterror();
970 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"projet";
971 $sql .=
" WHERE rowid=".((int) $this->
id);
975 $this->errors[] = $langs->trans(
"CantRemoveProject", $langs->transnoentitiesnoconv(
"ProjectOverview"));
985 if ($conf->project->dir_output) {
986 $dir = $conf->project->dir_output.
"/".$projectref;
987 if (file_exists($dir)) {
990 $this->errors[] =
'ErrorFailToDeleteDir';
1007 if (empty($error)) {
1008 $this->
db->commit();
1011 foreach ($this->errors as $errmsg) {
1012 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1013 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1015 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
1016 $this->
db->rollback();
1031 if ($this->
id <= 0) {
1035 if ($type ==
'agenda') {
1036 $sql =
"SELECT COUNT(id) as nb FROM ".MAIN_DB_PREFIX.
"actioncomm WHERE fk_project = ".((int) $this->
id).
" AND entity IN (".
getEntity(
'agenda').
")";
1037 } elseif ($type ==
'expensereport') {
1038 $sql =
"SELECT COUNT(ed.rowid) as nb FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"expensereport_det as ed WHERE e.rowid = ed.fk_expensereport AND e.entity IN (".
getEntity(
'expensereport').
") AND ed.fk_projet = ".((int) $this->
id);
1039 } elseif ($type ==
'project_task') {
1040 $sql =
"SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX.
"projet_task as pt WHERE pt.fk_projet = ".((int) $this->
id);
1041 } elseif ($type ==
'project_task_time') {
1042 $sql =
"SELECT DISTINCT COUNT(pt.rowid) as nb FROM ".MAIN_DB_PREFIX.
"projet_task as pt, ".MAIN_DB_PREFIX.
"projet_task_time as ptt WHERE pt.rowid = ptt.fk_task AND pt.fk_projet = ".((int) $this->
id);
1043 } elseif ($type ==
'stock_mouvement') {
1044 $sql =
"SELECT COUNT(ms.rowid) as nb FROM ".MAIN_DB_PREFIX.
"stock_mouvement as ms, ".MAIN_DB_PREFIX.
"entrepot as e WHERE e.rowid = ms.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
") AND ms.origintype = 'project' AND ms.fk_origin = ".((int) $this->
id).
" AND ms.type_mouvement = 1";
1045 } elseif ($type ==
'loan') {
1046 $sql =
"SELECT COUNT(l.rowid) as nb FROM ".MAIN_DB_PREFIX.
"loan as l WHERE l.entity IN (".
getEntity(
'loan').
") AND l.fk_projet = ".((int) $this->
id);
1048 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$tablename.
" WHERE ".$projectkey.
" = ".((int) $this->
id).
" AND entity IN (".
getEntity($type).
")";
1051 $result = $this->
db->query($sql);
1057 $obj = $this->
db->fetch_object($result);
1059 $this->
db->free($result);
1072 $countTasks = count($this->lines);
1075 foreach ($this->lines as $task) {
1076 if ($task->hasChildren() <= 0) {
1078 $ret = $task->delete($user);
1080 $this->errors[] = $this->
db->lasterror();
1087 if ($deleted && count($this->lines) < $countTasks) {
1088 if (count($this->lines)) {
1105 global $langs, $conf;
1109 if ($this->statut != 1) {
1111 if (preg_match(
'/^'.preg_quote($langs->trans(
"CopyOf").
' ').
'/', $this->title)) {
1112 $this->error = $langs->trans(
"ErrorFieldFormat", $langs->transnoentities(
"Label")).
'. '.$langs->trans(
'RemoveString', $langs->transnoentitiesnoconv(
"CopyOf"));
1118 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet";
1119 $sql .=
" SET fk_statut = 1";
1120 $sql .=
" WHERE rowid = ".((int) $this->
id);
1121 $sql .=
" AND entity = ".((int) $conf->entity);
1123 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
1127 if (empty($notrigger)) {
1128 $result = $this->
call_trigger(
'PROJECT_VALIDATE', $user);
1137 $this->
db->commit();
1140 $this->
db->rollback();
1141 $this->error = join(
',', $this->errors);
1142 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
1146 $this->
db->rollback();
1147 $this->error = $this->
db->lasterror();
1161 global $langs, $conf;
1167 if ($this->statut != self::STATUS_CLOSED) {
1170 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet";
1171 $sql .=
" SET fk_statut = ".self::STATUS_CLOSED.
", fk_user_close = ".((int) $user->id).
", date_close = '".$this->
db->idate($now).
"'";
1172 $sql .=
" WHERE rowid = ".((int) $this->
id);
1173 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1175 if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
1179 dol_syslog(get_class($this).
"::setClose", LOG_DEBUG);
1191 $this->
db->commit();
1194 $this->
db->rollback();
1195 $this->error = join(
',', $this->errors);
1196 dol_syslog(get_class($this).
"::setClose ".$this->error, LOG_ERR);
1200 $this->
db->rollback();
1201 $this->error = $this->
db->lasterror();
1217 return $this->
LibStatut(isset($this->statut) ? $this->statut : $this->status, $mode);
1233 $statustrans = array(
1239 $statusClass =
'status0';
1240 if (!empty($statustrans[$status])) {
1241 $statusClass = $statustrans[$status];
1244 return dolGetStatus($langs->transnoentitiesnoconv($this->statuts_long[$status]), $langs->transnoentitiesnoconv($this->statuts_short[$status]),
'', $statusClass, $mode);
1260 public function getNomUrl($withpicto = 0, $option =
'', $addlabel = 0, $moreinpopup =
'', $sep =
' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
1262 global $conf, $langs, $user, $hookmanager;
1264 if (!empty($conf->dol_no_mouse_hover)) {
1269 if (!empty($conf->global->PROJECT_OPEN_ALWAYS_ON_TAB)) {
1270 $option = $conf->global->PROJECT_OPEN_ALWAYS_ON_TAB;
1274 if ($option !=
'nolink') {
1275 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
' <u class="paddingrightonly">'.$langs->trans(
"Project").
'</u>';
1277 if (isset($this->status)) {
1278 $label .=
' '.$this->getLibStatut(5);
1280 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'Ref').
': </b>'.$this->ref;
1281 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'Label').
': </b>'.$this->title;
1282 if (isset($this->
public)) {
1283 $label .=
'<br><b>'.$langs->trans(
"Visibility").
":</b> ";
1284 $label .= ($this->
public ?
img_picto($langs->trans(
'SharedProject'),
'world',
'class="pictofixedwidth"').$langs->trans(
"SharedProject") :
img_picto($langs->trans(
'PrivateProject'),
'private',
'class="pictofixedwidth"').$langs->trans(
"PrivateProject"));
1286 if (!empty($this->thirdparty_name)) {
1287 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'ThirdParty').
': </b>'.$this->thirdparty_name;
1289 if (!empty($this->date_start)) {
1290 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'DateStart').
': </b>'.
dol_print_date($this->date_start,
'day');
1292 if (!empty($this->date_end)) {
1293 $label .= ($label ?
'<br>' :
'').
'<b>'.$langs->trans(
'DateEnd').
': </b>'.
dol_print_date($this->date_end,
'day');
1296 $label .=
'<br>'.$moreinpopup;
1300 if ($option !=
'nolink') {
1301 if (preg_match(
'/\.php$/', $option)) {
1303 } elseif ($option ==
'task') {
1304 $url = DOL_URL_ROOT.
'/projet/tasks.php?id='.$this->id;
1305 } elseif ($option ==
'preview') {
1306 $url = DOL_URL_ROOT.
'/projet/element.php?id='.$this->id;
1307 } elseif ($option ==
'eventorganization') {
1308 $url = DOL_URL_ROOT.
'/eventorganization/conferenceorbooth_list.php?projectid='.$this->id;
1310 $url = DOL_URL_ROOT.
'/projet/card.php?id='.$this->id;
1313 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1314 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1315 $add_save_lastsearch_values = 1;
1317 if ($add_save_lastsearch_values) {
1318 $url .=
'&save_lastsearch_values=1';
1323 if (empty($notooltip) && $user->hasRight(
'projet',
'lire')) {
1324 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1325 $label = $langs->trans(
"ShowProject");
1326 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1328 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1329 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1331 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1334 $picto =
'projectpub';
1335 if (!$this->
public) {
1339 $linkstart =
'<a href="'.$url.
'"';
1340 $linkstart .= $linkclose.
'>';
1343 $result .= $linkstart;
1345 $result .=
img_object(($notooltip ?
'' : $label), $picto, ($notooltip ? (($withpicto != 2) ?
'class="pictofixedwidth"' :
'') :
'class="'.(($withpicto != 2) ?
'pictofixedwidth ' :
'').
'classfortooltip pictofixedwidth em088"'), 0, 0, $notooltip ? 0 : 1);
1347 if ($withpicto != 2) {
1348 $result .= $this->ref;
1350 $result .= $linkend;
1351 if ($withpicto != 2) {
1352 $result .= (($addlabel && $this->title) ?
'<span class="opacitymedium">'.$sep.dol_trunc($this->title, ($addlabel > 1 ? $addlabel : 0)).
'</span>' :
'');
1356 $hookmanager->initHooks(array(
'projectdao'));
1357 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1358 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1360 $result = $hookmanager->resPrint;
1362 $result .= $hookmanager->resPrint;
1377 global $user, $langs, $conf;
1383 $this->
ref =
'SPECIMEN';
1384 $this->specimen = 1;
1386 $this->date_c = $now;
1387 $this->date_m = $now;
1388 $this->date_start = $now;
1389 $this->date_end = $now + (3600 * 24 * 365);
1390 $this->note_public =
'SPECIMEN';
1391 $this->fk_ele = 20000;
1392 $this->opp_amount = 20000;
1393 $this->budget_amount = 10000;
1395 $this->usage_opportunity = 1;
1396 $this->usage_task = 1;
1397 $this->usage_bill_time = 1;
1398 $this->usage_organize_event = 1;
1427 if (($mode ==
'read' && !empty($user->rights->projet->all->lire)) || ($mode ==
'write' && !empty($user->rights->projet->all->creer)) || ($mode ==
'delete' && !empty($user->rights->projet->all->supprimer))) {
1429 } elseif ($this->
public && (($mode ==
'read' && !empty($user->rights->projet->lire)) || ($mode ==
'write' && !empty($user->rights->projet->creer)) || ($mode ==
'delete' && !empty($user->rights->projet->supprimer)))) {
1432 foreach (array(
'internal',
'external') as $source) {
1434 $num = count($userRole);
1437 while ($nblinks < $num) {
1438 if ($source ==
'internal' && $user->id == $userRole[$nblinks][
'id']) {
1439 if ($mode ==
'read' && $user->rights->projet->lire) {
1442 if ($mode ==
'write' && $user->rights->projet->creer) {
1445 if ($mode ==
'delete' && $user->rights->projet->supprimer) {
1449 if ($source ==
'external' && $user->socid > 0 && $user->socid == $userRole[$nblinks][
'socid']) {
1450 if ($mode ==
'read' && $user->rights->projet->lire) {
1453 if ($mode ==
'write' && $user->rights->projet->creer) {
1456 if ($mode ==
'delete' && $user->rights->projet->supprimer) {
1472 return ($userAccess ? $userAccess : -1);
1487 $projects = array();
1490 $sql =
"SELECT ".(($mode == 0 || $mode == 1) ?
"DISTINCT " :
"").
"p.rowid, p.ref";
1491 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
1493 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON ec.element_id = p.rowid";
1494 } elseif ($mode == 1) {
1495 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
1496 } elseif ($mode == 2) {
1499 $sql .=
" WHERE p.entity IN (".getEntity(
'project').
")";
1503 $sql .=
" AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).
")";
1507 $listofprojectcontacttype = array();
1508 $sql2 =
"SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1509 $sql2 .=
" WHERE ctc.element = '".$this->db->escape($this->element).
"'";
1510 $sql2 .=
" AND ctc.source = 'internal'";
1513 while ($obj = $this->
db->fetch_object(
$resql)) {
1514 $listofprojectcontacttype[$obj->rowid] = $obj->code;
1519 if (count($listofprojectcontacttype) == 0) {
1520 $listofprojectcontacttype[0] =
'0';
1524 $sql .=
" AND ( p.public = 1";
1525 $sql .=
" OR ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(
',', array_keys($listofprojectcontacttype))).
")";
1526 $sql .=
" AND ec.fk_socpeople = ".((int) $user->id).
")";
1528 } elseif ($mode == 1) {
1529 $sql .=
" AND ec.element_id = p.rowid";
1531 $sql .=
" ( ec.fk_c_type_contact IN (".$this->db->sanitize(join(
',', array_keys($listofprojectcontacttype))).
")";
1532 $sql .=
" AND ec.fk_socpeople = ".((int) $user->id).
")";
1534 } elseif ($mode == 2) {
1543 $num = $this->
db->num_rows(
$resql);
1546 $row = $this->
db->fetch_row(
$resql);
1547 $projects[$row[0]] = $row[1];
1558 $result = implode(
',', $temp);
1583 public function createFromClone(
User $user, $fromid, $clone_contact =
false, $clone_task =
true, $clone_project_file =
false, $clone_task_file =
false, $clone_note =
true, $move_date =
true, $notrigger = 0, $newthirdpartyid = 0)
1585 global $langs, $conf;
1589 dol_syslog(
"createFromClone clone_contact=".$clone_contact.
" clone_task=".$clone_task.
" clone_project_file=".$clone_project_file.
" clone_note=".$clone_note.
" move_date=".$move_date, LOG_DEBUG);
1593 $clone_project =
new Project($this->
db);
1595 $clone_project->context[
'createfromclone'] =
'createfromclone';
1600 $clone_project->fetch($fromid);
1601 $clone_project->fetch_optionals();
1602 if ($newthirdpartyid > 0) {
1603 $clone_project->socid = $newthirdpartyid;
1605 $clone_project->fetch_thirdparty();
1607 $orign_dt_start = $clone_project->date_start;
1608 $orign_project_ref = $clone_project->ref;
1610 $clone_project->id = 0;
1612 $clone_project->date_start = $now;
1613 if (!(empty($clone_project->date_end))) {
1614 $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start);
1618 $clone_project->date_c = $now;
1621 $clone_project->note_private =
'';
1622 $clone_project->note_public =
'';
1627 $obj = empty($conf->global->PROJECT_ADDON) ?
'mod_project_simple' : $conf->global->PROJECT_ADDON;
1629 $file =
''; $classname =
''; $filefound = 0;
1630 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1631 foreach ($dirmodels as $reldir) {
1632 $file =
dol_buildpath($reldir.
"core/modules/project/".$obj.
'.php', 0);
1633 if (file_exists($file)) {
1636 $modProject =
new $obj;
1637 $defaultref = $modProject->getNextValue(is_object($clone_project->thirdparty) ? $clone_project->thirdparty :
null, $clone_project);
1641 if (is_numeric($defaultref) && $defaultref <= 0) {
1645 $clone_project->ref = $defaultref;
1646 $clone_project->title = $langs->trans(
"CopyOf").
' '.$clone_project->title;
1649 $result = $clone_project->create($user, $notrigger);
1653 $this->error .= $clone_project->error;
1659 $clone_project_id = $clone_project->id;
1663 $clone_project->note_private =
'';
1664 $clone_project->note_public =
'';
1667 $res = $clone_project->update_note(
dol_html_entity_decode($clone_project->note_public, ENT_QUOTES | ENT_HTML5),
'_public');
1669 $this->error .= $clone_project->error;
1671 $this->
db->rollback();
1673 $this->
db->commit();
1677 $res = $clone_project->update_note(
dol_html_entity_decode($clone_project->note_private, ENT_QUOTES | ENT_HTML5),
'_private');
1679 $this->error .= $clone_project->error;
1681 $this->
db->rollback();
1683 $this->
db->commit();
1688 if ($clone_contact) {
1689 $origin_project =
new Project($this->
db);
1690 $origin_project->fetch($fromid);
1692 foreach (array(
'internal',
'external') as $source) {
1693 $tab = $origin_project->liste_contact(-1, $source);
1694 if (is_array($tab) && count($tab)>0) {
1695 foreach ($tab as $contacttoadd) {
1696 $clone_project->add_contact($contacttoadd[
'id'], $contacttoadd[
'code'], $contacttoadd[
'source'], $notrigger);
1697 if ($clone_project->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1698 $langs->load(
"errors");
1699 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1702 if ($clone_project->error !=
'') {
1703 $this->error .= $clone_project->error;
1708 } elseif ($tab < 0) {
1709 $this->error .= $origin_project->error;
1716 if ($clone_project_file) {
1717 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1722 if (
dol_mkdir($clone_project_dir) >= 0) {
1723 $filearray =
dol_dir_list($ori_project_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$',
'', SORT_ASC, 1);
1724 foreach ($filearray as $key => $file) {
1725 $rescopy =
dol_copy($ori_project_dir.
'/'.$file[
'name'], $clone_project_dir.
'/'.$file[
'name'], 0, 1);
1726 if (is_numeric($rescopy) && $rescopy < 0) {
1727 $this->error .= $langs->trans(
"ErrorFailToCopyFile", $ori_project_dir.
'/'.$file[
'name'], $clone_project_dir.
'/'.$file[
'name']);
1732 $this->error .= $langs->trans(
'ErrorInternalErrorDetected').
':dol_mkdir';
1739 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1741 $taskstatic =
new Task($this->
db);
1745 if ($user->socid > 0) {
1746 $socid = $user->socid;
1749 $tasksarray = $taskstatic->getTasksArray(0, 0, $fromid, $socid, 0);
1751 $tab_conv_child_parent = array();
1754 foreach ($tasksarray as $tasktoclone) {
1755 $result_clone = $taskstatic->createFromClone($user, $tasktoclone->id, $clone_project_id, $tasktoclone->fk_parent, $move_date,
true,
false, $clone_task_file,
true,
false);
1756 if ($result_clone <= 0) {
1757 $this->error .= $taskstatic->error;
1760 $new_task_id = $result_clone;
1761 $taskstatic->fetch($tasktoclone->id);
1765 if (($taskstatic->hasChildren()) && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) {
1766 $tab_conv_child_parent[$tasktoclone->id] = $new_task_id;
1772 $tasksarray = $taskstatic->getTasksArray(0, 0, $clone_project_id, $socid, 0);
1773 foreach ($tasksarray as $task_cloned) {
1774 $taskstatic->fetch($task_cloned->id);
1775 if ($taskstatic->fk_task_parent != 0) {
1776 $taskstatic->fk_task_parent = $tab_conv_child_parent[$taskstatic->fk_task_parent];
1778 $res = $taskstatic->update($user, $notrigger);
1779 if ($result_clone <= 0) {
1780 $this->error .= $taskstatic->error;
1787 unset($clone_project->context[
'createfromclone']);
1790 $this->
db->commit();
1791 return $clone_project_id;
1793 $this->
db->rollback();
1794 dol_syslog(get_class($this).
"::createFromClone nbError: ".$error.
" error : ".$this->error, LOG_ERR);
1808 global $user, $langs, $conf;
1813 $taskstatic =
new Task($this->
db);
1817 if ($user->socid > 0) {
1818 $socid = $user->socid;
1821 $tasksarray = $taskstatic->getTasksArray(0, 0, $this->
id, $socid, 0);
1823 foreach ($tasksarray as $tasktoshiftdate) {
1826 if ((!empty($tasktoshiftdate->date_start)) || (!empty($tasktoshiftdate->date_end))) {
1829 $task =
new Task($this->
db);
1830 $result = $task->fetch($tasktoshiftdate->id);
1833 $this->error .= $task->error;
1839 if (!empty($tasktoshiftdate->date_start)) {
1840 $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start);
1844 if (!empty($tasktoshiftdate->date_end)) {
1845 $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start);
1849 $result = $task->update($user);
1852 $this->error .= $task->error;
1874 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tableName;
1876 if ($tableName ==
"actioncomm") {
1877 $sql .=
" SET fk_project=".$this->id;
1878 $sql .=
" WHERE id=".((int) $elementSelectId);
1879 } elseif ($tableName ==
"entrepot") {
1880 $sql .=
" SET fk_project=".$this->id;
1881 $sql .=
" WHERE rowid=".((int) $elementSelectId);
1883 $sql .=
" SET fk_projet=".$this->id;
1884 $sql .=
" WHERE rowid=".((int) $elementSelectId);
1887 dol_syslog(get_class($this).
"::update_element", LOG_DEBUG);
1890 $this->error = $this->
db->lasterror();
1907 public function remove_element($tableName, $elementSelectId, $projectfield =
'fk_projet')
1910 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tableName;
1912 if ($tableName ==
"actioncomm") {
1913 $sql .=
" SET fk_project=NULL";
1914 $sql .=
" WHERE id=".((int) $elementSelectId);
1916 $sql .=
" SET ".$projectfield.
"=NULL";
1917 $sql .=
" WHERE rowid=".((int) $elementSelectId);
1920 dol_syslog(get_class($this).
"::remove_element", LOG_DEBUG);
1923 $this->error = $this->
db->lasterror();
1940 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1942 global $conf, $langs;
1944 $langs->load(
"projects");
1947 $modele =
'baleine';
1949 if ($this->model_pdf) {
1950 $modele = $this->model_pdf;
1951 } elseif (!empty($conf->global->PROJECT_ADDON_PDF)) {
1952 $modele = $conf->global->PROJECT_ADDON_PDF;
1956 $modelpath =
"core/modules/project/doc/";
1958 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1975 $this->weekWorkLoad = array();
1976 $this->weekWorkLoadPerTask = array();
1978 if (empty($datestart)) {
1982 $sql =
"SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task";
1983 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time AS ptt, ".MAIN_DB_PREFIX.
"projet_task as pt";
1984 $sql .=
" WHERE ptt.fk_task = pt.rowid";
1985 $sql .=
" AND pt.fk_projet = ".((int) $this->
id);
1986 $sql .=
" AND (ptt.task_date >= '".$this->db->idate($datestart).
"' ";
1987 $sql .=
" AND ptt.task_date <= '".$this->db->idate(
dol_time_plus_duree($datestart, 1,
'w') - 1).
"')";
1989 $sql .=
" AND ptt.fk_task=".((int) $taskid);
1991 if (is_numeric($userid)) {
1992 $sql .=
" AND ptt.fk_user=".((int) $userid);
1998 $daylareadyfound = array();
2000 $num = $this->
db->num_rows(
$resql);
2004 $obj = $this->
db->fetch_object(
$resql);
2005 $day = $this->
db->jdate($obj->task_date);
2006 if (empty($daylareadyfound[$day])) {
2007 $this->weekWorkLoad[$day] = $obj->task_duration;
2008 $this->weekWorkLoadPerTask[$day][$obj->fk_task] = $obj->task_duration;
2010 $this->weekWorkLoad[$day] += $obj->task_duration;
2011 $this->weekWorkLoadPerTask[$day][$obj->fk_task] += $obj->task_duration;
2013 $daylareadyfound[$day] = 1;
2019 $this->error =
"Error ".$this->db->lasterror();
2020 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
2038 $this->monthWorkLoad = array();
2039 $this->monthWorkLoadPerTask = array();
2041 if (empty($datestart)) {
2045 $sql =
"SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task";
2046 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time AS ptt, ".MAIN_DB_PREFIX.
"projet_task as pt";
2047 $sql .=
" WHERE ptt.fk_task = pt.rowid";
2048 $sql .=
" AND pt.fk_projet = ".((int) $this->
id);
2049 $sql .=
" AND (ptt.task_date >= '".$this->db->idate($datestart).
"' ";
2050 $sql .=
" AND ptt.task_date <= '".$this->db->idate(
dol_time_plus_duree($datestart, 1,
'm') - 1).
"')";
2052 $sql .=
" AND ptt.fk_task=".((int) $taskid);
2054 if (is_numeric($userid)) {
2055 $sql .=
" AND ptt.fk_user=".((int) $userid);
2061 $weekalreadyfound = array();
2063 $num = $this->
db->num_rows(
$resql);
2067 $obj = $this->
db->fetch_object(
$resql);
2068 if (!empty($obj->task_date)) {
2069 $date = explode(
'-', $obj->task_date);
2072 if (empty($weekalreadyfound[$week_number])) {
2073 $this->monthWorkLoad[$week_number] = $obj->task_duration;
2074 $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] = $obj->task_duration;
2076 $this->monthWorkLoad[$week_number] += $obj->task_duration;
2077 $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] += $obj->task_duration;
2079 $weekalreadyfound[$week_number] = 1;
2085 $this->error =
"Error ".$this->db->lasterror();
2086 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
2101 global $conf, $langs;
2107 $response->warning_delay = $conf->project->warning_delay / 60 / 60 / 24;
2108 $response->label = $langs->trans(
"OpenedProjects");
2109 $response->labelShort = $langs->trans(
"Opened");
2110 $response->url = DOL_URL_ROOT.
'/projet/list.php?search_project_user=-1&search_status=1&mainmenu=project';
2111 $response->img =
img_object(
'',
"projectpub");
2112 $response->nbtodo = 0;
2113 $response->nbtodolate = 0;
2115 $sql =
"SELECT p.rowid, p.fk_statut as status, p.fk_opp_status, p.datee as datee";
2116 $sql .=
" FROM (".MAIN_DB_PREFIX.
"projet as p";
2118 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on p.fk_soc = s.rowid";
2121 $sql .=
" WHERE p.fk_statut = 1";
2122 $sql .=
" AND p.entity IN (".getEntity(
'project').
')';
2125 $projectsListId =
null;
2126 if (!$user->hasRight(
"projet",
"all",
"lire")) {
2127 $response->url = DOL_URL_ROOT.
'/projet/list.php?search_status=1&mainmenu=project';
2129 if (empty($projectsListId)) {
2133 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2144 $project_static =
new Project($this->
db);
2148 while ($obj = $this->
db->fetch_object(
$resql)) {
2149 $response->nbtodo++;
2151 $project_static->statut = $obj->status;
2152 $project_static->opp_status = $obj->fk_opp_status;
2153 $project_static->date_end = $this->
db->jdate($obj->datee);
2155 if ($project_static->hasDelay()) {
2156 $response->nbtodolate++;
2163 $this->error = $this->
db->error();
2196 $this->nb = array();
2198 $sql =
"SELECT count(p.rowid) as nb";
2199 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2201 $sql .=
" p.entity IN (".getEntity(
'project').
")";
2202 if (empty($user->rights->projet->all->lire)) {
2204 $sql .=
"AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
2209 while ($obj = $this->
db->fetch_object(
$resql)) {
2210 $this->nb[
"projects"] = $obj->nb;
2216 $this->error = $this->
db->error();
2231 if (!($this->statut == self::STATUS_VALIDATED)) {
2234 if (!$this->date_end) {
2240 return ($this->date_end) < ($now - $conf->project->warning_delay);
2252 $sql =
'SELECT c.rowid, datec as datec, tms as datem,';
2253 $sql .=
' date_close as datecloture,';
2254 $sql .=
' fk_user_creat as fk_user_author, fk_user_close as fk_use_cloture';
2255 $sql .=
' FROM '.MAIN_DB_PREFIX.
'projet as c';
2256 $sql .=
' WHERE c.rowid = '.((int) $id);
2257 $result = $this->
db->query($sql);
2259 if ($this->
db->num_rows($result)) {
2260 $obj = $this->
db->fetch_object($result);
2261 $this->
id = $obj->rowid;
2262 if ($obj->fk_user_author) {
2263 $cuser =
new User($this->
db);
2264 $cuser->fetch($obj->fk_user_author);
2265 $this->user_creation = $cuser;
2268 if (!empty($obj->fk_user_cloture)) {
2269 $cluser =
new User($this->
db);
2270 $cluser->fetch($obj->fk_user_cloture);
2271 $this->user_cloture = $cluser;
2274 $this->date_creation = $this->
db->jdate($obj->datec);
2275 $this->date_modification = $this->
db->jdate($obj->datem);
2276 $this->date_cloture = $this->
db->jdate($obj->datecloture);
2279 $this->
db->free($result);
2297 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2298 return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT);
2311 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
2312 $taskstatic =
new Task($this->
db);
2314 $this->lines = $taskstatic->getTasksArray(0, $user, $this->
id, 0, 0,
'',
'-1',
'', 0, 0, array(), 0, array(), 0, $loadRoleMode);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
liste_contact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1)
Get array of all contacts for an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage projects.
$user_author_id
Id of project creator. Not defined if shared project.
LibStatut($status, $mode=0)
Renvoi status label for a status.
getLibStatut($mode=0)
Return status label of object.
getElementCount($type, $tablename, $projectkey='fk_projet')
Return the count of a type of linked elements of this project.
setValid($user, $notrigger=0)
Validate a project.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
const STATUS_VALIDATED
Open/Validated status.
$public
Tell if this is a public or private project.
getProjectsAuthorizedForUser($user, $mode=0, $list=0, $socid=0, $filter='')
Return array of projects a user has permission on, is affected to, or all projects.
create($user, $notrigger=0)
Create a project into database.
load_state_board()
Charge indicateurs this->nb pour le tableau de bord.
const STATUS_CLOSED
Closed status.
const STATUS_DRAFT
Draft status.
loadTimeSpentMonth($datestart, $taskid=0, $userid=0)
Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of projec...
__construct($db)
Constructor.
get_element_list($type, $tablename, $datefieldname='', $date_start='', $date_end='', $projectkey='fk_projet')
Return list of elements for type, linked to a project.
fetch($id, $ref='', $ref_ext='', $email_msgid='')
Get object from database.
shiftTaskDate($old_project_dt_start)
Shift project task date from current date to delta.
hasDelay()
Is the project delayed?
remove_element($tableName, $elementSelectId, $projectfield='fk_projet')
Associate element to a project.
setCategories($categories)
Sets object to supplied categories.
update_element($tableName, $elementSelectId)
Associate element to a project.
createFromClone(User $user, $fromid, $clone_contact=false, $clone_task=true, $clone_project_file=false, $clone_task_file=false, $clone_note=true, $move_date=true, $notrigger=0, $newthirdpartyid=0)
Load an object from its id and create a new one in database.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getLinesArray($user, $loadRoleMode=1)
Create an array of tasks of current project.
info($id)
Charge les informations d'ordre info dans l'objet commande.
initAsSpecimen()
Initialise an instance with random values.
setClose($user)
Close a project.
loadTimeSpent($datestart, $taskid=0, $userid=0)
Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of projec...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into PROJECT_ADDON_PDF.
getNomUrl($withpicto=0, $option='', $addlabel=0, $moreinpopup='', $sep=' - ', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clickable name (with picto eventually)
restrictedProjectArea(User $user, $mode='read')
Check if user has permission on current project.
deleteTasks($user)
Delete tasks with no children first, then task with children recursively.
update($user, $notrigger=0)
Update a project.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
getWeekNumber($day, $month, $year)
Return week number.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db
API class for accounts.